+ {{ errors.bindings.dispatchLinks.unavailable }}
+
+ -
+ capture {{ r.event_id.slice(0, 8) }}
+ {{ r.trigger }}
+ run {{ r.run_id.slice(0, 8) }}
+
+
+
+ No runs yet.
+
diff --git a/ui/src/bindings/binding-trigger.ts b/ui/src/bindings/binding-trigger.ts
new file mode 100644
index 000000000..b40efb821
--- /dev/null
+++ b/ui/src/bindings/binding-trigger.ts
@@ -0,0 +1,99 @@
+/**
+ * The bindings vocabulary on the binary: a binding is a trigger bound to an
+ * event type, so the wire shape is the trigger's. The status ramp is
+ * binding-draft.ts's.
+ */
+
+import type { EventType } from "../captures/event-types";
+import type { Trigger, TriggerInput } from "../lib/api";
+
+/** A trigger bound to an event type, named by the trigger's name. */
+export interface Binding {
+ id: string;
+ name: string;
+ source: string;
+ event_type_id?: string;
+ mapping_id?: string;
+ workflow?: string;
+ status?: string;
+ /** The source takes deliveries with no verification. */
+ unsigned?: boolean;
+}
+
+export function bindingOfTrigger(trigger: Trigger): Binding {
+ return {
+ id: trigger.name,
+ name: trigger.name,
+ source: trigger.source ?? "",
+ event_type_id: trigger.event_type_id,
+ mapping_id: trigger.mapping_id,
+ workflow: trigger.workflow,
+ status: trigger.status,
+ unsigned: trigger.unsigned,
+ };
+}
+
+/** The fields of GET /api/mappings this page needs. */
+export interface MappingOption {
+ id: string;
+ name: string;
+ event_type_id?: string;
+}
+
+/** The mappings that belong to one event type, which are the ones a binding
+ * on that type can use. */
+export function mappingsForEventType(
+ mappings: MappingOption[],
+ eventTypeId: string,
+): MappingOption[] {
+ if (!eventTypeId) return [];
+ return mappings.filter((m) => m.event_type_id === eventTypeId);
+}
+
+/** A workflow a binding can start. */
+export interface WorkflowOption {
+ id: string;
+ name: string;
+}
+
+/** The editor's field state. */
+export interface BindingDraft {
+ /** The trigger's name when editing; null for a new binding. */
+ id: string | null;
+ name: string;
+ /** The event type the binding applies to; its source is the binding's. */
+ eventTypeId: string;
+ mappingId: string;
+ workflow: string;
+}
+
+export function emptyDraft(): BindingDraft {
+ return { id: null, name: "", eventTypeId: "", mappingId: "", workflow: "" };
+}
+
+export function draftFromBinding(binding: Binding): BindingDraft {
+ return {
+ id: binding.id,
+ name: binding.name,
+ eventTypeId: binding.event_type_id || "",
+ mappingId: binding.mapping_id || "",
+ workflow: binding.workflow || "",
+ };
+}
+
+/** The body PUT /api/triggers/{name} takes. A saved binding waits for
+ * approval again. */
+export function bindingPayload(
+ draft: BindingDraft,
+ eventTypes: EventType[],
+): TriggerInput {
+ const eventType = eventTypes.find((t) => t.id === draft.eventTypeId);
+ return {
+ source: eventType?.source ?? "",
+ event_type_id: draft.eventTypeId,
+ mapping_id: draft.mappingId || undefined,
+ workflow: draft.workflow,
+ disabled: false,
+ pending: true,
+ };
+}
diff --git a/ui/src/bindings/use-bindings.ts b/ui/src/bindings/use-bindings.ts
index 80ddc89dd..b428e9f7f 100644
--- a/ui/src/bindings/use-bindings.ts
+++ b/ui/src/bindings/use-bindings.ts
@@ -1,21 +1,21 @@
import { ref } from "vue";
-import { useEventsStore } from "@/stores/events";
import { api, ApiError, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import type { EventType } from "@/captures/event-types";
import {
+ bindingOfTrigger,
bindingPayload,
type Binding,
type BindingDraft,
type MappingOption,
type WorkflowOption,
-} from "./binding-draft";
+} from "./binding-trigger";
/**
- * Why the page has nothing to show. "unconfigured" is a daemon with no
- * bindings store wired (501/503) -- the feature is off, which reads very
- * differently from a daemon that answered badly.
+ * Why the page has nothing to show. "unconfigured" is a server that doesn't
+ * serve triggers (501/503), which reads very differently from one that
+ * answered badly.
*/
type LoadFailureKind = "unconfigured" | "failed";
@@ -25,8 +25,7 @@ export interface LoadFailure {
}
function failureFor(err: unknown): LoadFailure {
- const message =
- describeError(err, errors.common.unknown);
+ const message = describeError(err, errors.common.unknown);
const status = err instanceof ApiError ? err.status : undefined;
return {
kind: status === 501 || status === 503 ? "unconfigured" : "failed",
@@ -35,10 +34,9 @@ function failureFor(err: unknown): LoadFailure {
}
/**
- * The bindings page's data: the three lists the list and the editor read, the
- * load that fills them, and the three mutations. Every mutation goes through
- * api.* so the CSRF and Content-Type headers are sent -- a bare fetch is
- * refused 403/415 by archied's mutation guard.
+ * The bindings page's data: the lists the table and the editor read, the load
+ * that fills them, and the mutations. Every mutation goes through api.* so the
+ * CSRF and Content-Type headers are sent.
*/
export function useBindings() {
// null means loading, [] means loaded and empty.
@@ -56,18 +54,16 @@ export function useBindings() {
async function load(): Promise