From dc76c9aa1e6ab53f75bdaa2ff94d285c49d0ff1f Mon Sep 17 00:00:00 2001 From: Yogesh Bhutkar Date: Mon, 13 Jan 2025 12:01:57 +0530 Subject: [PATCH] Navigation: Surface `menu name` in the `List View` next to the `Navigation block` (#68446) Co-authored-by: yogeshbhutkar Co-authored-by: fabiankaegy Co-authored-by: t-hamano Co-authored-by: Mamaduka --- .../block-library/src/navigation/index.js | 20 +++++++++++++++++++ .../blocks/navigation-list-view.spec.js | 5 ++++- .../site-editor/navigation-editor.spec.js | 6 +++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/navigation/index.js b/packages/block-library/src/navigation/index.js index d0405be794ffe..36156e5f45bba 100644 --- a/packages/block-library/src/navigation/index.js +++ b/packages/block-library/src/navigation/index.js @@ -3,6 +3,9 @@ */ import { __ } 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,23 @@ export const settings = { }, edit, save, + __experimentalLabel: ( { ref } ) => { + if ( ! ref ) { + return; + } + + const navigation = select( coreStore ).getEditedEntityRecord( + 'postType', + 'wp_navigation', + ref + ); + + if ( ! navigation?.title ) { + return; + } + + return decodeEntities( navigation.title ); + }, deprecated, }; diff --git a/test/e2e/specs/editor/blocks/navigation-list-view.spec.js b/test/e2e/specs/editor/blocks/navigation-list-view.spec.js index 2f9963169a523..47313590f6579 100644 --- a/test/e2e/specs/editor/blocks/navigation-list-view.spec.js +++ b/test/e2e/specs/editor/blocks/navigation-list-view.spec.js @@ -555,7 +555,10 @@ test.describe( 'Navigation block - List view editing', () => { await editor.openDocumentSettingsSidebar(); - await page.getByLabel( 'Test Menu' ).click(); + await page + .getByRole( 'tabpanel' ) + .getByRole( 'button', { name: 'Test Menu' } ) + .click(); await page.keyboard.press( 'ArrowUp' ); diff --git a/test/e2e/specs/site-editor/navigation-editor.spec.js b/test/e2e/specs/site-editor/navigation-editor.spec.js index 64a80e814d629..2ceaea06ec2d4 100644 --- a/test/e2e/specs/site-editor/navigation-editor.spec.js +++ b/test/e2e/specs/site-editor/navigation-editor.spec.js @@ -40,6 +40,10 @@ test.describe( 'Editing Navigation Menus', () => { canvas: 'edit', } ); + await expect( + page.getByRole( 'button', { name: 'Document Overview' } ) + ).toBeVisible(); + // Open List View. await pageUtils.pressKeys( 'access+o' ); @@ -54,7 +58,7 @@ test.describe( 'Editing Navigation Menus', () => { await expect( listView ).toBeVisible(); const navBlockNode = listView.getByRole( 'link', { - name: 'Navigation', + name: 'Primary Menu', exact: true, } );