Skip to content

Commit

Permalink
De-duplicate block toolbar icons for patterns (#65054)
Browse files Browse the repository at this point in the history
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
  • Loading branch information
4 people authored Sep 4, 2024
1 parent 793d326 commit b1143fa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function PrivateBlockToolbar( {
shouldShowVisualToolbar,
showParentSelector,
isUsingBindings,
hasParentPattern,
} = useSelect( ( select ) => {
const {
getBlockName,
Expand All @@ -74,6 +75,7 @@ export function PrivateBlockToolbar( {
isBlockValid,
getBlockEditingMode,
getBlockAttributes,
getBlockParentsByBlockName,
} = select( blockEditorStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
Expand All @@ -94,6 +96,13 @@ export function PrivateBlockToolbar( {
( clientId ) =>
!! getBlockAttributes( clientId )?.metadata?.bindings
);

const _hasParentPattern = selectedBlockClientIds.every(
( clientId ) =>
getBlockParentsByBlockName( clientId, 'core/block', true )
.length > 0
);

return {
blockClientId: selectedBlockClientId,
blockClientIds: selectedBlockClientIds,
Expand All @@ -113,6 +122,7 @@ export function PrivateBlockToolbar( {
selectedBlockClientIds.length === 1 &&
_isDefaultEditingMode,
isUsingBindings: _isUsingBindings,
hasParentPattern: _hasParentPattern,
};
}, [] );

Expand Down Expand Up @@ -167,7 +177,7 @@ export function PrivateBlockToolbar( {
isDefaultEditingMode && <BlockParentSelector /> }
{ ( shouldShowVisualToolbar || isMultiToolbar ) &&
( isDefaultEditingMode ||
isContentOnlyEditingMode ||
( isContentOnlyEditingMode && ! hasParentPattern ) ||
isSynced ) && (
<div
ref={ nodeRef }
Expand Down

0 comments on commit b1143fa

Please sign in to comment.