feat(ui): the Logs page uses the task log's table

This commit is contained in:
sam committed 2026-10-25 02:17:35 +11:00
1 parent 4820c1b481
commit 3e59ce0701
8 files changed
+169 -209

No files matched your search

-56
View File
@@ -1,56 +0,0 @@
<script setup lang="ts">
import {
fmtValue,
LEVEL_COLOR,
levelKind,
rowClass,
shortTime,
type LogEntry,
} from "@/lib/log";
/**
* Shared log-entry rendering. Both the daemon-wide log page and a task's own
* attempt log render the same entry shape, so the row lives here rather than
* being duplicated a second time.
*/
const props = defineProps<{ entry: LogEntry; omit?: string[] }>();
// received_at restates the row's time; a page that sets the context (a task's
// own log) also omits the fields naming it.
const fields = () =>
Object.entries(props.entry.fields ?? {}).filter(
([k]) => k !== "received_at" && !props.omit?.includes(k),
);
</script>
<template>
<div
class="grid grid-cols-[62px_52px_1fr] items-baseline gap-x-3 gap-y-1 max-sm:grid-cols-[62px_1fr] border-b border-b-border border-l-2 px-1 py-2 hover:bg-accent"
:class="rowClass(props.entry.level)"
>
<span class="font-mono text-fg-subtle">{{
shortTime(props.entry.time)
}}</span>
<span
class="text-micro font-semibold tracking-[0.04em]"
:class="LEVEL_COLOR[levelKind(props.entry.level)]"
>
{{ (props.entry.level || "info").toUpperCase() }}
</span>
<span class="flex min-w-0 flex-wrap items-baseline gap-2 max-sm:col-span-2">
<span class="min-w-0 font-mono text-foreground [overflow-wrap:anywhere]">{{
props.entry.message || props.entry.msg || ""
}}</span>
<span
v-for="[k, v] in fields()"
:key="k"
class="max-w-full truncate rounded-sm bg-muted px-2 text-fg-muted"
>
<span class="text-fg-subtle after:opacity-60 after:content-['=']">{{
k
}}</span
>{{ fmtValue(v) }}
</span>
</span>
</div>
</template>
+57
View File
@@ -0,0 +1,57 @@
<script setup lang="ts">
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { MetadataList } from "@/components/ui/metadata-list";
import { fmtValue, LEVEL_COLOR, levelKind, rowClass, shortTime, type LogEntry } from "@/lib/log";
/**
* Log entries as a table: time, level, stage, service and message, with an
* entry's remaining fields opened beneath it. The task log and the
* instance-wide log page render the same entries through it.
*/
const props = withDefaults(
defineProps<{
entries: LogEntry[];
rowKey: (entry: LogEntry) => string;
storageKey: string;
/** Fields the page itself already names, such as the task it is about. */
omit?: string[];
/** Shows the service column by default, for logs spanning services. */
services?: boolean;
}>(),
{ omit: () => [], services: false },
);
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: "service", label: "Service", hidden: !props.services, class: "w-0 whitespace-nowrap" },
{ id: "stage", label: "Stage", class: "w-0 whitespace-nowrap" },
{ id: "message", label: "Message", fixed: true },
];
// received_at restates the time; stage and service have columns.
const shown = new Set(["received_at", "stage", "service", ...props.omit]);
const field = (entry: LogEntry, name: string) => fmtValue(entry.fields?.[name] ?? "");
const details = (entry: LogEntry) =>
Object.entries(entry.fields ?? {})
.filter(([k]) => !shown.has(k))
.map(([label, value]) => ({ label, value: fmtValue(value), mono: true }));
</script>
<template>
<DataTable :columns="columns" :rows="entries" :row-key="rowKey" :storage-key="storageKey" :row-class="(e) => rowClass(e.level)">
<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-service="{ row }"><span class="font-mono text-xs text-fg-muted">{{ field(row, "service") }}</span></template>
<template #cell-stage="{ row }"><span class="font-mono text-xs text-fg-muted">{{ field(row, "stage") }}</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 }} field{{ details(row).length === 1 ? "" : "s" }}</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>
</template>
@@ -29,6 +29,7 @@ const props = defineProps<{
storageKey: string;
rowLink?: (row: Row) => string;
rowLabel?: (row: Row) => string;
rowClass?: (row: Row) => string;
}>();
const slots = defineSlots<Record<string, (props: { row: Row }) => unknown> & { empty?: () => unknown; actions?: (props: { row: Row }) => unknown; detail?: (props: { row: Row }) => unknown }>();
@@ -123,7 +124,7 @@ function open(row: Row): void {
:role="rowLink ? 'link' : undefined"
:aria-label="rowLink && rowLabel ? rowLabel(row) : undefined"
:aria-expanded="expandable ? expanded.has(rowKey(row)) : undefined"
:class="['align-top', (rowLink || expandable) && 'cursor-pointer']"
:class="['align-top', (rowLink || expandable) && 'cursor-pointer', rowClass?.(row)]"
@click="open(row)"
@keydown.enter.self.prevent="open(row)"
@keydown.space.self.prevent="open(row)"
+2 -15
View File
@@ -52,22 +52,9 @@ export function levelKind(level: string | null | undefined): LevelKind {
}
}
/**
* The row's own treatment, by level. The level label carries the colour; the row
* carries the weight: an ERROR line is a block the eye lands on, not red text
* in a column of grey. Every row keeps a left edge of the same width, coloured
* or not, so the three columns never shift between rows.
*/
export const LEVEL_ROW: Record<LevelKind, string> = {
danger: "border-l-danger bg-danger-soft",
warn: "border-l-transparent",
info: "border-l-transparent",
idle: "border-l-transparent",
};
/** The classes one row wears for its level. */
/** An error line is a block the eye lands on, not red text in a grey column. */
export function rowClass(level: string | null | undefined): string {
return LEVEL_ROW[levelKind(level)];
return levelKind(level) === "danger" ? "bg-danger-soft hover:bg-danger-soft" : "";
}
export function fmtValue(v: unknown): string {
+2 -2
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import LogRow from "@/base/LogRow.vue";
import LogTable from "@/base/LogTable.vue";
import { Skeleton } from "@/components/ui/skeleton";
import { entryKey } from "./log-entries";
@@ -65,7 +65,7 @@ watch(
:detail="emptyDetail"
/>
<template v-else>
<LogRow v-for="entry in entries" :key="entryKey(entry)" :entry="entry" />
<LogTable :entries="entries" :row-key="entryKey" storage-key="logs" services />
</template>
</div>
</template>
+5 -34
View File
@@ -2,9 +2,8 @@
import { computed, nextTick, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
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 LogTable from "@/base/LogTable.vue";
import type { LogEntry } from "@/lib/log";
import { Button } from "@/components/ui/button";
import {
Empty,
@@ -199,22 +198,9 @@ watch([() => route.hash, current], async () => {
line?.scrollIntoView({ block: "center" });
line?.focus({ preventScroll: true });
}, { immediate: true, flush: "post" });
// 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 },
];
// The task this page is about.
const TASK_FIELDS = ["task", "task_id"];
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>
@@ -269,22 +255,7 @@ const details = (entry: LogEntry) =>
ref="logFrame"
class="max-h-[62vh] overflow-y-auto rounded-sm border border-border bg-card"
>
<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 }} field{{ details(row).length === 1 ? "" : "s" }}</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>
<LogTable :entries="view.entries" :row-key="rowKey" :omit="TASK_FIELDS" storage-key="task-log" />
</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>