-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Merged
draganescu
merged 4 commits into
WordPress:trunk
from
chad1008:migrate/delete-menu-confirm-dialog
Jan 31, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bb09c68
Migrate Edit Navigation screen "Delete menu" button from `confirm()` …
chad1008 06b5467
add handler method to reset `showConfirmDialog` state on `ConfirmDial…
chad1008 11bd435
simplify ConfirmDialog state using the built in isOpen prop
chad1008 4667075
explicitly close ConfirmDialog after confirmation
chad1008 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?)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.
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, thedeleteMenu
function comes from theuseNavigationEditor()
hook, and it is indeed anasync
function.So yeah, we could technically
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?We should have access to the loading state via the
isMenuBeingDeleted
prop passed to this component, but I don't think that theConfirmDialog
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.
c.c. @adamziel as this is a good example of lacking a clear and simple way to do loading state + error handling with the current API 😆 . (#38135)
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'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 whentrue
?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.
Yeah, I think so. Since it should be a common feature, we can allow a simple prop like
isLoading
ordisabled
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.
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 ais
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.