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

Add getCategoryWithFallbacks API function to @wordpress/blocks #23695

Closed
wants to merge 1 commit into from
Closed

Add getCategoryWithFallbacks API function to @wordpress/blocks #23695

wants to merge 1 commit into from

Conversation

fullofcaffeine
Copy link
Member

@fullofcaffeine fullofcaffeine commented Jul 4, 2020

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:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

- Can be used to provide a fallback mechanism assigning a category that's changed to a block, by passing al the categories from newest to oldest
- Allows for graceful degradation of block categories when used to assign the block category by only returning the first available category in the store
@gziolo
Copy link
Member

gziolo commented Jul 4, 2020

There is going to be Dev Note published that will cover changes to the list of default categories and how to approach the migration process. If you stick to old names then they will be automatically converted. If you want to use new names the there is going to be a conditional check necessary to detect whether a new category name is present. In addition to that, category is no longer mandatory so I’m not sure that the proposed functionality is necessary in the blocks package.

@fullofcaffeine
Copy link
Member Author

@gziolo As per our Slack convo, I'm closing this PR in favor of adding the function in the respective repositories. Thanks!

@fullofcaffeine fullofcaffeine deleted the add/get-category-with-fallbacks-to-blocks-api branch July 7, 2020 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants