Overviews: icon toolbar, dashboard drafts, publish all

Both overviews carried the same toolbar twice, left-aligned, with a search
field permanently taking a row of width. One `OverviewToolbar` now serves
them: the search folds into an icon and expands again on click (Escape puts
it away and hands focus back), create is a `+`, and everything sits right of
the page. Each page keeps its own create dialog — the toolbar only renders
the trigger — so the testids the runtime spec and the capture script drive
stayed where they were.

Dashboards get the flow store's draft/publish split. The editor autosaves
`dashboard.draft.json` beside `dashboard.json`; `/view/{name}`, `bindings_for`
and `history_requirements` keep reading the published file, so a wall panel
sees an edit only once someone publishes it. `POST /dashboards/{name}/publish`
and `/discard` mirror the flow routes down to the version precondition and the
409, `GET /dashboards/{name}?draft=true` is what the editor asks for, and the
dock grows the same Publish button — which flushes a queued save first, so an
autosave in flight is not published around. Creating a dashboard still writes
the published file directly: an empty document on a panel is harmless, and it
keeps the store free of a never-published case.

"Publish all" is a checkmark in the toolbar, live only when something actually
has `has_draft`. A summary carries no version and publish needs the one it is
based on, so each document's detail is read immediately before its publish —
honest against a stale list, and no version-less backend path to maintain.
Failures are counted rather than swallowed: three of five fails says so and
names the three.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XC2jX6Hdj7pxGGKzBTrbqB
This commit is contained in:
2026-08-17 11:57:11 +02:00
co-authored by Claude Opus 5
parent 683c25b26d
commit 9351a86eec
14 changed files with 713 additions and 144 deletions
+67 -52
View File
@@ -1,9 +1,13 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router"
import { Plus, Workflow } from "lucide-react"
import { Workflow } from "lucide-react"
import { useState } from "react"
import { FlowsService } from "@/client"
import {
OverviewToolbar,
usePublishAll,
} from "@/components/Common/OverviewToolbar"
import { flowKeys, flowsQueryOptions } from "@/components/Flow/queries"
import { Button } from "@/components/ui/button"
import {
@@ -13,7 +17,6 @@ import {
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import useCustomToast from "@/hooks/useCustomToast"
@@ -50,6 +53,20 @@ function Flows() {
onError: handleError.bind(showErrorToast),
})
// A summary carries no version, and publishing needs the one it is based
// on — so each flow's current version is read right before it is published.
const publishAll = usePublishAll(
async (flow) => {
const detail = await FlowsService.readFlow({ name: flow })
return FlowsService.publishFlow({
name: flow,
requestBody: { version: detail.definition.version ?? 1 },
})
},
"flow",
() => queryClient.invalidateQueries({ queryKey: flowKeys.all }),
)
const slug = name
.trim()
.toLowerCase()
@@ -58,6 +75,9 @@ function Flows() {
const flows = (data?.data ?? []).filter((flow) =>
`${flow.name} ${flow.title ?? ""}`.toLowerCase().includes(needle),
)
const drafts = (data?.data ?? [])
.filter((flow) => flow.has_draft)
.map((flow) => flow.name)
return (
<div className="grid gap-6">
@@ -69,57 +89,52 @@ function Flows() {
</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)}
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
<OverviewToolbar
search={search}
onSearch={setSearch}
searchLabel="Search flows"
searchTestId="search-flows"
createLabel="New flow"
createTestId="new-flow"
draftCount={drafts.length}
publishing={publishAll.isPending}
onPublishAll={() => publishAll.mutate(drafts)}
/>
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
<DialogTrigger asChild>
<Button variant="secondary" data-testid="new-flow">
<Plus />
Create
</Button>
</DialogTrigger>
<DialogContent>
<form
className="grid gap-4"
onSubmit={(event) => {
event.preventDefault()
if (NAME.test(slug)) create.mutate(slug)
}}
>
<DialogHeader>
<DialogTitle>New flow</DialogTitle>
<DialogDescription>
Flows are small on purpose. Name this one after what it does.
</DialogDescription>
</DialogHeader>
<Input
value={name}
placeholder="heating"
aria-label="New flow name"
autoComplete="off"
data-testid="new-flow-name"
onChange={(event) => setName(event.target.value)}
/>
<DialogFooter>
<Button
type="submit"
disabled={!NAME.test(slug) || create.isPending}
data-testid="create-flow"
>
Create flow
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
</div>
<DialogContent>
<form
className="grid gap-4"
onSubmit={(event) => {
event.preventDefault()
if (NAME.test(slug)) create.mutate(slug)
}}
>
<DialogHeader>
<DialogTitle>New flow</DialogTitle>
<DialogDescription>
Flows are small on purpose. Name this one after what it does.
</DialogDescription>
</DialogHeader>
<Input
value={name}
placeholder="heating"
aria-label="New flow name"
autoComplete="off"
data-testid="new-flow-name"
onChange={(event) => setName(event.target.value)}
/>
<DialogFooter>
<Button
type="submit"
disabled={!NAME.test(slug) || create.isPending}
data-testid="create-flow"
>
Create flow
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
{flows.length === 0 ? (
<p className="text-sm text-muted-foreground">