[WEB-1889] fix: handled tapping on a notification in Notifications from mobile in inbox issue and issue peek overview component (#5074)

* fix: handled tapping on a notification in Notifications from mobile in inbox issue and issue peekoverview component

* fix: code cleanup

* fix: code cleanup on workspace notification store

* fix: updated selected notification on workspace notification store
This commit is contained in:
guru_sainath 2024-07-08 18:52:30 +05:30 committed by GitHub
parent a623456e63
commit 7767be2e21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 131 additions and 99 deletions

View file

@ -5,9 +5,9 @@ import update from "lodash/update";
import { action, makeObservable, observable, runInAction } from "mobx";
import { computedFn } from "mobx-utils";
import {
TCurrentSelectedNotification,
TNotification,
TNotificationFilter,
TNotificationLite,
TNotificationPaginatedInfo,
TNotificationPaginatedInfoQueryParams,
TUnreadNotificationsCount,
@ -36,19 +36,20 @@ export interface IWorkspaceNotificationStore {
unreadNotificationsCount: TUnreadNotificationsCount;
notifications: Record<string, INotification>; // notification_id -> notification
currentNotificationTab: TNotificationTab;
currentSelectedNotification: TCurrentSelectedNotification;
currentSelectedNotificationId: string | undefined;
paginationInfo: Omit<TNotificationPaginatedInfo, "results"> | undefined;
filters: TNotificationFilter;
// computed
// computed functions
notificationIdsByWorkspaceId: (workspaceId: string) => string[] | undefined;
notificationLiteByNotificationId: (notificationId: string | undefined) => TNotificationLite;
// helper actions
mutateNotifications: (notifications: TNotification[]) => void;
updateFilters: <T extends keyof TNotificationFilter>(key: T, value: TNotificationFilter[T]) => void;
updateBulkFilters: (filters: Partial<TNotificationFilter>) => void;
// actions
setCurrentNotificationTab: (tab: TNotificationTab) => void;
setCurrentSelectedNotification: (notification: TCurrentSelectedNotification) => void;
setCurrentSelectedNotificationId: (notificationId: string | undefined) => void;
setUnreadNotificationsCount: (type: "increment" | "decrement") => void;
getUnreadNotificationsCount: (workspaceSlug: string) => Promise<TUnreadNotificationsCount | undefined>;
getNotifications: (
@ -70,13 +71,7 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore {
};
notifications: Record<string, INotification> = {};
currentNotificationTab: TNotificationTab = ENotificationTab.ALL;
currentSelectedNotification: TCurrentSelectedNotification = {
workspace_slug: undefined,
project_id: undefined,
notification_id: undefined,
issue_id: undefined,
is_inbox_issue: false,
};
currentSelectedNotificationId: string | undefined = undefined;
paginationInfo: Omit<TNotificationPaginatedInfo, "results"> | undefined = undefined;
filters: TNotificationFilter = {
type: {
@ -96,13 +91,13 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore {
unreadNotificationsCount: observable,
notifications: observable,
currentNotificationTab: observable.ref,
currentSelectedNotification: observable,
currentSelectedNotificationId: observable,
paginationInfo: observable,
filters: observable,
// computed
// helper actions
setCurrentNotificationTab: action,
setCurrentSelectedNotification: action,
setCurrentSelectedNotificationId: action,
setUnreadNotificationsCount: action,
mutateNotifications: action,
updateFilters: action,
@ -154,6 +149,24 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore {
return workspaceNotificationIds;
});
/**
* @description get notification lite by notification id
* @param { string } notificationId
*/
notificationLiteByNotificationId = computedFn((notificationId: string | undefined) => {
if (!notificationId) return {} as TNotificationLite;
const { workspaceSlug } = this.store.router;
const notification = this.notifications[notificationId];
if (!notification || !workspaceSlug) return {} as TNotificationLite;
return {
workspace_slug: workspaceSlug,
project_id: notification.project,
notification_id: notification.id,
issue_id: notification.data?.issue?.id,
is_inbox_issue: notification.is_inbox_issue || false,
};
});
// helper functions
/**
* @description generate notification query params
@ -255,11 +268,11 @@ export class WorkspaceNotificationStore implements IWorkspaceNotificationStore {
/**
* @description set current selected notification
* @param { TCurrentSelectedNotification } notification
* @param { string | undefined } notificationId
* @returns { void }
*/
setCurrentSelectedNotification = (notification: TCurrentSelectedNotification): void => {
set(this, "currentSelectedNotification", notification);
setCurrentSelectedNotificationId = (notificationId: string | undefined): void => {
set(this, "currentSelectedNotificationId", notificationId);
};
/**