Skip to content

Commit

Permalink
Update notification modifier for new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
wenincode authored and chris-hut committed Oct 16, 2023
1 parent cea2ab9 commit 964ef50
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions ui/packages/consul-ui/app/modifiers/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
}
}

0 comments on commit 964ef50

Please sign in to comment.