Skip to content

Commit

Permalink
Extract unrelated submenus concept from hook
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jul 27, 2022
1 parent f2f6d8a commit af8bbe9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,13 @@ function Navigation( {
hasUncontrolledInnerBlocks,
uncontrolledInnerBlocks,
isInnerBlockSelected,
hasSubmenus,
innerBlocks,
} = useInnerBlocks( clientId );

const hasSubmenus = !! innerBlocks.find(
( block ) => block.name === 'core/navigation-submenu'
);

const {
replaceInnerBlocks,
selectBlock,
Expand Down
10 changes: 4 additions & 6 deletions packages/block-library/src/navigation/edit/use-inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ export function useInnerBlocks( clientId ) {
// introduce a selector like `getUncontrolledInnerBlocks`, just in
// case `getBlock` is fixed.
const _uncontrolledInnerBlocks = getBlock( clientId ).innerBlocks;

const _hasUncontrolledInnerBlocks =
!! _uncontrolledInnerBlocks?.length;
const _controlledInnerBlocks = _hasUncontrolledInnerBlocks
? EMPTY_ARRAY
: getBlocks( clientId );
const innerBlocks = _hasUncontrolledInnerBlocks
? _uncontrolledInnerBlocks
: _controlledInnerBlocks;

return {
hasSubmenus: !! innerBlocks.find(
( block ) => block.name === 'core/navigation-submenu'
),
innerBlocks: _hasUncontrolledInnerBlocks
? _uncontrolledInnerBlocks
: _controlledInnerBlocks,
hasUncontrolledInnerBlocks: _hasUncontrolledInnerBlocks,
uncontrolledInnerBlocks: _uncontrolledInnerBlocks,
controlledInnerBlocks: _controlledInnerBlocks,
Expand Down

0 comments on commit af8bbe9

Please sign in to comment.