Skip to content

Commit

Permalink
Avoid showing Edit buttons on template part and synced pattern block …
Browse files Browse the repository at this point in the history
…toolbars when in Write Mode
  • Loading branch information
talldan committed Dec 24, 2024
1 parent a9ebf69 commit d1d7d62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
21 changes: 13 additions & 8 deletions packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,24 @@ function ReusableBlockControl( {
handleEditOriginal,
resetContent,
} ) {
const canUserEdit = useSelect(
( select ) =>
!! select( coreStore ).canUser( 'update', {
kind: 'postType',
name: 'wp_block',
id: recordId,
} ),
const { canUserEdit, isNavigationMode } = useSelect(
( select ) => {
const { canUser } = select( coreStore );
return {
canUserEdit: !! canUser( 'update', {
kind: 'postType',
name: 'wp_block',
id: recordId,
} ),
isNavigationMode: select( blockEditorStore ).isNavigationMode(),
};
},
[ recordId ]
);

return (
<>
{ canUserEdit && !! handleEditOriginal && (
{ canUserEdit && ! isNavigationMode && !! handleEditOriginal && (
<BlockControls>
<ToolbarGroup>
<ToolbarButton onClick={ handleEditOriginal }>
Expand Down
9 changes: 8 additions & 1 deletion packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ export default function TemplatePartEdit( {
onNavigateToEntityRecord,
title,
canUserEdit,
isNavigationMode,
} = useSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { getBlockCount, getSettings } = select( blockEditorStore );
const {
getBlockCount,
getSettings,
isNavigationMode: _isNavigationMode,
} = select( blockEditorStore );

const getEntityArgs = [
'postType',
Expand Down Expand Up @@ -168,6 +173,7 @@ export default function TemplatePartEdit( {
getSettings().onNavigateToEntityRecord,
title: entityRecord?.title,
canUserEdit: !! _canUserEdit,
isNavigationMode: _isNavigationMode(),
};
},
[ templatePartId, attributes.area, clientId ]
Expand Down Expand Up @@ -236,6 +242,7 @@ export default function TemplatePartEdit( {
<>
<RecursionProvider uniqueId={ templatePartId }>
{ isEntityAvailable &&
! isNavigationMode &&
onNavigateToEntityRecord &&
canUserEdit && (
<BlockControls group="other">
Expand Down

0 comments on commit d1d7d62

Please sign in to comment.