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: Fix ListView deprecation notice #51094

Merged
merged 2 commits into from
Jun 8, 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 @@ -32,6 +32,7 @@ const BLOCKS_WITH_LINK_UI_SUPPORT = [
'core/navigation-link',
'core/navigation-submenu',
];
const { PrivateListView } = unlock( blockEditorPrivateApis );
Copy link
Member Author

Choose a reason for hiding this comment

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

A minor code quality change.


function AdditionalBlockContent( { block, insertedBlock, setInsertedBlock } ) {
const { updateBlockAttributes } = useDispatch( blockEditorStore );
Expand Down Expand Up @@ -82,14 +83,9 @@ const MainContent = ( {
isNavigationMenuMissing,
onCreateNew,
} ) => {
const { PrivateListView } = unlock( blockEditorPrivateApis );

// Provide a hierarchy of clientIds for the given Navigation block (clientId).
// This is required else the list view will display the entire block tree.
const clientIdsTree = useSelect(
const hasChildren = useSelect(
( select ) => {
const { __unstableGetClientIdsTree } = select( blockEditorStore );
return __unstableGetClientIdsTree( clientId );
return !! select( blockEditorStore ).getBlockCount( clientId );
Copy link
Member Author

Choose a reason for hiding this comment

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

The component doesn't need a whole tree for the hasChildren check.

},
[ clientId ]
);
Expand All @@ -116,13 +112,12 @@ const MainContent = ( {

return (
<div className="wp-block-navigation__menu-inspector-controls">
{ clientIdsTree.length === 0 && (
{ ! hasChildren && (
<p className="wp-block-navigation__menu-inspector-controls__empty-message">
{ __( 'This navigation menu is empty.' ) }
</p>
) }
<PrivateListView
blocks={ clientIdsTree }
rootClientId={ clientId }
isExpanded
description={ description }
Expand Down