Skip to content

Commit ccf6e2b

Browse files
scruffianBen Dwyertalldangetdave
authored andcommitted
Update Nav OffCanvas Editor to use clientids tree (#46541)
* Navigation: Pass a tree of client ids instead of an array of blocks. Co-authored-by: Daniel Richards <[email protected]> * Explain passing custom clientIDs Co-authored-by: Ben Dwyer <[email protected]> Co-authored-by: Daniel Richards <[email protected]> Co-authored-by: Dave Smith <[email protected]>
1 parent 9837a0d commit ccf6e2b

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

packages/block-editor/src/components/off-canvas-editor/block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function ListViewBlock( {
145145

146146
const { isTreeGridMounted, expand, collapse } = useListViewContext();
147147

148-
const isEditable = block.name !== 'core/page-list-item';
148+
const isEditable = blockName !== 'core/page-list-item';
149149
const hasSiblings = siblingBlockCount > 0;
150150
const hasRenderedMovers = showBlockMovers && hasSiblings;
151151
const moverCellClassName = classnames(

packages/block-library/src/navigation/edit/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,13 @@ function Navigation( {
717717
return (
718718
<TagName { ...blockProps }>
719719
<MenuInspectorControls
720+
clientId={ clientId }
720721
createNavigationMenuIsSuccess={
721722
createNavigationMenuIsSuccess
722723
}
723724
createNavigationMenuIsError={ createNavigationMenuIsError }
724725
currentMenuId={ ref }
725726
isNavigationMenuMissing={ isNavigationMenuMissing }
726-
innerBlocks={ innerBlocks }
727727
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
728728
onCreateNew={ createUntitledEmptyNavigationMenu }
729729
onSelectClassicMenu={ onSelectClassicMenu }
@@ -759,12 +759,12 @@ function Navigation( {
759759
return (
760760
<TagName { ...blockProps }>
761761
<MenuInspectorControls
762+
clientId={ clientId }
762763
createNavigationMenuIsSuccess={
763764
createNavigationMenuIsSuccess
764765
}
765766
createNavigationMenuIsError={ createNavigationMenuIsError }
766767
isNavigationMenuMissing={ isNavigationMenuMissing }
767-
innerBlocks={ innerBlocks }
768768
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
769769
onCreateNew={ createUntitledEmptyNavigationMenu }
770770
onSelectClassicMenu={ onSelectClassicMenu }
@@ -832,13 +832,13 @@ function Navigation( {
832832
<EntityProvider kind="postType" type="wp_navigation" id={ ref }>
833833
<RecursionProvider uniqueId={ recursionId }>
834834
<MenuInspectorControls
835+
clientId={ clientId }
835836
createNavigationMenuIsSuccess={
836837
createNavigationMenuIsSuccess
837838
}
838839
createNavigationMenuIsError={ createNavigationMenuIsError }
839840
currentMenuId={ ref }
840841
isNavigationMenuMissing={ isNavigationMenuMissing }
841-
innerBlocks={ innerBlocks }
842842
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
843843
onCreateNew={ createUntitledEmptyNavigationMenu }
844844
onSelectClassicMenu={ onSelectClassicMenu }

packages/block-library/src/navigation/edit/menu-inspector-controls.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import {
55
__experimentalOffCanvasEditor as OffCanvasEditor,
66
InspectorControls,
7+
store as blockEditorStore,
78
} from '@wordpress/block-editor';
89
import { PanelBody, VisuallyHidden } from '@wordpress/components';
10+
import { useSelect } from '@wordpress/data';
911
import { __ } from '@wordpress/i18n';
1012

1113
/**
@@ -15,10 +17,10 @@ import ManageMenusButton from './manage-menus-button';
1517
import NavigationMenuSelector from './navigation-menu-selector';
1618

1719
const MenuInspectorControls = ( {
20+
clientId,
1821
createNavigationMenuIsSuccess,
1922
createNavigationMenuIsError,
2023
currentMenuId = null,
21-
innerBlocks,
2224
isManageMenusButtonDisabled,
2325
onCreateNew,
2426
onSelectClassicMenu,
@@ -32,6 +34,16 @@ const MenuInspectorControls = ( {
3234
/* translators: %s: The name of a menu. */
3335
const actionLabel = __( "Switch to '%s'" );
3436

37+
// Provide a hierarchy of clientIds for the given Navigation block (clientId).
38+
// This is required else the list view will display the entire block tree.
39+
const clientIdsTree = useSelect(
40+
( select ) => {
41+
const { __unstableGetClientIdsTree } = select( blockEditorStore );
42+
return __unstableGetClientIdsTree( clientId );
43+
},
44+
[ clientId ]
45+
);
46+
3547
return (
3648
<InspectorControls __experimentalGroup={ menuControlsSlot }>
3749
<PanelBody
@@ -60,7 +72,7 @@ const MenuInspectorControls = ( {
6072
/>
6173
{ isOffCanvasNavigationEditorEnabled ? (
6274
<OffCanvasEditor
63-
blocks={ innerBlocks }
75+
blocks={ clientIdsTree }
6476
isExpanded={ true }
6577
selectBlockInCanvas={ false }
6678
/>

0 commit comments

Comments
 (0)