diff --git a/web/components/issue-layouts/display-filters/display-properties.tsx b/web/components/issue-layouts/display-filters/display-properties.tsx index 40be9345b..dd234340a 100644 --- a/web/components/issue-layouts/display-filters/display-properties.tsx +++ b/web/components/issue-layouts/display-filters/display-properties.tsx @@ -13,6 +13,10 @@ export const FilterDisplayProperties = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleDisplayProperties = (key: string, value: boolean) => { + issueFilterStore.handleUserFilter("display_properties", key, !value); + }; + return (
{ ? `bg-custom-primary-200 border-custom-primary-200 text-white` : `hover:bg-custom-border-100 border-custom-border-100` }`} + onClick={() => + handleDisplayProperties( + _displayProperties?.key, + issueFilterStore?.userFilters?.display_properties?.[_displayProperties?.key] + ) + } > {_displayProperties?.title}
diff --git a/web/components/issue-layouts/display-filters/extra-options.tsx b/web/components/issue-layouts/display-filters/extra-options.tsx index 3e74e91d3..15450a24f 100644 --- a/web/components/issue-layouts/display-filters/extra-options.tsx +++ b/web/components/issue-layouts/display-filters/extra-options.tsx @@ -14,6 +14,10 @@ export const FilterExtraOptions = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleExtraOptions = (key: string, value: boolean) => { + issueFilterStore.handleUserFilter("display_filters", key, !value); + }; + return (
{ ? true : false } + onClick={() => + handleExtraOptions( + _extraProperties?.key, + issueFilterStore?.userFilters?.display_filters?.[_extraProperties?.key] + ) + } title={_extraProperties.title} /> ))} diff --git a/web/components/issue-layouts/display-filters/group-by.tsx b/web/components/issue-layouts/display-filters/group-by.tsx index 43ee083e0..fa46415ab 100644 --- a/web/components/issue-layouts/display-filters/group-by.tsx +++ b/web/components/issue-layouts/display-filters/group-by.tsx @@ -14,6 +14,10 @@ export const FilterGroupBy = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleGroupBy = (key: string, value: string) => { + issueFilterStore.handleUserFilter("display_filters", key, value); + }; + return (
{ ? true : false } + onClick={() => handleGroupBy("group_by", _groupBy?.key)} title={_groupBy.title} multiple={false} /> diff --git a/web/components/issue-layouts/display-filters/issue-type.tsx b/web/components/issue-layouts/display-filters/issue-type.tsx index 7171162c7..eaf9ae7bd 100644 --- a/web/components/issue-layouts/display-filters/issue-type.tsx +++ b/web/components/issue-layouts/display-filters/issue-type.tsx @@ -14,6 +14,10 @@ export const FilterIssueType = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleIssueType = (key: string, value: string) => { + issueFilterStore.handleUserFilter("display_filters", key, value); + }; + return (
{ ? true : false } + onClick={() => handleIssueType("type", _issueType?.key)} title={_issueType.title} multiple={false} /> diff --git a/web/components/issue-layouts/display-filters/order-by.tsx b/web/components/issue-layouts/display-filters/order-by.tsx index 7ada18cab..9e3b9e35d 100644 --- a/web/components/issue-layouts/display-filters/order-by.tsx +++ b/web/components/issue-layouts/display-filters/order-by.tsx @@ -14,6 +14,10 @@ export const FilterOrderBy = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleOrderBy = (key: string, value: string) => { + issueFilterStore.handleUserFilter("display_filters", key, value); + }; + return (
{ ? true : false } + onClick={() => handleOrderBy("order_by", _orderBy?.key)} title={_orderBy.title} multiple={false} /> diff --git a/web/components/issue-layouts/filters/assignees.tsx b/web/components/issue-layouts/filters/assignees.tsx index e8e222aa8..2e51a3a49 100644 --- a/web/components/issue-layouts/filters/assignees.tsx +++ b/web/components/issue-layouts/filters/assignees.tsx @@ -34,10 +34,20 @@ export const FilterAssignees = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleFilter = (key: string, value: string) => { + const _value = + issueFilterStore?.userFilters?.filters?.[key] != null + ? issueFilterStore?.userFilters?.filters?.[key].includes(value) + ? issueFilterStore?.userFilters?.filters?.[key].filter((p: string) => p != value) + : [...issueFilterStore?.userFilters?.filters?.[key], value] + : [value]; + issueFilterStore.handleUserFilter("filters", key, _value); + }; + return (
setPreviewEnabled(!previewEnabled)} /> @@ -54,6 +64,7 @@ export const FilterAssignees = observer(() => { ? true : false } + onClick={() => handleFilter("assignees", _member?.member?.id)} icon={ { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleFilter = (key: string, value: string) => { + const _value = + issueFilterStore?.userFilters?.filters?.[key] != null + ? issueFilterStore?.userFilters?.filters?.[key].includes(value) + ? issueFilterStore?.userFilters?.filters?.[key].filter((p: string) => p != value) + : [...issueFilterStore?.userFilters?.filters?.[key], value] + : [value]; + issueFilterStore.handleUserFilter("filters", key, _value); + }; + return (
setPreviewEnabled(!previewEnabled)} /> @@ -37,6 +47,7 @@ export const FilterCreatedBy = observer(() => { ? true : false } + onClick={() => handleFilter("created_by", _member?.member?.id)} icon={ { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleFilter = (key: string, value: string) => { + const _value = + issueFilterStore?.userFilters?.filters?.[key] != null + ? issueFilterStore?.userFilters?.filters?.[key].includes(value) + ? issueFilterStore?.userFilters?.filters?.[key].filter((p: string) => p != value) + : [...issueFilterStore?.userFilters?.filters?.[key], value] + : [value]; + issueFilterStore.handleUserFilter("filters", key, _value); + }; + return (
setPreviewEnabled(!previewEnabled)} /> @@ -42,6 +52,7 @@ export const FilterLabels = observer(() => { ? true : false } + onClick={() => handleFilter("labels", _label?.id)} icon={} title={_label.name} /> diff --git a/web/components/issue-layouts/filters/priority.tsx b/web/components/issue-layouts/filters/priority.tsx index d2f48ab9b..f8b104c81 100644 --- a/web/components/issue-layouts/filters/priority.tsx +++ b/web/components/issue-layouts/filters/priority.tsx @@ -56,10 +56,20 @@ export const FilterPriority = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleFilter = (key: string, value: string) => { + const _value = + issueFilterStore?.userFilters?.filters?.[key] != null + ? issueFilterStore?.userFilters?.filters?.[key].includes(value) + ? issueFilterStore?.userFilters?.filters?.[key].filter((p: string) => p != value) + : [...issueFilterStore?.userFilters?.filters?.[key], value] + : [value]; + issueFilterStore.handleUserFilter("filters", key, _value); + }; + return (
setPreviewEnabled(!previewEnabled)} /> @@ -76,14 +86,15 @@ export const FilterPriority = observer(() => { ? true : false } + onClick={() => handleFilter("priority", _priority?.key)} icon={} title={_priority.title} /> ))}
-
View more
View less
-
View all
+
View more
+ {/* TODO:
View all
*/}
)} diff --git a/web/components/issue-layouts/filters/start-date.tsx b/web/components/issue-layouts/filters/start-date.tsx index 2f62785ab..bfa342922 100644 --- a/web/components/issue-layouts/filters/start-date.tsx +++ b/web/components/issue-layouts/filters/start-date.tsx @@ -16,10 +16,15 @@ export const FilterStartDate = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleFilter = (key: string, value: string) => { + const _value = [value]; + issueFilterStore.handleUserFilter("filters", key, _value); + }; + return (
setPreviewEnabled(!previewEnabled)} /> @@ -30,7 +35,13 @@ export const FilterStartDate = observer(() => { issueFilterStore?.issueRenderFilters?.start_date.map((_startDate) => ( handleFilter("start_date", _startDate?.key)} title={_startDate.title} multiple={false} /> diff --git a/web/components/issue-layouts/filters/state-group.tsx b/web/components/issue-layouts/filters/state-group.tsx index be739d459..0c3da34ec 100644 --- a/web/components/issue-layouts/filters/state-group.tsx +++ b/web/components/issue-layouts/filters/state-group.tsx @@ -89,10 +89,20 @@ export const FilterStateGroup = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleFilter = (key: string, value: string) => { + const _value = + issueFilterStore?.userFilters?.filters?.[key] != null + ? issueFilterStore?.userFilters?.filters?.[key].includes(value) + ? issueFilterStore?.userFilters?.filters?.[key].filter((p: string) => p != value) + : [...issueFilterStore?.userFilters?.filters?.[key], value] + : [value]; + issueFilterStore.handleUserFilter("filters", key, _value); + }; + return (
setPreviewEnabled(!previewEnabled)} /> @@ -109,6 +119,7 @@ export const FilterStateGroup = observer(() => { ? true : false } + onClick={() => handleFilter("state_group", _stateGroup?.key)} icon={} title={_stateGroup.title} /> diff --git a/web/components/issue-layouts/filters/state.tsx b/web/components/issue-layouts/filters/state.tsx index 340080a4c..6cabd68a1 100644 --- a/web/components/issue-layouts/filters/state.tsx +++ b/web/components/issue-layouts/filters/state.tsx @@ -19,10 +19,26 @@ export const FilterState = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleFilter = (key: string, value: string) => { + const _value = + issueFilterStore?.userFilters?.filters?.[key] != null + ? issueFilterStore?.userFilters?.filters?.[key].includes(value) + ? issueFilterStore?.userFilters?.filters?.[key].filter((p: string) => p != value) + : [...issueFilterStore?.userFilters?.filters?.[key], value] + : [value]; + issueFilterStore.handleUserFilter("filters", key, _value); + }; + + const countAllState = issueStateGroupKeys + .map((_stateGroup) => issueFilterStore?.projectStates?.[_stateGroup].length || 0) + .reduce((sum: number, currentValue: number) => sum + currentValue, 0); + + console.log("countAllState", countAllState); + return (
setPreviewEnabled(!previewEnabled)} /> @@ -42,6 +58,7 @@ export const FilterState = observer(() => { ? true : false } + onClick={() => handleFilter("state", _state?.id)} icon={} title={_state?.name} /> diff --git a/web/components/issue-layouts/filters/target-date.tsx b/web/components/issue-layouts/filters/target-date.tsx index f886b70c4..0f777f752 100644 --- a/web/components/issue-layouts/filters/target-date.tsx +++ b/web/components/issue-layouts/filters/target-date.tsx @@ -16,10 +16,15 @@ export const FilterTargetDate = observer(() => { const [previewEnabled, setPreviewEnabled] = React.useState(true); + const handleFilter = (key: string, value: string) => { + const _value = [value]; + issueFilterStore.handleUserFilter("filters", key, _value); + }; + return (
setPreviewEnabled(!previewEnabled)} /> @@ -30,7 +35,13 @@ export const FilterTargetDate = observer(() => { issueFilterStore?.issueRenderFilters?.due_date.map((_targetDate) => ( handleFilter("target_date", _targetDate?.key)} title={_targetDate.title} multiple={false} /> diff --git a/web/components/issue-layouts/helpers/filter-option.tsx b/web/components/issue-layouts/helpers/filter-option.tsx index 34ed036a0..e96b3c5c9 100644 --- a/web/components/issue-layouts/helpers/filter-option.tsx +++ b/web/components/issue-layouts/helpers/filter-option.tsx @@ -7,10 +7,20 @@ interface IFilterOption { icon?: React.ReactNode; title: string; multiple?: boolean; + onClick?: () => void; } -export const FilterOption = ({ isChecked, icon, title, multiple = true }: IFilterOption) => ( -
+export const FilterOption = ({ + isChecked, + icon, + title, + multiple = true, + onClick, +}: IFilterOption) => ( +
{ }, ]; - const handleLayoutSelection = (layout: TIssueLayouts) => { - if (!issueFilterStore.workspaceId) return; - if (issueFilterStore.issueView === "my_issues") { - issueStore.getMyIssuesAsync(issueFilterStore.workspaceId, issueFilterStore.issueView, layout); - return; - } - - if (!issueFilterStore.projectId) return; - if (issueFilterStore.issueView === "issues") { - issueStore.getProjectIssuesAsync( - issueFilterStore.workspaceId, - issueFilterStore.projectId, - issueFilterStore.issueView, - layout - ); - return; - } - if (issueFilterStore.issueView === "modules" && issueFilterStore.moduleId) { - issueStore.getIssuesForModulesAsync( - issueFilterStore.workspaceId, - issueFilterStore.projectId, - issueFilterStore.moduleId, - issueFilterStore.issueView, - layout - ); - return; - } - if (issueFilterStore.issueView === "cycles" && issueFilterStore.cycleId) { - issueStore.getIssuesForCyclesAsync( - issueFilterStore.workspaceId, - issueFilterStore.projectId, - issueFilterStore.cycleId, - issueFilterStore.issueView, - layout - ); - return; - } - if (issueFilterStore.issueView === "views" && issueFilterStore.viewId) { - issueStore.getIssuesForViewsAsync( - issueFilterStore.workspaceId, - issueFilterStore.projectId, - issueFilterStore.viewId, - issueFilterStore.issueView, - layout - ); - return; - } + const handleLayoutSelection = (_layoutKey: string) => { + issueFilterStore.handleUserFilter("display_filters", "layout", _layoutKey); }; + console.log("----"); + console.log("workspace_id", issueFilterStore.workspaceId); + console.log("project_id", issueFilterStore.projectId); + console.log("module_id", issueFilterStore.moduleId); + console.log("cycle_id", issueFilterStore.cycleId); + console.log("view_id", issueFilterStore.viewId); + + console.log("issue_view", issueFilterStore.issueView); + console.log("issue_layout", issueFilterStore.issueLayout); + + console.log("----"); + return (
{layoutSelectionFilters.map((_layout) => ( diff --git a/web/pages/kanban.tsx b/web/pages/kanban.tsx index 08c4fe667..1a7d5b073 100644 --- a/web/pages/kanban.tsx +++ b/web/pages/kanban.tsx @@ -1,6 +1,4 @@ import React from "react"; -// swr -import useSWR from "swr"; // components import { IssueKanBanViewRoot } from "components/issue-layouts/kanban"; import { LayoutSelection } from "components/issue-layouts/layout-selection"; @@ -18,140 +16,29 @@ const KanBanViewRoot = () => { const projectSlug: string = "08d59d96-9dfb-40e5-aa30-ecc66319450f"; const moduleSlug: string = "05613afc-29ea-4fd8-a025-a3cdfed209d1"; const cycleSlug: string = "1f66a767-00d1-422c-8f8f-6925282b7249"; - const viewSlug: string = "1f66a767-00d1-422c-8f8f-6925282b7249"; + const viewSlug: string = "64e6ecca-80ca-4f7c-8476-d650fca9d5b9"; const store: RootStore = useMobxStore(); const { issueFilters: issueFilterStore, issueView: issueViewStore } = store; React.useEffect(() => { const init = async () => { + console.log("started--->"); // my issues under a workspace - // console.log("started--->"); - // await issueViewStore.getMyIssuesAsync(workspaceSlug, "my_issues", "list"); - // await issueViewStore.getMyIssuesAsync(workspaceSlug, "my_issues", "kanban"); - // await issueViewStore.getMyIssuesAsync(workspaceSlug, "my_issues", "calendar"); - // await issueViewStore.getMyIssuesAsync(workspaceSlug, "my_issues", "spreadsheet"); - // await issueViewStore.getMyIssuesAsync(workspaceSlug, "my_issues", "gantt"); + // await issueViewStore.getMyIssuesAsync(workspaceSlug); + // project issues under and workspace and project - // await issueViewStore.getProjectIssuesAsync(workspaceSlug, projectSlug, "issues", "list"); - await issueViewStore.getProjectIssuesAsync(workspaceSlug, projectSlug, "issues", "kanban"); - // await issueViewStore.getProjectIssuesAsync(workspaceSlug, projectSlug, "issues", "calendar"); - // await issueViewStore.getProjectIssuesAsync( - // workspaceSlug, - // projectSlug, - // "issues", - // "spreadsheet" - // ); - // await issueViewStore.getProjectIssuesAsync(workspaceSlug, projectSlug, "issues", "gantt"); + await issueViewStore.getProjectIssuesAsync(workspaceSlug, projectSlug); + // module issues under and workspace and project - // await issueViewStore.getIssuesForModulesAsync( - // workspaceSlug, - // projectSlug, - // moduleSlug, - // "modules", - // "list" - // ); - // await issueViewStore.getIssuesForModulesAsync( - // workspaceSlug, - // projectSlug, - // moduleSlug, - // "modules", - // "kanban" - // ); - // await issueViewStore.getIssuesForModulesAsync( - // workspaceSlug, - // projectSlug, - // moduleSlug, - // "modules", - // "calendar" - // ); - // await issueViewStore.getIssuesForModulesAsync( - // workspaceSlug, - // projectSlug, - // moduleSlug, - // "modules", - // "spreadsheet" - // ); - // await issueViewStore.getIssuesForModulesAsync( - // workspaceSlug, - // projectSlug, - // moduleSlug, - // "modules", - // "gantt" - // ); + // await issueViewStore.getIssuesForModulesAsync(workspaceSlug, projectSlug, moduleSlug); + // cycle issues under and workspace and project - // await issueViewStore.getIssuesForCyclesAsync( - // workspaceSlug, - // projectSlug, - // cycleSlug, - // "cycles", - // "list" - // ); - // await issueViewStore.getIssuesForCyclesAsync( - // workspaceSlug, - // projectSlug, - // cycleSlug, - // "cycles", - // "kanban" - // ); - // await issueViewStore.getIssuesForCyclesAsync( - // workspaceSlug, - // projectSlug, - // cycleSlug, - // "cycles", - // "calendar" - // ); - // await issueViewStore.getIssuesForCyclesAsync( - // workspaceSlug, - // projectSlug, - // cycleSlug, - // "cycles", - // "spreadsheet" - // ); - // await issueViewStore.getIssuesForCyclesAsync( - // workspaceSlug, - // projectSlug, - // cycleSlug, - // "cycles", - // "gantt" - // ); + // await issueViewStore.getIssuesForCyclesAsync(workspaceSlug, projectSlug, cycleSlug); + // cycle issues under and workspace and project - // await issueViewStore.getIssuesForViewsAsync( - // workspaceSlug, - // projectSlug, - // viewSlug, - // "views", - // "list" - // ); - // await issueViewStore.getIssuesForViewsAsync( - // workspaceSlug, - // projectSlug, - // viewSlug, - // "views", - // "kanban" - // ); - // await issueViewStore.getIssuesForViewsAsync( - // workspaceSlug, - // projectSlug, - // viewSlug, - // "views", - // "calendar" - // ); - // await issueViewStore.getIssuesForViewsAsync( - // workspaceSlug, - // projectSlug, - // viewSlug, - // "views", - // "spreadsheet" - // ); - // await issueViewStore.getIssuesForViewsAsync( - // workspaceSlug, - // projectSlug, - // viewSlug, - // "views", - // "gantt" - // ); - // console.log("ended--->"); + // await issueViewStore.getIssuesForViewsAsync(workspaceSlug, projectSlug, viewSlug); + console.log("ended--->"); }; init(); @@ -160,10 +47,7 @@ const KanBanViewRoot = () => { return (
-
+
Filter Header
@@ -179,6 +63,7 @@ const KanBanViewRoot = () => {
+
Hello
diff --git a/web/services/views.service.ts b/web/services/views.service.ts index e1d25925e..861f035e2 100644 --- a/web/services/views.service.ts +++ b/web/services/views.service.ts @@ -11,7 +11,7 @@ const { NEXT_PUBLIC_API_BASE_URL } = process.env; const trackEvent = process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1"; -class ViewServices extends APIService { +export class ViewServices extends APIService { constructor() { super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000"); } diff --git a/web/store/issue-views/Issues.ts b/web/store/issue-views/Issues.ts index e5cb82422..74803dc8a 100644 --- a/web/store/issue-views/Issues.ts +++ b/web/store/issue-views/Issues.ts @@ -48,37 +48,22 @@ export interface IIssueViewStore { // computed getIssues: IIssues | null | undefined; // actions - getMyIssuesAsync: ( - workspaceId: string, - _view: TIssueViews, - _layout: TIssueLayouts - ) => null | Promise; - getProjectIssuesAsync: ( - workspaceId: string, - projectId: string, - _view: TIssueViews, - _layout: TIssueLayouts - ) => null | Promise; + getMyIssuesAsync: (workspaceId: string) => null | Promise; + getProjectIssuesAsync: (workspaceId: string, projectId: string) => null | Promise; getIssuesForModulesAsync: ( workspaceId: string, projectId: string, - moduleId: string, - _view: TIssueViews, - _layout: TIssueLayouts + moduleId: string ) => null | Promise; getIssuesForCyclesAsync: ( workspaceId: string, projectId: string, - cycleId: string, - _view: TIssueViews, - _layout: TIssueLayouts + cycleId: string ) => null | Promise; getIssuesForViewsAsync: ( workspaceId: string, projectId: string, - viewId: string, - _view: TIssueViews, - _layout: TIssueLayouts + viewId: string ) => null | Promise; } @@ -159,7 +144,7 @@ class IssueViewStore implements IIssueViewStore { } // fetching my issues - getMyIssuesAsync = async (workspaceId: string, _view: TIssueViews, _layout: TIssueLayouts) => { + getMyIssuesAsync = async (workspaceId: string) => { try { this.loader = true; this.error = null; @@ -171,8 +156,7 @@ class IssueViewStore implements IIssueViewStore { null, null, null, - _view, - _layout + "my_issues" ); const issuesResponse = await this.userService.userIssues(workspaceId, filteredParams); @@ -183,7 +167,8 @@ class IssueViewStore implements IIssueViewStore { ...this?.issues[workspaceId], my_issues: { ...this?.issues[workspaceId]?.my_issues, - [_layout as string]: issuesResponse, + [this.rootStore?.issueFilters?.userFilters?.display_filters?.layout as string]: + issuesResponse, }, }, }; @@ -205,12 +190,7 @@ class IssueViewStore implements IIssueViewStore { }; // fetching project issues - getProjectIssuesAsync = async ( - workspaceId: string, - projectId: string, - _view: TIssueViews, - _layout: TIssueLayouts - ) => { + getProjectIssuesAsync = async (workspaceId: string, projectId: string) => { try { this.loader = true; this.error = null; @@ -222,8 +202,7 @@ class IssueViewStore implements IIssueViewStore { null, null, null, - _view, - _layout + "issues" ); const issuesResponse = await this.issueService.getIssuesWithParams( workspaceId, @@ -242,7 +221,8 @@ class IssueViewStore implements IIssueViewStore { ...this?.issues?.[workspaceId]?.project_issues?.[projectId], issues: { ...this?.issues[workspaceId]?.project_issues?.[projectId]?.issues, - [_layout as string]: issuesResponse, + [this.rootStore?.issueFilters?.userFilters?.display_filters?.layout as string]: + issuesResponse, }, }, }, @@ -266,13 +246,7 @@ class IssueViewStore implements IIssueViewStore { }; // fetching project issues for modules - getIssuesForModulesAsync = async ( - workspaceId: string, - projectId: string, - moduleId: string, - _view: TIssueViews, - _layout: TIssueLayouts - ) => { + getIssuesForModulesAsync = async (workspaceId: string, projectId: string, moduleId: string) => { try { this.loader = true; this.error = null; @@ -288,8 +262,7 @@ class IssueViewStore implements IIssueViewStore { moduleId, null, null, - _view, - _layout + "modules" ); const issuesResponse = await this.modulesService.getModuleIssuesWithParams( workspaceId, @@ -311,7 +284,8 @@ class IssueViewStore implements IIssueViewStore { ...this?.issues[workspaceId]?.project_issues?.[projectId]?.modules, [moduleId]: { ...this?.issues[workspaceId]?.project_issues?.[projectId]?.modules?.[moduleId], - [_layout as string]: issuesResponse, + [this.rootStore?.issueFilters?.userFilters?.display_filters?.layout as string]: + issuesResponse, }, }, }, @@ -336,13 +310,7 @@ class IssueViewStore implements IIssueViewStore { }; // fetching project issues for cycles - getIssuesForCyclesAsync = async ( - workspaceId: string, - projectId: string, - cycleId: string, - _view: TIssueViews, - _layout: TIssueLayouts - ) => { + getIssuesForCyclesAsync = async (workspaceId: string, projectId: string, cycleId: string) => { try { this.loader = true; this.error = null; @@ -358,8 +326,7 @@ class IssueViewStore implements IIssueViewStore { null, cycleId, null, - _view, - _layout + "cycles" ); const issuesResponse = await this.cyclesService.getCycleIssuesWithParams( workspaceId, @@ -381,7 +348,8 @@ class IssueViewStore implements IIssueViewStore { ...this?.issues[workspaceId]?.project_issues?.[projectId]?.cycles, [cycleId]: { ...this?.issues[workspaceId]?.project_issues?.[projectId]?.cycles?.[cycleId], - [_layout as string]: issuesResponse, + [this.rootStore?.issueFilters?.userFilters?.display_filters?.layout as string]: + issuesResponse, }, }, }, @@ -406,13 +374,7 @@ class IssueViewStore implements IIssueViewStore { }; // fetching project issues for views - getIssuesForViewsAsync = async ( - workspaceId: string, - projectId: string, - viewId: string, - _view: TIssueViews, - _layout: TIssueLayouts - ) => { + getIssuesForViewsAsync = async (workspaceId: string, projectId: string, viewId: string) => { try { this.loader = true; this.error = null; @@ -424,8 +386,7 @@ class IssueViewStore implements IIssueViewStore { null, null, viewId, - _view, - _layout + "views" ); const issuesResponse = await this.issueService.getIssuesWithParams( workspaceId, @@ -446,7 +407,8 @@ class IssueViewStore implements IIssueViewStore { ...this?.issues[workspaceId]?.project_issues?.[projectId]?.views, [viewId]: { ...this?.issues[workspaceId]?.project_issues?.[projectId]?.views?.[viewId], - [_layout as string]: issuesResponse, + [this.rootStore?.issueFilters?.userFilters?.display_filters?.layout as string]: + issuesResponse, }, }, }, diff --git a/web/store/issue-views/issue_filters.ts b/web/store/issue-views/issue_filters.ts index ee37f1f48..f5c16fc7a 100644 --- a/web/store/issue-views/issue_filters.ts +++ b/web/store/issue-views/issue_filters.ts @@ -6,6 +6,9 @@ import { WorkspaceService } from "services/workspace.service"; import { ProjectIssuesServices } from "services/issues.service"; import { ProjectStateServices } from "services/state.service"; import { ProjectServices } from "services/project.service"; +import { ProjectIssuesServices as ProjectModuleServices } from "services/modules.service"; +import { ProjectCycleServices } from "services/cycles.service"; +import { ViewServices as ProjectViewServices } from "services/views.service"; // default data import { filtersPriority, @@ -21,6 +24,7 @@ import { export type TIssueViews = "my_issues" | "issues" | "modules" | "views" | "cycles"; export type TIssueLayouts = "list" | "kanban" | "calendar" | "spreadsheet" | "gantt"; + export interface IIssueFilter { priority: string[] | undefined; state: string[] | undefined; @@ -92,6 +96,7 @@ export interface IIssueFilters { my_issue_properties: { filters: IIssueFilter; display_filters: IIssueDisplayFilters; + display_properties_id: null; display_properties: IIssueDisplayProperties; }; project_issue_properties: { @@ -115,6 +120,7 @@ export interface IIssueFilters { filters: IIssueFilter; }; }; + display_properties_id: string; display_properties: IIssueDisplayProperties; }; }; @@ -126,6 +132,7 @@ export interface IIssueFilterStore { error: any | null; // current workspace and project id + myUserId: string | null; workspaceId: string | null; projectId: string | null; moduleId: string | null; @@ -136,48 +143,65 @@ export interface IIssueFilterStore { issueRenderFilters: IIssueRenderFilters; issueFilters: IIssueFilters; - filterRenderProperties: - | { - [key: string]: { - isPreviewEnabled: boolean; - totalElements: number; - elementsVisible: number; - }; - }[] - | null; - // actions getWorkspaceMyIssuesFilters: (workspaceId: string) => Promise; - updateWorkspaceMyIssuesFilters: () => any | Promise; + updateWorkspaceMyIssuesFilters: (workspaceId: string, data: any) => Promise; - getProjectLevelMembers: (workspaceId: string, projectId: string) => any | Promise; - getProjectLevelStates: (workspaceId: string, projectId: string) => any | Promise; - getProjectLevelLabels: (workspaceId: string, projectId: string) => any | Promise; - getProjectDisplayFilters: (workspaceId: string, projectId: string) => any | Promise; - getProjectDisplayProperties: (workspaceId: string, projectId: string) => any | Promise; + getProjectLevelMembers: (workspaceId: string, projectId: string) => Promise; + getProjectLevelStates: (workspaceId: string, projectId: string) => Promise; + getProjectLevelLabels: (workspaceId: string, projectId: string) => Promise; + getProjectDisplayProperties: (workspaceId: string, projectId: string) => Promise; + updateProjectDisplayProperties: ( + workspaceId: string, + projectId: string, + display_properties_id: string, + data: any + ) => Promise; + getProjectDisplayFilters: (workspaceId: string, projectId: string) => Promise; + updateProjectDisplayFilters: (workspaceId: string, projectId: string, data: any) => Promise; + + getProjectIssueFilters: (workspaceId: string, projectId: string) => Promise; - getProjectIssueFilters: (workspaceId: string, projectId: string) => any | Promise; getProjectIssueModuleFilters: ( workspaceId: string, projectId: string, moduleId: string - ) => any | Promise; + ) => Promise; + updateProjectIssueModuleFilters: ( + workspaceId: string, + projectId: string, + moduleId: string, + data: any + ) => Promise; getProjectIssueCyclesFilters: ( workspaceId: string, projectId: string, cycleId: string - ) => any | Promise; + ) => Promise; + updateProjectIssueCyclesFilters: ( + workspaceId: string, + projectId: string, + cycleId: string, + data: any + ) => Promise; getProjectIssueViewsFilters: ( workspaceId: string, projectId: string, viewId: string - ) => any | Promise; + ) => Promise; + updateProjectIssueViewsFilters: ( + workspaceId: string, + projectId: string, + viewId: string, + data: any + ) => Promise; } class IssueFilterStore implements IIssueFilterStore { loader: boolean = false; error: any | null = null; + myUserId: string | null = null; workspaceId: string | null = null; projectId: string | null = null; moduleId: string | null = null; @@ -200,16 +224,6 @@ class IssueFilterStore implements IIssueFilterStore { }; issueFilters: IIssueFilters = {}; - filterRenderProperties: - | { - [key: string]: { - isPreviewEnabled: boolean; - totalElements: number; - elementsVisible: number; - }; - }[] - | null = null; - // root store rootStore; // service @@ -217,6 +231,9 @@ class IssueFilterStore implements IIssueFilterStore { issueService; stateService; projectService; + moduleService; + cycleService; + viewService; constructor(_rootStore: RootStore) { makeObservable(this, { @@ -224,6 +241,7 @@ class IssueFilterStore implements IIssueFilterStore { loader: observable, error: observable, + myUserId: observable, workspaceId: observable, projectId: observable, moduleId: observable, @@ -246,29 +264,34 @@ class IssueFilterStore implements IIssueFilterStore { userFilters: computed, - // action - setWorkspaceId: action, - setProjectId: action, - setModuleId: action, - setCycleId: action, - setViewId: action, - setIssueView: action, - + // actions getComputedFilters: action, + handleUserFilter: action, + getWorkspaceMyIssuesFilters: action, updateWorkspaceMyIssuesFilters: action, getProjectLevelMembers: action, getProjectLevelStates: action, getProjectLevelLabels: action, + getProjectDisplayFilters: action, + updateProjectDisplayFilters: action, + getProjectDisplayProperties: action, + updateProjectDisplayProperties: action, getProjectIssueFilters: action, + getProjectIssueModuleFilters: action, + updateProjectIssueModuleFilters: action, + getProjectIssueCyclesFilters: action, + updateProjectIssueCyclesFilters: action, + getProjectIssueViewsFilters: action, + updateProjectIssueViewsFilters: action, }); this.rootStore = _rootStore; @@ -276,15 +299,11 @@ class IssueFilterStore implements IIssueFilterStore { this.issueService = new ProjectIssuesServices(); this.stateService = new ProjectStateServices(); this.projectService = new ProjectServices(); + this.moduleService = new ProjectModuleServices(); + this.cycleService = new ProjectCycleServices(); + this.viewService = new ProjectViewServices(); } - setWorkspaceId = (_workspaceId: string | null) => (this.workspaceId = _workspaceId); - setProjectId = (_projectId: string | null) => (this.projectId = _projectId); - setModuleId = (_moduleId: string | null) => (this.moduleId = _moduleId); - setCycleId = (_cycleId: string | null) => (this.cycleId = _cycleId); - setViewId = (_viewId: string | null) => (this.viewId = _viewId); - setIssueView = (_view: TIssueViews | null) => (this.issueView = _view); - // computed get issueLayout() { if (!this.workspaceId) return null; @@ -331,22 +350,30 @@ class IssueFilterStore implements IIssueFilterStore { get userFilters() { if (!this.workspaceId) return null; if (this.issueView === "my_issues") - return this.issueFilters?.[this.workspaceId]?.my_issue_properties; + return { + ...this.issueFilters?.[this.workspaceId]?.my_issue_properties, + display_properties_id: null, + }; if (!this.projectId) return null; let _issueFilters: { filters: IIssueFilter | null; display_filters: IIssueDisplayFilters; + display_properties_id: string; display_properties: IIssueDisplayProperties; } = { filters: null, display_filters: this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[this.projectId]?.issues ?.display_filters, + display_properties_id: + this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[this.projectId] + ?.display_properties_id, display_properties: this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[this.projectId] ?.display_properties, }; + if (this.issueView === "issues") { _issueFilters = { ..._issueFilters, @@ -356,6 +383,7 @@ class IssueFilterStore implements IIssueFilterStore { }; return _issueFilters; } + if (this.issueView === "modules" && this.moduleId) { _issueFilters = { ..._issueFilters, @@ -365,6 +393,7 @@ class IssueFilterStore implements IIssueFilterStore { }; return _issueFilters; } + if (this.issueView === "cycles" && this.cycleId) { _issueFilters = { ..._issueFilters, @@ -374,6 +403,7 @@ class IssueFilterStore implements IIssueFilterStore { }; return _issueFilters; } + if (this.issueView === "views" && this.viewId) { _issueFilters = { ..._issueFilters, @@ -383,9 +413,243 @@ class IssueFilterStore implements IIssueFilterStore { }; return _issueFilters; } + return null; } - handleUserFilter = () => {}; + handleUserFilter = ( + filter_type: "filters" | "display_filters" | "display_properties", + filter_key: string, + value: any + ) => { + if (!this.workspaceId) return null; + + if (this.issueView === "my_issues") { + this.issueFilters = { + ...this.issueFilters, + [this.workspaceId]: { + ...this.issueFilters?.[this.workspaceId], + my_issue_properties: { + ...this.issueFilters?.[this.workspaceId]?.my_issue_properties, + [filter_type]: { + ...this.issueFilters?.[this.workspaceId]?.my_issue_properties?.[filter_type], + [filter_key]: value, + }, + }, + }, + }; + this.updateWorkspaceMyIssuesFilters(this.workspaceId, this.userFilters); + } + + if (!this.projectId) return null; + if (filter_type === "display_properties") { + this.issueFilters = { + ...this.issueFilters, + [this.workspaceId]: { + ...this.issueFilters?.[this.workspaceId], + project_issue_properties: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties, + [this.projectId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[this.projectId], + display_properties: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[this.projectId] + ?.display_properties, + [filter_key]: value, + }, + }, + }, + }, + }; + + if (this.userFilters?.display_properties_id) { + this.updateProjectDisplayProperties( + this.workspaceId, + this.projectId, + this.userFilters?.display_properties_id, + this.userFilters?.display_properties + ); + } + } + + if (filter_type === "display_filters") { + this.issueFilters = { + ...this.issueFilters, + [this.workspaceId]: { + ...this.issueFilters?.[this.workspaceId], + project_issue_properties: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties, + [this.projectId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[this.projectId], + issues: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[this.projectId] + ?.issues, + [filter_type]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.issues?.[filter_type], + [filter_key]: value, + }, + }, + }, + }, + }, + }; + this.updateProjectDisplayFilters(this.workspaceId, this.projectId, { + filters: this.userFilters?.filters, + display_filters: this.userFilters?.display_filters, + }); + } + + if (filter_type === "filters") { + if (this.issueView === "issues") { + this.issueFilters = { + ...this.issueFilters, + [this.workspaceId]: { + ...this.issueFilters?.[this.workspaceId], + project_issue_properties: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties, + [this.projectId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ], + issues: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.issues, + [filter_type]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.issues?.[filter_type], + [filter_key]: value, + }, + }, + }, + }, + }, + }; + this.updateProjectDisplayFilters(this.workspaceId, this.projectId, { + filters: this.userFilters?.filters, + display_filters: this.userFilters?.display_filters, + }); + } + + if (this.issueView === "modules" && this.moduleId) { + this.issueFilters = { + ...this.issueFilters, + [this.workspaceId]: { + ...this.issueFilters?.[this.workspaceId], + project_issue_properties: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties, + [this.projectId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ], + modules: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.modules, + [this.moduleId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.modules?.[this.moduleId], + [filter_type]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.modules?.[this.moduleId]?.[filter_type], + [filter_key]: value, + }, + }, + }, + }, + }, + }, + }; + this.updateProjectIssueModuleFilters( + this.workspaceId, + this.projectId, + this.moduleId, + this.userFilters?.filters + ); + } + + if (this.issueView === "cycles" && this.cycleId) { + this.issueFilters = { + ...this.issueFilters, + [this.workspaceId]: { + ...this.issueFilters?.[this.workspaceId], + project_issue_properties: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties, + [this.projectId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ], + cycles: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.cycles, + [this.cycleId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.cycles?.[this.cycleId], + [filter_type]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.cycles?.[this.cycleId]?.[filter_type], + [filter_key]: value, + }, + }, + }, + }, + }, + }, + }; + this.updateProjectIssueCyclesFilters( + this.workspaceId, + this.projectId, + this.cycleId, + this.userFilters?.filters + ); + } + + if (this.issueView === "views" && this.viewId) { + this.issueFilters = { + ...this.issueFilters, + [this.workspaceId]: { + ...this.issueFilters?.[this.workspaceId], + project_issue_properties: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties, + [this.projectId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ], + views: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.views, + [this.viewId]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.views?.[this.viewId], + [filter_type]: { + ...this.issueFilters?.[this.workspaceId]?.project_issue_properties?.[ + this.projectId + ]?.views?.[this.viewId]?.[filter_type], + [filter_key]: value, + }, + }, + }, + }, + }, + }, + }; + this.updateProjectIssueViewsFilters( + this.workspaceId, + this.projectId, + this.viewId, + this.userFilters?.filters + ); + } + } + }; computedFilter = (filters: any, filteredParams: any) => { const computedFilters: any = {}; @@ -405,15 +669,14 @@ class IssueFilterStore implements IIssueFilterStore { _moduleId: string | null, _cycleId: string | null, _viewId: string | null, - _issueView: TIssueViews, - _issueLayout: TIssueLayouts + _issueView: TIssueViews ) => { - this.setWorkspaceId(_workspaceId); - this.setProjectId(_projectId); - this.setModuleId(_moduleId); - this.setCycleId(_cycleId); - this.setViewId(_viewId); - this.setIssueView(_issueView); + this.workspaceId = _workspaceId; + this.projectId = _projectId; + this.moduleId = _moduleId; + this.cycleId = _cycleId; + this.viewId = _viewId; + this.issueView = _issueView; const _layout = this.userFilters?.display_filters?.layout; @@ -426,17 +689,15 @@ class IssueFilterStore implements IIssueFilterStore { labels: this.userFilters?.filters?.labels || undefined, start_date: this.userFilters?.filters?.start_date || undefined, target_date: this.userFilters?.filters?.target_date || undefined, - type: this.userFilters?.display_filters?.type || undefined, group_by: this.userFilters?.display_filters?.group_by || "state", order_by: this.userFilters?.display_filters?.order_by || "-created_at", + type: this.userFilters?.display_filters?.type || undefined, sub_issue: this.userFilters?.display_filters?.sub_issue || true, show_empty_groups: this.userFilters?.display_filters?.show_empty_groups || true, calendar_date_range: this.userFilters?.display_filters?.calendar_date_range || undefined, start_target_date: this.userFilters?.display_filters?.start_target_date || true, }; - console.log("filteredRouteParams", filteredRouteParams); - // start date and target date we have to construct the format here let filteredParams: any = {}; @@ -515,7 +776,6 @@ class IssueFilterStore implements IIssueFilterStore { filteredRouteParams = this.computedFilter(filteredRouteParams, filteredParams); // remove few attributes from the object when we are in workspace issues - console.log("filteredRouteParams", filteredRouteParams); return filteredRouteParams; }; @@ -667,36 +927,25 @@ class IssueFilterStore implements IIssueFilterStore { return error; } }; - updateWorkspaceMyIssuesFilters = async () => { + updateWorkspaceMyIssuesFilters = async (workspaceId: string, data: any) => { try { this.loader = true; this.error = null; - const workspaceId = "1"; - - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); + const payload = { + view_props: data, + }; + const issuesFiltersResponse = await this.workspaceService.updateWorkspaceView( + workspaceId, + payload + ); if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; - runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; this.loader = false; this.error = null; }); } - - // return issuesResponse; } catch (error) { console.warn("error in fetching workspace level issue filters", error); this.loader = false; @@ -837,6 +1086,7 @@ class IssueFilterStore implements IIssueFilterStore { ); if (issuesDisplayPropertiesResponse) { + const _myUserId: string = issuesDisplayPropertiesResponse?.user; const _issuesDisplayPropertiesResponse: any = { ...this.issueFilters, [workspaceId]: { @@ -845,13 +1095,17 @@ class IssueFilterStore implements IIssueFilterStore { ...this?.issueFilters[workspaceId]?.project_issue_properties, [projectId]: { ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId], - display_properties: issuesDisplayPropertiesResponse?.properties, + display_properties_id: issuesDisplayPropertiesResponse?.id, + display_properties: { + ...issuesDisplayPropertiesResponse?.properties, + }, }, }, }, }; runInAction(() => { + this.myUserId = _myUserId; this.issueFilters = _issuesDisplayPropertiesResponse; this.loader = false; this.error = null; @@ -866,33 +1120,29 @@ class IssueFilterStore implements IIssueFilterStore { return error; } }; - updateProjectDisplayProperties = async (workspaceId: string, projectId: string, data: any) => { + updateProjectDisplayProperties = async ( + workspaceId: string, + projectId: string, + display_properties_id: string, + data: any + ) => { try { this.loader = true; this.error = null; - const issuesDisplayPropertiesResponse = await this.issueService.getIssueProperties( + const payload = { + properties: data, + user: this.myUserId, + }; + const issuesDisplayPropertiesResponse = await this.issueService.patchIssueProperties( workspaceId, - projectId + projectId, + display_properties_id, + payload ); if (issuesDisplayPropertiesResponse) { - const _issuesDisplayPropertiesResponse: any = { - ...this.issueFilters, - [workspaceId]: { - ...this?.issueFilters[workspaceId], - project_issue_properties: { - ...this?.issueFilters[workspaceId]?.project_issue_properties, - [projectId]: { - ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId], - display_properties: issuesDisplayPropertiesResponse, - }, - }, - }, - }; - runInAction(() => { - this.issueFilters = _issuesDisplayPropertiesResponse; this.loader = false; this.error = null; }); @@ -946,7 +1196,7 @@ class IssueFilterStore implements IIssueFilterStore { }); } - // return issuesResponse; + return issuesDisplayFiltersResponse; } catch (error) { console.warn("error in fetching workspace level issue filters", error); this.loader = false; @@ -954,37 +1204,30 @@ class IssueFilterStore implements IIssueFilterStore { return error; } }; - updateProjectDisplayFilters = async (workspaceId: string, projectId: string) => { + updateProjectDisplayFilters = async (workspaceId: string, projectId: string, data: any) => { try { this.loader = true; this.error = null; - const workspaceId = "1"; - - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); + const payload: any = { + view_props: data, + }; + const issuesFiltersResponse = await this.projectService.setProjectView( + workspaceId, + projectId, + payload + ); if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; - runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; this.loader = false; this.error = null; }); } - // return issuesResponse; + return issuesFiltersResponse; } catch (error) { + this.getProjectDisplayFilters(workspaceId, projectId); console.warn("error in fetching workspace level issue filters", error); this.loader = false; this.error = null; @@ -1007,43 +1250,6 @@ class IssueFilterStore implements IIssueFilterStore { this.loader = false; this.error = null; }); - - // return issuesResponse; - } catch (error) { - console.warn("error in fetching workspace level issue filters", error); - this.loader = false; - this.error = null; - return error; - } - }; - updateProjectIssueFilters = async (workspaceId: string, projectId: string) => { - try { - this.loader = true; - this.error = null; - - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); - - if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; - - runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; - this.loader = false; - this.error = null; - }); - } - - // return issuesResponse; } catch (error) { console.warn("error in fetching workspace level issue filters", error); this.loader = false; @@ -1061,31 +1267,53 @@ class IssueFilterStore implements IIssueFilterStore { this.loader = true; this.error = null; - const workspaceId = "1"; + await this.getProjectIssueFilters(workspaceId, projectId); - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); + const issuesFiltersModuleResponse = await this.moduleService.getModuleDetails( + workspaceId, + projectId, + moduleId + ); - if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; + if (issuesFiltersModuleResponse) { + const _filters = { ...issuesFiltersModuleResponse?.view_props?.filters }; + const _issuesFiltersModuleResponse = { + ...this.issueFilters, + [workspaceId]: { + ...this?.issueFilters[workspaceId], + project_issue_properties: { + ...this?.issueFilters[workspaceId]?.project_issue_properties, + [projectId]: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId], + modules: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId] + ?.modules, + [moduleId]: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId] + ?.modules?.[moduleId], + filters: { + priority: _filters?.priority ?? undefined, + state: _filters?.state ?? undefined, + state_group: _filters?.state_group ?? undefined, + assignees: _filters?.assignees ?? undefined, + created_by: _filters?.created_by ?? undefined, + labels: _filters?.labels ?? undefined, + start_date: _filters?.start_date ?? undefined, + target_date: _filters?.target_date ?? undefined, + }, + }, + }, + }, + }, + }, + }; runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; + this.issueFilters = _issuesFiltersModuleResponse; this.loader = false; this.error = null; }); } - - // return issuesResponse; } catch (error) { console.warn("error in fetching workspace level issue filters", error); this.loader = false; @@ -1096,38 +1324,32 @@ class IssueFilterStore implements IIssueFilterStore { updateProjectIssueModuleFilters = async ( workspaceId: string, projectId: string, - moduleId: string + moduleId: string, + data: any ) => { try { this.loader = true; this.error = null; - const workspaceId = "1"; - - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); - - if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; + const payload = { + view_props: { filters: data }, + }; + const issuesFiltersModuleResponse = await this.moduleService.patchModule( + workspaceId, + projectId, + moduleId, + payload, + undefined // TODO: replace this with user + ); + if (issuesFiltersModuleResponse) { runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; this.loader = false; this.error = null; }); } - - // return issuesResponse; } catch (error) { + this.getProjectIssueModuleFilters(workspaceId, projectId, moduleId); console.warn("error in fetching workspace level issue filters", error); this.loader = false; this.error = null; @@ -1144,31 +1366,52 @@ class IssueFilterStore implements IIssueFilterStore { this.loader = true; this.error = null; - const workspaceId = "1"; + await this.getProjectIssueFilters(workspaceId, projectId); - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); + const issuesFiltersCycleResponse = await this.cycleService.getCycleDetails( + workspaceId, + projectId, + cycleId + ); - if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; + if (issuesFiltersCycleResponse) { + const _filters = { ...issuesFiltersCycleResponse?.view_props?.filters }; + const _issuesFiltersCycleResponse = { + ...this.issueFilters, + [workspaceId]: { + ...this?.issueFilters[workspaceId], + project_issue_properties: { + ...this?.issueFilters[workspaceId]?.project_issue_properties, + [projectId]: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId], + cycles: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId]?.cycles, + [cycleId]: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId] + ?.modules?.[cycleId], + filters: { + priority: _filters?.priority ?? undefined, + state: _filters?.state ?? undefined, + state_group: _filters?.state_group ?? undefined, + assignees: _filters?.assignees ?? undefined, + created_by: _filters?.created_by ?? undefined, + labels: _filters?.labels ?? undefined, + start_date: _filters?.start_date ?? undefined, + target_date: _filters?.target_date ?? undefined, + }, + }, + }, + }, + }, + }, + }; runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; + this.issueFilters = _issuesFiltersCycleResponse; this.loader = false; this.error = null; }); } - - // return issuesResponse; } catch (error) { console.warn("error in fetching workspace level issue filters", error); this.loader = false; @@ -1179,38 +1422,32 @@ class IssueFilterStore implements IIssueFilterStore { updateProjectIssueCyclesFilters = async ( workspaceId: string, projectId: string, - cycleId: string + cycleId: string, + data: any ) => { try { this.loader = true; this.error = null; - const workspaceId = "1"; - - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); - - if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; + const payload = { + view_props: { filters: data }, + }; + const issuesFiltersCycleResponse = await this.cycleService.patchCycle( + workspaceId, + projectId, + cycleId, + payload, + undefined // TODO: replace this with user + ); + if (issuesFiltersCycleResponse) { runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; this.loader = false; this.error = null; }); } - - // return issuesResponse; } catch (error) { + this.getProjectIssueCyclesFilters(workspaceId, projectId, cycleId); console.warn("error in fetching workspace level issue filters", error); this.loader = false; this.error = null; @@ -1223,31 +1460,52 @@ class IssueFilterStore implements IIssueFilterStore { this.loader = true; this.error = null; - const workspaceId = "1"; + await this.getProjectIssueFilters(workspaceId, projectId); - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); + const issuesFiltersViewResponse = await this.viewService.getViewDetails( + workspaceId, + projectId, + viewId + ); - if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; + if (issuesFiltersViewResponse) { + const _filters = { ...issuesFiltersViewResponse?.query_data } as any; + const _issuesFiltersViewResponse = { + ...this.issueFilters, + [workspaceId]: { + ...this?.issueFilters[workspaceId], + project_issue_properties: { + ...this?.issueFilters[workspaceId]?.project_issue_properties, + [projectId]: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId], + views: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId]?.cycles, + [viewId]: { + ...this?.issueFilters[workspaceId]?.project_issue_properties?.[projectId] + ?.modules?.[viewId], + filters: { + priority: _filters?.priority ?? undefined, + state: _filters?.state ?? undefined, + state_group: _filters?.state_group ?? undefined, + assignees: _filters?.assignees ?? undefined, + created_by: _filters?.created_by ?? undefined, + labels: _filters?.labels ?? undefined, + start_date: _filters?.start_date ?? undefined, + target_date: _filters?.target_date ?? undefined, + }, + }, + }, + }, + }, + }, + }; runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; + this.issueFilters = _issuesFiltersViewResponse; this.loader = false; this.error = null; }); } - - // return issuesResponse; } catch (error) { console.warn("error in fetching workspace level issue filters", error); this.loader = false; @@ -1258,45 +1516,40 @@ class IssueFilterStore implements IIssueFilterStore { updateProjectIssueViewsFilters = async ( workspaceId: string, projectId: string, - viewId: string + viewId: string, + data: any ) => { try { this.loader = true; this.error = null; - const workspaceId = "1"; - - const issuesFiltersResponse = await this.workspaceService.workspaceMemberMe(workspaceId); - - if (issuesFiltersResponse) { - // const _issuesFiltersResponse = this.issueFilters; - // const _issuesFiltersResponse: any = { - // ...this.issues, - // [workspaceId]: { - // ...this?.issues[workspaceId], - // my_issues: { - // ...this?.issues[workspaceId]?.my_issues, - // [_layout as string]: issuesResponse, - // }, - // }, - // }; + const payload = { + query_data: data, + }; + const issuesFiltersViewResponse = await this.viewService.patchView( + workspaceId, + projectId, + viewId, + payload, + undefined // TODO: replace this with user + ); + if (issuesFiltersViewResponse) { runInAction(() => { - // this.issueFilters = _issuesFiltersResponse; this.loader = false; this.error = null; }); } - // return issuesResponse; + return issuesFiltersViewResponse; } catch (error) { + this.getProjectIssueViewsFilters(projectId, workspaceId, viewId); console.warn("error in fetching workspace level issue filters", error); this.loader = false; this.error = null; return error; } }; - // project level filters ends } export default IssueFilterStore;