You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add new primitives to easily wire confirmation dialogs onto actions - #755
This PR adds two new primitives to easily wire Confirmation dialogs onto actions, allowing us to skip the whole prop definition + conditional displays in templates via:
a confirmable decorator that carry the whole logic and gates a method call
a imperative confirm function that carry that same logic for developers who would need to call it manually
lists:
delete_confirmation:
title: Delete this list?subtitle: It can't be undone.confirm: Deletecancel: Cancel
Imperative
In case you need to do this in the middle of existing code or simply want to run the dialog imperatively instead of via the decorator, you can still call it as follows:
Added/updated documentation with Figma design link. Don't forget to replace "design" by "file" in the URL. For example https://www.figma.com/file/example
…methods
Closing the dialog on a route change or the owner's destruction while the
method runs no longer resolves the call early: it still settles with the
method's result or error.
@confirmable now only accepts methods returning void or Promise<void>, since
the result is dropped once a dialog shows.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
A synchronous route transition inside onConfirm can dismiss the dialog before loading is set, incorrectly resolving the confirmation as cancelled and swallowing a later action rejection.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Mark confirmation action running before invoking onConfirm
If onConfirm starts a route transition synchronously before returning its promise, dismiss() runs while state.loading is still false and resolves the confirmation as cancelled. The caller therefore stops waiting for the action, and a later rejection is swallowed because the confirmation promise has already resolved. Mark the action as running before invoking onConfirm, and use the guarded settle() path for synchronous completion/errors too, since the transition may already have closed the dialog.
With @glimmer/component 2, ember-intl 6.4's private SafeString type no
longer resolves, which turns intl.t's return type, and the confirmation
texts typed from it, into any. 6.5 types it from @ember/template.
the generic signature just seems complex but it's just to say that the function might take any number of arguments. From the consumer's level, this will be totally obfuscated as type Text is not even exported
The reason will be displayed to describe this comment to others. Learn more.
@Miexil the thing is to have only one source of truth for the confirmable pattern usages, so having both public functions (the decorator and this one, the imperative way) in the same file makes sense to me (instead of decorator = one file and imperative = another file to import from)
A dialog opened on a context its owner never destroys (a plain object, a handler) stayed in activeDialog after the owner's teardown: its promise never settled and, if it was loading, every later confirm() resolved false. Tests cover it, along with a second confirmation from another context replacing the open one.
This file contains hidden or 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.
What does this PR do?
This PR adds two new primitives to easily wire Confirmation dialogs onto actions, allowing us to skip the whole prop definition + conditional displays in templates via:
confirmabledecorator that carry the whole logic and gates a method callconfirmfunction that carry that same logic for developers who would need to call it manuallyUsage
Decorator
with a translation bundle looking like:
Imperative
In case you need to do this in the middle of existing code or simply want to run the dialog imperatively instead of via the decorator, you can still call it as follows:
What are the observable changes?
Good PR checklist