-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Extract the manage menus button to a shared component to reduce duplicate code #45769
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
Size Change: +12 B (0%) Total Size: 1.29 MB
ℹ️ View Unchanged
|
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.
Looking good. Small refactors will help avoid bugs 👏 Thank you.
const ManageMenusButton = ( { buttonClassName = '' } ) => ( | ||
<Button | ||
variant="link" | ||
disabled={ ! hasManagePermissions || ! hasResolvedNavigationMenus } |
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.
These could be provided as props. This would make the component more isolated from it's environment and make it easier to extract to a separate file in future.
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 agree here. Let's move ManageMenusButton
outside the Navigation
component and accept disabled
as a prop.
There's no need to recreate React component on every rerender.
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.
Done here: #45782
8cb9463
to
e27ca92
Compare
What?
This refactors the manage menus button to a shared component.
Why?
This code is reused many times, so we should only have one copy of it.
How?
Extracts this button to a functional component so it can be reused.
Testing Instructions
Check that the manage menus button still appears in the same place with the off canvas editing experiment enabled/disabled.
Screenshots or screencast
Experiment disabled:
Experiment enabled: