Merge pull request #17 from MaTeMaTuK/dev
grouping works for project only
This commit is contained in:
commit
898487c81f
20
README.md
20
README.md
@ -68,16 +68,16 @@ npm start
|
|||||||
|
|
||||||
### EventOption
|
### EventOption
|
||||||
|
|
||||||
| Parameter Name | Type | Description |
|
| Parameter Name | Type | Description |
|
||||||
| :----------------- | :---------------------------------------------------------- | :-------------------------------------------------------------------------------------- |
|
| :----------------- | :---------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------- |
|
||||||
| onSelect | (task: Task, isSelected: boolean) => void | Specifies the function to be executed on the taskbar select or unselect event. |
|
| onSelect | (task: Task, isSelected: boolean) => void | Specifies the function to be executed on the taskbar select or unselect event. |
|
||||||
| onDoubleClick | (task: Task) => void | Specifies the function to be executed on the taskbar onDoubleClick event. |
|
| onDoubleClick | (task: Task) => void | Specifies the function to be executed on the taskbar onDoubleClick event. |
|
||||||
| onDelete\* | (task: Task) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed on the taskbar on Delete button press event. |
|
| onDelete\* | (task: Task) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed on the taskbar on Delete button press event. |
|
||||||
| onDateChange\* | (task: Task) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar event on timeline has finished. |
|
| onDateChange\* | (task: Task, children: Task[]) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar event on timeline has finished. |
|
||||||
| onProgressChange\* | (task: Task) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar progress event has finished. |
|
| onProgressChange\* | (task: Task, children: Task[]) => void/boolean/Promise<void>/Promise<boolean> | Specifies the function to be executed when drag taskbar progress event has finished. |
|
||||||
| timeStep | (task: Task) => number | A time step value for onDateChange. Specify in milliseconds. |
|
| timeStep | (task: Task) => number | A time step value for onDateChange. Specify in milliseconds. |
|
||||||
|
|
||||||
\* Chart undoes operation if method return false or error.
|
\* Chart undoes operation if method return false or error. Parameter children returns one level deep records.
|
||||||
|
|
||||||
### DisplayOption
|
### DisplayOption
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ npm start
|
|||||||
| isDisabled | bool | Disables all action for current task. |
|
| isDisabled | bool | Disables all action for current task. |
|
||||||
| fontSize | string | Specifies the taskbar font size locally. |
|
| fontSize | string | Specifies the taskbar font size locally. |
|
||||||
| project | string | Task project name |
|
| project | string | Task project name |
|
||||||
| hideChildren | bool | Hide children items. |
|
| hideChildren | bool | Hide children items. Parameter works with project type only |
|
||||||
|
|
||||||
\*Required
|
\*Required
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,8 @@ export function initTasks() {
|
|||||||
id: "ProjectSample",
|
id: "ProjectSample",
|
||||||
progress: 25,
|
progress: 25,
|
||||||
type: "project",
|
type: "project",
|
||||||
|
|
||||||
|
hideChildren: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 1),
|
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 1),
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gantt-task-react",
|
"name": "gantt-task-react",
|
||||||
"version": "0.3.4",
|
"version": "0.3.5",
|
||||||
"description": "Interactive Gantt Chart for React with TypeScript.",
|
"description": "Interactive Gantt Chart for React with TypeScript.",
|
||||||
"author": "MaTeMaTuK <maksym.vikarii@gmail.com>",
|
"author": "MaTeMaTuK <maksym.vikarii@gmail.com>",
|
||||||
"homepage": "https://github.com/MaTeMaTuK/gantt-task-react",
|
"homepage": "https://github.com/MaTeMaTuK/gantt-task-react",
|
||||||
|
|||||||
@ -85,7 +85,12 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
|
|||||||
|
|
||||||
// task change events
|
// task change events
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const filteredTasks = removeHiddenTasks(tasks);
|
let filteredTasks: Task[];
|
||||||
|
if (onExpanderClick) {
|
||||||
|
filteredTasks = removeHiddenTasks(tasks);
|
||||||
|
} else {
|
||||||
|
filteredTasks = tasks;
|
||||||
|
}
|
||||||
const [startDate, endDate] = ganttDateRange(filteredTasks, viewMode);
|
const [startDate, endDate] = ganttDateRange(filteredTasks, viewMode);
|
||||||
let newDates = seedDates(startDate, endDate, viewMode);
|
let newDates = seedDates(startDate, endDate, viewMode);
|
||||||
if (rtl) {
|
if (rtl) {
|
||||||
@ -137,6 +142,7 @@ export const Gantt: React.FunctionComponent<GanttProps> = ({
|
|||||||
milestoneBackgroundSelectedColor,
|
milestoneBackgroundSelectedColor,
|
||||||
rtl,
|
rtl,
|
||||||
scrollX,
|
scrollX,
|
||||||
|
onExpanderClick,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -134,7 +134,10 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
|
|||||||
isNotLikeOriginal
|
isNotLikeOriginal
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const result = await onDateChange(newChangedTask);
|
const result = await onDateChange(
|
||||||
|
newChangedTask,
|
||||||
|
newChangedTask.barChildren
|
||||||
|
);
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
operationSuccess = result;
|
operationSuccess = result;
|
||||||
}
|
}
|
||||||
@ -143,7 +146,10 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
|
|||||||
}
|
}
|
||||||
} else if (onProgressChange && isNotLikeOriginal) {
|
} else if (onProgressChange && isNotLikeOriginal) {
|
||||||
try {
|
try {
|
||||||
const result = await onProgressChange(newChangedTask);
|
const result = await onProgressChange(
|
||||||
|
newChangedTask,
|
||||||
|
newChangedTask.barChildren
|
||||||
|
);
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
operationSuccess = result;
|
operationSuccess = result;
|
||||||
}
|
}
|
||||||
@ -254,9 +260,9 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
|
|||||||
return task.barChildren.map(child => {
|
return task.barChildren.map(child => {
|
||||||
return (
|
return (
|
||||||
<Arrow
|
<Arrow
|
||||||
key={`Arrow from ${task.id} to ${tasks[child].id}`}
|
key={`Arrow from ${task.id} to ${tasks[child.index].id}`}
|
||||||
taskFrom={task}
|
taskFrom={task}
|
||||||
taskTo={tasks[child]}
|
taskTo={tasks[child.index]}
|
||||||
rowHeight={rowHeight}
|
rowHeight={rowHeight}
|
||||||
taskHeight={taskHeight}
|
taskHeight={taskHeight}
|
||||||
arrowIndent={arrowIndent}
|
arrowIndent={arrowIndent}
|
||||||
|
|||||||
@ -53,26 +53,13 @@ export const convertToBarTasks = (
|
|||||||
});
|
});
|
||||||
|
|
||||||
// set dependencies
|
// set dependencies
|
||||||
barTasks = barTasks.map((task, i) => {
|
barTasks = barTasks.map(task => {
|
||||||
const dependencies = task.dependencies || [];
|
const dependencies = task.dependencies || [];
|
||||||
for (let j = 0; j < dependencies.length; j++) {
|
for (let j = 0; j < dependencies.length; j++) {
|
||||||
const dependence = barTasks.findIndex(
|
const dependence = barTasks.findIndex(
|
||||||
value => value.id === dependencies[j]
|
value => value.id === dependencies[j]
|
||||||
);
|
);
|
||||||
if (dependence !== -1) barTasks[dependence].barChildren.push(i);
|
if (dependence !== -1) barTasks[dependence].barChildren.push(task);
|
||||||
}
|
|
||||||
return task;
|
|
||||||
});
|
|
||||||
// normalize flags for hideChildren
|
|
||||||
barTasks = barTasks.map(task => {
|
|
||||||
if (task.barChildren.length > 0) {
|
|
||||||
if (!task.hideChildren) {
|
|
||||||
task.hideChildren = false;
|
|
||||||
}
|
|
||||||
} else if (!task.hideChildren && task.type === "project") {
|
|
||||||
task.hideChildren = false;
|
|
||||||
} else if (!task.hideChildren) {
|
|
||||||
task.hideChildren = undefined;
|
|
||||||
}
|
}
|
||||||
return task;
|
return task;
|
||||||
});
|
});
|
||||||
@ -197,6 +184,7 @@ const convertToBar = (
|
|||||||
rtl
|
rtl
|
||||||
);
|
);
|
||||||
const y = taskYCoordinate(index, rowHeight, taskHeight);
|
const y = taskYCoordinate(index, rowHeight, taskHeight);
|
||||||
|
const hideChildren = task.type === "project" ? task.hideChildren : undefined;
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
backgroundColor: barBackgroundColor,
|
backgroundColor: barBackgroundColor,
|
||||||
@ -216,6 +204,7 @@ const convertToBar = (
|
|||||||
progressWidth,
|
progressWidth,
|
||||||
barCornerRadius,
|
barCornerRadius,
|
||||||
handleWidth,
|
handleWidth,
|
||||||
|
hideChildren,
|
||||||
height: taskHeight,
|
height: taskHeight,
|
||||||
barChildren: [],
|
barChildren: [],
|
||||||
styles,
|
styles,
|
||||||
@ -263,6 +252,7 @@ const convertToMilestone = (
|
|||||||
typeInternal: task.type,
|
typeInternal: task.type,
|
||||||
progress: 0,
|
progress: 0,
|
||||||
height: rotatedHeight,
|
height: rotatedHeight,
|
||||||
|
hideChildren: undefined,
|
||||||
barChildren: [],
|
barChildren: [],
|
||||||
styles,
|
styles,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -18,7 +18,9 @@ export function isBarTask(task: Task | BarTask): task is BarTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function removeHiddenTasks(tasks: Task[]) {
|
export function removeHiddenTasks(tasks: Task[]) {
|
||||||
const groupedTasks = tasks.filter(t => t.hideChildren);
|
const groupedTasks = tasks.filter(
|
||||||
|
t => t.hideChildren && t.type === "project"
|
||||||
|
);
|
||||||
if (groupedTasks.length > 0) {
|
if (groupedTasks.length > 0) {
|
||||||
for (let i = 0; groupedTasks.length > i; i++) {
|
for (let i = 0; groupedTasks.length > i; i++) {
|
||||||
const groupedTask = groupedTasks[i];
|
const groupedTask = groupedTasks[i];
|
||||||
|
|||||||
@ -11,7 +11,7 @@ export interface BarTask extends Task {
|
|||||||
progressWidth: number;
|
progressWidth: number;
|
||||||
barCornerRadius: number;
|
barCornerRadius: number;
|
||||||
handleWidth: number;
|
handleWidth: number;
|
||||||
barChildren: number[];
|
barChildren: BarTask[];
|
||||||
styles: {
|
styles: {
|
||||||
backgroundColor: string;
|
backgroundColor: string;
|
||||||
backgroundSelectedColor: string;
|
backgroundSelectedColor: string;
|
||||||
|
|||||||
@ -46,13 +46,15 @@ export interface EventOption {
|
|||||||
* Invokes on end and start time change. Chart undoes operation if method return false or error.
|
* Invokes on end and start time change. Chart undoes operation if method return false or error.
|
||||||
*/
|
*/
|
||||||
onDateChange?: (
|
onDateChange?: (
|
||||||
task: Task
|
task: Task,
|
||||||
|
children: Task[]
|
||||||
) => void | boolean | Promise<void> | Promise<boolean>;
|
) => void | boolean | Promise<void> | Promise<boolean>;
|
||||||
/**
|
/**
|
||||||
* Invokes on progress change. Chart undoes operation if method return false or error.
|
* Invokes on progress change. Chart undoes operation if method return false or error.
|
||||||
*/
|
*/
|
||||||
onProgressChange?: (
|
onProgressChange?: (
|
||||||
task: Task
|
task: Task,
|
||||||
|
children: Task[]
|
||||||
) => void | boolean | Promise<void> | Promise<boolean>;
|
) => void | boolean | Promise<void> | Promise<boolean>;
|
||||||
/**
|
/**
|
||||||
* Invokes on delete selected task. Chart undoes operation if method return false or error.
|
* Invokes on delete selected task. Chart undoes operation if method return false or error.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user