Skip to content

Commit

Permalink
Inserter: Don't auto-add block if it has variations
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Jan 24, 2020
1 parent d56e687 commit d11009e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { get } from 'lodash';
import { size } from 'lodash';
/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -140,12 +140,18 @@ export default compose( [
hasInserterItems,
__experimentalGetAllowedBlocks,
} = select( 'core/block-editor' );
const {
__experimentalGetBlockPatterns: getBlockPatterns,
} = select( 'core/blocks' );

rootClientId = rootClientId || getBlockRootClientId( clientId ) || undefined;

const allowedBlocks = __experimentalGetAllowedBlocks( rootClientId );

const hasSingleBlockType = allowedBlocks && ( get( allowedBlocks, [ 'length' ], 0 ) === 1 );
const hasSingleBlockType = (
size( allowedBlocks ) === 1 &&
size( getBlockPatterns( allowedBlocks[ 0 ].name, 'inserter' ) ) === 0
);

let allowedBlockType = false;
if ( hasSingleBlockType ) {
Expand Down

0 comments on commit d11009e

Please sign in to comment.