Frontend addresses flows and dashboards by id: routes /flows/$flowId, /dashboards/$id and /view/$id, query keys, saves, lists, device pickers, search, brain and endpoint links and generated results dashboards go by id, while live values, issues, pauses and message names keep the key; tabs take the title from the document; creating uses POST and opens the issued id; the flow and dashboard panels show key and id with a copy button and a served HTTP or WebSocket node shows its hook URL under the flow id; specs create by POST and ids.spec.ts exercises issued ids

This commit is contained in:
2026-11-02 19:57:43 +01:00
parent fd637e0f1e
commit fa15522cb0
65 changed files with 1380 additions and 784 deletions
@@ -385,6 +385,8 @@ export function DashboardEditor({
edit: boolean
}) {
const [draft, setDraft] = useState<Dashboard>(dashboard)
// What the API, the routes and the devices know it by; never edited.
const id = dashboard.id!
const [selected, setSelected] = useState<string | null>(null)
// The face a round dashboard shows: the widget picked, or the one last
// picked or paged to once its settings are put away.
@@ -403,9 +405,9 @@ export function DashboardEditor({
const root = useCanvasRoot(draft)
const navigate = useNavigate()
const queryClient = useQueryClient()
const save = useSaveDashboard(dashboard.name)
const publish = usePublishDashboard(dashboard.name)
const discard = useDiscardDashboardDraft(dashboard.name)
const save = useSaveDashboard(id)
const publish = usePublishDashboard(id)
const discard = useDiscardDashboardDraft(id)
const [discardOpen, setDiscardOpen] = useState(false)
const { showSuccessToast, showErrorToast } = useCustomToast()
const copied = useCopiedWidget()
@@ -484,8 +486,7 @@ export function DashboardEditor({
}
const remove = useMutation({
mutationFn: () =>
DashboardsService.deleteDashboard({ dashboardId: draft.name }),
mutationFn: () => DashboardsService.deleteDashboard({ dashboardId: id }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: dashboardKeys.all })
navigate({ to: "/dashboards" })
@@ -590,7 +591,7 @@ export function DashboardEditor({
(devices?.data ?? []).find(
(device) =>
(device.dashboards ?? []).length > 1 &&
(device.dashboards ?? []).includes(draft.name),
(device.dashboards ?? []).includes(id),
)?.dashboards ?? null
// A round face has no room for one: a panel swipes between those instead.
const hasRail = Boolean(railDashboards) && !stacked && !round
@@ -598,13 +599,13 @@ export function DashboardEditor({
railDashboards && !round ? (
<PanelRail
dashboards={railDashboards}
current={draft.name}
current={id}
horizontal={stacked}
// Editing one dashboard of a panel and editing its neighbour are the
// same job, so the rail keeps whichever mode this one is in.
linkFor={(name) => ({
to: "/dashboards/$name",
params: { name },
linkFor={(other) => ({
to: "/dashboards/$id",
params: { id: other },
search: edit ? { edit: true } : {},
})}
/>
@@ -675,8 +676,8 @@ export function DashboardEditor({
setSelected(null)
setSettingsOpen(false)
navigate({
to: "/dashboards/$name",
params: { name: draft.name },
to: "/dashboards/$id",
params: { id },
search: next ? { edit: true } : {},
})
}
@@ -685,7 +686,7 @@ export function DashboardEditor({
const pickable = (widget: WidgetDef, grip = false) => (
<Pickable
widget={widget}
dashboard={draft.name}
dashboard={id}
grip={grip}
selected={widget.id === selected}
onPick={() => {
@@ -985,7 +986,7 @@ export function DashboardEditor({
asChild
>
<a
href={appPath(`/view/${draft.name}`)}
href={appPath(`/view/${id}`)}
target="_blank"
rel="noreferrer"
>
@@ -97,14 +97,14 @@ export function DashboardPalette({
<CommandGroup heading="Dashboards">
{dashboards.map((dashboard) => (
<CommandItem
key={dashboard.name}
key={dashboard.id}
value={`dashboard ${dashboard.name} ${dashboard.title}`}
onSelect={() =>
close(() =>
// Editing a neighbour is the same job, as on the rail.
navigate({
to: "/dashboards/$name",
params: { name: dashboard.name },
to: "/dashboards/$id",
params: { id: dashboard.id! },
search: { edit: true },
}),
)
@@ -536,7 +536,7 @@ function WidgetGrid({
issue={widgetIssue(widget)}
scroll={scrolls(widget)}
>
<WidgetBody widget={widget} dashboard={dashboard.name} />
<WidgetBody widget={widget} dashboard={dashboard.id!} />
</Frame>
)}
</motion.div>
@@ -28,20 +28,21 @@ export function PanelRail({
linkFor,
horizontal,
}: {
/** Dashboard ids, in the order the device carries them. */
dashboards: string[]
current: string
linkFor: (name: string) => LinkProps
linkFor: (id: string) => LinkProps
horizontal?: boolean
}) {
const { Rail } = useUi()
const box = useRef<HTMLDivElement>(null)
const still = useReducedMotion()
const entries = useQueries({
queries: dashboards.map((name) => dashboardQueryOptions(name)),
queries: dashboards.map((id) => dashboardQueryOptions(id)),
combine: (results) =>
results.map((result, index) => ({
name: dashboards[index],
label: result.data?.title || dashboards[index],
label: result.data?.title || result.data?.name || dashboards[index],
icon: result.data?.icon ?? "",
active: dashboards[index] === current,
link: linkFor(dashboards[index]),
@@ -16,7 +16,7 @@ import { cn } from "@/lib/utils"
* One dashboard filling whatever screen it landed on.
*
* The whole of what a wall panel draws, shared by the single-dashboard route
* (`/view/{name}`) and the paired-panel one (`/panel/{id}`) so a device shows
* (`/view/{id}`) and the paired-panel one (`/panel/{id}`) so a device shows
* the same thing either way — the second merely has a rail beside it.
*
* The dashboard's theme is stated by the route rather than here: on these two
@@ -601,7 +601,7 @@ export function RoundView({
>
<Face
widget={one}
dashboard={dashboard.name}
dashboard={dashboard.id!}
size={size}
editing={editing}
onPick={onPick && (() => onPick(one.id))}
@@ -80,8 +80,10 @@ export function RunsContextProvider({
const finals = new Map<string, LiveValue>()
if (primary) {
const at = primary.finished_at ? Date.parse(String(primary.finished_at)) : 0
// Results are named under the flow's key, which `flow` (its id) is not.
const namespace = primary.flow_name || primary.flow
for (const [key, value] of Object.entries(primary.result ?? {})) {
finals.set(key.includes(".") ? key : `${primary.flow}.${key}`, {
finals.set(key.includes(".") ? key : `${namespace}.${key}`, {
value,
ts: at ? at / 1000 : null,
})
@@ -105,7 +107,7 @@ export function RunsContextProvider({
)
})
const flow = primary?.flow ?? ""
const flow = primary?.flow_name || primary?.flow || ""
const context: DataContext = {
kind: "runs",
label:
+11 -2
View File
@@ -8,6 +8,7 @@ import { screensOf } from "@/components/Devices/ports"
import { devicesQueryOptions } from "@/components/Devices/queries"
import {
FieldLabel,
IdentitySection,
InfoTip,
PANEL_SECTION,
PanelSection,
@@ -241,6 +242,8 @@ function RunsSourceFields({
}) {
const { data: flows } = useQuery(runOverviewQueryOptions())
const mode = runs.ids?.length ? "ids" : runs.group ? "group" : "latest"
// The pick holds the flow's id; its metrics are named under its key.
const key = flows?.find((row) => row.flow === runs.flow)?.flow_name
return (
<div className="grid gap-2">
@@ -256,7 +259,7 @@ function RunsSourceFields({
<SelectContent>
{(flows ?? []).map((row) => (
<SelectItem key={row.flow} value={row.flow}>
{row.flow}
{row.flow_name || row.flow}
</SelectItem>
))}
</SelectContent>
@@ -271,7 +274,7 @@ function RunsSourceFields({
placeholder="Pick a metric"
filter={(message) =>
(message.dtype === "float" || message.dtype === "int") &&
(!runs.flow || message.name.startsWith(`${runs.flow}.`))
(!runs.flow || !key || message.name.startsWith(`${key}.`))
}
onPick={(metric) => onChange({ ...runs, metric })}
/>
@@ -1980,6 +1983,12 @@ export function DashboardPanel({
}
>
<div className="grid gap-5 p-4">
<IdentitySection
name={dashboard.name}
id={dashboard.id!}
help="The key is the dashboard's name. The id never changes: this page's address, the view link, devices and the API use it."
/>
<PanelSection
title="Rail icon"
help="Drawn on the rail when a panel carries more than one dashboard."
+19 -18
View File
@@ -8,9 +8,9 @@ import {
export const dashboardKeys = {
all: ["dashboards"] as const,
/** The working copy and the published document are two different reads. */
detail: (name: string, draft = false) =>
["dashboards", name, draft ? "draft" : "published"] as const,
/** By id. The working copy and the published document are two reads. */
detail: (id: string, draft = false) =>
["dashboards", id, draft ? "draft" : "published"] as const,
messages: ["messages"] as const,
history: (message: string) => ["messages", message, "history"] as const,
}
@@ -26,9 +26,9 @@ export const dashboardsQueryOptions = () => ({
* A wall panel asks for the published one, which is the whole point of the
* split: nothing half-arranged reaches the wall until someone publishes.
*/
export const dashboardQueryOptions = (name: string, draft = false) => ({
queryKey: dashboardKeys.detail(name, draft),
queryFn: () => DashboardsService.readDashboard({ dashboardId: name, draft }),
export const dashboardQueryOptions = (id: string, draft = false) => ({
queryKey: dashboardKeys.detail(id, draft),
queryFn: () => DashboardsService.readDashboard({ dashboardId: id, draft }),
})
/** Every message any flow declares — what a widget can be pointed at. */
@@ -46,44 +46,44 @@ export const messageHistoryQueryOptions = (message: string) => ({
*
* This writes the draft; panels keep showing the published document.
*/
export function useSaveDashboard(name: string) {
export function useSaveDashboard(id: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (body: DashboardDef_Input) =>
DashboardsService.saveDashboard({ dashboardId: name, requestBody: body }),
DashboardsService.saveDashboard({ dashboardId: id, requestBody: body }),
onSuccess: (saved) => {
queryClient.setQueryData(dashboardKeys.detail(name, true), saved)
queryClient.setQueryData(dashboardKeys.detail(id, true), saved)
queryClient.invalidateQueries({ queryKey: dashboardKeys.all })
},
})
}
/** Publish the unpublished changes, which is what puts them on the panels. */
export function usePublishDashboard(name: string) {
export function usePublishDashboard(id: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (version: number) =>
DashboardsService.publishDashboard({
dashboardId: name,
dashboardId: id,
requestBody: { version },
}),
onSuccess: (published) => {
queryClient.setQueryData(dashboardKeys.detail(name, true), published)
queryClient.setQueryData(dashboardKeys.detail(name), published)
queryClient.setQueryData(dashboardKeys.detail(id, true), published)
queryClient.setQueryData(dashboardKeys.detail(id), published)
queryClient.invalidateQueries({ queryKey: dashboardKeys.all })
},
})
}
/** Throw the unpublished edit away; the panels keep showing what they had. */
export function useDiscardDashboardDraft(name: string) {
export function useDiscardDashboardDraft(id: string) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: () =>
DashboardsService.discardDashboardDraft({ dashboardId: name }),
DashboardsService.discardDashboardDraft({ dashboardId: id }),
onSuccess: (published) => {
queryClient.setQueryData(dashboardKeys.detail(name, true), published)
queryClient.setQueryData(dashboardKeys.detail(name), published)
queryClient.setQueryData(dashboardKeys.detail(id, true), published)
queryClient.setQueryData(dashboardKeys.detail(id), published)
queryClient.invalidateQueries({ queryKey: dashboardKeys.all })
},
})
@@ -116,7 +116,8 @@ export function usePublishMessage() {
requestBody: {
value,
source_kind: "dashboard",
// Matches the endpoint id the canvas builds for this widget.
// Matches the endpoint id the canvas builds for this widget,
// `dashboard:<dashboard id>:<widget>`.
source_id:
dashboard && widget ? `dashboard:${dashboard}:${widget}` : "",
source_label: label ?? widget ?? "Dashboard",
@@ -867,6 +867,7 @@ function DropdownWidget({ widget, dashboard }: WidgetProps) {
// ---------------------------------------------------------------------------
/** `dashboard` is the dashboard's id, which a control credits what it sends to. */
export type WidgetProps = { widget: WidgetDef; dashboard: string }
const RENDERERS: Partial<