Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename parentClientId to rootClientId for consistency #11274

Merged
merged 1 commit into from Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions docs/data/data-core-editor.md
Expand Up @@ -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*

Expand Down Expand Up @@ -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*

Expand Down
8 changes: 4 additions & 4 deletions packages/editor/src/components/autocompleters/block.js
Expand Up @@ -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<Editor.InserterItem>} 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 );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/inner-blocks/index.js
Expand Up @@ -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 ) => {
Expand Down
42 changes: 19 additions & 23 deletions packages/editor/src/store/selectors.js
Expand Up @@ -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;
Expand All @@ -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 ) {
Expand All @@ -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,
],
Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
Expand Down Expand Up @@ -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 ) => {
Expand Down Expand Up @@ -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;
}

Expand All @@ -1708,7 +1704,7 @@ export const getInserterItems = createSelector(
return false;
}

if ( ! canInsertBlockType( state, referencedBlockType.name, parentClientId ) ) {
if ( ! canInsertBlockType( state, referencedBlockType.name, rootClientId ) ) {
return false;
}

Expand Down Expand Up @@ -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,
Expand Down