feat(ui): workflow canvas cards expand in place instead of side panels

This commit is contained in:
sam committed 2026-10-18 01:59:09 +11:00
1 parent e3add11a1d
commit 7fc4f4f9d7
21 files changed
+691 -610

No files matched your search

+81 -75
View File
@@ -8,9 +8,8 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
import { computed, ref, watch } from "vue";
import { Ellipsis, RotateCcw, Trash2, X } from "@lucide/vue";
import { Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import {
@@ -28,13 +27,15 @@ import { restartAt, withRuns, workflowGraph } from "./workflow-graph";
import { api } from "@/lib/api";
import StepEditor from "./StepEditor.vue";
import WorkflowSettings from "./WorkflowSettings.vue";
import TriggerSettings from "./TriggerSettings.vue";
import OptionSelect from "./OptionSelect.vue";
import RunWorkflowButton from "./RunWorkflowButton.vue";
import TaskRowActions from "@/tasks/TaskRowActions.vue";
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, type StepPath } from "./workflow-edit";
import { deleteStep, duplicateStep, insertStep, moveStep, replaceStep, stepAt, workflowField, type StepPath } from "./workflow-edit";
import { useWorkflowRuns } from "./workflow-runs";
import { useWorkflowTriggers } from "./workflow-triggers";
import { cloneControlPlaneValue, useSettingsStore } from "@/stores/settings";
@@ -46,6 +47,8 @@ import {
} from "@/stores/workflows";
import {
parseWorkflowYaml,
settingsProblem,
stepControlsProblem,
validationLabel,
yamlLines,
yamlTokenClass,
@@ -68,27 +71,28 @@ defineProps<{ runsCount?: number }>();
const id = ref("");
const yaml = ref("");
const loadedYaml = ref("");
const selectedStep = ref<StepPath | null>(null);
// The slide-in panel shows one thing: a step's editor, or the workflow's settings.
const settingsOpen = ref(false);
watch(selectedStep, (path) => {
if (path) settingsOpen.value = false;
});
// The one card open in place: "workflow", "start", or a step's path as JSON.
const open = ref<string | null>(null);
const openPath = computed<StepPath | null>(() => (open.value?.startsWith("[") ? (JSON.parse(open.value) as StepPath) : null));
function openStepAt(path: StepPath | null): void {
open.value = path ? JSON.stringify(path) : null;
}
const localError = ref("");
const { runs, error: runsError, loading: runsLoading, watched, watchedRun, stages, attempt, pick, follow, refresh } = useWorkflowRuns(selected);
const stepTab = ref("definition");
const selectedNode = computed(() => withRuns(workflowGraph(yaml.value), stages.value).nodes.find((node) => JSON.stringify(node.data.path) === JSON.stringify(selectedStep.value))?.data);
function openStep(path: StepPath): void {
selectedStep.value = path;
stepTab.value = selectedNode.value?.run && watchedRun.value ? "run" : "definition";
const graph = computed(() => withRuns(workflowGraph(yaml.value), stages.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;
stepTab.value = run && watchedRun.value ? "run" : "definition";
}
watch(watched, () => { selectedStep.value = null; restartError.value = ""; });
watch(watched, () => { open.value = null; restartError.value = ""; });
// A parked run restarts at a step through the retry action, keeping the
// results of the steps before it.
const restartable = computed(() => watchedRun.value?.status === "parked");
const selectedRestart = computed(() => restartable.value && selectedStep.value ? restartAt(withRuns(workflowGraph(yaml.value), stages.value), selectedStep.value) : null);
const openRestart = computed(() => restartable.value && openPath.value ? restartAt(graph.value, openPath.value) : null);
const restarting = ref(false);
const restartError = ref("");
async function restartFrom(from: string): Promise<void> {
@@ -120,7 +124,7 @@ function openRevision(version: number): void {
// A restored version is an unsaved edit: nothing is written until Save.
function restoreRevision(restored: string): void {
yaml.value = restored;
selectedStep.value = null;
open.value = null;
view.value = "canvas";
}
@@ -130,22 +134,26 @@ function insertAt(after: StepPath, type: string): void {
stepTab.value = "definition";
const inserted = insertStep(yaml.value, after, type);
yaml.value = inserted.source;
selectedStep.value = inserted.path;
openStepAt(inserted.path);
}
function duplicateAt(path: StepPath): void {
stepTab.value = "definition";
const copied = duplicateStep(yaml.value, path);
yaml.value = copied.source;
selectedStep.value = copied.path;
openStepAt(copied.path);
}
function moveAt(path: StepPath, delta: -1 | 1): void {
const moved = moveStep(yaml.value, path, delta);
yaml.value = moved.source;
if (selectedStep.value) selectedStep.value = moved.path;
if (openPath.value) openStepAt(moved.path);
}
function removeAt(path: StepPath): void {
yaml.value = deleteStep(yaml.value, path);
selectedStep.value = null;
open.value = null;
}
function renameAt(path: StepPath, name: string): void {
const { id: _id, type, ...rest } = stepAt(yaml.value, path) ?? {};
yaml.value = replaceStep(yaml.value, path, { id: name || undefined, type, ...rest });
}
const shippedEntry = computed(() =>
@@ -159,7 +167,7 @@ function load(value: string): void {
id.value = entry?.id ?? value;
yaml.value = entry?.yaml ?? `id: ${value}\nsteps: []\n`;
loadedYaml.value = yaml.value;
selectedStep.value = null;
open.value = null;
localError.value = "";
}
@@ -233,6 +241,31 @@ const parsed = computed(() => parseWorkflowYaml(yaml.value, vocabulary.value));
const stored = computed(() => collection.value.definitions.find((entry) => entry.id === selected.value)?.yaml);
const dirty = computed(() => yaml.value !== (stored.value ?? ""));
const view = ref("canvas");
// What each step lacks, read the way its editor reads it.
const problems = computed(() =>
Object.fromEntries(
graph.value.nodes.flatMap((node) => {
const path = node.data.path;
const step = path && stepAt(yaml.value, path);
if (!step) return [];
const schema = vocabulary.value.find((info) => info.name === step.type)?.settings;
const problem = stepControlsProblem(step) || (schema && step.settings ? settingsProblem(step.settings, schema, "settings") : "");
return problem ? [[JSON.stringify(path), problem]] : [];
}),
),
);
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 runOptions = computed(() => [
{ value: "", label: "Definition only" },
...runs.value.map((run) => ({
value: String(run.id),
label: [`${run.source === "test" ? "Test" : "Run"} #${run.id}`, run.title, run.status, runRevision(run) ? `v${runRevision(run)!.version}` : ""].filter(Boolean).join(" · "),
})),
]);
const lines = computed(() => yamlLines(yaml.value));
// The highlight layer sits behind the textarea and never scrolls by itself, so
@@ -256,18 +289,7 @@ function syncScroll(event: Event): void {
<TabsTrigger v-if="$slots.runs" value="runs">Runs <span class="ml-1 font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
</TabsList>
<div v-if="runs.length && view === 'canvas'" class="flex min-w-0 items-center gap-1">
<NativeSelect
size="sm"
:model-value="watched"
aria-label="Run shown on the canvas"
class="min-w-0 max-w-64"
@update:model-value="(value) => pick(String(value))"
>
<NativeSelectOption value="">Definition only</NativeSelectOption>
<NativeSelectOption v-for="run in runs" :key="run.id" :value="String(run.id)">{{
[`${run.source === "test" ? "Test" : "Run"} #${run.id}`, run.title, run.status, runRevision(run) ? `v${runRevision(run)!.version}` : ""].filter(Boolean).join(" · ")
}}</NativeSelectOption>
</NativeSelect>
<OptionSelect :model-value="watched" :options="runOptions" aria-label="Run shown on the canvas" class="min-w-0 max-w-64" @update:model-value="pick" />
<template v-if="watchedRun">
<RouterLink :to="`/tasks/${watchedRun.id}`" class="shrink-0 px-1 text-xs text-muted-foreground hover:text-foreground hover:underline">Open</RouterLink>
<button v-if="watchedRevision" type="button" class="shrink-0 px-1 font-mono text-xs text-muted-foreground hover:text-foreground hover:underline" title="Open the version this run used" @click="openRevision(watchedRevision.version)">v{{ watchedRevision.version }}</button>
@@ -297,7 +319,7 @@ function syncScroll(event: Event): void {
<Spinner v-if="state.saving" data-icon="inline-start" />Save</Button>
</template>
</div>
<p v-if="runsLoading" class="text-xs text-fg-muted" role="status">Loading recent runs…</p>
<p v-if="runsLoading && !runs.length" class="text-xs text-fg-muted" role="status">Loading recent runs…</p>
<div v-else-if="runsError" class="text-sm text-danger" role="alert">
<p>Could not load recent runs: {{ runsError }}</p>
<Button type="button" variant="outline" size="sm" @click="refresh">Retry runs</Button>
@@ -311,60 +333,44 @@ function syncScroll(event: Event): void {
<WorkflowCanvas
:yaml="yaml"
:stages="stages"
:selected="selectedStep"
:open="open"
:triggers="triggers"
:types="stepTypeNames"
:restartable="restartable"
@edit="openStep"
:problems="problems"
:title="parsed.ok ? parsed.id : id"
:summary="workflowSummary"
@toggle="toggle"
@restart="restartFrom"
@settings="selectedStep = null; settingsOpen = true"
@insert="insertAt"
@duplicate="duplicateAt"
@move="moveAt"
@remove="removeAt"
/>
<Transition
enter-from-class="translate-x-full opacity-0"
leave-to-class="translate-x-full opacity-0"
enter-active-class="transition duration-200"
leave-active-class="transition duration-150"
@rename="renameAt"
>
<div v-if="settingsOpen" class="absolute inset-y-0 right-0 max-w-full overflow-hidden rounded-r-lg">
<WorkflowSettings v-model:yaml="yaml" :triggers="triggers" @close="settingsOpen = false" @bound="reloadTriggers" />
</div>
</Transition>
<Transition
enter-from-class="translate-x-full opacity-0"
leave-to-class="translate-x-full opacity-0"
enter-active-class="transition duration-200"
leave-active-class="transition duration-150"
>
<div v-if="selectedStep" class="absolute inset-y-0 right-0 flex max-w-full flex-col overflow-hidden rounded-r-lg border-l border-border bg-card shadow-xl">
<template v-if="selectedNode?.run && watchedRun">
<div class="flex items-center gap-2 border-b border-border px-3 py-2">
<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" />
<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>
<span class="min-w-0 flex-1 truncate text-xs" :title="selectedNode.run.name">{{ selectedNode.run.name }}</span>
<Button v-if="selectedRestart" type="button" size="sm" variant="outline" :disabled="restarting || selectedRestart.blocked" @click="restartFrom(selectedRestart.from)"><RotateCcw />{{ selectedRestart.label }}</Button>
<Button type="button" variant="ghost" size="icon-sm" aria-label="Close step details" @click="selectedStep = null"><X /></Button>
<Button v-if="openRestart" type="button" size="sm" variant="outline" class="ml-auto" :disabled="restarting || openRestart.blocked" @click="restartFrom(openRestart.from)"><RotateCcw />{{ openRestart.label }}</Button>
</div>
<div v-if="stepTab === 'run'" class="min-h-0 w-[32rem] max-w-[calc(100vw-3rem)] flex-1 overflow-y-auto">
<StepRun :task="watchedRun" :attempt="attempt" :stage="selectedNode.run" :stages="stages" />
<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>
<StepEditor
v-else
:key="open ?? ''"
v-model:yaml="yaml"
:workflows="collection.definitions"
:path="data.path"
:vocabulary="vocabulary"
:model-aliases="modelAliases"
/>
</template>
<StepEditor
:workflows="collection.definitions"
class="min-h-0 flex-1"
v-if="stepTab === 'definition' || !selectedNode?.run || !watchedRun"
:key="JSON.stringify(selectedStep)"
v-model:yaml="yaml"
:path="selectedStep"
:vocabulary="vocabulary"
:model-aliases="modelAliases"
@close="selectedStep = null"
@remove="removeAt(selectedStep)"
/>
</div>
</Transition>
</template>
</WorkflowCanvas>
</div>
</TabsContent>
<TabsContent value="history">