Skip to content

Commit

Permalink
Fix: Insert Before and Insert After appear even when default block ca…
Browse files Browse the repository at this point in the history
…n not be inserted.
  • Loading branch information
jorgefilipecosta committed Aug 5, 2019
1 parent 659b327 commit 484272c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
35 changes: 22 additions & 13 deletions packages/block-editor/src/components/block-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,57 @@ import { withSelect, withDispatch } from '@wordpress/data';
import { cloneBlock, hasBlockSupport, switchToBlockType } from '@wordpress/blocks';

function BlockActions( {
canDuplicate,
canInsertDefaultBlock,
children,
isLocked,
onDuplicate,
onRemove,
onInsertBefore,
onInsertAfter,
onGroup,
onInsertAfter,
onInsertBefore,
onRemove,
onUngroup,
isLocked,
canDuplicate,
children,
} ) {
return children( {
canDuplicate,
canInsertDefaultBlock,
isLocked,
onDuplicate,
onRemove,
onGroup,
onInsertAfter,
onInsertBefore,
onGroup,
onRemove,
onUngroup,
isLocked,
canDuplicate,
} );
}

export default compose( [
withSelect( ( select, props ) => {
const {
canInsertBlockType,
getBlockRootClientId,
getBlocksByClientId,
getTemplateLock,
getBlockRootClientId,
} = select( 'core/block-editor' );
const { getDefaultBlockName } = select( 'core/blocks' );

const blocks = getBlocksByClientId( props.clientIds );
const canDuplicate = every( blocks, ( block ) => {
return !! block && hasBlockSupport( block.name, 'multiple', true );
} );
const rootClientId = getBlockRootClientId( props.clientIds[ 0 ] );
const canInsertDefaultBlock = canInsertBlockType(
getDefaultBlockName(),
rootClientId
);

return {
isLocked: !! getTemplateLock( rootClientId ),
blocks,
canDuplicate,
rootClientId,
canInsertDefaultBlock,
extraProps: props,
isLocked: !! getTemplateLock( rootClientId ),
rootClientId,
};
} ),
withDispatch( ( dispatch, props, { select } ) => {
Expand Down
12 changes: 10 additions & 2 deletions packages/block-editor/src/components/block-settings-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ export function BlockSettingsMenu( { clientIds } ) {

return (
<BlockActions clientIds={ clientIds }>
{ ( { onDuplicate, onRemove, onInsertAfter, onInsertBefore, canDuplicate, isLocked } ) => (
{ ( {
canDuplicate,
canInsertDefaultBlock,
isLocked,
onDuplicate,
onInsertAfter,
onInsertBefore,
onRemove,
} ) => (
<Toolbar>
<DropdownMenu
icon="ellipsis"
Expand Down Expand Up @@ -69,7 +77,7 @@ export function BlockSettingsMenu( { clientIds } ) {
{ __( 'Duplicate' ) }
</MenuItem>
) }
{ ! isLocked && (
{ canInsertDefaultBlock && (
<>
<MenuItem
className="editor-block-settings-menu__control block-editor-block-settings-menu__control"
Expand Down

0 comments on commit 484272c

Please sign in to comment.