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: Use getTitle to get the navigation title #52635

Closed
wants to merge 5 commits into from
Closed
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
@@ -1,8 +1,10 @@
/**
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -11,7 +13,20 @@ import SidebarNavigationItem from '../sidebar-navigation-item';
import { useLink } from '../routes/link';

export default function TemplatePartNavigationMenuListItem( { id } ) {
const [ title ] = useEntityProp( 'postType', 'wp_navigation', 'title', id );
const title = useSelect( ( select ) => {
const { getEditedEntityRecord } = select( coreStore );
const { __experimentalGetTemplateInfo: getTemplateInfo } =
select( editorStore );

const _record = getEditedEntityRecord(
'postType',
'wp_navigation',
id
);

const templateInfo = getTemplateInfo( _record );
return templateInfo?.title || __( '(no title)' );
} );
Comment on lines +16 to +29
Copy link
Member

Choose a reason for hiding this comment

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

Can we just use record?.title?.rendered || record?.title here? We can leave no title fallback outside of the mapSelect.

Using the selector getTemplateInfo meant for different entities can have unexpected results in the future.

P.S. The useSelect is missing a dependency here.


const linkInfo = useLink( {
postId: id,
Expand All @@ -22,7 +37,7 @@ export default function TemplatePartNavigationMenuListItem( { id } ) {

return (
<SidebarNavigationItem withChevron { ...linkInfo }>
{ title || __( '(no title)' ) }
{ title }
</SidebarNavigationItem>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TemplatePartNavigationMenuListItem from './template-part-navigation-menu-
export default function TemplatePartNavigationMenuList( { menus } ) {
return (
<ItemGroup className="edit-site-sidebar-navigation-screen-template-part-navigation-menu-list">
{ menus.map( ( menuId ) => (
{ [ ...new Set( menus ) ].map( ( menuId ) => (
Copy link
Member

@Mamaduka Mamaduka Jul 18, 2023

Choose a reason for hiding this comment

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

Is this change related to the title rendering fix?

If we need to ensure that menus are a unique set, then this probably has to be done higher in the tree, maybe in useNavigationMenuContent or getBlocksOfTypeFromBlocks?

Edit: I just saw the #52707. I think this can be removed here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I don't see a new for Set here unless I missed something...?

<TemplatePartNavigationMenuListItem
key={ menuId }
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
id={ menuId }
Expand Down