Skip to content

Commit

Permalink
Remove the lock icon block content only blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Apr 24, 2024
1 parent a9fbf74 commit 2a85977
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,31 @@ import { BlockRenameControl, useBlockRename } from '../block-rename';
const { Fill, Slot } = createSlotFill( 'BlockSettingsMenuControls' );

const BlockSettingsMenuControlsSlot = ( { fillProps, clientIds = null } ) => {
const { selectedBlocks, selectedClientIds } = useSelect(
const { selectedBlocks, selectedClientIds, isContentOnly } = useSelect(
( select ) => {
const { getBlockNamesByClientId, getSelectedBlockClientIds } =
select( blockEditorStore );
const {
getBlockNamesByClientId,
getSelectedBlockClientIds,
getBlockEditingMode,
} = select( blockEditorStore );
const ids =
clientIds !== null ? clientIds : getSelectedBlockClientIds();
return {
selectedBlocks: getBlockNamesByClientId( ids ),
selectedClientIds: ids,
isContentOnly:
getBlockEditingMode( ids[ 0 ] ) === 'contentOnly',
};
},
[ clientIds ]
);

const { canLock } = useBlockLock( selectedClientIds[ 0 ] );
const { canRename } = useBlockRename( selectedBlocks[ 0 ] );
const showLockButton = selectedClientIds.length === 1 && canLock;
const showRenameButton = selectedClientIds.length === 1 && canRename;
const showLockButton =
selectedClientIds.length === 1 && canLock && ! isContentOnly;
const showRenameButton =
selectedClientIds.length === 1 && canRename && ! isContentOnly;

// Check if current selection of blocks is Groupable or Ungroupable
// and pass this props down to ConvertToGroupButton.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ function ListViewBlockSelectButton(
context: 'list-view',
} );
const { isLocked } = useBlockLock( clientId );
const { isContentOnly } = useSelect(
( select ) => ( {
isContentOnly:
select( blockEditorStore ).getBlockEditingMode( clientId ) ===
'contentOnly',
} ),
[ clientId ]
);
const shouldShowLockIcon = isLocked && ! isContentOnly;
const {
canInsertBlockType,
getSelectedBlockClientIds,
Expand Down Expand Up @@ -339,7 +348,7 @@ function ListViewBlockSelectButton(
) ) }
</span>
) : null }
{ isLocked && (
{ shouldShowLockIcon && (
<span className="block-editor-list-view-block-select-button__lock">
<Icon icon={ lock } />
</span>
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ function ListViewBlock( {
// since that menu is part of the toolbar in the editor canvas.
// List View respects this by also hiding the block settings menu.
hasBlockSupport( blockName, '__experimentalToolbar', true ) &&
// Don't show the settings menu if block is disabled or content only.
blockEditingMode === 'default';
// Don't show the settings menu if block is disabled.
blockEditingMode !== 'disabled';
const instanceId = useInstanceId( ListViewBlock );
const descriptionId = `list-view-block-select-button__description-${ instanceId }`;

Expand Down

0 comments on commit 2a85977

Please sign in to comment.