Skip to content

Commit

Permalink
Create the type GanttDateRounding for a better API
Browse files Browse the repository at this point in the history
This commits also moves BarMoveAction and RelationMoveTarget in public
types

Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
  • Loading branch information
lfasani committed Jun 18, 2024
1 parent b718df6 commit 8b6d9a2
Show file tree
Hide file tree
Showing 22 changed files with 244 additions and 249 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ npm start
| rtl | boolean | Sets rtl mode. |
| roundDate | | Allow to customize the way the date start/end are rounded |
| checkIsHoliday | | Tells if a date is a holday. It impacts the style of the day and the way the date is adjusted to working days|
| dateMoveStep | string | A string that correponds to a duration. It is composed of a number and a character among **[DHm]** (corresponding to Day, Hour and minutes). It gives the step to ajust to the working day when moving the date allowing a smooth feedback |
| dateMoveStep | | An object that corresponds to a duration. It gives the step to ajust to the working day when moving the date allowing a smooth feedback |

### StylingOption

Expand Down
5 changes: 3 additions & 2 deletions src/components/gantt/gantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, {
import enDateLocale from "date-fns/locale/en-US";

import {
BarMoveAction,
ChangeAction,
CheckTaskIdExistsAtLevel,
ColorStyles,
Expand All @@ -19,6 +20,7 @@ import {
Dependency,
Distances,
FixPosition,
GanttDateRoundingTimeUnit,
GanttProps,
OnDateChange,
OnDateChangeSuggestionType,
Expand Down Expand Up @@ -64,7 +66,6 @@ import { useHorizontalScrollbars } from "./use-horizontal-scrollbars";

import { getDateByOffset } from "../../helpers/get-date-by-offset";
import { getDatesDiff } from "../../helpers/get-dates-diff";
import { BarMoveAction } from "../../types/gantt-task-actions";
import { useGetTaskCurrentState } from "./use-get-task-current-state";
import { useSelection } from "./use-selection";
import { defaultCheckIsHoliday } from "./default-check-is-holiday";
Expand Down Expand Up @@ -224,7 +225,7 @@ export const Gantt: React.FC<GanttProps> = ({
renderBottomHeader = undefined,
renderTopHeader = undefined,
roundDate: roundDateProp = defaultRoundDate,
dateMoveStep = "1D",
dateMoveStep = { value: 1, timeUnit: GanttDateRoundingTimeUnit.DAY },
rtl = false,
tasks,
timeStep = 300000,
Expand Down
8 changes: 3 additions & 5 deletions src/components/gantt/task-gantt-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useMemo } from "react";
import type { MouseEvent, ReactNode } from "react";

import {
BarMoveAction,
ChildByLevelMap,
ChildOutOfParentWarnings,
ColorStyles,
Expand All @@ -12,6 +13,7 @@ import {
FixPosition,
GlobalRowIndexToTaskMap,
RelationKind,
RelationMoveTarget,
Task,
TaskContextualPaletteProps,
TaskCoordinates,
Expand All @@ -21,11 +23,7 @@ import {
import { Arrow } from "../other/arrow";
import { RelationLine } from "../other/relation-line";
import { TaskItem } from "../task-item/task-item";
import {
BarMoveAction,
GanttRelationEvent,
RelationMoveTarget,
} from "../../types/gantt-task-actions";
import { GanttRelationEvent } from "../../types/gantt-task-actions";
import { checkHasChildren } from "../../helpers/check-has-children";
import { checkTaskHasDependencyWarning } from "../../helpers/check-task-has-dependency-warning";
import type { OptimizedListParams } from "../../helpers/use-optimized-list";
Expand Down
6 changes: 2 additions & 4 deletions src/components/gantt/use-create-relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
getMapTaskToCoordinatesOnLevel,
getTaskCoordinates,
} from "../../helpers/get-task-coordinates";
import {
GanttRelationEvent,
RelationMoveTarget,
} from "../../types/gantt-task-actions";
import { GanttRelationEvent } from "../../types/gantt-task-actions";
import {
Distances,
MapTaskToCoordinates,
Expand All @@ -19,6 +16,7 @@ import {
Task,
TaskMapByLevel,
TaskOrEmpty,
RelationMoveTarget,
} from "../../types/public-types";

type UseCreateRelationParams = {
Expand Down
5 changes: 3 additions & 2 deletions src/components/gantt/use-get-task-current-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { checkIsDescendant } from "../../helpers/check-is-descendant";

import type {
AdjustTaskToWorkingDatesParams,
BarMoveAction,
ChangeInProgress,
DateExtremity,
GanttDateRounding,
MapTaskToCoordinates,
Task,
TaskMapByLevel,
} from "../../types/public-types";
import { roundTaskDates } from "../../helpers/round-task-dates";
import { BarMoveAction } from "../../types/gantt-task-actions";

type UseGetTaskCurrentStateParams = {
adjustTaskToWorkingDates: (params: AdjustTaskToWorkingDatesParams) => Task;
Expand All @@ -30,7 +31,7 @@ type UseGetTaskCurrentStateParams = {
dateExtremity: DateExtremity
) => Date;
tasksMap: TaskMapByLevel;
dateMoveStep: String;
dateMoveStep: GanttDateRounding;
};

export const useGetTaskCurrentState = ({
Expand Down
5 changes: 3 additions & 2 deletions src/components/gantt/use-holidays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { getPreviousWorkingDate as defaultGetPreviousWorkingDate } from "../../h

import {
AdjustTaskToWorkingDatesParams,
BarMoveAction,
DateExtremity,
DateSetup,
GanttDateRounding,
} from "../../types/public-types";
import { BarMoveAction } from "../../types/gantt-task-actions";
import { getStepTime } from "../../helpers/round-task-dates";

type UseHolidaysParams = {
Expand All @@ -27,7 +28,7 @@ type UseHolidaysParams = {
action: BarMoveAction,
dateExtremity: DateExtremity
) => Date;
dateMoveStep: String;
dateMoveStep: GanttDateRounding;
};

export const useHolidays = ({
Expand Down
5 changes: 3 additions & 2 deletions src/components/gantt/use-task-drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { handleTaskBySVGMouseEvent } from "../../helpers/bar-helper";

import { getTaskCoordinates } from "../../helpers/get-task-coordinates";
import { roundTaskDates } from "../../helpers/round-task-dates";
import { BarMoveAction } from "../../types/gantt-task-actions";

import {
ChangeInProgress,
Expand All @@ -19,6 +18,8 @@ import {
TaskCoordinates,
TaskMapByLevel,
DateExtremity,
BarMoveAction,
GanttDateRounding,
} from "../../types/public-types";

const SCROLL_DELAY = 25;
Expand Down Expand Up @@ -200,7 +201,7 @@ type UseTaskDragParams = {
action: BarMoveAction,
dateExtremity: DateExtremity
) => Date;
dateMoveStep: String;
dateMoveStep: GanttDateRounding;
rtl: boolean;
scrollToLeftStep: () => void;
scrollToRightStep: () => void;
Expand Down
8 changes: 6 additions & 2 deletions src/components/other/arrow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React, { memo, useCallback, useMemo } from "react";

import { ColorStyles, Distances, Task } from "../../types/public-types";
import { RelationMoveTarget } from "../../types/gantt-task-actions";
import {
ColorStyles,
Distances,
RelationMoveTarget,
Task,
} from "../../types/public-types";
import { generateTrianglePoints } from "../../helpers/generate-triangle-points";
import {
FixDependencyPosition,
Expand Down
2 changes: 1 addition & 1 deletion src/components/task-item/bar/bar-small.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React, { useCallback } from "react";
import stylesRelationHandle from "./bar-relation-handle.module.css";
import { BarDisplay } from "./bar-display";
import type { TaskItemProps } from "../task-item";
import type { BarMoveAction } from "../../../types/gantt-task-actions";

import styles from "./bar.module.css";
import { BarDateHandle } from "./bar-date-handle";
import { BarMoveAction } from "../../../types/public-types";

export const BarSmall: React.FC<
TaskItemProps & {
Expand Down
2 changes: 1 addition & 1 deletion src/components/task-item/bar/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { BarDisplay } from "./bar-display";
import { BarDateHandle } from "./bar-date-handle";
import { BarProgressHandle } from "./bar-progress-handle";
import type { TaskItemProps } from "../task-item";
import type { BarMoveAction } from "../../../types/gantt-task-actions";

import styles from "./bar.module.css";
import stylesRelationHandle from "./bar-relation-handle.module.css";
import { ProjectDisplay } from "../project/project-display";
import { BarMoveAction } from "../../../types/public-types";

export const Bar: React.FC<
TaskItemProps & {
Expand Down
2 changes: 1 addition & 1 deletion src/components/task-item/milestone/milestone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React, { useMemo } from "react";
import stylesRelationHandle from "../bar/bar-relation-handle.module.css";

import type { TaskItemProps } from "../task-item";
import type { BarMoveAction } from "../../../types/gantt-task-actions";

import styles from "./milestone.module.css";
import { BarMoveAction } from "../../../types/public-types";

export const Milestone: React.FC<
TaskItemProps & {
Expand Down
8 changes: 3 additions & 5 deletions src/components/task-item/task-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import React, {
} from "react";
import type { MouseEvent, MouseEventHandler } from "react";

import {
BarMoveAction,
GanttRelationEvent,
RelationMoveTarget,
} from "../../types/gantt-task-actions";
import { GanttRelationEvent } from "../../types/gantt-task-actions";
import {
ChildOutOfParentWarnings,
FixPosition,
Expand All @@ -21,6 +17,8 @@ import {
TaskOrEmpty,
Distances,
RelationKind,
BarMoveAction,
RelationMoveTarget,
} from "../../types/public-types";
import { Bar } from "./bar/bar";
import { BarSmall } from "./bar/bar-small";
Expand Down
10 changes: 7 additions & 3 deletions src/helpers/adjust-task-to-working-dates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { BarMoveAction } from "../types/gantt-task-actions";
import { DateExtremity, Task } from "../types/public-types";
import {
BarMoveAction,
DateExtremity,
GanttDateRounding,
Task,
} from "../types/public-types";
import { countHolidays } from "./count-holidays";
import {
ONE_DAY_DURATION,
Expand All @@ -22,7 +26,7 @@ type AdjustTaskToWorkingDatesParams = {
dateExtremity: DateExtremity
) => Date;
originalTask: Task;
dateMoveStep: String;
dateMoveStep: GanttDateRounding;
};

export const adjustTaskToWorkingDates = ({
Expand Down
Loading

0 comments on commit 8b6d9a2

Please sign in to comment.