From efc1671165181c9da8169c52af0ba1899afb1d94 Mon Sep 17 00:00:00 2001 From: sriram veeraghanta Date: Wed, 8 Nov 2023 14:27:24 +0530 Subject: [PATCH] fix: project issues using layouts --- .../roots/project-layout-root.tsx | 13 ++- web/services/issue/issue.service.ts | 8 ++ web/store/issue/issue-v2.store.ts | 83 +++++++++++++++++++ 3 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 web/store/issue/issue-v2.store.ts diff --git a/web/components/issues/issue-layouts/roots/project-layout-root.tsx b/web/components/issues/issue-layouts/roots/project-layout-root.tsx index 9fa9bb986b..0539542da5 100644 --- a/web/components/issues/issue-layouts/roots/project-layout-root.tsx +++ b/web/components/issues/issue-layouts/roots/project-layout-root.tsx @@ -22,15 +22,12 @@ export const ProjectLayoutRoot: React.FC = observer(() => { const { issue: issueStore, issueFilter: issueFilterStore } = useMobxStore(); - const { isLoading } = useSWR( - workspaceSlug && projectId ? `PROJECT_FILTERS_AND_ISSUES_${projectId.toString()}` : null, - async () => { - if (workspaceSlug && projectId) { - await issueFilterStore.fetchUserProjectFilters(workspaceSlug.toString(), projectId.toString()); - await issueStore.fetchIssues(workspaceSlug.toString(), projectId.toString()); - } + useSWR(workspaceSlug && projectId ? `PROJECT_FILTERS_AND_ISSUES_${projectId.toString()}` : null, async () => { + if (workspaceSlug && projectId) { + await issueFilterStore.fetchUserProjectFilters(workspaceSlug.toString(), projectId.toString()); + await issueStore.fetchIssues(workspaceSlug.toString(), projectId.toString()); } - ); + }); const activeLayout = issueFilterStore.userDisplayFilters.layout; diff --git a/web/services/issue/issue.service.ts b/web/services/issue/issue.service.ts index 5f28448963..37f688140e 100644 --- a/web/services/issue/issue.service.ts +++ b/web/services/issue/issue.service.ts @@ -32,6 +32,14 @@ export class IssueService extends APIService { }); } + async getV2Issues(workspaceSlug: string, projectId: string): Promise { + return this.get(`/api/v2/workspaces/${workspaceSlug}/projects/${projectId}/issues/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } + async getIssuesWithParams( workspaceSlug: string, projectId: string, diff --git a/web/store/issue/issue-v2.store.ts b/web/store/issue/issue-v2.store.ts new file mode 100644 index 0000000000..d999f12bbe --- /dev/null +++ b/web/store/issue/issue-v2.store.ts @@ -0,0 +1,83 @@ +import { observable, action, computed, makeObservable, runInAction, autorun } from "mobx"; +// store +import { RootStore } from "../root"; +// types +import { IIssue } from "types"; +// services +import { IssueService } from "services/issue"; +import { sortArrayByDate, sortArrayByPriority } from "constants/kanban-helpers"; +import { IBlockUpdateData } from "components/gantt-chart"; + +export type IIssueType = "grouped" | "groupWithSubGroups" | "ungrouped"; +export type IIssueGroupedStructure = { [group_id: string]: IIssue[] }; +export type IIssueGroupWithSubGroupsStructure = { + [group_id: string]: { + [sub_group_id: string]: IIssue[]; + }; +}; +export type IIssueUnGroupedStructure = IIssue[]; + +export interface IIssueStore { + loader: boolean; + error: any | null; + // issues + issues: { + [project_id: string]: IIssue[]; + }; + // computed + getIssueType: IIssueType | null; + getIssues: IIssueGroupedStructure | IIssueGroupWithSubGroupsStructure | IIssueUnGroupedStructure | null; + getIssuesCount: number; + // action + fetchIssues: (workspaceSlug: string, projectId: string) => Promise; + updateIssueStructure: (group_id: string | null, sub_group_id: string | null, issue: IIssue) => void; + removeIssueFromStructure: (group_id: string | null, sub_group_id: string | null, issue: IIssue) => void; + deleteIssue: (group_id: string | null, sub_group_id: string | null, issue: IIssue) => void; + updateGanttIssueStructure: (workspaceSlug: string, issue: IIssue, payload: IBlockUpdateData) => void; +} + +export class IssueStore implements IIssueStore { + loader: boolean = false; + error: any | null = null; + issues: { + [project_id: string]: IIssue[]; + } = {}; + // service + issueService; + rootStore; + + constructor(_rootStore: RootStore) { + makeObservable(this, { + // observable + loader: observable.ref, + error: observable.ref, + issues: observable.ref, + // computed + getIssues: computed, + // actions + fetchIssues: action, + }); + + this.rootStore = _rootStore; + this.issueService = new IssueService(); + } + + fetchIssues = async (workspaceSlug: string, projectId: string) => { + try { + const issues = await this.issueService.getV2Issues(workspaceSlug, projectId); + runInAction(() => { + this.issues = { + ...this.issues, + [projectId]: issues, + }; + }); + } catch (error) { + throw error; + } + }; + + get getIssues() { + const displayProperties = this.rootStore.issueFilter.userDisplayProperties; + return; + } +}