Skip to content
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

Indicate Draft status of menus in Nav block menu selector #51427

Merged
merged 3 commits into from
Jun 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ 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 === '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
);
}

function NavigationMenuSelector( {
Expand Down Expand Up @@ -61,8 +71,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,
Expand Down