feat(eda): link binding dispatches to the captures and tasks they started

This commit is contained in:
sam committed 2026-10-05 20:16:02 +11:00
1 parent f3f73f852f
commit fcd66395cd
24 files changed
+1315 -518

No files matched your search

+6
View File
@@ -1,4 +1,5 @@
<script setup lang="ts">
import DispatchLinks from "./DispatchLinks.vue";
import { computed, ref, watch } from "vue";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
@@ -313,6 +314,11 @@ const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
</Field>
</FieldGroup>
<section v-if="props.binding" class="mt-4 flex flex-col gap-2">
<h3 class="text-sm font-medium">Recent dispatches</h3>
<DispatchLinks kind="bindings" :id="props.binding.id" />
</section>
<!-- Beside the buttons, not at the top: the dialog scrolls, and Save is
clicked at the bottom, where a refusal must be seen. -->
<Alert v-if="props.error" variant="destructive" class="mt-4">
+85
View File
@@ -0,0 +1,85 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { api } from "@/lib/api";
import { ago } from "@/lib/format";
/**
* The dispatch ledger rows for one binding, capture or task, each linking the
* other two ends: which binding evaluated which capture, and the task it
* started or the reason it started none. `omit` drops the column the page
* already is.
*/
export interface Dispatch {
binding_id: string;
binding_version: number;
capture_id: string;
task_id?: number;
reason?: string;
dispatched_at: string;
}
const props = defineProps<{
kind: "bindings" | "captures" | "tasks";
id: string;
}>();
const dispatches = ref<Dispatch[]>([]);
const failed = ref(false);
watch(
() => [props.kind, props.id],
async () => {
failed.value = false;
try {
dispatches.value = await api.dispatches<Dispatch[]>(props.kind, props.id);
} catch {
dispatches.value = [];
failed.value = true;
}
},
{ immediate: true },
);
const captureLink = (id: string) => ({
path: "/events",
query: { tab: "inspector", capture: id },
});
</script>
<template>
<p v-if="failed" class="text-xs text-fg-muted">Dispatches unavailable.</p>
<ul v-else-if="dispatches.length" class="flex flex-col gap-1 text-xs">
<li
v-for="d in dispatches"
:key="d.binding_id + d.capture_id"
class="flex flex-wrap items-center gap-x-2 font-mono text-fg-muted"
>
<RouterLink
v-if="props.kind !== 'bindings'"
:to="{ path: '/events', query: { tab: 'bindings' } }"
class="hover:text-foreground"
>binding {{ d.binding_id.slice(0, 8) }} v{{ d.binding_version }}</RouterLink
>
<RouterLink
v-if="props.kind !== 'captures'"
:to="captureLink(d.capture_id)"
class="hover:text-foreground"
>capture {{ d.capture_id.slice(0, 8) }}</RouterLink
>
<template v-if="props.kind !== 'tasks'">
<RouterLink
v-if="d.task_id"
:to="`/tasks/${d.task_id}`"
class="text-foreground hover:underline"
>task #{{ d.task_id }}</RouterLink
>
<span v-else>{{ d.reason || "claimed, no task recorded" }}</span>
</template>
<span>{{ ago(d.dispatched_at) }}</span>
</li>
</ul>
<p v-else-if="props.kind !== 'tasks'" class="text-xs text-fg-muted">
No dispatches yet.
</p>
</template>
+5
View File
@@ -13,6 +13,7 @@ import { Badge } from "@/components/ui/badge";
import { ago } from "@/lib/format";
import { captureSignature } from "./capture-signature";
import CapturePayload from "./CapturePayload.vue";
import DispatchLinks from "@/bindings/DispatchLinks.vue";
import { selected } from "./state";
/**
@@ -90,6 +91,10 @@ watch(selected, () => {
<div class="flex flex-col gap-5">
<CapturePayload label="Payload" :raw="selected.body" />
<CapturePayload label="Headers" :raw="selected.headers" />
<section class="flex flex-col gap-2">
<h3 class="text-sm font-medium">Dispatches</h3>
<DispatchLinks kind="captures" :id="selected.id" />
</section>
</div>
</CardContent>
</Card>
+2 -2
View File
@@ -71,8 +71,8 @@ onMounted(async () => {
// The URL names a selection before the window is read, so the restore waits
// for the list; an id it no longer holds falls back to the newest capture,
// which is what a page opened with nothing named starts on too.
const named = Number(route.query.capture);
if (!Number.isInteger(named) || !selectById(named)) selectNewest();
const named = String(route.query.capture ?? "");
if (!named || !selectById(named)) selectNewest();
});
onBeforeUnmount(() => {
+2 -2
View File
@@ -18,7 +18,7 @@ import { loadEventTypes } from "./event-type-state";
* what the page prints is what the store holds.
*/
export interface Capture {
id: number;
id: string;
received_at?: string;
source?: string;
remote_addr?: string;
@@ -80,7 +80,7 @@ export async function load(): Promise<void> {
* it. A capture that has aged out cannot be resolved: the list is the only
* read of a capture's body, so an id it no longer carries has nothing to show.
* Reports whether it found one. */
export function selectById(id: number): boolean {
export function selectById(id: string): boolean {
const found = captures.value.find((capture) => capture.id === id);
if (found) selected.value = found;
return Boolean(found);
+3 -3
View File
@@ -247,14 +247,14 @@ export const api = {
method: "DELETE",
parse: false,
}),
// capture_id is an int64 on the wire (mappingPreviewRequest), so it is sent
// as a number: a JSON string is rejected as an invalid request body.
mappingPreview: <T = unknown>(captureId: number, fields: unknown) =>
mappingPreview: <T = unknown>(captureId: string, fields: unknown) =>
request<T>("/api/mappings/preview", {
method: "POST",
body: { capture_id: captureId, fields },
}),
bindings: <T = unknown>() => request<T>("/api/bindings"),
dispatches: <T = unknown>(kind: "bindings" | "captures" | "tasks", id: string) =>
request<T>(`/api/${kind}/${encodeURIComponent(id)}/dispatches`),
bindingCreate: <T = unknown>(binding: Payload) =>
request<T>("/api/bindings", { method: "POST", body: binding }),
bindingUpdate: <T = unknown>(id: string, binding: Payload) =>
+2 -2
View File
@@ -43,7 +43,7 @@ export interface Mapping {
/** A captured inbound event. Its body is redacted before it is stored, and is
* the only thing a path is ever resolved against. */
export interface Capture {
id: number;
id: string;
source?: string;
received_at?: string;
body: string;
@@ -74,7 +74,7 @@ export interface MappingDraft {
eventTypeId: string;
fields: MappingField[];
/** The capture the payload and the preview resolve against, or null. */
captureId: number | null;
captureId: string | null;
/** The parsed capture body, or null when no capture is picked. */
payload: unknown;
payloadError: string | null;
+2
View File
@@ -12,6 +12,7 @@ import {
} from "@/components/ui/breadcrumb";
import { StatusPill } from "@/components/ui/status-pill";
import { statusKind, statusLabel } from "@/lib/task-meta";
import DispatchLinks from "@/bindings/DispatchLinks.vue";
import StartNewRun from "./StartNewRun.vue";
import TaskRowActions from "./TaskRowActions.vue";
import { pillFor } from "./status-pill";
@@ -63,6 +64,7 @@ const headerActions = computed(() =>
rel="noreferrer"
>{{ run.task.owner }}/{{ run.task.repo }} #{{ run.task.issue_number }}<ArrowUpRight class="size-3" aria-hidden="true"
/></a>
<DispatchLinks kind="tasks" :id="id" />
<a
v-if="run.task?.pr_url && run.task?.pr_number"
class="inline-flex items-center gap-0.5 font-mono text-xs text-fg-muted hover:text-foreground"
+1 -1
View File
@@ -47,7 +47,7 @@ const loading = ref(true);
const source = ref("");
const newSource = ref("");
const captureId = ref<number | null>(null);
const captureId = ref<string | null>(null);
const rows = ref<Record<string, InputRow>>({});
const repositoryPath = ref("");
const preview = ref<Preview | null>(null);