Skip to content

Commit 535405a

Browse files
ramonjdtalldanellatrixandrewserong
authored
Block toolbar and context menu: hide pattern actions in Revisions UI (#76066)
Co-authored-by: ramonjd <[email protected]> Co-authored-by: talldan <[email protected]> Co-authored-by: ellatrix <[email protected]> Co-authored-by: andrewserong <[email protected]>
1 parent ff51a79 commit 535405a

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

packages/block-editor/src/components/block-toolbar/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export function PrivateBlockToolbar( {
7878
showBlockVisibilityButton,
7979
showSwitchSectionStyleButton,
8080
areSelectedBlocksHiddenOnViewport,
81+
canEdit,
8182
} = useSelect( ( select ) => {
83+
const { canEditBlock } = select( blockEditorStore );
8284
const {
8385
getBlockName,
8486
getBlockMode,
@@ -122,7 +124,9 @@ export function PrivateBlockToolbar( {
122124

123125
const _isZoomOut = isZoomOut();
124126
const _isSectionBlock = isSectionBlock( selectedBlockClientId );
125-
const _showSwitchSectionStyleButton = _isZoomOut || _isSectionBlock;
127+
const _canEditBlock = canEditBlock( selectedBlockClientId );
128+
const _showSwitchSectionStyleButton =
129+
_canEditBlock && ( _isZoomOut || _isSectionBlock );
126130

127131
const _currentDeviceType =
128132
getSettings()?.[ deviceTypeKey ]?.toLowerCase() || 'desktop';
@@ -161,6 +165,7 @@ export function PrivateBlockToolbar( {
161165
showSwitchSectionStyleButton: _showSwitchSectionStyleButton,
162166
areSelectedBlocksHiddenOnViewport:
163167
_areSelectedBlocksHiddenOnViewport,
168+
canEdit: _canEditBlock,
164169
};
165170
}, [] );
166171

@@ -245,7 +250,7 @@ export function PrivateBlockToolbar( {
245250
shouldShowVisualToolbar &&
246251
isMultiToolbar &&
247252
showGroupButtons && <BlockGroupToolbar /> }
248-
{ ! isMultiToolbar && (
253+
{ ! isMultiToolbar && canEdit && (
249254
<EditSectionButton clientId={ blockClientIds[ 0 ] } />
250255
) }
251256
{ ! areSelectedBlocksHiddenOnViewport && showShuffleButton && (

packages/patterns/src/components/patterns-manage-button.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ function PatternsManageButton( { clientId } ) {
2323
managePatternsUrl,
2424
isSyncedPattern,
2525
isUnsyncedPattern,
26+
canEdit,
2627
} = useSelect(
2728
( select ) => {
28-
const { canRemoveBlock, getBlock } = select( blockEditorStore );
29+
const { canRemoveBlock, getBlock, canEditBlock } =
30+
select( blockEditorStore );
2931
const { canUser } = select( coreStore );
3032
const block = getBlock( clientId );
3133

@@ -43,6 +45,7 @@ function PatternsManageButton( { clientId } ) {
4345

4446
return {
4547
attributes: block.attributes,
48+
canEdit: canEditBlock( clientId ),
4649
// For unsynced patterns, detaching is simply removing the `patternName` attribute.
4750
// For synced patterns, the `core:block` block is replaced with its inner blocks,
4851
// so checking whether `canRemoveBlock` is possible is required.
@@ -78,7 +81,7 @@ function PatternsManageButton( { clientId } ) {
7881
useDispatch( patternsStore )
7982
);
8083

81-
if ( ! isVisible ) {
84+
if ( ! isVisible || ! canEdit ) {
8285
return null;
8386
}
8487

0 commit comments

Comments
 (0)