Skip to content

Commit

Permalink
Navigation: Fix ListView deprecation notice (WordPress#51094)
Browse files Browse the repository at this point in the history
* Navigation: Fix ListView deprecation notice

* Unlock component at the file level
  • Loading branch information
Mamaduka authored and sethrubenstein committed Jul 13, 2023
1 parent 4fcf6f2 commit 8b5f01b
Showing 1 changed file with 4 additions and 9 deletions.
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 );

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

0 comments on commit 8b5f01b

Please sign in to comment.