Skip to content

Commit

Permalink
Update Nav OffCanvas Editor to use clientids tree (#46541)
Browse files Browse the repository at this point in the history
* Navigation: Pass a tree of client ids instead of an array of blocks.

Co-authored-by: Daniel Richards <677833+talldan@users.noreply.github.com>

* Explain passing custom clientIDs

Co-authored-by: Ben Dwyer <ben@bens-laptop.home>
Co-authored-by: Daniel Richards <677833+talldan@users.noreply.github.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
  • Loading branch information
4 people authored and dmsnell committed Dec 15, 2022
1 parent 9837a0d commit ccf6e2b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function ListViewBlock( {

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

const isEditable = block.name !== 'core/page-list-item';
const isEditable = blockName !== 'core/page-list-item';
const hasSiblings = siblingBlockCount > 0;
const hasRenderedMovers = showBlockMovers && hasSiblings;
const moverCellClassName = classnames(
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,13 @@ function Navigation( {
return (
<TagName { ...blockProps }>
<MenuInspectorControls
clientId={ clientId }
createNavigationMenuIsSuccess={
createNavigationMenuIsSuccess
}
createNavigationMenuIsError={ createNavigationMenuIsError }
currentMenuId={ ref }
isNavigationMenuMissing={ isNavigationMenuMissing }
innerBlocks={ innerBlocks }
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
onCreateNew={ createUntitledEmptyNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
Expand Down Expand Up @@ -759,12 +759,12 @@ function Navigation( {
return (
<TagName { ...blockProps }>
<MenuInspectorControls
clientId={ clientId }
createNavigationMenuIsSuccess={
createNavigationMenuIsSuccess
}
createNavigationMenuIsError={ createNavigationMenuIsError }
isNavigationMenuMissing={ isNavigationMenuMissing }
innerBlocks={ innerBlocks }
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
onCreateNew={ createUntitledEmptyNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
Expand Down Expand Up @@ -832,13 +832,13 @@ function Navigation( {
<EntityProvider kind="postType" type="wp_navigation" id={ ref }>
<RecursionProvider uniqueId={ recursionId }>
<MenuInspectorControls
clientId={ clientId }
createNavigationMenuIsSuccess={
createNavigationMenuIsSuccess
}
createNavigationMenuIsError={ createNavigationMenuIsError }
currentMenuId={ ref }
isNavigationMenuMissing={ isNavigationMenuMissing }
innerBlocks={ innerBlocks }
isManageMenusButtonDisabled={ isManageMenusButtonDisabled }
onCreateNew={ createUntitledEmptyNavigationMenu }
onSelectClassicMenu={ onSelectClassicMenu }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import {
__experimentalOffCanvasEditor as OffCanvasEditor,
InspectorControls,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { PanelBody, VisuallyHidden } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

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

const MenuInspectorControls = ( {
clientId,
createNavigationMenuIsSuccess,
createNavigationMenuIsError,
currentMenuId = null,
innerBlocks,
isManageMenusButtonDisabled,
onCreateNew,
onSelectClassicMenu,
Expand All @@ -32,6 +34,16 @@ const MenuInspectorControls = ( {
/* translators: %s: The name of a menu. */
const actionLabel = __( "Switch to '%s'" );

// 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(
( select ) => {
const { __unstableGetClientIdsTree } = select( blockEditorStore );
return __unstableGetClientIdsTree( clientId );
},
[ clientId ]
);

return (
<InspectorControls __experimentalGroup={ menuControlsSlot }>
<PanelBody
Expand Down Expand Up @@ -60,7 +72,7 @@ const MenuInspectorControls = ( {
/>
{ isOffCanvasNavigationEditorEnabled ? (
<OffCanvasEditor
blocks={ innerBlocks }
blocks={ clientIdsTree }
isExpanded={ true }
selectBlockInCanvas={ false }
/>
Expand Down

0 comments on commit ccf6e2b

Please sign in to comment.