-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
List draft navigations in Browse mode Navigation section #51422
Conversation
Size Change: +135 B (0%) Total Size: 1.42 MB
ℹ️ View Unchanged
|
Flaky tests detected in 5067d103867088278b2bf2b0b179c1f981961c91. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5323755413
|
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.
Let's not do this without implementing similar to what I proposed in #51427.
I think it will be extremely confusing to users to have a list of menus unless that can tell which are / aren't published.
I updated this to add a |
status: 'publish', | ||
status: [ 'publish', 'draft' ], |
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.
We need to amend the preloading in https://github.com/WordPress/gutenberg/blob/trunk/lib/compat/wordpress-6.3/navigation-block-preloading.php
Also can we add a link to that file as a code comment so folks are aware of this in future?
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 think this change might mean we can actually only have a single preloaded request which would be excellent. Needs to be carefully tested though.
@@ -19,6 +19,25 @@ import SidebarNavigationItem from '../sidebar-navigation-item'; | |||
import { PRELOADED_NAVIGATION_MENUS_QUERY } from './constants'; | |||
import { useLink } from '../routes/link'; | |||
|
|||
// Copied from packages/block-library/src/navigation/edit/navigation-menu-selector.js. |
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.
Note: I'm happy with this duplication. However let's track it in #51455
I have updated the two preloaded endpoints so that they are almost identical. However one of them uses the _locale param and the other does not. It looks non-trivial to get these aligned - one endpoint it called using |
packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/constants.js
Show resolved
Hide resolved
I agree this PR shouldn't be concerned with normalizing any preloaded queries. As long as the changes to the query in the JS has been updated in the PHP then it's fine. |
Are we sure we want the drafts to show up in the browse mode sidebar? I feel as if drafts are a lower level type of data whcih should be found in a more expanded view not in the sidebar. |
A good question. We do already show these in the navigation block, so I think if we don't want them here we shouldn't show them there either. When you create a new navigation it's in a draft state, so we probably need to show it... |
I think we should show it but we need to be clear about the statuses of each 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.
I tested this in all ways i could think of and it does what it says - shows navigation posts in the site editor sidebar which are not published yet,
@@ -71,7 +71,12 @@ function selectNavigationMenus( select ) { | |||
const args = [ | |||
'postType', | |||
'wp_navigation', | |||
{ per_page: -1, status: [ 'publish', 'draft' ] }, | |||
{ |
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.
You'll need to amend the tests with this query.
I think perhaps these tests are too tied to implementation details 🤔
@getdave I consolidated the settings into a constant, so that it's kept in sync in both places it's used. Does that look good to you? |
'postType', | ||
'wp_navigation', | ||
{ | ||
per_page: -1, |
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.
Won't this need to be 100
to match with the PHP preloading? I think we have middleware on the client side that doesn't allow unbounded queries (i.e. -1
) but worth double checking.
I noted some potential things to consider before we merge this. Also the tests are going to fail until you update them to account for the change to include draft menus. |
Once this is merged we'll need to ensure the changes are included in WordPress/wordpress-develop#4628 |
I fixed the tests... |
@@ -8,6 +8,7 @@ import { store as coreStore } from '@wordpress/core-data'; | |||
* Internal dependencies | |||
*/ | |||
import useNavigationMenu from '../use-navigation-menu'; | |||
import { SELECT_NAVIGATION_MENUS_ARGS } from '../constants'; |
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 know this might seem like a massive nit, but I would really prefer to avoid relying on app code to provide abstraction in tests.
Whilst it seems good now, further down the line it could lead to unexpected consequences with tests "automatically" adapting their behaviour when the production code changes.
I'd much prefer to see these arguments inlined and have a tonne of duplication which keeps things explicit and avoids abstraction in tests 🙏
import { SELECT_NAVIGATION_MENUS_ARGS } from '../constants'; |
per_page: -1, | ||
per_page: 100, | ||
status: [ 'publish', 'draft' ], | ||
order: 'desc', | ||
orderby: 'date', |
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 much prefer the inlining here 👍
…vigation-menus/constants.js Co-authored-by: Dave Smith <[email protected]>
Backporting in WordPress/wordpress-develop#4628 |
…1422) * Navigation: List draft navigations * Add a draft status to the navigation name * update the endpoints to make them more similar * Update packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/constants.js Co-authored-by: Dave Smith <[email protected]> * pacify PHPCS * update the entity to check * move the query config to a const * update tests * remove the abstraction for tests --------- Co-authored-by: Dave Smith <[email protected]>
What?
List draft navigations as well as published ones in the navigation sidebar, so that the browse mode matches the block.
Fixes #51417.
Why?
So that the same list appears in both places.
How?
Change the preload query. The other alternative is to hide the draft ones in the block.
Testing Instructions
Check that the list of navigations in the sidebar in browse mode is the same as the list in the block inspector controls.