Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project date change option #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ npm start
| onProgressChange\* | (task: Task, children: Task[]) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar progress event has finished. |
| onExpanderClick\* | onExpanderClick: (task: Task) => void; | Specifies the function to be executed on the table expander click |
| timeStep | number | A time step value for onDateChange. Specify in milliseconds. |
| allowProjectDateChange | boolean | Allows change of project date

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

Expand Down
2 changes: 2 additions & 0 deletions src/components/gantt/gantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
onDelete,
onSelect,
onExpanderClick,
allowProjectDateChange,
}) => {
const wrapperRef = useRef<HTMLDivElement>(null);
const taskListRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -429,6 +430,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
onDoubleClick,
onClick,
onDelete,
allowProjectDateChange
};

const tableProps: TaskListProps = {
Expand Down
2 changes: 2 additions & 0 deletions src/components/gantt/task-gantt-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
onDoubleClick,
onClick,
onDelete,
allowProjectDateChange,
}) => {
const point = svg?.current?.createSVGPoint();
const [xStep, setXStep] = useState(0);
Expand Down Expand Up @@ -283,6 +284,7 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
{tasks.map(task => {
return (
<TaskItem
allowProjectDateChange={allowProjectDateChange}
task={task}
arrowIndent={arrowIndent}
taskHeight={taskHeight}
Expand Down
4 changes: 2 additions & 2 deletions src/components/task-item/project/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { TaskItemProps } from "../task-item";
import styles from "./project.module.css";

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

return (
<g tabIndex={0} className={styles.projectWrapper}>
<g onMouseDown={onMouseDown} tabIndex={0} className={styles.projectWrapper}>
<rect
fill={barColor}
x={task.x1}
Expand Down
8 changes: 7 additions & 1 deletion src/components/task-item/task-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export type TaskItemProps = {
isDelete: boolean;
isSelected: boolean;
rtl: boolean;
allowProjectDateChange?: boolean;
onEventStart: (
action: GanttContentMoveAction,
selectedTask: BarTask,
event?: React.MouseEvent | React.KeyboardEvent
) => any;
onMouseDown?: (event: React.MouseEvent<SVGPolygonElement, MouseEvent>) => void;
};

export const TaskItem: React.FC<TaskItemProps> = props => {
Expand All @@ -30,7 +32,9 @@ export const TaskItem: React.FC<TaskItemProps> = props => {
isDelete,
taskHeight,
isSelected,
isDateChangeable,
rtl,
allowProjectDateChange,
onEventStart,
} = {
...props,
Expand All @@ -45,7 +49,9 @@ export const TaskItem: React.FC<TaskItemProps> = props => {
setTaskItem(<Milestone {...props} />);
break;
case "project":
setTaskItem(<Project {...props} />);
setTaskItem(<Project onMouseDown={e =>
isDateChangeable && allowProjectDateChange && onEventStart("move", task, e)
} {...props} />);
break;
case "smalltask":
setTaskItem(<BarSmall {...props} />);
Expand Down
4 changes: 4 additions & 0 deletions src/types/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export interface EventOption {
* Invokes on expander on task list
*/
onExpanderClick?: (task: Task) => void;
/**
* Allow project date change
*/
allowProjectDateChange?: boolean;
}

export interface DisplayOption {
Expand Down