-
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
Migrate Edit Navigation screen "Delete menu" button from confirm()
…
#37492
Migrate Edit Navigation screen "Delete menu" button from confirm()
…
#37492
Conversation
Marking as |
Fixed - state is now handled more effectively, and the confirmation dialog is reset after the cancel button is clicked. |
…to the new `ConfirmDialog` component
…og` cancellation
4756009
to
06b5467
Compare
Updated this PR to simplify the implementation of ConfirmDialog (cc @ciampo) |
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.
Hey @chad1008 , thank you for working on this!
My feedback is basically the same as the one I left in PR 37491, including the consideration about unit/e2e tests.
Update:
Even with the last comment addressed, I'd still be reluctant to merge this PR until we find a good fix for the |
setShowConfirmDialog( false ); | ||
onDeleteMenu(); |
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.
Maybe we should await
for onDeleteMenu()
to finish? (I think it returns a promise?)
Bonus point if we can also catch errors here and display the message somewhere, but that's probably best for a different PR.
Another micro-optimization we can make is to show a loading state when the menu is still being deleted. Something like disabling the confirm button and showing a loading icon on the button. But again, probably best for a follow-up PR (I don't think it's possible now with the current API in __experimentalConfirmDialog
anyway).
These are all just nitpicking though, I think we can merge this and work on those if needed.
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.
Maybe we should
await
foronDeleteMenu()
to finish? (I think it returns a promise?)`
Hard to say for sure without any docs in this component.
I did a quick search in the codebase, and it looks like the only usage is in packages/edit-navigation/src/components/layout/index.js
. In that case, the deleteMenu
function comes from the useNavigationEditor()
hook, and it is indeed an async
function.
So yeah, we could technically
await onDeleteMenu();
setShowConfirmDialog( false );
Bonus point if we can also catch errors here and display the message somewhere, but that's probably best for a different PR.
Given the delete function definition, it looks like errors are handled via the createErrorNotice
function, which seems to be connected to the notices store — I'm not familiar with what's the best "gutenberg" way to handle that?
Another micro-optimization we can make is to show a loading state when the menu is still being deleted. Something like disabling the confirm button and showing a loading icon on the button. But again, probably best for a follow-up PR (I don't think it's possible now with the current API in __experimentalConfirmDialog anyway).
We should have access to the loading state via the isMenuBeingDeleted
prop passed to this component, but I don't think that the ConfirmDialog
supports a way to disable its confirm button from outside the component (@fullofcaffeine can you confirm?)
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.
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.
supports a way to disable its confirm button from outside the component (@fullofcaffeine can you confirm?)
You're right, that's not supported at the moment. I think it's a great improvement idea! What would that API look like do you think? A simple isLoading
boolean prop that would disable the button and show a loading spinner when true
?
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.
A simple
isLoading
boolean prop that would disable the button and show a loading spinner whentrue
?
Yeah, I think so. Since it should be a common feature, we can allow a simple prop like isLoading
or disabled
to do the job.
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.
A simple
isLoading
boolean prop that would disable the button and show a loading spinner when true?
I think I like the sound of isDisabled
more as it is closer to what we want to achieve — disable interactions with the modal. Let's also add a is
in front of the prop to make it clear that it's a boolean flag.
We also have to disable pressing the ESC key and clicking on the background, and we'll have to make this feature work both in controlled and uncontrolled mode. We can discuss further these details and refine the UX separately in the PR implementing the feature.
Since this PR has been merged by @draganescu, let's add any remaining changes (potential e2e test improvements, and the points discussed in this conversation) in separate follow-up PRs (cc @chad1008 ). |
Related: #34153
Description
This PR aims to migrate the beta Navigation Editor's
Delete menu
button away from the currentconfirm()
implementation and instead use the new experimentalConfirmDialog
component.How has this been tested?
Running WordPress 5.8.2 via
wp-env
:Gutenberg > Experiments
Gutenberg > Navigation (beta)
Delete menu
button. Confirm there are no unexpected console errors and the newConfirmDialog
component is rendered instead of the browser'sconfirm()
prompt.Cancel
button. Confirm that the menu is still intact.Delete menu
button again, and this time selectOK
Delete menu
on all of themCreate your first menu
UINote, if you already have a menu saved from a previous session, attempting to delete it will result in an error. This doesn't appear to be related to this PR, and has been reported in #37794
I've tested in the latest Chrome, Firefox, and Safari.
Checklist:
*.native.js
files for terms that need renaming or removal).