mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-08 00:03:07 +00:00
* RunsPage redesign v0 * nit * Remove manualdatepicker * remove shadow * ui nits * nit scrollbar bg * prettier cards * nit * Remove code * command/meta multi select * Shift select * RightClickPopover * nit * Ctrl A * nit card * DropdownMenu * nit * count hint * fix stuck keys * opacity UX * error toasts pickhubscript * Improve UX * fix undefined error * keyboard nav * nit batch rerun fixes * nit fix scroll / height * Batch reruns actions + nits * nit * Cancel selected jobs * Cancel / re-run all filtered jobs * Go to job / flow / script action * nit * add batch actions back * nit * nit * bar on splitpane hover * nit * New Timeframe system * reset btn * nit fixes * dead code * nits * typecheck * naming clarity * Update frontend/src/lib/components/RightClickPopover.svelte Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> * unnecessary json stringify * dedup 'the' * Code deletion to prepare for changes * filter types * ui * fix bug with maxTs * stuck with melt * GenericDropdown * filters onclick * iterate * iter * add all filters * Descriptions * focus position * stash * TaggedTextInput works much much better * placeholder * currentTag suggestion * improve * nit * Keyboard nav * buildRunsFilterSearchbarSchema * nit naming * assignObjInPlace * Escaping + pretty dates * nit empty * fix cursor * nit space * Filter filtering * escape pasted value * nit * escape spaces * nit undefined * add space at end if right arrow * escape all spaces * arrow skips escape chars * escape \ too * delete whole escaped characters * double space to escape tag * code refactor * Ensure cursor visible * fix keyboard nav * safety * filterSchemaRecToZodSchema * URL Sync * fix readonly * fix typing * start replacing old filter logic * use new filter impl * nit * nit reactivity * nit fix * no more localStorage * Add back status and kind toggles * Nit fix * style nit * focus at end on click * clearn btn + fixes * fix broken date uri * nit * useSyncedTimeframe * negative filter button * negative filters helpers rust * Negated filters backed * nit * highlight * New useSearchParams * Accept comma separated list * nit allowNegative * openapi update * Fix trigger kind list/negation not working * nit oipenpai * Presets * DebouncedTempValue * remove presets from list when already applied * UI nit improvements * allowMultiple * hint * validateFilterInstance fn * nit fix * error highlights * nit ux selecting negative list * nit * on clear btn * SimpleEditor for JSON * nit * flop * Pass presets as param * nit delete * preventCursorMoveOnNextSync * responsive layout * Escape \n * Inline calendar input * mm/dd or dd/mm depending on US or not * onClickBehavior * infiniteRange * other nits * Wiring with runs filter * formatDateRange better * inits on right page * style * min hour support * Time input * use our components * Improve SKILL.md * dd mm yyyy numeric input * TimeframeSelect with new date picker * fixes * ensure date is in view when value changes externally * fixes * nit select all on focus * select year + nits * nit layout shift * nit negative when starting with ! * nit * SelectDropdown uses GenericDropdown now * Fix blank select dropdown rendering bug * icons * Reset btn + shorter date range formatting * overflow fix * unnecessary absolute * fix clear btn overlap * Update routes for new filters (assets, schedule, resource, variables) * update openapi * Impl for other pages * ui nits * nit fixes * Fix columns filter * super nits --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
266 lines
6.4 KiB
Svelte
266 lines
6.4 KiB
Svelte
<script lang="ts">
|
|
import 'chartjs-adapter-date-fns'
|
|
import zoomPlugin from 'chartjs-plugin-zoom'
|
|
import {
|
|
Chart as ChartJS,
|
|
CategoryScale,
|
|
Legend,
|
|
LineElement,
|
|
LinearScale,
|
|
PointElement,
|
|
TimeScale,
|
|
Title,
|
|
Tooltip
|
|
} from 'chart.js'
|
|
import type { CompletedJob, ExtendedJobs } from '$lib/gen'
|
|
import { getDbClockNow } from '$lib/forLater'
|
|
import { Line } from '$lib/components/chartjs-wrappers/chartJs'
|
|
|
|
interface Props {
|
|
extendedJobs?: ExtendedJobs | undefined
|
|
maxIsNow?: boolean
|
|
minTimeSet?: string | null
|
|
maxTimeSet?: string | null
|
|
onZoom: (zoom: { min: Date; max: Date }) => void
|
|
}
|
|
|
|
let {
|
|
extendedJobs = undefined,
|
|
maxIsNow = false,
|
|
minTimeSet = null,
|
|
maxTimeSet = null,
|
|
onZoom
|
|
}: Props = $props()
|
|
|
|
function calculateTimeSeries(extendedJobs: ExtendedJobs): AggregatedInterval[] {
|
|
const timeline = new Map<number, { count: number; id_started: string[]; id_ended: string[] }>()
|
|
|
|
extendedJobs.jobs.forEach((j) => {
|
|
if (j.started_at != undefined) {
|
|
const startTime = new Date(j.started_at).getTime()
|
|
if (!timeline.has(startTime)) {
|
|
timeline.set(startTime, { count: 0, id_started: [], id_ended: [] })
|
|
}
|
|
const s = timeline.get(startTime)!
|
|
s.count += 1
|
|
s.id_started.push(j.id)
|
|
if (j.type === 'CompletedJob') {
|
|
const jc = j as CompletedJob
|
|
const endTime = startTime + jc.duration_ms
|
|
if (!timeline.has(endTime)) {
|
|
timeline.set(endTime, { count: 0, id_started: [], id_ended: [] })
|
|
}
|
|
const e = timeline.get(endTime)!
|
|
e.count -= 1
|
|
e.id_ended.push(j.id)
|
|
}
|
|
}
|
|
})
|
|
|
|
extendedJobs.obscured_jobs.forEach((j) => {
|
|
if (j.started_at != undefined) {
|
|
const startTime = new Date(j.started_at).getTime()
|
|
if (!timeline.has(startTime)) {
|
|
timeline.set(startTime, { count: 0, id_started: [], id_ended: [] })
|
|
}
|
|
const s = timeline.get(startTime)!
|
|
s.count += 1
|
|
s.id_started.push('unknown')
|
|
if (j.duration_ms != undefined) {
|
|
const jc = j as CompletedJob
|
|
const endTime = startTime + jc.duration_ms
|
|
if (!timeline.has(endTime)) {
|
|
timeline.set(endTime, { count: 0, id_started: [], id_ended: [] })
|
|
}
|
|
const e = timeline.get(endTime)!
|
|
e.count -= 1
|
|
e.id_ended.push('unknown')
|
|
}
|
|
}
|
|
})
|
|
|
|
let count = 0
|
|
const result: AggregatedInterval[] = []
|
|
for (const [time, change] of [...timeline.entries()].sort(
|
|
([time1], [time2]) => time1 - time2
|
|
)) {
|
|
count += change.count
|
|
let msg = ''
|
|
msg += change.id_started.length != 0 ? `${change.id_started.join(',')} started` : ''
|
|
msg += change.id_started.length != 0 && change.id_ended.length != 0 ? '\n' : ''
|
|
msg += change.id_ended.length != 0 ? `${change.id_ended.join(',')} ended` : ''
|
|
result.push({ time: new Date(time), count, msg } as AggregatedInterval)
|
|
}
|
|
|
|
// Add points to continue the line towards the extremities
|
|
if (result.length > 0) {
|
|
let start_time = addSeconds(new Date(result[0].time), -1)
|
|
let start_count = 0
|
|
let end_count = result[result.length - 1].count
|
|
result.unshift({
|
|
time: start_time,
|
|
count: start_count
|
|
} as AggregatedInterval)
|
|
result.push({
|
|
time: new Date(),
|
|
count: end_count
|
|
} as AggregatedInterval)
|
|
}
|
|
|
|
return result
|
|
}
|
|
type AggregatedInterval = { time: Date; count: number; msg?: string }
|
|
|
|
ChartJS.register(
|
|
Title,
|
|
Tooltip,
|
|
Legend,
|
|
zoomPlugin,
|
|
LineElement,
|
|
CategoryScale,
|
|
LinearScale,
|
|
PointElement,
|
|
TimeScale
|
|
)
|
|
|
|
const zoomOptions = {
|
|
pan: {
|
|
enabled: true,
|
|
modifierKey: 'ctrl' as 'ctrl',
|
|
onPanComplete: ({ chart }) => {
|
|
onZoom({
|
|
min: addSeconds(new Date(chart.scales.x.min), -1),
|
|
max: addSeconds(new Date(chart.scales.x.max), 1)
|
|
})
|
|
}
|
|
},
|
|
zoom: {
|
|
drag: {
|
|
enabled: true
|
|
},
|
|
mode: 'x' as 'x',
|
|
onZoom: ({ chart }) => {
|
|
onZoom({
|
|
min: addSeconds(new Date(chart.scales.x.min), -1),
|
|
max: addSeconds(new Date(chart.scales.x.max), 1)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
function minJobTime(intervals: AggregatedInterval[]): Date {
|
|
return intervals[0].time
|
|
}
|
|
|
|
function maxJobTime(intervals: AggregatedInterval[]): Date {
|
|
return intervals[intervals?.length - 1].time
|
|
}
|
|
function computeMinMaxTime(
|
|
intervals: AggregatedInterval[] | undefined,
|
|
minTimeSet: string | null,
|
|
maxTimeSet: string | null
|
|
) {
|
|
let minTimeSetDate = minTimeSet ? new Date(minTimeSet) : undefined
|
|
let maxTimeSetDate = maxTimeSet ? new Date(maxTimeSet) : undefined
|
|
if (minTimeSetDate && maxTimeSetDate) {
|
|
return { min: minTimeSetDate, max: maxTimeSetDate }
|
|
}
|
|
|
|
if (intervals == undefined || intervals?.length == 0) {
|
|
const minTime = minTimeSetDate ?? addSeconds(new Date(), -300)
|
|
const maxTime = maxTimeSetDate ?? getDbClockNow()
|
|
return { min: minTime, max: maxTime }
|
|
}
|
|
|
|
const maxJob = maxIsNow ? getDbClockNow() : maxJobTime(intervals)
|
|
const minJob = minJobTime(intervals)
|
|
|
|
const diff = (maxJob.getTime() - minJob.getTime()) / 20000
|
|
|
|
const minTime = minTimeSetDate ?? addSeconds(minJob, -diff)
|
|
const maxTime = maxIsNow
|
|
? (maxTimeSetDate ?? maxJob)
|
|
: (maxTimeSetDate ?? addSeconds(maxJob, diff))
|
|
return { min: minTime, max: maxTime }
|
|
}
|
|
|
|
function addSeconds(date: Date, seconds: number): Date {
|
|
date.setTime(date.getTime() + seconds * 1000)
|
|
return date
|
|
}
|
|
|
|
const intervals = $derived(extendedJobs ? calculateTimeSeries(extendedJobs) : undefined)
|
|
|
|
let data = $derived({
|
|
datasets: [
|
|
{
|
|
borderColor: '#4ade80',
|
|
backgroundColor: '#f8717100',
|
|
pointRadius: 0,
|
|
label: 'running',
|
|
showLine: true,
|
|
stepped: true,
|
|
data:
|
|
intervals?.map((job) => ({
|
|
x: job.time as any,
|
|
y: job.count,
|
|
id: job.msg
|
|
})) ?? []
|
|
}
|
|
]
|
|
})
|
|
|
|
const minMaxTimes = $derived(computeMinMaxTime(intervals, minTimeSet, maxTimeSet))
|
|
|
|
let options = $derived({
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: {
|
|
zoom: zoomOptions,
|
|
legend: {
|
|
display: false
|
|
},
|
|
tooltip: {
|
|
callbacks: {
|
|
footer: function (context) {
|
|
return context[context.length - 1].raw.id
|
|
}
|
|
}
|
|
}
|
|
},
|
|
scales: {
|
|
x: {
|
|
type: 'time',
|
|
grid: {
|
|
display: false
|
|
},
|
|
min: minMaxTimes.min,
|
|
max: minMaxTimes.max,
|
|
ticks: { maxRotation: 0, minRotation: 0 }
|
|
},
|
|
y: {
|
|
grid: {
|
|
display: false
|
|
},
|
|
title: {
|
|
display: true,
|
|
text: 'concurrent jobs'
|
|
},
|
|
beginAtZero: true,
|
|
ticks: {
|
|
stepSize: 1
|
|
}
|
|
}
|
|
},
|
|
animation: false,
|
|
interaction: {
|
|
intersect: false,
|
|
mode: 'index'
|
|
}
|
|
} as any)
|
|
</script>
|
|
|
|
<div class="relative h-44">
|
|
<Line {data} {options} />
|
|
</div>
|