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

First pass at Navigation screen #21036

Merged
merged 4 commits into from
Mar 31, 2020
Merged

First pass at Navigation screen #21036

merged 4 commits into from
Mar 31, 2020

Conversation

noisysocks
Copy link
Member

@noisysocks noisysocks commented Mar 20, 2020

Very rough first pass at implementing #19170.

navigation

Adds a new Navigation screen, a new edit-navigation package, and a very rough UI for editing menus using the Navigation block.

The key functionality is in useNavigationBlocks — this is a hook which turns menu items from the REST API into blocks, and blocks into CRUD requests. I haven't tested it very thoroughly but I think it's a pretty viable way of implementing this screen.

The Navigation block is displayed on the page by rendering a @wordpress/block-editor BlockList with templateLock: 'all'. This also works pretty well. I tried rendering just the BlockEdit component but couldn't get it working.

I decided to build an entirely new screen. I did think about a different approach where we swap out #nav-menus-frame in the existing nav-menus.php page with a React app, but there's a few drawbacks to doing this: 1) We can't have both screens at once in the plugin; 2) We can't implement an "opt out" plugin similar to the Classic Editor plugin; 3) We would have to add a hook to nav-menus.php in Core to do this; 4) We can't use wp.data and have to do a lot of painful syncing between jQuery and React.

Tasks remaining:

cc. @talldan @draganescu @tellthemachines @adamziel

@noisysocks noisysocks added [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible [Block] Navigation Affects the Navigation Block labels Mar 20, 2020
@github-actions
Copy link

github-actions bot commented Mar 20, 2020

Size Change: +23 B (0%)

Total Size: 866 kB

Filename Size Change
build/autop/index.js 2.58 kB -2 B (0%)
build/block-directory/index.js 6.02 kB -4 B (0%)
build/block-editor/index.js 102 kB -2 B (0%)
build/block-library/index.js 110 kB +4 B (0%)
build/block-serialization-default-parser/index.js 1.65 kB +1 B
build/blocks/index.js 57.5 kB -2 B (0%)
build/components/index.js 191 kB -25 B (0%)
build/compose/index.js 6.21 kB +4 B (0%)
build/core-data/index.js 10.7 kB +71 B (0%)
build/data-controls/index.js 1.04 kB +2 B (0%)
build/data/index.js 8.26 kB -4 B (0%)
build/edit-post/index.js 92.3 kB -3 B (0%)
build/edit-site/index.js 8.65 kB -3 B (0%)
build/edit-widgets/index.js 4.43 kB +3 B (0%)
build/editor/index.js 42.8 kB -12 B (0%)
build/element/index.js 4.44 kB -1 B
build/hooks/index.js 1.93 kB +2 B (0%)
build/keyboard-shortcuts/index.js 2.3 kB -4 B (0%)
build/keycodes/index.js 1.7 kB +1 B
build/list-reusable-blocks/index.js 2.99 kB +1 B
build/media-utils/index.js 4.84 kB +3 B (0%)
build/notices/index.js 1.57 kB +1 B
build/nux/index.js 3.01 kB -3 B (0%)
build/plugins/index.js 2.54 kB -3 B (0%)
build/priority-queue/index.js 780 B -1 B
build/rich-text/index.js 14.5 kB +2 B (0%)
build/server-side-render/index.js 2.54 kB -1 B
build/token-list/index.js 1.28 kB +1 B
build/viewport/index.js 1.6 kB -3 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 998 B 0 B
build/annotations/index.js 3.44 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-editor/style-rtl.css 11 kB 0 B
build/block-editor/style.css 11 kB 0 B
build/block-library/editor-rtl.css 7.21 kB 0 B
build/block-library/editor.css 7.21 kB 0 B
build/block-library/style-rtl.css 7.5 kB 0 B
build/block-library/style.css 7.51 kB 0 B
build/block-library/theme-rtl.css 669 B 0 B
build/block-library/theme.css 671 B 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/style-rtl.css 15.8 kB 0 B
build/components/style.css 15.7 kB 0 B
build/date/index.js 5.36 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.06 kB 0 B
build/edit-navigation/index.js 2.4 kB 0 B
build/edit-navigation/style-rtl.css 95 B 0 B
build/edit-navigation/style.css 95 B 0 B
build/edit-post/style-rtl.css 8.35 kB 0 B
build/edit-post/style.css 8.34 kB 0 B
build/edit-site/style-rtl.css 3.46 kB 0 B
build/edit-site/style.css 3.46 kB 0 B
build/edit-widgets/style-rtl.css 2.57 kB 0 B
build/edit-widgets/style.css 2.57 kB 0 B
build/editor/editor-styles-rtl.css 423 B 0 B
build/editor/editor-styles.css 426 B 0 B
build/editor/style-rtl.css 3.38 kB 0 B
build/editor/style.css 3.38 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 6.95 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 712 B 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/primitives/index.js 1.5 kB 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/url/index.js 4.01 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

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

Was unable to test, but I wonder if this useNavigationBlocks is an approach that augments the Navigation block. I was under the impression that we'd add an entity provider and have the Navigation block "augmented" to work with that context when it existed and save to block structure otherwise.

packages/block-library/src/navigation/edit.js Show resolved Hide resolved
@ZebulanStanphill
Copy link
Member

I don't see the purpose in keeping the block interface at the bottom. There's no way for this interface to know how the theme is styling the navigation on the front-end, including whether or not it is vertical or horizontal. A block-based WYSIWYG interface only makes sense in the context of full site editing, in my opinion. Trying to jam it into this screen is confusing (since it misleads users into thinking the block interface is an accurate front-end preview), and not useful at all in terms of accessibility.

I think the purely semantic/structure-based UI at the top is all we need. We could refine it to expose all controls needed to replicate the same functionality that the current wp-admin Menus interface provides. This non-WYSIWYG interface could then be backported to the block, allowing for a refined alternate editing experience for keyboard users.

@draganescu
Copy link
Contributor

draganescu commented Mar 20, 2020

Howdy @ZebulanStanphill :) This will move towards the recent design iterations in #19170.

