From 4c69b29a1c7d5fae5bf647f81a9fe5b1e4ce01fc Mon Sep 17 00:00:00 2001 From: CrisGrud Date: Tue, 12 Mar 2024 17:25:58 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[Task]=20Fixed=20time=20?= =?UTF-8?q?return?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #210 --- src/grid/Cell/index.tsx | 1 + src/tasks/components/Task/index.tsx | 2 +- src/tasks/components/TaskLine/index.tsx | 13 ++-- src/tasks/utils/tasks.ts | 83 ++++++++++++++++++++++--- src/utils/timeBlockArray.ts | 12 ++-- 5 files changed, 89 insertions(+), 22 deletions(-) diff --git a/src/grid/Cell/index.tsx b/src/grid/Cell/index.tsx index 7b9e9de..8c1dd0d 100644 --- a/src/grid/Cell/index.tsx +++ b/src/grid/Cell/index.tsx @@ -62,6 +62,7 @@ const GridCell = ({ column, height, index, hourInfo: visibleDayInfo }: GridCellP } return DEFAULT_STROKE_DARK_MODE; }, [themeColor]); + return ( diff --git a/src/tasks/components/Task/index.tsx b/src/tasks/components/Task/index.tsx index 99af2fc..757aa82 100644 --- a/src/tasks/components/Task/index.tsx +++ b/src/tasks/components/Task/index.tsx @@ -157,7 +157,7 @@ const Task = ({ const dragSnapInPX = useMemo(() => { const resolutionInSnapUnit = Duration.fromObject({ [unit]: sizeInUnits }).as(dragUnit); const dragSnapInResUnit = dragSizeInUnits / resolutionInSnapUnit; - const dragSnapInPx = Math.floor(dragSnapInResUnit * columnWidth); + const dragSnapInPx = dragSnapInResUnit * columnWidth; if (!dragSnapInPx || isNaN(dragSnapInPx)) { return 1; } diff --git a/src/tasks/components/TaskLine/index.tsx b/src/tasks/components/TaskLine/index.tsx index 9e28e5f..b6d78df 100644 --- a/src/tasks/components/TaskLine/index.tsx +++ b/src/tasks/components/TaskLine/index.tsx @@ -179,11 +179,10 @@ const TaskLine = ({ const dragSnapInPX = useMemo(() => { const resolutionInSnapUnit = Duration.fromObject({ [unit]: sizeInUnits }).as(dragUnit); const dragSnapInResUnit = dragSizeInUnits / resolutionInSnapUnit; - const dragSnapInPx = Math.floor(dragSnapInResUnit * columnWidth); + const dragSnapInPx = dragSnapInResUnit * columnWidth; if (!dragSnapInPx || isNaN(dragSnapInPx)) { return 1; } - return dragSnapInPx; }, [columnWidth, dragUnit, dragSizeInUnits, sizeInUnits, unit]); @@ -371,8 +370,8 @@ const TaskLine = ({ workLine && workLine([]); if (data.relatedTasks) { const addTime = +time.end - +data.time.end; - const tasksId = connectedTasks(data, allValidTasks); - onTaskChange({ ...data, resourceId, time }, { tasksId, addTime }); + const tasksId = connectedTasks(data, allValidTasks, addTime, externalRangeInMillis); + onTaskChange({ ...data, resourceId, time }, { tasksId: tasksId.allKLine, addTime: tasksId.maxAddTime }); return; } onTaskChange({ ...data, resourceId, time }); @@ -391,6 +390,7 @@ const TaskLine = ({ interval, workLine, allValidTasks, + externalRangeInMillis, ] ); @@ -498,8 +498,8 @@ const TaskLine = ({ workLine && workLine([]); if (enableLines && data.relatedTasks && frontLine) { const addTime = +time.end - +data.time.end; - const tasksId = connectedTasks(data, allValidTasks); - onTaskChange({ ...data, time }, { tasksId, addTime }); + const tasksId = connectedTasks(data, allValidTasks, addTime, externalRangeInMillis); + onTaskChange({ ...data, time }, { tasksId: tasksId.allKLine, addTime: tasksId.maxAddTime }); return; } onTaskChange({ ...data, time }); @@ -516,6 +516,7 @@ const TaskLine = ({ allValidTasks, workLine, frontLine, + externalRangeInMillis, ] ); const percentage = useMemo(() => { diff --git a/src/tasks/utils/tasks.ts b/src/tasks/utils/tasks.ts index c653d0d..5363e55 100644 --- a/src/tasks/utils/tasks.ts +++ b/src/tasks/utils/tasks.ts @@ -158,31 +158,79 @@ export const onEndTimeRange = ( columnWidth: number, interval: Interval ): TimeRange => { + const columnInHrs = resolution.unit === "week" ? (resolution.sizeInUnits === 1 ? 168 : 336) : 24; const hrs = 3600000; + const hrsInPx = columnWidth / columnInHrs; const timeOffset = fromPxToTime(taskDimesion.x, resolution, columnWidth); const startTaskMillis = interval.start!.plus({ [resolution.unit]: timeOffset }).toMillis(); const startDate = DateTime.fromMillis(startTaskMillis); + const startOfBeforeDay = DateTime.fromMillis(startTaskMillis - 3600000).startOf("day"); + const startOfBeforeDayTz = startOfBeforeDay.toISO()!.slice(-5, -3); + + const startOfNextDay = DateTime.fromMillis(startTaskMillis + 3600000) + .startOf("day") + .toISO()! + .slice(-5, -3); + const intervalStartTZ = interval.start?.toISO().slice(-5, -3); //Interval start TZ - const taskStartTZ = DateTime.fromMillis(startTaskMillis).toISO()?.slice(-5, -3); //Task start TZ + const taskStartTZ = DateTime.fromMillis(startTaskMillis).startOf("day").toISO()?.slice(-5, -3); //Task start TZ const diffTZ = +intervalStartTZ! - +taskStartTZ!; const startOfDay = startDate.startOf("day").toISO()?.slice(-5, -3); //Day start TZ - const nexDay = startDate.plus({ day: 1 }).toISO()?.slice(-5, -3); //Next Day TZ - const diffTZInDay = +startOfDay! - +nexDay!; - const nexDayMillis = startDate.startOf("day").toMillis() + 24 * hrs; + const nexDay = startDate.startOf("day").plus({ day: 1 }).toISO()?.slice(-5, -3); //Next Day TZ + const diffTZInDay = +nexDay! - +startOfDay!; let gap = 0; + let hrsSpecialCase = 0; + if (resolution.unit === "day" || resolution.unit === "week") { - if (diffTZ !== 0) { - gap = hrs * diffTZ; - if (diffTZInDay !== 0 && startTaskMillis < nexDayMillis) { + if (diffTZ === 1) { + gap = hrsInPx * diffTZ; + + if (+startOfBeforeDayTz - +intervalStartTZ! === 0 && +startOfNextDay - +intervalStartTZ! !== 0) { gap = 0; + hrsSpecialCase = hrs; + } + } + + if (+startOfBeforeDayTz - +intervalStartTZ! !== 0 && +startOfNextDay - +intervalStartTZ! === 0) { + const timeOffsett = fromPxToTime(taskDimesion.x - hrsInPx * 23, resolution, columnWidth); + const startTaskMilliss = interval + .start!.plus({ [resolution.unit]: timeOffsett }) + .startOf("hour") + .toMillis(); + if (startOfBeforeDay.toMillis() === startTaskMilliss) { + hrsSpecialCase = hrs; + } + } + if (diffTZ === -1) { + gap = hrsInPx * diffTZ; + + if (diffTZInDay === -1) { + gap = hrsInPx * diffTZInDay; + } + const timeOffsett = fromPxToTime(taskDimesion.x - hrsInPx * 23, resolution, columnWidth); + const startTaskMilliss = interval.start!.plus({ [resolution.unit]: timeOffsett }).startOf("hour"); + if (startOfBeforeDay.toMillis() === startTaskMilliss.toMillis()) { + if (diffTZInDay !== 0) { + gap = 0; + hrsSpecialCase = -hrs; + } + } + if ( + startTaskMilliss.toMillis() + hrs * 23 === startDate.startOf("day").toMillis() && + startTaskMilliss.toISO().slice(-5, -3) === intervalStartTZ + ) { + gap = 0; + hrsSpecialCase = 0; } } } - const start = interval.start!.plus({ [resolution.unit]: timeOffset }).toMillis() - gap; + const timeOffsetB = fromPxToTime(taskDimesion.x - gap, resolution, columnWidth); + + const start = interval.start!.plus({ [resolution.unit]: timeOffsetB }).toMillis() - hrsSpecialCase; const end = start + Duration.fromObject({ @@ -191,16 +239,31 @@ export const onEndTimeRange = ( return { start, end }; }; -export const connectedTasks = (taskData: TaskData, allValidTasks: TaskData[]) => { +export const connectedTasks = ( + taskData: TaskData, + allValidTasks: TaskData[], + addTime: number, + range: InternalTimeRange +) => { + const { start, end } = range; let allKLine = taskData.relatedTasks ? taskData.relatedTasks : []; let newKLine: string[] = []; let noKLine = true; let iOffset = 0; + let maxAddTime = addTime; do { noKLine = false; let pushCount = iOffset === 0 ? allKLine.length - 1 : 0; for (let i = 0 + iOffset; i < allKLine.length; i++) { const val = allValidTasks.find((item) => item.id === allKLine[i]); + if (val) { + if (+val.time.start + addTime < start) { + maxAddTime = start - +val.time.start; + } + if (+val.time.end + addTime > end) { + maxAddTime = end - +val.time.end; + } + } if (val?.relatedTasks) { val.relatedTasks.map((value) => { if (!allKLine.includes(value) && !newKLine.includes(value)) { @@ -219,5 +282,5 @@ export const connectedTasks = (taskData: TaskData, allValidTasks: TaskData[]) => newKLine = []; iOffset = iOffset + pushCount; } while (noKLine); - return allKLine; + return { allKLine, maxAddTime }; }; diff --git a/src/utils/timeBlockArray.ts b/src/utils/timeBlockArray.ts index a53b78e..5418a71 100644 --- a/src/utils/timeBlockArray.ts +++ b/src/utils/timeBlockArray.ts @@ -24,14 +24,16 @@ export const getTimeBlocksTzInfo = (timeBlock: Interval[], initialTz?: string) = backHour: true, nextHour: false, }); - return; } - dayInfoArray.push({ - backHour: false, - nextHour: true, - }); + if (Number(initialTz?.slice(1, 3)) - Number(tzStart!.slice(1, 3)) < 0) { + dayInfoArray.push({ + backHour: false, + nextHour: true, + }); + return; + } } dayInfoArray.push({