fix(notifications): export notificationSeverities for reuse
The ordered array of constants is exported by the notifications-common for reusability by other plugins. Signed-off-by: Marek Libra <marek.libra@gmail.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-notifications-backend': patch
|
||||
'@backstage/plugin-notifications-common': patch
|
||||
---
|
||||
|
||||
The ordered list of notifications' severities is exported by notifications-common for reusability.
|
||||
@@ -475,3 +475,4 @@ Zolotusky
|
||||
zoomable
|
||||
zsh
|
||||
scrollable
|
||||
severities
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ export type NotificationReadSignal = {
|
||||
notification_ids: string[];
|
||||
};
|
||||
|
||||
// @public
|
||||
export const notificationSeverities: NotificationSeverity[];
|
||||
|
||||
// @public (undocumented)
|
||||
export type NotificationSeverity = 'critical' | 'high' | 'normal' | 'low';
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2024 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { NotificationSeverity } from './types';
|
||||
|
||||
/** Ordered list of severities used by the Notifications.
|
||||
*
|
||||
* @public */
|
||||
export const notificationSeverities: NotificationSeverity[] = [
|
||||
'critical',
|
||||
'high',
|
||||
'normal',
|
||||
'low',
|
||||
];
|
||||
@@ -21,3 +21,4 @@
|
||||
*/
|
||||
|
||||
export * from './types';
|
||||
export * from './constants';
|
||||
|
||||
Reference in New Issue
Block a user