From 7d39becce9a69ea0d4ce15540c56a664522c6ca3 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 17 Mar 2022 18:20:31 +0400 Subject: [PATCH] Blocks: Disable Grouping when block removal is locked (#39541) * Blocks: Disable Grouping when block removal is locked * Use selector in slot --- .../block-settings-menu-controls/index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/block-settings-menu-controls/index.js b/packages/block-editor/src/components/block-settings-menu-controls/index.js index 2702c675eefbe..5db8a69e91d23 100644 --- a/packages/block-editor/src/components/block-settings-menu-controls/index.js +++ b/packages/block-editor/src/components/block-settings-menu-controls/index.js @@ -26,11 +26,13 @@ import { store as blockEditorStore } from '../../store'; const { Fill, Slot } = createSlotFill( 'BlockSettingsMenuControls' ); const BlockSettingsMenuControlsSlot = ( { fillProps, clientIds = null } ) => { - const { selectedBlocks, selectedClientIds } = useSelect( + const { selectedBlocks, selectedClientIds, canRemove } = useSelect( ( select ) => { - const { getBlocksByClientId, getSelectedBlockClientIds } = select( - blockEditorStore - ); + const { + getBlocksByClientId, + getSelectedBlockClientIds, + canRemoveBlocks, + } = select( blockEditorStore ); const ids = clientIds !== null ? clientIds : getSelectedBlockClientIds(); return { @@ -39,6 +41,7 @@ const BlockSettingsMenuControlsSlot = ( { fillProps, clientIds = null } ) => { ( block ) => block.name ), selectedClientIds: ids, + canRemove: canRemoveBlocks( ids ), }; }, [ clientIds ] @@ -50,7 +53,8 @@ const BlockSettingsMenuControlsSlot = ( { fillProps, clientIds = null } ) => { // and pass this props down to ConvertToGroupButton. const convertToGroupButtonProps = useConvertToGroupButtonProps(); const { isGroupable, isUngroupable } = convertToGroupButtonProps; - const showConvertToGroupButton = isGroupable || isUngroupable; + const showConvertToGroupButton = + ( isGroupable || isUngroupable ) && canRemove; return (