Skip to content

Commit

Permalink
Address code review and hide non pattern/template menu
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed May 2, 2024
1 parent 2bdd5f2 commit 8b4ae5e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/block-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export default function BlockActions( {
getDirectInsertBlock,
canMoveBlocks,
canRemoveBlocks,
getBlockEditingMode,
} = select( blockEditorStore );

const blocks = getBlocksByClientId( clientIds );
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
const rootBlockEditingMode = getBlockEditingMode( rootClientId );
const canInsertDefaultBlock = canInsertBlockType(
getDefaultBlockName(),
rootClientId
Expand All @@ -46,7 +48,9 @@ export default function BlockActions( {
return {
canMove: canMoveBlocks( clientIds, rootClientId ),
canRemove: canRemoveBlocks( clientIds, rootClientId ),
canInsertBlock: canInsertDefaultBlock || !! directInsertBlock,
canInsertBlock:
( canInsertDefaultBlock || !! directInsertBlock ) &&
rootBlockEditingMode === 'default',
canCopyStyles: blocks.every( ( block ) => {
return (
!! block &&
Expand Down
68 changes: 40 additions & 28 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,34 +104,46 @@ function ListViewBlock( {

const blockInformation = useBlockDisplayInformation( clientId );

const { block, blockName, blockEditingMode, allowRightClickOverrides } =
useSelect(
( select ) => {
const {
getBlock,
getBlockName,
getBlockEditingMode,
getSettings,
} = select( blockEditorStore );

return {
block: getBlock( clientId ),
blockName: getBlockName( clientId ),
blockEditingMode: getBlockEditingMode( clientId ),
allowRightClickOverrides:
getSettings().allowRightClickOverrides,
};
},
[ clientId ]
);

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.
blockEditingMode !== 'disabled';
const { block, allowRightClickOverrides, showBlockActions } = useSelect(
( select ) => {
const {
getBlock,
getBlockName,
getSettings,
getContentLockingParent,
getBlockEditingMode,
getTemplateLock,
} = unlock( select( blockEditorStore ) );
const _blockName = getBlockName( clientId );
const isContentOnly =
getBlockEditingMode( clientId ) === 'contentOnly';
const contentLockingParent = getContentLockingParent( clientId );
// Don't show the block actions for template lock contentOnly.
// This block currently doesn't have any action to display in the menu dropdown.
const isContentLockingParentTemplateLock =
getTemplateLock( contentLockingParent ) === 'contentOnly';
// 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.
const hasToolbar = hasBlockSupport(
_blockName,
'__experimentalToolbar',
true
);

return {
block: getBlock( clientId ),
blockName: _blockName,
allowRightClickOverrides:
getSettings().allowRightClickOverrides,
showBlockActions:
hasToolbar &&
! ( isContentOnly && isContentLockingParentTemplateLock ),
};
},
[ clientId ]
);

const instanceId = useInstanceId( ListViewBlock );
const descriptionId = `list-view-block-select-button__description-${ instanceId }`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ function ContentOnlySettingsMenuItems( { clientId } ) {
getBlockAttributes( patternParent ).ref
);
} else {
const templateId = select( editorStore ).getCurrentTemplateId();
if ( templateId ) {
const { getCurrentPostType, getCurrentTemplateId } =
select( editorStore );
const currentPostType = getCurrentPostType();
const templateId = getCurrentTemplateId();
if ( currentPostType === 'page' && templateId ) {
record = select( coreStore ).getEntityRecord(
'postType',
'wp_template',
Expand Down

0 comments on commit 8b4ae5e

Please sign in to comment.