Skip to content

Commit

Permalink
Support authorized relation kinds for dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
  • Loading branch information
lfasani committed Mar 27, 2024
1 parent 8f5960c commit fdbccb3
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 100 deletions.
7 changes: 7 additions & 0 deletions src/components/gantt/gantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ export const Gantt: React.FC<GanttProps> = ({
TaskListTable = TaskListTableDefault,
TooltipContent = StandardTooltipContent,
ContextualPalette,
authorizedRelations = [
"startToStart",
"startToEnd",
"endToStart",
"endToEnd",
],
canMoveTasks = true,
canResizeColumns = true,
checkIsHoliday: checkIsHolidayProp = defaultCheckIsHoliday,
Expand Down Expand Up @@ -1799,6 +1805,7 @@ export const Gantt: React.FC<GanttProps> = ({

const barProps: TaskGanttContentProps = useMemo(
() => ({
authorizedRelations,
additionalLeftSpace,
additionalRightSpace,
checkIsHoliday,
Expand Down
9 changes: 6 additions & 3 deletions src/components/gantt/task-gantt-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Distances,
FixPosition,
GlobalRowIndexToTaskMap,
RelationKind,
Task,
TaskContextualPaletteProps,
TaskCoordinates,
Expand All @@ -30,6 +31,7 @@ import { checkTaskHasDependencyWarning } from "../../helpers/check-task-has-depe
import type { OptimizedListParams } from "../../helpers/use-optimized-list";

export type TaskGanttContentProps = {
authorizedRelations: RelationKind[];
additionalLeftSpace: number;
additionalRightSpace: number;
checkIsHoliday: (date: Date) => boolean;
Expand Down Expand Up @@ -80,6 +82,7 @@ export type TaskGanttContentProps = {
};

export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
authorizedRelations,
additionalLeftSpace,
additionalRightSpace,
checkIsHoliday,
Expand Down Expand Up @@ -122,8 +125,6 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
taskHalfHeight,
visibleTasksMirror,
}) => {
const isRelationDrawMode = Boolean(ganttRelationEvent);

const renderedHolidays = useMemo(() => {
const { holidayBackgroundColor } = colorStyles;
const { columnWidth } = distances;
Expand Down Expand Up @@ -266,10 +267,11 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
distances={distances}
taskHeight={taskHeight}
taskHalfHeight={taskHalfHeight}
isRelationDrawMode={isRelationDrawMode}
isProgressChangeable={!task.isDisabled}
isDateChangeable={!task.isDisabled}
isRelationChangeable={!task.isDisabled}
authorizedRelations={authorizedRelations}
ganttRelationEvent={ganttRelationEvent}
isDelete={!task.isDisabled}
onDoubleClick={onDoubleClick}
onClick={onClick}
Expand Down Expand Up @@ -468,6 +470,7 @@ export const TaskGanttContent: React.FC<TaskGanttContentProps> = ({
dependencyMap,
dependentMap,
fullRowHeight,
ganttRelationEvent,
getTaskCoordinates,
mapGlobalRowIndexToTask,
renderedRowIndexes,
Expand Down
2 changes: 1 addition & 1 deletion src/components/gantt/use-tablelist-resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const useTableListResize = (
setColumns([...columnsProp]);
setTableWidth(columnsProp.reduce((res, { width }) => res + width, 0));
}
}, [columnsProp]);
}, []);

const [tableResizeEvent, setTableResizeEvent] =
useState<TableResizeEvent | null>(null);
Expand Down
1 change: 1 addition & 0 deletions src/components/other/arrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const ArrowInner: React.FC<ArrowProps> = ({
return (
<g className={fixPositionContainerClass} fill={color} stroke={color}>
<g
data-testid={`task-arrow-${targetFrom}-${taskFrom.name}-${targetTo}-${taskTo.name}`}
className={`"arrow" ${styles.arrow_clickable}`}
onDoubleClick={onDoubleClick}
>
Expand Down
1 change: 0 additions & 1 deletion src/components/task-item/bar/bar-relation-handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const BarRelationHandleInner: React.FC<BarRelationHandleProps> = ({
}`}
onMouseDown={startDrawRelation}
onTouchStart={startDrawRelation}
data-draw-mode={isRelationDrawMode}
/>
);
};
Expand Down
37 changes: 3 additions & 34 deletions src/components/task-item/bar/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { useCallback } from "react";
import { getProgressPoint } from "../../../helpers/bar-helper";
import { BarDisplay } from "./bar-display";
import { BarDateHandle } from "./bar-date-handle";
import { BarRelationHandle } from "./bar-relation-handle";
import { BarProgressHandle } from "./bar-progress-handle";
import type { TaskItemProps } from "../task-item";
import type { BarMoveAction } from "../../../types/gantt-task-actions";
Expand All @@ -19,23 +18,15 @@ export const Bar: React.FC<
onTaskEventStart: (action: BarMoveAction, clientX: number) => void;
}
> = ({
children: relationhandles,
colorStyles,

distances: {
barCornerRadius,
handleWidth,
relationCircleOffset,
relationCircleRadius,
},
distances: { barCornerRadius, handleWidth },
hasChildren,
isCritical,
isDateChangeable,
isProgressChangeable,
isRelationChangeable,
isRelationDrawMode,
isSelected,
onLeftRelationTriggerMouseDown,
onRightRelationTriggerMouseDown,
onTaskEventStart,
progressWidth,
progressX,
Expand Down Expand Up @@ -157,29 +148,7 @@ export const Bar: React.FC<
/>
)}

{/* left */}
{isRelationChangeable && (
<BarRelationHandle
dataTestid={`task-relation-handle-left-${task.name}`}
isRelationDrawMode={isRelationDrawMode}
radius={relationCircleRadius}
startDrawRelation={onLeftRelationTriggerMouseDown}
x={x1 - relationCircleOffset}
y={taskYOffset + taskHalfHeight}
/>
)}

{/* right */}
{isRelationChangeable && (
<BarRelationHandle
dataTestid={`task-relation-handle-right-${task.name}`}
isRelationDrawMode={isRelationDrawMode}
radius={relationCircleRadius}
startDrawRelation={onRightRelationTriggerMouseDown}
x={x2 + relationCircleOffset}
y={taskYOffset + taskHalfHeight}
/>
)}
{relationhandles}

{isProgressChangeable && (
<BarProgressHandle
Expand Down
35 changes: 3 additions & 32 deletions src/components/task-item/milestone/milestone.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useMemo } from "react";

import { BarRelationHandle } from "../bar/bar-relation-handle";
import stylesRelationHandle from "../bar/bar-relation-handle.module.css";

import type { TaskItemProps } from "../task-item";
Expand All @@ -15,21 +14,16 @@ export const Milestone: React.FC<
onTaskEventStart: (action: BarMoveAction, clientX: number) => void;
}
> = ({
children: relationhandles,
task,
taskYOffset,
distances: { barCornerRadius, relationCircleOffset, relationCircleRadius },
distances: { barCornerRadius },
taskHeight,
taskHalfHeight,
isRelationChangeable,
isRelationDrawMode,
onLeftRelationTriggerMouseDown,
onRightRelationTriggerMouseDown,
onTaskEventStart,
isSelected,
isCritical,
colorStyles,
x1,
x2,
}) => {
const rotatedHeight = taskHeight / 1.414;

Expand Down Expand Up @@ -80,30 +74,7 @@ export const Milestone: React.FC<
}}
/>

<g className="handleGroup">
{isRelationChangeable && (
<g>
{/* left */}
<BarRelationHandle
dataTestid={`task-relation-handle-left-${task.name}`}
isRelationDrawMode={isRelationDrawMode}
x={x1 - relationCircleOffset}
y={taskYOffset + taskHalfHeight}
radius={relationCircleRadius}
startDrawRelation={onLeftRelationTriggerMouseDown}
/>
{/* right */}
<BarRelationHandle
dataTestid={`task-relation-handle-right-${task.name}`}
isRelationDrawMode={isRelationDrawMode}
x={x2 + relationCircleOffset}
y={taskYOffset + taskHalfHeight}
radius={relationCircleRadius}
startDrawRelation={onRightRelationTriggerMouseDown}
/>
</g>
)}
</g>
{relationhandles}
</g>
);
};
92 changes: 85 additions & 7 deletions src/components/task-item/task-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { MouseEvent, MouseEventHandler } from "react";

import {
BarMoveAction,
GanttRelationEvent,
RelationMoveTarget,
} from "../../types/gantt-task-actions";
import {
Expand All @@ -19,13 +20,15 @@ import {
ColorStyles,
TaskOrEmpty,
Distances,
RelationKind,
} from "../../types/public-types";
import { Bar } from "./bar/bar";
import { BarSmall } from "./bar/bar-small";
import { Milestone } from "./milestone/milestone";
import { TaskWarning } from "./task-warning";
import style from "./task-list.module.css";
import { BarFixWidth, fixWidthContainerClass } from "../other/bar-fix-width";
import { BarRelationHandle } from "./bar/bar-relation-handle";

export type TaskItemProps = {
getTaskGlobalIndexByRef: (task: Task) => number;
Expand All @@ -45,11 +48,12 @@ export type TaskItemProps = {
taskHalfHeight: number;
isProgressChangeable: boolean;
isDateChangeable: boolean;
authorizedRelations: RelationKind[];
isRelationChangeable: boolean;
ganttRelationEvent: GanttRelationEvent;
isDelete: boolean;
isSelected: boolean;
isCritical: boolean;
isRelationDrawMode: boolean;
rtl: boolean;
onDoubleClick?: (task: Task) => void;
onClick?: (task: Task, event: React.MouseEvent<SVGElement>) => void;
Expand All @@ -72,21 +76,28 @@ const TaskItemInner: React.FC<TaskItemProps> = props => {
childOutOfParentWarnings,
colorStyles: stylesProp,

distances: { arrowIndent, handleWidth, taskWarningOffset },

distances: {
arrowIndent,
handleWidth,
taskWarningOffset,
relationCircleOffset,
relationCircleRadius,
},
fixEndPosition = undefined,
fixStartPosition = undefined,
getTaskGlobalIndexByRef,
handleDeleteTasks,
hasDependencyWarning,
isDateChangeable,
isDelete,
isRelationDrawMode,
isSelected,
onClick = undefined,
onDoubleClick = undefined,
onEventStart,
onRelationStart,
authorizedRelations,
isRelationChangeable,
ganttRelationEvent,
rtl,
selectTaskOnMouseDown,
setTooltipTask,
Expand Down Expand Up @@ -205,6 +216,70 @@ const TaskItemInner: React.FC<TaskItemProps> = props => {
const [isTextInside, setIsTextInside] = useState(true);

const taskItem = useMemo(() => {
const isFromStartRelationAuthorized =
authorizedRelations.includes("startToStart") ||
authorizedRelations.includes("startToEnd");
const isFromEndRelationAuthorized =
authorizedRelations.includes("endToEnd") ||
authorizedRelations.includes("endToStart");
const isToStartRelationAuthorized =
(ganttRelationEvent?.target === "startOfTask" &&
authorizedRelations.includes("startToStart")) ||
(ganttRelationEvent?.target === "endOfTask" &&
authorizedRelations.includes("endToStart"));
const isToEndRelationAuthorized =
(ganttRelationEvent?.target === "startOfTask" &&
authorizedRelations.includes("startToEnd")) ||
(ganttRelationEvent?.target === "endOfTask" &&
authorizedRelations.includes("endToEnd"));

let displayLeftRelationHandle: boolean = false;
if (ganttRelationEvent && task !== ganttRelationEvent.task) {
displayLeftRelationHandle = rtl
? isToEndRelationAuthorized
: isToStartRelationAuthorized;
} else {
displayLeftRelationHandle = rtl
? isFromEndRelationAuthorized
: isFromStartRelationAuthorized;
}
let displayRightRelationHandle: boolean = false;
if (ganttRelationEvent && task !== ganttRelationEvent.task) {
displayRightRelationHandle = rtl
? isToStartRelationAuthorized
: isToEndRelationAuthorized;
} else {
displayRightRelationHandle = rtl
? isFromStartRelationAuthorized
: isFromEndRelationAuthorized;
}
const relationhandles = (
<>
{/* left */}
{isRelationChangeable && displayLeftRelationHandle && (
<BarRelationHandle
dataTestid={`task-relation-handle-left-${task.name}`}
isRelationDrawMode={!!ganttRelationEvent}
x={x1 - relationCircleOffset}
y={taskYOffset + taskHalfHeight}
radius={relationCircleRadius}
startDrawRelation={onLeftRelationTriggerMouseDown}
/>
)}
{/* right */}
{isRelationChangeable && displayRightRelationHandle && (
<BarRelationHandle
dataTestid={`task-relation-handle-right-${task.name}`}
isRelationDrawMode={!!ganttRelationEvent}
x={x2 + relationCircleOffset}
y={taskYOffset + taskHalfHeight}
radius={relationCircleRadius}
startDrawRelation={onRightRelationTriggerMouseDown}
/>
)}
</>
);

if (task.type === "milestone") {
return (
<Milestone
Expand All @@ -213,7 +288,9 @@ const TaskItemInner: React.FC<TaskItemProps> = props => {
onLeftRelationTriggerMouseDown={onLeftRelationTriggerMouseDown}
onRightRelationTriggerMouseDown={onRightRelationTriggerMouseDown}
onTaskEventStart={onTaskEventStart}
/>
>
{relationhandles}
</Milestone>
);
} else if (width < handleWidth * 2) {
return (
Expand All @@ -231,11 +308,12 @@ const TaskItemInner: React.FC<TaskItemProps> = props => {
onRightRelationTriggerMouseDown={onRightRelationTriggerMouseDown}
onTaskEventStart={onTaskEventStart}
colorStyles={styles}
/>
>
{relationhandles}
</Bar>
);
}, [
handleWidth,
isRelationDrawMode,
isSelected,
outOfParentWarnings,
props,
Expand Down
Loading

0 comments on commit fdbccb3

Please sign in to comment.