mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-07 16:03:21 +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>
297 lines
7.1 KiB
Svelte
297 lines
7.1 KiB
Svelte
<script lang="ts">
|
|
import 'chartjs-adapter-date-fns'
|
|
import zoomPlugin from 'chartjs-plugin-zoom'
|
|
import {
|
|
Chart as ChartJS,
|
|
Title,
|
|
Tooltip,
|
|
Legend,
|
|
LineElement,
|
|
CategoryScale,
|
|
LinearScale,
|
|
PointElement,
|
|
TimeScale,
|
|
LogarithmicScale,
|
|
type ChartOptions
|
|
} from 'chart.js'
|
|
import type { CompletedJob } from '$lib/gen'
|
|
import { getDbClockNow } from '$lib/forLater'
|
|
import { Scatter } from '$lib/components/chartjs-wrappers/chartJs'
|
|
import DarkModeObserver from './DarkModeObserver.svelte'
|
|
|
|
interface Props {
|
|
jobs?: CompletedJob[] | undefined
|
|
maxIsNow?: boolean
|
|
minTimeSet?: string | null
|
|
maxTimeSet?: string | null
|
|
selectedIds?: string[]
|
|
canSelect?: boolean
|
|
onPointClicked: (ids: string[]) => void
|
|
onZoom: (zoom: { min: Date; max: Date }) => void
|
|
}
|
|
|
|
let {
|
|
jobs = [],
|
|
maxIsNow = false,
|
|
minTimeSet = null,
|
|
maxTimeSet = null,
|
|
selectedIds = $bindable([]),
|
|
canSelect = true,
|
|
onPointClicked,
|
|
onZoom
|
|
}: Props = $props()
|
|
|
|
const SUCCESS_COLOR = '#4ade80'
|
|
// const SUCCESS_COLOR_TRANSPARENT = '#c9b638'
|
|
const SUCCESS_COLOR_TRANSPARENT = $derived(mergeColors(SUCCESS_COLOR, getBackgroundColor(), 0.8))
|
|
const FAIL_COLOR = '#f87171'
|
|
const FAIL_COLOR_TRANSPARENT = $derived(mergeColors(FAIL_COLOR, getBackgroundColor(), 0.8))
|
|
|
|
ChartJS.register(
|
|
Title,
|
|
Tooltip,
|
|
Legend,
|
|
zoomPlugin,
|
|
LineElement,
|
|
CategoryScale,
|
|
LinearScale,
|
|
LogarithmicScale,
|
|
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)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
let darkMode = $state(false)
|
|
$effect(() => {
|
|
ChartJS.defaults.color = darkMode ? '#ccc' : '#666'
|
|
ChartJS.defaults.borderColor = darkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)'
|
|
})
|
|
|
|
function getBackgroundColor(): string {
|
|
return darkMode ? '#2e3440' : '#ffffff'
|
|
}
|
|
function hexToRgb(hexColor: string): number[] {
|
|
hexColor = hexColor.replace(/^#/, '')
|
|
|
|
const r = parseInt(hexColor.substring(0, 2), 16)
|
|
const g = parseInt(hexColor.substring(2, 4), 16)
|
|
const b = parseInt(hexColor.substring(4, 6), 16)
|
|
|
|
return [r, g, b]
|
|
}
|
|
|
|
function rgbToHex(rgbColor: number[]): string {
|
|
// Convert RGB components to hexadecimal string
|
|
return (
|
|
'#' +
|
|
rgbColor
|
|
.map((c) => {
|
|
const hex = c.toString(16)
|
|
return hex.length === 1 ? '0' + hex : hex
|
|
})
|
|
.join('')
|
|
)
|
|
}
|
|
|
|
function mergeColors(color1: string, color2: string, slider: number): string {
|
|
const rgb1 = hexToRgb(color1)
|
|
const rgb2 = hexToRgb(color2)
|
|
|
|
// Blend colors based on percentage
|
|
const blendedRgb = rgb1.map((c1, i) => Math.round(c1 * (1 - slider) + rgb2[i] * slider))
|
|
|
|
return rgbToHex(blendedRgb)
|
|
}
|
|
|
|
function getPath(x: any): string {
|
|
return x.path
|
|
}
|
|
|
|
function minJobTime(jobs: CompletedJob[]): Date {
|
|
let min: Date = new Date(jobs[0].completed_at!)
|
|
for (const job of jobs) {
|
|
if (job.completed_at != undefined) {
|
|
const date = new Date(job.completed_at)
|
|
if (date < min) {
|
|
min = date
|
|
}
|
|
}
|
|
}
|
|
return min
|
|
}
|
|
|
|
function maxJobTime(jobs: CompletedJob[]): Date {
|
|
let max: Date = new Date(jobs[0].completed_at!)
|
|
for (const job of jobs) {
|
|
if (new Date(job.completed_at!) > max) {
|
|
max = new Date(job.completed_at!)
|
|
}
|
|
}
|
|
return max
|
|
}
|
|
|
|
function computeMinMaxTime(
|
|
jobs: CompletedJob[] | 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 { minTime: minTimeSetDate, maxTime: maxTimeSetDate }
|
|
}
|
|
|
|
if (jobs == undefined || jobs?.length == 0) {
|
|
const computedMinTime = minTimeSetDate ?? addSeconds(new Date(), -300)
|
|
const computedMaxTime = maxTimeSetDate ?? getDbClockNow()
|
|
return { minTime: computedMinTime, maxTime: computedMaxTime }
|
|
}
|
|
|
|
const maxJob = maxIsNow ? getDbClockNow() : maxJobTime(jobs)
|
|
const minJob = minJobTime(jobs)
|
|
|
|
const diff = (maxJob.getTime() - minJob.getTime()) / 20000
|
|
|
|
let computedMinTime = minTimeSetDate ?? addSeconds(minJob, -diff)
|
|
let computedMaxTime = maxIsNow
|
|
? (maxTimeSetDate ?? maxJob)
|
|
: (maxTimeSetDate ?? addSeconds(maxJob, diff))
|
|
return { minTime: computedMinTime, maxTime: computedMaxTime }
|
|
}
|
|
|
|
function addSeconds(date: Date, seconds: number): Date {
|
|
date.setTime(date.getTime() + seconds * 1000)
|
|
return date
|
|
}
|
|
|
|
let success = $derived(jobs?.filter((x) => x.success))
|
|
let failed = $derived(jobs?.filter((x) => !x.success))
|
|
let data = $derived.by(() => {
|
|
const data = {
|
|
datasets: [
|
|
{
|
|
borderColor: 'rgba(99,0,125, 0)',
|
|
backgroundColor: FAIL_COLOR as string | string[],
|
|
radius: 3,
|
|
label: 'Failed',
|
|
data:
|
|
failed?.map((job) => ({
|
|
x: job.started_at as any,
|
|
y: job.duration_ms,
|
|
id: job.id,
|
|
path: job.script_path
|
|
})) ?? []
|
|
},
|
|
{
|
|
borderColor: 'rgba(99,0,125, 0)',
|
|
backgroundColor: SUCCESS_COLOR as string | string[],
|
|
radius: 3,
|
|
label: 'Successful',
|
|
data:
|
|
success?.map((job) => ({
|
|
x: job.started_at as any,
|
|
y: job.duration_ms,
|
|
id: job.id,
|
|
path: job.script_path
|
|
})) ?? []
|
|
}
|
|
]
|
|
}
|
|
if (!canSelect || selectedIds.length === 0) {
|
|
data.datasets[0].backgroundColor = FAIL_COLOR
|
|
data.datasets[1].backgroundColor = SUCCESS_COLOR
|
|
} else {
|
|
data.datasets[0].backgroundColor = data.datasets[0].data.map((p) =>
|
|
selectedIds.includes(p.id) ? FAIL_COLOR : FAIL_COLOR_TRANSPARENT
|
|
)
|
|
data.datasets[1].backgroundColor = data.datasets[1].data.map((p) =>
|
|
selectedIds.includes(p.id) ? SUCCESS_COLOR : SUCCESS_COLOR_TRANSPARENT
|
|
)
|
|
}
|
|
return data
|
|
})
|
|
|
|
const minMaxTime = $derived.by(() => computeMinMaxTime(jobs, minTimeSet, maxTimeSet))
|
|
|
|
let scatterOptions: ChartOptions<'scatter'> = $derived({
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: {
|
|
zoom: zoomOptions,
|
|
legend: {
|
|
display: false
|
|
},
|
|
tooltip: {
|
|
callbacks: {
|
|
label: function (context: any) {
|
|
return getPath(context.raw)
|
|
}
|
|
}
|
|
}
|
|
},
|
|
onClick: (_e: any, u: any) => {
|
|
if (canSelect) {
|
|
const ids = u.map((j: any) => data.datasets[j.datasetIndex].data[j.index].id)
|
|
selectedIds = ids
|
|
onPointClicked(ids)
|
|
}
|
|
},
|
|
|
|
scales: {
|
|
x: {
|
|
type: 'time',
|
|
grid: {
|
|
display: false
|
|
},
|
|
min: minMaxTime.minTime.getTime(),
|
|
max: minMaxTime.maxTime.getTime(),
|
|
ticks: { maxRotation: 0, minRotation: 0 }
|
|
},
|
|
y: {
|
|
grid: {
|
|
display: false
|
|
},
|
|
title: {
|
|
display: true,
|
|
text: 'job duration (ms)'
|
|
},
|
|
type: 'logarithmic',
|
|
afterFit: function (axis) {
|
|
axis.width = Math.max(axis.width, 65) // min width to prevent layout flickering
|
|
}
|
|
}
|
|
},
|
|
animation: false
|
|
})
|
|
</script>
|
|
|
|
<DarkModeObserver bind:darkMode />
|
|
|
|
<div class="relative h-44">
|
|
<Scatter {data} options={scatterOptions} />
|
|
</div>
|