Build dashboards you can actually look at and press

Widgets bind to a message name and read it live off the socket the editor
already had — lifted out of the flow editor so a dashboard route gets the
same values, which also gives the home page live data for free.

The input widgets close the loop the other way: a slider publishes into
the graph and whatever consumes that message runs. Verified end to end in
the running app — moving a slider set a flow input, and the stat bound to
what the flow computed from it followed.

View mode is plain CSS grid. A wall panel that only displays should not
download the code that lets someone drag things around, and it now does
not. Editing is a widget picker, a per-widget width control and a
settings card fed by the message catalog.

No new dependencies: the slider is a range input, the gauge is an arc,
and the markdown is a five-line subset. Charts are the one widget still
missing — they need a charting library and the chart tokens the design
guidelines reserved — so they are stored and validated but not offered.
This commit is contained in:
2026-08-16 09:33:02 +02:00
parent be31cada87
commit 113fdb5a26
15 changed files with 1388 additions and 7 deletions
@@ -0,0 +1,112 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router"
import { LayoutDashboard, Plus } from "lucide-react"
import { useState } from "react"
import { DashboardsService } from "@/client"
import {
dashboardKeys,
dashboardsQueryOptions,
} from "@/components/Dashboard/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/dashboards/")({
component: Dashboards,
})
function Dashboards() {
const { data } = useQuery(dashboardsQueryOptions())
const queryClient = useQueryClient()
const navigate = useNavigate()
const { showErrorToast } = useCustomToast()
const [name, setName] = useState("")
const create = useMutation({
mutationFn: (dashboard: string) =>
DashboardsService.createDashboard({ name: dashboard }),
onSuccess: (created) => {
queryClient.invalidateQueries({ queryKey: dashboardKeys.all })
navigate({
to: "/dashboards/$name",
params: { name: created.name },
search: { edit: true },
})
},
onError: handleError.bind(showErrorToast),
})
const dashboards = data?.data ?? []
// The store only accepts this shape, so say so before the request does.
const slug = name
.trim()
.toLowerCase()
.replace(/[^a-z0-9]+/g, "_")
return (
<div className="grid gap-6">
<div className="grid gap-1">
<h1 className="text-2xl">Dashboards</h1>
<p className="text-sm text-muted-foreground">
What a wall panel shows, built from the messages your flows carry.
</p>
</div>
<form
className="flex max-w-md items-center gap-2"
onSubmit={(event) => {
event.preventDefault()
if (slug) create.mutate(slug)
}}
>
<Input
value={name}
placeholder="New dashboard"
aria-label="New dashboard name"
data-testid="new-dashboard-name"
onChange={(event) => setName(event.target.value)}
/>
<Button
type="submit"
variant="secondary"
disabled={!slug || create.isPending}
data-testid="create-dashboard"
>
<Plus />
Create
</Button>
</form>
{dashboards.length === 0 ? (
<p className="text-sm text-muted-foreground">
No dashboards yet. Name one above to start.
</p>
) : (
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{dashboards.map((dashboard) => (
<Link
key={dashboard.name}
to="/dashboards/$name"
params={{ name: dashboard.name }}
className="grid gap-1 rounded-lg border border-border bg-card p-4 shadow-e1 transition-colors hover:bg-accent/50"
data-testid="dashboard-card"
>
<span className="flex items-center gap-2">
<LayoutDashboard className="size-4 text-muted-foreground" />
{dashboard.title || dashboard.name}
</span>
<span className="text-sm text-muted-foreground">
{dashboard.widget_count} widget
{dashboard.widget_count === 1 ? "" : "s"} ·{" "}
{dashboard.page_count} page
{dashboard.page_count === 1 ? "" : "s"}
</span>
</Link>
))}
</div>
)}
</div>
)
}