diff --git a/addons/core/addon/decorators/notify.js b/addons/core/addon/decorators/notify.js index 5d34d4b48..2cf2c6b69 100644 --- a/addons/core/addon/decorators/notify.js +++ b/addons/core/addon/decorators/notify.js @@ -45,9 +45,15 @@ export function notifySuccess(notification) { * * @param {string|function} notification * @param {object} options - * @param {object} options.catch - defaults to false + * @param {object} options.sticky - defaults to true, whether or not to persist + * the notification until user dismissal + * @param {object} options.catch - defaults to false, whether or not to catch + * and squelch the error */ -export function notifyError(notification, options = { catch: false }) { +export function notifyError( + notification, + options = { catch: false, sticky: true } +) { return function (_target, _propertyKey, desc) { const method = desc.value; desc.value = async function () { @@ -67,9 +73,16 @@ export function notifyError(notification, options = { catch: false }) { ? intlService.t(candidateKey) : candidateKey; + // Default is `true`. Since `options` is a new object instance + // when passed, the values shown in the signature aren't + // true defaults. For example, if a value `{ catch: true }` were + // passed, `sticky` would actually be falsy, even though the intended + // default is `true`. Hence this extra step. + const sticky = options.sticky === undefined ? true : options.sticky; + notifyService.danger(text, { noticationType: 'error', - sticky: true, + sticky, dismiss: (flash) => flash.destroyMessage(), }); diff --git a/ui/admin/app/routes/scopes/scope/authenticate/method.js b/ui/admin/app/routes/scopes/scope/authenticate/method.js index 9b7ede0ae..10b29b80a 100644 --- a/ui/admin/app/routes/scopes/scope/authenticate/method.js +++ b/ui/admin/app/routes/scopes/scope/authenticate/method.js @@ -47,7 +47,10 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route { */ @action @loading - @notifyError(() => 'errors.authentication-failed.title', { catch: true }) + @notifyError(() => 'errors.authentication-failed.title', { + sticky: false, + catch: true, + }) async authenticate(creds) { const scope = this.modelFor('scopes.scope'); const authMethod = this.modelFor('scopes.scope.authenticate.method'); diff --git a/ui/desktop/app/routes/scopes/scope/authenticate/method.js b/ui/desktop/app/routes/scopes/scope/authenticate/method.js index 77b9cdae5..cba3d9997 100644 --- a/ui/desktop/app/routes/scopes/scope/authenticate/method.js +++ b/ui/desktop/app/routes/scopes/scope/authenticate/method.js @@ -54,7 +54,10 @@ export default class ScopesScopeAuthenticateMethodRoute extends Route { */ @action @loading - @notifyError(() => 'errors.authentication-failed.title', { catch: true }) + @notifyError(() => 'errors.authentication-failed.title', { + sticky: false, + catch: true, + }) async authenticate(creds) { const scope = this.modelFor('scopes.scope'); const authMethod = this.modelFor('scopes.scope.authenticate.method');