Files
nomad/ui/app/services/notifications.js
Phil Renaud fcd51dce4b [ui] Fix: New toast notifications no longer last forever (#16384)
* Removes an errant console.log and corrects a default sticky=true on toast notifications

* Default so no need to refault
2023-03-08 14:50:18 -05:00

42 lines
1.1 KiB
JavaScript

// @ts-check
import { default as FlashService } from 'ember-cli-flash/services/flash-messages';
/**
* @typedef {Object} NotificationObject
* @property {string} title
* @property {string} [message]
* @property {string} [type]
* @property {string} [color = 'neutral']
* @property {boolean} [sticky = true]
* @property {boolean} [destroyOnClick = false]
* @property {number} [timeout = 5000]
*/
/**
* @class NotificationsService
* @extends FlashService
* A wrapper service around Ember Flash Messages, for adding notifications to the UI
*/
export default class NotificationsService extends FlashService {
/**
* @param {NotificationObject} notificationObject
* @returns {FlashService}
*/
add(notificationObject) {
// Set some defaults
if (!('type' in notificationObject)) {
notificationObject.type = notificationObject.color || 'neutral';
}
if (!('destroyOnClick' in notificationObject)) {
notificationObject.destroyOnClick = false;
}
if (!('timeout' in notificationObject)) {
notificationObject.timeout = 5000;
}
return super.add(notificationObject);
}
}