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

Creation of menus on the edit navigation screen #22309

Merged
merged 36 commits into from
May 18, 2020

Conversation

talldan
Copy link
Contributor

@talldan talldan commented May 13, 2020

Description

Closes #21281

Allows creation of new menus from the experimental navigation menu screen.

This is fairly rough and ready, but I think good enough for a first draft.

How has this been tested?

First menu

  1. Visit the page when there are no menus
  2. Create a new menu

With existing menus

  1. Visit the page when there are menus
  2. Click the Create Menu button
  3. Create a new menu

Screenshots

Screenshot 2020-05-14 at 6 11 24 pm

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.

@talldan talldan added [Type] Enhancement A suggestion for improvement. [Block] Navigation Affects the Navigation Block labels May 13, 2020
@talldan talldan self-assigned this May 13, 2020
@github-actions
Copy link

github-actions bot commented May 13, 2020

Size Change: +2.24 kB (0%)

Total Size: 835 kB

Filename Size Change
build/annotations/index.js 3.62 kB +1 B
build/block-directory/index.js 6.93 kB +341 B (4%)
build/block-directory/style-rtl.css 790 B +26 B (3%)
build/block-directory/style.css 791 B +27 B (3%)
build/block-editor/index.js 105 kB +749 B (0%)
build/block-library/index.js 118 kB +11 B (0%)
build/blocks/index.js 48.1 kB +1 B
build/components/index.js 182 kB -1 B
build/core-data/index.js 11.4 kB +1 B
build/dom/index.js 3.11 kB +9 B (0%)
build/edit-navigation/index.js 6.6 kB +824 B (12%) ⚠️
build/edit-navigation/style-rtl.css 832 B +123 B (14%) ⚠️
build/edit-navigation/style.css 831 B +123 B (14%) ⚠️
build/edit-site/index.js 12 kB -1 B
build/edit-widgets/index.js 7.87 kB +1 B
build/editor/index.js 44.3 kB +1 B
build/format-library/index.js 7.64 kB +1 B
build/list-reusable-blocks/index.js 3.13 kB +1 B
build/plugins/index.js 2.56 kB +2 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.02 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 620 B 0 B
build/block-editor/style-rtl.css 10.8 kB 0 B
build/block-editor/style.css 10.8 kB 0 B
build/block-library/editor-rtl.css 7.19 kB 0 B
build/block-library/editor.css 7.19 kB 0 B
build/block-library/style-rtl.css 7.48 kB 0 B
build/block-library/style.css 7.48 kB 0 B
build/block-library/theme-rtl.css 683 B 0 B
build/block-library/theme.css 685 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/style-rtl.css 17.1 kB 0 B
build/components/style.css 17 kB 0 B
build/compose/index.js 6.67 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.42 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/edit-post/index.js 28.1 kB 0 B
build/edit-post/style-rtl.css 12.2 kB 0 B
build/edit-post/style.css 12.2 kB 0 B
build/edit-site/style-rtl.css 5.22 kB 0 B
build/edit-site/style.css 5.22 kB 0 B
build/edit-widgets/style-rtl.css 4.69 kB 0 B
build/edit-widgets/style.css 4.69 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/editor/style-rtl.css 5.07 kB 0 B
build/editor/style.css 5.08 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 5.29 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 14.8 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.02 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@draganescu
Copy link
Contributor

👋 I tested this locally and noted the following:

  • I should have a cancel link to get out of the create menu form and return to where I was
  • there is a flicker when creating menus, probably everything gets re-rendered
  • if I create a menu with a name that already exists, the menu does not get created but I'm not notified
  • we should rebase this to include the menu locations to see if the new menu appears there as well (currently for me master crashes)

@talldan talldan force-pushed the add/nav-menu-create-button branch from 2ab0e73 to 64716e2 Compare May 14, 2020 04:19
@talldan
Copy link
Contributor Author

talldan commented May 14, 2020

Thanks for testing @draganescu.

I'll work on validation, cancelling menu creation, and also have a fix for that error (that I'll move into a separate PR as well).

The flickering is a tricky one to solve and I might have to defer to a separate PR. It seems to be related to core/data refetching menus again after a menu creation.

It might be possible to use some smoke and mirrors to hide this, maybe by adding a debounce to the spinner.

@talldan talldan force-pushed the add/nav-menu-create-button branch from 0ee88f7 to 1ccfdda Compare May 14, 2020 09:38
@talldan
Copy link
Contributor Author

talldan commented May 14, 2020

Not too far off with this, though there are a few issues I've outlined in my comments above. Would welcome further testing, reviews, and opinions!

@talldan talldan added the Needs Design Feedback Needs general design feedback. label May 14, 2020
@draganescu
Copy link
Contributor

One other functional tid bit @talldan, it would be nice that after menu creation the selected one is the newly created menu.

