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-24 23:47:22 +03:00
|
|
|
const [scrollY, setScrollY] = useState(0);
|
2020-08-23 22:33:25 +03:00
|
|
|
|
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;
|
2020-08-24 23:47:22 +03:00
|
|
|
const ganttFullHeight = ganttTasks.length * rowHeight;
|
2020-08-23 22:33:25 +03:00
|
|
|
|
|
|
|
|
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>) => {
|
2020-08-24 23:47:22 +03:00
|
|
|
setScrollY(event.currentTarget.scrollTop);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleWheel = (event: React.WheelEvent<HTMLDivElement>) => {
|
|
|
|
|
const newScrollY = scrollY + event.deltaY;
|
|
|
|
|
if (newScrollY < 0) {
|
|
|
|
|
setScrollY(0);
|
|
|
|
|
} else if (newScrollY > ganttFullHeight - ganttHeight) {
|
|
|
|
|
setScrollY(ganttFullHeight - ganttHeight);
|
|
|
|
|
} else {
|
|
|
|
|
setScrollY(scrollY + event.deltaY);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
|
|
|
let newScrollY = 0;
|
|
|
|
|
let isX = true;
|
|
|
|
|
switch (event.key) {
|
|
|
|
|
case "Down": // IE/Edge specific value
|
|
|
|
|
case "ArrowDown":
|
|
|
|
|
newScrollY = scrollY + rowHeight;
|
|
|
|
|
isX = false;
|
|
|
|
|
break;
|
|
|
|
|
case "Up": // IE/Edge specific value
|
|
|
|
|
case "ArrowUp":
|
|
|
|
|
newScrollY = scrollY - rowHeight;
|
|
|
|
|
isX = false;
|
|
|
|
|
break;
|
|
|
|
|
case "ArrowLeft":
|
|
|
|
|
// Do something for "left arrow" key press.
|
|
|
|
|
break;
|
|
|
|
|
case "Right": // IE/Edge specific value
|
|
|
|
|
case "ArrowRight":
|
|
|
|
|
// Do something for "right arrow" key press.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (isX) {
|
|
|
|
|
} else {
|
|
|
|
|
if (newScrollY < 0) {
|
|
|
|
|
setScrollY(0);
|
|
|
|
|
} else if (newScrollY > ganttFullHeight - ganttHeight) {
|
|
|
|
|
setScrollY(ganttFullHeight - ganttHeight);
|
|
|
|
|
} else {
|
|
|
|
|
setScrollY(newScrollY);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-23 22:33:25 +03:00
|
|
|
};
|
|
|
|
|
|
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,
|
2020-08-24 23:47:22 +03:00
|
|
|
scrollY,
|
2020-08-23 22:33:25 +03:00
|
|
|
ganttHeight,
|
|
|
|
|
horizontalContainerClass: styles.horizontalContainer,
|
|
|
|
|
TaskListHeader,
|
|
|
|
|
TaskListTable,
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-22 20:50:43 +03:00
|
|
|
return (
|
2020-08-24 23:47:22 +03:00
|
|
|
<div
|
|
|
|
|
className={styles.wrapper}
|
|
|
|
|
onWheel={handleWheel}
|
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
tabIndex={0}
|
|
|
|
|
>
|
2020-08-23 22:33:25 +03:00
|
|
|
{listCellWidth && <TaskList {...tableProps} />}
|
|
|
|
|
<TaskGantt
|
|
|
|
|
gridProps={gridProps}
|
|
|
|
|
calendarProps={calendarProps}
|
|
|
|
|
barProps={barProps}
|
|
|
|
|
ganttHeight={ganttHeight}
|
2020-08-24 23:47:22 +03:00
|
|
|
scrollY={scrollY}
|
2020-08-23 22:33:25 +03:00
|
|
|
/>
|
|
|
|
|
<Scroll
|
2020-08-24 23:47:22 +03:00
|
|
|
ganttFullHeight={ganttFullHeight}
|
2020-08-23 22:33:25 +03:00
|
|
|
ganttHeight={ganttHeight}
|
|
|
|
|
headerHeight={headerHeight}
|
2020-08-24 23:47:22 +03:00
|
|
|
scroll={scrollY}
|
2020-08-23 22:33:25 +03:00
|
|
|
onScroll={handleScroll}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2020-07-22 20:50:43 +03:00
|
|
|
);
|
|
|
|
|
};
|