|
|
|
@@ -9,14 +9,13 @@ import {
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
} from "@/components/ui/alert-dialog";
|
|
|
|
|
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
|
|
|
|
import { ChevronDown, Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
|
|
|
|
|
import { CircleAlert, Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
|
|
|
|
|
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
|
|
|
|
import { Spinner } from "@/components/ui/spinner";
|
|
|
|
@@ -38,10 +37,10 @@ import { revisionOfRun, type WorkflowRevision } from "./workflow-revisions";
|
|
|
|
|
import { deleteStep, duplicateStep, insertStep, moveStep, replaceStep, revertWorkflowChange, stepAt, workflowChanges, workflowField, type StepPath } from "./workflow-edit";
|
|
|
|
|
import ChangeList from "@/components/ChangeList.vue";
|
|
|
|
|
import CoBuilder from "./CoBuilder.vue";
|
|
|
|
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
|
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
|
|
|
|
import { useWorkflowRuns } from "./workflow-runs";
|
|
|
|
|
import { useWorkflowTriggers } from "./workflow-triggers";
|
|
|
|
|
import { cloneControlPlaneValue, useSettingsStore } from "@/stores/settings";
|
|
|
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
|
|
|
import {
|
|
|
|
|
removeWorkflowDefinition,
|
|
|
|
|
upsertWorkflowDefinition,
|
|
|
|
@@ -67,7 +66,6 @@ const modelAliases = computed(() =>
|
|
|
|
|
.sort(),
|
|
|
|
|
);
|
|
|
|
|
const collection = computed(() => workflows.collection);
|
|
|
|
|
const shipped = computed(() => workflows.shipped);
|
|
|
|
|
// Which definition is open belongs to the page, which also lists them.
|
|
|
|
|
const selected = defineModel<string>("selected", { required: true });
|
|
|
|
|
defineProps<{ runsCount?: number }>();
|
|
|
|
@@ -159,10 +157,6 @@ function renameAt(path: StepPath, name: string): void {
|
|
|
|
|
yaml.value = replaceStep(yaml.value, path, { id: name || undefined, type, ...rest });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const shippedEntry = computed(() =>
|
|
|
|
|
shipped.value.definitions.find((entry) => entry.id === id.value),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
function load(value: string): void {
|
|
|
|
|
const entry = collection.value.definitions.find(
|
|
|
|
|
(candidate) => candidate.id === value,
|
|
|
|
@@ -240,7 +234,8 @@ async function takeProposal(): Promise<void> {
|
|
|
|
|
unsaved = undefined;
|
|
|
|
|
load(selected.value);
|
|
|
|
|
}
|
|
|
|
|
async function discard(): Promise<void> {
|
|
|
|
|
// Back to the published definition: the draft is dropped, not merged.
|
|
|
|
|
async function restorePublished(): Promise<void> {
|
|
|
|
|
await dropDraft(selected.value);
|
|
|
|
|
load(selected.value);
|
|
|
|
|
}
|
|
|
|
@@ -274,6 +269,10 @@ 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.
|
|
|
|
|
const runOpen = ref(false);
|
|
|
|
|
const draftOpen = ref(false);
|
|
|
|
|
const confirmDelete = ref(false);
|
|
|
|
|
async function remove(): Promise<void> {
|
|
|
|
|
if (!selected.value) return;
|
|
|
|
@@ -287,22 +286,6 @@ async function remove(): Promise<void> {
|
|
|
|
|
yaml.value = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function restoreOne(): Promise<void> {
|
|
|
|
|
if (!shippedEntry.value) return;
|
|
|
|
|
// The restored definition replaces whatever draft was open.
|
|
|
|
|
if (
|
|
|
|
|
await save(
|
|
|
|
|
upsertWorkflowDefinition(
|
|
|
|
|
collection.value,
|
|
|
|
|
cloneControlPlaneValue(shippedEntry.value),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
await dropDraft(selected.value);
|
|
|
|
|
load(selected.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// What is typed, read against the served step vocabulary (workflow-yaml.ts).
|
|
|
|
|
// The Steps preview, the gutter and the validity indicator are three readings
|
|
|
|
|
// of one parse, so they cannot disagree about the same text. Step settings are
|
|
|
|
@@ -339,9 +322,10 @@ const runOptions = computed(() => [
|
|
|
|
|
})),
|
|
|
|
|
]);
|
|
|
|
|
const lines = computed(() => yamlLines(yaml.value));
|
|
|
|
|
// Below md the section tabs that do not fit beside Canvas and YAML are picked
|
|
|
|
|
// from one menu, which also names the section in view.
|
|
|
|
|
const OVERFLOW: Record<string, string> = { history: "History", performance: "Performance", runs: "Runs" };
|
|
|
|
|
// The sections that sit beside Canvas and YAML once the editor has the width
|
|
|
|
|
// for them (the workflow list takes 24rem of it), and otherwise the one menu,
|
|
|
|
|
// which names the section in view beside the tabs.
|
|
|
|
|
const SECTIONS: Record<string, string> = { history: "History", performance: "Performance", runs: "Runs" };
|
|
|
|
|
|
|
|
|
|
// The highlight layer sits behind the textarea and never scrolls by itself, so
|
|
|
|
|
// it follows the textarea's own scroll on both axes.
|
|
|
|
@@ -356,79 +340,80 @@ function syncScroll(event: Event): void {
|
|
|
|
|
<template>
|
|
|
|
|
<form class="space-y-4" @submit.prevent="publish">
|
|
|
|
|
<Tabs v-model="view" class="space-y-1.5">
|
|
|
|
|
<div class="flex flex-wrap items-center gap-2">
|
|
|
|
|
<TabsList class="max-w-full justify-start">
|
|
|
|
|
<!--
|
|
|
|
|
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">
|
|
|
|
|
<TabsList class="shrink-0 justify-start">
|
|
|
|
|
<TabsTrigger value="canvas">Canvas</TabsTrigger>
|
|
|
|
|
<TabsTrigger value="yaml">YAML</TabsTrigger>
|
|
|
|
|
<TabsTrigger v-if="stored !== undefined" value="history" class="max-md:hidden">History</TabsTrigger>
|
|
|
|
|
<TabsTrigger v-if="$slots.performance" value="performance" class="max-md:hidden">Performance</TabsTrigger>
|
|
|
|
|
<TabsTrigger v-if="$slots.runs" value="runs" class="max-md:hidden">Runs <span class="ml-1 font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
|
|
|
|
|
<TabsTrigger v-if="stored !== undefined" value="history" class="max-xl:hidden">History</TabsTrigger>
|
|
|
|
|
<TabsTrigger v-if="$slots.performance" value="performance" class="max-xl:hidden">Performance</TabsTrigger>
|
|
|
|
|
<TabsTrigger v-if="$slots.runs" value="runs" class="max-xl:hidden">Runs <span class="ml-1 font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
|
|
|
|
|
</TabsList>
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger as-child>
|
|
|
|
|
<Button type="button" variant="outline" size="sm" class="md:hidden" aria-label="More sections">
|
|
|
|
|
{{ OVERFLOW[view] ?? "More" }}<ChevronDown data-icon="inline-end" />
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="start" class="w-40">
|
|
|
|
|
<DropdownMenuItem v-if="stored !== undefined" @select="view = 'history'">History</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="$slots.performance" @select="view = 'performance'">Performance</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="$slots.runs" @select="view = 'runs'">Runs <span class="ml-auto font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
<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-64" @update:model-value="pick" />
|
|
|
|
|
<template v-if="watchedRun">
|
|
|
|
|
<RouterLink :to="`/tasks/${watchedRun.id}`" class="shrink-0 px-1 text-xs text-fg-muted hover:text-foreground hover:underline">Open</RouterLink>
|
|
|
|
|
<button v-if="watchedRevision" type="button" class="shrink-0 px-1 font-mono text-xs text-fg-muted hover:text-foreground hover:underline" title="Open the version this run used" @click="openRevision(watchedRevision.version)">v{{ watchedRevision.version }}</button>
|
|
|
|
|
<TaskRowActions :task="watchedRun" class="shrink-0" @done="refresh" />
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
<template v-if="view === 'canvas' || view === 'yaml'">
|
|
|
|
|
<div class="ml-auto flex flex-wrap items-center justify-end gap-2">
|
|
|
|
|
<span v-if="!parsed.ok" class="max-w-md truncate text-xs text-danger" role="status" :title="validationLabel(parsed)">
|
|
|
|
|
{{ validationLabel(parsed) }}
|
|
|
|
|
<span v-if="SECTIONS[view]" class="shrink-0 text-xs font-medium text-fg-muted xl:hidden">{{ SECTIONS[view] }}</span>
|
|
|
|
|
<div class="ml-auto flex min-w-0 items-center gap-1">
|
|
|
|
|
<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" @update:model-value="pick" />
|
|
|
|
|
<template v-if="watchedRun">
|
|
|
|
|
<Button as-child variant="ghost" size="sm" class="max-md:hidden"><RouterLink :to="`/tasks/${watchedRun.id}`">Open</RouterLink></Button>
|
|
|
|
|
<Button v-if="watchedRevision" type="button" variant="ghost" size="sm" class="max-md:hidden font-mono text-xs" title="Open the version this run used" @click="openRevision(watchedRevision.version)">v{{ watchedRevision.version }}</Button>
|
|
|
|
|
<!-- One run control keeps the row short; the run's other actions
|
|
|
|
|
are on the run, one Open away. -->
|
|
|
|
|
<TaskRowActions :task="watchedRun" :only="watchedRun.actions?.slice(0, 1)" class="max-md:hidden" @done="refresh" />
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
<span v-if="!parsed.ok" class="hidden max-w-md truncate text-xs text-danger sm:block" role="status" :title="validationLabel(parsed)">{{ validationLabel(parsed) }}</span>
|
|
|
|
|
<span v-if="!parsed.ok" class="sm:hidden" role="status" :title="validationLabel(parsed)">
|
|
|
|
|
<CircleAlert class="size-4 text-danger" aria-hidden="true" /><span class="sr-only">{{ validationLabel(parsed) }}</span>
|
|
|
|
|
</span>
|
|
|
|
|
<Popover v-else-if="dirty">
|
|
|
|
|
<PopoverTrigger as-child>
|
|
|
|
|
<Button type="button" variant="ghost" size="sm" class="text-xs text-fg-subtle">
|
|
|
|
|
Draft · {{ changes.length }} {{ changes.length === 1 ? "change" : "changes" }}</Button>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
<PopoverContent align="end" class="max-h-96 w-96 overflow-y-auto p-0">
|
|
|
|
|
<ChangeList :changes="changes" @revert="(change) => (yaml = revertWorkflowChange(yaml, change))" />
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
|
|
|
|
<!-- 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">
|
|
|
|
|
<RunWorkflowButton
|
|
|
|
|
v-model:open="runOpen"
|
|
|
|
|
:workflow="selected"
|
|
|
|
|
:draft="dirty ? yaml : undefined"
|
|
|
|
|
:disabled="!parsed.ok"
|
|
|
|
|
@started="(id) => { view = 'canvas'; void follow(id); }"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger as-child>
|
|
|
|
|
<Button type="button" variant="ghost" size="icon-sm" aria-label="More"><Ellipsis /></Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="end" class="w-48">
|
|
|
|
|
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="discard"><RotateCcw />Discard draft</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="shippedEntry" @select="restoreOne"><RotateCcw />Restore default</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuSeparator v-if="dirty || shippedEntry" />
|
|
|
|
|
<DropdownMenuItem variant="destructive" @select="confirmDelete = true"><Trash2 />Delete workflow</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="stored !== undefined" class="xl:hidden" @select="view = 'history'">History</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="$slots.performance" class="xl:hidden" @select="view = 'performance'">Performance</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="$slots.runs" class="xl:hidden" @select="view = 'runs'">Runs <span class="ml-auto font-mono text-xs text-fg-subtle">{{ runsCount ?? 0 }}</span></DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="watchedRun" as-child class="md:hidden"><RouterLink :to="`/tasks/${watchedRun.id}`">Open run</RouterLink></DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="watchedRevision" class="md:hidden" @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="dirty" @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>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
<RunWorkflowButton v-if="stored !== undefined" :workflow="selected" :draft="yaml" :disabled="!parsed.ok" @started="(id) => { view = 'canvas'; void follow(id); }" />
|
|
|
|
|
<RunWorkflowButton v-if="stored !== undefined" :workflow="selected" :disabled="dirty" @started="(id) => { view = 'canvas'; void follow(id); }" />
|
|
|
|
|
<Button type="submit" size="sm" :disabled="state.saving || !parsed.ok || !dirty || archieWorking">
|
|
|
|
|
<Button v-if="view === 'canvas' || view === 'yaml'" type="submit" size="sm" :disabled="state.saving || !parsed.ok || !dirty || archieWorking">
|
|
|
|
|
<Spinner v-if="state.saving" data-icon="inline-start" />Publish</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
<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>
|
|
|
|
|
</div>
|
|
|
|
|
<p v-if="watchedRun && !watchedRun.workflow_definition_yaml" class="text-xs text-fg-muted" role="status">No workflow snapshot was recorded for this run.</p>
|
|
|
|
|
<p v-if="view === 'canvas' && watchedRun && !watchedRun.workflow_definition_yaml" 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. A phone stacks more chrome
|
|
|
|
|
above it (the workflow list, a two-row toolbar and the run picker),
|
|
|
|
|
hence the larger offset below md. -->
|
|
|
|
|
itself does not scroll; the canvas pans. A phone stacks the run
|
|
|
|
|
selector over the step tooling, hence the larger offset below md. -->
|
|
|
|
|
<div class="relative flex h-[calc(100dvh-17rem)] min-h-[26rem] flex-col max-md:h-[calc(100dvh-22rem)] max-md:min-h-[23rem]">
|
|
|
|
|
<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
|
|
|
|
@@ -552,6 +537,16 @@ function syncScroll(event: Event): void {
|
|
|
|
|
<p v-if="localError || state.error" class="text-sm text-danger" role="alert">
|
|
|
|
|
{{ localError || state.error }}
|
|
|
|
|
</p>
|
|
|
|
|
<Dialog v-model:open="draftOpen">
|
|
|
|
|
<DialogContent class="sm:max-w-lg">
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>Draft changes</DialogTitle>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<div class="max-h-96 overflow-y-auto rounded-md border border-border">
|
|
|
|
|
<ChangeList :changes="changes" @revert="(change) => (yaml = revertWorkflowChange(yaml, change))" />
|
|
|
|
|
</div>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
<AlertDialog v-model:open="confirmDelete">
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
<AlertDialogHeader>
|
|
|
|
|