Rework the dashboards onto the flow canvas

One shell for both editors. Flows and dashboards each get a searchable
overview under the padded shell, their editors move to the full-bleed
canvas, and the floating chrome is shared: a title bar that only says
what you are looking at, and a bottom dock carrying everything else —
the flow bar's status, settings and Publish moved down there, the
add-flow button moved to the overview.

Dashboards gain the rest of M4's visualization work:

- widgets are picked by clicking them, with the header as the drag
  handle so a slider still slides and a switch still flips while
  editing; settings moved into the flows' SidePanel
- react-grid-layout for drag and edge-resize, so the stored x/y finally
  mean something; a dashboard nobody arranged is shelf-packed once
- a per-dashboard grid size, so a panel can be matched to its screen
- the chart widget, drawn with uPlot: several messages on one axis, fed
  from the stored history plus the live socket tail, coloured from the
  new --chart-1..5 ramp
- /view/{name}: the URL a wall panel is pointed at — no sidebar, no
  footer, no editing, and no editor code, since routes are split
- a widget wired to a payload type it cannot carry, or wired to nothing
  at all, carries the same red dot a failing node does; the picker
  records the type it bound and WidgetDef refuses a mismatch on save
This commit is contained in:
2026-08-16 17:13:10 +02:00
parent 391d0aea5d
commit 42244196a1
24 changed files with 1799 additions and 1558 deletions
+133
View File
@@ -0,0 +1,133 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router"
import { Plus, Workflow } from "lucide-react"
import { useState } from "react"
import { FlowsService } from "@/client"
import { flowKeys, flowsQueryOptions } from "@/components/Flow/queries"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import useCustomToast from "@/hooks/useCustomToast"
import { handleError } from "@/utils"
export const Route = createFileRoute("/_layout/flows/")({
component: Flows,
head: () => ({ meta: [{ title: "Flows - Fluksio" }] }),
})
/** The shape the store accepts, so a bad name is caught before the request. */
const NAME = /^[a-z][a-z0-9_]*$/
function Flows() {
const { data } = useQuery(flowsQueryOptions())
const queryClient = useQueryClient()
const navigate = useNavigate()
const { showErrorToast } = useCustomToast()
const [name, setName] = useState("")
const [search, setSearch] = useState("")
const create = useMutation({
mutationFn: (flow: string) =>
FlowsService.saveFlow({
name: flow,
requestBody: { name: flow, nodes: [], inputs: [] },
}),
onSuccess: (_saved, flow) => {
queryClient.invalidateQueries({ queryKey: flowKeys.all })
navigate({ to: "/flows/$flowName", params: { flowName: flow } })
},
onError: handleError.bind(showErrorToast),
})
const slug = name
.trim()
.toLowerCase()
.replace(/[^a-z0-9]+/g, "_")
const needle = search.trim().toLowerCase()
const flows = (data?.data ?? []).filter((flow) =>
`${flow.name} ${flow.title ?? ""}`.toLowerCase().includes(needle),
)
return (
<div className="grid gap-6">
<div className="grid gap-1">
<h1 className="text-2xl">Flows</h1>
<p className="text-sm text-muted-foreground">
A flow is a handful of nodes passing messages to each other. Keep them
small and name them after what they do.
</p>
</div>
<div className="flex flex-wrap items-center gap-2">
<Input
value={search}
placeholder="Search flows"
aria-label="Search flows"
className="max-w-xs"
data-testid="search-flows"
onChange={(event) => setSearch(event.target.value)}
/>
<form
className="flex items-center gap-2"
onSubmit={(event) => {
event.preventDefault()
if (NAME.test(slug)) create.mutate(slug)
}}
>
<Input
value={name}
placeholder="New flow"
aria-label="New flow name"
data-testid="new-flow-name"
onChange={(event) => setName(event.target.value)}
/>
<Button
type="submit"
variant="secondary"
disabled={!NAME.test(slug) || create.isPending}
data-testid="create-flow"
>
<Plus />
Create
</Button>
</form>
</div>
{flows.length === 0 ? (
<p className="text-sm text-muted-foreground">
{needle
? "No flow matches that."
: "No flows yet. Name one above to start."}
</p>
) : (
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{flows.map((flow) => (
<Link
key={flow.name}
to="/flows/$flowName"
params={{ flowName: flow.name }}
className="grid gap-1 rounded-lg border border-border bg-card p-4 shadow-e1 transition-colors hover:bg-accent/50"
data-testid="flow-card"
>
<span className="flex items-center gap-2">
<Workflow className="size-4 text-muted-foreground" />
{flow.title || flow.name}
{flow.has_draft ? (
<span className="size-1.5 shrink-0 rounded-full bg-primary">
<span className="sr-only">Unpublished changes</span>
</span>
) : null}
</span>
<span className="text-sm text-muted-foreground">
{flow.node_count ?? 0} node
{flow.node_count === 1 ? "" : "s"} ·{" "}
{flow.enabled === false ? "stopped" : "running"}
{flow.error_count ? ` · ${flow.error_count} to fix` : ""}
</span>
</Link>
))}
</div>
)}
</div>
)
}