-
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: Surface menu name
in the List View
next to the Navigation block
#68446
Open
yogeshbhutkar
wants to merge
9
commits into
WordPress:trunk
Choose a base branch
from
yogeshbhutkar:68177/add-navigation-block-label
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+26
−2
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
54b9364
Add menuTitle attribute to navigation block and update label display
yogeshbhutkar 9e5240d
Refactor: label updation logic to use refs
yogeshbhutkar 453a690
Update navigation title rendering to include block title and decode H…
yogeshbhutkar 1273df0
Refactor: use `getEditedEntityRecord` instead of `getEntityRecord`
yogeshbhutkar 1706ef7
Test Cases: Fix failing tests
yogeshbhutkar 68dee39
Refactor: enhance __experimentalLabel logic to handle end cases
yogeshbhutkar 77e23ec
Refactor: simplify navigation title check logic
yogeshbhutkar 9c254e4
Refactor: simplify navigation title rendering logic
yogeshbhutkar d7faa4a
Test case: fix failing tests
yogeshbhutkar 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 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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { navigation as icon } from '@wordpress/icons'; | ||
import { select } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -52,6 +55,26 @@ export const settings = { | |
}, | ||
edit, | ||
save, | ||
__experimentalLabel: ( { ref } ) => { | ||
if ( ! ref ) { | ||
return __( 'Navigation' ); | ||
} | ||
|
||
const navigation = select( coreStore ).getEditedEntityRecord( | ||
'postType', | ||
'wp_navigation', | ||
ref | ||
); | ||
|
||
return navigation?.title | ||
? sprintf( | ||
/* translators: %1$s: block title, %2$s: navigation menu title */ | ||
__( '%1$s (%2$s)' ), | ||
metadata.title, | ||
decodeEntities( navigation.title ) | ||
) | ||
: __( 'Navigation' ); | ||
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. Same here. Let's return |
||
}, | ||
deprecated, | ||
}; | ||
|
||
|
This file contains 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 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
Oops, something went wrong.
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.
The block title may have changed. Example code:
Should this possibility be considered?
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.
You can return
undefined
here. This will signal the block editor to display the block's default title.See the Template Part block for a similar example:
gutenberg/packages/block-library/src/template-part/index.js
Lines 31 to 33 in e746a95