From 8632a1b785e7e119686bffef97f69658ed175aee Mon Sep 17 00:00:00 2001 From: scruffian Date: Tue, 27 Jun 2023 10:51:56 +0100 Subject: [PATCH 1/2] Navigation: Add the draft status to the navigation title --- .../index.js | 7 +++++- .../single-navigation-menu.js | 7 +++++- .../build-navigation-label.js | 24 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/build-navigation-label.js diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js index 6bce0f356f7400..bc0b879bc62b0a 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js @@ -17,6 +17,7 @@ import { SidebarNavigationScreenWrapper } from '../sidebar-navigation-screen-nav import ScreenNavigationMoreMenu from './more-menu'; import SingleNavigationMenu from './single-navigation-menu'; import useNavigationMenuHandlers from './use-navigation-menu-handlers'; +import { buildNavigationLabel } from '../sidebar-navigation-screen-navigation-menus/build-navigation-label'; export const postType = `wp_navigation`; @@ -94,7 +95,11 @@ export default function SidebarNavigationScreenNavigationMenu() { onDuplicate={ _handleDuplicate } /> } - title={ decodeEntities( menuTitle ) } + title={ buildNavigationLabel( + navigationMenu?.title, + navigationMenu?.id, + navigationMenu?.status + ) } description={ __( 'This Navigation Menu is empty.' ) } /> ); diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js index 6351c83323f98f..1d7202becbf2fe 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js @@ -9,6 +9,7 @@ import { decodeEntities } from '@wordpress/html-entities'; import { SidebarNavigationScreenWrapper } from '../sidebar-navigation-screen-navigation-menus'; import ScreenNavigationMoreMenu from './more-menu'; import NavigationMenuEditor from './navigation-menu-editor'; +import { buildNavigationLabel } from '../sidebar-navigation-screen-navigation-menus/build-navigation-label'; export default function SingleNavigationMenu( { navigationMenu, @@ -28,7 +29,11 @@ export default function SingleNavigationMenu( { onDuplicate={ handleDuplicate } /> } - title={ decodeEntities( menuTitle ) } + title={ buildNavigationLabel( + navigationMenu?.title, + navigationMenu?.id, + navigationMenu?.status + ) } description={ __( 'Navigation menus are a curated collection of blocks that allow visitors to get around your site.' ) } diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/build-navigation-label.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/build-navigation-label.js new file mode 100644 index 00000000000000..a4b656896d44fa --- /dev/null +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/build-navigation-label.js @@ -0,0 +1,24 @@ +/** + * WordPress dependencies + */ +import { __, sprintf } from '@wordpress/i18n'; +import { decodeEntities } from '@wordpress/html-entities'; + +// Copied from packages/block-library/src/navigation/edit/navigation-menu-selector.js. +export function buildNavigationLabel( title, id, status ) { + if ( ! title?.rendered ) { + /* translators: %s is the index of the menu in the list of menus. */ + return sprintf( __( '(no title %s)' ), id ); + } + + if ( status === 'publish' ) { + return decodeEntities( title?.rendered ); + } + + return sprintf( + // translators: %1s: title of the menu; %2s: status of the menu (draft, pending, etc.). + __( '%1$s (%2$s)' ), + decodeEntities( title?.rendered ), + status + ); +} From d04f4c3a24f5bb0bcf838e159d15d563385289ab Mon Sep 17 00:00:00 2001 From: scruffian Date: Wed, 28 Jun 2023 12:29:11 +0100 Subject: [PATCH 2/2] Move the buildNavigationLabel function to the default export --- .../sidebar-navigation-screen-navigation-menu/index.js | 2 +- .../single-navigation-menu.js | 2 +- .../build-navigation-label.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js index bc0b879bc62b0a..22beaa3571fedf 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js @@ -17,7 +17,7 @@ import { SidebarNavigationScreenWrapper } from '../sidebar-navigation-screen-nav import ScreenNavigationMoreMenu from './more-menu'; import SingleNavigationMenu from './single-navigation-menu'; import useNavigationMenuHandlers from './use-navigation-menu-handlers'; -import { buildNavigationLabel } from '../sidebar-navigation-screen-navigation-menus/build-navigation-label'; +import buildNavigationLabel from '../sidebar-navigation-screen-navigation-menus/build-navigation-label'; export const postType = `wp_navigation`; diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js index 1d7202becbf2fe..d988308b167135 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js @@ -9,7 +9,7 @@ import { decodeEntities } from '@wordpress/html-entities'; import { SidebarNavigationScreenWrapper } from '../sidebar-navigation-screen-navigation-menus'; import ScreenNavigationMoreMenu from './more-menu'; import NavigationMenuEditor from './navigation-menu-editor'; -import { buildNavigationLabel } from '../sidebar-navigation-screen-navigation-menus/build-navigation-label'; +import buildNavigationLabel from '../sidebar-navigation-screen-navigation-menus/build-navigation-label'; export default function SingleNavigationMenu( { navigationMenu, diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/build-navigation-label.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/build-navigation-label.js index a4b656896d44fa..d5e5ff02c63bfd 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/build-navigation-label.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/build-navigation-label.js @@ -5,7 +5,7 @@ import { __, sprintf } from '@wordpress/i18n'; import { decodeEntities } from '@wordpress/html-entities'; // Copied from packages/block-library/src/navigation/edit/navigation-menu-selector.js. -export function buildNavigationLabel( title, id, status ) { +export default function buildNavigationLabel( title, id, status ) { if ( ! title?.rendered ) { /* translators: %s is the index of the menu in the list of menus. */ return sprintf( __( '(no title %s)' ), id );