Skip to content

Commit

Permalink
Refactor: enhance __experimentalLabel logic to handle end cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Jan 10, 2025
1 parent 1706ef7 commit 68dee39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
28 changes: 17 additions & 11 deletions packages/block-library/src/navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export const settings = {
},
edit,
save,
__experimentalLabel: ( { ref } ) => {
if ( ! ref ) {
return __( 'Navigation' );
__experimentalLabel: ( { ref }, { context } ) => {
if ( ! ref || context !== 'list-view' ) {
return;
}

const navigation = select( coreStore ).getEditedEntityRecord(
Expand All @@ -66,14 +66,20 @@ export const settings = {
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' );
if ( ! navigation?.title ) {
return;
}

if ( navigation.title === metadata.title ) {
return;
}

return sprintf(
// translators: %1$s: block title, %2$s: navigation title.
__( '%1$s (%2$s)' ),
metadata.title,
decodeEntities( navigation.title )
);
},
deprecated,
};
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/specs/site-editor/navigation-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ test.describe( 'Editing Navigation Menus', () => {
canvas: 'edit',
} );

// Wait for the toggle to be visible.
await expect(
page.locator(
'.editor-document-tools__document-overview-toggle'
)
page.getByRole( 'button', { name: 'Document Overview' } )
).toBeVisible();

// Open List View.
Expand Down

0 comments on commit 68dee39

Please sign in to comment.