feat(ui): task log opens newest first
This commit is contained in:
1 parent
f2b8681611
commit
33da08bce5
4 files changed
+30
-8
No files matched your search
@@ -1,5 +1,7 @@
|
||||
<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, shortTime, type LogEntry } from "@/lib/log";
|
||||
|
||||
@@ -18,12 +20,18 @@ const props = withDefaults(
|
||||
/** 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 },
|
||||
{ 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" },
|
||||
{ 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" },
|
||||
@@ -40,7 +48,15 @@ const details = (entry: LogEntry) =>
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DataTable :columns="columns" :rows="entries" :row-key="rowKey" :storage-key="storageKey" :row-class="(e) => rowClass(e.level)" sticky-header>
|
||||
<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-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>
|
||||
|
||||
Reference in new issue
Block a user