From 029d2964d950271e261a0aba97de7d6fe4df9280 Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Mon, 10 Oct 2022 22:28:48 +0300 Subject: [PATCH] [Block Settings]: Show `move to` on nested blocks when only one root block (#44827) * [Block Settings]: Show `move to` on nested blocks when only one root block * use `getBlockRootClientId` --- .../block-settings-dropdown.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js index 2076b4bb49091d..df2111da3b33e4 100644 --- a/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js +++ b/packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js @@ -74,7 +74,7 @@ export function BlockSettingsDropdown( { const { getBlockCount, getBlockName, - getBlockParents, + getBlockRootClientId, getPreviousBlockClientId, getNextBlockClientId, getSelectedBlockClientIds, @@ -84,19 +84,22 @@ export function BlockSettingsDropdown( { const { getActiveBlockVariation } = select( blocksStore ); - const parents = getBlockParents( firstBlockClientId ); - const _firstParentClientId = parents[ parents.length - 1 ]; - const parentBlockName = getBlockName( _firstParentClientId ); + const _firstParentClientId = + getBlockRootClientId( firstBlockClientId ); + const parentBlockName = + _firstParentClientId && getBlockName( _firstParentClientId ); return { firstParentClientId: _firstParentClientId, isDistractionFree: getSettings().isDistractionFree, - onlyBlock: 1 === getBlockCount(), + onlyBlock: 1 === getBlockCount( _firstParentClientId ), parentBlockType: - getActiveBlockVariation( + _firstParentClientId && + ( getActiveBlockVariation( parentBlockName, getBlockAttributes( _firstParentClientId ) - ) || getBlockType( parentBlockName ), + ) || + getBlockType( parentBlockName ) ), previousBlockClientId: getPreviousBlockClientId( firstBlockClientId ), nextBlockClientId: getNextBlockClientId( firstBlockClientId ), @@ -221,7 +224,7 @@ export function BlockSettingsDropdown( { <__unstableBlockSettingsMenuFirstItem.Slot fillProps={ { onClose } } /> - { firstParentClientId !== undefined && ( + { !! firstParentClientId && (