Skip to content

Commit 7563def

Browse files
committed
Gantt chart doesn't extend to 5 weeks out from any wp without time info
1 parent e59d678 commit 7563def

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

src/frontend/src/utils/gantt.utils.tsx

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,21 @@ export type RequestEventChange<T> = {
134134
};
135135

136136
export const getProjectStartDate = (project: ProjectGantt): Date => {
137-
const wpStart = project.workPackages.reduce((acc, current) => {
138-
if (current.startDate < acc) return current.startDate;
139-
return acc;
140-
}, new Date());
141-
return project.tasks.reduce((acc, current) => {
142-
if (current.startDate && current.startDate < acc) return current.startDate;
143-
return acc;
144-
}, wpStart);
137+
const candidates: Date[] = [
138+
...project.workPackages.map((wp) => wp.startDate),
139+
...project.tasks.map((t) => t.startDate).filter((d): d is Date => !!d)
140+
];
141+
if (candidates.length === 0) return project.startDate ?? new Date();
142+
return new Date(Math.min(...candidates.map((d) => d.valueOf())));
145143
};
146144

147145
export const getProjectEndDate = (project: ProjectGantt): Date => {
148-
const wpEnd = project.workPackages.reduce(
149-
(acc, current) => {
150-
if (current.endDate > acc) return current.endDate;
151-
return acc;
152-
},
153-
new Date(Date.now() + 1000 * 60 * 60 * 24 * 7 * 5)
154-
);
155-
return project.tasks.reduce((acc, current) => {
156-
if (current.deadline && current.deadline > acc) return current.deadline;
157-
return acc;
158-
}, wpEnd);
146+
const candidates: Date[] = [
147+
...project.workPackages.map((wp) => wp.endDate),
148+
...project.tasks.map((t) => t.deadline).filter((d): d is Date => !!d)
149+
];
150+
if (candidates.length === 0) return project.endDate ?? new Date();
151+
return new Date(Math.max(...candidates.map((d) => d.valueOf())));
159152
};
160153

161154
export const transformDesignReviewEventToGanttEvent = (event: EventPreview): GanttEvent => {

0 commit comments

Comments
 (0)