From 15b4a54b4697abffbfb05a041aa6b8b9a75f0e53 Mon Sep 17 00:00:00 2001 From: luciob Date: Thu, 28 Sep 2023 17:38:23 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20[Timeline]=20Added=20onE?= =?UTF-8?q?rrors=20callback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #95 --- src/timeline/TimelineContext.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/timeline/TimelineContext.tsx b/src/timeline/TimelineContext.tsx index e629e20..77ee42f 100644 --- a/src/timeline/TimelineContext.tsx +++ b/src/timeline/TimelineContext.tsx @@ -4,11 +4,12 @@ import { DateTime, Interval } from "luxon"; import { addHeaderResource } from "../resources/utils/resources"; import { filterTasks, TaskData, validateTasks } from "../tasks/utils/tasks"; import { DEFAULT_GRID_COLUMN_WIDTH, DEFAULT_GRID_ROW_HEIGHT, MINIMUM_GRID_ROW_HEIGHT } from "../utils/dimensions"; -import { logDebug, logError, logWarn } from "../utils/logger"; +import { logDebug, logWarn } from "../utils/logger"; import { TimeRange, toInterval } from "../utils/time-range"; import { getResolutionData, Resolution, ResolutionData } from "../utils/time-resolution"; import { TimelineInput } from "../utils/timeline"; import { executeWithPerfomanceCheck } from "../utils/utils"; +import { KonvaTimelineError } from ".."; declare global { interface Window { @@ -23,6 +24,10 @@ export type TimelineProviderProps = PropsWithChildren & { * Enables debug logging in browser console */ debug?: boolean; + /** + * Callback invoked when errors are thrown + */ + onErrors?: (errors: KonvaTimelineError[]) => void; /** * Event handler for task click */ @@ -48,6 +53,7 @@ type TimelineContextType = Required< dragResolution: ResolutionData; drawRange: TimeRange; interval: Interval; + onErrors?: (errors: KonvaTimelineError[]) => void; onTaskClick?: (task: TaskData) => void; onTaskDrag?: (task: TaskData) => void; resolution: ResolutionData; @@ -72,6 +78,7 @@ export const TimelineProvider = ({ displayTasksLabel = false, dragResolution: externalDragResolution, hideResources = false, + onErrors, onTaskClick, onTaskDrag, tasks: externalTasks, @@ -190,9 +197,10 @@ export const TimelineProvider = ({ }, [externalTheme]); useEffect(() => { - // const realErrors = validTasks.errors.filter((error) => error.level === "error"); - logError("TimelineProvider", `Thrown ${validTasks.errors.length} task errors`); - }, [validTasks]); + if (onErrors) { + onErrors(validTasks.errors); + } + }, [onErrors, validTasks]); return (