Merge pull request #23882 from mareklibra/export.severities

fix(notifications): export notificationSeverities for reuse
This commit is contained in:
Patrik Oldsberg
2024-04-13 16:11:45 +02:00
committed by GitHub
6 changed files with 41 additions and 10 deletions
@@ -25,6 +25,7 @@ import {
import {
Notification,
NotificationSeverity,
notificationSeverities,
} from '@backstage/plugin-notifications-common';
import { Knex } from 'knex';
@@ -49,16 +50,9 @@ const NOTIFICATION_COLUMNS = [
'saved',
];
const severities: NotificationSeverity[] = [
'critical',
'high',
'normal',
'low',
];
export const normalizeSeverity = (input?: string): NotificationSeverity => {
let lower = (input ?? 'normal').toLowerCase() as NotificationSeverity;
if (severities.indexOf(lower) < 0) {
if (notificationSeverities.indexOf(lower) < 0) {
lower = 'normal';
}
return lower;
@@ -219,8 +213,8 @@ export class DatabaseNotificationsStore implements NotificationsStore {
} // or match both if undefined
if (options.minimumSeverity !== undefined) {
const idx = severities.indexOf(options.minimumSeverity);
const equalOrHigher = severities.slice(0, idx + 1);
const idx = notificationSeverities.indexOf(options.minimumSeverity);
const equalOrHigher = notificationSeverities.slice(0, idx + 1);
query.whereIn('severity', equalOrHigher);
}