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: Delete template action. #31678

Merged
merged 8 commits into from
May 19, 2021
Merged

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented May 10, 2021

Part of #31076.

This PR implements a delete action for page templates.

For now, the UI is a simple action link like the other actions (edit and new), in the future we may iterate on the design.

How has this been tested?

I verified I could delete user-created templates.

@jorgefilipecosta jorgefilipecosta changed the title Add. Delete template action. Add: Delete template action. May 10, 2021
@jorgefilipecosta jorgefilipecosta added the [Feature] Template Editing Mode Related to the template editor available in the Block Editor label May 10, 2021
@github-actions
Copy link

github-actions bot commented May 10, 2021

Size Change: +319 kB (+24%) 🚨

Total Size: 1.62 MB

Filename Size Change
build/annotations/index.js 2.93 kB +1 B (0%)
build/block-directory/index.js 6.61 kB -1 B (0%)
build/block-directory/style-rtl.css 989 B -4 B (0%)
build/block-directory/style.css 990 B -5 B (-1%)
build/block-editor/index.js 118 kB +319 B (0%)
build/block-editor/style-rtl.css 12.8 kB -159 B (-1%)
build/block-editor/style.css 12.8 kB -162 B (-1%)
build/block-library/blocks/file/frontend.js 771 B -1 B (0%)
build/block-library/blocks/navigation-link/editor-rtl.css 633 B +16 B (+3%)
build/block-library/blocks/navigation-link/editor.css 634 B +15 B (+2%)
build/block-library/blocks/navigation/editor-rtl.css 1.54 kB +4 B (0%)
build/block-library/blocks/navigation/editor.css 1.54 kB +4 B (0%)
build/block-library/blocks/navigation/style-rtl.css 1.78 kB +74 B (+4%)
build/block-library/blocks/navigation/style.css 1.78 kB +70 B (+4%)
build/block-library/blocks/social-links/editor-rtl.css 800 B +4 B (+1%)
build/block-library/blocks/social-links/editor.css 799 B +4 B (+1%)
build/block-library/editor-rtl.css 9.92 kB +21 B (0%)
build/block-library/editor.css 9.91 kB +22 B (0%)
build/block-library/index.js 146 kB +3 B (0%)
build/block-library/style-rtl.css 10.2 kB +91 B (+1%)
build/block-library/style.css 10.3 kB +90 B (+1%)
build/block-serialization-default-parser/index.js 1.29 kB -1 B (0%)
build/block-serialization-spec-parser/index.js 3.06 kB -1 B (0%)
build/blocks/index.js 47.1 kB +1 B (0%)
build/components/index.js 188 kB -7 B (0%)
build/components/style-rtl.css 16.2 kB -182 B (-1%)
build/components/style.css 16.2 kB -181 B (-1%)
build/compose/index.js 9.95 kB +23 B (0%)
build/core-data/index.js 12.1 kB +2 B (0%)
build/customize-widgets/index.js 43.2 kB +37.2 kB (+621%) 🆘
build/customize-widgets/style-rtl.css 1.38 kB +684 B (+98%) 🆘
build/customize-widgets/style.css 1.38 kB +682 B (+98%) 🆘
build/data-controls/index.js 829 B +1 B (0%)
build/date/index.js 31.8 kB -1 B (0%)
build/edit-navigation/index.js 13.6 kB +1 B (0%)
build/edit-navigation/style-rtl.css 2.82 kB -7 B (0%)
build/edit-navigation/style.css 2.82 kB -7 B (0%)
build/edit-post/index.js 335 kB +725 B (0%)
build/edit-post/style-rtl.css 6.8 kB -39 B (-1%)
build/edit-post/style.css 6.79 kB -39 B (-1%)
build/edit-site/index.js 26 kB -7 B (0%)
build/edit-site/style-rtl.css 4.76 kB -38 B (-1%)
build/edit-site/style.css 4.75 kB -36 B (-1%)
build/edit-widgets/index.js 292 kB +279 kB (+2226%) 🆘
build/edit-widgets/style-rtl.css 3.46 kB +441 B (+15%) ⚠️
build/edit-widgets/style.css 3.47 kB +440 B (+15%) ⚠️
build/editor/index.js 38.4 kB -16 B (0%)
build/editor/style-rtl.css 3.92 kB -35 B (-1%)
build/editor/style.css 3.91 kB -37 B (-1%)
build/format-library/index.js 5.67 kB -1 B (0%)
build/hooks/index.js 1.76 kB -1 B (0%)
build/html-entities/index.js 627 B -1 B (0%)
build/i18n/index.js 3.73 kB +1 B (0%)
build/media-utils/index.js 3.08 kB +1 B (0%)
build/nux/index.js 2.31 kB +1 B (0%)
build/plugins/index.js 1.99 kB -1 B (0%)
build/primitives/index.js 1.03 kB -1 B (0%)
build/redux-routine/index.js 2.82 kB +1 B (0%)
build/reusable-blocks/index.js 2.54 kB -1 B (0%)
build/token-list/index.js 846 B -1 B (0%)
build/viewport/index.js 1.28 kB +2 B (0%)
build/widgets/index.js 1.66 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.12 kB 0 B
build/api-fetch/index.js 2.42 kB 0 B
build/autop/index.js 2.28 kB 0 B
build/blob/index.js 673 B 0 B
build/block-library/blocks/archives/editor-rtl.css 61 B 0 B
build/block-library/blocks/archives/editor.css 60 B 0 B
build/block-library/blocks/audio/editor-rtl.css 58 B 0 B
build/block-library/blocks/audio/editor.css 58 B 0 B
build/block-library/blocks/audio/style-rtl.css 112 B 0 B
build/block-library/blocks/audio/style.css 112 B 0 B
build/block-library/blocks/block/editor-rtl.css 161 B 0 B
build/block-library/blocks/block/editor.css 161 B 0 B
build/block-library/blocks/button/editor-rtl.css 475 B 0 B
build/block-library/blocks/button/editor.css 474 B 0 B
build/block-library/blocks/button/style-rtl.css 601 B 0 B
build/block-library/blocks/button/style.css 600 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 315 B 0 B
build/block-library/blocks/buttons/editor.css 315 B 0 B
build/block-library/blocks/buttons/style-rtl.css 375 B 0 B
build/block-library/blocks/buttons/style.css 375 B 0 B
build/block-library/blocks/calendar/style-rtl.css 208 B 0 B
build/block-library/blocks/calendar/style.css 208 B 0 B
build/block-library/blocks/categories/editor-rtl.css 84 B 0 B
build/block-library/blocks/categories/editor.css 83 B 0 B
build/block-library/blocks/categories/style-rtl.css 79 B 0 B
build/block-library/blocks/categories/style.css 79 B 0 B
build/block-library/blocks/code/style-rtl.css 90 B 0 B
build/block-library/blocks/code/style.css 90 B 0 B
build/block-library/blocks/columns/editor-rtl.css 190 B 0 B
build/block-library/blocks/columns/editor.css 190 B 0 B
build/block-library/blocks/columns/style-rtl.css 422 B 0 B
build/block-library/blocks/columns/style.css 422 B 0 B
build/block-library/blocks/cover/editor-rtl.css 643 B 0 B
build/block-library/blocks/cover/editor.css 645 B 0 B
build/block-library/blocks/cover/style-rtl.css 1.22 kB 0 B
build/block-library/blocks/cover/style.css 1.22 kB 0 B
build/block-library/blocks/embed/editor-rtl.css 486 B 0 B
build/block-library/blocks/embed/editor.css 486 B 0 B
build/block-library/blocks/embed/style-rtl.css 401 B 0 B
build/block-library/blocks/embed/style.css 400 B 0 B
build/block-library/blocks/file/editor-rtl.css 301 B 0 B
build/block-library/blocks/file/editor.css 300 B 0 B
build/block-library/blocks/file/style-rtl.css 255 B 0 B
build/block-library/blocks/file/style.css 255 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.45 kB 0 B
build/block-library/blocks/freeform/editor.css 2.45 kB 0 B
build/block-library/blocks/gallery/editor-rtl.css 704 B 0 B
build/block-library/blocks/gallery/editor.css 705 B 0 B
build/block-library/blocks/gallery/style-rtl.css 1.06 kB 0 B
build/block-library/blocks/gallery/style.css 1.05 kB 0 B
build/block-library/blocks/group/editor-rtl.css 160 B 0 B
build/block-library/blocks/group/editor.css 160 B 0 B
build/block-library/blocks/group/style-rtl.css 57 B 0 B
build/block-library/blocks/group/style.css 57 B 0 B
build/block-library/blocks/heading/editor-rtl.css 129 B 0 B
build/block-library/blocks/heading/editor.css 129 B 0 B
build/block-library/blocks/heading/style-rtl.css 76 B 0 B
build/block-library/blocks/heading/style.css 76 B 0 B
build/block-library/blocks/home-link/style-rtl.css 259 B 0 B
build/block-library/blocks/home-link/style.css 259 B 0 B
build/block-library/blocks/html/editor-rtl.css 281 B 0 B
build/block-library/blocks/html/editor.css 281 B 0 B
build/block-library/blocks/image/editor-rtl.css 717 B 0 B
build/block-library/blocks/image/editor.css 716 B 0 B
build/block-library/blocks/image/style-rtl.css 481 B 0 B
build/block-library/blocks/image/style.css 485 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 281 B 0 B
build/block-library/blocks/latest-comments/style.css 282 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B 0 B
build/block-library/blocks/latest-posts/editor.css 137 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 523 B 0 B
build/block-library/blocks/latest-posts/style.css 522 B 0 B
build/block-library/blocks/legacy-widget/editor-rtl.css 557 B 0 B
build/block-library/blocks/legacy-widget/editor.css 557 B 0 B
build/block-library/blocks/list/style-rtl.css 63 B 0 B
build/block-library/blocks/list/style.css 63 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 176 B 0 B
build/block-library/blocks/media-text/editor.css 176 B 0 B
build/block-library/blocks/media-text/style-rtl.css 492 B 0 B
build/block-library/blocks/media-text/style.css 489 B 0 B
build/block-library/blocks/more/editor-rtl.css 434 B 0 B
build/block-library/blocks/more/editor.css 434 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B 0 B
build/block-library/blocks/navigation-link/style.css 94 B 0 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B 0 B
build/block-library/blocks/nextpage/editor.css 395 B 0 B
build/block-library/blocks/page-list/editor-rtl.css 310 B 0 B
build/block-library/blocks/page-list/editor.css 311 B 0 B
build/block-library/blocks/page-list/style-rtl.css 233 B 0 B
build/block-library/blocks/page-list/style.css 233 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B 0 B
build/block-library/blocks/paragraph/editor.css 157 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 247 B 0 B
build/block-library/blocks/paragraph/style.css 248 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 209 B 0 B
build/block-library/blocks/post-author/editor.css 209 B 0 B
build/block-library/blocks/post-author/style-rtl.css 183 B 0 B
build/block-library/blocks/post-author/style.css 184 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B 0 B
build/block-library/blocks/post-comments-form/style.css 140 B 0 B
build/block-library/blocks/post-comments/style-rtl.css 360 B 0 B
build/block-library/blocks/post-comments/style.css 359 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 139 B 0 B
build/block-library/blocks/post-content/editor.css 139 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B 0 B
build/block-library/blocks/post-excerpt/editor.css 73 B 0 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B 0 B
build/block-library/blocks/post-excerpt/style.css 69 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 338 B 0 B
build/block-library/blocks/post-featured-image/editor.css 338 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 119 B 0 B
build/block-library/blocks/post-featured-image/style.css 119 B 0 B
build/block-library/blocks/post-title/style-rtl.css 60 B 0 B
build/block-library/blocks/post-title/style.css 60 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 103 B 0 B
build/block-library/blocks/preformatted/style.css 103 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 183 B 0 B
build/block-library/blocks/pullquote/editor.css 183 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 318 B 0 B
build/block-library/blocks/pullquote/style.css 318 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 83 B 0 B
build/block-library/blocks/query-loop/editor.css 82 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 315 B 0 B
build/block-library/blocks/query-loop/style.css 317 B 0 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B 0 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B 0 B
build/block-library/blocks/query-pagination/editor-rtl.css 270 B 0 B
build/block-library/blocks/query-pagination/editor.css 262 B 0 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B 0 B
build/block-library/blocks/query-pagination/style.css 168 B 0 B
build/block-library/blocks/query-title/editor-rtl.css 86 B 0 B
build/block-library/blocks/query-title/editor.css 86 B 0 B
build/block-library/blocks/query/editor-rtl.css 131 B 0 B
build/block-library/blocks/query/editor.css 132 B 0 B
build/block-library/blocks/quote/style-rtl.css 169 B 0 B
build/block-library/blocks/quote/style.css 169 B 0 B
build/block-library/blocks/rss/editor-rtl.css 201 B 0 B
build/block-library/blocks/rss/editor.css 202 B 0 B
build/block-library/blocks/rss/style-rtl.css 290 B 0 B
build/block-library/blocks/rss/style.css 290 B 0 B
build/block-library/blocks/search/editor-rtl.css 189 B 0 B
build/block-library/blocks/search/editor.css 189 B 0 B
build/block-library/blocks/search/style-rtl.css 359 B 0 B
build/block-library/blocks/search/style.css 362 B 0 B
build/block-library/blocks/separator/editor-rtl.css 99 B 0 B
build/block-library/blocks/separator/editor.css 99 B 0 B
build/block-library/blocks/separator/style-rtl.css 251 B 0 B
build/block-library/blocks/separator/style.css 251 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 512 B 0 B
build/block-library/blocks/shortcode/editor.css 512 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 440 B 0 B
build/block-library/blocks/site-logo/editor.css 441 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 154 B 0 B
build/block-library/blocks/site-logo/style.css 154 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 164 B 0 B
build/block-library/blocks/social-link/editor.css 165 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB 0 B
build/block-library/blocks/social-links/style.css 1.33 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 308 B 0 B
build/block-library/blocks/spacer/editor.css 308 B 0 B
build/block-library/blocks/spacer/style-rtl.css 48 B 0 B
build/block-library/blocks/spacer/style.css 48 B 0 B
build/block-library/blocks/table/editor-rtl.css 478 B 0 B
build/block-library/blocks/table/editor.css 478 B 0 B
build/block-library/blocks/table/style-rtl.css 485 B 0 B
build/block-library/blocks/table/style.css 485 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 118 B 0 B
build/block-library/blocks/tag-cloud/editor.css 118 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 94 B 0 B
build/block-library/blocks/tag-cloud/style.css 94 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 551 B 0 B
build/block-library/blocks/template-part/editor.css 550 B 0 B
build/block-library/blocks/term-description/editor-rtl.css 90 B 0 B
build/block-library/blocks/term-description/editor.css 90 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B 0 B
build/block-library/blocks/text-columns/editor.css 95 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 166 B 0 B
build/block-library/blocks/text-columns/style.css 166 B 0 B
build/block-library/blocks/verse/style-rtl.css 87 B 0 B
build/block-library/blocks/verse/style.css 87 B 0 B
build/block-library/blocks/video/editor-rtl.css 569 B 0 B
build/block-library/blocks/video/editor.css 570 B 0 B
build/block-library/blocks/video/style-rtl.css 169 B 0 B
build/block-library/blocks/video/style.css 169 B 0 B
build/block-library/common-rtl.css 1.26 kB 0 B
build/block-library/common.css 1.26 kB 0 B
build/block-library/reset-rtl.css 506 B 0 B
build/block-library/reset.css 507 B 0 B
build/block-library/theme-rtl.css 692 B 0 B
build/block-library/theme.css 693 B 0 B
build/data/index.js 7.23 kB 0 B
build/deprecated/index.js 739 B 0 B
build/dom-ready/index.js 577 B 0 B
build/dom/index.js 4.62 kB 0 B
build/edit-post/classic-rtl.css 454 B 0 B
build/edit-post/classic.css 454 B 0 B
build/element/index.js 3.44 kB 0 B
build/escape-html/index.js 739 B 0 B
build/format-library/style-rtl.css 637 B 0 B
build/format-library/style.css 639 B 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 1.65 kB 0 B
build/keycodes/index.js 1.43 kB 0 B
build/list-reusable-blocks/index.js 2.06 kB 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/navigation/index.js 2.85 kB 0 B
build/notices/index.js 1.07 kB 0 B
build/nux/style-rtl.css 718 B 0 B
build/nux/style.css 716 B 0 B
build/priority-queue/index.js 791 B 0 B
build/react-i18n/index.js 923 B 0 B
build/reusable-blocks/style-rtl.css 225 B 0 B
build/reusable-blocks/style.css 225 B 0 B
build/rich-text/index.js 10.7 kB 0 B
build/server-side-render/index.js 1.64 kB 0 B
build/shortcode/index.js 1.68 kB 0 B
build/url/index.js 1.95 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.24 kB 0 B

