Files
grafana/public/app/core/copy/appNotification.ts
kay delaney 99411bf37a Types: Adds type safety to appEvents (#19418)
* Types: Add type safety to appEvents
2019-10-14 09:27:47 +01:00

50 lines
1.2 KiB
TypeScript

import { AppNotification, AppNotificationSeverity, AppNotificationTimeout } from 'app/types';
import { getMessageFromError } from 'app/core/utils/errors';
const defaultSuccessNotification = {
title: '',
text: '',
severity: AppNotificationSeverity.Success,
icon: 'fa fa-check',
timeout: AppNotificationTimeout.Success,
};
const defaultWarningNotification = {
title: '',
text: '',
severity: AppNotificationSeverity.Warning,
icon: 'fa fa-exclamation',
timeout: AppNotificationTimeout.Warning,
};
const defaultErrorNotification = {
title: '',
text: '',
severity: AppNotificationSeverity.Error,
icon: 'fa fa-exclamation-triangle',
timeout: AppNotificationTimeout.Error,
};
export const createSuccessNotification = (title: string, text = ''): AppNotification => ({
...defaultSuccessNotification,
title: title,
text: text,
id: Date.now(),
});
export const createErrorNotification = (title: string, text = ''): AppNotification => {
return {
...defaultErrorNotification,
title: title,
text: getMessageFromError(text),
id: Date.now(),
};
};
export const createWarningNotification = (title: string, text = ''): AppNotification => ({
...defaultWarningNotification,
title: title,
text: text,
id: Date.now(),
});