From 9bc763e0494cccbd4326757cb665c84a9947baaa Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 12 Jun 2023 16:22:07 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Add=20=E2=80=9CDraft=E2=80=9D=20in=20bracke?= =?UTF-8?q?ts=20after=20menu=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edit/navigation-menu-selector.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/navigation/edit/navigation-menu-selector.js b/packages/block-library/src/navigation/edit/navigation-menu-selector.js index a7458fd3011654..664e88a4c6af09 100644 --- a/packages/block-library/src/navigation/edit/navigation-menu-selector.js +++ b/packages/block-library/src/navigation/edit/navigation-menu-selector.js @@ -19,12 +19,18 @@ import { useEntityProp } from '@wordpress/core-data'; import useNavigationMenu from '../use-navigation-menu'; import useNavigationEntities from '../use-navigation-entities'; -function buildMenuLabel( title, id ) { - const label = - decodeEntities( title?.rendered ) || +function buildMenuLabel( title, id, status ) { + if ( ! title?.rendered ) { /* translators: %s is the index of the menu in the list of menus. */ - sprintf( __( '(no title %s)' ), id ); - return label; + return sprintf( __( '(no title %s)' ), id ); + } + + if ( status === 'draft' ) { + /* translators: %s is the title of the menu. */ + return sprintf( __( '%s (draft)' ), decodeEntities( title?.rendered ) ); + } + + return decodeEntities( title?.rendered ); } function NavigationMenuSelector( { @@ -61,8 +67,8 @@ function NavigationMenuSelector( { const menuChoices = useMemo( () => { return ( - navigationMenus?.map( ( { id, title }, index ) => { - const label = buildMenuLabel( title, index + 1 ); + navigationMenus?.map( ( { id, title, status }, index ) => { + const label = buildMenuLabel( title, index + 1, status ); return { value: id, From f32bb68072ec48cd5008c371e175148bb81f214e Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 12 Jun 2023 16:29:57 +0100 Subject: [PATCH 2/3] Allow all statuses dynamically --- .../src/navigation/edit/navigation-menu-selector.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/navigation/edit/navigation-menu-selector.js b/packages/block-library/src/navigation/edit/navigation-menu-selector.js index 664e88a4c6af09..c6ee43aaa67aa3 100644 --- a/packages/block-library/src/navigation/edit/navigation-menu-selector.js +++ b/packages/block-library/src/navigation/edit/navigation-menu-selector.js @@ -25,12 +25,15 @@ function buildMenuLabel( title, id, status ) { return sprintf( __( '(no title %s)' ), id ); } - if ( status === 'draft' ) { - /* translators: %s is the title of the menu. */ - return sprintf( __( '%s (draft)' ), decodeEntities( title?.rendered ) ); + if ( status === 'publish' ) { + return decodeEntities( title?.rendered ); } - return decodeEntities( title?.rendered ); + // translators: %1s: title of the menu; %2s: status of the menu (draft, pending, etc.). + return sprintf( __( '%1$s (%2$s)' ), [ + decodeEntities( title?.rendered ), + status, + ] ); } function NavigationMenuSelector( { From 0812e7db9af26d62863b71dcf460f972468b4ca1 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 12 Jun 2023 16:32:10 +0100 Subject: [PATCH 3/3] Allow all statuses --- .../src/navigation/edit/navigation-menu-selector.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/navigation/edit/navigation-menu-selector.js b/packages/block-library/src/navigation/edit/navigation-menu-selector.js index c6ee43aaa67aa3..eebd3987b9b425 100644 --- a/packages/block-library/src/navigation/edit/navigation-menu-selector.js +++ b/packages/block-library/src/navigation/edit/navigation-menu-selector.js @@ -29,11 +29,12 @@ function buildMenuLabel( title, id, status ) { return decodeEntities( title?.rendered ); } - // translators: %1s: title of the menu; %2s: status of the menu (draft, pending, etc.). - return sprintf( __( '%1$s (%2$s)' ), [ + return sprintf( + // translators: %1s: title of the menu; %2s: status of the menu (draft, pending, etc.). + __( '%1$s (%2$s)' ), decodeEntities( title?.rendered ), - status, - ] ); + status + ); } function NavigationMenuSelector( {