fix(ui): trigger forms show the server's binding status and load what they read (#1951)

This commit is contained in:
sam committed 2026-11-13 14:35:24 +11:00
1 parent 6a17951a3a
commit ecf4e6b95a
5 files changed
+39 -36

No files matched your search

+3 -13
View File
@@ -44,7 +44,7 @@ import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
import DraftHint from "@/settings/DraftHint.vue";
import HistoryLink from "@/settings/HistoryLink.vue";
import ScheduleEditor from "./ScheduleEditor.vue";
import { runDuration, timingWords, type Schedule, type ScheduleSettings } from "./schedule";
import { blankSchedule, runDuration, timingWords, type Schedule, type ScheduleSettings } from "./schedule";
const SETTINGS = "schedule-settings";
@@ -128,19 +128,9 @@ function edit(schedule: Schedule, title: string): void {
editorTitle.value = title;
editorOpen.value = true;
}
function blank(): Schedule {
return {
id: crypto.randomUUID(),
name: "",
owner: { kind: "instance" },
enabled: true,
built_in: false,
timing: { kind: "interval", interval: "24h0m0s" },
};
}
const create = () => edit(blank(), "New schedule");
const create = () => edit(blankSchedule(), "New schedule");
const duplicate = (schedule: Schedule) =>
edit({ ...blank(), name: `${schedule.name} copy`, timing: { ...schedule.timing }, enabled: false }, "Duplicate schedule");
edit({ ...blankSchedule(), name: `${schedule.name} copy`, timing: { ...schedule.timing }, enabled: false }, "Duplicate schedule");
const removing = ref<Schedule | null>(null);
const remove = () =>
+12
View File
@@ -163,3 +163,15 @@ export const RESULT_TONE: Record<RunResult, "ok" | "warn" | "danger" | "idle"> =
failed: "danger",
skipped: "warn",
};
/** A new schedule's starting values: runs daily, owned by the instance. */
export function blankSchedule(): Schedule {
return {
id: crypto.randomUUID(),
name: "",
owner: { kind: "instance" },
enabled: true,
built_in: false,
timing: { kind: "interval", interval: "24h0m0s" },
};
}
+8 -6
View File
@@ -250,12 +250,14 @@ async function save(): Promise<void> {
}
// transition runs one lifecycle command and shows the status it leads to.
async function transition(command: (id: string) => Promise<unknown>, next: string): Promise<void> {
// The server answers with the binding as it now stands; its status is what
// the form shows, not a guess at the next state.
async function transition(command: (id: string) => Promise<unknown>): Promise<void> {
if (!props.binding) return;
error.value = "";
try {
await command(props.binding.id);
status.value = next;
const updated = (await command(props.binding.id)) as { status?: string } | undefined;
if (updated?.status) status.value = updated.status;
emit("saved");
} catch (err) {
error.value = describeError(err, errors.common.unknown);
@@ -274,9 +276,9 @@ async function removeBinding(): Promise<void> {
saving.value = false;
}
}
const approve = () => transition(api.bindingApprove, "armed");
const pause = () => transition(api.bindingPause, "paused");
const resume = () => transition(api.bindingResume, "pending_approval");
const approve = () => transition(api.bindingApprove);
const pause = () => transition(api.bindingPause);
const resume = () => transition(api.bindingResume);
</script>
<template>
+10 -15
View File
@@ -23,7 +23,7 @@ import { api, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import { constantValue, statusKind, statusLabel, type Binding, type InputSource } from "@/bindings/binding-draft";
import ScheduleEditor from "@/schedules/ScheduleEditor.vue";
import { type Schedule } from "@/schedules/schedule";
import { blankSchedule, type Schedule } from "@/schedules/schedule";
import type { InputSpec } from "./bind-event";
import OptionSelect from "./OptionSelect.vue";
import { workflowField } from "./workflow-edit";
@@ -88,14 +88,7 @@ function pickSchedule(value: string): void {
scheduleId.value = value;
return;
}
draft.value = {
id: crypto.randomUUID(),
name: workflow.value,
owner: { kind: "instance" },
enabled: true,
built_in: false,
timing: { kind: "interval", interval: "24h0m0s" },
};
draft.value = { ...blankSchedule(), name: workflow.value };
editorOpen.value = true;
}
function created(schedule: Schedule): void {
@@ -148,12 +141,14 @@ async function save(): Promise<void> {
}
}
async function transition(command: (id: string) => Promise<unknown>, next: string): Promise<void> {
// The server answers with the binding as it now stands; its status is what
// the form shows, not a guess at the next state.
async function transition(command: (id: string) => Promise<unknown>): Promise<void> {
if (!props.binding) return;
error.value = "";
try {
await command(props.binding.id);
status.value = next;
const updated = (await command(props.binding.id)) as { status?: string } | undefined;
if (updated?.status) status.value = updated.status;
emit("saved");
} catch (err) {
error.value = describeError(err, errors.common.unknown);
@@ -219,9 +214,9 @@ async function remove(): Promise<void> {
<p v-else-if="blockers.length" class="text-caption text-fg-subtle">{{ errors.workflows.bindingSave.cannotSave(blockers[0] ?? "") }}</p>
<div class="flex flex-wrap gap-2">
<Button type="submit" size="sm" :disabled="saving || !!blockers.length"><Spinner v-if="saving" />Save trigger</Button>
<Button v-if="binding && status === 'pending_approval'" type="button" size="sm" variant="outline" @click="transition(api.bindingApprove, 'armed')">Approve</Button>
<Button v-if="binding && status === 'armed'" type="button" size="sm" variant="outline" @click="transition(api.bindingPause, 'paused')">Pause</Button>
<Button v-if="binding && status === 'paused'" type="button" size="sm" variant="outline" @click="transition(api.bindingResume, 'pending_approval')">Resume</Button>
<Button v-if="binding && status === 'pending_approval'" type="button" size="sm" variant="outline" @click="transition(api.bindingApprove)">Approve</Button>
<Button v-if="binding && status === 'armed'" type="button" size="sm" variant="outline" @click="transition(api.bindingPause)">Pause</Button>
<Button v-if="binding && status === 'paused'" type="button" size="sm" variant="outline" @click="transition(api.bindingResume)">Resume</Button>
<Button v-if="binding" type="button" size="sm" variant="destructive" @click="confirmRemove = true">Remove trigger</Button>
</div>
</div>
+6 -2
View File
@@ -151,9 +151,13 @@ export function useWorkflowTriggers(id: Ref<string>) {
const [response, listed] = await Promise.all([
api.bindings<{ bindings?: Binding[] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
api.schedules<{ schedules?: TriggerSources["schedules"] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
// Playbook triggers come from that resource; it is read here rather
// than trusting another page to have loaded it.
store.stateFor("eda-playbooks").resource ? null : store.loadResource("eda-playbooks").catch(() => null),
]);
bindings.value = response?.bindings ?? [];
schedules.value = listed?.schedules ?? [];
// A failed read keeps what was shown, beside the error.
if (response) bindings.value = response.bindings ?? [];
if (listed) schedules.value = listed.schedules ?? [];
error.value = response === null || listed === null ? readError || errors.workflows.triggers.notLoaded : "";
}
onMounted(reload);