diff --git a/packages/block-editor/src/components/inserter/index.js b/packages/block-editor/src/components/inserter/index.js index 46930c44005588..87eabe4dc155d1 100644 --- a/packages/block-editor/src/components/inserter/index.js +++ b/packages/block-editor/src/components/inserter/index.js @@ -7,13 +7,14 @@ import { /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; +import { __, _x, sprintf } from '@wordpress/i18n'; import { Dropdown, IconButton } from '@wordpress/components'; import { Component } from '@wordpress/element'; import { withDispatch, withSelect } from '@wordpress/data'; import { compose, ifCondition } from '@wordpress/compose'; import { createBlock, + getBlockType, } from '@wordpress/blocks'; /** @@ -21,8 +22,8 @@ import { */ import InserterMenu from './menu'; -const defaultRenderToggle = ( { onToggle, disabled, isOpen, blockName = 'block' } ) => { - const label = `${ __( 'Add' ) } ${ blockName }`; +const defaultRenderToggle = ( { onToggle, disabled, isOpen, blockTitle } ) => { + const label = sprintf( _x( 'Add %s', 'directly add the allowed block' ), blockTitle ); return ( { - const { hasInserterItems, hasOneAllowedItem, getOneAllowedItemName } = select( 'core/block-editor' ); - + const { hasInserterItems, hasOneAllowedItem, getOneAllowedItem } = select( 'core/block-editor' ); + const allowedBlock = getBlockType( getOneAllowedItem( rootClientId ) ); return { hasItems: hasInserterItems( rootClientId ), hasOneAllowedItem: hasOneAllowedItem( rootClientId ), - blockName: getOneAllowedItemName( rootClientId ), + blockTitle: allowedBlock ? allowedBlock.title : '', }; } ), withDispatch( ( dispatch, ownProps, { select } ) => { diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 1e4e2ffe8e8090..3dc8657dcc9463 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1278,6 +1278,7 @@ export const hasInserterItems = createSelector( /** * Determines whether there is only one item that may be inserted. + * * @param {Object} state Editor state. * @param {?string} rootClientId Optional root client ID of block list. * @@ -1294,29 +1295,29 @@ export const hasOneAllowedItem = ( state, rootClientId = null ) => { /** * Determines whether there is only one item that may be inserted. + * * @param {Object} state Editor state. * @param {?string} rootClientId Optional root client ID of block list. * * @return {string} The name of the allowed block. */ -export const getOneAllowedItemName = ( state, rootClientId = null ) => { - if ( rootClientId ) { - const parentBlockListSettings = getBlockListSettings( state, rootClientId ); - - if ( get( parentBlockListSettings, [ 'allowedBlocks', 'length' ], 0 ) === 1 ) { - let name = get( parentBlockListSettings, [ 'allowedBlocks' ] )[ 0 ]; - name = name.split( '/' )[ 1 ].replace( '-', ' ' ); - return name; - } - +export const getOneAllowedItem = ( state, rootClientId = null ) => { + if ( ! rootClientId ) { + return false; + } + if ( ! hasOneAllowedItem( state, rootClientId ) ) { return false; } - return false; + const parentBlockListSettings = getBlockListSettings( state, rootClientId ); + const name = get( parentBlockListSettings, [ 'allowedBlocks', 0 ], 0 ); + + return name; }; /** * Determines whether there is only one item that may be inserted. + * * @param {Object} state Editor state. * @param {?string} clientId Block client ID. * @param {?string} destinationRootClientId Root client ID of block list. diff --git a/packages/block-library/src/column/edit.js b/packages/block-library/src/column/edit.js index 9b39f31971da51..72f359f33da599 100644 --- a/packages/block-library/src/column/edit.js +++ b/packages/block-library/src/column/edit.js @@ -68,7 +68,6 @@ function ColumnEdit( {