From 691cbef1f2bba7bb523e02b7d3aac23f346a8bf7 Mon Sep 17 00:00:00 2001 From: Prateek Shourya Date: Fri, 28 Mar 2025 15:12:40 +0530 Subject: [PATCH] [WEB-3701] fix: use `getCycleById` to ensure null handling for cycle access (#6838) * [WEB-3701] fix: use `getCycleById` to ensure null handling for cycle access * fix: cycle sidebar storage values --- .../[projectId]/cycles/(detail)/[cycleId]/page.tsx | 6 +++--- .../(detail)/[projectId]/cycles/(detail)/header.tsx | 6 +++--- web/core/store/cycle.store.ts | 11 +++++------ web/core/store/issue/cycle/issue.store.ts | 5 +++++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/cycles/(detail)/[cycleId]/page.tsx b/web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/cycles/(detail)/[cycleId]/page.tsx index 381b567df..fbe8ed85d 100644 --- a/web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/cycles/(detail)/[cycleId]/page.tsx +++ b/web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/cycles/(detail)/[cycleId]/page.tsx @@ -26,7 +26,7 @@ const CycleDetailPage = observer(() => { const { getProjectById } = useProject(); // const { issuesFilter } = useIssues(EIssuesStoreType.CYCLE); // hooks - const { setValue, storedValue } = useLocalStorage("cycle_sidebar_collapsed", "false"); + const { setValue, storedValue } = useLocalStorage("cycle_sidebar_collapsed", false); useCyclesDetails({ workspaceSlug: workspaceSlug?.toString(), @@ -34,7 +34,7 @@ const CycleDetailPage = observer(() => { cycleId: cycleId.toString(), }); // derived values - const isSidebarCollapsed = storedValue ? (storedValue === "true" ? true : false) : false; + const isSidebarCollapsed = storedValue ? (storedValue === true ? true : false) : false; const cycle = cycleId ? getCycleById(cycleId.toString()) : undefined; const project = projectId ? getProjectById(projectId.toString()) : undefined; const pageTitle = project?.name && cycle?.name ? `${project?.name} - ${cycle?.name}` : undefined; @@ -42,7 +42,7 @@ const CycleDetailPage = observer(() => { /** * Toggles the sidebar */ - const toggleSidebar = () => setValue(`${!isSidebarCollapsed}`); + const toggleSidebar = () => setValue(!isSidebarCollapsed); // const activeLayout = issuesFilter?.issueFilters?.displayFilters?.layout; diff --git a/web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/cycles/(detail)/header.tsx b/web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/cycles/(detail)/header.tsx index 508da58a2..106dfa4d2 100644 --- a/web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/cycles/(detail)/header.tsx +++ b/web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/cycles/(detail)/header.tsx @@ -99,11 +99,11 @@ export const CycleIssuesHeader: React.FC = observer(() => { const activeLayout = issueFilters?.displayFilters?.layout; - const { setValue, storedValue } = useLocalStorage("cycle_sidebar_collapsed", "false"); + const { setValue, storedValue } = useLocalStorage("cycle_sidebar_collapsed", false); - const isSidebarCollapsed = storedValue ? (storedValue === "true" ? true : false) : false; + const isSidebarCollapsed = storedValue ? (storedValue === true ? true : false) : false; const toggleSidebar = () => { - setValue(`${!isSidebarCollapsed}`); + setValue(!isSidebarCollapsed); }; const handleLayoutChange = useCallback( diff --git a/web/core/store/cycle.store.ts b/web/core/store/cycle.store.ts index 89221ee7c..d08d8e935 100644 --- a/web/core/store/cycle.store.ts +++ b/web/core/store/cycle.store.ts @@ -241,10 +241,10 @@ export class CycleStore implements ICycleStore { } getIsPointsDataAvailable = computedFn((cycleId: string) => { - const cycle = this.cycleMap[cycleId]; + const cycle = this.getCycleById(cycleId); if (!cycle) return false; - if (this.cycleMap[cycleId].version === 2) return cycle.progress.some((p) => p.total_estimate_points > 0); - else if (this.cycleMap[cycleId].version === 1) { + if (cycle.version === 2) return cycle.progress?.some((p) => p.total_estimate_points > 0); + else if (cycle.version === 1) { const completionChart = cycle.estimate_distribution?.completion_chart || {}; return !isEmpty(completionChart) && Object.keys(completionChart).some((p) => completionChart[p]! > 0); } else return false; @@ -560,8 +560,7 @@ export class CycleStore implements ICycleStore { * @returns */ updateCycleDistribution = (distributionUpdates: DistributionUpdates, cycleId: string) => { - const cycle = this.cycleMap[cycleId]; - + const cycle = this.getCycleById(cycleId); if (!cycle) return; runInAction(() => { @@ -644,7 +643,7 @@ export class CycleStore implements ICycleStore { entity_type: "cycle", entity_identifier: cycleId, project_id: projectId, - entity_data: { name: this.cycleMap[cycleId].name || "" }, + entity_data: { name: currentCycle?.name || "" }, }); return response; } catch (error) { diff --git a/web/core/store/issue/cycle/issue.store.ts b/web/core/store/issue/cycle/issue.store.ts index 87f5a9212..9bf2c7e16 100644 --- a/web/core/store/issue/cycle/issue.store.ts +++ b/web/core/store/issue/cycle/issue.store.ts @@ -21,6 +21,7 @@ import { // helpers import { getDistributionPathsPostUpdate } from "@/helpers/distribution-update.helper"; //local +import { storage } from "@/lib/local-storage"; import { persistence } from "@/local-db/storage.sqlite"; import { BaseIssuesStore, IBaseIssuesStore } from "../helpers/base-issues.store"; // @@ -142,8 +143,12 @@ export class CycleIssues extends BaseIssuesStore implements ICycleIssues { projectId && cycleId && this.rootIssueStore.rootStore.cycle.fetchCycleDetails(workspaceSlug, projectId, cycleId); // fetch cycle progress + const isSidebarCollapsed = storage.get("cycle_sidebar_collapsed"); projectId && cycleId && + this.rootIssueStore.rootStore.cycle.getCycleById(cycleId)?.version === 2 && + isSidebarCollapsed && + JSON.parse(isSidebarCollapsed) === false && this.rootIssueStore.rootStore.cycle.fetchActiveCycleProgressPro(workspaceSlug, projectId, cycleId); };