-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Navigation: Always create a fallback menu #47684
Conversation
Flaky tests detected in 3a5252b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4192731842
|
Size Change: +30 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
A problem with this is that I cannot ever be in a state where I have no block menus. In the editor if I delete the last block navigation it will just create a new one with a page list in it. |
Yes, when you try to use it. Is that a problem? |
c536475
to
3b5a0a9
Compare
Actually I am wrong @scruffian because if I have block navigation then the block has a ref and when I delete the menu that the ref points to I get the warning. If there are no menus that I can switch to, I see the warning and I can:
Cool! 👍🏻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I have a menu with a ref and the ref'd menu is deleted, when I open the template part I see the warning briefly and then the new menu gets created.
- We should only autocreate if there is no ref.
Good catch. Fixed in 4fd95cb |
@scruffian this PR should also remove the current page list fallback behavior . 🙏🏻 |
I think this is ready for another review. |
3a15b83
to
3d041f2
Compare
|
I added a commit to fix the tests. |
716f4ec
to
e072b47
Compare
This is not what happens in my testing. |
01988b7
to
083adec
Compare
I managed to replicate the issue once, but not again. I think it's probably connected to the order in which the classic menus API request loads. I have updated the dependencies for the useEffect that handles the creation of classic menus, to ensure that they are all loaded before it happens. Hopefully this fixes the issue for you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I couldn't break this w/ testing and the code looks good to me. Let's ship it and see how it works in real life. Overall I think this is a good change compared to the cooler but way buggier path of having a "fallback" that is not an actual menu but some limbo state confusing users and developers :)
I think this is only possible today after all the refinements added to the navigation block in relation to defaults, theme switching behavior and UI so awesome job 👏🏻
@@ -237,6 +209,40 @@ function Navigation( { | |||
[ navigationMenus ] | |||
); | |||
|
|||
// This useEffect adds snackbar and speak status notices when menus are created. | |||
// If there are no fallback navigation menus then we don't show these messages, | |||
// because this means that we are creating the first, fallback navigation menu. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we / Should we - also hide the snackbar about the importing of the default classic menu? If I have a classic menu and it is used as the basis for the default block navigation I get a snackbar saying classic menu imported ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but I'm not sure. It's a different case and I thought it might be useful to know what's happened in that case.
I wonder if we should, later, unify the code that handles defaulting and fallback in some REST endpoint in the menus group of endpoints? It would really make this a lot less frail and also stop us from introducing inadvertently conflicting behavior between the front end and the editor. @spacedmonkey @TimothyBJacobs - is an endpoint that checks and solves the situation of "a navigation block wants to render something but there is nothing there so let's find the most appropriate thing to render" in conflict with any REST principle or can we have such an utility endpoint? |
1d59818
to
3a5252b
Compare
@draganescu It's not very RESTful, I'd probably just make a one-off endpoint in |
3a5252b
to
f5fe083
Compare
@TimothyBJacobs a one off endpoint in |
@draganescu Right so a REST endpoint that you can query and say get me a fallback menu and it will return one. Can be used in editor and front of site. This would
|
This PR creates multiple wp_navigation CPTs when there are multiple blocks in the same post. Reverting in #48602 until we have a way to deal with that problem. |
What?
This creates a fallback navigation CPT when there isn't one. Fixes #47058
Why?
This should simplify several things
How?
We automatically create a wp_navigation CPT in both the editor and the frontend, if a user doesn't have one.
Testing Instructions
Testing Instructions for Keyboard
As above.