[ experimental/nav-menus ] Add/menu location management#21351
[ experimental/nav-menus ] Add/menu location management#21351noisysocks merged 17 commits intomasterfrom
Conversation
|
Size Change: +877 B (0%) Total Size: 825 kB
ℹ️ View Unchanged
|
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
|
Looking at the requests you are sending here, they seem wrong. Requests are being sent the menus endpoint like so. However, this is wrong. You should be updating a menu by it's id. Work noting that all locations need to be passed in the
Hope this is helpful. |
|
Howdy @spacedmonkey this is weird since I see this in my tools: So it looks like I am sending the <menu_id> . And that works. What doesn't seem to work is sending quick POST to assign menus to locations: In this GIF you can see that if I only set one menu it is saved right, but if I try to set two menus to two locations, they get set wrongly (one of the two is not saved). Is there anything in the API that allows me one bulk call? Also why would there be a problem to send serial requests as long as they're about different menus and different locations? |
|
These are the request I see. Not what I am seeing. I can't see a id in those request. Also the id should not be passed as a query param in this case, should be pass in the url, like a post update.
Updating a term uses editable methods ( WP_REST_Server::EDITABLE ) which are Another issue with the PR, is that I think that javascript will need to await for the response of the apiFetch. I think if all requests are sent at the same time, that there will be a race conditions where data is overridden. |
6bab1cf to
635d261
Compare
|
Great catch with the "await"-ing for menu location assignment @spacedmonkey, I didn't expect that to be the need since I've always sent different id/location combos so I thought they're independent. Now with awaiting, multiple assignment in one save works all right. |
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
|
@noisysocks I've addressed your review, but still need to refactor so that assigning one menu to multiple locations works. |
|
This is almost ready, but now upon changing tabs the state is not correct as the menu locations are not fetched again and the edits are not saved in the state. |
|
Ok, we're good for a re-review now. |
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
|
Couple of tweaks to improve the code but the new changes are now sending the correct data to the api. |
41174fc to
993f59f
Compare
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/menu-select-control.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/menu-select-control.js
Outdated
Show resolved
Hide resolved
|
I really like the idea of using a hook for this! I think can we can take it a little bit further and have the hook fully encapsulate the data structure that the REST API needs and expose only an API that aligns closely with the UI of the Manage Locations tab. What do you think? const [
// Object that maps menu location names to an object containing menu location name, description and (possibly null) assigned menu ID.
menuLocations, // Record<string, { name: string, description: string, assignedMenuID: number? }>
// Function that assigns the given menu ID to the given menu location.
assignMenuLocationMenu, // ( menuLocationName: string, menuID: number ) => void
// Function that persists the current state of menuLocations using REST API.
saveMenuLocations, // () => void
] = useMenuLocations();
...
<form onSubmit={ saveMenuLocations }>
...
{ map( menuLocations, ( menuLocation ) => (
{ menuLocation.description }
...
<SelectControl
options={ availableMenuOptions }
value={ menuLocation.assignedMenuID }
onChange={ ( menuID ) => {
assignMenuLocationMenu( menuLocation.name, menuID );
} }
/>
) ) }
...
</form> |
|
Hey @noisysocks your review suggestions are now baked in. Also, I've moved some of the form's onSubmit logic into the hook and re-renamed the variables in the Unfortunately we need to keep |
draganescu
left a comment
There was a problem hiding this comment.
Ok so I've added all the review items.
@adamziel removing the api refresh, does not show the spinner, which creates the need for a notification. I would like to add notifications in a separate PR.
@noisysocks the new control is gone, so less code \o/
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/use-menu-locations.js
Outdated
Show resolved
Hide resolved
packages/edit-navigation/src/components/menu-locations-editor/index.js
Outdated
Show resolved
Hide resolved
|
@draganescu sounds good! Also, I think this should use a single save request in the grand scheme of things, not a request per menu location. That being said, it doesn't have to be in this PR - let's proceed as it is. |
|
@draganescu it works! 👍One last note I have is that the state manipulation logic is pretty verbose. Storing state as |
That is very tempting but: |
main change is elliminating some useless falsey checks
d70221a to
3126b46
Compare
|
Let's get this in and iterate! Thanks @draganescu! |





Description
Closes #21283
How has this been tested?
Tested locally by:
Screenshots
Types of changes
Non breaking additions to the edit-navigaion package.
Known issues
These issues are either b/c the payload sent to the API is wrong or there is some bug in the menus endpoint. cc @spacedmonkey