-
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
Update FidesJS fides_embed
option to support embedding both banner & modal components
#4782
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Passing run #7172 ↗︎
Details:
Review all test suite changes for PR #4782 ↗︎ |
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.
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.
one quick nit! haven't reviewed in detail yet 👯
fides_embed
option to support embedding both banner & modal components
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'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.
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.
docs nit pick :)
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`. |
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'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?
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 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", () => { |
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 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); |
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.
@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?
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.
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.
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.
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.
Okay, I think I understand it now. There's this bit of code in Overlay.tsx
:
fides/clients/fides-js/src/components/Overlay.tsx
Lines 144 to 150 in df46bf6
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.
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 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!
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, 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.
…& modal components (#4782) Co-authored-by: Neville Samuell <[email protected]>
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
. ThebannerIsOpen
state inOverlay
is used to control if the banner or the modal is shown.Code Changes
Overlay
component state managementSteps 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. Usingfides_disable_banner=true
will skip the banner and show the modal immediately, which is the previous behavior.Pre-Merge Checklist
CHANGELOG.md