-
Notifications
You must be signed in to change notification settings - Fork 72
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
Adding Fides.showModal #4617
Adding Fides.showModal #4617
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@@ -100,7 +102,16 @@ const Overlay: FunctionComponent<Props> = ({ | |||
return () => clearTimeout(delayBanner); | |||
}, [setBannerIsOpen]); | |||
|
|||
const showModal = () => { | |||
if (!isModalLinkFound) { | |||
document.body.classList.add("fides-modal-link-shown"); |
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.
Only adds the fides-modal-link-shown
class to the body
if the modal link isn't found
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.
nit: I think it's slightly safer to do a different classname to not redefine the semantic meaning of this class. In other words, I could see someone already doing this:
.fides-modal-link-shown { font-size: 40px }
...since today we only ever add that class to the individual link element, that would have been "safe". But if we start adding this class to the body
that could be disastrous!
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.
Ah! I misread the class name, updated to fides-overlay-modal-link-shown
Passing run #6296 ↗︎
Details:
Review all test suite changes for PR #4617 ↗︎ |
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 know this is WIP, but it looks good to me! Some nits and suggestions
if (!isModalLinkFound) { | ||
document.body.classList.add("fides-modal-link-shown"); | ||
} | ||
setBannerIsOpen(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.
nit: can't this be moved into handleOpenModal()
?
@@ -100,7 +102,16 @@ const Overlay: FunctionComponent<Props> = ({ | |||
return () => clearTimeout(delayBanner); | |||
}, [setBannerIsOpen]); | |||
|
|||
const showModal = () => { | |||
if (!isModalLinkFound) { | |||
document.body.classList.add("fides-modal-link-shown"); |
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.
nit: I think it's slightly safer to do a different classname to not redefine the semantic meaning of this class. In other words, I could see someone already doing this:
.fides-modal-link-shown { font-size: 40px }
...since today we only ever add that class to the individual link element, that would have been "safe". But if we start adding this class to the body
that could be disastrous!
setBannerIsOpen(false); | ||
handleOpenModal(); | ||
}; | ||
modalLink.onclick = window.Fides.showModal; |
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 is pretty much what I was imagining, yup!
As a slight bonus to this... I think we should consider switching this to use addEventListener("click", (evt) => { ... })
instead of onclick = () => { ... }
. This isn't the core ask of the ticket, but looking at this code again reminds me that, in general onclick
feels fragile.
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.
Couple more nits but this looks good!
@@ -110,19 +127,26 @@ const Overlay: FunctionComponent<Props> = ({ | |||
options.debug, | |||
"Modal link element found, updating it to show and trigger modal on click." | |||
); | |||
modalLinkRef.current = modalLinkEl; | |||
// Update modal link to trigger modal on click | |||
const modalLink = modalLinkEl; |
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 delete this var and use the ref instead 👍
setBannerIsOpen(false); | ||
handleOpenModal(); | ||
}; | ||
modalLink.addEventListener("click", window.Fides.showModal); |
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.
modalLink.addEventListener("click", window.Fides.showModal); | |
modalLinkRef.current.addEventListener("click", window.Fides.showModal); |
@@ -100,7 +109,15 @@ const Overlay: FunctionComponent<Props> = ({ | |||
return () => clearTimeout(delayBanner); | |||
}, [setBannerIsOpen]); | |||
|
|||
const showModal = () => { | |||
if (!modalLinkRef.current) { | |||
document.body.classList.add("fides-overlay-modal-link-shown"); |
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, I think I was confusing everyone about this.
I'd like us to add this class to the body immediately when the overlay renders, so that it's there and available as a utility class for the engineer to pull from.
So I'd do this right on line 120 instead, see next comment...
useEffect(() => { | ||
window.Fides.showModal = showModal; |
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.
window.Fides.showModal = showModal; | |
window.Fides.showModal = showModal; | |
document.body.classList.add("fides-overlay-modal-link-shown") |
Basically that CSS class should be synced to whether or not the modal link should be shown and usable.
|
||
it("Should allow showModal", () => { | ||
// eslint-disable-next-line cypress/no-unnecessary-waiting | ||
cy.wait(100); |
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.
Give enough time for the Overlay.tsx
component to run the useEffect
that sets Fides.showModal
Closes PROD-1689
Description Of Changes
Adds
Fides.showModal
to be able to manually trigger the modal if supported by the current experience configuration.Steps to Confirm
clients
directory and runturbo run dev
window.Fides.showModal
in the console, verify the console appearsPre-Merge Checklist
CHANGELOG.md