Files
archie/ui/src/workflows/WorkflowPage.vue
T
samandCopilot 264062866c feat(ui): run events, workflows, runs, controls and settings pages on the archie binary (#2023)
Events (sources, triggers), workflows (list, document, YAML publish,
read-only canvas), runs with approvals and the decision trail, controls
(policies, guards, action classes), agent models, accepted extensions,
secret engines and credentials now read the binary's API. Capabilities
name every section, so pages the binary can't back yet (the visual
workflow editor, captures, mappings, bindings, the extension catalogue,
model aliases and the rest) stay in the tree, hidden. Adds
GET /api/credential-kinds for the credentials form.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-20 01:04:29 +11:00

114 lines
6.0 KiB
Vue

<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { Badge } from "@/components/ui/badge";
import { Switch } from "@/components/ui/switch";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Spinner } from "@/components/ui/spinner";
import { Button } from "@/components/ui/button";
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
import WorkflowEditor from "./WorkflowEditor.vue";
import { useWorkflowStats } from "./use-workflow-stats";
import { triggerSummary, useWorkflowTriggers } from "./workflow-triggers";
const route = useRoute();
const router = useRouter();
const { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate } = useWorkflowStats();
// The path names the workflow; the editor renames or clears it by publishing
// under another id or deleting, and the URL follows.
const selected = computed({
get: () => String(route.params.id ?? ""),
set: (id: string) => void (id ? router.replace({ name: "workflow-editor", params: { id }, query: route.query }) : router.replace({ name: "workflow-editor-list" })),
});
// ?view= opens a tab and ?run= opens the run dialog; a link carries them once.
const view = ref(["history", "runs"].includes(String(route.query.view)) ? String(route.query.view) : "canvas");
const runOpen = ref(route.query.run !== undefined);
onMounted(() => {
if (route.query.run !== undefined) void router.replace({ query: { ...route.query, run: undefined } });
});
const stored = computed(() => store.collection.definitions);
const known = computed(
() =>
stored.value.some((d) => d.id === selected.value) ||
store.drafts.some((d) => d.id === selected.value) ||
(data.value.workflows ?? []).some((w) => w.workflow === selected.value),
);
const enabled = computed(() => enabledOf(selected.value));
const draft = computed(() => store.drafts.some((d) => d.id === selected.value));
// Whether this workflow is still the one archie ships: "Edited" when it has
// been changed, "Custom" when archie ships nothing by that name.
const provenance = computed(() => {
const shippedYAML = store.shipped.definitions.find((d) => d.id === selected.value)?.yaml;
const storedYAML = stored.value.find((d) => d.id === selected.value)?.yaml;
if (storedYAML === undefined) return "";
if (shippedYAML === undefined) return "Custom";
return shippedYAML === storedYAML ? "" : "Edited";
});
const stages = computed(() => (data.value.stages ?? []).filter((s) => s.workflow === selected.value));
const startedBy = computed(() => data.value.definitions?.find((d) => d.id === selected.value)?.started_by ?? []);
const { triggers, reload: reloadTriggers, error: triggersError } = useWorkflowTriggers(selected, startedBy);
const trigger = computed(() => triggerSummary(triggers.value));
async function copy(id: string) {
const next = await duplicate(id);
if (next) selected.value = next;
}
</script>
<template>
<div class="max-md:flex max-md:min-h-0 max-md:flex-1 max-md:flex-col">
<div v-if="error || store.error" class="mb-4 text-label text-danger" role="alert">
<p>{{ error || store.error }}</p>
<Button variant="outline" size="sm" @click="load(); store.load()">Retry</Button>
</div>
<p v-if="loading || (!store.state.resource && !store.error)" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading workflow…</p>
<Empty v-else-if="!known && !error">
<EmptyHeader>
<EmptyTitle>Workflow not found</EmptyTitle>
</EmptyHeader>
</Empty>
<!-- No card around the editor: the canvas draws its own frame. -->
<div v-else-if="known" 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">
<header class="mb-2 flex shrink-0 flex-wrap items-center gap-x-3 gap-y-0.5 lg:hidden">
<h1 class="min-w-0 truncate text-title font-medium">{{ selected }}</h1>
<Switch v-if="enabled !== undefined" size="sm" :model-value="enabled" :aria-label="`${selected} enabled`" @update:model-value="setEnabled(selected, $event)" />
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
<ApplyStatusRows kind="workflow-definitions" compact />
<p v-if="trigger.text || (!triggersError && !triggers.length)" class="flex min-w-0 basis-full items-center gap-1.5 text-caption text-fg-muted lg:basis-0 lg:flex-1">
<span class="truncate">{{ trigger.text || "Manual" }}</span>
<Badge v-if="trigger.more.length" variant="secondary" :title="trigger.more.join('\n')">+{{ trigger.more.length }}</Badge>
</p>
</header>
<WorkflowEditor
v-model:selected="selected"
v-model:view="view"
v-model:run-open="runOpen"
:stage-stats="stages"
:triggers="triggers"
:triggers-error="triggersError"
:stats-known="statsKnown"
:stats-error="error ?? ''"
@duplicate="copy"
@reload-triggers="reloadTriggers"
>
<template #title>
<h1 class="min-w-0 truncate text-title font-medium">{{ selected }}</h1>
<Switch v-if="enabled !== undefined" size="sm" :model-value="enabled" :aria-label="`${selected} enabled`" @update:model-value="setEnabled(selected, $event)" />
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
<ApplyStatusRows kind="workflow-definitions" compact />
<p v-if="trigger.text || (!triggersError && !triggers.length)" class="flex min-w-0 max-w-64 items-center gap-1.5 text-caption text-fg-muted">
<span class="truncate">{{ trigger.text || "Manual" }}</span>
<Badge v-if="trigger.more.length" variant="secondary" :title="trigger.more.join('\n')">+{{ trigger.more.length }}</Badge>
</p>
</template>
</WorkflowEditor>
</div>
</div>
</template>