From 53df658b608849efdb1144679f2537f7947015dd Mon Sep 17 00:00:00 2001 From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Date: Tue, 21 Mar 2023 12:47:47 +0530 Subject: [PATCH] refactor: added params to filters, and removed manual mutation (#480) * refractor: added params to fetch key * feat: create views directly from views list page fix: selected filter not showing up in multi-level dropdown, refactor: arranged imports * refactor: added params to filters, and removed manual mutation --- apps/app/constants/fetch-keys.ts | 17 +++++++----- apps/app/contexts/issue-view.context.tsx | 33 ------------------------ 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/apps/app/constants/fetch-keys.ts b/apps/app/constants/fetch-keys.ts index 8592a22c0..c01052afe 100644 --- a/apps/app/constants/fetch-keys.ts +++ b/apps/app/constants/fetch-keys.ts @@ -1,16 +1,19 @@ const paramsToKey = (params: any) => { const { state, priority, assignees } = params; - let stateKey = state ? state.split(",").join(" ") : ""; - let priorityKey = priority ? priority.split(",").join(" ") : ""; - let assigneesKey = assignees ? assignees.split(",").join(" ") : ""; + let stateKey = state ? state.split(",") : []; + let priorityKey = priority ? priority.split(",") : []; + let assigneesKey = assignees ? assignees.split(",") : []; + const type = params.type ? params.type.toUpperCase() : "NULL"; + const groupBy = params.group_by ? params.group_by.toUpperCase() : "NULL"; + const orderBy = params.order_by ? params.order_by.toUpperCase() : "NULL"; // sorting each keys in ascending order - stateKey = stateKey.split(" ").sort().join(""); - priorityKey = priorityKey.split(" ").sort().join(""); - assigneesKey = assigneesKey.split(" ").sort().join(""); + stateKey = stateKey.sort().join("_"); + priorityKey = priorityKey.sort().join("_"); + assigneesKey = assigneesKey.sort().join("_"); - return `${stateKey}_${priorityKey}_${assigneesKey}`; + return `${stateKey}_${priorityKey}_${assigneesKey}_${type}_${groupBy}_${orderBy}`; }; export const CURRENT_USER = "CURRENT_USER"; diff --git a/apps/app/contexts/issue-view.context.tsx b/apps/app/contexts/issue-view.context.tsx index 2713b3245..1a897bc22 100644 --- a/apps/app/contexts/issue-view.context.tsx +++ b/apps/app/contexts/issue-view.context.tsx @@ -424,39 +424,6 @@ export const IssueViewContextProvider: React.FC<{ children: React.ReactNode }> = }); }, [myViewProps, viewDetails]); - useEffect(() => { - const params: any = { - order_by: state.orderBy, - group_by: state.groupByProperty, - assignees: state.filters?.assignees ? state.filters?.assignees.join(",") : undefined, - state: state.filters?.state ? state.filters?.state.join(",") : undefined, - priority: state.filters?.priority ? state.filters?.priority.join(",") : undefined, - type: state.filters?.type ? state.filters?.type : undefined, - labels: state.filters?.labels ? state.filters?.labels.join(",") : undefined, - issue__assignees__id: state.filters?.issue__assignees__id - ? state.filters?.issue__assignees__id.join(",") - : undefined, - issue__labels__id: state.filters?.issue__labels__id - ? state.filters?.issue__labels__id.join(",") - : undefined, - }; - - // TODO: think of a better way to do this - if (cycleId) { - mutate(CYCLE_ISSUES_WITH_PARAMS(cycleId as string, params), {}, false); - mutate(CYCLE_ISSUES_WITH_PARAMS(cycleId as string, params)); - } else if (moduleId) { - mutate(MODULE_ISSUES_WITH_PARAMS(moduleId as string, params), {}, false); - mutate(MODULE_ISSUES_WITH_PARAMS(moduleId as string, params)); - } else if (viewId) { - mutate(VIEW_ISSUES(viewId as string), {}, false); - mutate(VIEW_ISSUES(viewId as string)); - } else { - mutate(PROJECT_ISSUES_LIST_WITH_PARAMS(projectId as string, params), {}, false); - mutate(PROJECT_ISSUES_LIST_WITH_PARAMS(projectId as string, params)); - } - }, [state, projectId, cycleId, moduleId, viewId]); - return (