feat(ui): task logs as a table with expandable fields

This commit is contained in:
sam committed 2026-10-25 01:21:21 +11:00
1 parent e143362479
commit 849e24757d
4 files changed
+175 -126

No files matched your search

+37 -5
View File
@@ -2,7 +2,9 @@
import { computed, nextTick, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import LogRow from "@/base/LogRow.vue";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { MetadataList } from "@/components/ui/metadata-list";
import { fmtValue, LEVEL_COLOR, levelKind, shortTime, type LogEntry } from "@/lib/log";
import { Button } from "@/components/ui/button";
import {
Empty,
@@ -191,13 +193,28 @@ watch([() => route.hash, current], async () => {
if (focusedHash === route.hash) return;
if (page.value) { page.value = null; newerPages.value = []; }
await nextTick();
const line = logFrame.value?.querySelector<HTMLElement>(`[data-log-id="${match[1]}"]`);
const line = logFrame.value?.querySelector<HTMLElement>(`[data-row-key="${match[1]}"]`);
if (!line) return;
focusedHash = route.hash;
line?.scrollIntoView({ block: "center" });
line?.focus({ preventScroll: true });
}, { immediate: true, flush: "post" });
const TASK_FIELDS = ["task", "task_id"];
// Fields the columns or the page already show: the time, the task this page
// is about, and the stage and service columns.
const SHOWN_FIELDS = new Set(["received_at", "task", "task_id", "stage", "service"]);
const columns: DataTableColumn<LogEntry>[] = [
{ id: "time", label: "Time", fixed: true, class: "w-0 whitespace-nowrap" },
{ id: "level", label: "Level", fixed: true, class: "w-0" },
{ id: "stage", label: "Stage", class: "w-0 whitespace-nowrap" },
{ id: "service", label: "Service", hidden: true, class: "w-0 whitespace-nowrap" },
{ id: "message", label: "Message", fixed: true },
];
const rowKey = (entry: LogEntry) => String(entry.id ?? `${entry.time}|${entry.message ?? entry.msg}`);
const field = (entry: LogEntry, name: string) => fmtValue(entry.fields?.[name] ?? "");
const details = (entry: LogEntry) =>
Object.entries(entry.fields ?? {})
.filter(([k]) => !SHOWN_FIELDS.has(k))
.map(([label, value]) => ({ label, value: fmtValue(value), mono: true }));
</script>
<template>
@@ -250,9 +267,24 @@ const TASK_FIELDS = ["task", "task_id"];
read surface of its own and the tallest one on the page. -->
<div
ref="logFrame"
class="max-h-[62vh] overflow-y-auto rounded-sm border border-border bg-card px-2"
class="max-h-[62vh] overflow-y-auto rounded-sm border border-border bg-card"
>
<LogRow v-for="(entry, i) in view.entries" :key="entry.id ?? i" :entry="entry" :omit="TASK_FIELDS" :data-log-id="entry.id" tabindex="-1" />
<DataTable :columns="columns" :rows="view.entries" :row-key="rowKey" storage-key="task-log">
<template #cell-time="{ row }"><span class="font-mono text-xs text-fg-subtle">{{ shortTime(row.time) }}</span></template>
<template #cell-level="{ row }">
<span class="text-micro font-semibold tracking-[0.04em]" :class="LEVEL_COLOR[levelKind(row.level)]">{{ (row.level || "info").toUpperCase() }}</span>
</template>
<template #cell-stage="{ row }"><span class="font-mono text-xs text-fg-muted">{{ field(row, "stage") }}</span></template>
<template #cell-service="{ row }"><span class="font-mono text-xs text-fg-muted">{{ field(row, "service") }}</span></template>
<template #cell-message="{ row }">
<span class="font-mono text-xs [overflow-wrap:anywhere]">{{ row.message || row.msg || "" }}</span>
<span v-if="details(row).length" class="ml-2 text-xs text-fg-subtle">{{ details(row).length }} fields</span>
</template>
<template #detail="{ row }">
<MetadataList v-if="details(row).length" :rows="details(row)" class="text-xs" />
<span v-else class="text-xs text-fg-subtle">No fields</span>
</template>
</DataTable>
</div>
<div v-if="canPage" class="mt-2 flex flex-wrap items-center gap-2 px-1">
<Button variant="outline" size="sm" :disabled="!canOlder" @click="loadOlder">Older</Button>