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 23, 2024
1 parent 73a17b0 commit 7789e0e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 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
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ function ListViewBlock( {
[]
);

const isContentOnly = blockEditingMode === 'contentOnly';
const showBlockActions =
// When a block hides its toolbar it also hides the block settings menu,
// 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';
( blockEditingMode === 'default' || isContentOnly );
const instanceId = useInstanceId( ListViewBlock );
const descriptionId = `list-view-block-select-button__description-${ instanceId }`;

Expand Down

0 comments on commit 7789e0e

Please sign in to comment.