components/ui and the pages now use only the style.css scale: text-[0.8rem]→text-label, text-[0.625rem]→text-micro, text-base/text-sm→ text-label (rows and controls), text-xs→text-caption (captions and secondary text), text-lg/text-xl/text-2xl→text-title (panel and page titles). Rendered markdown (ChatMarkdown/ChatInline/markdown.ts) keeps Tailwind steps as the issue allows. 196 files, class-token swaps only.
81 lines
4.0 KiB
Vue
81 lines
4.0 KiB
Vue
<script setup lang="ts">
|
|
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
|
import { computed } from "vue";
|
|
|
|
import { MetadataList } from "@/components/ui/metadata-list";
|
|
import { fmtValue, LEVEL_COLOR, levelKind, rowClass, type LogEntry } from "@/lib/log";
|
|
import { shortTime } from "@/lib/format";
|
|
import { useAppearanceStore } from "@/stores/appearance";
|
|
|
|
const appearance = useAppearanceStore();
|
|
|
|
/**
|
|
* 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 service and component columns by default, for logs spanning
|
|
* services; a task's own log shows its stage instead. */
|
|
services?: boolean;
|
|
/** Opens with the newest entry first; the Time header flips it. */
|
|
newestFirst?: boolean;
|
|
}>(),
|
|
{ omit: () => [], services: false, newestFirst: false },
|
|
);
|
|
|
|
// Entries arrive in log order, which is the order to sort time by: equal
|
|
// timestamps keep the order they were written in.
|
|
const position = computed(() => new Map(props.entries.map((entry, i) => [entry, i])));
|
|
|
|
const columns: DataTableColumn<LogEntry>[] = [
|
|
{ id: "time", label: "Time", fixed: true, class: "w-0 whitespace-nowrap", sort: (e) => position.value.get(e) ?? 0 },
|
|
{ id: "level", label: "Level", fixed: true, class: "w-0" },
|
|
{ id: "service", label: "Service", hidden: !props.services, class: "w-0 whitespace-nowrap" },
|
|
{ id: "component", label: "Component", hidden: !props.services, class: "w-0 whitespace-nowrap" },
|
|
{ id: "stage", label: "Stage", hidden: props.services, class: "w-0 whitespace-nowrap" },
|
|
{ id: "message", label: "Message", fixed: true, class: "whitespace-normal" },
|
|
];
|
|
// received_at restates the time; the rest have columns.
|
|
const shown = new Set(["received_at", "stage", "service", "component", ...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)"
|
|
:initial-sort="newestFirst ? { id: 'time', desc: true } : undefined"
|
|
sticky-header
|
|
>
|
|
<template #cell-time="{ row }"><span class="font-mono text-caption text-fg-subtle">{{ shortTime(row.time, appearance.timeZone) }}</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="block max-w-40 truncate font-mono text-caption text-fg-muted">{{ field(row, "service") }}</span></template>
|
|
<template #cell-component="{ row }"><span class="block max-w-48 truncate font-mono text-caption text-fg-muted">{{ field(row, "component") }}</span></template>
|
|
<template #cell-stage="{ row }"><span class="block max-w-48 truncate font-mono text-caption text-fg-muted" :title="field(row, 'stage')">{{ field(row, "stage") }}</span></template>
|
|
<template #cell-message="{ row }">
|
|
<span class="font-mono text-caption [overflow-wrap:anywhere]">{{ row.message || row.msg || "" }}</span>
|
|
<span v-if="details(row).length" class="ml-2 text-caption 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-caption" />
|
|
<span v-else class="text-caption text-fg-subtle">No fields</span>
|
|
</template>
|
|
</DataTable>
|
|
</template>
|