Skip to content

Commit 839cd4e

Browse files
authored
Merge pull request #4222 from Northeastern-Electric-Racing/4210-projects-page-gantt-chart
4210-projects-page-gantt-chart replace react-google-charts with internal GanttChart in project detail Gantt tab
2 parents 55dc5f6 + 78a7266 commit 839cd4e

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/ProjectGantt.tsx

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,38 @@
33
* See the LICENSE file in the repository root folder for details.
44
*/
55

6-
import Chart from 'react-google-charts';
76
import { WorkPackage } from 'shared';
87
import { Box } from '@mui/material';
9-
10-
export const ganttAllColumns = [
11-
{ type: 'string', label: 'Task ID' },
12-
{ type: 'string', label: 'Task Name' },
13-
{ type: 'date', label: 'Start Date' },
14-
{ type: 'date', label: 'End Date' },
15-
{ type: 'number', label: 'Duration' },
16-
{ type: 'number', label: 'Percent Complete' },
17-
{ type: 'string', label: 'Dependencies' }
18-
];
8+
import { add, sub } from 'date-fns';
9+
import GanttChart from '../../GanttPage/GanttChart/GanttChart';
10+
import { GanttCollection, transformWorkPackageToGanttTask } from '../../../utils/gantt.utils';
1911

2012
interface ProjectGanttProps {
2113
workPackages: WorkPackage[];
2214
}
2315

2416
const ProjectGantt: React.FC<ProjectGanttProps> = ({ workPackages }) => {
25-
const rows = workPackages.map((wp) => [wp.id, wp.name, wp.startDate, wp.endDate, wp.duration, 100, null]);
26-
const data = [ganttAllColumns, ...rows];
27-
const options = {
28-
height: 30 * rows.length + 50,
29-
gantt: {
30-
trackHeight: 30,
31-
barHeight: 20,
32-
labelStyle: {
33-
fontName: 'Oswald',
34-
fontSize: 14
35-
}
36-
}
17+
if (workPackages.length === 0) return <Box sx={{ my: 2 }} />;
18+
19+
const startDate = sub(
20+
workPackages.map((wp) => wp.startDate).reduce((prev, curr) => (prev < curr ? prev : curr), new Date(8.64e15)),
21+
{ weeks: 2 }
22+
);
23+
const endDate = add(
24+
workPackages.map((wp) => wp.endDate).reduce((prev, curr) => (prev > curr ? prev : curr), new Date(-8.64e15)),
25+
{ months: 6 }
26+
);
27+
28+
const collection: GanttCollection<string, WorkPackage> = {
29+
id: 'project-gantt',
30+
element: 'Work Packages',
31+
title: 'Work Packages',
32+
tasks: workPackages.map((wp) => transformWorkPackageToGanttTask(wp, workPackages))
3733
};
34+
3835
return (
3936
<Box sx={{ my: 2 }}>
40-
{workPackages.length > 0 ? <Chart chartType="Gantt" width="100%" height="100%" data={data} options={options} /> : ''}
37+
<GanttChart collections={[collection]} startDate={startDate} endDate={endDate} />
4138
</Box>
4239
);
4340
};

0 commit comments

Comments
 (0)