generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
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-142935 [Project PEP] PEP <> Geo Routing Modal Interactions #2403
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6ff3c98
modified georouting and pep so that pep only appears if a) GRM is not…
sharmrj 2d0ee33
Unit test for GRM/PEP interaction
sharmrj 164037a
changed grmActive to geoRoutinActive
sharmrj 0cff0ae
Fixed unit test for grm/pep interaction
sharmrj 50c63e3
removed unused imports
sharmrj 99e4d1d
Cleaned up the implementation
sharmrj f1b4a5e
Changed from polling to listening for an event
sharmrj c2aadc2
removed an unnecessary line
sharmrj c52ffa9
Modified unit test
sharmrj d73dbf8
Changed the implementation to use polling for any modal
sharmrj d5fbaef
Merge branch 'stage' of https://github.com/adobecom/milo into pep-geo…
sharmrj 2ad215a
Changed pep loading logic to poll for modals only after the close mod…
sharmrj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -35,6 +35,13 @@ const getIcon = (content) => { | |||||
return icons.company; | ||||||
}; | ||||||
|
||||||
const geoRoutingActive = () => !!document.querySelector('.locale-modal-v2') | ||||||
|| !!document.querySelector('.locale-modal'); | ||||||
|
||||||
const waitForClosedGRMThen = (loadPEP) => { | ||||||
window.addEventListener('milo:modal:closed', loadPEP); | ||||||
}; | ||||||
|
||||||
class AppPrompt { | ||||||
constructor({ promptPath, entName, parent, getAnchorState } = {}) { | ||||||
this.promptPath = promptPath; | ||||||
|
@@ -43,8 +50,8 @@ class AppPrompt { | |||||
this.getAnchorState = getAnchorState; | ||||||
this.id = this.promptPath.split('/').pop(); | ||||||
this.elements = {}; | ||||||
|
||||||
this.init(); | ||||||
if (geoRoutingActive()) waitForClosedGRMThen(this.init); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
else this.init(); | ||||||
} | ||||||
|
||||||
init = async () => { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
sorry for doing this, but I just realized that it's possible for two dialogs to be open.
see this link - https://stage--cc--adobecom.hlx.page/products/photoshop/ai?milolibs=pep-georouting&skipPepEntitlements=true#langnav
we need to add a check here that geoRoutingActive() is now false.
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've discovered that when the event is emitted it won't necessarily trigger PEP's
init
method, since it's possible for the modal to still exist in the DOM at that point. I'm looking into why this might be.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.
completely agree.
In my opinion PEP should not be appearing if any modal is open, but since that makes your task more complicated I didn't mention it.
Maybe you can mention that to your PdM and if they deem it necessary then tackle that in a separate task.
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.
oh and btw, you want to clean up your listener once you've triggered it once.
https://dev.to/js_bits_bill/addeventlistener-once-js-bits-565d
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.
So it seems a bit implementation dependent (which means the whatwg spec doesn't seem to have information about this, but there is a chromium design document here), but on chrome once the event is dispatched it seems that the eventListener's callback is called first, and then the rest of the code that removes the modal fires (kind of like a delimited continuation). See the video below:
eb.mp4
I believe the behavior that targets specifically the GRM (or perhaps modals in general?) with a custom event might be better in this case, but this would involve touching a lot more code.
In the most general sense, it's not possible for me to predict if sometime between the moment a modal is closed and the moment where the user is redirected by pep a modal will pop up (as lang nav pops up very late). So I'm willing to compromise to allowing PEP to begin iff there are no modals on the screen, while making no guarantees about future modals.
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.
@sharmrj it seems to me that the right solution would be to change the modal.js so that the close event is sent after removing the modal.
@JasonHowellSlavin can you weigh in if you see issues with moving the window.dispatchEvent of milo:modal:closed after removing the modal?
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.
Hi @vhargrave, I do think both you and @sharmrj have identified a key issue with the
milo:modal:closed
dispatch being placed too high in the function and not reflecting what is actually occurring. I don't see an issue with moving it down, but since there are a few other files that rely on it, it might be good to raise that as an issue and specifically test for those implementations.It also looks like @sharmrj has done some experimentation and found the performance impact of the current code to be negligible.
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.
@JasonHowellSlavin ok, thanks for confirming 👍