grafana/public/app/core/copy/appNotification.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-10-24 07:33:53 -05:00
import { AppNotification, AppNotificationSeverity, AppNotificationTimeout } from 'app/types';
import { getMessageFromError } from 'app/core/utils/errors';
2018-10-24 07:33:53 -05:00
const defaultSuccessNotification = {
2018-10-24 07:33:53 -05:00
title: '',
text: '',
severity: AppNotificationSeverity.Success,
icon: 'check',
2018-10-24 07:33:53 -05:00
timeout: AppNotificationTimeout.Success,
};
const defaultWarningNotification = {
2018-10-24 07:33:53 -05:00
title: '',
text: '',
severity: AppNotificationSeverity.Warning,
icon: 'exclamation-triangle',
2018-10-24 07:33:53 -05:00
timeout: AppNotificationTimeout.Warning,
};
const defaultErrorNotification = {
2018-10-24 07:33:53 -05:00
title: '',
text: '',
severity: AppNotificationSeverity.Error,
icon: 'exclamation-triangle',
2018-10-24 07:33:53 -05:00
timeout: AppNotificationTimeout.Error,
};
export const createSuccessNotification = (title: string, text = ''): AppNotification => ({
2018-10-24 07:33:53 -05:00
...defaultSuccessNotification,
title: title,
text: text,
id: Date.now(),
});
export const createErrorNotification = (title: string, text = '', component?: React.ReactElement): AppNotification => {
2019-02-05 07:42:29 -06:00
return {
...defaultErrorNotification,
text: getMessageFromError(text),
title,
2019-02-05 07:42:29 -06:00
id: Date.now(),
component,
2019-02-05 07:42:29 -06:00
};
};
2018-10-24 07:33:53 -05:00
export const createWarningNotification = (title: string, text = ''): AppNotification => ({
2018-10-24 07:33:53 -05:00
...defaultWarningNotification,
title: title,
text: text,
id: Date.now(),
});