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

Block Library: Move supports to block.json files for core blocks #22422

Merged
merged 8 commits into from
May 20, 2020

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented May 18, 2020

Description

I still consider breaking down this PR into smaller tasks because it contains the following refactorings:

  • Moves supports to block.json files for core blocks
  • Moves parents to block.json files for core blocks
  • Adds a default variation with initial attributes set to translatable strings to Search block to make the block definition static
  • Introduces block.json for the following blocks:
    • Navigation
    • Search
  • Removes the script that generates server-registered.json to use with integration tests and replaces it with the data loaded from block.json files

How has this been tested?

npm run test-unit
npm run test-e2e

Manually tested that Navigation and Search block works as before.

Types of changes

Refactoring

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.

@gziolo gziolo self-assigned this May 18, 2020
@gziolo gziolo added [Package] Block library /packages/block-library [Type] Task Issues or PRs that have been broken down into an individual action to take labels May 18, 2020
@github-actions
Copy link

github-actions bot commented May 18, 2020

Size Change: +45 B (0%)

Total Size: 1.11 MB

Filename Size Change
build/block-library/index.js 119 kB +45 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.02 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.93 kB 0 B
build/block-directory/style-rtl.css 790 B 0 B
build/block-directory/style.css 791 B 0 B
build/block-editor/index.js 105 kB 0 B
build/block-editor/style-rtl.css 10.8 kB 0 B
build/block-editor/style.css 10.8 kB 0 B
build/block-library/editor-rtl.css 7.22 kB 0 B
build/block-library/editor.css 7.22 kB 0 B
build/block-library/style-rtl.css 7.48 kB 0 B
build/block-library/style.css 7.48 kB 0 B
build/block-library/theme-rtl.css 683 B 0 B
build/block-library/theme.css 685 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 180 kB 0 B
build/components/style-rtl.css 17.1 kB 0 B
build/components/style.css 17.1 kB 0 B
build/compose/index.js 9.24 kB 0 B
build/core-data/index.js 11.4 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.42 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.11 kB 0 B
build/edit-navigation/index.js 6.6 kB 0 B
build/edit-navigation/style-rtl.css 857 B 0 B
build/edit-navigation/style.css 856 B 0 B
build/edit-post/index.js 302 kB 0 B
build/edit-post/style-rtl.css 12.2 kB 0 B
build/edit-post/style.css 12.2 kB 0 B
build/edit-site/index.js 12.8 kB 0 B
build/edit-site/style-rtl.css 5.22 kB 0 B
build/edit-site/style.css 5.22 kB 0 B
build/edit-widgets/index.js 7.73 kB 0 B
build/edit-widgets/style-rtl.css 4.59 kB 0 B
build/edit-widgets/style.css 4.59 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/editor/index.js 44.3 kB 0 B
build/editor/style-rtl.css 5.07 kB 0 B
build/editor/style.css 5.08 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.64 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.13 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 5.29 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 14.8 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.02 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@gziolo gziolo requested review from aduth, oandregal and youknowriad May 18, 2020 14:43
@gziolo gziolo force-pushed the update/block-json-supports branch from e271143 to 815cca2 Compare May 18, 2020 16:04
Copy link
Member

@ZebulanStanphill ZebulanStanphill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any mistakes in the block.json files, so those look good to go.

The // TODO: Decide how to handle it. comments seem rather vague to me. I think we should make them a bit more descriptive if we're not going to resolve them in this PR.

@gziolo
Copy link
Member Author

gziolo commented May 19, 2020

The // TODO: Decide how to handle it. comments seem rather vague to me. I think we should make them a bit more descriptive if we're not going to resolve them in this PR.

I'm going to remove them and open an issue with a list to address it separately. It isn't clear to me why it can't be handled in the place that handles the supports flag instead.

@gziolo gziolo changed the title Update/block json supports Block Library: Move supports to block.json files for core blocks May 19, 2020
@gziolo gziolo force-pushed the update/block-json-supports branch from 815cca2 to 68c7157 Compare May 19, 2020 17:37
@gziolo
Copy link
Member Author

gziolo commented May 19, 2020

The // TODO: Decide how to handle it. comments seem rather vague to me. I think we should make them a bit more descriptive if we're not going to resolve them in this PR.

I'm going to remove them and open an issue with a list to address it separately. It isn't clear to me why it can't be handled in the place that handles the supports flag instead.

Blocks that should be tackled separately because of the condition in supports:

__experimentalColor: Platform.OS === 'web' && { gradients: true },

__experimentalColor: Platform.OS === 'web' && { gradients: true },

__experimentalColor: Platform.OS === 'web',

