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

Navigation: Add the draft status to the navigation title #51967

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
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 @@ -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`;

Expand Down Expand Up @@ -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.' ) }
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,7 +29,11 @@ export default function SingleNavigationMenu( {
onDuplicate={ handleDuplicate }
/>
}
title={ decodeEntities( menuTitle ) }
title={ buildNavigationLabel(
navigationMenu?.title,
navigationMenu?.id,
navigationMenu?.status
Comment on lines +33 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to seem strange. It's like we should just pass the entire Post 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did wonder that too

) }
description={ __(
'Navigation menus are a curated collection of blocks that allow visitors to get around your site.'
) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tracked here #51446

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 );
}

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
);
}
Comment on lines +8 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for now but I wonder if in future we could define some of these defaults centrally in packages/core-data/src/entities.js and avoid having to repeat ourselves.