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 <heikki.hellgren@op.fi>
This commit is contained in:
Hellgren Heikki
2025-02-19 18:04:06 +02:00
parent 8dee48768c
commit 20e8d12655
3 changed files with 10 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-notifications-backend': patch
---
Fix null topics being returned from notification API
@@ -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 });
@@ -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) };
}
}