feat(ui): workflow canvas fills the editor; cards say what they are; one step menu for pointer, keyboard and touch (#1954)

This commit is contained in:
sam committed 2026-11-13 17:54:29 +11:00
1 parent 9d8e4f68ab
commit 6516477b20
6 files changed
+48 -34

No files matched your search

+2 -2
View File
@@ -24,10 +24,10 @@ const path = computed(() =>
<BaseEdge :id="id" :path="path[0]" :class="['workflow-flow-edge', data?.trace && `trace-${data.trace}`]" /> <BaseEdge :id="id" :path="path[0]" :class="['workflow-flow-edge', data?.trace && `trace-${data.trace}`]" />
<EdgeLabelRenderer v-if="data?.editable && data.insertAfter !== undefined"> <EdgeLabelRenderer v-if="data?.editable && data.insertAfter !== undefined">
<div <div
class="workflow-insert absolute p-3 opacity-0 transition-opacity focus-within:opacity-100 hover:opacity-100 has-[[data-state=open]]:opacity-100" class="workflow-insert absolute p-3 opacity-0 transition-opacity focus-within:opacity-100 hover:opacity-100 pointer-coarse:opacity-100 has-[[data-state=open]]:opacity-100"
:style="{ transform: `translate(-50%, -50%) translate(${path[1]}px, ${path[2]}px)`, pointerEvents: 'all' }" :style="{ transform: `translate(-50%, -50%) translate(${path[1]}px, ${path[2]}px)`, pointerEvents: 'all' }"
> >
<AddStepMenu :types="data.types" :label="data.insertAfter.length > 2 ? `Add a step in ${data.insertAfter[3]}` : undefined" @pick="data.onInsert(data.insertAfter!, $event)" /> <AddStepMenu :types="data.types" :label="data.insertAfter.length > 2 ? `Add a step in ${data.insertAfter.at(-2)}` : undefined" @pick="data.onInsert(data.insertAfter!, $event)" />
</div> </div>
</EdgeLabelRenderer> </EdgeLabelRenderer>
</template> </template>
+16 -21
View File
@@ -1,12 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { stageStatusMeta } from "@/tasks/stage-rail"; import { stageStatusMeta } from "@/tasks/stage-rail";
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from "vue"; import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { Handle, Position } from "@vue-flow/core"; import { Handle, Position } from "@vue-flow/core";
import { CircleAlert, CircleCheck, CircleMinus, CircleX, Copy, EllipsisVertical, Flag, LoaderCircle, Pencil, Play, Repeat, Settings2, SkipForward, Tag, Trash2, Workflow, Zap, BookOpen, CalendarClock } from "@lucide/vue"; import { CircleAlert, CircleCheck, CircleMinus, CircleX, EllipsisVertical, Flag, LoaderCircle, Play, Repeat, Settings2, SkipForward, Tag, Workflow, Zap, BookOpen, CalendarClock } from "@lucide/vue";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { duration } from "@/lib/format"; import { duration } from "@/lib/format";
import { stepIcon } from "./step-icons"; import { stepIcon } from "./step-icons";
@@ -19,8 +17,12 @@ export interface StepCardData extends StepNodeData {
onToggle?: () => void; onToggle?: () => void;
onResize?: (height: number) => void; onResize?: (height: number) => void;
onRename?: (name: string) => void; onRename?: (name: string) => void;
onDuplicate?: () => void;
onRemove?: () => void; onRemove?: () => void;
/** Opens the canvas's step menu, the one right-click opens, at the card. */
onMenu?: (event: MouseEvent) => void;
/** The canvas menu's Rename asked this card to start renaming. */
renameRequested?: boolean;
onRenameDone?: () => void;
} }
const props = defineProps<{ data: StepCardData }>(); const props = defineProps<{ data: StepCardData }>();
@@ -89,6 +91,9 @@ onBeforeUnmount(() => observer?.disconnect());
const renaming = ref(false); const renaming = ref(false);
const nameInput = ref<InstanceType<typeof Input> | null>(null); const nameInput = ref<InstanceType<typeof Input> | null>(null);
watch(() => props.data.renameRequested, (requested) => {
if (requested) void rename();
});
async function rename(): Promise<void> { async function rename(): Promise<void> {
renaming.value = true; renaming.value = true;
await nextTick(); await nextTick();
@@ -97,6 +102,7 @@ async function rename(): Promise<void> {
function commitRename(event: Event): void { function commitRename(event: Event): void {
if (!renaming.value) return; if (!renaming.value) return;
renaming.value = false; renaming.value = false;
props.data.onRenameDone?.();
// A step id is a stable identifier that template references name, so a // A step id is a stable identifier that template references name, so a
// typed title becomes lowercase words joined by hyphens. // typed title becomes lowercase words joined by hyphens.
const name = (event.target as HTMLInputElement).value const name = (event.target as HTMLInputElement).value
@@ -128,9 +134,9 @@ function commitRename(event: Event): void {
@click="data.onToggle?.()" @click="data.onToggle?.()"
> >
<div class="flex items-center gap-1.5"> <div class="flex items-center gap-1.5">
<Badge variant="outline" class="max-w-40 gap-1 bg-background"> <span class="flex min-w-0 items-center gap-1 text-caption text-fg-muted">
<component :is="badge.icon" class="text-link" aria-hidden="true" /><span class="truncate" :title="badge.label">{{ badge.label }}</span> <component :is="badge.icon" class="size-3.5 shrink-0 text-link" :aria-label="badge.label" /><span v-if="badge.label !== data.title" class="truncate" :title="badge.label">{{ badge.label }}</span>
</Badge> </span>
<span v-if="data.run?.duration_ms !== undefined" class="ml-auto font-mono text-caption text-fg-subtle">{{ duration(data.run.duration_ms) }}</span> <span v-if="data.run?.duration_ms !== undefined" class="ml-auto font-mono text-caption text-fg-subtle">{{ duration(data.run.duration_ms) }}</span>
<component :is="status.icon" v-if="status" class="size-4 shrink-0" :class="[status.class, data.run?.duration_ms === undefined && 'ml-auto']" :aria-label="status.label" :title="data.run?.error || status.label" /> <component :is="status.icon" v-if="status" class="size-4 shrink-0" :class="[status.class, data.run?.duration_ms === undefined && 'ml-auto']" :aria-label="status.label" :title="data.run?.error || status.label" />
<span v-else class="ml-auto" /> <span v-else class="ml-auto" />
@@ -147,7 +153,7 @@ function commitRename(event: Event): void {
:placeholder="stepTitle(data.type)" :placeholder="stepTitle(data.type)"
@click.stop @click.stop
@keydown.enter.prevent="commitRename" @keydown.enter.prevent="commitRename"
@keydown.esc="renaming = false" @keydown.esc="renaming = false; data.onRenameDone?.()"
@blur="commitRename" @blur="commitRename"
/> />
<span v-else class="truncate" :title="data.title">{{ data.title }}</span> <span v-else class="truncate" :title="data.title">{{ data.title }}</span>
@@ -175,18 +181,7 @@ function commitRename(event: Event): void {
<p v-if="data.run?.error" class="mt-1 line-clamp-2 text-caption text-danger" :title="data.run.error">{{ data.run.error }}</p> <p v-if="data.run?.error" class="mt-1 line-clamp-2 text-caption text-danger" :title="data.run.error">{{ data.run.error }}</p>
</template> </template>
</component> </component>
<DropdownMenu v-if="data.editable && data.kind === 'step'"> <Button v-if="data.editable && data.kind === 'step' && data.onMenu" variant="ghost" size="icon-xs" class="nodrag nopan absolute top-2.5 right-1.5" aria-label="Step actions" aria-haspopup="menu" @click.stop="data.onMenu($event)"><EllipsisVertical /></Button>
<DropdownMenuTrigger as-child>
<Button variant="ghost" size="icon-xs" class="nodrag nopan absolute top-2.5 right-1.5" aria-label="Step actions" @click.stop><EllipsisVertical /></Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" class="w-40">
<DropdownMenuItem @select="data.onToggle?.()"><Pencil />Edit</DropdownMenuItem>
<DropdownMenuItem @select="rename"><Pencil />Rename</DropdownMenuItem>
<DropdownMenuItem v-if="!['parallel', 'switch'].includes(data.type)" @select="data.onDuplicate?.()"><Copy />Duplicate</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" @select="data.onRemove?.()"><Trash2 />Delete</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Transition enter-from-class="opacity-0 -translate-y-1" enter-active-class="transition duration-200" leave-to-class="opacity-0" leave-active-class="transition duration-100"> <Transition enter-from-class="opacity-0 -translate-y-1" enter-active-class="transition duration-200" leave-to-class="opacity-0" leave-active-class="transition duration-100">
<div v-if="data.expanded" class="nodrag nopan nowheel cursor-auto border-t border-border" @click.stop> <div v-if="data.expanded" class="nodrag nopan nowheel cursor-auto border-t border-border" @click.stop>
<slot /> <slot />
+7 -3
View File
@@ -18,6 +18,7 @@ import type { StageRun } from "./workflow-graph";
const props = defineProps<{ task: TaskRecord; attempt: number; stage: StageRun; stages: StageRun[] }>(); const props = defineProps<{ task: TaskRecord; attempt: number; stage: StageRun; stages: StageRun[] }>();
const events = ref<TaskEvent[]>([]); const events = ref<TaskEvent[]>([]);
const changes = ref<ChangesState>(); const changes = ref<ChangesState>();
const logOpen = ref(false);
const logs = ref<LogState | null>(); const logs = ref<LogState | null>();
const activityError = ref(""); const activityError = ref("");
const changesError = ref(""); const changesError = ref("");
@@ -146,14 +147,17 @@ const scopedLogs = computed(() => logs.value ? { ...logs.value, entries: (logs.v
<li v-for="(event, i) in recorded" :key="i" class="px-3 py-2 text-caption break-words whitespace-pre-wrap">{{ event.detail }}</li> <li v-for="(event, i) in recorded" :key="i" class="px-3 py-2 text-caption break-words whitespace-pre-wrap">{{ event.detail }}</li>
</ul> </ul>
</section> </section>
<section class="space-y-3"> <!-- Only a step that captured changes, or failed to read them, has this. -->
<section v-if="captures.length || changesError" class="space-y-3">
<h3 class="text-caption font-medium uppercase text-fg-muted">Captured changes</h3> <h3 class="text-caption font-medium uppercase text-fg-muted">Captured changes</h3>
<p v-if="changesError" role="alert" class="text-danger">{{ changesError }}</p> <p v-if="changesError" role="alert" class="text-danger">{{ changesError }}</p>
<ChangeCapture v-for="(capture, i) in captures" :key="i" :capture="capture" :task="task" /> <ChangeCapture v-for="(capture, i) in captures" :key="i" :capture="capture" :task="task" />
</section> </section>
<!-- The log opens on demand, like the transcript: a table this wide
crowds the card when all it needs to say is how the step went. -->
<section class="space-y-2"> <section class="space-y-2">
<h3 class="text-caption font-medium uppercase text-fg-muted">Log</h3> <Button type="button" variant="link" size="xs" class="px-0 text-caption font-medium uppercase text-fg-muted" :aria-expanded="logOpen" @click="logOpen = !logOpen">Log</Button>
<TaskLogs :state="scopedLogs" :attempt="attempt" :filterable="false" /> <TaskLogs v-if="logOpen" :state="scopedLogs" :attempt="attempt" :filterable="false" />
</section> </section>
</div> </div>
</template> </template>
+19 -4
View File
@@ -73,7 +73,7 @@ const graph = computed(() => {
const laid = withRuns(workflowGraph(props.yaml), props.stages ?? []); const laid = withRuns(workflowGraph(props.yaml), props.stages ?? []);
if (!props.types?.length) return laid; if (!props.types?.length) return laid;
// Workflow-wide settings sit on a card above the trigger. // Workflow-wide settings sit on a card above the trigger.
const workflow: GraphNode = { id: "workflow", type: "step", position: { x: 0, y: TOP }, data: { kind: "workflow", key: "workflow", title: props.title || "Workflow", type: "", detail: props.summary ?? "" } }; const workflow: GraphNode = { id: "workflow", type: "step", position: { x: 0, y: TOP }, data: { kind: "workflow", key: "workflow", title: "Settings", type: "", detail: props.summary ?? "" } };
return { nodes: [workflow, ...laid.nodes], edges: [{ id: "flow-workflow-start", source: "workflow", target: "start", kind: "flow" as const }, ...laid.edges] }; return { nodes: [workflow, ...laid.nodes], edges: [{ id: "flow-workflow-start", source: "workflow", target: "start", kind: "flow" as const }, ...laid.edges] };
}); });
const stepCount = computed(() => graph.value.nodes.filter((node) => node.data.path?.length === 2).length); const stepCount = computed(() => graph.value.nodes.filter((node) => node.data.path?.length === 2).length);
@@ -121,8 +121,10 @@ function card(node: GraphNode): GraphNode {
if (editable.value) { if (editable.value) {
if (path) { if (path) {
extra.onRename = (name: string) => emit("rename", path, name); extra.onRename = (name: string) => emit("rename", path, name);
extra.onDuplicate = () => emit("duplicate", path);
extra.onRemove = () => emit("remove", path); extra.onRemove = () => emit("remove", path);
extra.onMenu = (event: MouseEvent) => openMenu(event, data);
extra.renameRequested = renaming.value === key;
extra.onRenameDone = () => (renaming.value = null);
} }
} }
return { ...node, data: { ...data, ...extra } }; return { ...node, data: { ...data, ...extra } };
@@ -194,7 +196,10 @@ const edges = computed(() =>
type: "smoothstep", type: "smoothstep",
pathOptions: { offset: offset ?? 20, borderRadius: 8 }, pathOptions: { offset: offset ?? 20, borderRadius: 8 },
class: "workflow-data-edge", class: "workflow-data-edge",
data: { label }, // Vue Flow draws edge.label; it never reads data.label.
label,
labelBgPadding: [4, 2] as [number, number],
labelBgBorderRadius: 4,
}, },
), ),
); );
@@ -271,8 +276,17 @@ function openMenu(event: MouseEvent, step?: StepNodeData): void {
if (!editable.value) return; if (!editable.value) return;
event.preventDefault(); event.preventDefault();
const box = container.value?.getBoundingClientRect(); const box = container.value?.getBoundingClientRect();
menu.value = { open: true, x: event.clientX - (box?.left ?? 0), y: event.clientY - (box?.top ?? 0), step, seq: menu.value.seq + 1 }; // A keyboard press has no pointer position: the menu opens under the button.
let { clientX: x, clientY: y } = event;
if (!x && !y && event.currentTarget instanceof HTMLElement) {
const button = event.currentTarget.getBoundingClientRect();
x = button.left;
y = button.bottom;
}
menu.value = { open: true, x: x - (box?.left ?? 0), y: y - (box?.top ?? 0), step, seq: menu.value.seq + 1 };
} }
// The step the menu's Rename asked to rename; its card shows the name field.
const renaming = ref<string | null>(null);
function onNodeMenu({ event, node }: NodeMouseEvent): void { function onNodeMenu({ event, node }: NodeMouseEvent): void {
if (node.type !== "step" || (node.data as StepNodeData).kind === "workflow") return; if (node.type !== "step" || (node.data as StepNodeData).kind === "workflow") return;
openMenu(event as MouseEvent, node.data as StepNodeData); openMenu(event as MouseEvent, node.data as StepNodeData);
@@ -374,6 +388,7 @@ const beforePath = computed(() => menuPath.value ? [...menuPath.value.slice(0, -
<DropdownMenuSeparator /> <DropdownMenuSeparator />
</template> </template>
<DropdownMenuItem @select="emit('toggle', JSON.stringify(menuPath))"><Pencil />Edit</DropdownMenuItem> <DropdownMenuItem @select="emit('toggle', JSON.stringify(menuPath))"><Pencil />Edit</DropdownMenuItem>
<DropdownMenuItem @select="renaming = JSON.stringify(menuPath)"><Pencil />Rename</DropdownMenuItem>
<DropdownMenuSub> <DropdownMenuSub>
<DropdownMenuSubTrigger>Insert before</DropdownMenuSubTrigger> <DropdownMenuSubTrigger>Insert before</DropdownMenuSubTrigger>
<DropdownMenuSubContent class="w-52"><StepTypeItems :types="typesAt(menuPath)" @pick="emit('insert', beforePath, $event)" /></DropdownMenuSubContent> <DropdownMenuSubContent class="w-52"><StepTypeItems :types="typesAt(menuPath)" @pick="emit('insert', beforePath, $event)" /></DropdownMenuSubContent>
+1 -1
View File
@@ -533,7 +533,7 @@ onBeforeUnmount(() => yamlObserver?.disconnect());
<!-- Kept mounted so an Archie turn started here still finishes, unlocks the <!-- Kept mounted so an Archie turn started here still finishes, unlocks the
editor and loads its draft when the operator switches tabs. --> editor and loads its draft when the operator switches tabs. -->
<TabsContent value="canvas" force-mount class="space-y-2 data-[state=inactive]:hidden max-md:flex max-md:min-h-0 max-md:flex-col"> <TabsContent value="canvas" force-mount class="space-y-2 data-[state=inactive]:hidden max-md:flex max-md:min-h-0 max-md:flex-col">
<div class="relative flex h-[calc(100dvh-22rem)] min-h-[26rem] flex-col max-md:h-auto max-md:min-h-0 max-md:flex-1"> <div class="relative flex h-[calc(100dvh-14rem)] min-h-[26rem] flex-col max-md:h-auto max-md:min-h-0 max-md:flex-1">
<Alert v-if="restartError" variant="destructive" class="absolute bottom-16 left-14 z-10 max-w-xl rounded-md border border-danger/40 bg-card px-3 py-2 shadow-lg"><AlertDescription>{{ restartError }}</AlertDescription></Alert> <Alert v-if="restartError" variant="destructive" class="absolute bottom-16 left-14 z-10 max-w-xl rounded-md border border-danger/40 bg-card px-3 py-2 shadow-lg"><AlertDescription>{{ restartError }}</AlertDescription></Alert>
<WorkflowCanvas <WorkflowCanvas
class="h-auto min-h-0 flex-1" class="h-auto min-h-0 flex-1"
+3 -3
View File
@@ -13,7 +13,6 @@ import {
EmptyTitle, EmptyTitle,
} from "@/components/ui/empty"; } from "@/components/ui/empty";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { Card } from "@/components/ui/card";
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu"; import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/ui/context-menu";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { MoreMenu } from "@/components/ui/more-menu"; import { MoreMenu } from "@/components/ui/more-menu";
@@ -261,7 +260,8 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</EmptyHeader> </EmptyHeader>
</Empty> </Empty>
</Section> </Section>
<Card v-else-if="selected && store.state.resource" class="min-w-0 px-3 sm:px-5 max-md:flex max-md:h-full max-md:min-h-0 max-md:flex-col" role="region" aria-label="Workflow"> <!-- No card around the editor: the canvas draws its own frame. -->
<div v-else-if="selected && store.state.resource" class="min-w-0 max-md:flex max-md:h-full max-md:min-h-0 max-md:flex-col" role="region" aria-label="Workflow">
<!-- Below lg the list is gone: this picks the workflow instead. --> <!-- Below lg the list is gone: this picks the workflow instead. -->
<header class="mb-2 flex shrink-0 items-center gap-2 lg:hidden"> <header class="mb-2 flex shrink-0 items-center gap-2 lg:hidden">
<div class="min-w-0 flex-1"><WorkflowPicker class="w-full" :value="selected" :workflows="rows" label="Workflow" @pick="selected = $event" /></div> <div class="min-w-0 flex-1"><WorkflowPicker class="w-full" :value="selected" :workflows="rows" label="Workflow" @pick="selected = $event" /></div>
@@ -275,7 +275,7 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
<ApplyStatusRows kind="workflow-definitions" compact /> <ApplyStatusRows kind="workflow-definitions" compact />
</template> </template>
</WorkflowEditor> </WorkflowEditor>
</Card> </div>
</div> </div>
</div> </div>
</template> </template>