compressed-size-action

);
updateEditorSettings( {
...editorSettings,
availableTemplates: newAvailableTemplates,
Copy link
Contributor

Choose a reason for hiding this comment

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

When creating new templates (new link there), we don't update this setting at the moment, it seems we should have that covered similarly. I think ideally, this should be a REST API request but right now patching the setting might be ok.

Also, I noticed that editorSettitngs is only used in the event handler which means we don't need to return it in useSelect, we can just use the selector with the new syntax

const { getSettings ) = useSelect( 'core/block-editor' );

Copy link
Member Author

Choose a reason for hiding this comment

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

his should be a REST API request but right now patching the setting might be ok.

Right now there are filters in the core that allow plugins and themes to select which templates are available to select by the user on a post type or even a specific post. We could not just show make a rest request on the templates post type. I think we would need a specific endpoint that returns templates available for a given post where the existing core filters are executed.

Copy link
Contributor

@carolinan carolinan left a comment

Choose a reason for hiding this comment

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

When I create a new template with the new link, save and return to the block editor,
a different template than the one I created is selected in the dropdown,
and the delete link is available for that template.

This scenario needs to be prevented because it looks like I am about to
delete the 404 template, which is an HTML file in the theme.

the 404 page is selected in a dropdown, and a delete link is available

This is extra confusing because when I click the delete link,
the confirmation dialog does not include the name of the template that am I deleting.
-I think it would be good to include the template name. It will help against missclicks.

-I would also want to know what happens when I delete a template and it is currently in use,
but this information can be added later.

@jameskoster
Copy link
Contributor

This scenario needs to be prevented because it looks like I am about to delete the 404 template, which is an HTML file in the theme.

+1, this issue is becoming quite troublesome.

I'd love to hear more thoughts on this from others, but I don't think the delete action should be so prominent. Deleting a template is a significant destructive action, performing it from the sidebar of the post editor feels inappropriate to me. I think I'd prefer to see something like the designs shared in #31076 (comment)

@jameskoster jameskoster added the Needs Design Feedback Needs general design feedback. label May 11, 2021
@paaljoachim
Copy link
Contributor

paaljoachim commented May 11, 2021

What about adjusting the position of the various options....?

Screen Shot 2021-05-11 at 19 01 32

I am not sure if I like it or not....

A variation.

Screen Shot 2021-05-11 at 19 07 30

The Delete option is very prominent. Finding a way to have it visible but not have it so prominent could perhaps help.

@ghost
Copy link

ghost commented May 11, 2021

Schermafbeelding 2021-05-11 om 19 19 07

Another option to give it some more hierarchy and drag attention away from the Delete link.

@jameskoster
Copy link
Contributor

Ah, I wasn't referring to the visual prominence. I was questioning whether this action should be possible in the post editor at all.

Personally I don't think you should be able to delete a template in the post editor, in the same way that I don't believe you should be able to delete a post in the template editor. The consequences can be severe, and enabling folks to take this action while editing a single post may mislead them in to believe that only that post will be affected.

Perhaps this is something we can finesse in #31591

@youknowriad
Copy link
Contributor

Good point, I guess the difficulty right now is that we'll be shipping the template mode in 5.8 without the templates UI or the site editor which means we do need a temporary solution for this in the post editor.

@paaljoachim
Copy link
Contributor

paaljoachim commented May 12, 2021

Brainstorming.

1 - Adding the above mockup delete text link. Clicking delete will bring a popup warning saying that all pages that use the Page template will be affected. We might need a warning popup also listing pages that use the specific page template.
2 - Having a Manage Template screen link similar to the Reusable blocks manage screen. One goes there to among various things also delete the template.
3 - Going to edit a template and from inside the template being able to delete it.
4 - Adding no UI. Forcing the user to locate the template files in the theme folder and manually delete these. As I assume these are somewhere in the themes folder (could not locate any though) as separate files for each Page template created.

We should look at how the Page template will likely progress and go for the most likely easy to tackle method that can be included into WP 5.8.

@jameskoster
Copy link
Contributor

jameskoster commented May 12, 2021

The template editor will be in 5.8, right? So we could try something like this:

Screenshot 2021-05-12 at 11 10 56

Or:

Screenshot 2021-05-12 at 11 15 41

This also solves another problem: Only block templates can be deleted in the UI. So it would be peculiar to only see the delete action when certain templates are chosen in the dropdown.

@carolinan
Copy link
Contributor

I like the example where the delete button is placed in the template sidebar of the template editing mode.
It reduces the confusion about which template is being deleted.

I like it even more if this can be kept long term, maybe even in the site editor.

I agree that if it is only placed centered in the top bar below the template name, there can be problems with discoverability since this placement is new.

@jorgefilipecosta
Copy link
Member Author

When I create a new template with the new link, save and return to the block editor,
a different template than the one I created is selected in the dropdown,
and the delete link is available for that template.

This scenario needs to be prevented because it looks like I am about to
delete the 404 template, which is an HTML file in the theme.

the 404 page is selected in a dropdown, and a delete link is available

This is extra confusing because when I click the delete link,
the confirmation dialog does not include the name of the template that am I deleting.
-I think it would be good to include the template name. It will help against missclicks.

-I would also want to know what happens when I delete a template and it is currently in use,
but this information can be added later.

Hi @carolinan, that for sharing this issue. I think this issue happens because what @youknowriad said "When creating new templates (new link there), we don't update this setting at the moment". I guess we should probably fix it in a side PR.

@jorgefilipecosta
Copy link
Member Author

I updated this PR it now implements the first UI proposed by @jameskoster in #31678 (comment). I opted for the first proposal because there are plans to have the delete button at the top in the long term. From here we can expand the dropdown to include other information.

@jameskoster
Copy link
Contributor

Nice, this seems like a promising start to me :)

Screenshot 2021-05-17 at 12 11 02

Aside from some visual styling adjustments that we can fine tune later, I have a couple of comments in relation to general functionality:

  • I don't see the template name in the top bar when I create a new template, should I?
  • In the popover, the template name seems to be a button. This should be an input where I can update the template name (appreciate this might be out of scope for this PR)
  • It would be cool if clicking the post name in the top bar returned you to the post editor. IE behave the same as the "<- Back button" (appreciate this may also be out of scope :D).
  • When I delete the template and am returned to the post editor, we should probably display a '"Template name" deleted' Snackbar confirmation with an undo action. Otherwise it's quite a pain to restore the template.

@carolinan
Copy link
Contributor

The delete link is still present in the block editor in the template section.
I think it is more important that the name of the template is in the "Are you sure" message in this view where you select between multiple templates.

@carolinan
Copy link
Contributor

carolinan commented May 17, 2021

Tested with NVDA screen reader and Chrome on Windows 10.
In template editing mode, the button below the name "About"-text has no context. If the template name is test2, it only reads "test2 button".

The name of the current post or page is not read when navigating:

List view  menu button  collapsed  subMenu
test2  button
Switch to draft  button  

When the button is activated, there is no context:

test2  button
TITLE  grouping
test2  1 of 1
Delete  1 of 1

Title of what?
Delete what?

@carolinan
Copy link
Contributor

One more test: When I activate the button that is below the name of current page or post,
focus is placed inside a modal and I can not navigate out of this keyboard trap without pressing escape.
When I tab, or use arrow keys, including tabbing backwards, focus moves between the "title" and the delete button, there is no close.

{ __( 'About' ) }
</div>
<Button isSmall isTertiary onClick={ onToggle }>
{ templateTitle }
Copy link
Contributor

@carolinan carolinan May 19, 2021

Choose a reason for hiding this comment

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

What is a suitable context for this button?
What do we call the modal popover, "Template options"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes the aria-label sounds good to me 👍

disabled
>
<MenuItem>{ templateTitle }</MenuItem>
</MenuGroup>
Copy link
Contributor

Choose a reason for hiding this comment

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

This menu is clickable and focusable but doesn't actually do anything.
I suggest not adding this as a menu until there is an action.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, the user already clicked on a button with the template name, so making this focusable doesn't add anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned here, this should be an input, not a menu item.

</>
) }
renderContent={ () => (
<NavigableMenu>
Copy link
Contributor

@talldan talldan May 19, 2021

Choose a reason for hiding this comment

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

If we want to achieve something like the example:
image

I think it's probably better to avoid using a NavigableMenu/MenuGroup/MenuItem, which should generally only be used for vertical list menus. Those components are not needed in a plain dropdown and will make it difficult to achieve the desired result. I think the screenshot above is closer to something like the Link UI in terms of the way it's presented. Arrow key navigation isn't needed for that kind of component, tabs are fine.

An example is here where the Delete button takes up the full width because it's a menu item (and some of the other styles aren't quite right):
Screenshot 2021-05-19 at 5 44 43 pm

Copy link
Contributor

Choose a reason for hiding this comment

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

Although I see in the issue that this is the latest quick win design:
Screenshot 2021-04-22 at 12 17 03

I still think it'd be better not to use NavigableMenu because there's only one button that can be tabbed to.

Copy link
Contributor

Choose a reason for hiding this comment

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

A close button needs to be added because it is now a keyboard trap.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, there are some other designs proposed in this PR as well, not sure which is the latest 😄

A close button needs to be added because it is now a keyboard trap.

Escape or clicking outside should be fine, most popovers in the editor do this.

@paaljoachim
Copy link
Contributor

paaljoachim commented May 19, 2021

Testing.

WordPress 5.7.2. Twenty Twenty One.
Special Gutenberg version of this PR.

This is what I see.

Delete-template-title-drop-down.mp4

It would be good to have consistency with the Site Editor template drop down:
(Using the same type of drop down.)

Site-Editor-Index-template-drop-down.mp4
  • Includes the arrow.
  • Includes the hover/tooltip information.
  • Behaves the same way as the Site Editor drop down.

@jameskoster
Copy link
Contributor

I agree with Paal on the tooltip, but I don't know that we need the arrow 🤔

I suppose it's a question of what we want to be consistent with. The Site Editor has the arrow, but this isn't actually live yet and therefore not a familiar pattern to the average user. The post editor has the preview menu:

Screenshot 2021-05-19 at 13 07 20

Which is just a button and a popover. This is pretty much the same use case as we're building here, so it may make more sense to be consistent with that for now?

@paaljoachim
Copy link
Contributor

paaljoachim commented May 19, 2021

As we need to have the delete template feature in 5.8. I would say go with what feels natural...:)
It can always change at a later time.

jorgefilipecosta and others added 7 commits May 19, 2021 15:05
…-template.js

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>
…-template.js

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>
…-template.js

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>
…-template.js

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>
Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>
…-template.js

Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>
@jorgefilipecosta
Copy link
Member Author

Hi @carolinan thank you a lot for all the code suggestions you proposed for this PR 👍 They were applied.

This PR was updated it now implements an input field that also allows the change of the template title as suggested. The design is not there yet and we may need to do some follow-ups but I feel this PR implements the required functionality and should be ready of 10.7. We can after iterate and cherry-pick the additional PR's.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

I tried this, I don't like the editable title personally, it felt too confusing for me in a dropdown without any label or anything. I have a small preference for just not including that feature.

That said, I think we can merge to include this and iterate.

@jorgefilipecosta jorgefilipecosta merged commit 249d3bd into trunk May 19, 2021
@jorgefilipecosta jorgefilipecosta deleted the add/delete-template-action branch May 19, 2021 17:44
jffng pushed a commit that referenced this pull request May 19, 2021
Co-authored-by: Carolina Nymark <hi@themesbycarolina.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Template Editing Mode Related to the template editor available in the Block Editor Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants