Skip to content

Commit

Permalink
Blocks: Disable Convert to Reusable for nested blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Feb 14, 2018
1 parent ad1fd15 commit 8872058
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions editor/components/block-settings-menu/reusable-block-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,28 @@ import { isReusableBlock } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import { getBlock, getReusableBlock } from '../../store/selectors';
import {
getBlock,
getBlockOrder,
getReusableBlock,
} from '../../store/selectors';
import { convertBlockToStatic, convertBlockToReusable, deleteReusableBlock } from '../../store/actions';

export function ReusableBlockSettings( { reusableBlock, onConvertToStatic, onConvertToReusable, onDelete } ) {
export function ReusableBlockSettings( {
reusableBlock,
isValidForConvert,
onConvertToStatic,
onConvertToReusable,
onDelete,
} ) {
return (
<Fragment>
{ ! reusableBlock && (
<IconButton
className="editor-block-settings-menu__control"
icon="controls-repeat"
onClick={ onConvertToReusable }
disabled={ ! isValidForConvert }
>
{ __( 'Convert to Reusable Block' ) }
</IconButton>
Expand Down Expand Up @@ -56,7 +67,9 @@ export function ReusableBlockSettings( { reusableBlock, onConvertToStatic, onCon
export default connect(
( state, { uid } ) => {
const block = getBlock( state, uid );

return {
isValidForConvert: ! getBlockOrder( state, block.uid ).length,
reusableBlock: isReusableBlock( block ) ? getReusableBlock( state, block.attributes.ref ) : null,
};
},
Expand Down

0 comments on commit 8872058

Please sign in to comment.