onDelete={ onDeleteMenu }
/>
</div>
{ hasMenu && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this component just return null when hasMenu === false?

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 ended up removing that and going with the suggestion of @paaljoachim below and showing the create panel alongside other panels.


return (
<Panel className="edit-navigation-menu-editor__navigation-structure-panel">
<PanelBody
title={ __( 'Navigation structure' ) }
initialOpen={ initialOpen }
>
{ !! blocks.length && (
{ showNavigationStructure && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above - should this component just return null when showNavigationStructure === false?

Copy link
Contributor Author

@talldan talldan May 15, 2020

Choose a reason for hiding this comment

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

I changed this back to how it was before for the same reason as above, the panel will show at the same time as the create panel.

@@ -68,6 +68,10 @@
-ms-grid-row-align: start;
}

.edit-navigation-menu-editor__cancel-create-menu-button {
margin-left: 1ch;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we're using either 6px or 8px for this kind of margin in other places.

return;
}

saveMenu( { name: menuName } );
Copy link
Contributor

Choose a reason for hiding this comment

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

Something like this should take care of the notifications.

Suggested change
saveMenu( { name: menuName } );
try {
await saveMenu( { name: menuName } );
createInfoNotice( __( 'Menu created' ), {
type: 'snackbar',
isDismissible: true,
} );
} catch (err) {
createErrorNotice( __( 'Menu creation failed' ), {
type: 'snackbar',
isDismissible: true,
} );
}

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, that works nicely 👍

@adamziel
Copy link
Contributor

Aside of the things already mentioned in comments, it seems to work pretty well. Good job @talldan !

@paaljoachim
Copy link
Contributor

paaljoachim commented May 14, 2020

I am testing the PR at gutenberg.run.

This is my initial test of the Navigation (beta) screen, and I am very impressed with all the work that has been done up to this point. Very nice!

The process of creating a menu.

  1. Click Create a new menu
    Screen Shot 2020-05-14 at 16 35 11

A new screen opens.
Screen Shot 2020-05-14 at 15 59 30

It surprised me that a new screen was seen.

To me it would seem that the accordion would be a part of the general Edit Navigation screen.

Nav-Create-new-menu-1

Open accordion.
Nav-screen-accordion-open

Another idea. Click "Create a new menu" and the accordion is seen below along with the other options.
Nav-same-screen

Here the user clicks "Create a new menu" and it opens in the same screen. It does not open in another "Edit Navigation" screen.

User fills out the name "Top nav" and clicks "Create menu" and the "Edit Navigation" screen is auto updated.
Screen Shot 2020-05-14 at 16 34 01

I am not saying the above is a good or bad or useful idea, but I wanted to bring up the initial brain storming that hit me. It would make the "Create menu" a hidden accordion on the same screen as the other nav items.

@talldan talldan force-pushed the add/nav-menu-create-button branch from 1ccfdda to 357dfda Compare May 15, 2020 07:58
@talldan
Copy link
Contributor Author

talldan commented May 15, 2020

I think I've fixed most of the issues now. I agree with @paaljoachim's suggestion of having the panel appear alongside the other UI, so it works similarly that now. That also inadvertently fixed the focus management issues 🎉

Also managed to fix the glitchy page updates that were occurring when creating a menu and the success/error notifications. It feels a lot smoother now.

if ( ! hasCompletedFirstLoad && hasLoadedMenus ) {
setHasCompletedFirstLoad( true );
}
}, [ hasCompletedFirstLoad, hasLoadedMenus ] );
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: does it need to depend on hasCompletedFirstLoad?

Copy link
Contributor

@adamziel adamziel left a comment

Choose a reason for hiding this comment

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

@talldan the glitchy behavior is gone, good job on this one! I left a few minor comments but nothing overly big.

The ones referring to the progress state will fix this problem where you get stuck in a progress state in some cases (but the submit button continues to work):

Zrzut ekranu 2020-05-15 o 12 28 22

Also this is not specific to this PR, but I totally missed the notification, I think we should make them more visible cc @karmatosed @mapk:

Zrzut ekranu 2020-05-15 o 12 28 46

Another design thing is that I think we can do better in the future with how the empty state feels right after a new menu is created:

Zrzut ekranu 2020-05-15 o 12 30 54

@paaljoachim
Copy link
Contributor

paaljoachim commented May 15, 2020

I went ahead and tested at gutenberg.run again.
Experimental settings: Turned on Enable Navigation screen.
Then went to the screen to create a menu. I tried making a menu and clicked Create Menu but nothing happened. So I again tried to create a menu. I then saw this:

Screen Shot 2020-05-15 at 12 37 36

Inspect:
{"code":"rest_cannot_view","message":"Sorry, you cannot view these menus, unless you have access to permission edit them. ","data":{"status":401}}

Screen Shot 2020-05-15 at 12 39 08

@paaljoachim
Copy link
Contributor

paaljoachim commented May 15, 2020

Hey @adamziel

Notifications in general show up on the bottom left. Notifications become an extra visual mark in addition to an action that has just been taken by the user. In this case an extra visual mark that one has created a menu in addition to create menu action that is seen. An action should hopefully show the result of what is going on. (I can take another test at gutenberg.run again later on.)

G2 Notifications issue:
#20591
Here we can discuss placement and other issues in regards to notifications.

@talldan talldan changed the title Add nav menu screen creation Creation of menus on the edit navigation screen May 18, 2020
@talldan
Copy link
Contributor Author

talldan commented May 18, 2020

@paaljoachim Thanks for testing. Guessing the error is related to permissions when using gutenberg.run. But the error messages should be better.

It looks like the try/catch was only catching JavaScript errors, and for REST/entity errors the getLastEntitySaveError selector should be used, so I've implemented that, and the correct error message is now shown.

I've applied all the other suggestions and will merge this when tests pass.

I also discovered #22404 while working on this, that can cause the created menu not to be selected if there are more than 10 menus.

@talldan talldan merged commit c05a5ad into master May 18, 2020
@talldan talldan deleted the add/nav-menu-create-button branch May 18, 2020 05:58
@github-actions github-actions bot added this to the Gutenberg 8.2 milestone May 18, 2020
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 Design Feedback Needs general design feedback. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow creation/deletion of Navigation Menus on the Navigation screen.
4 participants