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

Update FidesJS fides_embed option to support embedding both banner & modal components #4782

Merged
merged 11 commits into from
Apr 11, 2024

Conversation

guncha
Copy link
Contributor

@guncha guncha commented Apr 10, 2024

Description Of Changes

This turned out to be a bit of an adventure. Initially I wanted to allow embedding the banner and the modal in separate containers and after spending some time going in this direction, it turned out to be not possible without a lot of effort refactoring the code which I didn't feel comfortable doing (also time). The issue is that putting the banner and the modal in two different containers would require separating the components "all the way to the top", so to speak, which would mean they'd have entirely separate state and everything.

The approach here is to embed both the banner and the modal in the same fides-embed-container. The bannerIsOpen state in Overlay is used to control if the banner or the modal is shown.

Code Changes

  • Overlay component state management
  • CSS overrides when the banner is embedded

Steps to Confirm

The changes can be tested by using the fides_embed=true override. The banner will be shown first and it should be replaced with the Layer 2 "modal" when the "Manage preferences" link is clicked. Using fides_disable_banner=true will skip the banner and show the modal immediately, which is the previous behavior.

Pre-Merge Checklist

@guncha guncha requested a review from NevilleS April 10, 2024 03:13
Copy link

vercel bot commented Apr 10, 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 Apr 11, 2024 1:43am

Copy link

cypress bot commented Apr 10, 2024

Passing run #7172 ↗︎

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 479345e into a0faefa...
Project: fides Commit: 4382c4ae48 ℹ️
Status: Passed Duration: 00:37 💡
Started: Apr 11, 2024 1:54 AM Ended: Apr 11, 2024 1:55 AM

Review all test suite changes for PR #4782 ↗︎

Copy link
Contributor

@eastandwestwind eastandwestwind left a comment

Choose a reason for hiding this comment

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

Tested this and looking great! It's almost there, just wanna fix that duplicate event firing.

banner:
Screenshot 2024-04-10 at 5 26 44 PM

modal:
Screenshot 2024-04-10 at 5 27 00 PM

Also confirmed that Admin UI preview mode still looks good:
Screenshot 2024-04-10 at 5 53 00 PM

clients/fides-js/src/components/fides.css Show resolved Hide resolved
clients/fides-js/src/components/Overlay.tsx Show resolved Hide resolved
clients/fides-js/src/components/Overlay.tsx Outdated Show resolved Hide resolved
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.

one quick nit! haven't reviewed in detail yet 👯

@NevilleS NevilleS changed the title Embed the banner Update FidesJS fides_embed option to support embedding both banner & modal components Apr 10, 2024
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'm comfy merging this as-is (once we're up to date with main & CHANGELOG) but I do have one more stretch ask...

Can you also update the developer docs here:

* When `true`, require FidesJS to "embed" it's UI into a specific `<div>` on

(/clients/fides-js/src/docs/fides-options.ts)

A quick explanation there will be helpful, and you can reference the fides_disable_banner option to explain to a developer how to only embed the modal.

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.

docs nit pick :)

Comment on lines 84 to 86
Before version 2.34 only the consent modal was embedded while the banner was
not shown at all, but since that version both will be embedded. To get the
previous behavior also set `fides_disable_banner` to `true`.
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'd rather not reference "previous versions" here, just state the fact:

  • will embed banner & modal
  • if you don't want banner, disable it

does that make sense?

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 think I fixed this, but want to get @guncha to double-check me

fidesDisableBanner: true,
},
experience: experience.items[0],
describe("when fides_embed is 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 diff is hard to read, but I reorganized the specs to be:

  • when fides_embed is true
    • when fides_disable_banner is false
      • (NEW) test the layer 1 banner is shown
    • when fides_disable_banner is true
      • (all existing tests go here)

@@ -76,7 +76,7 @@ const Overlay: FunctionComponent<Props> = ({
const delayBannerMilliseconds = 100;
const delayModalLinkMilliseconds = 200;
const hasMounted = useHasMounted();
const [bannerIsOpen, setBannerIsOpen] = useState(options.fidesEmbed);
const [bannerIsOpen, setBannerIsOpen] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

@guncha: I switched this back to default to false and it fixes things - but want to understand why before just shipping this... does this make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I did it was because otherwise, when fides_disable_banner is false, it would flash the modal and then re-render immediately and show the banner. My change didn't take into account fides_disable_banner so it should have had the opposite problem when it was set to true. Seems like it should be options.fidesEmbed && !options.fidesDisableBanner. Not quite sure why it would break the tests though so I'll do some investigation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So yeah, this is the issue with just setting to to false:

content-flash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I think I understand it now. There's this bit of code in Overlay.tsx:

useEffect(() => {
const delayBanner = setTimeout(() => {
if (showBanner) {
setBannerIsOpen(true);
}
}, delayBannerMilliseconds);
return () => clearTimeout(delayBanner);

This is needed to first render ConsentBanner in the DOM with bannerIsOpen=false and then flip it to true after a short delay which will result in the removal of the fides-banner-hidden class and a nice entry animation.

In the embed case, we are not animating anything so we can jump to the final state, but it has to be the correct one, otherwise there will be a blip of the other component OR nothing being rendered. Still not sure how this worked before, but I'm glad the e2e test caught it.

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 it worked before because we were not rendering the banner at all with the embed mode. But this is a good catch, I've not used the performance tab in this way before, so I learned something new!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, gotcha. Alright, I think overall this still feels like a fragile bit of state to manage (ie if we were being extra careful, that "banner is open" state feels like it's the job of the ConsentBanner component itself to handle it's own animation on mount) but this looks good now.

@NevilleS NevilleS merged commit 19b99df into main Apr 11, 2024
13 checks passed
@NevilleS NevilleS deleted the ga-embed-banner branch April 11, 2024 11:36
NevilleS added a commit that referenced this pull request Apr 11, 2024
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