fix(ui): fit phone workflows and allow dynamic handoffs

This commit is contained in:
sam committed 2026-10-19 01:04:32 +11:00
1 parent 454e08cabe
commit 0e3cb2e4d3
15 files changed
+499 -239

No files matched your search

+1 -2
View File
@@ -29,12 +29,11 @@ function started(taskId: number): void {
type="button"
size="sm"
variant="outline"
class="max-sm:w-8 max-sm:px-0"
:aria-label="`${draft !== undefined ? 'Test' : 'Run'} ${workflow}`"
:disabled="disabled"
:title="draft !== undefined ? 'Runs this draft once. Forge writes and pushes are skipped, including in called workflows; commands and tools still run' : disabled ? 'Save first' : undefined"
>
<component :is="draft !== undefined ? FlaskConical : Play" data-icon="inline-start" /> <span class="max-sm:hidden">{{ draft !== undefined ? "Test" : "Run" }}</span></Button>
<component :is="draft !== undefined ? FlaskConical : Play" data-icon="inline-start" /> <span>{{ draft !== undefined ? "Test" : "Run" }}</span></Button>
</DialogTrigger>
<DialogContent class="sm:max-w-[640px]">
<DialogHeader>
+2 -2
View File
@@ -179,7 +179,7 @@ const ON_FAILURE = [{ value: "", label: "Park the task" }, { value: "continue",
{{ label(fields.lead.key, fields.lead.schema) }}
<CircleHelp v-if="fields.lead.schema.description" class="size-3 text-fg-subtle" />
</div>
<WorkflowPicker v-if="fields.lead.kind === 'workflow'" :value="text(fields.lead.key)" :workflows="workflows" :label="label(fields.lead.key, fields.lead.schema)" @pick="setTarget(fields.lead.key, $event)" />
<WorkflowPicker v-if="fields.lead.kind === 'workflow'" :editable="type !== 'workflow.call'" :value="text(fields.lead.key)" :workflows="workflows" :label="label(fields.lead.key, fields.lead.schema)" @pick="setTarget(fields.lead.key, $event)" />
<OptionSelect v-else-if="fields.lead.kind === 'select'" class="w-full" :model-value="text(fields.lead.key)" :options="choices(fields.lead.options)" :aria-label="label(fields.lead.key, fields.lead.schema)" @update:model-value="setSetting(fields.lead.key, $event || undefined)" />
<Textarea
v-else-if="fields.lead.kind === 'text'"
@@ -213,7 +213,7 @@ const ON_FAILURE = [{ value: "", label: "Park the task" }, { value: "continue",
{{ label(field.key, field.schema) }}
<CircleHelp v-if="field.schema.description" class="size-3 text-fg-subtle" />
</span>
<WorkflowPicker v-if="field.kind === 'workflow'" class="max-w-48" :value="text(field.key)" :workflows="workflows" :label="label(field.key, field.schema)" @pick="setTarget(field.key, $event)" />
<WorkflowPicker v-if="field.kind === 'workflow'" :editable="type !== 'workflow.call'" class="max-w-48" :value="text(field.key)" :workflows="workflows" :label="label(field.key, field.schema)" @pick="setTarget(field.key, $event)" />
<Switch v-else-if="field.kind === 'boolean'" :model-value="settings[field.key] === true" @update:model-value="setSetting(field.key, $event || undefined)" />
<OptionSelect v-else-if="field.kind === 'select'" class="w-40" :model-value="text(field.key)" :options="choices(field.options)" :aria-label="label(field.key, field.schema)" @update:model-value="setSetting(field.key, $event || undefined)" />
<Input
+2 -6
View File
@@ -59,7 +59,7 @@ const STATUS = {
const status = computed(() => {
const run = props.data.run?.status;
if (run) return STATUS[run as keyof typeof STATUS] ?? null;
if (props.data.problem) return { icon: CircleAlert, class: "text-warn", label: props.data.problem };
if (props.data.problem) return { icon: CircleAlert, class: "text-danger", label: props.data.problem };
if (props.data.editable && props.data.kind === "step") return { icon: CircleCheck, class: "text-ok/70", label: "Ready" };
return null;
});
@@ -70,9 +70,6 @@ const badge = computed(() => {
return { icon: stepIcon(props.data.type), label: stepTitle(props.data.type) };
});
const number = computed(() => (props.data.step ? `${Number(props.data.step)}.` : ""));
// A step with no id of its own is titled by its type, so the chip would repeat
// the line below it; the icon alone still names the type there.
const typeNamed = computed(() => props.data.title !== badge.value.label);
function duration(ms?: number): string {
if (ms === undefined) return "";
@@ -119,7 +116,7 @@ function commitRename(event: Event): void {
<Handle id="data-in" type="target" :position="Position.Right" class="!opacity-0" />
<div class="px-3 py-2.5" @click="data.onToggle?.()">
<div class="flex items-center gap-1.5">
<Badge v-if="typeNamed" variant="outline" class="max-w-40 gap-1 bg-background">
<Badge variant="outline" class="max-w-40 gap-1 bg-background">
<component :is="badge.icon" class="text-primary" aria-hidden="true" /><span class="truncate" :title="badge.label">{{ badge.label }}</span>
</Badge>
<span v-if="data.run?.duration_ms !== undefined" class="ml-auto font-mono text-[11px] text-fg-subtle">{{ duration(data.run.duration_ms) }}</span>
@@ -138,7 +135,6 @@ function commitRename(event: Event): void {
</DropdownMenu>
</div>
<div class="mt-1.5 flex min-w-0 items-baseline gap-1 text-sm font-medium">
<component :is="badge.icon" v-if="!typeNamed" class="size-3.5 shrink-0 self-center text-primary" aria-hidden="true" />
<span v-if="number" class="shrink-0">{{ number }}</span>
<Input
v-if="renaming"
+69 -75
View File
@@ -2,11 +2,9 @@
import { computed, nextTick, ref, watch } from "vue";
import { VueFlow, type NodeMouseEvent, type VueFlowStore } from "@vue-flow/core";
import { Background } from "@vue-flow/background";
import { ControlButton, Controls } from "@vue-flow/controls";
import { usePreferredReducedMotion, useTransition } from "@vueuse/core";
import { useMediaQuery, usePreferredReducedMotion, useResizeObserver, useTransition } from "@vueuse/core";
import { ArrowDown, ArrowUp, Copy, Maximize, Minus, Pencil, Plus, RotateCcw, Trash2 } from "@lucide/vue";
import "@vue-flow/core/dist/style.css";
import "@vue-flow/controls/dist/style.css";
import {
DropdownMenu,
@@ -19,6 +17,8 @@ import {
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import AddNode from "./AddNode.vue";
import InsertEdge from "./InsertEdge.vue";
import StepNode, { type StepCardData } from "./StepNode.vue";
@@ -36,6 +36,7 @@ const props = defineProps<{
triggers?: WorkflowTrigger[];
/** Step type names; when given, the canvas offers editing. */
types?: string[];
readonly?: boolean;
/** The watched run is parked, so its steps offer to restart it. */
restartable?: boolean;
/** Steps that differ from the definition being compared, by node id. */
@@ -59,16 +60,18 @@ const emit = defineEmits<{
const NODE_WIDTH = 240;
const OPEN_WIDTH = 416;
const TOP = -140;
const editable = computed(() => !!props.types?.length);
const editable = computed(() => !!props.types?.length && !props.readonly);
const types = computed(() => [...(props.types ?? []), "parallel", "switch"]);
const branchTypes = computed(() => types.value.filter((type) => ["agent.run", "workflow.call"].includes(type)));
const typesAt = (path?: StepPath) => (path && inParallel(path) ? branchTypes.value : types.value);
const keyOf = (data: StepNodeData) => (data.kind === "step" ? JSON.stringify(data.path ?? null) : data.kind);
const container = ref<HTMLElement | null>(null);
const viewport = ref<HTMLElement | null>(null);
const phone = useMediaQuery("(max-width: 767px)");
const graph = computed(() => {
const laid = withRuns(workflowGraph(props.yaml), props.stages ?? []);
if (!editable.value) return laid;
if (!props.types?.length) return laid;
// 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 ?? "" } };
return { nodes: [workflow, ...laid.nodes], edges: [{ id: "flow-workflow-start", source: "workflow", target: "start", kind: "flow" as const }, ...laid.edges] };
@@ -87,7 +90,7 @@ function resized(id: string, height: number): void {
if (anchor.value?.id !== id) closedHeights.value = { ...closedHeights.value, [id]: height };
}
const growth = computed(() => {
const id = anchor.value?.id;
const id = phone.value ? undefined : anchor.value?.id;
return id && heights.value[id] ? Math.max(0, heights.value[id] - (closedHeights.value[id] ?? heights.value[id])) : 0;
});
const motion = usePreferredReducedMotion();
@@ -109,13 +112,13 @@ function card(node: GraphNode): GraphNode {
const path = data.path;
const extra: Partial<StepCardData> = {
triggers: data.kind === "start" ? (props.triggers ?? []) : data.triggers,
expanded: key === props.open,
expanded: !phone.value && key === props.open,
editable: editable.value,
problem: path ? props.problems?.[key] : undefined,
onResize: (height: number) => resized(node.id, height),
};
if (props.types?.length) extra.onToggle = () => emit("toggle", key);
if (editable.value) {
extra.onToggle = () => emit("toggle", key);
if (path) {
extra.onRename = (name: string) => emit("rename", path, name);
extra.onDuplicate = () => emit("duplicate", path);
@@ -130,12 +133,12 @@ function card(node: GraphNode): GraphNode {
const WIDEN = OPEN_WIDTH - NODE_WIDTH;
const holdsOpen = (node: GraphNode) => {
const open = anchor.value;
if (!open || !node.style?.width) return false;
if (phone.value || !open || !node.style?.width) return false;
return node.position.x <= open.position.x && node.position.x + parseFloat(String(node.style.width)) >= open.position.x + NODE_WIDTH;
};
function spread(node: GraphNode): number {
const open = anchor.value;
if (!open) return 0;
if (phone.value || !open) return 0;
if (node.id === open.id || holdsOpen(node)) return -WIDEN / 2;
const centre = open.position.x + NODE_WIDTH / 2;
const width = node.style?.width ? parseFloat(String(node.style.width)) : node.type === "step" ? NODE_WIDTH : 32;
@@ -201,7 +204,7 @@ const ZOOM = 0.9;
// touch them.
const PAD = 20;
let flow: VueFlowStore | undefined;
const top = computed(() => (editable.value ? TOP : 0));
const top = computed(() => (props.types?.length ? TOP : 0));
// The graph's horizontal extent, in canvas units: a lane is wider than the card
// it holds, and a card opened in place is wider still.
@@ -212,7 +215,7 @@ function extent(): { left: number; width: number } {
// An insertion point is a glyph, not a card, and it sits inside the extent
// of the cards around it.
if (node.type !== "step" && node.type !== "lane") continue;
const width = node.style?.width ? parseFloat(String(node.style.width)) : node.id === anchor.value?.id ? OPEN_WIDTH : NODE_WIDTH;
const width = node.style?.width ? parseFloat(String(node.style.width)) : !phone.value && node.id === anchor.value?.id ? OPEN_WIDTH : NODE_WIDTH;
left = Math.min(left, node.position.x);
right = Math.max(right, node.position.x + width);
}
@@ -223,7 +226,7 @@ function extent(): { left: number; width: number } {
// canvas with clearance at both edges, at no more than the readable size.
function framing(width: number): { x: number; zoom: number } {
const { left, width: span } = extent();
const zoom = Math.max(0.3, Math.min(ZOOM, (width - PAD * 2) / span));
const zoom = Math.max(0.01, Math.min(ZOOM, (width - PAD * 2) / span));
return { x: width / 2 - (left + span / 2) * zoom, zoom };
}
@@ -232,18 +235,26 @@ function framing(width: number): { x: number; zoom: number } {
function place(store?: VueFlowStore): void {
flow = store ?? flow;
if (!flow) return;
const { x, zoom } = framing(container.value?.clientWidth ?? 800);
const width = viewport.value?.clientWidth;
if (!width) return;
const { x, zoom } = framing(width);
void flow.setViewport({ x, y: 24 - top.value * zoom, zoom });
}
useResizeObserver(viewport, () => place());
watch([() => props.title, () => graph.value.nodes.map((node) => `${node.id}:${node.position.x}:${node.position.y}`).join(",")], async () => {
await nextTick();
place();
});
// A card opened low on the canvas scrolls up so its form is in view, and one
// opened wider than the canvas allows is framed so its edges stay reachable.
watch(anchor, async (node) => {
await nextTick();
if (!node || !flow) return;
if (phone.value || !node || !flow) return;
const { y } = flow.getViewport();
const width = container.value?.clientWidth ?? 800;
const height = container.value?.clientHeight ?? 560;
const width = viewport.value?.clientWidth ?? 800;
const height = viewport.value?.clientHeight ?? 560;
const { x, zoom } = framing(width);
const screenTop = (node.position.y + pushed(node.position.y)) * zoom + y;
const away = screenTop < 8 || screenTop > height / 2;
@@ -270,48 +281,50 @@ const beforePath = computed(() => menuPath.value ? [...menuPath.value.slice(0, -
</script>
<template>
<div ref="container" class="workflow-canvas relative h-full overflow-hidden rounded-lg border border-border bg-background">
<VueFlow
class="h-full"
:nodes="nodes"
:edges="edges"
:nodes-draggable="false"
:nodes-connectable="false"
:elements-selectable="false"
:min-zoom="0.3"
:max-zoom="1.5"
pan-on-scroll
@pane-ready="place"
@node-mouse-enter="hovered = $event.node.id"
@node-mouse-leave="hovered = null"
@node-context-menu="onNodeMenu"
@pane-context-menu="openMenu($event as MouseEvent)"
>
<template #node-step="nodeProps">
<StepNode v-bind="nodeProps"><slot name="body" :data="nodeProps.data" /></StepNode>
</template>
<template #node-lane="nodeProps">
<LaneNode v-bind="nodeProps" />
</template>
<template #node-add="nodeProps">
<AddNode v-bind="nodeProps" />
</template>
<template #edge-insert="edgeProps">
<InsertEdge v-bind="edgeProps" />
</template>
<Background :gap="20" />
<Controls :show-interactive="false">
<template #control-zoom-in>
<ControlButton title="Zoom in" aria-label="Zoom in" @click="flow?.zoomIn()"><Plus /></ControlButton>
<div ref="container" class="workflow-canvas relative flex h-full min-h-0 flex-col overflow-hidden rounded-lg border border-border bg-background">
<div ref="viewport" class="min-h-0 flex-1">
<VueFlow
class="h-full"
:nodes="nodes"
:edges="edges"
:nodes-draggable="false"
:nodes-connectable="false"
:elements-selectable="false"
:min-zoom="0.01"
:max-zoom="1.5"
pan-on-scroll
@pane-ready="place"
@node-mouse-enter="hovered = $event.node.id"
@node-mouse-leave="hovered = null"
@node-context-menu="onNodeMenu"
@pane-context-menu="openMenu($event as MouseEvent)"
>
<template #node-step="nodeProps">
<StepNode v-bind="nodeProps"><slot name="body" :data="nodeProps.data" /></StepNode>
</template>
<template #control-zoom-out>
<ControlButton title="Zoom out" aria-label="Zoom out" @click="flow?.zoomOut()"><Minus /></ControlButton>
<template #node-lane="nodeProps">
<LaneNode v-bind="nodeProps" />
</template>
<template #control-fit-view>
<ControlButton title="Fit view" aria-label="Fit view" @click="flow?.fitView()"><Maximize /></ControlButton>
<template #node-add="nodeProps">
<AddNode v-bind="nodeProps" />
</template>
</Controls>
</VueFlow>
<template #edge-insert="edgeProps">
<InsertEdge v-bind="edgeProps" />
</template>
<Background :gap="20" />
</VueFlow>
</div>
<div class="flex shrink-0 items-center justify-center gap-1 border-t border-border bg-card p-1">
<Button variant="ghost" size="icon-sm" title="Zoom in" aria-label="Zoom in" @click="flow?.zoomIn()"><Plus /></Button>
<Button variant="ghost" size="icon-sm" title="Zoom out" aria-label="Zoom out" @click="flow?.zoomOut()"><Minus /></Button>
<Button variant="ghost" size="icon-sm" title="Fit view" aria-label="Fit view" @click="place()"><Maximize /></Button>
</div>
<Dialog :open="phone && !!anchor" @update:open="!$event && anchor && emit('toggle', keyOf(anchor.data))">
<DialogContent v-if="anchor" class="max-h-[calc(100dvh-2rem)] overflow-y-auto" :aria-describedby="undefined">
<DialogHeader><DialogTitle class="pr-8">{{ anchor.data.title }}</DialogTitle></DialogHeader>
<slot name="body" :data="anchor.data" />
</DialogContent>
</Dialog>
<DropdownMenu v-model:open="menu.open">
<DropdownMenuTrigger as-child>
@@ -391,23 +404,4 @@ const beforePath = computed(() => menuPath.value ? [...menuPath.value.slice(0, -
.step-running {
animation: step-running 1.6s ease-in-out infinite;
}
.workflow-canvas .vue-flow__controls {
box-shadow: none;
}
.workflow-canvas .vue-flow__controls-button {
width: 1.25rem;
height: 1.25rem;
padding: 0.5rem;
background: var(--color-card);
border-color: var(--color-border);
color: var(--color-foreground);
}
.workflow-canvas .vue-flow__controls-button svg {
max-width: 1rem;
max-height: 1rem;
fill: none;
}
.workflow-canvas .vue-flow__controls-button:hover {
background: var(--color-secondary);
}
</style>
+50 -49
View File
@@ -37,7 +37,7 @@ import WorkflowCanvas from "./WorkflowCanvas.vue";
import WorkflowHistory from "./WorkflowHistory.vue";
import { useWorkflowHistory } from "./workflow-history";
import { revisionOfRun, type WorkflowRevision } from "./workflow-revisions";
import { deleteStep, duplicateStep, insertStep, moveStep, replaceStep, revertWorkflowChange, stepAt, workflowChanges, workflowField, type StepPath } from "./workflow-edit";
import { deleteStep, duplicateStep, insertStep, moveStep, normalizeStepIDs, replaceStep, revertWorkflowChange, stepAt, workflowChanges, workflowField, type StepPath } from "./workflow-edit";
import ChangeList from "@/components/ChangeList.vue";
import CoBuilder from "./CoBuilder.vue";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
@@ -89,7 +89,9 @@ const stepTab = ref("definition");
// the canvas draws the definition alone.
const unpinned = computed(() => Boolean(watchedRun.value && !watchedRun.value.workflow_definition_yaml));
const drawnStages = computed(() => unpinned.value ? [] : stages.value);
const graph = computed(() => withRuns(workflowGraph(yaml.value), drawnStages.value));
const pinnedYaml = computed(() => watchedRun.value?.workflow_definition_yaml);
const canvasYaml = computed(() => pinnedYaml.value || yaml.value);
const graph = computed(() => withRuns(workflowGraph(canvasYaml.value), drawnStages.value));
function toggle(key: string): void {
open.value = open.value === key ? null : key;
const run = graph.value.nodes.find((node) => JSON.stringify(node.data.path ?? null) === open.value)?.data.run;
@@ -169,8 +171,8 @@ function load(value: string): void {
(candidate) => candidate.id === value,
);
id.value = entry?.id ?? value;
yaml.value = workflows.drafts.find((draft) => draft.id === value)?.yaml ?? entry?.yaml ?? `id: ${value}\nsteps: []\n`;
loadedYaml.value = yaml.value;
loadedYaml.value = workflows.drafts.find((draft) => draft.id === value)?.yaml ?? entry?.yaml ?? `id: ${value}\nsteps: []\n`;
yaml.value = normalizeStepIDs(loadedYaml.value);
open.value = null;
localError.value = "";
}
@@ -276,8 +278,7 @@ async function publish(): Promise<void> {
}
}
// The run and draft dialogs are opened from the one toolbar menu when the row
// has no button for them; each block and its menu item drive one flag.
// The run button and draft menu item each control their dialog.
const runOpen = ref(false);
const draftOpen = ref(false);
const confirmDelete = ref(false);
@@ -336,13 +337,9 @@ function showError(path?: StepPath): void {
view.value = "canvas";
openStepAt(path);
}
const WORKS_ON: Record<string, string> = { optional: "Repository if given", none: "No repository" };
const REQUIRED = "Works on a repository";
const workflowSummary = computed(() =>
[WORKS_ON[String(workflowField(yaml.value, "repository") ?? "")] ?? REQUIRED, workflowField(yaml.value, "profile")].filter(Boolean).join(" · "),
);
const workflowSummary = computed(() => String(workflowField(canvasYaml.value, "profile") ?? ""));
const runOptions = computed(() => [
{ value: "", label: "Current definition" },
{ value: "", label: "Definition" },
...runs.value.map((run) => ({
value: String(run.id),
label: [`${run.source === "test" ? "Test" : "Run"} #${run.id}`, run.status && statusLabel(run.status), run.created_at ? ago(run.created_at) : ""].filter(Boolean).join(" · "),
@@ -365,16 +362,9 @@ function syncScroll(event: Event): void {
</script>
<template>
<form class="space-y-4" @submit.prevent="publish">
<Tabs v-model="view" class="space-y-1.5">
<!--
Two rows at every width: the page header above names the workflow, and
this row is one toolbar. The tabs hold the views that fit, the run
selector and the actions share the right end, and everything else is in
the single menu beside Publish. Nothing wraps: the run selector gives up
width first.
-->
<div class="flex items-center gap-2">
<form class="space-y-4 max-md:flex max-md:min-h-0 max-md:flex-1 max-md:flex-col" @submit.prevent="publish">
<Tabs v-model="view" class="space-y-1.5 max-md:min-h-0 max-md:flex-1">
<div class="workflow-editor-toolbar flex shrink-0 items-center gap-2 max-sm:grid max-sm:grid-cols-[1fr_auto]">
<TabsList class="shrink-0 justify-start">
<TabsTrigger value="canvas">Canvas</TabsTrigger>
<TabsTrigger value="yaml">YAML</TabsTrigger>
@@ -383,10 +373,8 @@ function syncScroll(event: Event): void {
<TabsTrigger v-if="$slots.runs && stored !== undefined" value="runs" class="max-xl:hidden">Runs <span class="ml-1 font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
</TabsList>
<span v-if="SECTIONS[view]" class="shrink-0 text-xs font-medium text-fg-muted xl:hidden">{{ SECTIONS[view] }}</span>
<div role="group" aria-label="Runs" class="ml-auto flex min-w-0 items-center gap-1">
<!-- The dialog is teleported, so hiding this wrapper below sm hides the
trigger only and leaves the one dialog reachable from the menu. -->
<div v-if="stored !== undefined && (view === 'canvas' || view === 'yaml')" class="max-sm:hidden">
<div role="group" aria-label="Runs" class="workflow-run-actions ml-auto flex min-w-0 items-center gap-1 max-sm:col-span-2 max-sm:row-start-2 max-sm:ml-0">
<div v-if="stored !== undefined && (view === 'canvas' || view === 'yaml')" class="shrink-0">
<RunWorkflowButton
v-model:open="runOpen"
:workflow="selected"
@@ -395,8 +383,8 @@ function syncScroll(event: Event): void {
@started="(id) => { view = 'canvas'; void follow(id); }"
/>
</div>
<div v-if="runs.length && view === 'canvas'" class="flex min-w-0 items-center gap-1">
<OptionSelect :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-0 max-w-24 sm:max-w-56 *:data-[slot=select-value]:block *:data-[slot=select-value]:truncate" @update:model-value="pick" />
<div v-if="runs.length && view === 'canvas'" class="flex min-w-0 items-center gap-1 max-sm:flex-1">
<OptionSelect :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-0 max-w-56 max-sm:w-full *:data-[slot=select-value]:block *:data-[slot=select-value]:truncate" @update:model-value="pick" />
<template v-if="watchedRun">
<!-- One run control keeps the row short; the run's other actions
are on the run, behind Open run in this menu. -->
@@ -404,7 +392,7 @@ function syncScroll(event: Event): void {
</template>
</div>
</div>
<div role="group" aria-label="Edit" class="flex min-w-0 items-center gap-1 border-l pl-2">
<div role="group" aria-label="Edit" class="workflow-edit-actions flex min-w-0 items-center gap-1 border-l pl-2 max-sm:col-start-2 max-sm:row-start-1">
<slot name="toolbar" />
<Popover v-if="!parsed.ok">
<PopoverTrigger as-child>
@@ -436,7 +424,6 @@ function syncScroll(event: Event): void {
row controls: the row keeps the width for the picked run. -->
<DropdownMenuItem v-if="watchedRun" as-child><RouterLink :to="`/tasks/${watchedRun.id}`">Open run</RouterLink></DropdownMenuItem>
<DropdownMenuItem v-if="watchedRevision" @select="openRevision(watchedRevision.version)">Version {{ watchedRevision.version }}</DropdownMenuItem>
<DropdownMenuItem v-if="stored !== undefined && (view === 'canvas' || view === 'yaml')" class="sm:hidden" :disabled="!parsed.ok" @select="runOpen = true">{{ dirty ? "Test" : "Run" }}</DropdownMenuItem>
<DropdownMenuItem v-if="changes.length" @select="draftOpen = true">Draft changes <span class="ml-auto font-mono text-xs text-fg-subtle">{{ changes.length }}</span></DropdownMenuItem>
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="restorePublished"><RotateCcw />Restore</DropdownMenuItem>
<DropdownMenuItem v-if="view === 'canvas' || view === 'yaml'" variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
@@ -452,23 +439,20 @@ function syncScroll(event: Event): void {
<p v-if="view === 'canvas' && unpinned" class="text-xs text-fg-muted" role="status">No workflow snapshot was recorded for this run.</p>
<!-- Kept mounted so an Archie turn started here still finishes, unlocks the
editor and loads its draft when the operator switches tabs. -->
<TabsContent value="canvas" force-mount class="space-y-2 data-[state=inactive]:hidden">
<!-- The canvas takes the height the viewport has left, so the page
itself does not scroll; the canvas pans. On a phone the Archie bar
already sits beside the launcher, so the canvas takes back the
launcher padding the page reserves below it. -->
<div class="relative flex h-[calc(100dvh-17rem)] min-h-[26rem] flex-col max-md:-mb-20 max-md:min-h-[23rem]">
<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-17rem)] min-h-[26rem] flex-col max-md:h-auto max-md:min-h-0 max-md:flex-1">
<p v-if="restartError" role="alert" class="absolute bottom-16 left-14 z-10 max-w-xl rounded-md border border-danger/40 bg-card px-3 py-2 text-sm text-danger shadow-lg">{{ restartError }}</p>
<WorkflowCanvas
class="h-auto min-h-0 flex-1"
:inert="archieWorking"
:yaml="yaml"
:yaml="canvasYaml"
:stages="drawnStages"
:open="open"
:triggers="triggers"
:types="stepTypeNames"
:readonly="!!pinnedYaml"
:restartable="restartable"
:problems="nodeProblems"
:problems="pinnedYaml ? undefined : nodeProblems"
:title="parsed.ok ? parsed.id : id"
:summary="workflowSummary"
@toggle="toggle"
@@ -480,8 +464,8 @@ function syncScroll(event: Event): void {
@rename="renameAt"
>
<template #body="{ data }">
<WorkflowSettings v-if="data.kind === 'workflow'" v-model:yaml="yaml" />
<TriggerSettings v-else-if="data.kind === 'start'" v-model:yaml="yaml" :triggers="triggers" @bound="reloadTriggers" />
<fieldset v-if="data.kind === 'workflow'" :disabled="!!pinnedYaml" class="min-w-0"><WorkflowSettings :yaml="canvasYaml" @update:yaml="yaml = $event" /></fieldset>
<fieldset v-else-if="data.kind === 'start'" :disabled="!!pinnedYaml" class="min-w-0"><TriggerSettings :yaml="canvasYaml" :triggers="triggers" @update:yaml="yaml = $event" @bound="reloadTriggers" /></fieldset>
<template v-else-if="data.path">
<div v-if="data.run && watchedRun" class="flex items-center gap-2 border-b border-border px-3 py-2">
<Tabs v-model="stepTab"><TabsList><TabsTrigger value="run">Run</TabsTrigger><TabsTrigger value="definition">Definition</TabsTrigger></TabsList></Tabs>
@@ -490,21 +474,23 @@ function syncScroll(event: Event): void {
<div v-if="data.run && watchedRun && stepTab === 'run'" class="max-h-[32rem] overflow-y-auto">
<StepRun :task="watchedRun" :attempt="attempt" :stage="data.run" :stages="stages" />
</div>
<fieldset v-else :disabled="!!pinnedYaml" class="min-w-0">
<StepEditor
v-else
:key="open ?? ''"
v-model:yaml="yaml"
:yaml="canvasYaml"
@update:yaml="yaml = $event"
:workflows="collection.definitions"
:path="data.path"
:vocabulary="vocabulary"
:model-aliases="modelAliases"
/>
</fieldset>
</template>
</template>
</WorkflowCanvas>
<!-- Below the canvas rather than over it: nodes run to the bottom edge,
so a floating bar hid the last step. -->
<div class="flex justify-center px-3 pt-2">
<div class="flex shrink-0 justify-center px-3 pt-2">
<CoBuilder
v-if="selected"
:key="selected"
@@ -516,12 +502,12 @@ function syncScroll(event: Event): void {
</div>
</div>
</TabsContent>
<TabsContent value="history">
<TabsContent value="history" class="max-md:min-h-0 max-md:overflow-y-auto">
<WorkflowHistory v-model:selected="historyRevision" v-model:mode="historyMode" :revisions="revisions" :current="yaml" :error="historyError" @restore="restoreRevision" />
</TabsContent>
<TabsContent value="performance" class="grid gap-4"><slot name="performance" /></TabsContent>
<TabsContent value="runs"><slot name="runs" /></TabsContent>
<TabsContent value="yaml" :inert="archieWorking">
<TabsContent value="performance" class="grid gap-4 max-md:min-h-0 max-md:overflow-y-auto"><slot name="performance" /></TabsContent>
<TabsContent value="runs" class="max-md:min-h-0 max-md:overflow-y-auto"><slot name="runs" /></TabsContent>
<TabsContent value="yaml" :inert="archieWorking" class="max-md:min-h-0 max-md:overflow-y-auto">
<!--
A gutter and a highlighted layer behind the live textarea, so the YAML
is numbered and coloured where it is edited rather than in a second,
@@ -530,7 +516,7 @@ function syncScroll(event: Event): void {
screen reader reach.
-->
<div
class="relative overflow-hidden rounded-lg border border-input font-mono text-[13px] leading-6 focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50"
class="relative overflow-hidden rounded-lg border border-input font-mono max-md:h-full text-[13px] leading-6 focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50"
>
<div
aria-hidden="true"
@@ -568,7 +554,7 @@ function syncScroll(event: Event): void {
v-model="yaml"
name="workflow-yaml"
required
class="relative min-h-96 resize-y rounded-none border-0 bg-transparent py-3 pr-3 pl-14 text-[13px] leading-6 text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
class="relative min-h-96 resize-y max-md:h-full max-md:min-h-0 max-md:resize-none rounded-none border-0 bg-transparent py-3 pr-3 pl-14 text-[13px] leading-6 text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
spellcheck="false"
wrap="off"
@scroll="syncScroll"
@@ -602,3 +588,18 @@ function syncScroll(event: Event): void {
</AlertDialog>
</form>
</template>
<style scoped>
@media (max-width: 360px) {
.workflow-editor-toolbar {
grid-template-columns: minmax(0, 1fr);
}
.workflow-editor-toolbar > .workflow-edit-actions {
grid-area: 2 / 1;
justify-content: flex-end;
}
.workflow-editor-toolbar > .workflow-run-actions {
grid-area: 3 / 1;
}
}
</style>
+9 -2
View File
@@ -1,12 +1,19 @@
<script setup lang="ts">
import { useId } from "vue";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
defineProps<{ value: string; workflows: { id: string }[]; label: string; class?: string }>();
defineProps<{ value: string; workflows: { id: string }[]; label: string; class?: string; editable?: boolean }>();
const listId = useId();
const emit = defineEmits<{ pick: [string] }>();
</script>
<template>
<Select :model-value="value || undefined" @update:model-value="emit('pick', String($event))">
<template v-if="editable">
<Input :model-value="value" :list="listId" :aria-label="label" :class="$props.class" placeholder="Workflow id or {{ reference }}" @update:model-value="emit('pick', String($event))" />
<datalist :id="listId"><option v-for="entry in workflows" :key="entry.id" :value="entry.id" /></datalist>
</template>
<Select v-else :model-value="value || undefined" @update:model-value="emit('pick', String($event))">
<SelectTrigger :aria-label="label" :class="$props.class"><SelectValue placeholder="Choose workflow" /></SelectTrigger>
<SelectContent>
<SelectItem v-if="value && !workflows.some((entry) => entry.id === value)" :value="value" disabled>{{ value }} (unavailable)</SelectItem>
+8 -7
View File
@@ -162,8 +162,10 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</script>
<template>
<div>
<PageHeader title="Workflows" />
<div class="max-md:flex max-md:min-h-0 max-md:flex-1 max-md:flex-col">
<PageHeader title="Workflows" class="shrink-0">
<Button size="icon-sm" variant="ghost" aria-label="New workflow" title="New workflow" @click="create"><Plus /></Button>
</PageHeader>
<div v-if="error || store.error" class="mb-4 text-sm text-danger" role="alert">
<p>{{ error || store.error }}</p>
@@ -171,9 +173,8 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</div>
<p v-if="loading || (!store.state.resource && !store.error)" class="text-sm text-fg-muted" role="status">Loading workflows…</p>
<div class="grid items-start gap-6 lg:grid-cols-[24rem_minmax(0,1fr)]">
<div class="flex min-w-0 flex-col gap-1">
<Button size="icon-sm" variant="ghost" class="self-end" aria-label="New workflow" title="New workflow" @click="create"><Plus /></Button>
<div class="grid items-start gap-6 lg:grid-cols-[24rem_minmax(0,1fr)] max-md:min-h-0 max-md:flex-1 max-md:grid-rows-[minmax(0,1fr)]">
<div class="hidden min-w-0 flex-col gap-1 lg:flex">
<ul class="hidden max-h-[calc(100dvh-10rem)] flex-col gap-0.5 overflow-y-auto lg:flex" aria-label="Workflows">
<li v-for="row in rows" :key="row.id" class="min-w-0">
<button
@@ -210,8 +211,8 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
</EmptyHeader>
</Empty>
</section>
<section v-else-if="selected && store.state.resource" class="min-w-0 rounded-lg border border-border bg-card px-3 py-4 sm:px-5" aria-label="Workflow">
<header class="mb-2 flex items-center gap-2">
<section v-else-if="selected && store.state.resource" class="min-w-0 rounded-lg border border-border bg-card px-3 py-4 sm:px-5 max-md:flex max-md:h-full max-md:min-h-0 max-md:flex-col" aria-label="Workflow">
<header class="mb-2 flex shrink-0 items-center gap-2">
<!-- Below lg the list is gone: this picks the workflow instead. -->
<div class="min-w-0 flex-1 lg:hidden"><WorkflowPicker class="w-full" :value="selected" :workflows="rows" label="Workflow" @pick="selected = $event" /></div>
<h2 class="min-w-0 truncate text-[15px] font-medium max-lg:hidden">{{ selected }}</h2>
+48 -1
View File
@@ -1,4 +1,4 @@
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
import { isMap, isScalar, isSeq, parseDocument, visit } from "yaml";
import { diffValues, pathSegments, type Change } from "../lib/changes.ts";
/**
@@ -155,6 +155,53 @@ export function moveStep(source: string, path: StepPath, delta: -1 | 1): { sourc
return { source: document.toString(), path: [...path.slice(0, -1), target] };
}
/** Insert chips need reference-safe ids; update the ids and their references
* together so existing connections survive. */
export function normalizeStepIDs(source: string): string {
const document = parseDocument(source);
if (document.errors.length) return source;
const records: { id: string; path: StepPath }[] = [];
const collect = (steps: unknown, path: StepPath): void => {
if (!Array.isArray(steps)) return;
steps.forEach((step, index) => {
if (!isRecord(step)) return;
const at = [...path, index];
if (typeof step.id === "string" && step.id) records.push({ id: step.id, path: at });
const branches = branchingOf(step);
if (branches) for (const [name, children] of branches.branches) collect(children, [...at, ...branches.base, name]);
});
};
const value = document.toJS() as { steps?: unknown } | null;
collect(value?.steps, ["steps"]);
// Stable ids allow dots, but reference paths split on dots; step ids cannot.
const valid = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
const used = new Set(records.filter(({ id }) => valid.test(id)).map(({ id }) => id));
const replacements = new Map<string, string>();
for (const { id, path } of records) {
if (valid.test(id)) continue;
let next = replacements.get(id);
if (!next) {
const slug = id.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
const base = /^[a-z]/.test(slug) ? slug : `step${slug ? `-${slug}` : ""}`;
next = base;
for (let suffix = 2; used.has(next); suffix++) next = `${base}-${suffix}`;
used.add(next);
replacements.set(id, next);
}
document.setIn([...path, "id"], next);
}
if (!replacements.size) return source;
// A dotted id cannot be a reference target: its suffix names a result field.
const escaped = [...replacements.keys()].filter((id) => !id.includes(".")).sort((a, b) => b.length - a.length).map((id) => id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
const references = new RegExp(`steps\\.(${escaped.join("|")})(?=\\.|[^A-Za-z0-9_-]|$)`, "g");
if (escaped.length) visit(document, {
Scalar(_key, node) {
if (typeof node.value === "string") node.value = node.value.replace(references, (_match, id: string) => `steps.${replacements.get(id)}`);
},
});
return document.toString();
}
/** The ids every step before the given one declares, which are the steps its
* settings may reference. Inside a branch, sibling branches are not visible. */
export function earlierStepIDs(source: string, path: StepPath): string[] {