Act on a run, and read Home top-down
Runs: a run can now be deleted (DELETE /runs/{id}, cancelling a live one
first), exported as csv from the screen's own filters, and its flow label
opens the flow. Its "Parameters" panel became "Inputs" and lists every
input the flow declares, marking the ones that took the flow's own value
rather than the run's — the comparison table resolves the same defaults
instead of printing "unset".
Home reads brain, dashboards, health, flows: the mosaic is one full-width
scrolling strip, and the flows list and the flow-activity rollups merged
into a single left-joined table so a flow's state and its numbers sit on
one row.
Charts take a drag to narrow the x window and a double click or tap to
come back out. UplotChart holds the scale and passes resetScales:false
while a window is held, which is what the old comment said made this
impossible.
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
shortCommit,
|
||||
shortId,
|
||||
useCancelRun,
|
||||
useFlowInputs,
|
||||
} from "./queries"
|
||||
import { NodeStatusBadge, RunStatusBadge, statusReason } from "./RunStatus"
|
||||
|
||||
@@ -39,6 +40,7 @@ export function RunDetail({ id }: { id: string }) {
|
||||
const { data: run, isPending } = useQuery(runQueryOptions(id))
|
||||
const cancel = useCancelRun()
|
||||
const names = useMetricNames(id)
|
||||
const declared = useFlowInputs(run?.flow)
|
||||
const [metric, setMetric] = useState("")
|
||||
|
||||
if (isPending || !run) return <Skeleton className="h-96 w-full rounded-lg" />
|
||||
@@ -52,6 +54,20 @@ export function RunDetail({ id }: { id: string }) {
|
||||
// Said once, where it applies.
|
||||
const cached = nodes.some((node) => node.status === "cached")
|
||||
|
||||
// Declared order first, so the panel reads the way the flow does; anything
|
||||
// the run carries that the flow no longer declares still shows, since it is
|
||||
// what the run was actually given.
|
||||
const fed = [
|
||||
...[...declared.keys()].map((name) => ({
|
||||
name,
|
||||
value: name in run.params ? run.params[name] : declared.get(name),
|
||||
fromFlow: !(name in run.params),
|
||||
})),
|
||||
...Object.keys(run.params)
|
||||
.filter((name) => !declared.has(name))
|
||||
.map((name) => ({ name, value: run.params[name], fromFlow: false })),
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<header className="flex flex-wrap items-center gap-3">
|
||||
@@ -113,16 +129,26 @@ export function RunDetail({ id }: { id: string }) {
|
||||
</Fact>
|
||||
</section>
|
||||
|
||||
{/* What the run actually ran with, which is not the same list as what it
|
||||
was passed: a flow's inputs *are* its parameters, and one left alone
|
||||
took the flow's own value. Both are drawn, and which is which is
|
||||
marked — reading a number off a chart is worth nothing if the other
|
||||
half of the setting is invisible. */}
|
||||
<section className={cn(CARD, "flex flex-col gap-2")}>
|
||||
<h2 className="font-medium text-sm">Parameters</h2>
|
||||
{Object.keys(run.params).length === 0 ? (
|
||||
<h2 className="font-medium text-sm">Inputs</h2>
|
||||
{fed.length === 0 ? (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
This run took its flow's own defaults.
|
||||
This flow declares no inputs, so there was nothing to choose.
|
||||
</p>
|
||||
) : (
|
||||
<dl className="grid gap-x-6 gap-y-1 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{Object.entries(run.params).map(([key, value]) => (
|
||||
<Entry key={key} name={key} value={value} />
|
||||
{fed.map(({ name, value, fromFlow }) => (
|
||||
<Entry
|
||||
key={name}
|
||||
name={name}
|
||||
value={value}
|
||||
note={fromFlow ? "default" : undefined}
|
||||
/>
|
||||
))}
|
||||
</dl>
|
||||
)}
|
||||
@@ -167,7 +193,16 @@ export function RunDetail({ id }: { id: string }) {
|
||||
* record like any other, and serialising it onto one truncated line answers
|
||||
* nothing.
|
||||
*/
|
||||
function Entry({ name, value }: { name: string; value: unknown }) {
|
||||
function Entry({
|
||||
name,
|
||||
value,
|
||||
note,
|
||||
}: {
|
||||
name: string
|
||||
value: unknown
|
||||
/** Where the value came from, when it was not this run. */
|
||||
note?: string
|
||||
}) {
|
||||
const structured = value !== null && typeof value === "object"
|
||||
return (
|
||||
<div
|
||||
@@ -176,7 +211,14 @@ function Entry({ name, value }: { name: string; value: unknown }) {
|
||||
structured ? "flex flex-col" : "flex justify-between",
|
||||
)}
|
||||
>
|
||||
<dt className={LABEL}>{name}</dt>
|
||||
<dt className={cn(LABEL, "flex items-baseline gap-1.5")}>
|
||||
{name}
|
||||
{note && (
|
||||
<span className="rounded-full border border-border px-1.5 text-[10px]">
|
||||
{note}
|
||||
</span>
|
||||
)}
|
||||
</dt>
|
||||
<dd
|
||||
className={cn(
|
||||
"min-w-0",
|
||||
|
||||
@@ -1,13 +1,27 @@
|
||||
import { useInfiniteQuery, useQuery } from "@tanstack/react-query"
|
||||
import {
|
||||
useInfiniteQuery,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from "@tanstack/react-query"
|
||||
import { Link } from "@tanstack/react-router"
|
||||
import { FlaskConical, X } from "lucide-react"
|
||||
import { useRef } from "react"
|
||||
import { Download, FlaskConical, Trash2, X } from "lucide-react"
|
||||
import { useRef, useState } from "react"
|
||||
|
||||
import type { fluksio__api__routes__runs__RunRow as RunRow } from "@/client"
|
||||
import {
|
||||
ConfirmDelete,
|
||||
useDeleteSelected,
|
||||
} from "@/components/Common/OverviewToolbar"
|
||||
import { MAX_SERIES } from "@/components/Common/UplotChart"
|
||||
import { ValuePreview } from "@/components/Flow/ValuePreview"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -34,15 +48,20 @@ import {
|
||||
import { OpenInDashboard } from "./OpenInDashboard"
|
||||
import {
|
||||
CARD,
|
||||
cancelThenDelete,
|
||||
exportMetrics,
|
||||
exportRuns,
|
||||
LIST_CAP,
|
||||
MAX_SELECTION,
|
||||
paramText,
|
||||
runKeys,
|
||||
runOverviewQueryOptions,
|
||||
runsInfiniteQueryOptions,
|
||||
STATUSES,
|
||||
STEP_AXIS,
|
||||
shortCommit,
|
||||
shortId,
|
||||
useFlowInputs,
|
||||
varyingKeys,
|
||||
} from "./queries"
|
||||
import { RunStatusBadge } from "./RunStatus"
|
||||
@@ -111,6 +130,24 @@ export function RunsScreen({
|
||||
put(already ? [] : shown)
|
||||
}
|
||||
|
||||
// What a download asks for: the picks when there are any, and otherwise
|
||||
// whatever the screen is currently filtered to. Either way it is what the
|
||||
// person looking at it would have called "these runs".
|
||||
const exportQuery = (format: string) =>
|
||||
new URLSearchParams(
|
||||
selected.length
|
||||
? { ids: selected.join(","), format }
|
||||
: { ...filters, format },
|
||||
)
|
||||
|
||||
const client = useQueryClient()
|
||||
const [confirming, setConfirming] = useState(false)
|
||||
const remove = useDeleteSelected(cancelThenDelete, "run", () => {
|
||||
setConfirming(false)
|
||||
update({ compare: undefined })
|
||||
client.invalidateQueries({ queryKey: runKeys.all })
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6 lg:flex-row">
|
||||
<FlowRail
|
||||
@@ -157,8 +194,55 @@ export function RunsScreen({
|
||||
<X className="ml-1 size-3" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-8"
|
||||
data-testid="export-runs"
|
||||
>
|
||||
<Download className="size-3.5" />
|
||||
Export
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onSelect={() => exportRuns(exportQuery("csv"))}>
|
||||
Runs table (.csv)
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onSelect={() => exportMetrics(exportQuery("csv"))}
|
||||
>
|
||||
Metrics (.csv)
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{selected.length > 0 && (
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
className="h-8"
|
||||
onClick={() => setConfirming(true)}
|
||||
aria-label={`Delete ${selected.length} runs`}
|
||||
data-testid="delete-selected"
|
||||
>
|
||||
<Trash2 className="size-3.5" />
|
||||
</Button>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<ConfirmDelete
|
||||
open={confirming}
|
||||
onOpenChange={setConfirming}
|
||||
names={selected.map(shortId)}
|
||||
noun="run"
|
||||
pending={remove.isPending}
|
||||
description="A run still going is cancelled first. What it recorded — its numbers, its nodes and the outputs other runs reuse from the cache — goes with it, and nothing brings it back."
|
||||
onConfirm={() => remove.mutate(selected)}
|
||||
/>
|
||||
|
||||
{isPending ? (
|
||||
<Skeleton className="h-64 w-full rounded-lg" />
|
||||
) : (
|
||||
@@ -417,8 +501,14 @@ function RunsTable({
|
||||
</div>
|
||||
</TableCell>
|
||||
{showFlow && (
|
||||
<TableCell className="text-muted-foreground text-sm">
|
||||
{run.flow}
|
||||
<TableCell className="text-sm">
|
||||
<Link
|
||||
to="/flows/$flowName"
|
||||
params={{ flowName: run.flow }}
|
||||
className="text-muted-foreground hover:underline"
|
||||
>
|
||||
{run.flow}
|
||||
</Link>
|
||||
</TableCell>
|
||||
)}
|
||||
<TableCell>
|
||||
@@ -576,6 +666,12 @@ function Compare({
|
||||
* grows downwards, where there is somewhere to grow.
|
||||
*/
|
||||
function ParamDiff({ rows }: { rows: RunRow[] }) {
|
||||
// What the flow declares, so a run that was never given a parameter reads as
|
||||
// the value it actually ran with rather than as a blank.
|
||||
// ponytail: only when the picks share one flow — spanning flows would mean a
|
||||
// declaration lookup per flow, and a sweep comparison never does.
|
||||
const one = rows.every((run) => run.flow === rows[0].flow)
|
||||
const declared = useFlowInputs(one ? rows[0].flow : undefined)
|
||||
const varying = varyingKeys(rows)
|
||||
// Not a parameter, but it is part of what produced the number, and in a
|
||||
// sweep it is often the only thing that moved.
|
||||
@@ -640,9 +736,16 @@ function ParamDiff({ rows }: { rows: RunRow[] }) {
|
||||
<TableCell key={key}>
|
||||
{key in run.params ? (
|
||||
<ParamValue value={run.params[key]} />
|
||||
) : declared.has(key) ? (
|
||||
// Not "empty": this run was never given the parameter, so
|
||||
// what it ran with is what the flow declares.
|
||||
<span className="flex items-baseline gap-1.5">
|
||||
<ParamValue value={declared.get(key)} />
|
||||
<span className="rounded-full border border-border px-1.5 text-[10px] text-muted-foreground">
|
||||
default
|
||||
</span>
|
||||
</span>
|
||||
) : (
|
||||
// Not "empty": this run was never given the parameter, and
|
||||
// took whatever the flow declares as its default.
|
||||
<span className="text-muted-foreground text-xs">unset</span>
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { OpenAPI, RunsService } from "@/client"
|
||||
import { flowQueryOptions } from "@/components/Flow/queries"
|
||||
import { apiToken } from "@/lib/portal"
|
||||
|
||||
/**
|
||||
@@ -147,6 +149,93 @@ export async function downloadArtifact(digest: string, name: string) {
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
/**
|
||||
* What a flow declares it can be given, by input name.
|
||||
*
|
||||
* A batch flow's inputs *are* its parameters — a run supplies values for the
|
||||
* ones it names and takes the flow's own for the rest — so this is what turns
|
||||
* `run.params` from "what was passed" into "what the run actually ran with".
|
||||
*
|
||||
* The declarations are the flow's *current* ones, while a run carries the
|
||||
* `flow_version` it was submitted against. An input added since is shown on an
|
||||
* older run as a default it never actually received.
|
||||
*/
|
||||
export function useFlowInputs(flow: string | undefined) {
|
||||
const { data } = useQuery({
|
||||
...flowQueryOptions(flow ?? ""),
|
||||
enabled: Boolean(flow),
|
||||
})
|
||||
const inputs = data?.definition.inputs
|
||||
return useMemo(
|
||||
() =>
|
||||
new Map<string, unknown>(
|
||||
(inputs ?? [])
|
||||
.filter((one) => Boolean(one.spec.name))
|
||||
.map((one) => [one.spec.name ?? "", one.initial ?? null]),
|
||||
),
|
||||
[inputs],
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the current selection as a file.
|
||||
*
|
||||
* The same trip `downloadArtifact` makes and for the same reason — the export
|
||||
* routes take a bearer token, which an anchor cannot carry. Not the generated
|
||||
* SDK either: it parses every body as JSON, and these stream csv.
|
||||
*/
|
||||
async function exportAs(what: "runs" | "metrics", query: URLSearchParams) {
|
||||
const token = apiToken()
|
||||
const answer = await fetch(
|
||||
`${OpenAPI.BASE}/api/v1/runs/export/${what}?${query}`,
|
||||
{ headers: token ? { Authorization: `Bearer ${token}` } : {} },
|
||||
)
|
||||
if (!answer.ok) throw new Error(`Could not export the ${what}`)
|
||||
const url = URL.createObjectURL(await answer.blob())
|
||||
const link = document.createElement("a")
|
||||
link.href = url
|
||||
link.download = `${what}.${query.get("format") ?? "csv"}`
|
||||
link.click()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
/** The runs themselves: one row each, with the parameters that varied. */
|
||||
export const exportRuns = (query: URLSearchParams) => exportAs("runs", query)
|
||||
|
||||
/** Every recorded number of the selection, one row per point. */
|
||||
export const exportMetrics = (query: URLSearchParams) =>
|
||||
exportAs("metrics", query)
|
||||
|
||||
/** How long a cancelled run is given to actually stop before delete gives up. */
|
||||
const SETTLE_TRIES = 30
|
||||
const SETTLE_WAIT_MS = 500
|
||||
|
||||
/**
|
||||
* Delete a run, cancelling it first if it is still going.
|
||||
*
|
||||
* The route refuses a live run rather than racing its driver, so the two steps
|
||||
* are the caller's to sequence. The wait is bounded and throws when it runs
|
||||
* out, which is what puts a stuck run in the partial-success toast by name
|
||||
* instead of hanging the button.
|
||||
*
|
||||
* ponytail: polling, because nothing pushes a run's status to a caller that is
|
||||
* not rendering it. The socket already carries run_finished if this ever needs
|
||||
* to be immediate.
|
||||
*/
|
||||
export async function cancelThenDelete(runId: string) {
|
||||
const run = await RunsService.readRun({ runId })
|
||||
if (isLive(run.status)) {
|
||||
await RunsService.cancelRun({ runId })
|
||||
let settled = false
|
||||
for (let tries = 0; tries < SETTLE_TRIES && !settled; tries++) {
|
||||
await new Promise((wake) => setTimeout(wake, SETTLE_WAIT_MS))
|
||||
settled = !isLive((await RunsService.readRun({ runId })).status)
|
||||
}
|
||||
if (!settled) throw new Error(`${shortId(runId)} did not stop`)
|
||||
}
|
||||
await RunsService.deleteRun({ runId })
|
||||
}
|
||||
|
||||
/**
|
||||
* Why a finished run can have nothing to draw.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user