From c75091ca3a13f6d14ea44ce938a7b9ae58b986d5 Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Fri, 5 Jul 2024 16:09:16 +0530 Subject: [PATCH] [WEB-1803] chore: workspace notification sorting when we refresh the notifications on workspace notifications (#5049) * chore: workspace notification sorting when we refresh the notifications on workspace notifications * chore: replaced sorting with ISO to EPOCH * chore: converted obj to array --- .../notifications/workspace-notifications.store.ts | 10 +++++++++- web/helpers/date-time.helper.ts | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/web/core/store/notifications/workspace-notifications.store.ts b/web/core/store/notifications/workspace-notifications.store.ts index 2cfe37990..59e9b07a2 100644 --- a/web/core/store/notifications/workspace-notifications.store.ts +++ b/web/core/store/notifications/workspace-notifications.store.ts @@ -1,4 +1,5 @@ import isEmpty from "lodash/isEmpty"; +import orderBy from "lodash/orderBy"; import set from "lodash/set"; import update from "lodash/update"; import { action, makeObservable, observable, runInAction } from "mobx"; @@ -18,6 +19,8 @@ import { ENotificationTab, TNotificationTab, } from "@/constants/notification"; +// helpers +import { convertToEpoch } from "@/helpers/date-time.helper"; // services import workspaceNotificationService from "@/services/workspace-notification.service"; // store @@ -119,7 +122,12 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore { */ notificationIdsByWorkspaceId = computedFn((workspaceId: string) => { if (!workspaceId || isEmpty(this.notifications)) return undefined; - const workspaceNotificationIds = Object.values(this.notifications || {}) + const workspaceNotifications = orderBy( + Object.values(this.notifications || []), + (n) => convertToEpoch(n.created_at), + ["desc"] + ); + const workspaceNotificationIds = workspaceNotifications .filter((n) => n.workspace === workspaceId) .filter((n) => { if (!this.filters.archived && !this.filters.snoozed) { diff --git a/web/helpers/date-time.helper.ts b/web/helpers/date-time.helper.ts index 1eb7fdd70..b6ec11655 100644 --- a/web/helpers/date-time.helper.ts +++ b/web/helpers/date-time.helper.ts @@ -279,6 +279,18 @@ export const convertToISODateString = (dateString: string | undefined) => { return date.toISOString(); }; +/** + * returns the date string in Epoch regardless of the timezone in input date string + * @param dateString + * @returns + */ +export const convertToEpoch = (dateString: string | undefined) => { + if (!dateString) return dateString; + + const date = new Date(dateString); + return date.getTime(); +}; + /** * get current Date time in UTC ISO format * @returns