Skip to content

Commit

Permalink
only send the allowedBlocks arg if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Jan 9, 2023
1 parent 7a12fe7 commit 435536d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ _Parameters_

_Returns_

- `string[]`: Array of allowed core block names or `['true']` if all blocks are allowed.
- `string[]|boolean`: Array of allowed core block names or `true` if all blocks are allowed.

<!-- END TOKEN(Autogenerated selectors|../../../packages/block-editor/src/store/selectors.js) -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ function PatternList( { filterValue, selectedCategory } ) {
[ destinationRootClientId ]
);
const options = {
allowed_blocks: allowedBlocks.join( ',' ),
allowed_blocks: Array.isArray( allowedBlocks )
? allowedBlocks.join( ',' )
: undefined,
};
if ( !! filterValue ) {
options.search = filterValue;
Expand Down
6 changes: 3 additions & 3 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@ export const getInserterItems = createSelector(
* @param {Object} state Editor state.
* @param {?string} rootClientId Optional root client ID of block list.
*
* @return {string[]} Array of allowed core block names or `['true']` if all blocks are allowed.
* @return {string[]|boolean} Array of allowed core block names or `true` if all blocks are allowed.
*/
export const __getAllowedCoreBlockNames = createSelector(
( state, rootClientId = null ) => {
Expand Down Expand Up @@ -2076,7 +2076,7 @@ export const __getAllowedCoreBlockNames = createSelector(
// Keep track of the blocks that cannot be inserted based on the provided rootClientId.
const allowedBlockNames = allCoreBlockTypes
.filter( ( blockType ) =>
canInsertBlockTypeUnmemoized( state, blockType, rootClientId )
canIncludeBlockTypeInInserter( state, blockType, rootClientId )
)
.map( ( { name } ) => name );
// We need to get all the blocks that cannot be inserted directly, but their parent/ancestor
Expand All @@ -2098,7 +2098,7 @@ export const __getAllowedCoreBlockNames = createSelector(
if (
allowedBlocksWithNestedBlocks.length === allCoreBlockTypes.length
) {
return [ 'all' ];
return true;
}
allowedBlocksWithNestedBlocks.sort();
return allowedBlocksWithNestedBlocks;
Expand Down

0 comments on commit 435536d

Please sign in to comment.