|
3 | 3 | * See the LICENSE file in the repository root folder for details. |
4 | 4 | */ |
5 | 5 |
|
6 | | -import Chart from 'react-google-charts'; |
7 | 6 | import { WorkPackage } from 'shared'; |
8 | 7 | 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'; |
19 | 11 |
|
20 | 12 | interface ProjectGanttProps { |
21 | 13 | workPackages: WorkPackage[]; |
22 | 14 | } |
23 | 15 |
|
24 | 16 | 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)) |
37 | 33 | }; |
| 34 | + |
38 | 35 | return ( |
39 | 36 | <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} /> |
41 | 38 | </Box> |
42 | 39 | ); |
43 | 40 | }; |
|
0 commit comments