diff --git a/.changeset/moody-pianos-notice.md b/.changeset/moody-pianos-notice.md new file mode 100644 index 0000000000..beb686fb6b --- /dev/null +++ b/.changeset/moody-pianos-notice.md @@ -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. diff --git a/.github/vale/config/vocabularies/Backstage/accept.txt b/.github/vale/config/vocabularies/Backstage/accept.txt index 043728013f..b525d7e48e 100644 --- a/.github/vale/config/vocabularies/Backstage/accept.txt +++ b/.github/vale/config/vocabularies/Backstage/accept.txt @@ -475,3 +475,4 @@ Zolotusky zoomable zsh scrollable +severities diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts index f4f1f174be..ae548a9892 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts @@ -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); } diff --git a/plugins/notifications-common/api-report.md b/plugins/notifications-common/api-report.md index bd01aa7f5a..bdcd202ed3 100644 --- a/plugins/notifications-common/api-report.md +++ b/plugins/notifications-common/api-report.md @@ -39,6 +39,9 @@ export type NotificationReadSignal = { notification_ids: string[]; }; +// @public +export const notificationSeverities: NotificationSeverity[]; + // @public (undocumented) export type NotificationSeverity = 'critical' | 'high' | 'normal' | 'low'; diff --git a/plugins/notifications-common/src/constants.ts b/plugins/notifications-common/src/constants.ts new file mode 100644 index 0000000000..3c0610737c --- /dev/null +++ b/plugins/notifications-common/src/constants.ts @@ -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', +]; diff --git a/plugins/notifications-common/src/index.ts b/plugins/notifications-common/src/index.ts index 8d9f26f07a..7d74c75be8 100644 --- a/plugins/notifications-common/src/index.ts +++ b/plugins/notifications-common/src/index.ts @@ -21,3 +21,4 @@ */ export * from './types'; +export * from './constants';