-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Consolidate inserter block filter (#34545)
* Consolidate inserter block filtering * Use an array of available embeds * Update packages/block-editor/src/components/inserter/menu.native.js Fix typo Co-authored-by: Carlos Garcia <fluiddot@gmail.com> * Move allowed block filter to a util file * Clean up typo and remove unused prop * Fix default named params Co-authored-by: jhnstn <jason@readysetandco.com> Co-authored-by: Carlos Garcia <fluiddot@gmail.com>
- Loading branch information
1 parent
f8a3f6c
commit f2c0752
Showing
5 changed files
with
44 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/block-editor/src/components/inserter/utils.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const REUSABLE_BLOCKS_CATEGORY = 'reusable'; | ||
const ALLOWED_EMBED_VARIATIONS = [ 'core/embed' ]; | ||
|
||
export function blockAllowed( block, { onlyReusable, allowReusable } ) { | ||
const { id, category } = block; | ||
const isReusable = category === REUSABLE_BLOCKS_CATEGORY; | ||
|
||
if ( onlyReusable ) { | ||
return isReusable; | ||
} | ||
|
||
if ( isReusable ) { | ||
return allowReusable; | ||
} | ||
// We don't want to show all possible embed variations | ||
// as different blocks in the inserter. We'll only show a | ||
// few popular ones. | ||
return category !== 'embed' || ALLOWED_EMBED_VARIATIONS.includes( id ); | ||
} | ||
|
||
export function filterInserterItems( | ||
items, | ||
{ onlyReusable = false, allowReusable = false } = {} | ||
) { | ||
return items.filter( ( block ) => | ||
blockAllowed( block, { onlyReusable, allowReusable } ) | ||
); | ||
} |