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

Updated default block categories for Automattic blocks #43198

Closed
5 of 6 tasks
simison opened this issue Jun 11, 2020 · 5 comments
Closed
5 of 6 tasks

Updated default block categories for Automattic blocks #43198

simison opened this issue Jun 11, 2020 · 5 comments
Assignees
Labels
[Goal] Gutenberg Working towards full integration with Gutenberg [Type] Task

Comments

@simison
Copy link
Member

simison commented Jun 11, 2020

In Gutenberg 8.3.0 we have updated default block categories (WordPress/gutenberg#19279). Those are now running on edge sites, and within a week on production. These new categories are now in production.

We'll need to match Automattic block categories with new categories.

We'll also need to keep supporting old default categories for Atomic sites which might not run Gutenberg.

The tasks needs:

*We announced this initiative and asked for feedback here: pbAok1-18e-p2

Screenshots

The goal is just to illustrate what the change is about and how it reflects in the UI. If you'd like to know all categories that have been changed, check the PRs linked above.

image-compare (Jetpack)

GB with legacy categories GB with updated categories
image-compare-old-gb image-compare-new-gb

a8c/layout-grid (block-experiments)

GB with legacy categories GB with updated categories
layout-grid-block-exp-old-gb layout-grid-block-exp-new-gb
@sirreal
Copy link
Member

sirreal commented Jun 12, 2020

Gutenberg ships with some compatibility mappings (PHP and JS) that will ensure legacy categories aren't broken.

I'm slightly more concerned about using the new category names where we may not be on a recent editor version. I did some quick testing and it suggests if categories are updated before the plugin, the block won't be registered. Instead, you'll see a consol error like The block "my-block/name" must have a registered category.

It may be best to go slow on this change. Legacy categories are compatible with updated categories, but updated categories are not compatible with the legacy ones.

@sirreal
Copy link
Member

sirreal commented Jun 12, 2020

I asked if there are recommendations about how block authors should handle this in core-editor slack: https://wordpress.slack.com/archives/C02QB2JS7/p1591974296075900

@sirreal sirreal added the [Goal] Gutenberg Working towards full integration with Gutenberg label Jun 12, 2020
@sirreal
Copy link
Member

sirreal commented Jun 12, 2020

Here's the recommendation: WordPress/gutenberg#19279 (comment)

Namely, check if the category exists before you use it:

var hasFormattingCategory = wp.blocks.getCategories().some( function( category ) {
   return category.slug === 'formatting';
} );

wp.blocks.registerBlockType( 'my-plugin/my-block', {
   category: hasFormattingCategory ? 'formatting' : 'media',
} );

Note that example checks for a legacy category. I'd have expected to check for the new category and fallback to the legacy category otherwise.

@richtabor
Copy link

richtabor commented Jun 22, 2020

var hasFormattingCategory = wp.blocks.getCategories().some( function( category ) {
   return category.slug === 'formatting';
} );

wp.blocks.registerBlockType( 'my-plugin/my-block', {
   category: hasFormattingCategory ? 'formatting' : 'media',
} );

This is what we're doing in CoBlocks (godaddy-wordpress/coblocks#1535); looking to go out in this week's release.

fullofcaffeine added a commit that referenced this issue Jul 3, 2020
Context: #43198

- Also add a helper function that can be used to check if old category names are still being used, and fallback to the old name if so. This should ideally be used in a ternary expression while setting the category name for blocks to provide the fallback old category name in order to support WP environments with older versions of Gutenberg.
- Legacy categories were explicitly set to the new updated ones, following this example: https://github.com/WordPress/gutenberg/blob/84df4bd6082e7793a2befddb2a652cb42f445d21/packages/blocks/src/api/registration.js#L131-L135
- Some blocks might not have followed the example above and might have been moved to a category that made more sense for them
fullofcaffeine added a commit that referenced this issue Jul 7, 2020
Context: #43198

- Also add a helper function that can be used to check if old category names are still being used, and fallback to the old name if so. This should ideally be used in a ternary expression while setting the category name for blocks to provide the fallback old category name in order to support WP environments with older versions of Gutenberg.
- Legacy categories were explicitly set to the new updated ones, following this example: https://github.com/WordPress/gutenberg/blob/84df4bd6082e7793a2befddb2a652cb42f445d21/packages/blocks/src/api/registration.js#L131-L135
- Some blocks might not have followed the example above and might have been moved to a category that made more sense for them
fullofcaffeine added a commit that referenced this issue Jul 13, 2020
Context: #43198.

- Also add a helper function for FSE blocks that can be used to check if old category names exist in the store and fall-backs to an older version(s) otherwise. This function should be used when the updated category is a completely new category being introduced by a new version of Gutenberg. You then pass this new category + the older categorie(s) that will be tried in sequence if the previous one was not found.
- Tweaked the FSE Jest configuration to support TypeScript.
fullofcaffeine added a commit that referenced this issue Jul 14, 2020
Context: #43198.

- Also add a helper function for FSE blocks that can be used to check if old category names exist in the store and fall-backs to an older version(s) otherwise. This function should be used when the updated category is a completely new category being introduced by a new version of Gutenberg. You then pass this new category + the older categorie(s) that will be tried in sequence if the previous one was not found.
- Tweaked the FSE Jest configuration to support TypeScript.
fullofcaffeine added a commit that referenced this issue Jul 15, 2020
Context: #43198.

- Also add a helper function for FSE blocks that can be used to check if old category names exist in the store and fall-backs to an older version(s) otherwise. This function should be used when the updated category is a completely new category being introduced by a new version of Gutenberg. You then pass this new category + the older categorie(s) that will be tried in sequence if the previous one was not found.
- Tweaked the FSE Jest configuration to support TypeScript.
fullofcaffeine added a commit that referenced this issue Jul 15, 2020
* Change the category of FSE blocks from legacy to the updated ones

Context: #43198.

- Also add a helper function for FSE blocks that can be used to check if old category names exist in the store and fall-backs to an older version(s) otherwise. This function should be used when the updated category is a completely new category being introduced by a new version of Gutenberg. You then pass this new category + the older categorie(s) that will be tried in sequence if the previous one was not found.
- Tweaked the FSE Jest configuration to support TypeScript.

* Fix workflow logic to not run phpcs for deleted files

* Remove fallback to layout from button and login-button from premium-content

The fallback was causing these blocks to appear in older versions of Gutenberg where the `design` category was not available. Until here, all good. However, they were all er'ing upon insertion. We thought it would be better to rollback this change for now.
@sirreal
Copy link
Member

sirreal commented Jul 21, 2020

With Automattic/block-experiments#110 handed off and everything else merged, I think we're good to close this. Thanks @fullofcaffeine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Goal] Gutenberg Working towards full integration with Gutenberg [Type] Task
Projects
None yet
Development

No branches or pull requests

6 participants