Skip to content

Commit

Permalink
updates to the appender
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Sep 25, 2019
1 parent 58d98c5 commit 15bb9c7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
17 changes: 9 additions & 8 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ 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';

/**
* Internal dependencies
*/
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 (
<IconButton
icon="insert"
Expand Down Expand Up @@ -69,7 +70,7 @@ class Inserter extends Component {
const {
disabled,
hasOneAllowedItem,
blockName,
blockTitle,
createIfOne,
renderToggle = defaultRenderToggle,
} = this.props;
Expand All @@ -78,7 +79,7 @@ class Inserter extends Component {
onToggle = createIfOne;
}

return renderToggle( { onToggle, isOpen, disabled, blockName } );
return renderToggle( { onToggle, isOpen, disabled, blockTitle } );
}

/**
Expand Down Expand Up @@ -125,12 +126,12 @@ class Inserter extends Component {

export default compose( [
withSelect( ( select, { rootClientId } ) => {
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 } ) => {
Expand Down
23 changes: 12 additions & 11 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ function ColumnEdit( {
</PanelBody>
</InspectorControls>
<InnerBlocks
allowedBlocks={ [ 'core/paragraph' ] }
templateLock={ false }
renderAppender={ (
hasChildBlocks ?
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/navigation-menu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function NavigationMenu( {
<div className="wp-block-navigation-menu">
<InnerBlocks
allowedBlocks={ [ 'core/navigation-menu-item' ] }
renderAppender={ InnerBlocks.ButtonBlockAppender }
/>
</div>
</Fragment>
Expand Down

0 comments on commit 15bb9c7

Please sign in to comment.