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

Save Navigation Block data to a wp_navigation post type #35746

Merged
merged 24 commits into from
Oct 26, 2021

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Oct 19, 2021

Description

Closes #34612. Alternative to #35418, that instead of using a template part post type, uses a dedicated wp_navigation custom post type for saving the navigation block's inner blocks.

TODO:

  • Add a switcher to the block toolbar for choosing another navigation post.
  • Renaming of navigation posts.
  • Decide what to do about the wp-admin view of navigation posts. Maybe hide it and then follow up with work on a way to edit in isolation? (edit: have disabled this, but it leaves an issue in that there's no way to delete menus)
  • Improve copy. What should we publicly call the user facing post type for a navigation block? Is 'Navigation blocks' ok, or is that confusing? (edit: I've settled on 'Navigation Menu' for now)
  • Handle existing navigation blocks in content. Offer a path for saving their inner blocks?
  • Fix any failing tests

How has this been tested?

New blocks

  1. Open the site editor
  2. Add a navigation block
  3. Choose 'new menu'
  4. Add some blocks
  5. Save (making sure to save the navigation data) and reload, content should still be present
  6. Add a new navigation block elsewhere
  7. Select the previously created menu
  8. Modify the inner blocks, both navigation blocks should show the updated content
  9. Apply styling to one of the blocks. Only the modified block should be affected.

Upgrading blocks

  1. Checkout trunk, build the codebase.
  2. In the site or post editor, create a nav block with some inner blocks and save the content.
    3 Checkout this branch
  3. Follow the process for upgrading the block

Screenshots

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.
  • I've tested my changes with keyboard and screen readers.
  • 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 (please manually search all *.native.js files for terms that need renaming or removal).

@talldan talldan added [Type] Enhancement A suggestion for improvement. [Block] Navigation Affects the Navigation Block labels Oct 19, 2021
@talldan talldan self-assigned this Oct 19, 2021
@talldan talldan added this to 👀 PRs needing review in Navigation block via automation Oct 19, 2021
@talldan talldan changed the title Update nav block to use custom post type Save Navigation Block data to a wp_navigation post type Oct 19, 2021
@github-actions
Copy link

github-actions bot commented Oct 19, 2021

Size Change: +1.67 kB (0%)

Total Size: 1.07 MB

Filename Size Change
build/block-library/blocks/navigation/editor-rtl.css 1.78 kB +71 B (+4%)
build/block-library/blocks/navigation/editor.css 1.78 kB +72 B (+4%)
build/block-library/editor-rtl.css 9.67 kB +64 B (+1%)
build/block-library/editor.css 9.67 kB +65 B (+1%)
build/block-library/index.min.js 151 kB +1.39 kB (+1%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.2 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/index.min.js 134 kB
build/block-editor/style-rtl.css 13.9 kB
build/block-editor/style.css 13.9 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 549 B
build/block-library/blocks/button/style.css 549 B
build/block-library/blocks/buttons/editor-rtl.css 309 B
build/block-library/blocks/buttons/editor.css 309 B
build/block-library/blocks/buttons/style-rtl.css 317 B
build/block-library/blocks/buttons/style.css 317 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 206 B
build/block-library/blocks/columns/editor.css 205 B
build/block-library/blocks/columns/style-rtl.css 497 B
build/block-library/blocks/columns/style.css 496 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.17 kB
build/block-library/blocks/cover/style.css 1.17 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 977 B
build/block-library/blocks/gallery/editor.css 982 B
build/block-library/blocks/gallery/style-rtl.css 1.6 kB
build/block-library/blocks/gallery/style.css 1.59 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 502 B
build/block-library/blocks/image/style.css 505 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 488 B
build/block-library/blocks/navigation-link/editor.css 489 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/style-rtl.css 195 B
build/block-library/blocks/navigation-submenu/style.css 195 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/style-rtl.css 1.71 kB
build/block-library/blocks/navigation/style.css 1.7 kB
build/block-library/blocks/navigation/view.min.js 2.74 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 198 B
build/block-library/blocks/page-list/style.css 198 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 347 B
build/block-library/blocks/post-comments-form/style.css 347 B
build/block-library/blocks/post-comments/style-rtl.css 475 B
build/block-library/blocks/post-comments/style.css 475 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 396 B
build/block-library/blocks/post-featured-image/editor.css 397 B
build/block-library/blocks/post-featured-image/style-rtl.css 156 B
build/block-library/blocks/post-featured-image/style.css 156 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 391 B
build/block-library/blocks/post-template/style.css 392 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 60 B
build/block-library/blocks/post-title/style.css 60 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 378 B
build/block-library/blocks/pullquote/style.css 378 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 262 B
build/block-library/blocks/query-pagination/editor.css 255 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 250 B
build/block-library/blocks/separator/style.css 250 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 770 B
build/block-library/blocks/site-logo/editor.css 770 B
build/block-library/blocks/site-logo/style-rtl.css 165 B
build/block-library/blocks/site-logo/style.css 165 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 824 B
build/block-library/blocks/social-links/editor.css 823 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB
build/block-library/blocks/social-links/style.css 1.32 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 815 B
build/block-library/common.css 812 B
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 10.5 kB
build/block-library/style.css 10.5 kB
build/block-library/theme-rtl.css 668 B
build/block-library/theme.css 673 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46 kB
build/components/index.min.js 212 kB
build/components/style-rtl.css 15.4 kB
build/components/style.css 15.4 kB
build/compose/index.min.js 10.4 kB
build/core-data/index.min.js 12.4 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/data/index.min.js 7.1 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.44 kB
build/edit-navigation/index.min.js 15.8 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.4 kB
build/edit-post/style-rtl.css 7.12 kB
build/edit-post/style.css 7.12 kB
build/edit-site/index.min.js 30.7 kB
build/edit-site/style-rtl.css 5.78 kB
build/edit-site/style.css 5.78 kB
build/edit-widgets/index.min.js 16.3 kB
build/edit-widgets/style-rtl.css 4.17 kB
build/edit-widgets/style.css 4.18 kB
build/editor/index.min.js 37.7 kB
build/editor/style-rtl.css 3.78 kB
build/editor/style.css 3.77 kB
build/element/index.min.js 3.21 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 5.99 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.6 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.72 kB
build/keycodes/index.min.js 1.3 kB
build/list-reusable-blocks/index.min.js 1.85 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.19 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.7 kB
build/server-side-render/index.min.js 1.52 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.74 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.11 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@jasmussen
Copy link
Contributor

Thanks for taking a stab at this. I'm tripping myself on some of the testing steps, and find myself unable to select a previously created menu. What am I doing wrong in this GIF?
nav

@talldan
Copy link
Contributor Author

talldan commented Oct 19, 2021

@jasmussen That's interesting. You should be seeing a two-step block placeholder, first step should look like this, similar to when a template part is added:
Screenshot 2021-10-19 at 4 39 34 pm

@talldan
Copy link
Contributor Author

talldan commented Oct 19, 2021

@jasmussen That might happen if your code isn't re-built for some reason, maybe the build failed? It looks like you have the PHP changes but not the JavaScript changes.

@jasmussen
Copy link
Contributor

Thanks, I'll give this another shot. Back in a moment.

@jasmussen
Copy link
Contributor

jasmussen commented Oct 19, 2021

This is an impressive PR:

test

Whether data should be saved as a custom post type or as a template part, I'm unqualified to chime in on. Focusing purely on the navigation block part of it, the primary effort would be to integrate a menu picker into the existing setup state so we end up with a one-step placeholder. I'll note down a task to do some mockups here.

@draganescu
Copy link
Contributor

Took this for a spin and just like @jasmussen I am amazed how impressive it is. I did not have to figure it out at all, it just worked. The one problem I found is that the front end does not render the menu I see in the Site Editor. Is this known or am I doing it wrong?

I see this in the editor:

Screen Shot 2021-10-19 at 17 07 14

And this rendered:

Screen Shot 2021-10-19 at 17 07 23

@gwwar
Copy link
Contributor

gwwar commented Oct 19, 2021

This one looks pretty interesting @talldan! Nice work. ✨

Things that need fixing

❌ From testing I believe top level attributes on the nav block like vertical variation aren't being saved. Would it be simpler to insert a block reference, and have the navigation CPT store both the nav block and the inner-content?

Context on Flow

So for folks reviewing, this PR plays around with the serialization of the block. Instead of storing link content inline, we instead create a nav CPT, and simply link to the post id:

Nav block points to the CPT id CPT content stores the inner content (everything but the nav container) If we edit 3 Nav blocks, we see these queued up for save on publish
CleanShot 2021-10-19 at 10 37 44@2x CleanShot 2021-10-19 at 10 37 24@2x CleanShot 2021-10-19 at 10 48 00@2x

In terms of workflow, there's a new step when adding a nav block, we give it a name. I understand that we're still prototyping here. Some suggested feedback for the new flow:

  • To make this a little friendlier we might want to suggest something more memorable to start as a placeholder prompt like "Header menu" or "Nav menu" etc. Since each is backed by a CPT, it'd be ideal to also show the navigation menu name in ListView and when we select the block. (Similar to how we show named headers).
  • Step 2 likely needs some copy changes or some 🤔 After naming a menu it's confusing to pick from other named menus. Maybe something like populate, or start from? Can we also start from content from other CPT nav menus?
  • More of an enhancement for another PR but I wonder if at step 2 we can show some pattern placeholders w/hover preview. It'd make this step less intimidating.

CleanShot 2021-10-19 at 10 38 09@2x

CleanShot.2021-10-19.at.10.39.39.mp4

Questions from summary

Handle existing navigation blocks in content. Offer a path for saving their inner blocks?

There's a lot of similarities here for saving navigation content with a CPT and reusable blocks. Provided we are pretty clear on what is backed by a CPT and what's saved inline to a post, I think it might be a simple as showing some actions like "convert to reusable menu" and "convert to regular blocks" (or whatever we decide to call these sorts of nav blocks).

CleanShot 2021-10-19 at 11 00 09@2x

Decide what to do about the wp-admin view of navigation posts. Maybe hide it and then follow up with work on a way to edit in isolation?

Probably a good opportunity to edit these CPTs with a block based editor like the nav editor. The post editor is serviceable enough in the meantime, but folks might need some explanation of what it is. We could maybe add a filter for this CPT, and add a wrapper nav block that doesn't get serialized? Or perhaps save the entire nav + contents in one place.

What should we publicly call the user facing post type for a navigation block?

There's already "Menus" so how about "Block Menus"? No strong feelings on this one.

Misc thoughts

One thing that comes to mind is that if we use a CPT, there's very little difference here between backing a nav block with a CPT vs one with an existing menu. The latter would likely need a simple adapter, and some extra logic limiting the type of inner blocks we can add.

Overall, I think the idea here is pretty promising. It be great to get some feedback from folks more familiar with how folks prefer building sites. Perhaps a +1 review from folks more familiar with themes, and another from APIs?

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

This is looking really good!

In addition to the todoes other folks have mentioned (block not rendering on the front end and not saving customizations such as color and variation jumped out the most to me), there's also:

  • direct insert logic not working as expected (it always assumes direct insert is true, independently of what type of blocks are in the nav);
  • in editor accessible from "All Navigation Menus", all blocks can still being inserted, as if it were a regular post. (I like the idea of leveraging the navigation editor for this view, but it doesn't feel like a must-have for V1 of this work, so perhaps we can just hide it for now.)

As for the CPT vs Template Part, there doesn't seem to be too much duplication of logic in this PR? I reckon it's worth going with the CPT.

➕ to making the 2-step placeholder flow 1 step only 😄

function gutenberg_register_navigation_post_type() {
// TODO - Some of the language here needs to be revised. 'Navigation' is a
// singular noun, so cannot comfortably be used in a plural form, which
// leads to a situation where something like 'menus' needs to be suffixed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we call the post type "menu" instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

In general can we decide on "navigation" vs "menu". I had understood we were normalizing towards "navigation" so as to disambiguate from classic Menus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@getdave Navigation is a singular noun, it doesn't have a plural form, so I think we're going to struggle to use it everywhere. Have a look through the strings below this comment to see what I mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with Navigation Menu for now, it can be refined.

'insert_into_item' => __( 'Insert into Navigation', 'gutenberg' ),
'uploaded_to_this_item' => __( 'Uploaded to this Navigation', 'gutenberg' ),
// Some of these are a bit weird, what are they for?
'filter_items_list' => __( 'Filter Navigation list', 'gutenberg' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

This one seems to provide the screen reader text for the "Filter" section in the Navigation post type index page:

Screen Shot 2021-10-20 at 5 23 03 pm

The docs for register_post_type might need updating 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for finding that!

} }
/>
<Warning>
{ __( 'Block cannot be rendered inside itself.' ) }
Copy link
Contributor

Choose a reason for hiding this comment

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

I was still able to add the block inside itself if I go through "All Navigation Menus" to the standalone editor. It rendered the whole block, with the warning in the place where the nested block would be. Then it started flickering, but I was able to save it.

Interestingly enough, when I tried the same with a menu that wasn't being used in any location, it didn't show that menu as an option to pick from in the site editor. But if the menu is already being used somewhere, it still shows.

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that's because the isolated editor doesn't have a wrapper Nav block. There's work to do there in general about allowing insertion of child Nav blocks outside of the Nav parent block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the standalone editor is just a post editor.

Interestingly enough, when I tried the same with a menu that wasn't being used in any location, it didn't show that menu as an option to pick from in the site editor. But if the menu is already being used somewhere, it still shows

@tellthemachines would you be able to elaborate on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

What I did was:

  • Create a new nav post from the "All Navigation Menus" page.
  • Give it a name and populate it only with blocks that can exist inside a Nav, such as Search and Social links.
  • Save the post. I think I refreshed the page after that.
  • Add a Navigation block to the post, click "Choose existing" and choose the one I am currently editing.
  • The Navigation was added to the post, and inside it were all the blocks I had added above, plus the warning that the block can't render inside itself.
  • I then went to to the Site Editor, and added a new Nav block to the index template.
  • Under "Choose existing", the navigation that I had just created did not appear.
  • I then went back and edited the post to remove the nested Nav block.
  • Going back to the Site Editor and refreshing the page, that post now appeared under "Choose existing" in my new nav block.

Then I tried:

  • From the "All Navigation Menus" page, opening an existing nav post that was already in use in a template.
  • Adding a new nav block inside it, and choosing itself from "Choose existing".
  • The block was added, but immediately started flickering, and clicking "update" made the whole editor hang, though it did save the post after a while. (The flickering and hanging didn't happen in the previous test.)
  • I went to the Site Editor, and added a new Nav block to the index template.
  • Under "Choose existing", I was able to choose the navigation that I had just mangled by rendering it inside itself.
  • Both that, and the other existing instance of the same navigation in that template, displayed the warning about the block rendering inside itself, in addition to the other blocks that nav contained.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the editor at 'All Navigation Menus' is just the post editor, and as @getdave mentioned, because there's no wrapping Navigation Block, there's no recursion provider in that view, so it's possible for a user to create anything there.

I think for this PR, that option should be hidden in WP Admin.

The flickering sounds unusual. Not sure why that would happen.

You also mentioned this:

Under "Choose existing", the navigation that I had just created did not appear.

At the moment, drafts don't appear in that menu, so it might be that you saved it as a draft? I couldn't reproduce what you mentioned otherwise.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Great work exploring these PRs Dan. Very much appreciated 🙇 👏 👏 👏

I've undertaken a review of this on video (with audio!).

What are we looking to achieve?

Before I make comments let's reflect on the wider goals we're looking to address (some of which may not be addressed in this PR):

  • Allow navigations to be used in different locations within the same template/site.
  • Allow reuse of the same navigation data but with different presentational treatments.
  • Retain ability to quickly build new navigations.
  • Separate presentation and data in order to afford editing navigation data in isolation (e.g. Nav Editor project).
  • Allow reuse of navigations across Themes.

Overall, I think this PR is addressing (with some refinement) the first 4 items which is great (the point about Theme switching is being discussed in #35750).

Notes from Video

  • The workflow was a lot more intuitive - less baggage from Template Parts is a win.
  • I tried using the same menu in the header and footer but applying different presentational treatments (text colors...etc). This worked initially but when I reloaded some of these visual distinctions were lost.
  • I really like the isolated view which has just the nav items and not the wrapper. This for me is where the Nav Editor should be headed. Avoids all baggage from the Nav block and provides a very useable experience to manipulate the data.
  • as in Try using a template part in the navigation block #35418 when viewing the CPT in isolated view you cannot add Nav block items because they are not part of parent. We should be able to work around that somehow.

Technical approach

I would also like to emphasise that I believe you are taking the correct route in not serializing the Nav block itself to the CPT. The block should be a wrapper concerned solely with presentation specific to the location (within the template) in which it is being used, where as the inner blocks should represent the data structure of the navigation itself. If we were to serialize the Nav block then we'd also persist all the presentation and it would therefore make it far less flexible when attempting to reuse the same navigation data between instances (eg: header vs footer) or indeed within an Isolated Editor view (e.g. Nav Editor).

function gutenberg_register_navigation_post_type() {
// TODO - Some of the language here needs to be revised. 'Navigation' is a
// singular noun, so cannot comfortably be used in a plural form, which
// leads to a situation where something like 'menus' needs to be suffixed.
Copy link
Contributor

Choose a reason for hiding this comment

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

In general can we decide on "navigation" vs "menu". I had understood we were normalizing towards "navigation" so as to disambiguate from classic Menus.

packages/block-library/src/navigation/edit/index.js Outdated Show resolved Hide resolved
packages/block-library/src/navigation/edit/index.js Outdated Show resolved Hide resolved
Comment on lines 191 to 195
// We don't want to render a missing state if we have any inner blocks.
// A new template part is automatically created if we have any inner blocks but no entity.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// We don't want to render a missing state if we have any inner blocks.
// A new template part is automatically created if we have any inner blocks but no entity.
// If we have a reference to the Navigation Post but the post entity no longer exists
// then show a warning to the user.

Question: if the users ends up in this state can we provide them with an option to create a new navigation rather than having to remove the block and re-add it?

packages/block-library/src/navigation/edit/index.js Outdated Show resolved Hide resolved
packages/block-library/src/navigation/edit/index.js Outdated Show resolved Hide resolved
Comment on lines 41 to 42
? __( 'Choose an existing menu or create a new one.' )
: __( 'Create a new menu.' )
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
? __( 'Choose an existing menu or create a new one.' )
: __( 'Create a new menu.' )
? __( 'Choose an existing navigation or create a new one.' )
: __( 'Create a new navigation.' )

@getdave getdave mentioned this pull request Oct 20, 2021
38 tasks
@spacedmonkey
Copy link
Member

Question: If we store menus in this new post type, will titles of posts, pages etc will be dynamitically be updated like the current menus. Will pages / posts that are deleted, automatically be removed from this content? Will links to CPT that are no longer be register also be removed.

Menus have be somewhat dynamic, as they link to other WordPress content. If menu is not dynamic, then this is a massive step backwards for users, IMO.

@talldan
Copy link
Contributor Author

talldan commented Oct 26, 2021

Nav blocks seem to take a bit longer to render when loading in both post and site editors; on trunk they load straightaway.

Hmm, yeah, there's some asynchronicity from the REST request needed to load the navigation block data. This will be a difficult one to solve, but I'll look at how it can be improved. Some form of preloading would be good, but the server side code would need to know what to preload.

@tellthemachines This is going to be a difficult one to improve. I think it needs more discussion. I've made an issue outlining the challenges and detailing a potential solution - #35942

@noisysocks noisysocks added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Oct 26, 2021
@noisysocks noisysocks merged commit 9a58337 into trunk Oct 26, 2021
Navigation block automation moved this from 👀 PRs needing review to ✅ Done Oct 26, 2021
@noisysocks noisysocks deleted the update/nav-block-to-use-custom-post-type branch October 26, 2021 06:41
WordPress 5.9 Must-Haves automation moved this from 🏗️ In progress to ✅ Done Oct 26, 2021
@github-actions github-actions bot added this to the Gutenberg 11.9 milestone Oct 26, 2021
@noisysocks
Copy link
Member

Nice work! Let's get this in early and iterate since other issues and PRs depend on it. I added "needs dev note" since it would be good to explain the CPT intricacies on Make/Core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block Needs Dev Note Requires a developer note for a major WordPress release cycle [Type] Enhancement A suggestion for improvement.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Navigation Block: save data to a custom post type
9 participants