Skip to content

Full Site Editing: Add Support for Templates Default and Custom Titles and Descriptions (JS Side)#27038

Merged
Copons merged 6 commits into
masterfrom
update/use-default-template-types
Nov 20, 2020
Merged

Full Site Editing: Add Support for Templates Default and Custom Titles and Descriptions (JS Side)#27038
Copons merged 6 commits into
masterfrom
update/use-default-template-types

Conversation

@Copons
Copy link
Copy Markdown
Contributor

@Copons Copons commented Nov 17, 2020

Description

This PR was originally part of #26636 and it depends on #27036.

  • New templates created from the Site Editor sidebar will also automatically use the default template types definitions, and will be saved as draft. They will become published once saved the first time.
  • The default definitions are used across the Site Editor as a fallback for templates without title or excerpt.
  • Converted the getTemplateInfo utility into the getTemplateInfo selector, since it relies on the core/editor state.

How has this been tested?

These test steps take advantage of #27034.
If it's not merged yet, just skip the steps related to the "wp-admin Templates list".

  1. Open the Site Editor. Behind the scenes, all theme's and plugins' templates will be converted into new wp_template items of status auto-draft; there might be duplicates for unrelated reasons.
  2. Open the wp-admin Templates list (/edit.php?post_type=wp_template).
  3. Make sure it shows the following columns: title, slug, description, status.
  4. Notice it shows also auto-draft templates. Feel free to wipe this list clean by moving all templates to trash, and permanently delete them.
  5. Open the Site Editor (if you wiped the templates, now it will generate new ones, hopefully without duplicates).
  6. Open the sidebar, and navigate into the Templates menu.
  7. Make sure the items use the title and description as provided by the definitions list introduced in this PR.
  8. Create a new template with the New Template dropdown (click on + in the Templates menu).
  9. Make sure the items in the New Template dropdown use the definitions list.
  10. Make sure the new template's name is the one provided by the definitions list (it should match the one from the New Template dropdown).
  11. Check in the sidebar that the new template shows up (it might be easier to just look in the All Templates menu), it has the correct title and description, and is marked as "[Draft]".
  12. Click on "Update Design" (it might be disabled: do some changes to enable it).
  13. Review the changes, and make sure the template is listed with the correct title.
  14. The template has now been published, so make sure it lost the "[Draft]" label.
  15. Open the wp-admin Templates list, and make sure the new template shows up with the right title, description, and status.

Screenshots

Screenshot 2020-10-26 at 17 44 59

Screenshot 2020-10-26 at 17 44 41

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.

@Copons Copons self-assigned this Nov 17, 2020
@Copons Copons changed the title Update/use default template types Full Site Editing: Add Support for Templates Default and Custom Titles and Descriptions (JS Side) Nov 17, 2020
@Copons Copons marked this pull request as ready for review November 17, 2020 13:21
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 17, 2020

Size Change: +660 B (0%)

Total Size: 1.19 MB

Filename Size Change
build/annotations/index.js 3.8 kB +1 B
build/block-editor/index.js 133 kB +10 B (0%)
build/block-library/index.js 147 kB +8 B (0%)
build/blocks/index.js 48 kB +2 B (0%)
build/components/index.js 172 kB +1 B
build/core-data/index.js 14.8 kB +1 B
build/edit-site/index.js 23.1 kB -59 B (0%)
build/edit-site/style-rtl.css 3.86 kB +11 B (0%)
build/edit-site/style.css 3.86 kB +11 B (0%)
build/edit-widgets/index.js 26.4 kB -2 B (0%)
build/editor/index.js 43.3 kB +672 B (1%)
build/keyboard-shortcuts/index.js 2.54 kB +2 B (0%)
build/rich-text/index.js 13.4 kB +2 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 664 B 0 B
build/block-directory/index.js 8.72 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/style-rtl.css 11.3 kB 0 B
build/block-editor/style.css 11.3 kB 0 B
build/block-library/editor-rtl.css 8.95 kB 0 B
build/block-library/editor.css 8.95 kB 0 B
build/block-library/style-rtl.css 8.1 kB 0 B
build/block-library/style.css 8.1 kB 0 B
build/block-library/theme-rtl.css 792 B 0 B
build/block-library/theme.css 793 B 0 B
build/block-serialization-default-parser/index.js 1.87 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/components/style.css 15.3 kB 0 B
build/compose/index.js 9.95 kB 0 B
build/data-controls/index.js 827 B 0 B
build/data/index.js 8.8 kB 0 B
build/date/index.js 11.2 kB 0 B
build/deprecated/index.js 768 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.92 kB 0 B
build/edit-navigation/index.js 11.2 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.45 kB 0 B
build/edit-post/style.css 6.44 kB 0 B
build/edit-widgets/style-rtl.css 3.13 kB 0 B
build/edit-widgets/style.css 3.13 kB 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/element/index.js 4.62 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.86 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.16 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.1 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.81 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 3.06 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.05 kB 0 B
build/viewport/index.js 1.86 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@Copons Copons force-pushed the update/default-template-types branch from 4fbac9c to 8c907a6 Compare November 17, 2020 17:59
Copy link
Copy Markdown
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

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

