-
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
Menus endpoints don't allow for menu item reordering #21964
Comments
The menus endpoint does support the reordering of menu items. However, at the moment, there are check to see you do not place a menu item in the place of another, so 2 menu items can not be 5 for example. Meaning if you want to reorder a whole menu, you would have set the order in a clever way. So move everything back a order number first. So 9 moved to 10 etc, until 5 is free. This isn't great. The REST API doesn't currently support multiple updates in one request, which it may have to do. Thoughts @TimothyBJacobs |
Yeah this is what I was referring to in the ergonomic issues WP-API/menus-endpoints#28. To me the solution isn't making multiple updates in one request, because even if we allowed that, unless the updates were processed simultaneously on the server as well, you'd still run into the issue of orders stepping on each other. I think menu ordering needs to be thought of as a distinct RPC-like action. |
There is also this discussion about showing save/error notifications on save: I don't think we're able to provide a consistently good experience without an atomic navigation save endpoint that either stores all the changes at once or doesn't change anything at all. The worst possible scenario here is that 50% of the requests succeeds, and the other 50% does not not - which means the live site now is broken and it's quite hard to communicate how to get it fixed.
I am imagining the following scenario:
|
Agree with @adamziel. Could we collapse the
I can't think of a use case where we'd want to fetch a single menu item without also fetching its siblings, and, in WP Admin, the existing menu screens and the proposed Navigation screen all take a click Save to save everything at once approach. I know that menu items are stored as posts but this could be an implementation detail. |
To be clear what I meant, a would add an new endpoint that is specially designed for reordering.
This would make the menu order in one request. |
@spacedmonkey I'm thinking about a single API endpoint to save everything. Otherwise how would you handle partial success if we use multiple requests to save changes? |
Yes, I understand that. Menu items are storied as posts in WP. Each menu item has be updated in it's own request. I don't understand the issue here. |
@spacedmonkey let's imagine the following scenario: I have a website with a navigation such as: Now, I want to refresh it a little bit and achieve the following result: I go either to nav-menus.php, remove some undergraduate degrees, add graduate degrees and a bunch of submenu items, then I click save.
Let's imagine some of my requests worked and some other did not. There are multiple possible causes - a Gutenberg/WordPress bug, a network issue, a database availability problem. If that's a temporary network problem, we can just retry. If for whatever reason a request cannot be processed properly by the backend, retrying won't help. Ditto for more persistent network failure (like flaky internet that just disconnected mid-save). Now - what's stored in the database is neither what I started with, nor what I wanted to end up with. It's some interim state, and now it's live on my website. How do I know this happened? How should I fix it? I don't think it's just a corner case that we could dismiss.
The endpoint shouldn't be overly complex. I'm not sure about the frontend part - I'd need to take a deeper dive in core/data and such. But I'm happy to volunteer and prepare a proof of concept that we could discuss further. |
I can see that the difficulty here is the way the menu items are represented as posts, but I think the alternative being proposed is to move this transactional and error handling logic to the client side, which makes less sense to me as the client side code is further from the source of truth and less able to reason about the state of data. |
Just surfacing my early explorations: #22148 |
I think there are three issues here that need separating.
Though, I think we should consider how practical of a problem it is. From what I can tell of the customizer, it essentially does 2 where each menu item is validated. Then if validation is successful, does the actual saving. If the saving fails, this is sent back in the response, but as far as I can tell, not shown in the UI anywhere. Error Response{
"success": true,
"data": {
"setting_validities": {
"nav_menu_item[1176]": true
},
"changeset_status": "publish",
"next_changeset_uuid": "a30aa304-493c-479d-8c01-c75d39a2fb4e",
"nav_menu_item_updates": [
{
"post_id": 1176,
"previous_post_id": null,
"error": "test_error",
"status": "error"
}
]
}
} Given that, I don't think it is too likely for menu items to pass validation, but then fail when actually persisting the data. Maybe @westonruter could shed some light on the customizer menus implementation and how often the persistence of menu items actually fails. So from my perspective, we should 1) add a new ordering endpoint, 2) add batch processing to the REST API. For now, we could skip rolling back, but if it turned out to be a common issue we could work to support it. |
Correct. Only when all settings are validated should they actually be persisted to the DB.
How are you causing an error? From looking at the code, it doesn't look like the |
Thanks for clarifying @westonruter! I returned a new |
👋 @TimothyBJacobs what does "formally introduce" mean? |
@draganescu Introduce as a first-class feature. In other words, not tied so closely to the menus endpoint. |
Reordering menus is now functional and this issue can be closed. For now we're using the customizer endpoint, but the endgame there is using batch/bulk REST api endpoints. |
See #25096. |
Is your feature request related to a problem? Please describe.
For the experiment to use the navigation block in nav-menus.php, we need the block to have identical functionality to the
nav-menus.php
page. Part of this is the ability to reorder menu items.To save edits to a menu in the navigation block, we're currently using the
__experimental/menu-items
API endpoint to save each menu item individually. But this code prevents us from saving any changes to a menu item position, so we can't use this endpoint to reorder menu items.Describe the solution you'd like
A possible solution would be an endpoint that allowed us to save the menu as a whole for each edit, or to PATCH it, instead of saving items one by one.
Describe alternatives you've considered
Not sure if removing the check for potential duplicates qualifies as an alternative solution 😅
The text was updated successfully, but these errors were encountered: