Skip to content

Commit

Permalink
Patterns: Don't override the rootClientID in create menu - only set i…
Browse files Browse the repository at this point in the history
…f undefined (#52713)
  • Loading branch information
glendaviesnz authored Jul 19, 2023
1 parent 643b7b8 commit 82893e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { useSelect } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';

/**
Expand All @@ -10,7 +10,12 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
import ReusableBlockConvertButton from './reusable-block-convert-button';
import ReusableBlocksManageButton from './reusable-blocks-manage-button';

function ReusableBlocksMenuItems( { clientIds, rootClientId } ) {
export default function ReusableBlocksMenuItems( { rootClientId } ) {
const clientIds = useSelect(
( select ) => select( blockEditorStore ).getSelectedBlockClientIds(),
[]
);

return (
<>
<ReusableBlockConvertButton
Expand All @@ -23,16 +28,3 @@ function ReusableBlocksMenuItems( { clientIds, rootClientId } ) {
</>
);
}

export default withSelect( ( select ) => {
const { getSelectedBlockClientIds, getBlockRootClientId } =
select( blockEditorStore );
const clientIds = getSelectedBlockClientIds();
return {
clientIds,
rootClientId:
clientIds?.length > 0
? getBlockRootClientId( clientIds[ 0 ] )
: undefined,
};
} )( ReusableBlocksMenuItems );
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,17 @@ export default function ReusableBlockConvertButton( {
const canConvert = useSelect(
( select ) => {
const { canUser } = select( coreStore );
const { getBlocksByClientId, canInsertBlockType } =
select( blockEditorStore );
const {
getBlocksByClientId,
canInsertBlockType,
getBlockRootClientId,
} = select( blockEditorStore );

const rootId =
rootClientId ||
( clientIds.length > 0
? getBlockRootClientId( clientIds[ 0 ] )
: undefined );

const blocks = getBlocksByClientId( clientIds ) ?? [];

Expand All @@ -70,7 +79,7 @@ export default function ReusableBlockConvertButton( {
// Hide when this is already a reusable block.
! isReusable &&
// Hide when reusable blocks are disabled.
canInsertBlockType( 'core/block', rootClientId ) &&
canInsertBlockType( 'core/block', rootId ) &&
blocks.every(
( block ) =>
// Guard against the case where a regular block has *just* been converted.
Expand Down

1 comment on commit 82893e3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 82893e3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5594537941
📝 Reported issues:

Please sign in to comment.