Add getCategoryWithFallbacks API function to @wordpress/blocks
#23695
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This adds a function to the
@wordpress/blocks
's public API that can be used to provide graceful degradation of block categories when used to assign the block category by only returning the first available category in the store from an array of categories passed to it.Related to pbAok1-18e-p2 and Automattic/wp-calypso#43670 (comment).
Why?
Block categories have been changed and might change again. It makes sense to have a utility function that is aware of the available categories for the current block editor environment and returns only the (first) one available from the list provided. The alternative is to have this function duplicated across many repositories (almost all repos that implement blocks).
Let me know if this is the right place for it :)
How has this been tested?
I've tested by linking the local dev package to a local WordPress instance running modified calypso/jetpack branches, then consumed this function and used it to set the block's categories and verified that it was working as expected.
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: