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-140481: Delayed modal #1877

Closed
wants to merge 10 commits into from

Conversation

mirafedas
Copy link
Contributor

@mirafedas mirafedas commented Feb 14, 2024

This feature enables the delayed display of a modal, primarily intended for promotional purposes.

When parsing the promotional manifest, if we encounter a rule labeled insertContentAfter containing a link with valid parameters for delay and display, we dynamically generate a hidden link within the specified selector. This link behaves conventionally, triggering a modal upon click. Following this setup, we introduce a delay of some number of seconds before unveiling the modal, simultaneously appending a modal hash to the browser's URL. If the modal is configured for a one-time session display (display="session"), we remember this in sessionStorage to prevent subsequent displays upon page reload.

Resolves: MWPW-140481

Authoring documentation

Test URLs:

  • Before: not applicable, because this is a newly added feature
  • After:
    First page
    Second page
    Feel free to change the display param to either pageload or session in this file

@mirafedas mirafedas requested a review from a team as a code owner February 14, 2024 13:36
@mirafedas mirafedas added @modal Run Modal Tests Nala new-feature New block or other feature needs-verification PR requires E2E testing by a reviewer run-nala Run Nala Test Automation against PR labels Feb 14, 2024
@@ -99,18 +99,105 @@ export const preloadManifests = ({ targetManifests = [], persManifests = [] }) =

export const getFileName = (path) => path?.split('/').pop();

const createFrag = (el, url, manifestId) => {
let href = url;
export async function initDelayedModal({
Copy link
Contributor

Choose a reason for hiding this comment

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

I think modal logic should go in modal.js

if (!window.sessionStorage.getItem('wasDelayedModalShown')) {
setTimeout(() => {
getModal(details);
window.sessionStorage.setItem('wasDelayedModalShown', true);
Copy link
Contributor

Choose a reason for hiding this comment

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

this implementation supports one single delayed modal.
if the user navigates from one page to another in the same session, I think the other modals will not be shown.

Copy link
Contributor Author

@mirafedas mirafedas Feb 15, 2024

Choose a reason for hiding this comment

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

@yesil
I created two test pages to verify this:

  1. First page
  2. Second page

On both pages I placed some traditional modals.
To me all works as expected.
If you want to test yourself, feel free to change the display param to either pageload or session in this file

Copy link
Contributor

Choose a reason for hiding this comment

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

this test doesn't cover oncePerSession option.
please use oncePerSession, and link one page to the other one and try to navigate.
I expect the second modal will not be shown.

Copy link
Contributor Author

@mirafedas mirafedas Feb 19, 2024

Choose a reason for hiding this comment

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

@yesil
I cross-linked both pages, set the display param to session, and it works as expected:

  1. When I open the first page for the first time, the modal is shown, and the the wasDelayedModalShown key is saved in the session storage;
  2. Then I click the link to navigate to the second page, and the modal is not shown, which is expected as the modal should be shown once per browser session and it was already shown on the first page.
  3. Other modals which I linked to both pages get opened on click.
    I will ask Reuben to verify this as well.
    I also refactored the code a bit to make it simpler, could you please review once again?

});

it('creates and opens the delayed modal', async () => {
const hash = '#delayed-modal';
Copy link
Contributor

Choose a reason for hiding this comment

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

delayed-modal shounds to technical.

I wonder if we could adopt a more short/cryptic naming here, like md or dm.

Copy link
Member

@auniverseaway auniverseaway left a comment

Choose a reason for hiding this comment

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

I think this can be simpler.

Copy link

codecov bot commented Feb 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.68%. Comparing base (f5e68ff) to head (c11d4e8).
Report is 1 commits behind head on main.

❗ Current head c11d4e8 differs from pull request most recent head 2725066. Consider uploading reports for the commit 2725066 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1877      +/-   ##
==========================================
+ Coverage   95.64%   95.68%   +0.04%     
==========================================
  Files         159      159              
  Lines       41183    41345     +162     
==========================================
+ Hits        39388    39562     +174     
+ Misses       1795     1783      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mirafedas
Copy link
Contributor Author

@auniverseaway
Do you have any tips on how to simplify this? Otherwise, I'm not sure what changes I should make

@mirafedas mirafedas added the do not merge PR should not be merged yet label Feb 15, 2024
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal branch from 46631ba to e4dfe62 Compare February 15, 2024 13:45
@mirafedas mirafedas removed the do not merge PR should not be merged yet label Feb 15, 2024
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal branch from eebf905 to 80e56ec Compare February 19, 2024 15:04
@mirafedas mirafedas force-pushed the MWPW-140481-delayed-modal branch from c0c5740 to c11d4e8 Compare February 19, 2024 16:11
Copy link
Contributor

@chrischrischris chrischrischris left a comment

Choose a reason for hiding this comment

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

I haven't had a chance for an in-depth review but wanted to ask - why are all the changes in personalization needed?

Also we don't want personalization.js to load any external files (modal.js) unless absolutely needed.

I think that all of the modal logic needs to be in modal.js and should not require MEP in any way.

@chrischrischris
Copy link
Contributor

chrischrischris commented Feb 20, 2024

My thoughts:

  • No modal code should be in personalization.js, all functionality should be in modal.js
  • Instead of query params, we should have the params built into the modal name: #modal-name:delay=3:display=session.
    • This allows for the modal.js code to remove the params from the url without needing to do a refresh.
  • delayed modals should work without MEP - e.g: www.adobe.com/nz/mypage#modal-name:delay=3:display=session will work on page load.

With these changes, there are no changes needed to MEP. The fragment link set in the manifest would contain the info and modal.js would handle everything else.

More minor thoughts:

  • What should the behavior be if multiple fragments specify a delayed modal?
  • What happens when a modal is deep linked (so displaying immediately on page load) and a fragment has a delayed modal?
  • sessionstorage should differentiate between which delayed modal was shown. A single wasDelayedModalShown key would stop a possible other delayed modal unrelated to the original one from being show. Something like shown:modal-name.

Implementation details:

  • The parsing of the modal hash happens in modal.js init. Your code should go there to check / parse / setTimeout the opening of a modal hash with delay params.
  • There is also a modal:open event that you can fire that will trigger a modal if that approach works better.

@Roycethan
Copy link

Roycethan commented Feb 20, 2024

@mirafedas few observations adding here: plz review

  1. I don't see modal loading on successive page loads, Say below link (with hash) is deep-linked in some other site and user clik on the CTA to launch this deep link with hash
    https://mwpw-140481-delayed-modal--milo--mirafedas.hlx.page/drafts/mirafedas/secondpage#delayed-modal
    OR
    User launch https://mwpw-140481-delayed-modal--milo--mirafedas.hlx.page/drafts/mirafedas/secondpage and click on say 'Save' to navigate to Checkout (if linked to open in same page ) and the click Back in browser

2 Click event outside the modal has web interaction name 'modalClose:buttonClose'
Ideally it should be : 'modalClose:overlayClose' to distinguish between button click and outside clicks.

@mirafedas
Copy link
Contributor Author

Closing this PR as these changes are not actual anymore, and opening a new one

@mirafedas mirafedas closed this Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@modal Run Modal Tests Nala needs-verification PR requires E2E testing by a reviewer new-feature New block or other feature run-nala Run Nala Test Automation against PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants