Skip to content

Commit

Permalink
Site Editor: Do not display 'trashed' navigation menus in Sidebar (#5…
Browse files Browse the repository at this point in the history
…5072)

* Site Editor: Do not display 'trashed' navigation menus in Sidebar

* Extract selector into a hook

Co-authored-by: Aaron Robertshaw <[email protected]>

---------

Co-authored-by: Aaron Robertshaw <[email protected]>
  • Loading branch information
2 people authored and mikachan committed Oct 5, 2023
1 parent 0c89d7e commit d0630d0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
/**
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import SidebarNavigationItem from '../sidebar-navigation-item';
import useNavigationMenuTitle from './use-navigation-menu-title';
import { useLink } from '../routes/link';
import { NAVIGATION_POST_TYPE } from '../../utils/constants';

export default function TemplatePartNavigationMenuListItem( { id } ) {
const [ title ] = useEntityProp(
'postType',
NAVIGATION_POST_TYPE,
'title',
id
);
const title = useNavigationMenuTitle( id );

const linkInfo = useLink( {
postId: id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
*/
import { __ } from '@wordpress/i18n';
import { __experimentalHeading as Heading } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import NavigationMenuEditor from '../sidebar-navigation-screen-navigation-menu/navigation-menu-editor';
import { NAVIGATION_POST_TYPE } from '../../utils/constants';
import useNavigationMenuTitle from './use-navigation-menu-title';

export default function TemplatePartNavigationMenu( { id } ) {
const [ title ] = useEntityProp(
'postType',
NAVIGATION_POST_TYPE,
'title',
id
);
const title = useNavigationMenuTitle( id );

if ( ! id || title === undefined ) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import { NAVIGATION_POST_TYPE } from '../../utils/constants';

export default function useNavigationMenuTitle( id ) {
return useSelect(
( select ) => {
if ( ! id ) {
return undefined;
}

const editedRecord = select( coreStore ).getEditedEntityRecord(
'postType',
NAVIGATION_POST_TYPE,
id
);

// Do not display a 'trashed' navigation menu.
return editedRecord.status === 'trash'
? undefined
: editedRecord.title;
},
[ id ]
);
}

0 comments on commit d0630d0

Please sign in to comment.