Skip to content

Commit

Permalink
feat: 🎸 [Timeline] Added onErrors callback
Browse files Browse the repository at this point in the history
✅ Closes: #95
  • Loading branch information
luciob committed Sep 28, 2023
1 parent cabcee1 commit 15b4a54
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/timeline/TimelineContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,6 +24,10 @@ export type TimelineProviderProps = PropsWithChildren<TimelineInput> & {
* Enables debug logging in browser console
*/
debug?: boolean;
/**
* Callback invoked when errors are thrown
*/
onErrors?: (errors: KonvaTimelineError[]) => void;
/**
* Event handler for task click
*/
Expand All @@ -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;
Expand All @@ -72,6 +78,7 @@ export const TimelineProvider = ({
displayTasksLabel = false,
dragResolution: externalDragResolution,
hideResources = false,
onErrors,
onTaskClick,
onTaskDrag,
tasks: externalTasks,
Expand Down Expand Up @@ -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 (
<TimelineContext.Provider
Expand All @@ -203,6 +211,7 @@ export const TimelineProvider = ({
drawRange,
hideResources,
interval,
onErrors,
onTaskClick,
onTaskDrag,
resolution,
Expand Down

0 comments on commit 15b4a54

Please sign in to comment.