feat(runs,events,ui): identify workflows by immutable UUID (#2125)
This commit is contained in:
46 files changed
+1284
-512
No files matched your search
@@ -14,6 +14,8 @@ export interface Binding {
|
||||
source: string;
|
||||
event_type_id?: string;
|
||||
mapping_id?: string;
|
||||
workflow_id?: string;
|
||||
/** The workflow's name. */
|
||||
workflow?: string;
|
||||
status?: string;
|
||||
/** The source takes deliveries with no verification. */
|
||||
@@ -27,6 +29,7 @@ export function bindingOfTrigger(trigger: Trigger): Binding {
|
||||
source: trigger.source ?? "",
|
||||
event_type_id: trigger.event_type_id,
|
||||
mapping_id: trigger.mapping_id,
|
||||
workflow_id: trigger.workflow_id,
|
||||
workflow: trigger.workflow,
|
||||
status: trigger.status,
|
||||
unsigned: trigger.unsigned,
|
||||
@@ -64,6 +67,7 @@ export interface BindingDraft {
|
||||
/** The event type the binding applies to; its source is the binding's. */
|
||||
eventTypeId: string;
|
||||
mappingId: string;
|
||||
/** The id of the workflow the binding starts. */
|
||||
workflow: string;
|
||||
}
|
||||
|
||||
@@ -77,7 +81,7 @@ export function draftFromBinding(binding: Binding): BindingDraft {
|
||||
name: binding.name,
|
||||
eventTypeId: binding.event_type_id || "",
|
||||
mappingId: binding.mapping_id || "",
|
||||
workflow: binding.workflow || "",
|
||||
workflow: binding.workflow_id || "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -92,7 +96,7 @@ export function bindingPayload(
|
||||
source_id: eventType?.source_id ?? "",
|
||||
event_type_id: draft.eventTypeId,
|
||||
mapping_id: draft.mappingId || undefined,
|
||||
workflow: draft.workflow,
|
||||
workflow_id: draft.workflow,
|
||||
disabled: false,
|
||||
pending: true,
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ export function useBindings() {
|
||||
bindings.value = triggers.filter((x) => x.event_type_id).map(bindingOfTrigger);
|
||||
mappings.value = m.mappings || [];
|
||||
eventTypes.value = t.event_types || [];
|
||||
workflows.value = w.map((d) => ({ id: d.name, name: d.name }));
|
||||
workflows.value = w.map((d) => ({ id: d.id, name: d.name }));
|
||||
} catch (err) {
|
||||
failure.value = failureFor(err);
|
||||
bindings.value = null;
|
||||
|
||||
@@ -43,7 +43,7 @@ interface TaskEntry {
|
||||
|
||||
const pages = computed(() => navEntries(props.hidden));
|
||||
const tasks = ref<TaskEntry[]>([]);
|
||||
const workflows = ref<string[]>([]);
|
||||
const workflows = ref<{ id: string; name: string }[]>([]);
|
||||
const shortcut = navigator.platform.startsWith("Mac") ? "⌘K" : "Ctrl K";
|
||||
const showWorkflows = computed(() => !props.hidden.includes("/workflows"));
|
||||
const showTasks = computed(() => !props.hidden.includes("/tasks"));
|
||||
@@ -63,7 +63,7 @@ async function loadEntries(): Promise<void> {
|
||||
tasksError.value = taskPage === null;
|
||||
tasks.value = taskPage?.tasks ?? [];
|
||||
workflowsError.value = workflowList === null;
|
||||
workflows.value = (workflowList ?? []).map(({ name }) => name);
|
||||
workflows.value = (workflowList ?? []).map(({ id, name }) => ({ id, name }));
|
||||
}
|
||||
|
||||
watch(open, (value) => {
|
||||
@@ -129,12 +129,12 @@ onUnmounted(() => document.removeEventListener("keydown", onGlobalKeydown));
|
||||
</CommandGroup>
|
||||
<CommandGroup v-else-if="workflows.length" heading="Workflows">
|
||||
<CommandItem
|
||||
v-for="id in workflows"
|
||||
:key="id"
|
||||
:value="`workflow:${id}`"
|
||||
@select="go(`/workflows/${encodeURIComponent(id)}`)"
|
||||
v-for="workflow in workflows"
|
||||
:key="workflow.id"
|
||||
:value="`workflow:${workflow.name}`"
|
||||
@select="go(`/workflows/${encodeURIComponent(workflow.id)}`)"
|
||||
>
|
||||
{{ id }}
|
||||
{{ workflow.name }}
|
||||
</CommandItem>
|
||||
</CommandGroup>
|
||||
<CommandGroup v-if="tasksError" heading="Tasks">
|
||||
|
||||
@@ -23,7 +23,8 @@ import { useRead } from "@/lib/use-read";
|
||||
import { interval } from "@/workflows/use-workflow-list";
|
||||
import { triggerInput } from "./trigger";
|
||||
|
||||
/** With `workflow`, only the triggers that run it, and new ones run it. */
|
||||
/** With `workflow`, a workflow's id, only the triggers that run it, and new
|
||||
* ones run it. */
|
||||
const props = defineProps<{ workflow?: string }>();
|
||||
|
||||
const { data, error, reload } = useRead(() => api.triggers());
|
||||
@@ -34,7 +35,7 @@ onMounted(() => {
|
||||
void sources.reload();
|
||||
if (!props.workflow) void workflows.reload();
|
||||
});
|
||||
const rows = computed(() => (data.value ?? []).filter((t) => !props.workflow || t.workflow === props.workflow));
|
||||
const rows = computed(() => (data.value ?? []).filter((t) => !props.workflow || t.workflow_id === props.workflow));
|
||||
|
||||
const columns = computed<DataTableColumn<Trigger>[]>(() => [
|
||||
{ id: "name", label: "Trigger", fixed: true, width: "auto", sort: (t) => t.name },
|
||||
@@ -73,7 +74,7 @@ function open(trigger?: Trigger): void {
|
||||
source_id: trigger?.every ? "" : (trigger?.source_id ?? ""),
|
||||
event_type: trigger?.every ? "" : (trigger?.event_type ?? ""),
|
||||
every: trigger?.every ?? "",
|
||||
workflow: trigger?.workflow ?? props.workflow ?? "",
|
||||
workflow: trigger?.workflow_id ?? props.workflow ?? "",
|
||||
filter: trigger?.every ? "" : toLines(trigger?.filter ?? {}),
|
||||
disabled: trigger ? !trigger.enabled : false,
|
||||
};
|
||||
@@ -84,8 +85,8 @@ async function submit(): Promise<void> {
|
||||
const filter = fromLines(f.filter);
|
||||
const input: TriggerInput =
|
||||
f.mode === "schedule"
|
||||
? { every: f.every.trim(), workflow: f.workflow, disabled: f.disabled }
|
||||
: { source_id: f.source_id, event_type: f.event_type.trim(), filter, workflow: f.workflow, disabled: f.disabled };
|
||||
? { every: f.every.trim(), workflow_id: f.workflow, disabled: f.disabled }
|
||||
: { source_id: f.source_id, event_type: f.event_type.trim(), filter, workflow_id: f.workflow, disabled: f.disabled };
|
||||
if (await save(f.name.trim(), input)) editing.value = false;
|
||||
}
|
||||
</script>
|
||||
@@ -105,7 +106,7 @@ async function submit(): Promise<void> {
|
||||
<template v-if="row.every">Every {{ interval(row.every) }}</template>
|
||||
<template v-else>{{ row.source }} <span class="font-mono text-caption text-fg-muted">{{ row.event_type }}</span></template>
|
||||
</template>
|
||||
<template #cell-workflow="{ row }"><RouterLink class="hover:underline" :to="`/workflows/${row.workflow}`">{{ row.workflow }}</RouterLink></template>
|
||||
<template #cell-workflow="{ row }"><RouterLink class="hover:underline" :to="`/workflows/${row.workflow_id}`">{{ row.workflow }}</RouterLink></template>
|
||||
<template #cell-filter="{ row }">
|
||||
<span v-if="!row.every" class="font-mono text-caption">{{ Object.entries(row.filter ?? {}).map(([k, v]) => `${k}=${v}`).join(", ") }}</span>
|
||||
</template>
|
||||
@@ -142,7 +143,7 @@ async function submit(): Promise<void> {
|
||||
<Select v-if="!workflow" v-model="form.workflow" required>
|
||||
<SelectTrigger class="w-full" aria-label="Workflow"><SelectValue placeholder="Workflow it runs" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="w in workflows.data.value ?? []" :key="w.name" :value="w.name">{{ w.name }}</SelectItem>
|
||||
<SelectItem v-for="w in workflows.data.value ?? []" :key="w.id" :value="w.id">{{ w.name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p v-if="actionError" role="alert" class="text-caption text-danger">{{ actionError }}</p>
|
||||
|
||||
@@ -3,12 +3,12 @@ import type { Trigger, TriggerInput } from "@/lib/api";
|
||||
/** triggerInput is the put that keeps a listed trigger as it is. A schedule
|
||||
* sends only its interval: the server fixes its source, type and filter. */
|
||||
export function triggerInput(trigger: Trigger): TriggerInput {
|
||||
if (trigger.every) return { every: trigger.every, workflow: trigger.workflow, disabled: !trigger.enabled };
|
||||
if (trigger.every) return { every: trigger.every, workflow_id: trigger.workflow_id, disabled: !trigger.enabled };
|
||||
return {
|
||||
source_id: trigger.source_id,
|
||||
event_type: trigger.event_type,
|
||||
filter: trigger.filter,
|
||||
workflow: trigger.workflow,
|
||||
workflow_id: trigger.workflow_id,
|
||||
disabled: !trigger.enabled,
|
||||
};
|
||||
}
|
||||
+44
-19
@@ -185,7 +185,7 @@ async function request<T = unknown>(
|
||||
|
||||
export const api = {
|
||||
// The archie binary's module API; the wire types are below the object.
|
||||
runs: (limit = 200, workflow?: string) => request<Run[]>("/api/runs" + qs({ limit, workflow })),
|
||||
runs: (limit = 200, workflowId?: string) => request<Run[]>("/api/runs" + qs({ limit, workflow_id: workflowId })),
|
||||
run: (id: string) => request<RunTrail>(`/api/runs/${encodeURIComponent(id)}`),
|
||||
/** Queues a parked run again from the step that parked it, or from `from`. */
|
||||
retryRun: (id: string, from?: string) =>
|
||||
@@ -245,32 +245,36 @@ export const api = {
|
||||
putTrigger: (name: string, trigger: TriggerInput) =>
|
||||
request<{ trigger: string }>(`/api/triggers/${encodeURIComponent(name)}`, { method: "PUT", body: trigger }),
|
||||
workflowList: () => request<WorkflowVersion[]>("/api/workflows"),
|
||||
workflow: (name: string, version?: number) =>
|
||||
request<WorkflowVersion>(`/api/workflows/${encodeURIComponent(name)}` + qs({ version })),
|
||||
/** Publishes a document as the next version; `expectedVersion` makes the save fail with 409 when another is stored. */
|
||||
putWorkflow: (name: string, body: string, expectedVersion?: number) =>
|
||||
request<WorkflowVersion>(`/api/workflows/${encodeURIComponent(name)}`, { method: "PUT", body: { body, expected_version: expectedVersion } }),
|
||||
deleteWorkflow: (name: string) => request<void>(`/api/workflows/${encodeURIComponent(name)}`, { method: "DELETE", parse: false }),
|
||||
setWorkflowEnabled: (name: string, enabled: boolean) =>
|
||||
request<WorkflowVersion>(`/api/workflows/${encodeURIComponent(name)}/enabled`, { method: "PUT", body: { enabled } }),
|
||||
runWorkflow: (name: string, input?: Record<string, unknown>) =>
|
||||
request<Run>(`/api/workflows/${encodeURIComponent(name)}/runs`, { method: "POST", body: { input } }),
|
||||
/** Creates a workflow, publishing body as its first version when given. */
|
||||
createWorkflow: (name: string, body?: string) =>
|
||||
request<WorkflowIdentity>("/api/workflows", { method: "POST", body: body === undefined ? { name } : { name, body } }),
|
||||
renameWorkflow: (id: string, name: string) =>
|
||||
request<WorkflowIdentity>(`/api/workflows/${encodeURIComponent(id)}/name`, { method: "PUT", body: { name } }),
|
||||
workflow: (id: string, version?: number) =>
|
||||
request<WorkflowVersion>(`/api/workflows/${encodeURIComponent(id)}` + qs({ version })),
|
||||
putWorkflow: (id: string, body: string, expectedVersion?: number) =>
|
||||
request<WorkflowVersion>(`/api/workflows/${encodeURIComponent(id)}`, { method: "PUT", body: { body, expected_version: expectedVersion } }),
|
||||
deleteWorkflow: (id: string) => request<void>(`/api/workflows/${encodeURIComponent(id)}`, { method: "DELETE", parse: false }),
|
||||
setWorkflowEnabled: (id: string, enabled: boolean) =>
|
||||
request<WorkflowVersion>(`/api/workflows/${encodeURIComponent(id)}/enabled`, { method: "PUT", body: { enabled } }),
|
||||
runWorkflow: (id: string, input?: Record<string, unknown>) =>
|
||||
request<Run>(`/api/workflows/${encodeURIComponent(id)}/runs`, { method: "POST", body: { input } }),
|
||||
workflowDrafts: () => request<WorkflowDraft[]>("/api/workflow-drafts"),
|
||||
/** A workflow's draft, or null when it has none. */
|
||||
workflowDraft: async (name: string) => {
|
||||
workflowDraft: async (id: string) => {
|
||||
try {
|
||||
return await request<WorkflowDraft>(`/api/workflows/${encodeURIComponent(name)}/draft`);
|
||||
return await request<WorkflowDraft>(`/api/workflows/${encodeURIComponent(id)}/draft`);
|
||||
} catch (cause) {
|
||||
if (cause instanceof ApiError && cause.status === 404) return null;
|
||||
throw cause;
|
||||
}
|
||||
},
|
||||
/** Saves a draft; `revision` is the one last read, 0 for none, and a stale one fails with 409. */
|
||||
putWorkflowDraft: (name: string, body: string, revision: number) =>
|
||||
request<WorkflowDraft>(`/api/workflows/${encodeURIComponent(name)}/draft`, { method: "PUT", body: { body, revision } }),
|
||||
discardWorkflowDraft: (name: string) => request<void>(`/api/workflows/${encodeURIComponent(name)}/draft`, { method: "DELETE", parse: false }),
|
||||
testWorkflowDraft: (name: string, input?: Record<string, unknown>) =>
|
||||
request<Run>(`/api/workflows/${encodeURIComponent(name)}/draft/test-run`, { method: "POST", body: { input } }),
|
||||
putWorkflowDraft: (id: string, body: string, revision: number) =>
|
||||
request<WorkflowDraft>(`/api/workflows/${encodeURIComponent(id)}/draft`, { method: "PUT", body: { body, revision } }),
|
||||
discardWorkflowDraft: (id: string) => request<void>(`/api/workflows/${encodeURIComponent(id)}/draft`, { method: "DELETE", parse: false }),
|
||||
testWorkflowDraft: (id: string, input?: Record<string, unknown>) =>
|
||||
request<Run>(`/api/workflows/${encodeURIComponent(id)}/draft/test-run`, { method: "POST", body: { input } }),
|
||||
workflowStats: () => request<WorkflowStats[]>("/api/workflow-stats"),
|
||||
workflowStepTypes: () => request<StepType[]>("/api/workflow-step-types"),
|
||||
extensionKinds: () => request<ExtensionKindInfo[]>("/api/extension-kinds"),
|
||||
@@ -784,6 +788,9 @@ export interface ChatActionRecord {
|
||||
|
||||
export interface Run {
|
||||
id: string;
|
||||
/** Empty for a test run of a document that isn't a workflow yet. */
|
||||
workflow_id?: string;
|
||||
/** The workflow's current name. */
|
||||
workflow: string;
|
||||
workflow_version: number;
|
||||
state: string;
|
||||
@@ -1048,6 +1055,8 @@ export interface NoRunReason {
|
||||
code: "mapping_mismatch" | "access_denied" | "workflow_disabled" | string;
|
||||
mapping?: string;
|
||||
failures?: MappingFailure[];
|
||||
workflow_id?: string;
|
||||
/** The workflow's name when the dispatch was refused. */
|
||||
workflow?: string;
|
||||
detail?: string;
|
||||
}
|
||||
@@ -1118,6 +1127,8 @@ export interface Trigger {
|
||||
source?: string;
|
||||
event_type?: string;
|
||||
every?: string;
|
||||
workflow_id: string;
|
||||
/** The workflow's current name. */
|
||||
workflow: string;
|
||||
filter?: Record<string, string>;
|
||||
enabled: boolean;
|
||||
@@ -1132,7 +1143,7 @@ export interface TriggerInput {
|
||||
source_id?: string;
|
||||
event_type?: string;
|
||||
every?: string;
|
||||
workflow: string;
|
||||
workflow_id: string;
|
||||
filter?: Record<string, string>;
|
||||
disabled: boolean;
|
||||
event_type_id?: string;
|
||||
@@ -1141,7 +1152,17 @@ export interface TriggerInput {
|
||||
pending?: boolean;
|
||||
}
|
||||
|
||||
/** A workflow apart from its versions. */
|
||||
export interface WorkflowIdentity {
|
||||
id: string;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
/** The version published with it, 0 when none was. */
|
||||
version: number;
|
||||
}
|
||||
|
||||
export interface WorkflowVersion {
|
||||
id: string;
|
||||
name: string;
|
||||
version: number;
|
||||
body: string;
|
||||
@@ -1154,6 +1175,8 @@ export interface WorkflowVersion {
|
||||
|
||||
/** The unpublished edit of a workflow. */
|
||||
export interface WorkflowDraft {
|
||||
workflow_id: string;
|
||||
/** The workflow's name. */
|
||||
name: string;
|
||||
body: string;
|
||||
/** The published version it began from, 0 for a workflow not yet published. */
|
||||
@@ -1165,6 +1188,8 @@ export interface WorkflowDraft {
|
||||
}
|
||||
|
||||
export interface WorkflowStats {
|
||||
workflow_id: string;
|
||||
/** The workflow's name. */
|
||||
workflow: string;
|
||||
total: number;
|
||||
succeeded: number;
|
||||
|
||||
@@ -148,7 +148,8 @@ const result = computed(() => {
|
||||
<MetadataList :rows="details">
|
||||
<template #value="{ row }">
|
||||
<span v-if="row.label === 'Workflow'" class="inline-flex flex-wrap items-center gap-2">
|
||||
<RouterLink class="underline" :to="`/workflows/${data.run.workflow}`">{{ row.value }}</RouterLink>
|
||||
<RouterLink v-if="data.run.workflow_id" class="underline" :to="`/workflows/${data.run.workflow_id}`">{{ row.value }}</RouterLink>
|
||||
<span v-else>{{ row.value }}</span>
|
||||
<Badge variant="outline">v{{ data.run.workflow_version }}</Badge>
|
||||
</span>
|
||||
<span v-else-if="row.label === 'Event' || row.label === 'Run'" class="inline-flex items-center gap-1">
|
||||
|
||||
@@ -48,7 +48,7 @@ const columns: DataTableColumn<Run>[] = [
|
||||
<template #cell-id="{ row }"><span class="font-mono text-caption text-fg-muted">{{ row.id.slice(0, 8) }}</span></template>
|
||||
<template #menu="{ row }">
|
||||
<ContextMenuItem @select="router.push(`/runs/${row.id}`)"><ExternalLink />Open run</ContextMenuItem>
|
||||
<ContextMenuItem @select="router.push(`/workflows/${row.workflow}`)"><Workflow />Open workflow</ContextMenuItem>
|
||||
<ContextMenuItem v-if="row.workflow_id" @select="router.push(`/workflows/${row.workflow_id}`)"><Workflow />Open workflow</ContextMenuItem>
|
||||
</template>
|
||||
<template #empty><slot name="empty" /></template>
|
||||
</DataTable>
|
||||
|
||||
@@ -2,11 +2,12 @@ import { defineStore } from "pinia";
|
||||
import { computed, reactive, ref } from "vue";
|
||||
|
||||
import { errors } from "../copy/errors/index.ts";
|
||||
import { api, ApiError, describeError } from "../lib/api.ts";
|
||||
import { api, ApiError, describeError, type WorkflowDraft, type WorkflowVersion } from "../lib/api.ts";
|
||||
import type { StepTypeInfo } from "../workflows/workflow-yaml.ts";
|
||||
|
||||
export interface WorkflowDefinitionEntry {
|
||||
id: string;
|
||||
name: string;
|
||||
yaml: string;
|
||||
/** The published version the yaml is. */
|
||||
version: number;
|
||||
@@ -19,6 +20,7 @@ export interface WorkflowDefinitionCollection {
|
||||
/** A workflow's unpublished edit. */
|
||||
export interface WorkflowDraftEntry {
|
||||
id: string;
|
||||
name: string;
|
||||
yaml: string;
|
||||
/** The draft's revision as last read; a save names it. */
|
||||
revision: number;
|
||||
@@ -42,7 +44,7 @@ export const useWorkflowsStore = defineStore("workflows", () => {
|
||||
async function load(): Promise<void> {
|
||||
try {
|
||||
const [published, held, types] = await Promise.all([api.workflowList(), api.workflowDrafts(), api.workflowStepTypes()]);
|
||||
definitions.value = published.map((w) => ({ id: w.name, yaml: w.body, version: w.version, enabled: w.enabled }));
|
||||
definitions.value = published.map(definitionEntry);
|
||||
drafts.value = held.map(draftEntry);
|
||||
stepTypes.value = types as StepTypeInfo[];
|
||||
loaded.value = true;
|
||||
@@ -103,8 +105,7 @@ export const useWorkflowsStore = defineStore("workflows", () => {
|
||||
error.value = "";
|
||||
try {
|
||||
const w = await api.putWorkflow(id, yaml, expected);
|
||||
const entry = { id: w.name, yaml: w.body, version: w.version, enabled: w.enabled };
|
||||
definitions.value = [...definitions.value.filter((d) => d.id !== id), entry].sort((a, b) => a.id.localeCompare(b.id));
|
||||
definitions.value = [...definitions.value.filter((d) => d.id !== id), definitionEntry(w)].sort((a, b) => a.name.localeCompare(b.name));
|
||||
drafts.value = drafts.value.filter((draft) => draft.id !== id);
|
||||
return true;
|
||||
} catch (cause) {
|
||||
@@ -115,7 +116,21 @@ export const useWorkflowsStore = defineStore("workflows", () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** Deletes a published workflow with its draft; the server refuses while anything still names it. */
|
||||
/** Creates a workflow called name with yaml as its draft, and returns its id,
|
||||
* or undefined when it couldn't be created. */
|
||||
async function create(name: string, yaml: string): Promise<string | undefined> {
|
||||
draftState.error = "";
|
||||
try {
|
||||
const { id } = await api.createWorkflow(name);
|
||||
drafts.value = [...drafts.value, draftEntry(await api.putWorkflowDraft(id, yaml, 0))];
|
||||
return id;
|
||||
} catch (cause) {
|
||||
draftState.error = describeError(cause, errors.common.unknown);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/** Deletes a workflow with its draft; the server refuses while anything still refers to it. */
|
||||
async function remove(id: string): Promise<boolean> {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
@@ -132,9 +147,13 @@ export const useWorkflowsStore = defineStore("workflows", () => {
|
||||
}
|
||||
}
|
||||
|
||||
return { state, drafts, draftState, putDraft, reloadDrafts, error, collection, stepTypes, load, publish, remove };
|
||||
return { state, drafts, draftState, putDraft, reloadDrafts, error, collection, stepTypes, load, publish, create, remove };
|
||||
});
|
||||
|
||||
function draftEntry(draft: { name: string; body: string; revision: number; base_version: number }): WorkflowDraftEntry {
|
||||
return { id: draft.name, yaml: draft.body, revision: draft.revision, baseVersion: draft.base_version };
|
||||
function definitionEntry(w: WorkflowVersion): WorkflowDefinitionEntry {
|
||||
return { id: w.id, name: w.name, yaml: w.body, version: w.version, enabled: w.enabled };
|
||||
}
|
||||
|
||||
function draftEntry(draft: WorkflowDraft): WorkflowDraftEntry {
|
||||
return { id: draft.workflow_id, name: draft.name, yaml: draft.body, revision: draft.revision, baseVersion: draft.base_version };
|
||||
}
|
||||
@@ -105,7 +105,7 @@ function setTarget(key: string, value: string): void {
|
||||
}
|
||||
write({ ...step.value, settings: next });
|
||||
}
|
||||
const callee = computed(() => props.workflows.find((entry) => entry.id === settings.value.workflow));
|
||||
const callee = computed(() => props.workflows.find((entry) => entry.name === settings.value.workflow));
|
||||
const callInputs = computed(() => declaredSpecs(callee.value?.yaml ?? "", "inputs"));
|
||||
const callOutputs = computed(() => declaredSpecs(callee.value?.yaml ?? "", "outputs"));
|
||||
const callerInputs = computed(() => declaredSpecs(props.yaml, "inputs"));
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||
import { CircleAlert, Copy, ExternalLink, RotateCcw, Square, Trash2 } from "@lucide/vue";
|
||||
import { CircleAlert, Copy, ExternalLink, Pencil, RotateCcw, Square, Trash2 } from "@lucide/vue";
|
||||
import { isSending, setTurnHooks } from "@/chat/state";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -39,7 +39,8 @@ import WorkflowHistory from "./WorkflowHistory.vue";
|
||||
import { revisionOfRun, useWorkflowHistory, type WorkflowRevision } from "./workflow-revisions";
|
||||
import { deleteStep, duplicateStep, insertStep, moveStep, normalizeStepIDs, replaceStep, revertWorkflowChange, stepAt, stepIDs, workflowChanges, type StepPath } from "./workflow-edit";
|
||||
import ChangeList from "@/components/ChangeList.vue";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useWorkflowRuns } from "./workflow-runs";
|
||||
import WorkflowRuns from "./WorkflowRuns.vue";
|
||||
import type { WorkflowTrigger } from "./workflow-triggers";
|
||||
@@ -341,9 +342,28 @@ async function publish(): Promise<void> {
|
||||
const runOpen = defineModel<boolean>("runOpen", { default: false });
|
||||
const draftOpen = ref(false);
|
||||
const confirmDelete = ref(false);
|
||||
// A rename changes only the label: runs, triggers and callers refer to the id.
|
||||
const renaming = ref(false);
|
||||
const newName = ref("");
|
||||
const renameError = ref("");
|
||||
function startRename(): void {
|
||||
newName.value = name.value;
|
||||
renameError.value = "";
|
||||
renaming.value = true;
|
||||
}
|
||||
async function rename(): Promise<void> {
|
||||
try {
|
||||
await api.renameWorkflow(selected.value, newName.value.trim());
|
||||
await Promise.all([workflows.load(), workflows.reloadDrafts()]);
|
||||
renaming.value = false;
|
||||
} catch (cause) {
|
||||
renameError.value = describeError(cause, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
const confirmDiscard = ref(false);
|
||||
// A published workflow is deleted with its draft; one never published has only
|
||||
// the draft to discard. The server refuses a delete while anything names it.
|
||||
// Deleting a workflow discards its draft too. The server refuses a delete while
|
||||
// anything refers to the workflow.
|
||||
async function remove(): Promise<void> {
|
||||
if (!selected.value) return;
|
||||
clearTimeout(pending);
|
||||
@@ -351,7 +371,7 @@ async function remove(): Promise<void> {
|
||||
// The page unmounts the editor as the workflow disappears, and unmounting
|
||||
// would write the draft back.
|
||||
removed = true;
|
||||
const done = stored.value === undefined ? await workflows.putDraft(selected.value, undefined) : await workflows.remove(selected.value);
|
||||
const done = await workflows.remove(selected.value);
|
||||
if (!done) removed = false;
|
||||
else emit("deleted");
|
||||
}
|
||||
@@ -364,7 +384,14 @@ const vocabulary = computed(() => workflows.stepTypes);
|
||||
// The definitions loaded but carried no step types: cards can't open and YAML
|
||||
// can't be checked, which must not look like an empty, valid workflow.
|
||||
const stepTypesMissing = computed(() => !!workflows.state.resource && !vocabulary.value.length);
|
||||
const parsed = computed(() => parseWorkflowYaml(yaml.value, vocabulary.value, selected.value));
|
||||
// The path holds the workflow's id; people read its name.
|
||||
const name = computed(
|
||||
() =>
|
||||
collection.value.definitions.find((entry) => entry.id === selected.value)?.name ??
|
||||
workflows.drafts.find((draft) => draft.id === selected.value)?.name ??
|
||||
"",
|
||||
);
|
||||
const parsed = computed(() => parseWorkflowYaml(yaml.value, vocabulary.value, name.value));
|
||||
const stored = computed(() => collection.value.definitions.find((entry) => entry.id === selected.value)?.yaml);
|
||||
const dirty = computed(() => yaml.value !== (stored.value ?? ""));
|
||||
const changes = computed(() => (dirty.value ? workflowChanges(stored.value ?? "", yaml.value) : []));
|
||||
@@ -470,6 +497,7 @@ const runOptions = computed(() => [
|
||||
<DropdownMenuItem v-if="watchedRevision" @select="openRevision(watchedRevision.version)">Version {{ watchedRevision.version }}</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="changes.length" @select="draftOpen = true">Draft changes <span class="ml-auto font-mono text-caption text-fg-subtle">{{ changes.length }}</span></DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="dirty" :disabled="archieWorking" @select="confirmDiscard = true"><RotateCcw />Discard changes</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="startRename"><Pencil />Rename</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="stored !== undefined" @select="emit('duplicate', selected)"><Copy />Duplicate</DropdownMenuItem>
|
||||
<DropdownMenuItem variant="destructive" @select="confirmDelete = true"><Trash2 />{{ stored === undefined ? "Discard workflow" : "Delete workflow" }}</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
@@ -500,7 +528,7 @@ const runOptions = computed(() => [
|
||||
:readonly="!!pinnedYaml || archieWorking"
|
||||
:restartable="restartable"
|
||||
:problems="pinnedYaml ? undefined : nodeProblems"
|
||||
:title="selected"
|
||||
:title="name"
|
||||
@toggle="toggle"
|
||||
@restart="restartFrom"
|
||||
@insert="insertAt"
|
||||
@@ -572,7 +600,7 @@ const runOptions = computed(() => [
|
||||
<AlertDialog v-model:open="confirmDiscard">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Discard the unpublished changes to {{ selected }}?</AlertDialogTitle>
|
||||
<AlertDialogTitle>Discard the unpublished changes to {{ name }}?</AlertDialogTitle>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
@@ -591,10 +619,20 @@ const runOptions = computed(() => [
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
<Dialog v-model:open="renaming">
|
||||
<DialogContent class="sm:max-w-md">
|
||||
<DialogHeader><DialogTitle>Rename {{ name }}</DialogTitle></DialogHeader>
|
||||
<form id="rename-workflow" class="flex flex-col gap-3" @submit.prevent="rename">
|
||||
<Input v-model="newName" aria-label="Name" placeholder="Name" pattern="[a-z0-9]+([.\-][a-z0-9]+)*" required />
|
||||
<p v-if="renameError" role="alert" class="text-caption text-danger">{{ renameError }}</p>
|
||||
</form>
|
||||
<DialogFooter><Button type="submit" form="rename-workflow" :disabled="!newName.trim() || newName.trim() === name">Rename</Button></DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<AlertDialog v-model:open="confirmDelete">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{{ stored === undefined ? "Discard" : "Delete" }} the {{ selected }} workflow?</AlertDialogTitle>
|
||||
<AlertDialogTitle>{{ stored === undefined ? "Discard" : "Delete" }} the {{ name }} workflow?</AlertDialogTitle>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
|
||||
@@ -33,7 +33,7 @@ onMounted(() => {
|
||||
});
|
||||
usePoll(reload);
|
||||
|
||||
// The path names the workflow; deleting it returns to the list.
|
||||
// The path holds the workflow's id; deleting it returns to the list.
|
||||
const selected = computed({
|
||||
get: () => String(route.params.id ?? ""),
|
||||
set: (id: string) => void (id ? router.replace({ name: "workflow", params: { id }, query: route.query }) : router.replace({ name: "workflows" })),
|
||||
@@ -49,15 +49,15 @@ onMounted(() => {
|
||||
|
||||
const stored = computed(() => workflows.collection.definitions.find((d) => d.id === selected.value));
|
||||
const draft = computed(() => workflows.drafts.some((d) => d.id === selected.value));
|
||||
// A workflow just created has no draft until its first edit is saved.
|
||||
const known = computed(() => !!stored.value || draft.value || route.query.new !== undefined);
|
||||
const name = computed(() => stored.value?.name ?? workflows.drafts.find((d) => d.id === selected.value)?.name ?? "");
|
||||
const known = computed(() => !!stored.value || draft.value);
|
||||
const loaded = computed(() => !!workflows.state.resource);
|
||||
// A workflow that was open and is gone has been deleted: back to the list.
|
||||
watch(known, (now, was) => {
|
||||
if (was && !now) selected.value = "";
|
||||
});
|
||||
|
||||
const own = computed(() => (triggers.data.value ?? []).filter((t) => t.workflow === selected.value));
|
||||
const own = computed(() => (triggers.data.value ?? []).filter((t) => t.workflow_id === selected.value));
|
||||
const starts = computed(() => [...new Set(own.value.map(startedBy))]);
|
||||
const startsText = computed(() => starts.value[0] ?? (triggers.data.value ? "Manual" : ""));
|
||||
const startsMore = computed(() => starts.value.slice(1));
|
||||
@@ -76,10 +76,11 @@ async function setEnabled(enabled: boolean): Promise<void> {
|
||||
async function copy(id: string): Promise<void> {
|
||||
const source = workflows.drafts.find((d) => d.id === id)?.yaml ?? stored.value?.yaml;
|
||||
if (source === undefined) return;
|
||||
const taken = new Set([...workflows.collection.definitions.map((d) => d.id), ...workflows.drafts.map((d) => d.id)]);
|
||||
let next = `${id}-copy`;
|
||||
for (let n = 2; taken.has(next); n++) next = `${id}-copy-${n}`;
|
||||
if (await workflows.putDraft(next, source)) void router.push({ name: "workflow", params: { id: next } });
|
||||
const taken = new Set([...workflows.collection.definitions.map((d) => d.name), ...workflows.drafts.map((d) => d.name)]);
|
||||
let next = `${name.value}-copy`;
|
||||
for (let n = 2; taken.has(next); n++) next = `${name.value}-copy-${n}`;
|
||||
const created = await workflows.create(next, source);
|
||||
if (created) void router.push({ name: "workflow", params: { id: created } });
|
||||
else toast.error(workflows.draftState.error || errors.workflows.editor.draftNotSaved);
|
||||
}
|
||||
</script>
|
||||
@@ -99,8 +100,8 @@ async function copy(id: string): Promise<void> {
|
||||
<!-- No card around the editor: the canvas draws its own frame. -->
|
||||
<div v-else 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="stored" size="sm" :model-value="stored.enabled" :aria-label="`${selected} enabled`" @update:model-value="setEnabled" />
|
||||
<h1 class="min-w-0 truncate text-title font-medium">{{ name }}</h1>
|
||||
<Switch v-if="stored" size="sm" :model-value="stored.enabled" :aria-label="`${name} enabled`" @update:model-value="setEnabled" />
|
||||
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
|
||||
<p v-if="startsText" class="flex min-w-0 basis-full items-center gap-1.5 text-caption text-fg-muted">
|
||||
<span class="truncate">{{ startsText }}</span>
|
||||
@@ -111,14 +112,14 @@ async function copy(id: string): Promise<void> {
|
||||
v-model:selected="selected"
|
||||
v-model:view="view"
|
||||
v-model:run-open="runOpen"
|
||||
:stats="stats.data.value?.find((s) => s.workflow === selected)"
|
||||
:stats="stats.data.value?.find((s) => s.workflow_id === selected)"
|
||||
:triggers="canvasTriggers"
|
||||
@duplicate="copy"
|
||||
@deleted="selected = ''"
|
||||
>
|
||||
<template #title>
|
||||
<h1 class="min-w-0 truncate text-title font-medium">{{ selected }}</h1>
|
||||
<Switch v-if="stored" size="sm" :model-value="stored.enabled" :aria-label="`${selected} enabled`" @update:model-value="setEnabled" />
|
||||
<h1 class="min-w-0 truncate text-title font-medium">{{ name }}</h1>
|
||||
<Switch v-if="stored" size="sm" :model-value="stored.enabled" :aria-label="`${name} enabled`" @update:model-value="setEnabled" />
|
||||
<Badge v-if="draft" variant="outline" class="shrink-0">Draft</Badge>
|
||||
<p v-if="startsText" class="flex min-w-0 max-w-64 items-center gap-1.5 text-caption text-fg-muted">
|
||||
<span class="truncate">{{ startsText }}</span>
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
import { SuggestInput } from "@/components/ui/suggest-input";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
|
||||
defineProps<{ value: string; workflows: { id: string }[]; label: string; class?: string; editable?: boolean }>();
|
||||
defineProps<{ value: string; workflows: { id: string; name: string }[]; label: string; class?: string; editable?: boolean }>();
|
||||
const emit = defineEmits<{ pick: [string] }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="editable">
|
||||
<SuggestInput :model-value="value" :options="workflows.map((entry) => entry.id)" :aria-label="label" :class="$props.class" placeholder="Workflow id or {{ reference }}" @update:model-value="emit('pick', $event)" />
|
||||
<SuggestInput :model-value="value" :options="workflows.map((entry) => entry.name)" :aria-label="label" :class="$props.class" placeholder="Workflow name or {{ reference }}" @update:model-value="emit('pick', $event)" />
|
||||
</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>
|
||||
<SelectItem v-for="entry in workflows" :key="entry.id" :value="entry.id">{{ entry.id }}</SelectItem>
|
||||
<SelectItem v-if="value && !workflows.some((entry) => entry.name === value)" :value="value" disabled>{{ value }} (unavailable)</SelectItem>
|
||||
<SelectItem v-for="entry in workflows" :key="entry.id" :value="entry.name">{{ entry.name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</template>
|
||||
@@ -7,7 +7,7 @@ import { MoreMenu } from "@/components/ui/more-menu";
|
||||
import RunWorkflowButton from "./RunWorkflowButton.vue";
|
||||
|
||||
/** The run button and overflow menu for one workflow row. */
|
||||
const props = defineProps<{ id: string; yaml: string; published: boolean; enabled: boolean }>();
|
||||
const props = defineProps<{ id: string; name: string; yaml: string; published: boolean; enabled: boolean }>();
|
||||
const emit = defineEmits<{ runs: []; duplicate: []; delete: [] }>();
|
||||
const router = useRouter();
|
||||
</script>
|
||||
@@ -23,7 +23,7 @@ const router = useRouter();
|
||||
disabled-reason="Disabled"
|
||||
@started="(runId) => router.push(`/runs/${runId}`)"
|
||||
/>
|
||||
<MoreMenu :label="`${id} actions`">
|
||||
<MoreMenu :label="`${name} actions`">
|
||||
<DropdownMenuItem v-if="props.published" @select="emit('runs')"><ListChecks />Open runs</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="emit('duplicate')"><Copy />Duplicate</DropdownMenuItem>
|
||||
<DropdownMenuItem variant="destructive" @select="emit('delete')"><Trash2 />{{ props.published ? "Delete" : "Discard" }}</DropdownMenuItem>
|
||||
|
||||
@@ -39,7 +39,7 @@ const shown = computed(() => {
|
||||
return needle ? rows.value.filter((row) => row.name.toLowerCase().includes(needle) || row.starts.some((s) => s.toLowerCase().includes(needle))) : rows.value;
|
||||
});
|
||||
|
||||
const open = (name: string, query?: Record<string, string>) => void router.push({ path: `/workflows/${name}`, query });
|
||||
const open = (id: string) => void router.push({ path: `/workflows/${id}` });
|
||||
const openRuns = (name: string) => void router.push({ path: "/runs", query: { workflow: name } });
|
||||
const startsText = (row: WorkflowRow) => row.starts[0] ?? "";
|
||||
const startsMore = (row: WorkflowRow) => row.starts.slice(1);
|
||||
@@ -53,9 +53,10 @@ async function copy(row: WorkflowRow): Promise<void> {
|
||||
let next = `${row.name}-copy`;
|
||||
for (let n = 2; taken.has(next); n++) next = `${row.name}-copy-${n}`;
|
||||
try {
|
||||
const draft = await api.workflowDraft(row.name);
|
||||
await api.putWorkflowDraft(next, draft?.body ?? row.body, 0);
|
||||
open(next);
|
||||
const draft = await api.workflowDraft(row.id);
|
||||
const { id } = await api.createWorkflow(next);
|
||||
await api.putWorkflowDraft(id, draft?.body ?? row.body, 0);
|
||||
open(id);
|
||||
} catch (cause) {
|
||||
toast.error(describeError(cause, errors.common.unknown));
|
||||
}
|
||||
@@ -63,19 +64,18 @@ async function copy(row: WorkflowRow): Promise<void> {
|
||||
|
||||
async function setEnabled(row: WorkflowRow, enabled: boolean): Promise<void> {
|
||||
try {
|
||||
await api.setWorkflowEnabled(row.name, enabled);
|
||||
await api.setWorkflowEnabled(row.id, enabled);
|
||||
} catch (cause) {
|
||||
toast.error(describeError(cause, errors.common.unknown));
|
||||
}
|
||||
await reload();
|
||||
}
|
||||
|
||||
// A published workflow is deleted; one with only a draft has the draft discarded.
|
||||
// Deleting a workflow discards its draft too.
|
||||
const deleting = ref<WorkflowRow | null>(null);
|
||||
async function remove(row: WorkflowRow): Promise<void> {
|
||||
try {
|
||||
if (row.version) await api.deleteWorkflow(row.name);
|
||||
else await api.discardWorkflowDraft(row.name);
|
||||
await api.deleteWorkflow(row.id);
|
||||
} catch (cause) {
|
||||
toast.error(describeError(cause, errors.common.unknown));
|
||||
}
|
||||
@@ -86,14 +86,20 @@ async function remove(row: WorkflowRow): Promise<void> {
|
||||
const creating = ref(false);
|
||||
const name = ref("");
|
||||
const createError = ref("");
|
||||
function create(): void {
|
||||
async function create(): Promise<void> {
|
||||
const next = name.value.trim();
|
||||
if (rows.value.some((row) => row.name === next)) {
|
||||
createError.value = `${next} already exists`;
|
||||
return;
|
||||
}
|
||||
creating.value = false;
|
||||
void router.push({ path: `/workflows/${next}`, query: { new: "" } });
|
||||
try {
|
||||
const { id } = await api.createWorkflow(next);
|
||||
await api.putWorkflowDraft(id, "steps: []\n", 0);
|
||||
creating.value = false;
|
||||
open(id);
|
||||
} catch (cause) {
|
||||
createError.value = describeError(cause, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -135,12 +141,12 @@ function create(): void {
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<ContextMenu v-for="row in shown" :key="row.name">
|
||||
<ContextMenu v-for="row in shown" :key="row.id">
|
||||
<ContextMenuTrigger as-child>
|
||||
<TableRow class="cursor-pointer align-middle" @click="open(row.name)">
|
||||
<TableRow class="cursor-pointer align-middle" @click="open(row.id)">
|
||||
<TableCell class="whitespace-normal">
|
||||
<span class="flex min-w-0 items-center gap-2">
|
||||
<RouterLink :to="`/workflows/${row.name}`" class="min-w-0 truncate font-medium hover:underline focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.name }}</RouterLink>
|
||||
<RouterLink :to="`/workflows/${row.id}`" class="min-w-0 truncate font-medium hover:underline focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.name }}</RouterLink>
|
||||
<span class="shrink-0 text-caption text-fg-subtle">{{ versionLabel(row) }}</span>
|
||||
<Badge v-if="row.draft" variant="outline" class="shrink-0">Draft</Badge>
|
||||
</span>
|
||||
@@ -162,7 +168,7 @@ function create(): void {
|
||||
<span class="flex flex-col gap-0.5"><Timestamp :at="row.published" /><span v-if="row.by" class="truncate text-caption text-fg-muted">{{ row.by }}</span></span>
|
||||
</TableCell>
|
||||
<TableCell class="text-right">
|
||||
<WorkflowRowActions :id="row.name" :yaml="row.body" :published="!!row.version" :enabled="row.enabled" @runs="openRuns(row.name)" @duplicate="copy(row)" @delete="deleting = row" />
|
||||
<WorkflowRowActions :id="row.id" :name="row.name" :yaml="row.body" :published="!!row.version" :enabled="row.enabled" @runs="openRuns(row.name)" @duplicate="copy(row)" @delete="deleting = row" />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</ContextMenuTrigger>
|
||||
@@ -176,16 +182,16 @@ function create(): void {
|
||||
</Table>
|
||||
|
||||
<ul v-else-if="shown.length" class="flex flex-col gap-2" aria-label="Workflows">
|
||||
<li v-for="row in shown" :key="row.name">
|
||||
<li v-for="row in shown" :key="row.id">
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger as-child>
|
||||
<Card class="cursor-pointer gap-2.5 px-4 py-3 transition-colors hover:bg-secondary/60" @click="open(row.name)">
|
||||
<Card class="cursor-pointer gap-2.5 px-4 py-3 transition-colors hover:bg-secondary/60" @click="open(row.id)">
|
||||
<div class="flex items-center gap-2">
|
||||
<RouterLink :to="`/workflows/${row.name}`" class="min-w-0 truncate text-label font-medium focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.name }}</RouterLink>
|
||||
<RouterLink :to="`/workflows/${row.id}`" class="min-w-0 truncate text-label font-medium focus-visible:outline-2 focus-visible:outline-ring" @click.stop>{{ row.name }}</RouterLink>
|
||||
<span class="shrink-0 text-caption text-fg-subtle">{{ versionLabel(row) }}</span>
|
||||
<Badge v-if="row.draft" variant="outline" class="shrink-0">Draft</Badge>
|
||||
<Switch v-if="row.version" size="sm" class="ml-auto" :model-value="row.enabled" :aria-label="`${row.name} enabled`" @click.stop @update:model-value="setEnabled(row, $event)" />
|
||||
<WorkflowRowActions :id="row.name" :yaml="row.body" :published="!!row.version" :enabled="row.enabled" :class="row.version ? '' : 'ml-auto'" @runs="openRuns(row.name)" @duplicate="copy(row)" @delete="deleting = row" />
|
||||
<WorkflowRowActions :id="row.id" :name="row.name" :yaml="row.body" :published="!!row.version" :enabled="row.enabled" :class="row.version ? '' : 'ml-auto'" @runs="openRuns(row.name)" @duplicate="copy(row)" @delete="deleting = row" />
|
||||
</div>
|
||||
<p class="flex min-w-0 items-center gap-1.5 text-caption text-fg-muted">
|
||||
<span class="truncate">{{ startsText(row) || (triggersKnown ? "Manual" : "") }}</span>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { usePoll, useRead } from "@/lib/use-read";
|
||||
import { useLiveResource } from "@/stores/session";
|
||||
|
||||
export interface WorkflowRow {
|
||||
id: string;
|
||||
name: string;
|
||||
/** The published version; 0 for a workflow with only a draft. */
|
||||
version: number;
|
||||
@@ -56,19 +57,20 @@ export function useWorkflowList() {
|
||||
usePoll(reload);
|
||||
|
||||
const rows = computed<WorkflowRow[]>(() => {
|
||||
const counted = new Map((stats.data.value ?? []).map((s) => [s.workflow, s]));
|
||||
const held = new Set((drafts.data.value ?? []).map((d) => d.name));
|
||||
const row = (name: string, own: Partial<WorkflowRow>): WorkflowRow => {
|
||||
const s = counted.get(name);
|
||||
const counted = new Map((stats.data.value ?? []).map((s) => [s.workflow_id, s]));
|
||||
const held = new Set((drafts.data.value ?? []).map((d) => d.workflow_id));
|
||||
const row = (id: string, name: string, own: Partial<WorkflowRow>): WorkflowRow => {
|
||||
const s = counted.get(id);
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
version: 0,
|
||||
body: "",
|
||||
steps: 0,
|
||||
published: "",
|
||||
enabled: true,
|
||||
draft: held.has(name),
|
||||
starts: [...new Set((triggers.data.value ?? []).filter((t) => t.workflow === name).map(startedBy))],
|
||||
draft: held.has(id),
|
||||
starts: [...new Set((triggers.data.value ?? []).filter((t) => t.workflow_id === id).map(startedBy))],
|
||||
runs: s?.total ?? 0,
|
||||
succeeded: s?.succeeded ?? 0,
|
||||
running: s?.active ?? 0,
|
||||
@@ -77,10 +79,12 @@ export function useWorkflowList() {
|
||||
};
|
||||
};
|
||||
const published = (workflows.data.value ?? []).map((w) =>
|
||||
row(w.name, { version: w.version, body: w.body, steps: w.steps?.length ?? 0, published: w.created_at, by: w.created_by, enabled: w.enabled }),
|
||||
row(w.id, w.name, { version: w.version, body: w.body, steps: w.steps?.length ?? 0, published: w.created_at, by: w.created_by, enabled: w.enabled }),
|
||||
);
|
||||
const known = new Set(published.map((r) => r.name));
|
||||
const drafted = (drafts.data.value ?? []).filter((d) => !known.has(d.name)).map((d) => row(d.name, { body: d.body, published: d.updated_at, by: d.updated_by }));
|
||||
const known = new Set(published.map((r) => r.id));
|
||||
const drafted = (drafts.data.value ?? [])
|
||||
.filter((d) => !known.has(d.workflow_id))
|
||||
.map((d) => row(d.workflow_id, d.name, { body: d.body, published: d.updated_at, by: d.updated_by }));
|
||||
return [...published, ...drafted].sort(byActivity);
|
||||
});
|
||||
/** Triggers, drafts or counts that failed to load: rows show without them, beside this. */
|
||||
|
||||
@@ -86,9 +86,9 @@ export function stepMarks(source: string, other: string, missing: "added" | "rem
|
||||
return marks;
|
||||
}
|
||||
|
||||
/** Every published version of workflow `name`, newest first, read again when
|
||||
* a new version is published. */
|
||||
export function useWorkflowHistory(name: Ref<string>, published: Ref<number>) {
|
||||
/** Every published version of the workflow with id `workflow`, newest first,
|
||||
* read again when a new version is published. */
|
||||
export function useWorkflowHistory(workflow: Ref<string>, published: Ref<number>) {
|
||||
const revisions = ref<WorkflowRevision[]>([]);
|
||||
const error = ref("");
|
||||
const loaded = ref(false);
|
||||
@@ -96,7 +96,7 @@ export function useWorkflowHistory(name: Ref<string>, published: Ref<number>) {
|
||||
let generation = 0;
|
||||
async function reload(): Promise<void> {
|
||||
const current = ++generation;
|
||||
const requested = name.value;
|
||||
const requested = workflow.value;
|
||||
try {
|
||||
const versions = await Promise.all(Array.from({ length: published.value }, (_, i) => api.workflow(requested, i + 1)));
|
||||
if (current !== generation) return;
|
||||
|
||||
@@ -8,9 +8,9 @@ export interface WorkflowTrigger {
|
||||
detail?: string;
|
||||
}
|
||||
|
||||
/** The triggers that start a workflow. */
|
||||
/** The triggers that start the workflow with that id. */
|
||||
export function workflowTriggers(triggers: Trigger[], workflow: string): WorkflowTrigger[] {
|
||||
return triggers
|
||||
.filter((t) => t.workflow === workflow)
|
||||
.filter((t) => t.workflow_id === workflow)
|
||||
.map((t) => ({ kind: t.every ? "schedule" : "event", label: t.every ? startedBy(t) : t.name, detail: t.every ? undefined : startedBy(t) }));
|
||||
}
|
||||
Reference in new issue
Block a user