feat(ui): split agents from services, choose status columns, open reasons from the state badge

This commit is contained in:
sam committed 2026-10-24 11:45:57 +11:00
1 parent c7fc55a0ef
commit b2f720cc2b
13 files changed
+198 -142

No files matched your search

+85 -29
View File
@@ -1,8 +1,17 @@
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from "vue";
import { computed, onMounted, onUnmounted, ref } from "vue";
import { useLocalStorage } from "@vueuse/core";
import { ChevronDown, Columns3 } from "@lucide/vue";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Card, CardAction, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
Table,
TableBody,
@@ -11,6 +20,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { api } from "@/lib/api";
interface AppliedRecord {
@@ -39,6 +49,29 @@ let timer: ReturnType<typeof setInterval> | undefined;
const tone = { up: "ok", degraded: "warn", down: "danger", unknown: "idle" } as const;
type Column = "version" | "install" | "uptime" | "seen" | "problems";
const COLUMNS: { id: Column; label: string }[] = [
{ id: "version", label: "Version" },
{ id: "install", label: "Runs as" },
{ id: "uptime", label: "Uptime" },
{ id: "seen", label: "Last seen" },
{ id: "problems", label: "State" },
];
// A browser-local view preference, like the appearance settings.
const shown = useLocalStorage<Column[]>("archie.status.columns", ["version", "uptime", "problems"]);
const visible = (column: Column) => shown.value.includes(column);
function toggle(column: Column, on: boolean): void {
shown.value = on ? [...shown.value, column] : shown.value.filter((c) => c !== column);
}
// An agent reports for one task, so agents get their own table keyed by task.
const daemons = computed(() => services.value.filter((s) => s.service !== "archie-agent"));
const agents = computed(() => services.value.filter((s) => s.service === "archie-agent"));
const tables = computed(() => [
{ title: "Services", rows: daemons.value, agent: false },
...(agents.value.length ? [{ title: "Agents", rows: agents.value, agent: true }] : []),
]);
function uptime(service: Service): string {
if (!service.started_at || service.state === "down") return "";
const seconds = Math.max(
@@ -74,12 +107,15 @@ function problems(service: Service): { key: string; text: string }[] {
];
}
const stateLabel = (service: Service, agent: boolean) => (agent && service.state === "down" ? "stale" : service.state);
const reasons = (service: Service) => {
const found = problems(service).map((problem) => problem.text);
return found.length || !service.detail ? found : [service.detail];
};
async function load(): Promise<void> {
try {
// An agent reports for one task; once that task ends its row is history.
services.value = (await api.services<Service[]>()).filter(
(service) => !(service.service === "archie-agent" && service.state === "down"),
);
services.value = await api.services<Service[]>();
error.value = null;
} catch (err) {
error.value = String((err as Error).message || err);
@@ -94,39 +130,59 @@ onUnmounted(() => clearInterval(timer));
</script>
<template>
<Card>
<p v-if="error" class="mb-4 text-sm text-danger">{{ error }}</p>
<Card v-for="(table, index) in tables" v-else :key="table.title" :class="index ? 'mt-4' : ''">
<CardHeader>
<CardTitle>Services</CardTitle>
<CardTitle>{{ table.title }}</CardTitle>
<CardAction v-if="!index">
<DropdownMenu>
<DropdownMenuTrigger as-child>
<Button variant="ghost" size="icon-sm" aria-label="Columns" title="Columns"><Columns3 /></Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuCheckboxItem
v-for="column in COLUMNS"
:key="column.id"
:model-value="visible(column.id)"
@update:model-value="toggle(column.id, $event)"
@select.prevent
>{{ column.label }}</DropdownMenuCheckboxItem>
</DropdownMenuContent>
</DropdownMenu>
</CardAction>
</CardHeader>
<CardContent>
<p v-if="error" class="text-sm text-danger">{{ error }}</p>
<Table v-else>
<Table>
<TableHeader>
<TableRow>
<TableHead>Service</TableHead>
<TableHead>Version</TableHead>
<TableHead>Uptime</TableHead>
<TableHead class="w-full">Problems</TableHead>
<TableHead>{{ table.agent ? "Task" : "Service" }}</TableHead>
<TableHead v-for="column in COLUMNS.filter((c) => visible(c.id))" :key="column.id">{{ column.label }}</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow
v-for="service in services"
:key="`${service.service}/${service.instance_id}`"
class="align-top"
>
<TableRow v-for="service in table.rows" :key="`${service.service}/${service.instance_id}`" class="align-top">
<TableCell>
<span class="font-mono">{{ service.service }}</span>
<span v-if="service.service === 'archie-agent'" class="ml-2 text-fg-muted">task {{ service.instance_id }}</span>
<RouterLink v-if="table.agent" :to="`/tasks/${service.instance_id}`" class="hover:underline">#{{ service.instance_id }}</RouterLink>
<span v-else class="font-mono">{{ service.service }}</span>
</TableCell>
<TableCell class="font-mono text-fg-muted" :title="service.install_type">{{ service.version }}</TableCell>
<TableCell class="tabular-nums" :title="lastSeen(service) && `Last seen ${lastSeen(service)}`">{{ uptime(service) }}</TableCell>
<TableCell class="min-w-64 whitespace-normal">
<Badge v-if="service.state !== 'up'" :variant="tone[service.state]">{{ service.state }}</Badge>
<span v-if="service.state !== 'up' && service.detail && !problems(service).length" class="ml-2 text-fg-muted">{{
service.detail
}}</span>
<p v-for="problem in problems(service)" :key="problem.key" class="text-warn">{{ problem.text }}</p>
<TableCell v-if="visible('version')" class="font-mono text-fg-muted">{{ service.version }}</TableCell>
<TableCell v-if="visible('install')" class="text-fg-muted">{{ service.install_type }}</TableCell>
<TableCell v-if="visible('uptime')" class="tabular-nums">{{ uptime(service) }}</TableCell>
<TableCell v-if="visible('seen')" class="text-fg-muted">{{ lastSeen(service) }}</TableCell>
<TableCell v-if="visible('problems')">
<template v-if="service.state !== 'up'">
<Popover v-if="reasons(service).length">
<PopoverTrigger as-child>
<button type="button" class="rounded-sm" :aria-label="`Why ${service.service} is ${service.state}`">
<Badge :variant="tone[service.state]">{{ stateLabel(service, table.agent) }}<ChevronDown data-icon="inline-end" /></Badge>
</button>
</PopoverTrigger>
<PopoverContent align="start" class="w-96 max-w-[calc(100vw-2rem)] space-y-1 text-sm">
<p v-for="reason in reasons(service)" :key="reason" class="break-words">{{ reason }}</p>
</PopoverContent>
</Popover>
<Badge v-else :variant="tone[service.state]">{{ stateLabel(service, table.agent) }}</Badge>
</template>
</TableCell>
</TableRow>
</TableBody>