-
Notifications
You must be signed in to change notification settings - Fork 203
chore: Add Flashbar and Alert dismiss persistence #4035
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
base: main
Are you sure you want to change the base?
Conversation
1dec203 to
f0eff84
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4035 +/- ##
=======================================
Coverage 96.99% 96.99%
=======================================
Files 861 861
Lines 25214 25257 +43
Branches 9094 9103 +9
=======================================
+ Hits 24456 24499 +43
Misses 711 711
Partials 47 47 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f0eff84 to
d9dfbdb
Compare
d9dfbdb to
842c792
Compare
just-boris
left a comment
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.
Legend
⛳ – blocking comments, possible bugs
Other comments are optional code style suggestions
842c792 to
0730c73
Compare
0730c73 to
ba0873c
Compare
just-boris
left a comment
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.
All blocking comments resolved, thanks
|
|
||
| // Resolve second call first (race condition scenario) | ||
| resolveSecond!(false); // Item 2 should be visible | ||
| await waitFor(() => {}); |
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.
Is this needed for anything?
| const [checkedPersistenceKeys, setCheckedPersistenceKeys] = useState<Set<string>>(new Set()); | ||
| const [persistentItemsVisibility, setPersistentItemsVisibility] = useState<Map<string, boolean>>(new Map()); | ||
|
|
||
| const visibleItems = useMemo(() => { |
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 benefit is not measurable in any way. This is why typically I recommend to keep the code simple without extra things
| setIsPersistentlyDismissed(!!dismissed); | ||
| }); | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps |
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.
why? what if persistenceConfig.crossServicePersistence changes?
|
|
||
| const dismiss = () => { | ||
| fireNonCancelableEvent(onDismiss); | ||
| if (persistenceConfig && persistenceConfig.uniqueKey) { |
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.
[minor] for consistency
| if (persistenceConfig && persistenceConfig.uniqueKey) { | |
| if (persistenceConfig?.uniqueKey) { |
| const headerRef = useMergeRefs(headerRefAction, headerRefContent); | ||
| const contentRef = useMergeRefs(contentRefAction, contentRefContent); | ||
| const [isPersistentlyDismissed, setIsPersistentlyDismissed] = useState( | ||
| !!(persistenceConfig && persistenceConfig.uniqueKey) |
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.
default-to-dismissed seems dangerous here, especially combined with promise without error handling in the useEffect below: if something within retrieveAlertDismiss fails then user will never see the alert.
At the very minimum the promise should have error handling, but I would strongly prefer an approach of default-to-visible
| } | ||
|
|
||
| const checkNewPersistentItems = async () => { | ||
| const results = await Promise.all( |
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.
needs some error handling around awaits
| ); | ||
| }, [items, persistentItemsVisibility]); | ||
|
|
||
| useEffect(() => { |
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.
useEffect with async code needs cleanup function
| i18nStrings?.dismissAriaLabel ?? i18n('dismissAriaLabel', deprecatedDismissAriaLabel) | ||
| ); | ||
|
|
||
| useEffect(() => { |
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.
useEffect with async code needs cleanup function
| } | ||
| } | ||
|
|
||
| // eslint-disable-next-line require-await |
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.
[minor] you could probably avoid these with return await Promise.resolve();?
| retrieveAlertDismiss?: (persistenceConfig: AlertProps.PersistenceConfig) => Promise<boolean>; | ||
| } | ||
|
|
||
| export function setPersistenceFunctionsForTesting(functions: PersistenceFunction) { |
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.
why not just use mocking?
| } | ||
|
|
||
| // Hook for managing flashbar items visibility with persistence | ||
| export function useFlashbarVisibility(items: ReadonlyArray<FlashbarProps.MessageDefinition>) { |
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.
could we move the complexity of this into the plugin rather than in the component itself? so just have a single call to retrieveFlashbarDismiss(items) which then internally handles which ones need to be fetched and which not?
Description
Add code to support Persistence feature in Flashbar and Alert [qIQZAtdAL9Xj].
The home of core function of Persistence is CR-199098474.
Related links, issue #, if available: n/a
How has this been tested?
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md.CONTRIBUTING.md.Security
checkSafeUrlfunction.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.