From b0efaa81c1da154b6c3fd8b285205adddbf25ca6 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Wed, 31 Oct 2018 10:09:05 +1100 Subject: [PATCH] Rename parentClientId to rootClientId for consistency We refer to the same concept as rootClientId elsewhere in the application. --- docs/data/data-core-editor.md | 12 ++---- .../src/components/autocompleters/block.js | 8 ++-- .../src/components/inner-blocks/index.js | 4 +- packages/editor/src/store/selectors.js | 42 +++++++++---------- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/docs/data/data-core-editor.md b/docs/data/data-core-editor.md index 78c2371a6e3e21..ebbc303649e17e 100644 --- a/docs/data/data-core-editor.md +++ b/docs/data/data-core-editor.md @@ -1074,17 +1074,13 @@ Post content. ### canInsertBlockType -Determines if the given block type is allowed to be inserted, and, if -parentClientId is provided, whether it is allowed to be nested within the -given parent. +Determines if the given block type is allowed to be inserted into the block list. *Parameters* * state: Editor state. - * blockName: The name of the given block type, e.g. - 'core/paragraph'. - * parentClientId: The parent that the given block is to be - nested within, or null. + * blockName: The name of the block type, e.g.' core/paragraph'. + * rootClientId: Optional root client ID of block list. *Returns* @@ -1114,7 +1110,7 @@ Items are returned ordered descendingly by their 'utility' and 'frecency'. *Parameters* * state: Editor state. - * parentClientId: The block we are inserting into, if any. + * rootClientId: Optional root client ID of block list. *Returns* diff --git a/packages/editor/src/components/autocompleters/block.js b/packages/editor/src/components/autocompleters/block.js index c864e2a77edb69..e48bf2f48e7380 100644 --- a/packages/editor/src/components/autocompleters/block.js +++ b/packages/editor/src/components/autocompleters/block.js @@ -23,14 +23,14 @@ function defaultGetBlockInsertionParentClientId() { /** * Returns the inserter items for the specified parent block. * - * @param {string} parentClientId Client ID of the block for which to retrieve - * inserter items. + * @param {string} rootClientId Client ID of the block for which to retrieve + * inserter items. * * @return {Array} The inserter items for the specified * parent. */ -function defaultGetInserterItems( parentClientId ) { - return select( 'core/editor' ).getInserterItems( parentClientId ); +function defaultGetInserterItems( rootClientId ) { + return select( 'core/editor' ).getInserterItems( rootClientId ); } /** diff --git a/packages/editor/src/components/inner-blocks/index.js b/packages/editor/src/components/inner-blocks/index.js index 0c06acd345eb5f..c9252e912b5df1 100644 --- a/packages/editor/src/components/inner-blocks/index.js +++ b/packages/editor/src/components/inner-blocks/index.js @@ -128,12 +128,12 @@ InnerBlocks = compose( [ getTemplateLock, } = select( 'core/editor' ); const { clientId } = ownProps; - const parentClientId = getBlockRootClientId( clientId ); + const rootClientId = getBlockRootClientId( clientId ); return { isSelectedBlockInRoot: isBlockSelected( clientId ) || hasSelectedInnerBlock( clientId ), block: getBlock( clientId ), blockListSettings: getBlockListSettings( clientId ), - parentLock: getTemplateLock( parentClientId ), + parentLock: getTemplateLock( rootClientId ), }; } ), withDispatch( ( dispatch, ownProps ) => { diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index 79cd4ca0fc8a05..b31ff36d46794f 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1506,20 +1506,16 @@ export const getEditedPostContent = createSelector( ); /** - * Determines if the given block type is allowed to be inserted, and, if - * parentClientId is provided, whether it is allowed to be nested within the - * given parent. + * Determines if the given block type is allowed to be inserted into the block list. * - * @param {Object} state Editor state. - * @param {string} blockName The name of the given block type, e.g. - * 'core/paragraph'. - * @param {?string} parentClientId The parent that the given block is to be - * nested within, or null. + * @param {Object} state Editor state. + * @param {string} blockName The name of the block type, e.g.' core/paragraph'. + * @param {?string} rootClientId Optional root client ID of block list. * * @return {boolean} Whether the given block type is allowed to be inserted. */ export const canInsertBlockType = createSelector( - ( state, blockName, parentClientId = null ) => { + ( state, blockName, rootClientId = null ) => { const checkAllowList = ( list, item, defaultResult = null ) => { if ( isBoolean( list ) ) { return list; @@ -1542,17 +1538,17 @@ export const canInsertBlockType = createSelector( return false; } - const isLocked = !! getTemplateLock( state, parentClientId ); + const isLocked = !! getTemplateLock( state, rootClientId ); if ( isLocked ) { return false; } - const parentBlockListSettings = getBlockListSettings( state, parentClientId ); + const parentBlockListSettings = getBlockListSettings( state, rootClientId ); const parentAllowedBlocks = get( parentBlockListSettings, [ 'allowedBlocks' ] ); const hasParentAllowedBlock = checkAllowList( parentAllowedBlocks, blockName ); const blockAllowedParentBlocks = blockType.parent; - const parentName = getBlockName( state, parentClientId ); + const parentName = getBlockName( state, rootClientId ); const hasBlockAllowedParent = checkAllowList( blockAllowedParentBlocks, parentName ); if ( hasParentAllowedBlock !== null && hasBlockAllowedParent !== null ) { @@ -1565,9 +1561,9 @@ export const canInsertBlockType = createSelector( return true; }, - ( state, blockName, parentClientId ) => [ - state.blockListSettings[ parentClientId ], - state.editor.present.blocksByClientId[ parentClientId ], + ( state, blockName, rootClientId ) => [ + state.blockListSettings[ rootClientId ], + state.editor.present.blocksByClientId[ rootClientId ], state.settings.allowedBlockTypes, state.settings.templateLock, ], @@ -1607,8 +1603,8 @@ function getInsertUsage( state, id ) { * * Items are returned ordered descendingly by their 'utility' and 'frecency'. * - * @param {Object} state Editor state. - * @param {?string} parentClientId The block we are inserting into, if any. + * @param {Object} state Editor state. + * @param {?string} rootClientId Optional root client ID of block list. * * @return {Editor.InserterItem[]} Items that appear in inserter. * @@ -1626,7 +1622,7 @@ function getInsertUsage( state, id ) { * @property {number} frecency Hueristic that combines frequency and recency. */ export const getInserterItems = createSelector( - ( state, parentClientId = null ) => { + ( state, rootClientId = null ) => { const calculateUtility = ( category, count, isContextual ) => { if ( isContextual ) { return INSERTER_UTILITY_HIGH; @@ -1664,7 +1660,7 @@ export const getInserterItems = createSelector( return false; } - return canInsertBlockType( state, blockType.name, parentClientId ); + return canInsertBlockType( state, blockType.name, rootClientId ); }; const buildBlockTypeInserterItem = ( blockType ) => { @@ -1694,7 +1690,7 @@ export const getInserterItems = createSelector( }; const shouldIncludeReusableBlock = ( reusableBlock ) => { - if ( ! canInsertBlockType( state, 'core/block', parentClientId ) ) { + if ( ! canInsertBlockType( state, 'core/block', rootClientId ) ) { return false; } @@ -1708,7 +1704,7 @@ export const getInserterItems = createSelector( return false; } - if ( ! canInsertBlockType( state, referencedBlockType.name, parentClientId ) ) { + if ( ! canInsertBlockType( state, referencedBlockType.name, rootClientId ) ) { return false; } @@ -1753,8 +1749,8 @@ export const getInserterItems = createSelector( [ 'desc', 'desc' ] ); }, - ( state, parentClientId ) => [ - state.blockListSettings[ parentClientId ], + ( state, rootClientId ) => [ + state.blockListSettings[ rootClientId ], state.editor.present.blockOrder, state.editor.present.blocksByClientId, state.preferences.insertUsage,