it misleads users into thinking the block interface is an accurate front-end preview

This is a very good point!

@noisysocks
Copy link
Member Author

noisysocks commented Mar 22, 2020

@ZebulanStanphill: You raise some good points about the design of this screen that are important to discuss! I'd like us to keep that discussion in #19170, though, so that this thread can focus more on the technical approach. I've replied here: #19170 (comment).

I was under the impression that we'd add an entity provider and have the Navigation block "augmented" to work with that context when it existed and save to block structure otherwise.

@draganescu: This sounds interesting, but I don't quite grok what you mean. (I don't really know anything about entity providers!) Could you elaborate with some pseudocode or, even better, spin up an alternative technical prototype PR? I'm happy for us to explore the problem space by having a few "competing implementations".

Copy link
Contributor

@talldan talldan 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 great! There's only the introduction of the entities that I'd consider something we might want to be tentative about. The rest of this I think is good in the spirit of an experimental feature, a great starting point.

@@ -67,6 +67,27 @@ export const defaultEntities = [
plural: 'comments',
label: __( 'Comment' ),
},
{
name: 'menu',
Copy link
Contributor

Choose a reason for hiding this comment

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

The generated functions become part of the stable api of core data, but meanwhile the endpoint is still experimental and could be changed. I think it'd be good if the entity could be marked as experimental to match the endpoint. I made small PR that enables that - #21072

const [ menuId, setMenuId ] = useState( 0 );

useEffect( () => {
if ( menus?.length ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh, a ?. in the wild. 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't scare it!

import Layout from './components/layout';

export function initialize( id, settings ) {
registerCoreBlocks();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, do we need all these? We can probably get away with only registering the Nav and Nav Link blocks.

@draganescu
Copy link
Contributor

I don't really know anything about entity providers!

Me neither! I am not even sure this is possible.

I was thinking (and trying to no avail) to use EntityProvider to wrap a navigation block and provide a menu id and then in the Navigation block to use useEntityBlockEditor to build the innerBlocks based on the content of that Navigation block.

Actually I have no idea if anything I am saying here makes sense. After all selecting select( 'core' ).getMenuItems works just as well and am also unsure of how adjusting Navigation to work with entities like that would benefit. Maybe in FSE?

Adds a new Navigation screen, a new edit-navigation package, and a very
rough UI for editing menus using the Navigation block.
@talldan talldan force-pushed the try/navigation-screen branch from d6f2ada to ddcbc58 Compare March 31, 2020 08:34
Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

This give us a good starting point to go off and work on smaller PRs, and it doesn't touch too much existing code, so I think it's worth getting this merged asap so that we can make progress 👍

Good work @noisysocks!

@talldan talldan merged commit b84e38f into master Mar 31, 2020
@talldan talldan deleted the try/navigation-screen branch March 31, 2020 09:11
@github-actions github-actions bot added this to the Gutenberg 7.9 milestone Mar 31, 2020
@mtias
Copy link
Member

mtias commented Mar 31, 2020

Thanks for getting this in

@talldan
Copy link
Contributor

talldan commented Mar 31, 2020

I've created the above issues for the follow-ups.

@manmotive
Copy link

manmotive commented Apr 29, 2020

Hi @noisysocks ,

I'm trying to use the block API to get the selected menu item ID (the actual post ID). I think it's stored as the clientId (or maybe blockId - I'm not entirely sure at this point) on this screen.

The following code works on a standard post/page:

wp.data.select( 'core/block-editor' ).getSelectedBlock().clientId;

... but not on the experimental navigation page.

Is this a bug or am I doing something wrong? I'm happy to open a new issue if needed, but right now I'm not sure if I'm just taking the wrong approach (maybe there is a better way to get the ID of the selected menu item?). Thanks!

Edit, I have reported this here #22022

@noisysocks
Copy link
Member Author

noisysocks commented May 14, 2020

@manmotive: There's no way to do that right now as the mapping between block client ID and menu item post ID is stored in component state. This might be possible later if/when we move to using @wordpress/data for this screen.

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 [Type] Technical Prototype Offers a technical exploration into an idea as an example of what's possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants