Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/lib/components/lines-and-dots/end-time-interval.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

export let workflow: WorkflowExecution;
export let startTime: string | Timestamp;
export let overrideEndTime: string | undefined = undefined;

let currentTime = Date.now();

Expand All @@ -16,29 +17,29 @@
return currentTime + 1000;
};

$: endTime = workflow?.endTime || rightNow();
$: endTime = overrideEndTime || workflow?.endTime || rightNow();
$: duration = getMillisecondDuration({
start: startTime,
end: endTime,
onlyUnderSecond: false,
});

let endTimeInterval;
let endTimeInterval: ReturnType<typeof setInterval> | null = null;

const clearEndTimeInterval = (endTime: string) => {
if (endTime) {
clearInterval(endTimeInterval);
if (endTimeInterval) clearInterval(endTimeInterval);
endTimeInterval = null;
}
};

const startStopInterval = (pauseLiveUpdates) => {
if (pauseLiveUpdates) {
clearInterval(endTimeInterval);
const startStopInterval = (pauseLiveUpdates: boolean) => {
if (pauseLiveUpdates || overrideEndTime) {
if (endTimeInterval) clearInterval(endTimeInterval);
endTimeInterval = null;
} else if (!endTimeInterval && (workflow.isRunning || workflow.isPaused)) {
endTimeInterval = setInterval(() => {
endTime = rightNow();

Check warning on line 42 in src/lib/components/lines-and-dots/end-time-interval.svelte

View workflow job for this annotation

GitHub Actions / lint

Assignment to reactive value 'endTime'
}, 1000);
}
};
Expand All @@ -47,7 +48,7 @@
$: startStopInterval($pauseLiveUpdates);

onDestroy(() => {
clearInterval(endTimeInterval);
if (endTimeInterval) clearInterval(endTimeInterval);
endTimeInterval = null;
$pauseLiveUpdates = false;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@
onlyUnderSecond: false,
});

const clampRatio = (r: number) => Math.max(0, Math.min(1, r));

const points = group.eventList.map((event) => {
const distance = getMillisecondDuration({
start: startTime,
end: event.eventTime,
onlyUnderSecond: false,
});

const ratio = distance / workflowDistance;
const ratio = clampRatio((distance ?? 0) / (workflowDistance ?? 1));
return Math.round(ratio * timelineWidth) + gutter;
});

Expand All @@ -104,7 +106,7 @@
onlyUnderSecond: false,
});

const ratio = distance / workflowDistance;
const ratio = clampRatio((distance ?? 0) / (workflowDistance ?? 1));
const pausePoint = Math.round(ratio * timelineWidth) + gutter;
points.push(pausePoint);
}
Expand Down Expand Up @@ -239,7 +241,7 @@
startPoint={[x, y]}
endPoint={[canvasWidth - gutter, y]}
category={pendingActivity
? pendingActivity.attempt > 1
? (pendingActivity.attempt ?? 0) > 1
? 'retry'
: 'pending'
: group.category}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
viewportHeight: number | undefined;
readOnly?: boolean;
error?: boolean;
overrideStartTime?: string;
overrideEndTime?: string;
}

let {
Expand All @@ -35,6 +37,8 @@
viewportHeight,
readOnly = false,
error = false,
overrideStartTime,
overrideEndTime,
}: Props = $props();

const { height, gutter, radius } = TimelineConfig;
Expand All @@ -59,7 +63,9 @@
});

const startTime = $derived(
(!isWorkflowDelayed(workflow) && firstStartTime) || workflow.startTime,
overrideStartTime ||
(!isWorkflowDelayed(workflow) && firstStartTime) ||
workflow.startTime,
);
const timelineHeight = $derived(
Math.max(height * (filteredGroups.length + 2), 120) + expandedGroupHeight,
Expand Down Expand Up @@ -93,6 +99,7 @@
<EndTimeInterval
{workflow}
{startTime}
{overrideEndTime}
let:endTime
let:duration
let:currentTime
Expand Down
Loading
Loading