Files
archie/ui/src/bindings/DispatchLinks.vue
T

91 lines
2.7 KiB
Vue

<script setup lang="ts">
import { ref, watch } from "vue";
import { api } from "@/lib/api";
import { errors } from "@/copy/errors";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Timestamp } from "@/components/ui/timestamp";
/**
* 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);
let generation = 0;
watch(
() => [props.kind, props.id],
async () => {
const current = ++generation;
failed.value = false;
try {
const res = await api.dispatches<Dispatch[]>(props.kind, props.id);
if (current !== generation) return;
dispatches.value = res;
} catch {
if (current !== generation) return;
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-caption text-fg-muted">{{ errors.bindings.dispatchLinks.unavailable }}</p>
<ul v-else-if="dispatches.length" class="flex flex-col gap-1 text-caption">
<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 || errors.bindings.dispatchLinks.noTask }}</span>
</template>
<Timestamp :at="d.dispatched_at" />
</li>
</ul>
<Empty v-else-if="props.kind !== 'tasks'"><EmptyHeader><EmptyTitle>No dispatches yet.</EmptyTitle></EmptyHeader></Empty>
</template>