From 2643de80af35c76361a7f5e091f1329cfd0cf645 Mon Sep 17 00:00:00 2001 From: sriram veeraghanta Date: Thu, 28 Sep 2023 20:30:48 +0530 Subject: [PATCH] cycles changes --- .../all-cycles-list.tsx | 3 +- .../completed-cycles-list.tsx | 0 .../draft-cycles-list.tsx | 0 .../index.ts | 0 .../upcoming-cycles-list.tsx | 0 web/components/cycles/cycles-list.tsx | 30 +++ web/components/cycles/cycles-view.tsx | 40 ++-- .../cycles/gantt-chart/cycles-list-layout.tsx | 47 +++-- web/constants/cycle.ts | 37 ++++ .../projects/[projectId]/cycles/index.tsx | 181 +++++++----------- web/store/cycles.ts | 17 +- 11 files changed, 188 insertions(+), 167 deletions(-) rename web/components/cycles/{cycles-list => cycles-list-legacy}/all-cycles-list.tsx (86%) rename web/components/cycles/{cycles-list => cycles-list-legacy}/completed-cycles-list.tsx (100%) rename web/components/cycles/{cycles-list => cycles-list-legacy}/draft-cycles-list.tsx (100%) rename web/components/cycles/{cycles-list => cycles-list-legacy}/index.ts (100%) rename web/components/cycles/{cycles-list => cycles-list-legacy}/upcoming-cycles-list.tsx (100%) create mode 100644 web/components/cycles/cycles-list.tsx create mode 100644 web/constants/cycle.ts diff --git a/web/components/cycles/cycles-list/all-cycles-list.tsx b/web/components/cycles/cycles-list-legacy/all-cycles-list.tsx similarity index 86% rename from web/components/cycles/cycles-list/all-cycles-list.tsx rename to web/components/cycles/cycles-list-legacy/all-cycles-list.tsx index 26bf0799c..a387261b6 100644 --- a/web/components/cycles/cycles-list/all-cycles-list.tsx +++ b/web/components/cycles/cycles-list-legacy/all-cycles-list.tsx @@ -20,8 +20,7 @@ export const AllCyclesList: React.FC = ({ viewType }) => { const { data: allCyclesList, mutate } = useSWR( workspaceSlug && projectId ? CYCLES_LIST(projectId.toString()) : null, workspaceSlug && projectId - ? () => - cyclesService.getCyclesWithParams(workspaceSlug.toString(), projectId.toString(), "all") + ? () => cyclesService.getCyclesWithParams(workspaceSlug.toString(), projectId.toString(), "all") : null ); diff --git a/web/components/cycles/cycles-list/completed-cycles-list.tsx b/web/components/cycles/cycles-list-legacy/completed-cycles-list.tsx similarity index 100% rename from web/components/cycles/cycles-list/completed-cycles-list.tsx rename to web/components/cycles/cycles-list-legacy/completed-cycles-list.tsx diff --git a/web/components/cycles/cycles-list/draft-cycles-list.tsx b/web/components/cycles/cycles-list-legacy/draft-cycles-list.tsx similarity index 100% rename from web/components/cycles/cycles-list/draft-cycles-list.tsx rename to web/components/cycles/cycles-list-legacy/draft-cycles-list.tsx diff --git a/web/components/cycles/cycles-list/index.ts b/web/components/cycles/cycles-list-legacy/index.ts similarity index 100% rename from web/components/cycles/cycles-list/index.ts rename to web/components/cycles/cycles-list-legacy/index.ts diff --git a/web/components/cycles/cycles-list/upcoming-cycles-list.tsx b/web/components/cycles/cycles-list-legacy/upcoming-cycles-list.tsx similarity index 100% rename from web/components/cycles/cycles-list/upcoming-cycles-list.tsx rename to web/components/cycles/cycles-list-legacy/upcoming-cycles-list.tsx diff --git a/web/components/cycles/cycles-list.tsx b/web/components/cycles/cycles-list.tsx new file mode 100644 index 000000000..02fcf11c0 --- /dev/null +++ b/web/components/cycles/cycles-list.tsx @@ -0,0 +1,30 @@ +import { useRouter } from "next/router"; +import { FC } from "react"; +import useSWR from "swr"; +// store +import { useMobxStore } from "lib/mobx/store-provider"; +import { CyclesView } from "./cycles-view"; + +export interface ICyclesList { + filter: "all" | "current" | "upcoming" | "draft" | "completed" | "incomplete"; +} + +export const CyclesList: FC = (props) => { + const { filter } = props; + // router + const router = useRouter(); + const { workspaceSlug, projectId } = router.query; + // store + const { cycle: cycleStore } = useMobxStore(); + + useSWR( + workspaceSlug && projectId ? `CYCLES_LIST_${projectId}` : null, + workspaceSlug && projectId + ? () => cycleStore.fetchCycles(workspaceSlug.toString(), projectId.toString(), filter) + : null + ); + if (!projectId) { + return <>; + } + return ; +}; diff --git a/web/components/cycles/cycles-view.tsx b/web/components/cycles/cycles-view.tsx index f6d0ab512..9d469c7ea 100644 --- a/web/components/cycles/cycles-view.tsx +++ b/web/components/cycles/cycles-view.tsx @@ -32,10 +32,11 @@ import { DRAFT_CYCLES_LIST, UPCOMING_CYCLES_LIST, } from "constants/fetch-keys"; +import { CYCLE_TAB_LIST, CYCLE_VIEWS } from "constants/cycle"; type Props = { cycles: ICycle[] | undefined; - mutateCycles: KeyedMutator; + mutateCycles?: KeyedMutator; viewType: string | null; }; @@ -46,7 +47,8 @@ export const CyclesView: React.FC = ({ cycles, mutateCycles, viewType }) const [deleteCycleModal, setDeleteCycleModal] = useState(false); const [selectedCycleToDelete, setSelectedCycleToDelete] = useState(null); - const { storedValue: cycleTab } = useLocalStorage("cycleTab", "All"); + const { storedValue: cycleTab } = useLocalStorage("cycle_tab", "all"); + console.log("cycleTab", cycleTab); const router = useRouter(); const { workspaceSlug, projectId } = router.query; @@ -145,15 +147,13 @@ export const CyclesView: React.FC = ({ cycles, mutateCycles, viewType }) false ); - cyclesService - .removeCycleFromFavorites(workspaceSlug as string, projectId as string, cycle.id) - .catch(() => { - setToastAlert({ - type: "error", - title: "Error!", - message: "Couldn't remove the cycle from favorites. Please try again.", - }); + cyclesService.removeCycleFromFavorites(workspaceSlug as string, projectId as string, cycle.id).catch(() => { + setToastAlert({ + type: "error", + title: "Error!", + message: "Couldn't remove the cycle from favorites. Please try again.", }); + }); }; return ( @@ -209,20 +209,8 @@ export const CyclesView: React.FC = ({ cycles, mutateCycles, viewType })
- - + + = ({ cycles, mutateCycles, viewType })

- {cycleTab === "All" - ? "No cycles" - : `No ${cycleTab === "Drafts" ? "draft" : cycleTab?.toLowerCase()} cycles`} + {cycleTab === "all" ? "No cycles" : `No ${cycleTab} cycles`}

- + {cycleTab && } - {cyclesView !== "gantt_chart" && ( - - - - )} - - + + - + {cycleTab && } + + + {cycleTab && } + + + {cycleTab && } - {cyclesView !== "gantt_chart" && ( - - - - )} )} ); -}; +}); -export default ProjectCycles; +export default ProjectCyclesPage; diff --git a/web/store/cycles.ts b/web/store/cycles.ts index afde42bb9..0ea92649a 100644 --- a/web/store/cycles.ts +++ b/web/store/cycles.ts @@ -18,6 +18,12 @@ export interface ICycleStore { cycle_details: { [cycle_id: string]: ICycle; }; + + fetchCycles: ( + workspaceSlug: string, + projectSlug: string, + params: "all" | "current" | "upcoming" | "draft" | "completed" | "incomplete" + ) => Promise; } class CycleStore implements ICycleStore { @@ -47,8 +53,9 @@ class CycleStore implements ICycleStore { cycles: observable.ref, // computed - + projectCycles: computed, // actions + fetchCycles: action, }); this.rootStore = _rootStore; @@ -64,12 +71,16 @@ class CycleStore implements ICycleStore { } // actions - fetchCycles = async (workspaceSlug: string, projectSlug: string) => { + fetchCycles = async ( + workspaceSlug: string, + projectSlug: string, + params: "all" | "current" | "upcoming" | "draft" | "completed" | "incomplete" + ) => { try { this.loader = true; this.error = null; - const cyclesResponse = await this.cycleService.getCyclesWithParams(workspaceSlug, projectSlug, "all"); + const cyclesResponse = await this.cycleService.getCyclesWithParams(workspaceSlug, projectSlug, params); runInAction(() => { this.cycles = {