[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
This commit is contained in:
Prateek Shourya 2025-03-28 15:12:40 +05:30 committed by GitHub
parent fed0ef6185
commit 691cbef1f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 12 deletions

View file

@ -26,7 +26,7 @@ const CycleDetailPage = observer(() => {
const { getProjectById } = useProject(); const { getProjectById } = useProject();
// const { issuesFilter } = useIssues(EIssuesStoreType.CYCLE); // const { issuesFilter } = useIssues(EIssuesStoreType.CYCLE);
// hooks // hooks
const { setValue, storedValue } = useLocalStorage("cycle_sidebar_collapsed", "false"); const { setValue, storedValue } = useLocalStorage("cycle_sidebar_collapsed", false);
useCyclesDetails({ useCyclesDetails({
workspaceSlug: workspaceSlug?.toString(), workspaceSlug: workspaceSlug?.toString(),
@ -34,7 +34,7 @@ const CycleDetailPage = observer(() => {
cycleId: cycleId.toString(), cycleId: cycleId.toString(),
}); });
// derived values // 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 cycle = cycleId ? getCycleById(cycleId.toString()) : undefined;
const project = projectId ? getProjectById(projectId.toString()) : undefined; const project = projectId ? getProjectById(projectId.toString()) : undefined;
const pageTitle = project?.name && cycle?.name ? `${project?.name} - ${cycle?.name}` : undefined; const pageTitle = project?.name && cycle?.name ? `${project?.name} - ${cycle?.name}` : undefined;
@ -42,7 +42,7 @@ const CycleDetailPage = observer(() => {
/** /**
* Toggles the sidebar * Toggles the sidebar
*/ */
const toggleSidebar = () => setValue(`${!isSidebarCollapsed}`); const toggleSidebar = () => setValue(!isSidebarCollapsed);
// const activeLayout = issuesFilter?.issueFilters?.displayFilters?.layout; // const activeLayout = issuesFilter?.issueFilters?.displayFilters?.layout;

View file

@ -99,11 +99,11 @@ export const CycleIssuesHeader: React.FC = observer(() => {
const activeLayout = issueFilters?.displayFilters?.layout; 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 = () => { const toggleSidebar = () => {
setValue(`${!isSidebarCollapsed}`); setValue(!isSidebarCollapsed);
}; };
const handleLayoutChange = useCallback( const handleLayoutChange = useCallback(

View file

@ -241,10 +241,10 @@ export class CycleStore implements ICycleStore {
} }
getIsPointsDataAvailable = computedFn((cycleId: string) => { getIsPointsDataAvailable = computedFn((cycleId: string) => {
const cycle = this.cycleMap[cycleId]; const cycle = this.getCycleById(cycleId);
if (!cycle) return false; if (!cycle) return false;
if (this.cycleMap[cycleId].version === 2) return cycle.progress.some((p) => p.total_estimate_points > 0); if (cycle.version === 2) return cycle.progress?.some((p) => p.total_estimate_points > 0);
else if (this.cycleMap[cycleId].version === 1) { else if (cycle.version === 1) {
const completionChart = cycle.estimate_distribution?.completion_chart || {}; const completionChart = cycle.estimate_distribution?.completion_chart || {};
return !isEmpty(completionChart) && Object.keys(completionChart).some((p) => completionChart[p]! > 0); return !isEmpty(completionChart) && Object.keys(completionChart).some((p) => completionChart[p]! > 0);
} else return false; } else return false;
@ -560,8 +560,7 @@ export class CycleStore implements ICycleStore {
* @returns * @returns
*/ */
updateCycleDistribution = (distributionUpdates: DistributionUpdates, cycleId: string) => { updateCycleDistribution = (distributionUpdates: DistributionUpdates, cycleId: string) => {
const cycle = this.cycleMap[cycleId]; const cycle = this.getCycleById(cycleId);
if (!cycle) return; if (!cycle) return;
runInAction(() => { runInAction(() => {
@ -644,7 +643,7 @@ export class CycleStore implements ICycleStore {
entity_type: "cycle", entity_type: "cycle",
entity_identifier: cycleId, entity_identifier: cycleId,
project_id: projectId, project_id: projectId,
entity_data: { name: this.cycleMap[cycleId].name || "" }, entity_data: { name: currentCycle?.name || "" },
}); });
return response; return response;
} catch (error) { } catch (error) {

View file

@ -21,6 +21,7 @@ import {
// helpers // helpers
import { getDistributionPathsPostUpdate } from "@/helpers/distribution-update.helper"; import { getDistributionPathsPostUpdate } from "@/helpers/distribution-update.helper";
//local //local
import { storage } from "@/lib/local-storage";
import { persistence } from "@/local-db/storage.sqlite"; import { persistence } from "@/local-db/storage.sqlite";
import { BaseIssuesStore, IBaseIssuesStore } from "../helpers/base-issues.store"; 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); projectId && cycleId && this.rootIssueStore.rootStore.cycle.fetchCycleDetails(workspaceSlug, projectId, cycleId);
// fetch cycle progress // fetch cycle progress
const isSidebarCollapsed = storage.get("cycle_sidebar_collapsed");
projectId && projectId &&
cycleId && cycleId &&
this.rootIssueStore.rootStore.cycle.getCycleById(cycleId)?.version === 2 &&
isSidebarCollapsed &&
JSON.parse(isSidebarCollapsed) === false &&
this.rootIssueStore.rootStore.cycle.fetchActiveCycleProgressPro(workspaceSlug, projectId, cycleId); this.rootIssueStore.rootStore.cycle.fetchActiveCycleProgressPro(workspaceSlug, projectId, cycleId);
}; };