From ad9db305b6285080285d8de1518a56e1c0835a89 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Tue, 24 Sep 2019 15:56:37 +0300 Subject: [PATCH] updates to the appender --- .../src/components/inserter/index.js | 17 +++++++------- packages/block-editor/src/store/selectors.js | 23 ++++++++++--------- packages/block-library/src/column/edit.js | 1 - .../block-library/src/navigation-menu/edit.js | 1 - 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/block-editor/src/components/inserter/index.js b/packages/block-editor/src/components/inserter/index.js index cdd8f380e9e47..770aefeb173e6 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 1e4e2ffe8e809..3dc8657dcc946 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 9b39f31971da5..72f359f33da59 100644 --- a/packages/block-library/src/column/edit.js +++ b/packages/block-library/src/column/edit.js @@ -68,7 +68,6 @@ function ColumnEdit( {