-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigation block - minor refactor to classic menu conversion code #43081
Conversation
Size Change: -35 B (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
…the convertClassicMenu function
729d5d5
to
8a015b1
Compare
onSelectClassicMenu={ ( classicMenu ) => { | ||
convert( classicMenu.id, classicMenu.name ); | ||
setShouldFocusNavigationSelector( true ); | ||
onSelectClassicMenu={ async ( classicMenu ) => { |
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.
Would it be worth extracting this to a shared method since it is the same as the above event handler?
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.
Thanks for reviewing. The final code is different in #42956, where there will be an extra line in one of the callbacks.
Extracting to another function is still possible, but I'm not sure it's worth it for only a few lines. I personally prefer the improved readability gained by not having to scroll to the definition.
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.
Worked as advertised for me. Was able to:
✅ Add a Navigation block and from the block toolbar, use the 'Select menu' dropdown to select a classic menu and the classic menu was created.
✅ Use the toolbar's 'Select menu' dropdown again and click 'Create new menu'
then from the placeholder use the 'Select menu' dropdown and select a classic menu and it was created.
What?
Originally part of #42956, split into a seperate PR as requested
This updates the
convert
function that's returned from theuseConvertClassicToBlockMenu
hook so that it returns a promise that resolves to the createdwp_navigation
menu.Why?
Previously, the code used an effect to handle the result of classic menu conversion.
This posed a problem for the changes in #42956. In my PR, I need to handle the outcome differently depending on whether the user converted a menu from the placeholder or whether they converted a menu from the block toolbar. The former calls
selectBlock
as it does intrunk
, but the latter doesn't (as doing so causes a focus loss).With the effect, there was no way to determine the source of the conversion. In this PR the code can
await
the menu conversion and then either select the block or not in the event handler.Testing Instructions
(Before testing, ensure you have some classic menus)