Files
archie/ui/src/events/EventList.vue
T
sam 9c5af2c2d3 feat(ui/events,settings): give the event, source, trigger, model, credential and extension lists the original layout (#2023)
Tables use fixed column widths and the ghost add button. The models page
keeps the aliases section with one inline row per alias.
2026-11-22 02:36:13 +11:00

104 lines
4.6 KiB
Vue

<script setup lang="ts">
import { computed, onMounted, ref, watch } from "vue";
import { useRoute } from "vue-router";
import { Badge } from "@/components/ui/badge";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Input } from "@/components/ui/input";
import { ReadError } from "@/components/ui/read-error";
import { Section } from "@/components/ui/section";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Skeleton } from "@/components/ui/skeleton";
import { Timestamp } from "@/components/ui/timestamp";
import { api, type EventRecord } from "@/lib/api";
import { usePoll, useRead } from "@/lib/use-read";
import { useLiveResource } from "@/stores/session";
import EventDetail from "./EventDetail.vue";
const route = useRoute();
const ALL = "__all__";
const source = ref(ALL);
const type = ref("");
const matched = ref(ALL);
const sources = useRead(() => api.eventSources());
const { data, error, reload } = useRead(() =>
api.events({
limit: 200,
source: source.value === ALL ? undefined : source.value,
type: type.value.trim() || undefined,
matched: matched.value === ALL ? undefined : matched.value,
}),
);
onMounted(() => {
void reload();
void sources.reload();
});
watch([source, matched], () => void reload());
useLiveResource(null, () => void reload());
usePoll(reload);
// ?event= opens one event above the list: a run links to the event it started from.
const linked = computed(() => String(route.query.event ?? ""));
const time = (at?: string) => (at ? Date.parse(at) : 0);
const columns: DataTableColumn<EventRecord>[] = [
{ id: "type", label: "Type", fixed: true, width: "auto", sort: (e) => e.type },
{ id: "source", label: "Source", fixed: true, width: "12rem", sort: (e) => e.source },
{ id: "matched", label: "Trigger", width: "9rem", sort: (e) => (e.matched ? 1 : 0) },
{ id: "received", label: "Received", fixed: true, width: "9rem", sort: (e) => time(e.received_at) },
{ id: "occurred", label: "Occurred", hidden: true, width: "9rem", sort: (e) => time(e.occurred_at) },
{ id: "linked", label: "Same as", hidden: true, width: "10rem" },
];
</script>
<template>
<div>
<Section v-if="linked" title="Event"><EventDetail :id="linked" /></Section>
<div class="mb-3 flex flex-wrap items-center gap-2">
<Select v-model="source">
<SelectTrigger size="sm" aria-label="Source"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem :value="ALL">All sources</SelectItem>
<SelectItem v-for="s in sources.data.value ?? []" :key="s.name" :value="s.name">{{ s.name }}</SelectItem>
</SelectContent>
</Select>
<Select v-model="matched">
<SelectTrigger size="sm" aria-label="Trigger outcome"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem :value="ALL">Matched or not</SelectItem>
<SelectItem value="true">Matched a trigger</SelectItem>
<SelectItem value="false">Unmatched</SelectItem>
</SelectContent>
</Select>
<form class="contents" @submit.prevent="reload">
<Input v-model="type" class="h-8 w-48" placeholder="Event type" aria-label="Event type" @change="reload" />
</form>
</div>
<ReadError v-if="error" :message="error" retry-label="Retry" @retry="reload" />
<div v-else-if="!data" role="status" aria-label="Loading events" class="space-y-2"><Skeleton class="h-8 w-full" /><Skeleton class="h-8 w-full" /></div>
<DataTable
v-else
:columns="columns"
:rows="data"
:row-key="(e) => e.id"
storage-key="events"
:initial-sort="{ id: 'received', desc: true }"
>
<template #cell-received="{ row }"><Timestamp :at="row.received_at" /></template>
<template #cell-source="{ row }"><span class="font-mono">{{ row.source }}</span></template>
<template #cell-type="{ row }"><span class="font-mono">{{ row.type }}</span></template>
<template #cell-matched="{ row }">
<Badge :variant="row.matched ? 'ok' : 'idle'">{{ row.matched ? "Matched" : "Unmatched" }}</Badge>
</template>
<template #cell-occurred="{ row }"><Timestamp :at="row.occurred_at" /></template>
<template #cell-linked="{ row }"><span class="font-mono text-caption text-fg-muted">{{ row.linked_to?.slice(0, 8) }}</span></template>
<template #detail="{ row }"><EventDetail :id="row.id" /></template>
<template #empty>
<Empty><EmptyHeader><EmptyTitle>No events</EmptyTitle></EmptyHeader></Empty>
</template>
</DataTable>
</div>
</template>