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 and tellthemachines committed Jul 24, 2023
1 parent 99d55d1 commit 88e1896
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

0 comments on commit 88e1896

Please sign in to comment.