__experimentalColor: Platform.OS === 'web' && { gradients: true },

__experimentalColor: Platform.OS === 'web',

With that, I can remove those comments :)

@gziolo gziolo force-pushed the update/block-json-supports branch from 68c7157 to 5a39992 Compare May 19, 2020 17:55
@gziolo gziolo mentioned this pull request May 19, 2020
6 tasks
@gziolo
Copy link
Member Author

gziolo commented May 19, 2020

@Soean and @ZebulanStanphill – thanks for your feedback, I addressed both issues.

@gziolo
Copy link
Member Author

gziolo commented May 19, 2020

There is one more thing to clarify since I mentioned that I could split this PR into smaller parts. Given that I had to rebase this PR already, I would be more than happy to land all changes in one batch given how they all are interconnected. In fact, this is mostly "extract and move" refactoring.

@youknowriad
Copy link
Contributor

About the mobile checks to disable the supports, I think that's probably a wrong approach, instead they should update the hooks to "not apply" if needed or apply differently and not disable the support entirely.

@gziolo
Copy link
Member Author

gziolo commented May 20, 2020

About the mobile checks to disable the supports, I think that's probably a wrong approach, instead they should update the hooks to "not apply" if needed or apply differently and not disable the support entirely.

I'll propose that as an independent PR.

isDefault: true,
attributes: { buttonText: __( 'Search' ), label: __( 'Search' ) },
},
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting usage of "Variations" :)

Copy link
Member Author

@gziolo gziolo May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the same approach with File block but it uses placeholders so it loses the attribute that is sourced from HTML after save and refresh because it isn't stored with save method.

There are drawbacks in some cases :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note (mostly to myself) for future reference. We could try to experiment with supports: { placeholder: { type: 'media' } }. With that flag, it would show media placeholder and when saving it would serialize attributes sources from HTML as attributes serialized in HTML comment of the block. It would resolve the issue with variations. The same could work with supports: { placeholder: { type: 'variations' } } for Columns block but it would show the variations picker when save returns null.

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I see this is already approved but I have a few comments/questions about this that I wanted to share:

  • Is it the goal to replace register_block_type by register_block_type_from_metadata? The first is still used in the post_comments block.

  • variations for the search block: what if we also added placeholder for completeness? I know it's not translated yet so it's not really necessary. It's fine as it is also.

  • supports key: besides all the blocks with conditionals you mentioned, there's also the widget-area block. Can we migrate this to block.json as well?

  • I saw that we added a parent for the query-loop and query-pagination blocks. It makes sense to me but also changes the behavior so I wanted to confirm this was intentional.

  • We also added html:false for search and post-tags. Not sure what's the criteria for not allowing editing the html of block so wanted to flag to confirm this is intentional.

It's fine by me if we want to do this in follow-up PRs (if they make sense).

@gziolo
Copy link
Member Author

gziolo commented May 20, 2020

  • Is it the goal to replace register_block_type by register_block_type_from_metadata? The first is still used in the post_comments block.

Yes, ideally we use register_block_type_from_metadata (which still uses register_block_type internally). New commit b5f607f comming up soon.

  • variations for the search block: what if we also added placeholder for completeness? I know it's not translated yet so it's not really necessary. It's fine as it is also.

It's an empty string so I think it's fine to leave it as is.

  • supports key: besides all the blocks with conditionals you mentioned, there's also the widget-area block. Can we migrate this to block.json as well?

It was added recently, it's hard to keep up but here you go 9ba3e75.

  • I saw that we added a parent for the query-loop and query-pagination blocks. It makes sense to me but also changes the behavior so I wanted to confirm this was intentional.

It might be a rebase issue, I will double-check. It was in the JS file before. See 0490313.

  • We also added html:false for search and post-tags. Not sure what's the criteria for not allowing editing the html of block so wanted to flag to confirm this is intentional.

I think it's expected since those blocks don't define save so it's defaulting to null. There is nothing to edit in HTML mode :)

It's fine by me if we want to do this in follow-up PRs (if they make sense).

I think I addressed all those points :)

@gziolo
Copy link
Member Author

gziolo commented May 20, 2020

I opened #22502 to refactor the remaining blocks listed in #22422 (comment).

@gziolo
Copy link
Member Author

gziolo commented May 20, 2020

Thank you all for help 💯

@gziolo gziolo merged commit d26842b into master May 20, 2020
@gziolo gziolo deleted the update/block-json-supports branch May 20, 2020 19:35
@github-actions github-actions bot added this to the Gutenberg 8.2 milestone May 20, 2020
@ellatrix ellatrix mentioned this pull request Jun 16, 2020
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block library /packages/block-library [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants