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

Adding Fides.showModal #4617

Merged
merged 7 commits into from
Feb 16, 2024
Merged

Adding Fides.showModal #4617

merged 7 commits into from
Feb 16, 2024

Conversation

galvana
Copy link
Contributor

@galvana galvana commented Feb 15, 2024

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

Pre-Merge Checklist

Copy link

vercel bot commented Feb 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview Feb 16, 2024 9:31pm

@@ -100,7 +102,16 @@ const Overlay: FunctionComponent<Props> = ({
return () => clearTimeout(delayBanner);
}, [setBannerIsOpen]);

const showModal = () => {
if (!isModalLinkFound) {
document.body.classList.add("fides-modal-link-shown");
Copy link
Contributor Author

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

Copy link
Contributor

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!

Copy link
Contributor Author

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

clients/fides-js/src/components/Overlay.tsx Show resolved Hide resolved
Copy link

cypress bot commented Feb 15, 2024

Passing run #6296 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge ea025f8 into 57011ac...
Project: fides Commit: 0c57f7769d ℹ️
Status: Passed Duration: 00:34 💡
Started: Feb 16, 2024 9:42 PM Ended: Feb 16, 2024 9:43 PM

Review all test suite changes for PR #4617 ↗︎

Copy link
Contributor

@NevilleS NevilleS left a 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);
Copy link
Contributor

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

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

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.

Copy link
Contributor

@NevilleS NevilleS left a 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;
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 delete this var and use the ref instead 👍

setBannerIsOpen(false);
handleOpenModal();
};
modalLink.addEventListener("click", window.Fides.showModal);
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
modalLink.addEventListener("click", window.Fides.showModal);
modalLinkRef.current.addEventListener("click", window.Fides.showModal);

clients/fides-js/src/components/Overlay.tsx Show resolved Hide resolved
@@ -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");
Copy link
Contributor

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;
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
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.

@galvana galvana marked this pull request as ready for review February 16, 2024 18:58

it("Should allow showModal", () => {
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(100);
Copy link
Contributor Author

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

@Kelsey-Ethyca Kelsey-Ethyca merged commit 68c204a into main Feb 16, 2024
13 checks passed
@Kelsey-Ethyca Kelsey-Ethyca deleted the PROD-1689-fides-show-modal branch February 16, 2024 22:20
Kelsey-Ethyca pushed a commit that referenced this pull request Feb 16, 2024
@cypress cypress bot mentioned this pull request Feb 16, 2024
31 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants