From 864519e770cfcbce0bd032f24b5ec469b9493aa5 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Thu, 18 Jan 2024 17:26:13 +0530 Subject: [PATCH] chore: issue filter loader improvement (#3406) --- web/store/issue/archived/filter.store.ts | 11 +++++++++-- web/store/issue/cycle/filter.store.ts | 11 ++++++++++- web/store/issue/draft/filter.store.ts | 11 +++++++++-- web/store/issue/module/filter.store.ts | 12 ++++++++++-- web/store/issue/profile/filter.store.ts | 7 ++++++- web/store/issue/project-views/filter.store.ts | 11 ++++++++++- web/store/issue/project/filter.store.ts | 10 +++++++++- web/store/issue/workspace/filter.store.ts | 10 +++++++++- 8 files changed, 72 insertions(+), 11 deletions(-) diff --git a/web/store/issue/archived/filter.store.ts b/web/store/issue/archived/filter.store.ts index 7192cc012..fe4d68642 100644 --- a/web/store/issue/archived/filter.store.ts +++ b/web/store/issue/archived/filter.store.ts @@ -1,6 +1,8 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"; import isEmpty from "lodash/isEmpty"; import set from "lodash/set"; +import pickBy from "lodash/pickBy"; +import isArray from "lodash/isArray"; // base class import { IssueFilterHelperStore } from "../helpers/issue-filter-helper.store"; // helpers @@ -148,8 +150,13 @@ export class ArchivedIssuesFilter extends IssueFilterHelperStore implements IArc set(this.filters, [projectId, "filters", _key], updatedFilters[_key as keyof IIssueFilterOptions]); }); }); - - this.rootIssueStore.archivedIssues.fetchIssues(workspaceSlug, projectId, "mutation"); + const appliedFilters = _filters.filters || {}; + const filteredFilters = pickBy(appliedFilters, (value) => value && isArray(value) && value.length > 0); + this.rootIssueStore.archivedIssues.fetchIssues( + workspaceSlug, + projectId, + isEmpty(filteredFilters) ? "init-loader" : "mutation" + ); this.handleIssuesLocalFilters.set(EIssuesStoreType.ARCHIVED, type, workspaceSlug, projectId, undefined, { filters: _filters.filters, }); diff --git a/web/store/issue/cycle/filter.store.ts b/web/store/issue/cycle/filter.store.ts index 4c640977a..e6ea3dde1 100644 --- a/web/store/issue/cycle/filter.store.ts +++ b/web/store/issue/cycle/filter.store.ts @@ -1,6 +1,8 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"; import isEmpty from "lodash/isEmpty"; import set from "lodash/set"; +import pickBy from "lodash/pickBy"; +import isArray from "lodash/isArray"; // base class import { IssueFilterHelperStore } from "../helpers/issue-filter-helper.store"; // helpers @@ -158,7 +160,14 @@ export class CycleIssuesFilter extends IssueFilterHelperStore implements ICycleI }); }); - this.rootIssueStore.cycleIssues.fetchIssues(workspaceSlug, projectId, "mutation", cycleId); + const appliedFilters = _filters.filters || {}; + const filteredFilters = pickBy(appliedFilters, (value) => value && isArray(value) && value.length > 0); + this.rootIssueStore.cycleIssues.fetchIssues( + workspaceSlug, + projectId, + isEmpty(filteredFilters) ? "init-loader" : "mutation", + cycleId + ); await this.issueFilterService.patchCycleIssueFilters(workspaceSlug, projectId, cycleId, { filters: _filters.filters, }); diff --git a/web/store/issue/draft/filter.store.ts b/web/store/issue/draft/filter.store.ts index a303ee90e..658a2dd24 100644 --- a/web/store/issue/draft/filter.store.ts +++ b/web/store/issue/draft/filter.store.ts @@ -1,6 +1,8 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"; import isEmpty from "lodash/isEmpty"; import set from "lodash/set"; +import pickBy from "lodash/pickBy"; +import isArray from "lodash/isArray"; // base class import { IssueFilterHelperStore } from "../helpers/issue-filter-helper.store"; // helpers @@ -143,8 +145,13 @@ export class DraftIssuesFilter extends IssueFilterHelperStore implements IDraftI set(this.filters, [projectId, "filters", _key], updatedFilters[_key as keyof IIssueFilterOptions]); }); }); - - this.rootIssueStore.draftIssues.fetchIssues(workspaceSlug, projectId, "mutation"); + const appliedFilters = _filters.filters || {}; + const filteredFilters = pickBy(appliedFilters, (value) => value && isArray(value) && value.length > 0); + this.rootIssueStore.draftIssues.fetchIssues( + workspaceSlug, + projectId, + isEmpty(filteredFilters) ? "init-loader" : "mutation" + ); this.handleIssuesLocalFilters.set(EIssuesStoreType.DRAFT, type, workspaceSlug, projectId, undefined, { filters: _filters.filters, }); diff --git a/web/store/issue/module/filter.store.ts b/web/store/issue/module/filter.store.ts index d7d4d56da..1e00dc8c0 100644 --- a/web/store/issue/module/filter.store.ts +++ b/web/store/issue/module/filter.store.ts @@ -1,6 +1,8 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"; import isEmpty from "lodash/isEmpty"; import set from "lodash/set"; +import pickBy from "lodash/pickBy"; +import isArray from "lodash/isArray"; // base class import { IssueFilterHelperStore } from "../helpers/issue-filter-helper.store"; // helpers @@ -157,8 +159,14 @@ export class ModuleIssuesFilter extends IssueFilterHelperStore implements IModul set(this.filters, [moduleId, "filters", _key], updatedFilters[_key as keyof IIssueFilterOptions]); }); }); - - this.rootIssueStore.moduleIssues.fetchIssues(workspaceSlug, projectId, "mutation", moduleId); + const appliedFilters = _filters.filters || {}; + const filteredFilters = pickBy(appliedFilters, (value) => value && isArray(value) && value.length > 0); + this.rootIssueStore.moduleIssues.fetchIssues( + workspaceSlug, + projectId, + isEmpty(filteredFilters) ? "init-loader" : "mutation", + moduleId + ); await this.issueFilterService.patchModuleIssueFilters(workspaceSlug, projectId, moduleId, { filters: _filters.filters, }); diff --git a/web/store/issue/profile/filter.store.ts b/web/store/issue/profile/filter.store.ts index fe30a1c58..e7d33c48b 100644 --- a/web/store/issue/profile/filter.store.ts +++ b/web/store/issue/profile/filter.store.ts @@ -1,6 +1,8 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"; import isEmpty from "lodash/isEmpty"; import set from "lodash/set"; +import pickBy from "lodash/pickBy"; +import isArray from "lodash/isArray"; // base class import { IssueFilterHelperStore } from "../helpers/issue-filter-helper.store"; // helpers @@ -150,13 +152,16 @@ export class ProfileIssuesFilter extends IssueFilterHelperStore implements IProf }); }); + const appliedFilters = _filters.filters || {}; + const filteredFilters = pickBy(appliedFilters, (value) => value && isArray(value) && value.length > 0); this.rootIssueStore.profileIssues.fetchIssues( workspaceSlug, undefined, - "mutation", + isEmpty(filteredFilters) ? "init-loader" : "mutation", userId, this.rootIssueStore.profileIssues.currentView ); + this.handleIssuesLocalFilters.set(EIssuesStoreType.PROFILE, type, workspaceSlug, userId, undefined, { filters: _filters.filters, }); diff --git a/web/store/issue/project-views/filter.store.ts b/web/store/issue/project-views/filter.store.ts index 610d92998..828eca29a 100644 --- a/web/store/issue/project-views/filter.store.ts +++ b/web/store/issue/project-views/filter.store.ts @@ -1,6 +1,8 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"; import isEmpty from "lodash/isEmpty"; import set from "lodash/set"; +import pickBy from "lodash/pickBy"; +import isArray from "lodash/isArray"; // base class import { IssueFilterHelperStore } from "../helpers/issue-filter-helper.store"; // helpers @@ -159,7 +161,14 @@ export class ProjectViewIssuesFilter extends IssueFilterHelperStore implements I }); }); - this.rootIssueStore.projectViewIssues.fetchIssues(workspaceSlug, projectId, "mutation", viewId); + const appliedFilters = _filters.filters || {}; + const filteredFilters = pickBy(appliedFilters, (value) => value && isArray(value) && value.length > 0); + this.rootIssueStore.projectViewIssues.fetchIssues( + workspaceSlug, + projectId, + isEmpty(filteredFilters) ? "init-loader" : "mutation", + viewId + ); break; case EIssueFilterType.DISPLAY_FILTERS: const updatedDisplayFilters = filters as IIssueDisplayFilterOptions; diff --git a/web/store/issue/project/filter.store.ts b/web/store/issue/project/filter.store.ts index 83a95aa6d..aaa8d81d9 100644 --- a/web/store/issue/project/filter.store.ts +++ b/web/store/issue/project/filter.store.ts @@ -1,6 +1,8 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"; import isEmpty from "lodash/isEmpty"; import set from "lodash/set"; +import pickBy from "lodash/pickBy"; +import isArray from "lodash/isArray"; // base class import { IssueFilterHelperStore } from "../helpers/issue-filter-helper.store"; // helpers @@ -155,7 +157,13 @@ export class ProjectIssuesFilter extends IssueFilterHelperStore implements IProj }); }); - this.rootIssueStore.projectIssues.fetchIssues(workspaceSlug, projectId, "mutation"); + const appliedFilters = _filters.filters || {}; + const filteredFilters = pickBy(appliedFilters, (value) => value && isArray(value) && value.length > 0); + this.rootIssueStore.projectIssues.fetchIssues( + workspaceSlug, + projectId, + isEmpty(filteredFilters) ? "init-loader" : "mutation" + ); await this.issueFilterService.patchProjectIssueFilters(workspaceSlug, projectId, { filters: _filters.filters, }); diff --git a/web/store/issue/workspace/filter.store.ts b/web/store/issue/workspace/filter.store.ts index dcacb117e..95a9a8831 100644 --- a/web/store/issue/workspace/filter.store.ts +++ b/web/store/issue/workspace/filter.store.ts @@ -1,6 +1,8 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"; import isEmpty from "lodash/isEmpty"; import set from "lodash/set"; +import pickBy from "lodash/pickBy"; +import isArray from "lodash/isArray"; // base class import { IssueFilterHelperStore } from "../helpers/issue-filter-helper.store"; // helpers @@ -180,7 +182,13 @@ export class WorkspaceIssuesFilter extends IssueFilterHelperStore implements IWo set(this.filters, [viewId, "filters", _key], updatedFilters[_key as keyof IIssueFilterOptions]); }); }); - this.rootIssueStore.workspaceIssues.fetchIssues(workspaceSlug, viewId, "mutation"); + const appliedFilters = _filters.filters || {}; + const filteredFilters = pickBy(appliedFilters, (value) => value && isArray(value) && value.length > 0); + this.rootIssueStore.workspaceIssues.fetchIssues( + workspaceSlug, + viewId, + isEmpty(filteredFilters) ? "init-loader" : "mutation" + ); break; case EIssueFilterType.DISPLAY_FILTERS: const updatedDisplayFilters = filters as IIssueDisplayFilterOptions;