Skip to content

Commit 8872058

Browse files
committed
Blocks: Disable Convert to Reusable for nested blocks
1 parent ad1fd15 commit 8872058

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

editor/components/block-settings-menu/reusable-block-settings.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,28 @@ import { isReusableBlock } from '@wordpress/blocks';
1515
/**
1616
* Internal dependencies
1717
*/
18-
import { getBlock, getReusableBlock } from '../../store/selectors';
18+
import {
19+
getBlock,
20+
getBlockOrder,
21+
getReusableBlock,
22+
} from '../../store/selectors';
1923
import { convertBlockToStatic, convertBlockToReusable, deleteReusableBlock } from '../../store/actions';
2024

21-
export function ReusableBlockSettings( { reusableBlock, onConvertToStatic, onConvertToReusable, onDelete } ) {
25+
export function ReusableBlockSettings( {
26+
reusableBlock,
27+
isValidForConvert,
28+
onConvertToStatic,
29+
onConvertToReusable,
30+
onDelete,
31+
} ) {
2232
return (
2333
<Fragment>
2434
{ ! reusableBlock && (
2535
<IconButton
2636
className="editor-block-settings-menu__control"
2737
icon="controls-repeat"
2838
onClick={ onConvertToReusable }
39+
disabled={ ! isValidForConvert }
2940
>
3041
{ __( 'Convert to Reusable Block' ) }
3142
</IconButton>
@@ -56,7 +67,9 @@ export function ReusableBlockSettings( { reusableBlock, onConvertToStatic, onCon
5667
export default connect(
5768
( state, { uid } ) => {
5869
const block = getBlock( state, uid );
70+
5971
return {
72+
isValidForConvert: ! getBlockOrder( state, block.uid ).length,
6073
reusableBlock: isReusableBlock( block ) ? getReusableBlock( state, block.attributes.ref ) : null,
6174
};
6275
},

0 commit comments

Comments
 (0)