[WEB-1747] fix: switching between intake sorting and filters are persisting same in all the project intakes (#5196)

* fix: switching between intake sorting and filters are persisting same in all the project intakes

* chore: typos and commented the methods in intake store
This commit is contained in:
guru_sainath 2024-07-23 16:18:19 +05:30 committed by GitHub
parent 8a05cd442c
commit 2978593c63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -34,12 +34,14 @@ export interface IProjectInboxStore {
loader: TLoader; loader: TLoader;
error: { message: string; status: "init-error" | "pagination-error" } | undefined; error: { message: string; status: "init-error" | "pagination-error" } | undefined;
currentInboxProjectId: string; currentInboxProjectId: string;
inboxFilters: Partial<TInboxIssueFilter>; filtersMap: Record<string, Partial<TInboxIssueFilter>>; // projectId -> Partial<TInboxIssueFilter>
inboxSorting: Partial<TInboxIssueSorting>; sortingMap: Record<string, Partial<TInboxIssueSorting>>; // projectId -> Partial<TInboxIssueSorting>
inboxIssuePaginationInfo: TInboxIssuePaginationInfo | undefined; inboxIssuePaginationInfo: TInboxIssuePaginationInfo | undefined;
inboxIssues: Record<string, IInboxIssueStore>; // issue_id -> IInboxIssueStore inboxIssues: Record<string, IInboxIssueStore>; // issue_id -> IInboxIssueStore
inboxIssueIds: string[]; inboxIssueIds: string[];
// computed // computed
inboxFilters: Partial<TInboxIssueFilter>; // computed project inbox filters
inboxSorting: Partial<TInboxIssueSorting>; // computed project inbox sorting
getAppliedFiltersCount: number; getAppliedFiltersCount: number;
filteredInboxIssueIds: string[]; filteredInboxIssueIds: string[];
// computed functions // computed functions
@ -76,13 +78,8 @@ export class ProjectInboxStore implements IProjectInboxStore {
loader: TLoader = "init-loading"; loader: TLoader = "init-loading";
error: { message: string; status: "init-error" | "pagination-error" } | undefined = undefined; error: { message: string; status: "init-error" | "pagination-error" } | undefined = undefined;
currentInboxProjectId: string = ""; currentInboxProjectId: string = "";
inboxFilters: Partial<TInboxIssueFilter> = { filtersMap: Record<string, Partial<TInboxIssueFilter>> = {};
status: [EInboxIssueStatus.PENDING], sortingMap: Record<string, Partial<TInboxIssueSorting>> = {};
};
inboxSorting: Partial<TInboxIssueSorting> = {
order_by: "issue__created_at",
sort_by: "desc",
};
inboxIssuePaginationInfo: TInboxIssuePaginationInfo | undefined = undefined; inboxIssuePaginationInfo: TInboxIssuePaginationInfo | undefined = undefined;
inboxIssues: Record<string, IInboxIssueStore> = {}; inboxIssues: Record<string, IInboxIssueStore> = {};
inboxIssueIds: string[] = []; inboxIssueIds: string[] = [];
@ -95,12 +92,14 @@ export class ProjectInboxStore implements IProjectInboxStore {
loader: observable.ref, loader: observable.ref,
error: observable, error: observable,
currentInboxProjectId: observable.ref, currentInboxProjectId: observable.ref,
inboxFilters: observable, filtersMap: observable,
inboxSorting: observable, sortingMap: observable,
inboxIssuePaginationInfo: observable, inboxIssuePaginationInfo: observable,
inboxIssues: observable, inboxIssues: observable,
inboxIssueIds: observable, inboxIssueIds: observable,
// computed // computed
inboxFilters: computed,
inboxSorting: computed,
getAppliedFiltersCount: computed, getAppliedFiltersCount: computed,
filteredInboxIssueIds: computed, filteredInboxIssueIds: computed,
// actions // actions
@ -116,6 +115,30 @@ export class ProjectInboxStore implements IProjectInboxStore {
} }
// computed // computed
/**
* @description computed project inbox filters
*/
get inboxFilters() {
const { projectId } = this.store.router;
if (!projectId) return {} as TInboxIssueFilter;
return isEmpty(this.filtersMap?.[projectId])
? this.currentTab === EInboxIssueCurrentTab.OPEN
? { status: [EInboxIssueStatus.PENDING] }
: { status: [EInboxIssueStatus.ACCEPTED, EInboxIssueStatus.DECLINED, EInboxIssueStatus.DUPLICATE] }
: this.filtersMap?.[projectId];
}
/**
* @description computed project inbox sorting
*/
get inboxSorting() {
const { projectId } = this.store.router;
if (!projectId) return {} as TInboxIssueSorting;
return isEmpty(this.sortingMap?.[projectId])
? ({ order_by: "issue__created_at", sort_by: "desc" } as TInboxIssueSorting)
: this.sortingMap?.[projectId];
}
get getAppliedFiltersCount() { get getAppliedFiltersCount() {
let count = 0; let count = 0;
this.inboxFilters != undefined && this.inboxFilters != undefined &&
@ -219,33 +242,37 @@ export class ProjectInboxStore implements IProjectInboxStore {
handleCurrentTab = (workspaceSlug: string, projectId: string, tab: TInboxIssueCurrentTab) => { handleCurrentTab = (workspaceSlug: string, projectId: string, tab: TInboxIssueCurrentTab) => {
runInAction(() => { runInAction(() => {
set(this, "currentTab", tab); set(this, "currentTab", tab);
set(this, "inboxFilters", undefined);
set(this, ["inboxSorting", "order_by"], "issue__created_at");
set(this, ["inboxSorting", "sort_by"], "desc");
set(this, ["inboxIssueIds"], []); set(this, ["inboxIssueIds"], []);
set(this, ["inboxIssuePaginationInfo"], undefined); set(this, ["inboxIssuePaginationInfo"], undefined);
if (tab === "closed") set(this, ["inboxFilters", "status"], [-1, 1, 2]); set(this, ["sorting", projectId, "order_by"], "issue__created_at");
else set(this, ["inboxFilters", "status"], [-2]); set(this, ["sorting", projectId, "sort_by"], "desc");
set(this, "filters", undefined);
if (tab === "closed") set(this, ["filters", projectId, "status"], [-1, 1, 2]);
else set(this, ["filters", projectId, "status"], [-2]);
}); });
if (workspaceSlug && projectId) this.fetchInboxIssues(workspaceSlug, projectId, "filter-loading"); if (workspaceSlug && projectId) this.fetchInboxIssues(workspaceSlug, projectId, "filter-loading");
}; };
handleInboxIssueFilters = <T extends keyof TInboxIssueFilter>(key: T, value: TInboxIssueFilter[T]) => { handleInboxIssueFilters = <T extends keyof TInboxIssueFilter>(key: T, value: TInboxIssueFilter[T]) => {
const { workspaceSlug, projectId } = this.store.router;
if (workspaceSlug && projectId) {
runInAction(() => { runInAction(() => {
set(this.inboxFilters, key, value); set(this.filtersMap, [projectId, key], value);
set(this, ["inboxIssuePaginationInfo"], undefined); set(this, ["inboxIssuePaginationInfo"], undefined);
}); });
const { workspaceSlug, projectId } = this.store.router; this.fetchInboxIssues(workspaceSlug, projectId, "filter-loading");
if (workspaceSlug && projectId) this.fetchInboxIssues(workspaceSlug, projectId, "filter-loading"); }
}; };
handleInboxIssueSorting = <T extends keyof TInboxIssueSorting>(key: T, value: TInboxIssueSorting[T]) => { handleInboxIssueSorting = <T extends keyof TInboxIssueSorting>(key: T, value: TInboxIssueSorting[T]) => {
const { workspaceSlug, projectId } = this.store.router;
if (workspaceSlug && projectId) {
runInAction(() => { runInAction(() => {
set(this.inboxSorting, key, value); set(this.sortingMap, [projectId, key], value);
set(this, ["inboxIssuePaginationInfo"], undefined); set(this, ["inboxIssuePaginationInfo"], undefined);
}); });
const { workspaceSlug, projectId } = this.store.router; this.fetchInboxIssues(workspaceSlug, projectId, "filter-loading");
if (workspaceSlug && projectId) this.fetchInboxIssues(workspaceSlug, projectId, "filter-loading"); }
}; };
/** /**