Skip to content

Commit 8ae1c80

Browse files
prateekshourya29sriramveeraghanta
authored andcommitted
[WEB-1481] fix: inbox issue list update after changing issue status. (#4715)
1 parent 5827a3c commit 8ae1c80

File tree

3 files changed

+27
-39
lines changed

3 files changed

+27
-39
lines changed

web/components/inbox/content/inbox-issue-header.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const InboxIssueActionsHeader: FC<TInboxIssueActionsHeader> = observer((p
5252
const [declineIssueModal, setDeclineIssueModal] = useState(false);
5353
const [deleteIssueModal, setDeleteIssueModal] = useState(false);
5454
// store
55-
const { currentTab, deleteInboxIssue, inboxIssueIds } = useProjectInbox();
55+
const { currentTab, deleteInboxIssue, filteredInboxIssueIds } = useProjectInbox();
5656
const { data: currentUser } = useUser();
5757
const {
5858
membership: { currentProjectRole },
@@ -76,11 +76,11 @@ export const InboxIssueActionsHeader: FC<TInboxIssueActionsHeader> = observer((p
7676

7777
const redirectIssue = (): string | undefined => {
7878
let nextOrPreviousIssueId: string | undefined = undefined;
79-
const currentIssueIndex = inboxIssueIds.findIndex((id) => id === currentInboxIssueId);
80-
if (inboxIssueIds[currentIssueIndex + 1])
81-
nextOrPreviousIssueId = inboxIssueIds[currentIssueIndex + 1];
82-
else if (inboxIssueIds[currentIssueIndex - 1])
83-
nextOrPreviousIssueId = inboxIssueIds[currentIssueIndex - 1];
79+
const currentIssueIndex = filteredInboxIssueIds.findIndex((id) => id === currentInboxIssueId);
80+
if (filteredInboxIssueIds[currentIssueIndex + 1])
81+
nextOrPreviousIssueId = filteredInboxIssueIds[currentIssueIndex + 1];
82+
else if (filteredInboxIssueIds[currentIssueIndex - 1])
83+
nextOrPreviousIssueId = filteredInboxIssueIds[currentIssueIndex - 1];
8484
else nextOrPreviousIssueId = undefined;
8585
return nextOrPreviousIssueId;
8686
};
@@ -134,22 +134,22 @@ export const InboxIssueActionsHeader: FC<TInboxIssueActionsHeader> = observer((p
134134
})
135135
);
136136

137-
const currentIssueIndex = inboxIssueIds.findIndex((issueId) => issueId === currentInboxIssueId) ?? 0;
137+
const currentIssueIndex = filteredInboxIssueIds.findIndex((issueId) => issueId === currentInboxIssueId) ?? 0;
138138

139139
const handleInboxIssueNavigation = useCallback(
140140
(direction: "next" | "prev") => {
141-
if (!inboxIssueIds || !currentInboxIssueId) return;
141+
if (!filteredInboxIssueIds || !currentInboxIssueId) return;
142142
const activeElement = document.activeElement as HTMLElement;
143143
if (activeElement && (activeElement.classList.contains("tiptap") || activeElement.id === "title-input")) return;
144144
const nextIssueIndex =
145145
direction === "next"
146-
? (currentIssueIndex + 1) % inboxIssueIds.length
147-
: (currentIssueIndex - 1 + inboxIssueIds.length) % inboxIssueIds.length;
148-
const nextIssueId = inboxIssueIds[nextIssueIndex];
146+
? (currentIssueIndex + 1) % filteredInboxIssueIds.length
147+
: (currentIssueIndex - 1 + filteredInboxIssueIds.length) % filteredInboxIssueIds.length;
148+
const nextIssueId = filteredInboxIssueIds[nextIssueIndex];
149149
if (!nextIssueId) return;
150150
router.push(`/${workspaceSlug}/projects/${projectId}/inbox?inboxIssueId=${nextIssueId}`);
151151
},
152-
[currentInboxIssueId, currentIssueIndex, inboxIssueIds, projectId, router, workspaceSlug]
152+
[currentInboxIssueId, currentIssueIndex, filteredInboxIssueIds, projectId, router, workspaceSlug]
153153
);
154154

155155
const onKeyDown = useCallback(

web/components/inbox/sidebar/root.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const InboxSidebar: FC<IInboxSidebarProps> = observer((props) => {
4444
currentTab,
4545
handleCurrentTab,
4646
loader,
47-
inboxIssueIds,
47+
filteredInboxIssueIds,
4848
inboxIssuePaginationInfo,
4949
fetchInboxPaginationIssues,
5050
getAppliedFiltersCount,
@@ -106,13 +106,13 @@ export const InboxSidebar: FC<IInboxSidebarProps> = observer((props) => {
106106
className="w-full h-full overflow-hidden overflow-y-auto vertical-scrollbar scrollbar-md"
107107
ref={containerRef}
108108
>
109-
{inboxIssueIds.length > 0 ? (
109+
{filteredInboxIssueIds.length > 0 ? (
110110
<InboxIssueList
111111
setIsMobileSidebar={setIsMobileSidebar}
112112
workspaceSlug={workspaceSlug}
113113
projectId={projectId}
114114
projectIdentifier={currentProjectDetails?.identifier}
115-
inboxIssueIds={inboxIssueIds}
115+
inboxIssueIds={filteredInboxIssueIds}
116116
/>
117117
) : (
118118
<div className="flex items-center justify-center h-full w-full">

web/store/inbox/project-inbox.store.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { uniq, update } from "lodash";
22
import isEmpty from "lodash/isEmpty";
33
import omit from "lodash/omit";
4-
import orderBy from "lodash/orderBy";
54
import set from "lodash/set";
65
import { action, computed, makeObservable, observable, runInAction } from "mobx";
76
import { computedFn } from "mobx-utils";
@@ -42,11 +41,11 @@ export interface IProjectInboxStore {
4241
inboxIssueIds: string[];
4342
// computed
4443
getAppliedFiltersCount: number;
44+
filteredInboxIssueIds: string[];
4545
// computed functions
4646
getIssueInboxByIssueId: (issueId: string) => IInboxIssueStore;
4747
getIsIssueAvailable: (inboxIssueId: string) => boolean;
4848
// helper actions
49-
inboxIssueSorting: (issues: IInboxIssueStore[]) => IInboxIssueStore[];
5049
inboxIssueQueryParams: (
5150
inboxFilters: Partial<TInboxIssueFilter>,
5251
inboxSorting: Partial<TInboxIssueSorting>,
@@ -103,6 +102,7 @@ export class ProjectInboxStore implements IProjectInboxStore {
103102
inboxIssueIds: observable,
104103
// computed
105104
getAppliedFiltersCount: computed,
105+
filteredInboxIssueIds: computed,
106106
// actions
107107
handleInboxIssueFilters: action,
108108
handleInboxIssueSorting: action,
@@ -127,35 +127,23 @@ export class ProjectInboxStore implements IProjectInboxStore {
127127
return count;
128128
}
129129

130+
get filteredInboxIssueIds() {
131+
let appliedFilters =
132+
this.currentTab === EInboxIssueCurrentTab.OPEN
133+
? [EInboxIssueStatus.PENDING, EInboxIssueStatus.SNOOZED]
134+
: [EInboxIssueStatus.ACCEPTED, EInboxIssueStatus.DECLINED, EInboxIssueStatus.DUPLICATE];
135+
appliedFilters = appliedFilters.filter((filter) => this.inboxFilters?.status?.includes(filter));
136+
137+
return this.inboxIssueIds.filter((id) => appliedFilters.includes(this.inboxIssues[id].status));
138+
}
139+
130140
getIssueInboxByIssueId = computedFn((issueId: string) => this.inboxIssues?.[issueId]);
131141

132142
getIsIssueAvailable = computedFn((inboxIssueId: string) => {
133143
if (!this.inboxIssueIds) return true;
134144
return this.inboxIssueIds.includes(inboxIssueId);
135145
});
136146

137-
// helpers
138-
inboxIssueSorting = (issues: IInboxIssueStore[]) => {
139-
let inboxIssues: IInboxIssueStore[] = issues;
140-
inboxIssues = orderBy(inboxIssues, "issue.sequence_id", "desc");
141-
if (this.inboxSorting?.order_by && this.inboxSorting?.sort_by) {
142-
switch (this.inboxSorting.order_by) {
143-
case "issue__created_at":
144-
if (this.inboxSorting.sort_by === "desc") inboxIssues = orderBy(inboxIssues, "issue.created_at", "desc");
145-
else inboxIssues = orderBy(inboxIssues, "issue.created_at", "asc");
146-
case "issue__updated_at":
147-
if (this.inboxSorting.sort_by === "desc") inboxIssues = orderBy(inboxIssues, "issue.updated_at", "desc");
148-
else inboxIssues = orderBy(inboxIssues, "issue.updated_at", "asc");
149-
case "issue__sequence_id":
150-
if (this.inboxSorting.sort_by === "desc") inboxIssues = orderBy(inboxIssues, "issue.sequence_id", "desc");
151-
else inboxIssues = orderBy(inboxIssues, "issue.sequence_id", "asc");
152-
default:
153-
inboxIssues = inboxIssues;
154-
}
155-
}
156-
return inboxIssues;
157-
};
158-
159147
inboxIssueQueryParams = (
160148
inboxFilters: Partial<TInboxIssueFilter>,
161149
inboxSorting: Partial<TInboxIssueSorting>,

0 commit comments

Comments
 (0)