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

Block Hooks: Do not remove toggle if hooked block is present elsewhere #57928

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
20 changes: 4 additions & 16 deletions packages/block-editor/src/hooks/block-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ function BlockHooksControlPure( { name, clientId } ) {
const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(
( clientIds, block ) => {
// If the block doesn't exist anywhere in the block tree,
// we know that we have to display the toggle for it, and set
// it to disabled.
// we know that we have to set the toggle to disabled.
if ( getGlobalBlockCount( block.name ) === 0 ) {
return clientIds;
}
Expand Down Expand Up @@ -96,13 +95,8 @@ function BlockHooksControlPure( { name, clientId } ) {
}

// If no hooked block was found in any of its designated locations,
// but it exists elsewhere in the block tree, we consider it manually inserted.
// In this case, we take note and will remove the corresponding toggle from the
// block inspector panel.
return {
...clientIds,
[ block.name ]: false,
};
// we set the toggle to disabled.
return clientIds;
},
{}
);
Expand All @@ -118,13 +112,7 @@ function BlockHooksControlPure( { name, clientId } ) {

const { insertBlock, removeBlock } = useDispatch( blockEditorStore );

// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.
const hookedBlocksForCurrentBlockIfNotPresentElsewhere =
hookedBlocksForCurrentBlock?.filter(
( block ) => hookedBlockClientIds?.[ block.name ] !== false
);

if ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {
if ( ! hookedBlocksForCurrentBlock.length ) {
return null;
}

Expand Down
Loading