-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MWPW-153363] Countdown Timer - CDT #2803
Conversation
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## stage #2803 +/- ##
==========================================
+ Coverage 95.87% 96.10% +0.22%
==========================================
Files 173 216 +43
Lines 46333 54216 +7883
==========================================
+ Hits 44421 52102 +7681
- Misses 1912 2114 +202 ☔ View full report in Codecov by Sentry. |
libs/features/mas/web-components/src/cdt/countdown-timer.css.js
Outdated
Show resolved
Hide resolved
libs/features/mas/web-components/src/cdt/countdown-timer.css.js
Outdated
Show resolved
Hide resolved
This pull request is not passing all required checks. Please see this discussion for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
With https://github.com/orgs/adobecom/discussions/2819#discussioncomment-10544162, the LCP impact could be even further reduced.
cc: @narcis-radu @mokimo
width: 100%; | ||
font-size: 14px; | ||
font-weight: regular; | ||
text-align: left; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about RTL locales?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start
is likely a better option here, as @narcis-radu mentioned - https://developer.mozilla.org/en-US/docs/Web/CSS/text-align
} | ||
|
||
.horizontal .timer-block { | ||
margin-left: 10px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might create issues on RTL locales
@@ -33,6 +33,14 @@ function decorateQr(el) { | |||
qrImage.classList.add('qr-code-img'); | |||
} | |||
|
|||
export async function loadCountDownTimer(el) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the same method in both marquee and media; what do you think about adding it to decorate.js
and load it conditionally?
} | ||
|
||
.timer-label { | ||
font-size: 16px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aren't the font sizes supposed to be consistent with existing variables?
|
||
.timer-label { | ||
font-size: 16px; | ||
font-weight: bold; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use numeric value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't block the PR//request changes anymore - given the business priority, however I still don't agree with how a few things been done. Milo has a certain coding style and patterns, which this block does not follow.
- This block is written in a very different way compared to other blocks.
- It attaches itself to the shadowRoot, which is a very novel pattern
- It inlines styles
- It uses private class variables, which I haven't ever seen before
- It's a performance anti-pattern to add loading more things to the LCP block IMO
- The CDT block could be loaded asynchronously, but you would need to work around the potential CLS. That way you wouldn't impact performance.
- Nested blocks are bad for several reasons and discouraged by AEM https://www.aem.live/docs/davidsmodel#rule-2-no-nested-blocks-for-authors
beside creating a CDT-Marquee which does not look great (or does it? temp/bin components folder?)
Current PR looks like the only solution to me together probably with preload/prefetches
I personally feel like a "Temp" CDT-Marquee would be a cleaner solution, also given that the marquee is a widely used block and we now add features to the block that might only be used on very special occasions during the year.
As discussed with @yesil and @vhargrave last week, another good idea would be making this an autoblock which would then be re-useable across blocks by default. |
The testing status has been updated in the linked JIRA ticket: [MWPW-153363] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think we need to pull a hard brake with this implementation.
There are a lot of things going on here that are not milo standard and that additionally are not good practice for LCP.
- declaring CSS in the .js file
- setting innerHTML with content from our authors (security issue)
- loading in content over a fragment in the LCP block
- loading a block within a block
This is also not a typical use case, so I think we need to come up with a good solution for it. My opinion currently is that the best solution to add this would be to add it as a feature. Add metadata which defines the start & end date of this timer, and either add information to the metadata, to which block this feature should be added, or have a little code in the blocks that add this timer to the end of the text in the block.
This is just my best idea currently though, and there could be other better ideas.
cc: @mokimo @narcis-radu @overmyheadandbody @robert-bogos
P.S. I also think an autoblock could work here and would also be a decent solution, but it seems little hard for our authors to author. That's the only reason I'm not all for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor things on top of the over-arching feedback provided so far. This is not consistent with any of the current Milo practices and will be an issue for maintainability. What is the major advantage of this approach to justify going against other patterns?
.horizontal { | ||
display: flex; | ||
flex-direction: row; | ||
padding: 20px 0px; | ||
} | ||
|
||
.vertical { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 20px 0px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.horizontal { | |
display: flex; | |
flex-direction: row; | |
padding: 20px 0px; | |
} | |
.vertical { | |
display: flex; | |
flex-direction: column; | |
padding: 20px 0px; | |
} | |
.horizontal, .vertical { | |
display: flex; | |
padding: 20px 0; | |
} | |
.vertical { | |
flex-direction: column; | |
} |
flex-direction
is row
by default, some repetition can be avoided here
} | ||
|
||
.light .timer-label { | ||
color: #000000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
color: #000000; | |
color: #000; |
} | ||
|
||
.dark .timer-label { | ||
color: #FFFFFF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
color: #FFFFFF; | |
color: #FFF; |
} | ||
|
||
.horizontal .timer-label { | ||
margin: 0px 2px 45px 2px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
margin: 0px 2px 45px 2px; | |
margin: 0px 2px 45px; |
Also, why do you need the 45px
? They seem to be taking up additional space, expanding the host block more than would be needed.
background-color: #222222; | ||
color: #FFFFFF; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
background-color: #222222; | |
color: #FFFFFF; | |
background-color: #222; | |
color: #FFF; |
|
||
#timeRangesEpoch = []; | ||
|
||
static css = ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intent to avoid loading the CSS file? It's a well established pattern in Milo, I don't see why you'd want to add things here, since a request is still made for the styles. This goes against current conventions, is a risk for maintainability and likely doesn't improve performance, if that was the goal.
|
||
countdownCompleted() { | ||
this.isVisible = false; | ||
clearInterval(this.countdownInterval); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you call disconnectedCallback
instead? Also, the method name uses an adjective to define an action, disconnectCallback
might be a better fit
this.shadowRoot.innerHTML = ''; | ||
return; | ||
} | ||
|
||
this.shadowRoot.innerHTML = ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting innerHTML
will likely trigger some Kodiak alerts
el.replaceWith(cdt); | ||
} catch (error) { | ||
el.replaceWith(''); | ||
window.lana?.log(`Failed to load countdown timer module: ${error}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should likely add some tags to this, latest format can be seen in this PR.
@@ -105,4 +113,8 @@ export default function init(el) { | |||
const mediaRowReversed = el.querySelector(':scope > .foreground > .media-row > div').classList.contains('text'); | |||
if (mediaRowReversed) el.classList.add('media-reverse-mobile'); | |||
decorateTextOverrides(el); | |||
|
|||
if (el.classList.contains('countdown-timer')) { | |||
loadCountDownTimer(el); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be await
ed here as well?
@@ -0,0 +1,242 @@ | |||
import { createTag } from '../../utils/utils.js'; | |||
|
|||
export class CountdownTimer extends HTMLElement { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought Milo blocks were not supposed to use classes and web components. Normally classes are defined in web-components
folder.
What is the reason for doing this way?
@npeltier @yesil @rahulgupta999 to not block you on this, if you do create a new temp-marquee specifically for the CDT to hit the business goals, that would be the easiest and quickest way to merge this (IMO) ... a new block or "block-valid-till-X" is easier to create and hopefully also clean up again |
I disagree with @mokimo's suggestion, as I believe at a general level this could lead to dependencies once the code intended for removal reaches production. We may face difficulties deprecating it if it's still being used on certain pages, the team will not see a RTB task as a top priority. Nevertheless, this discussion is more suitable for https://github.com/orgs/adobecom/discussions if we need to follow-up. |
} | ||
|
||
this.shadowRoot.innerHTML = ` | ||
<style>${CountdownTimer.css}</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rahulgupta999 you can load the CSS as at https://github.com/adobecom/milo/blob/stage/libs/blocks/bulk-publish-v2/components/bulk-publisher.js#L58
it is more aligned with Milo.
Closing this PR as this has been replaced with approach to use page metadata |
As presented in AST, the regions have been using a ticker/timer/countdown visual to boost click through rates and engagement as an enticement for certain promotions; e.g., Black Friday / Cyber Monday
Countdown Timer (CDT)
Properties:
CDT Layout: horizontal (default), vertical
CDT Color mode: light (default), dark
CDT End Date: input as YYYY-MM-DD, dd:hh:mm, time zone code
CDT Start Date: input as YYYY-MM-DD, dd:hh:mm, time zone code
Resolves: MWPW-153363
Test URLs: