diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts index 8abb0f1c06..c3f42767d7 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts @@ -228,7 +228,7 @@ describe.each(databases.eachSupportedId())( await insertNotification({ id: id1, ...testNotification, - created: new Date(Date.now() - 1 * 60 * 60 * 1000 /* an hour ago */), + created: new Date(now - 1 * 60 * 60 * 1000 /* an hour ago */), }); await insertNotification({ id: id2, @@ -270,7 +270,7 @@ describe.each(databases.eachSupportedId())( const notifications = await storage.getNotifications({ user, - createdAfter: new Date(Date.now() - 5 * 60 * 1000 /* 5mins */), + createdAfter: new Date(now - 5 * 60 * 1000 /* 5 mins */), }); expect(notifications.length).toBe(6); expect(notifications.at(0)?.id).toEqual(id7); diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts index 0ff1d10c56..4c2d2cc5e1 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts @@ -171,8 +171,7 @@ export class DatabaseNotificationsStore implements NotificationsStore { countOptions.sort = null; const notificationQuery = this.getNotificationsBaseQuery(countOptions); const response = await notificationQuery.count('* as CNT'); - const totalCount = Number.parseInt(response[0].CNT.toString(), 10); - return totalCount; + return Number(response[0].CNT); } async saveNotification(notification: Notification) { diff --git a/plugins/notifications-backend/src/service/router.ts b/plugins/notifications-backend/src/service/router.ts index b99350e9e4..9939040d37 100644 --- a/plugins/notifications-backend/src/service/router.ts +++ b/plugins/notifications-backend/src/service/router.ts @@ -212,8 +212,10 @@ export async function createRouter( opts.createdAfter = new Date(sinceEpoch); } - const notifications = await store.getNotifications(opts); - const totalCount = await store.getNotificationsCount(opts); + const [notifications, totalCount] = await Promise.all([ + store.getNotifications(opts), + store.getNotificationsCount(opts), + ]); res.send({ totalCount, notifications, diff --git a/plugins/notifications/api-report.md b/plugins/notifications/api-report.md index 666daebdfe..caf9b4a2e5 100644 --- a/plugins/notifications/api-report.md +++ b/plugins/notifications/api-report.md @@ -14,6 +14,7 @@ import { Notification as Notification_2 } from '@backstage/plugin-notifications- import { NotificationStatus } from '@backstage/plugin-notifications-common'; import { default as React_2 } from 'react'; import { RouteRef } from '@backstage/core-plugin-api'; +import { TableProps } from '@backstage/core-components'; // @public (undocumented) export type GetNotificationsOptions = { @@ -24,6 +25,12 @@ export type GetNotificationsOptions = { createdAfter?: Date; }; +// @public (undocumented) +export type GetNotificationsResponse = { + notifications: Notification_2[]; + totalCount: number; +}; + // @public (undocumented) export interface NotificationsApi { // (undocumented) @@ -31,7 +38,7 @@ export interface NotificationsApi { // (undocumented) getNotifications( options?: GetNotificationsOptions, - ): Promise; + ): Promise; // (undocumented) getStatus(): Promise; // (undocumented) @@ -51,7 +58,7 @@ export class NotificationsClient implements NotificationsApi { // (undocumented) getNotifications( options?: GetNotificationsOptions, - ): Promise; + ): Promise; // (undocumented) getStatus(): Promise; // (undocumented) @@ -83,14 +90,23 @@ export const NotificationsTable: ({ notifications, onUpdate, setContainsText, + onPageChange, + onRowsPerPageChange, + page, + pageSize, + totalCount, }: NotificationsTableProps) => React_2.JSX.Element; // @public (undocumented) -export type NotificationsTableProps = { +export type NotificationsTableProps = Pick< + TableProps, + 'onPageChange' | 'onRowsPerPageChange' | 'page' | 'totalCount' +> & { isLoading?: boolean; notifications?: Notification_2[]; onUpdate: () => void; setContainsText: (search: string) => void; + pageSize: number; }; // @public (undocumented)