Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-duplicate block toolbar icons for patterns #65054

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading