-
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
Navigation: Add an experimental label #54946
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: +1.28 kB (0%) Total Size: 1.65 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.
return buildNavigationLabel( | ||
navigationMenu?.title, | ||
1, // This has to be 1 because in this context there is only one Navigation shown. | ||
navigationMenu?.status | ||
); |
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.
Given this function signature is a little opaque (especially the 2nd argument) I wonder whether it's better just to pass the entire navigationMenu and have the function grab the bit it needs.
I feel perhaps the consumer needs to know too much.
What do you think?
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.
Just passing the entire thing won't be enough, as we still need to know the index. We could ditch the third argument though.
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.
In that case maybe make the function accept an object with named arguments? It might be easier to understand.
Not a blocker though. Just a code quality idea.
Flaky tests detected in 546f365. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6419324118
|
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
546f365
to
47f2d01
Compare
@@ -72,7 +55,7 @@ function NavigationMenuSelector( { | |||
const menuChoices = useMemo( () => { | |||
return ( | |||
navigationMenus?.map( ( { id, title, status }, index ) => { | |||
const label = buildMenuLabel( | |||
const label = buildNavigationLabel( |
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 destructuring of the navigationMenu object in here means we need to make more changes to the code to pass the whole object. I'm not sure it's worth it. By only passing the properties we need we keep the function clearer and less susceptible to side effects.
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 there could be a danger of consuming a hook inside what is basically a util function. I saw a order of hooks error when inserting a Nav into a Post:
It might be you'll need to handle this more like we do for reusable blocks:
packages/block-editor/src/components/block-title/use-block-display-title.js
But that's hardcoding WP specific blocks into the block editor which isn't great. So we'd need a way to abstract the concept.
} | ||
|
||
if ( status === 'publish' ) { | ||
return decodeEntities( title ); |
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: can we do decodeEntities( title )
once before the if ( status === 'publish' ) {
. That way we don't have any chance of refactoring loosing the decoding.
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 haven't tested this but the code looks good. Any hold backs appart from the mentioned required PR which landed in the mean time?
import { __, sprintf } from '@wordpress/i18n'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
|
||
function buildNavigationLabel( title, id, status ) { |
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.
let's add a docblock to this function?
Yes, this feature crashes the editor - just insert a navigation block and you'll see it - because of the order of hooks issue. What I thought would be a quick fix ended up being far from simple :) |
What?
This PR requires #54426.
This adds a label to the list view is the name of the navigation in the database.
Why?
This will make the connection between the block and the data within the block clearer.
How?
Add an __experimentalLabel function to the Navigation block, and reuse the buildNavigationLabel function do display the name of the navigation in the list view.
Testing Instructions
Screenshots or screencast