Skip to content
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

Closed
wants to merge 42 commits into from

Conversation

rahulgupta999
Copy link
Contributor

@rahulgupta999 rahulgupta999 commented Aug 29, 2024

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
image

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:

@rahulgupta999 rahulgupta999 requested a review from a team as a code owner August 29, 2024 08:07
@rahulgupta999 rahulgupta999 marked this pull request as draft August 29, 2024 08:07
Copy link
Contributor

aem-code-sync bot commented Aug 29, 2024

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.10%. Comparing base (510f7a6) to head (bf6a427).
Report is 47 commits behind head on stage.

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.
📢 Have feedback on the report? Share it here.

@rahulgupta999 rahulgupta999 added run-nala Run Nala Test Automation against PR new-feature New block or other feature labels Aug 29, 2024
Copy link
Contributor

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.

libs/blocks/countdown-timer/countdown-timer.js Outdated Show resolved Hide resolved
libs/blocks/countdown-timer/countdown-timer.js Outdated Show resolved Hide resolved
libs/blocks/countdown-timer/countdown-timer.js Outdated Show resolved Hide resolved
Copy link
Contributor

@yesil yesil left a 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

@mokimo mokimo self-requested a review September 6, 2024 14:55
@mokimo mokimo dismissed their stale review September 9, 2024 07:56

no longer requesting changes

width: 100%;
font-size: 14px;
font-weight: regular;
text-align: left;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about RTL locales?

Copy link
Contributor

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;
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor

@mokimo mokimo left a 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.

@mokimo
Copy link
Contributor

mokimo commented Sep 9, 2024

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.
That way you also avoid the loadBlock portion within the marquee

@Priyankavgit
Copy link

The testing status has been updated in the linked JIRA ticket: [MWPW-153363]
Apart from the hero-marquee, the rest of the changes have been fixed and are working properly.

@Priyankavgit Priyankavgit added the verified PR has been E2E tested by a reviewer label Sep 9, 2024
Copy link
Contributor

@vhargrave vhargrave left a 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.

  1. declaring CSS in the .js file
  2. setting innerHTML with content from our authors (security issue)
  3. loading in content over a fragment in the LCP block
  4. 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.

Copy link
Contributor

@overmyheadandbody overmyheadandbody left a 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?

Comment on lines +17 to +27
.horizontal {
display: flex;
flex-direction: row;
padding: 20px 0px;
}

.vertical {
display: flex;
flex-direction: column;
padding: 20px 0px;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
color: #000000;
color: #000;

}

.dark .timer-label {
color: #FFFFFF;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
color: #FFFFFF;
color: #FFF;

}

.horizontal .timer-label {
margin: 0px 2px 45px 2px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +76 to +77
background-color: #222222;
color: #FFFFFF;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
background-color: #222222;
color: #FFFFFF;
background-color: #222;
color: #FFF;


#timeRangesEpoch = [];

static css = `
Copy link
Contributor

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);
Copy link
Contributor

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

Comment on lines +168 to +172
this.shadowRoot.innerHTML = '';
return;
}

this.shadowRoot.innerHTML = `
Copy link
Contributor

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}`);
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be awaited here as well?

@@ -0,0 +1,242 @@
import { createTag } from '../../utils/utils.js';

export class CountdownTimer extends HTMLElement {
Copy link
Member

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?

@mokimo
Copy link
Contributor

mokimo commented Sep 17, 2024

@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

@narcis-radu
Copy link
Contributor

narcis-radu commented Sep 18, 2024

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.
My suggestion is to investigate the previously shared feedback and see whether an auto block makes more sense here; if not, we need to address things in a way that they don't impact performance. Regardless of the approach, the code footprint should be small enough and should follow the general guidelines in Milo.

}

this.shadowRoot.innerHTML = `
<style>${CountdownTimer.css}</style>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahulgupta999
Copy link
Contributor Author

Closing this PR as this has been replaced with approach to use page metadata
#2928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commerce new-feature New block or other feature run-nala Run Nala Test Automation against PR verified PR has been E2E tested by a reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants