Repository navigation
[UIE-9533] -Hopeful fix: Race condition with Preferences overrides in PrimaryNav #13056
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e2d12d0
attempt to rule out any race condition
abailly-akamai 3718f79
Merge branch 'develop' into UIE-9533
abailly-akamai 4fe23b1
Merge branch 'develop' into UIE-9533
abailly-akamai eaa4cb9
comments
abailly-akamai 20ba753
code and fixes
abailly-akamai aa0a560
cleanup
abailly-akamai 71d3764
Merge branch 'develop' into UIE-9533
abailly-akamai d3b5cee
Added changeset: Race condition with Preferences overrides in PrimaryNav
abailly-akamai f1484fc
Merge branch 'develop' into UIE-9533
abailly-akamai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@linode/manager": Fixed | ||
| --- | ||
|
|
||
| Race condition with Preferences overrides in PrimaryNav ([#13056](https://github.com/linode/manager/pull/13056)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,7 @@ export const PrimaryNav = (props: PrimaryNavProps) => { | |
| const location = useLocation(); | ||
|
|
||
| const { data: accountSettings } = useAccountSettings(); | ||
|
|
||
| const isManaged = accountSettings?.managed ?? false; | ||
|
|
||
| const { isACLPEnabled } = useIsACLPEnabled(); | ||
|
|
@@ -114,16 +115,18 @@ export const PrimaryNav = (props: PrimaryNavProps) => { | |
| const { isIAMBeta, isIAMEnabled } = useIsIAMEnabled(); | ||
|
|
||
| const { | ||
| data: collapsedSideNavPreference, | ||
| data: preferences, | ||
| error: preferencesError, | ||
| isLoading: preferencesLoading, | ||
| } = usePreferences( | ||
| (preferences) => preferences?.collapsedSideNavProductFamilies | ||
| ); | ||
| } = usePreferences(); | ||
|
|
||
| const collapsedAccordions = collapsedSideNavPreference ?? [ | ||
| 1, 2, 3, 4, 5, 6, 7, | ||
| ]; // by default, we collapse all categories if no preference is set; | ||
| const collapsedSideNavPreference = | ||
| preferences?.collapsedSideNavProductFamilies; | ||
|
|
||
| const collapsedAccordions = React.useMemo( | ||
| () => collapsedSideNavPreference ?? [1, 2, 3, 4, 5, 6, 7], // by default, we collapse all categories if no preference is set; | ||
| [collapsedSideNavPreference] | ||
| ); | ||
|
|
||
| const { mutateAsync: updatePreferences } = useMutatePreferences(); | ||
|
|
||
|
|
@@ -337,22 +340,22 @@ export const PrimaryNav = (props: PrimaryNavProps) => { | |
| ] | ||
| ); | ||
|
|
||
| const accordionClicked = (index: number) => { | ||
| let updatedCollapsedAccordions: number[] = [1, 2, 3, 4, 5, 6, 7]; | ||
| if (collapsedAccordions.includes(index)) { | ||
| updatedCollapsedAccordions = collapsedAccordions.filter( | ||
| (accIndex) => accIndex !== index | ||
| ); | ||
| updatePreferences({ | ||
| collapsedSideNavProductFamilies: updatedCollapsedAccordions, | ||
| }); | ||
| } else { | ||
| updatedCollapsedAccordions = [...collapsedAccordions, index]; | ||
| const accordionClicked = React.useCallback( | ||
| (index: number) => { | ||
| let updatedCollapsedAccordions: number[]; | ||
|
abailly-akamai marked this conversation as resolved.
|
||
| if (collapsedAccordions.includes(index)) { | ||
| updatedCollapsedAccordions = collapsedAccordions.filter( | ||
| (accIndex) => accIndex !== index | ||
| ); | ||
| } else { | ||
| updatedCollapsedAccordions = [...collapsedAccordions, index]; | ||
| } | ||
| updatePreferences({ | ||
| collapsedSideNavProductFamilies: updatedCollapsedAccordions, | ||
| }); | ||
| } | ||
| }; | ||
| }, | ||
| [collapsedAccordions, updatePreferences] | ||
| ); | ||
|
|
||
| const checkOverflow = React.useCallback(() => { | ||
| if (navItemsRef.current && primaryNavRef.current) { | ||
|
|
@@ -404,10 +407,17 @@ export const PrimaryNav = (props: PrimaryNavProps) => { | |
| // When a user lands on a page and does not have any preference set, | ||
| // we want to expand the accordion that contains the active link for convenience and discoverability | ||
| React.useEffect(() => { | ||
| // Wait for preferences to load or if there's an error | ||
| if (preferencesLoading || preferencesError) { | ||
| return; | ||
| } | ||
|
|
||
| // Wait for preferences data to be available (not just the field, but the whole object) | ||
| if (!preferences) { | ||
| return; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual intended fix |
||
|
|
||
| // If user has already set collapsedSideNavProductFamilies preference, don't override it | ||
| if (collapsedSideNavPreference) { | ||
| return; | ||
| } | ||
|
|
@@ -424,13 +434,13 @@ export const PrimaryNav = (props: PrimaryNavProps) => { | |
| if (activeGroupIndex !== -1) { | ||
| accordionClicked(activeGroupIndex); | ||
| } | ||
|
|
||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [ | ||
| accordionClicked, | ||
| location.pathname, | ||
| location.search, | ||
| productFamilyLinkGroups, | ||
| collapsedSideNavPreference, | ||
| preferences, | ||
| preferencesLoading, | ||
| preferencesError, | ||
| ]); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ export const DevTools = (props: Props) => { | |
| }; | ||
|
|
||
| const handleGoToPreferences = () => { | ||
| window.location.assign('/profile/settings?preferenceEditor=true'); | ||
| window.location.assign('/profile/preferences?preferenceEditor=true'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. link was broken due to recent nav changes |
||
| }; | ||
|
|
||
| React.useEffect(() => { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
π how was that even working it's mocking an endpoint that doesn't exist