looks pretty solid to me, just left a few comments

Comment thread packages/edit-site/src/components/editor/index.js
Comment thread packages/edit-site/src/store/selectors.js Outdated
key
);
const { title: templateTitle } = select(
'core/edit-site'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels really weird to me -- are we sure this package can rely on the edit site store being available all the time? I wonder if there are scenarios where it could be used when the store hasn't been registered

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is an early return for ! select( 'core/edit-site' ) a few lines above. 🙂

Anyhow, I'm not happy with this as well.
I would absolutely love to move the getTemplateInfo selector elsewhere shared (e.g. core/editor).
However, there is an inconsistency between edit-post and edit-site initialization that prevent this, as settings initialized in PHP are fed to core/editor in edit-post, and core/edit-site in edit-site.

My opinion is that we should reduce/remove all inconsistencies between the different editor inits, but this is not the place.

I should probably add a todo comment explaining what happens here.

Copy link
Copy Markdown
Member

@gziolo gziolo Nov 18, 2020

Choose a reason for hiding this comment

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

It creates a cyclic dependency between edit-site and editor that should be avoided. We have just landed API extensions to @wordpress/data (#26655) that is going to prevent this type of reference by using direct store definition imports. Would it be possible to pass entityRecordTitle as part of the record.title prop passed to EntityRecordItem instead or something along those lines?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This originates from 2 different entities quirks:

What we want is for templates to use the default title whenever possible.
This normally would mean to create them with the default title (which is what we do), but then when the template becomes an entity, given it is an auto-draft, it loses the title.
This in turn requires us to have that getTemplateInfo selector which gives templates back their intended title (or handles the various fallbacks).

The EntityRecordItem is, as far as I can see, the only place that would need this "title fix", as it's not tied to any specific entity.
But its part of the editor package, which shouldn't need edit-site.
The post editor initializes its settings into core/editor, while the Site Editor into core/edit-site. I really don't like it, but it's how it is right now.

In one of my previous attempts, I tried adding an exception to the entities actions: if it's a wp_template, don't clear the title.
But that was a bit smelly, and eventually I decided to avoid introducing exceptions in such a key part of the entire app, without understanding all the possible consequences.

The only other option (as far as I can see) it's to handle it whenever needed, which... is where we are right now! 😄

Looking at EntityRecordItem, I don't see a good way to pass the "generated" template title without introducing exceptions to the dirty entities, which is something I'd rather avoid.

On the other hand, I'm exploring what it would take to update the Site Editor init to register the default template types to the core/editor settings instead of the core/edit-site's, removing its unnecessary dependency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've pushed an experimental commit to demonstrate what I mean with "moving defaultTemplateTypes to core/editor: 827464c

Specifically this is where it happens:
827464c#diff-53f39da7a5f1f996f5359a2dd7b2747fb3d60a494523dd73dba946fab8e82592R115-R119

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On the other hand, I'm exploring what it would take to update the Site Editor init to register the default template types to the core/editor settings instead of the core/edit-site's, removing its unnecessary dependency.

It's not optimal and it's hacky. But I don't think we have a better option due to the way of how different editors initialized. ✅

Copy link
Copy Markdown
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

This PR probably requires a rebase on top of update/default-template-types as it includes all changes applied there.

@Copons Copons force-pushed the update/default-template-types branch from 8c907a6 to 7eef161 Compare November 18, 2020 10:48
@Copons Copons force-pushed the update/use-default-template-types branch from f7f7527 to 689eccb Compare November 18, 2020 10:51
@Copons Copons force-pushed the update/default-template-types branch from 7eef161 to 61eae5b Compare November 19, 2020 10:49
@Copons Copons force-pushed the update/use-default-template-types branch from 827464c to 99bf728 Compare November 19, 2020 11:07
Base automatically changed from update/default-template-types to master November 19, 2020 15:00
@Copons Copons force-pushed the update/use-default-template-types branch from 99bf728 to 226ab3c Compare November 19, 2020 15:04
Comment thread packages/edit-site/src/components/header/index.js Outdated
Copy link
Copy Markdown
Member

@david-szabo97 david-szabo97 left a comment

Choose a reason for hiding this comment

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

Works well and tests are passing! ✅

@Copons Copons force-pushed the update/use-default-template-types branch from 226ab3c to e7f9af4 Compare November 19, 2020 17:50

- `string`: Post type.

<a name="getDefaultTemplateType" href="#getDefaultTemplateType">#</a> **getDefaultTemplateType**
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should all three new API methods be marked unstable or even experimental to give them some time to mature? This way they won't be exposed in docs until we are 100% sure that we can support them indefinitely 😃

@adamziel has recently extracted store handling related to reusable blocks to its own store and moved to an isolated package. It's something that should be discussed in this context as well. I'd like to get some feedback from @youknowriad who has the best overview how editor packages are architected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are totally right.
These selectors originated in edit-site where we work under the assumption that everything is experimental, and didn't think of explicitly marking them as such when moving them here.
I'll definitely mark them as __experimental if we decide that this approach is the right one!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Eh, I went ahead and done it anyway. 😄

TIL about the reusable-blocks package!
It sounds like a very neat idea, that in our case could be used to store all FSE-related functions that might be used in different editors and contexts.

As it always is, naming is hard!
templates sounds clean and nifty, but FSE is not just templates (there are also... template parts! 😄 )
full-site-editing would be catch-all, but it sounds slightly awkward to me.

Also, I've never created a new package.
Is there anything I should know to make it work smoothly?
How would publishing it to npm work?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should help with a new package:
https://github.com/WordPress/gutenberg/tree/master/packages#creating-a-new-package

You can wait a bit more with that step. It might help to better understand what scope such package would have. We have also @wordpress/media-utils that is catch it all for media related code 😄

Publishing is automated, so you don't have to worry about it other than set some version lower than 1.0 to make it clear that it's all experimental.

I'm checking #25859 to learn if there is anything that isn't included in the docs but I think everything else will catch CI. I assume you will have to run npm run docs:build to expose README in the documentation portal at https://developer.wordpress.org/block-editor/packages/. It should add a section like this in the manifest file:

gutenberg/docs/manifest.json

Lines 1670 to 1675 in 3aeb89e

{
"title": "@wordpress/list-reusable-blocks",
"slug": "packages-list-reusable-blocks",
"markdown_source": "../packages/list-reusable-blocks/README.md",
"parent": "packages"
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @gziolo !
I've started working on it in #27148 (not ready and not working btw 😄) mostly to learn more about how packages work and interact between each other.

I think right now there isn't that much stuff to justify a new package, but maybe in the future things will change. 👍

Copy link
Copy Markdown
Member

@gziolo gziolo Nov 20, 2020

Choose a reason for hiding this comment

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

Yes, it's fine to explore and keep the branch ready for the package extraction 😄

Comment thread packages/editor/src/components/entities-saved-states/entity-record-item.js Outdated
Copy link
Copy Markdown
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Thank you for applying updates 👍

@Copons Copons merged commit 3aeb89e into master Nov 20, 2020
@Copons Copons deleted the update/use-default-template-types branch November 20, 2020 12:43
@github-actions github-actions Bot added this to the Gutenberg 9.5 milestone Nov 20, 2020
@youknowriad
Copy link
Copy Markdown
Contributor

youknowriad commented Oct 28, 2022

I know it's been a long time but I wanted to share some thoughts here as I stumbled on this code :)

This PR added a dependency from edit-site to editor package and from block-library to editor package. If I'm understanding properly, this requirement is because we want to add "configuration" (default template parts) to the template part block and that block is useful in both the post editor (template mode) and the site editor so it had been decided that the "editor" package would be the common denominator here to add "block configuration".

The issue conceptually for me is that the "editor" package is not meant as a package to hold block configurations, it's actually a package to hold reusable components to build "post editors" (not even site editors), basically the edit-site should ideally not depend on it at all.

I think it's probably fine for now as is, but I guess the ideal scenario is to have a getDefaultTemplates() getDefaultTemplateParts as part of the core-data package. (so potentially a REST API).

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.

5 participants