Skip to content

Commit

Permalink
Remove convert template menu item if the block is content only
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Apr 29, 2024
1 parent e0100f8 commit cb90568
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/edit-site/src/components/template-part-converter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ export default function TemplatePartConverter() {
}

function TemplatePartConverterMenuItem( { clientIds, onClose } ) {
const blocks = useSelect(
( select ) =>
select( blockEditorStore ).getBlocksByClientId( clientIds ),
const { isContentOnly, blocks } = useSelect(
( select ) => {
const { getBlocksByClientId, getBlockEditingMode } =
select( blockEditorStore );
return {
blocks: getBlocksByClientId( clientIds ),
isContentOnly:
clientIds.length === 1 &&
getBlockEditingMode( clientIds[ 0 ] ) === 'contentOnly',
};
},
[ clientIds ]
);

// Do not show the convert button if the block is in content-only mode.
if ( isContentOnly ) return null;

// Allow converting a single template part to standard blocks.
if ( blocks.length === 1 && blocks[ 0 ]?.name === 'core/template-part' ) {
return (
Expand Down

0 comments on commit cb90568

Please sign in to comment.