fix(ui): trigger forms show the server's binding status and load what they read (#1951)
This commit is contained in:
5 files changed
+39
-36
No files matched your search
@@ -44,7 +44,7 @@ import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
|
|||||||
import DraftHint from "@/settings/DraftHint.vue";
|
import DraftHint from "@/settings/DraftHint.vue";
|
||||||
import HistoryLink from "@/settings/HistoryLink.vue";
|
import HistoryLink from "@/settings/HistoryLink.vue";
|
||||||
import ScheduleEditor from "./ScheduleEditor.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";
|
const SETTINGS = "schedule-settings";
|
||||||
|
|
||||||
@@ -128,19 +128,9 @@ function edit(schedule: Schedule, title: string): void {
|
|||||||
editorTitle.value = title;
|
editorTitle.value = title;
|
||||||
editorOpen.value = true;
|
editorOpen.value = true;
|
||||||
}
|
}
|
||||||
function blank(): Schedule {
|
const create = () => edit(blankSchedule(), "New 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 duplicate = (schedule: 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 removing = ref<Schedule | null>(null);
|
||||||
const remove = () =>
|
const remove = () =>
|
||||||
|
|||||||
@@ -163,3 +163,15 @@ export const RESULT_TONE: Record<RunResult, "ok" | "warn" | "danger" | "idle"> =
|
|||||||
failed: "danger",
|
failed: "danger",
|
||||||
skipped: "warn",
|
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" },
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -250,12 +250,14 @@ async function save(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// transition runs one lifecycle command and shows the status it leads to.
|
// 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;
|
if (!props.binding) return;
|
||||||
error.value = "";
|
error.value = "";
|
||||||
try {
|
try {
|
||||||
await command(props.binding.id);
|
const updated = (await command(props.binding.id)) as { status?: string } | undefined;
|
||||||
status.value = next;
|
if (updated?.status) status.value = updated.status;
|
||||||
emit("saved");
|
emit("saved");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = describeError(err, errors.common.unknown);
|
error.value = describeError(err, errors.common.unknown);
|
||||||
@@ -274,9 +276,9 @@ async function removeBinding(): Promise<void> {
|
|||||||
saving.value = false;
|
saving.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const approve = () => transition(api.bindingApprove, "armed");
|
const approve = () => transition(api.bindingApprove);
|
||||||
const pause = () => transition(api.bindingPause, "paused");
|
const pause = () => transition(api.bindingPause);
|
||||||
const resume = () => transition(api.bindingResume, "pending_approval");
|
const resume = () => transition(api.bindingResume);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import { api, describeError } from "@/lib/api";
|
|||||||
import { errors } from "@/copy/errors";
|
import { errors } from "@/copy/errors";
|
||||||
import { constantValue, statusKind, statusLabel, type Binding, type InputSource } from "@/bindings/binding-draft";
|
import { constantValue, statusKind, statusLabel, type Binding, type InputSource } from "@/bindings/binding-draft";
|
||||||
import ScheduleEditor from "@/schedules/ScheduleEditor.vue";
|
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 type { InputSpec } from "./bind-event";
|
||||||
import OptionSelect from "./OptionSelect.vue";
|
import OptionSelect from "./OptionSelect.vue";
|
||||||
import { workflowField } from "./workflow-edit";
|
import { workflowField } from "./workflow-edit";
|
||||||
@@ -88,14 +88,7 @@ function pickSchedule(value: string): void {
|
|||||||
scheduleId.value = value;
|
scheduleId.value = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
draft.value = {
|
draft.value = { ...blankSchedule(), name: workflow.value };
|
||||||
id: crypto.randomUUID(),
|
|
||||||
name: workflow.value,
|
|
||||||
owner: { kind: "instance" },
|
|
||||||
enabled: true,
|
|
||||||
built_in: false,
|
|
||||||
timing: { kind: "interval", interval: "24h0m0s" },
|
|
||||||
};
|
|
||||||
editorOpen.value = true;
|
editorOpen.value = true;
|
||||||
}
|
}
|
||||||
function created(schedule: Schedule): void {
|
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;
|
if (!props.binding) return;
|
||||||
error.value = "";
|
error.value = "";
|
||||||
try {
|
try {
|
||||||
await command(props.binding.id);
|
const updated = (await command(props.binding.id)) as { status?: string } | undefined;
|
||||||
status.value = next;
|
if (updated?.status) status.value = updated.status;
|
||||||
emit("saved");
|
emit("saved");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = describeError(err, errors.common.unknown);
|
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>
|
<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">
|
<div class="flex flex-wrap gap-2">
|
||||||
<Button type="submit" size="sm" :disabled="saving || !!blockers.length"><Spinner v-if="saving" />Save trigger</Button>
|
<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 === '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, 'paused')">Pause</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, 'pending_approval')">Resume</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>
|
<Button v-if="binding" type="button" size="sm" variant="destructive" @click="confirmRemove = true">Remove trigger</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -151,9 +151,13 @@ export function useWorkflowTriggers(id: Ref<string>) {
|
|||||||
const [response, listed] = await Promise.all([
|
const [response, listed] = await Promise.all([
|
||||||
api.bindings<{ bindings?: Binding[] }>().catch((err) => { readError = describeError(err, errors.common.unknown); return null; }),
|
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; }),
|
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 ?? [];
|
// A failed read keeps what was shown, beside the error.
|
||||||
schedules.value = listed?.schedules ?? [];
|
if (response) bindings.value = response.bindings ?? [];
|
||||||
|
if (listed) schedules.value = listed.schedules ?? [];
|
||||||
error.value = response === null || listed === null ? readError || errors.workflows.triggers.notLoaded : "";
|
error.value = response === null || listed === null ? readError || errors.workflows.triggers.notLoaded : "";
|
||||||
}
|
}
|
||||||
onMounted(reload);
|
onMounted(reload);
|
||||||
|
|||||||
Reference in new issue
Block a user