Skip to content

Commit 1c9b1fc

Browse files
Merge pull request #5 from AquilesOliveiraDev/feature/allow-project-date-change
Add project date change option
2 parents 253590a + 67cedd6 commit 1c9b1fc

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ npm start
7979
| onProgressChange\* | (task: Task, children: Task[]) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar progress event has finished. |
8080
| onExpanderClick\* | onExpanderClick: (task: Task) => void; | Specifies the function to be executed on the table expander click |
8181
| timeStep | number | A time step value for onDateChange. Specify in milliseconds. |
82+
| allowProjectDateChange | boolean | Allows change of project date
8283

8384
\* Chart undoes operation if method return false or error. Parameter children returns one level deep records.
8485

src/components/gantt/gantt.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
7070
onDelete,
7171
onSelect,
7272
onExpanderClick,
73+
allowProjectDateChange,
7374
}) => {
7475
const wrapperRef = useRef<HTMLDivElement>(null);
7576
const taskListRef = useRef<HTMLDivElement>(null);
@@ -436,6 +437,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
436437
onClick,
437438
onClickLine,
438439
onDelete,
440+
allowProjectDateChange
439441
};
440442

441443
const tableProps: TaskListProps = {

src/components/gantt/task-gantt-content.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
5656
onClick,
5757
onClickLine,
5858
onDelete,
59+
allowProjectDateChange,
5960
}) => {
6061
const point = svg?.current?.createSVGPoint();
6162
const [xStep, setXStep] = useState(0);
@@ -285,6 +286,7 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
285286
{tasks.map(task => {
286287
return (
287288
<TaskItem
289+
allowProjectDateChange={allowProjectDateChange}
288290
task={task}
289291
arrowIndent={arrowIndent}
290292
taskHeight={taskHeight}

src/components/task-item/project/project.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { TaskItemProps } from "../task-item";
33
import styles from "./project.module.css";
44

5-
export const Project: React.FC<TaskItemProps> = ({ task, isSelected }) => {
5+
export const Project: React.FC<TaskItemProps> = ({ task, isSelected, onMouseDown }) => {
66
const barColor = isSelected
77
? task.styles.backgroundSelectedColor
88
: task.styles.backgroundColor;
@@ -29,7 +29,7 @@ export const Project: React.FC<TaskItemProps> = ({ task, isSelected }) => {
2929
].join(",");
3030

3131
return (
32-
<g tabIndex={0} className={styles.projectWrapper}>
32+
<g onMouseDown={onMouseDown} tabIndex={0} className={styles.projectWrapper}>
3333
<rect
3434
fill={barColor}
3535
x={task.x1}

src/components/task-item/task-item.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export type TaskItemProps = {
1616
isDelete: boolean;
1717
isSelected: boolean;
1818
rtl: boolean;
19+
allowProjectDateChange?: boolean;
1920
onEventStart: (
2021
action: GanttContentMoveAction,
2122
selectedTask: BarTask,
2223
event?: React.MouseEvent | React.KeyboardEvent
2324
) => any;
25+
onMouseDown?: (event: React.MouseEvent<SVGPolygonElement, MouseEvent>) => void;
2426
};
2527

2628
export const TaskItem: React.FC<TaskItemProps> = props => {
@@ -30,7 +32,9 @@ export const TaskItem: React.FC<TaskItemProps> = props => {
3032
isDelete,
3133
taskHeight,
3234
isSelected,
35+
isDateChangeable,
3336
rtl,
37+
allowProjectDateChange,
3438
onEventStart,
3539
} = {
3640
...props,
@@ -45,7 +49,9 @@ export const TaskItem: React.FC<TaskItemProps> = props => {
4549
setTaskItem(<Milestone {...props} />);
4650
break;
4751
case "project":
48-
setTaskItem(<Project {...props} />);
52+
setTaskItem(<Project onMouseDown={e =>
53+
isDateChangeable && allowProjectDateChange && onEventStart("move", task, e)
54+
} {...props} />);
4955
break;
5056
case "smalltask":
5157
setTaskItem(<BarSmall {...props} />);

src/types/public-types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export interface EventOption {
8383
* Invokes on expander on task list
8484
*/
8585
onExpanderClick?: (task: Task) => void;
86+
/**
87+
* Allow project date change
88+
*/
89+
allowProjectDateChange?: boolean;
8690
}
8791

8892
export interface DisplayOption {

0 commit comments

Comments
 (0)