2020-08-23 22:33:25 +03:00
|
|
|
import React, { useState, SyntheticEvent } from "react";
|
2020-08-11 01:16:53 +03:00
|
|
|
import { ViewMode, GanttProps, Task } from "../../types/public-types";
|
2020-08-23 22:33:25 +03:00
|
|
|
import { GridProps } from "../grid/grid";
|
2020-08-05 08:14:22 +03:00
|
|
|
import { ganttDateRange, seedDates } from "../../helpers/date-helper";
|
2020-08-23 22:33:25 +03:00
|
|
|
import { CalendarProps } from "../calendar/calendar";
|
|
|
|
|
import { TaskGanttContentProps } from "./task-gantt-content";
|
|
|
|
|
import { TaskListHeaderDefault } from "../task-list/task-list-header";
|
|
|
|
|
import { TaskListTableDefault } from "../task-list/task-list-table";
|
|
|
|
|
import { StandardTooltipContent } from "../other/tooltip";
|
|
|
|
|
import { Scroll } from "../other/scroll";
|
|
|
|
|
import { TaskListProps, TaskList } from "../task-list/task-list";
|
|
|
|
|
import styles from "./gantt.module.css";
|
|
|
|
|
import { TaskGantt } from "./task-gantt";
|
2020-07-22 20:50:43 +03:00
|
|
|
|
|
|
|
|
export const Gantt: React.SFC<GanttProps> = ({
|
|
|
|
|
tasks,
|
|
|
|
|
headerHeight = 50,
|
|
|
|
|
columnWidth = 60,
|
2020-08-23 22:33:25 +03:00
|
|
|
listCellWidth = "150px",
|
2020-07-22 20:50:43 +03:00
|
|
|
rowHeight = 50,
|
2020-08-23 22:33:25 +03:00
|
|
|
ganttHeight = 0,
|
2020-07-22 20:50:43 +03:00
|
|
|
viewMode = ViewMode.Day,
|
2020-08-05 08:14:22 +03:00
|
|
|
locale = "en-GB",
|
2020-07-22 20:50:43 +03:00
|
|
|
barFill = 60,
|
|
|
|
|
barCornerRadius = 3,
|
2020-08-05 08:14:22 +03:00
|
|
|
barProgressColor = "#a3a3ff",
|
|
|
|
|
barProgressSelectedColor = "#8282f5",
|
|
|
|
|
barBackgroundColor = "#b8c2cc",
|
|
|
|
|
barBackgroundSelectedColor = "#aeb8c2",
|
2020-07-22 20:50:43 +03:00
|
|
|
handleWidth = 8,
|
|
|
|
|
timeStep = 300000,
|
2020-08-05 08:14:22 +03:00
|
|
|
arrowColor = "grey",
|
|
|
|
|
fontFamily = "Arial, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue",
|
|
|
|
|
fontSize = "14px",
|
2020-07-22 20:50:43 +03:00
|
|
|
arrowIndent = 20,
|
2020-08-05 08:14:22 +03:00
|
|
|
todayColor = "rgba(252, 248, 227, 0.5)",
|
2020-08-23 22:33:25 +03:00
|
|
|
TooltipContent = StandardTooltipContent,
|
|
|
|
|
TaskListHeader = TaskListHeaderDefault,
|
|
|
|
|
TaskListTable = TaskListTableDefault,
|
2020-07-22 20:50:43 +03:00
|
|
|
onDateChange,
|
|
|
|
|
onProgressChange,
|
|
|
|
|
onDoubleClick,
|
|
|
|
|
onTaskDelete,
|
|
|
|
|
}) => {
|
2020-08-11 01:16:53 +03:00
|
|
|
const [ganttTasks, setGanttTasks] = useState<Task[]>(tasks);
|
2020-08-23 22:33:25 +03:00
|
|
|
const [scroll, setScroll] = useState(0);
|
|
|
|
|
|
2020-08-11 01:16:53 +03:00
|
|
|
const [startDate, endDate] = ganttDateRange(ganttTasks, viewMode);
|
|
|
|
|
const dates = seedDates(startDate, endDate, viewMode);
|
|
|
|
|
|
2020-08-23 22:33:25 +03:00
|
|
|
const svgHeight = rowHeight * tasks.length;
|
|
|
|
|
const gridWidth = dates.length * columnWidth;
|
|
|
|
|
|
|
|
|
|
const onTasksDateChange = (tasks: Task[]) => {
|
2020-08-11 01:16:53 +03:00
|
|
|
setGanttTasks(tasks);
|
|
|
|
|
};
|
2020-07-22 20:50:43 +03:00
|
|
|
|
2020-08-23 22:33:25 +03:00
|
|
|
const handleScroll = (event: SyntheticEvent<HTMLDivElement>) => {
|
|
|
|
|
setScroll(event.currentTarget.scrollTop);
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-22 20:50:43 +03:00
|
|
|
const gridProps: GridProps = {
|
|
|
|
|
columnWidth,
|
2020-08-23 22:33:25 +03:00
|
|
|
gridWidth,
|
2020-08-11 01:16:53 +03:00
|
|
|
tasks: ganttTasks,
|
2020-07-22 20:50:43 +03:00
|
|
|
rowHeight,
|
|
|
|
|
dates,
|
2020-07-30 00:01:51 +03:00
|
|
|
todayColor,
|
2020-07-22 20:50:43 +03:00
|
|
|
};
|
|
|
|
|
const calendarProps: CalendarProps = {
|
|
|
|
|
dates,
|
|
|
|
|
locale,
|
|
|
|
|
viewMode,
|
|
|
|
|
headerHeight,
|
|
|
|
|
columnWidth,
|
|
|
|
|
fontFamily,
|
|
|
|
|
fontSize,
|
|
|
|
|
};
|
2020-08-23 22:33:25 +03:00
|
|
|
const barProps: TaskGanttContentProps = {
|
2020-08-11 01:16:53 +03:00
|
|
|
tasks: ganttTasks,
|
2020-07-22 20:50:43 +03:00
|
|
|
rowHeight,
|
|
|
|
|
barCornerRadius,
|
|
|
|
|
columnWidth,
|
|
|
|
|
dates,
|
|
|
|
|
barFill,
|
2020-07-30 00:01:51 +03:00
|
|
|
barProgressColor,
|
|
|
|
|
barProgressSelectedColor,
|
|
|
|
|
barBackgroundColor,
|
|
|
|
|
barBackgroundSelectedColor,
|
2020-07-22 20:50:43 +03:00
|
|
|
handleWidth,
|
|
|
|
|
arrowColor,
|
2020-08-11 01:16:53 +03:00
|
|
|
timeStep,
|
2020-07-22 20:50:43 +03:00
|
|
|
fontFamily,
|
|
|
|
|
fontSize,
|
|
|
|
|
arrowIndent,
|
2020-08-23 22:33:25 +03:00
|
|
|
svgHeight,
|
|
|
|
|
onTasksDateChange: onTasksDateChange,
|
2020-07-22 20:50:43 +03:00
|
|
|
onDateChange,
|
|
|
|
|
onProgressChange,
|
|
|
|
|
onDoubleClick,
|
|
|
|
|
onTaskDelete,
|
2020-08-23 22:33:25 +03:00
|
|
|
TooltipContent,
|
2020-07-22 20:50:43 +03:00
|
|
|
};
|
2020-08-23 22:33:25 +03:00
|
|
|
|
|
|
|
|
const tableProps: TaskListProps = {
|
|
|
|
|
rowHeight,
|
|
|
|
|
rowWidth: listCellWidth,
|
|
|
|
|
fontFamily,
|
|
|
|
|
fontSize,
|
|
|
|
|
tasks: ganttTasks,
|
|
|
|
|
locale,
|
|
|
|
|
headerHeight,
|
|
|
|
|
scroll,
|
|
|
|
|
ganttHeight,
|
|
|
|
|
horizontalContainerClass: styles.horizontalContainer,
|
|
|
|
|
TaskListHeader,
|
|
|
|
|
TaskListTable,
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-22 20:50:43 +03:00
|
|
|
return (
|
2020-08-23 22:33:25 +03:00
|
|
|
<div className={styles.wrapper}>
|
|
|
|
|
{listCellWidth && <TaskList {...tableProps} />}
|
|
|
|
|
<TaskGantt
|
|
|
|
|
gridProps={gridProps}
|
|
|
|
|
calendarProps={calendarProps}
|
|
|
|
|
barProps={barProps}
|
|
|
|
|
ganttHeight={ganttHeight}
|
|
|
|
|
scroll={scroll}
|
|
|
|
|
/>
|
|
|
|
|
<Scroll
|
|
|
|
|
ganttFullHeight={ganttTasks.length * rowHeight}
|
|
|
|
|
ganttHeight={ganttHeight}
|
|
|
|
|
headerHeight={headerHeight}
|
|
|
|
|
onScroll={handleScroll}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2020-07-22 20:50:43 +03:00
|
|
|
);
|
|
|
|
|
};
|