From 964ef50df35d3d868812e0fe18dcaa2cb9b60b00 Mon Sep 17 00:00:00 2001 From: wenincode Date: Fri, 13 Oct 2023 14:22:14 -0600 Subject: [PATCH] Update notification modifier for new structure --- .../consul-ui/app/modifiers/notification.js | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ui/packages/consul-ui/app/modifiers/notification.js b/ui/packages/consul-ui/app/modifiers/notification.js index 1da17f4fb447..3b0f5ef05bb3 100644 --- a/ui/packages/consul-ui/app/modifiers/notification.js +++ b/ui/packages/consul-ui/app/modifiers/notification.js @@ -5,20 +5,28 @@ import Modifier from 'ember-modifier'; import { inject as service } from '@ember/service'; +import { registerDestructor } from '@ember/destroyable'; +function cleanup(instance) { + if (instance && instance?.named?.sticky) { + instance.notify?.clearMessages(); + } +} export default class NotificationModifier extends Modifier { @service('flashMessages') notify; - didInstall() { - this.element.setAttribute('role', 'alert'); - this.element.dataset['notification'] = null; + modify(element, _, named) { + this.named = named; + element.setAttribute('role', 'alert'); + element.dataset['notification'] = null; + const options = { timeout: 6000, extendedTimeout: 300, - ...this.args.named, + ...named, }; - options.dom = this.element.outerHTML; - this.element.remove(); + options.dom = element.outerHTML; + element.remove(); this.notify.clearMessages(); if (typeof options.after === 'function') { Promise.resolve() @@ -28,16 +36,13 @@ export default class NotificationModifier extends Modifier { throw e; } }) - .then((res) => { + .then((_) => { this.notify.add(options); }); } else { this.notify.add(options); } - } - willDestroy() { - if (this.args.named.sticky) { - this.notify.clearMessages(); - } + + registerDestructor(this, cleanup); } }