From 20e8d126558f71e1285eba4c37ca6482d1bf89bb Mon Sep 17 00:00:00 2001 From: Hellgren Heikki Date: Wed, 19 Feb 2025 18:04:06 +0200 Subject: [PATCH] fix(notifications): filter null topics fixes the frontend topic filter when there are notifications without any topic in the database closes #28902 Signed-off-by: Hellgren Heikki --- .changeset/itchy-houses-whisper.md | 5 +++++ .../src/database/DatabaseNotificationsStore.test.ts | 3 ++- .../src/database/DatabaseNotificationsStore.ts | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .changeset/itchy-houses-whisper.md diff --git a/.changeset/itchy-houses-whisper.md b/.changeset/itchy-houses-whisper.md new file mode 100644 index 0000000000..2b633dbdee --- /dev/null +++ b/.changeset/itchy-houses-whisper.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-notifications-backend': patch +--- + +Fix null topics being returned from notification API diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts index d4edcd1e89..0386b516a2 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts @@ -14,9 +14,9 @@ * limitations under the License. */ import { + mockServices, TestDatabaseId, TestDatabases, - mockServices, } from '@backstage/backend-test-utils'; import { DatabaseNotificationsStore } from './DatabaseNotificationsStore'; import { Knex } from 'knex'; @@ -748,6 +748,7 @@ describe.each(databases.eachSupportedId())( await storage.saveNotification(testNotification1); await storage.saveNotification(testNotification2); await storage.saveBroadcast(testNotification3); + await storage.saveNotification(testNotification4); // One without topic await storage.saveNotification(otherUserNotification); const topics = await storage.getTopics({ user }); diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts index cf19874ff2..b258f38e7a 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts @@ -570,7 +570,9 @@ export class DatabaseNotificationsStore implements NotificationsStore { ...options, orderField: [{ field: 'topic', order: 'asc' }], }); - const topics = await notificationQuery.distinct(['topic']); + const topics = await notificationQuery + .whereNotNull('topic') + .distinct(['topic']); return { topics: topics.map(row => row.topic) }; } }