fix(ui/data-table): keep the growing column readable and hide secondary columns on narrow screens (#2023)
This commit is contained in:
8 files changed
+42
-32
No files matched your search
@@ -79,6 +79,16 @@ const sortIcon = (id: string) => (sortBy.value?.id !== id ? ArrowUpDown : sortBy
|
||||
const grows = computed(() => (props.columns.some((c) => c.width === "auto") ? "auto" : props.columns[0]?.id));
|
||||
const width = (column: DataTableColumn<Row>) =>
|
||||
column.width === "auto" || (!column.width && grows.value === column.id) ? undefined : { width: column.width ?? "10rem" };
|
||||
// The table never squeezes the growing column below 8rem: it scrolls instead.
|
||||
// Each breakpoint sums only the columns it still shows.
|
||||
const rem = (column: DataTableColumn<Row>) => (column.width === "auto" || (!column.width && grows.value === column.id) ? 8 : parseFloat(column.width ?? "10"));
|
||||
const minimum = (keep: (column: DataTableColumn<Row>) => boolean) =>
|
||||
`${shown.value.filter(keep).reduce((sum, c) => sum + rem(c), trailing.value ? 3 : 0)}rem`;
|
||||
const minimums = computed(() => ({
|
||||
"--min-lg": minimum(() => true),
|
||||
"--min-md": minimum((c) => c.hide !== "md"),
|
||||
"--min-sm": minimum((c) => !c.hide),
|
||||
}));
|
||||
const hidden = (column: DataTableColumn<Row>) => (column.hide ? (column.hide === "sm" ? "max-sm:hidden" : "max-md:hidden") : undefined);
|
||||
|
||||
const expandable = computed(() => !props.rowLink && !!slots.detail);
|
||||
@@ -99,7 +109,7 @@ function open(row: Row): void {
|
||||
<template>
|
||||
<!-- A sticky header sticks to the page's scrolling frame, so the table
|
||||
must not be a scroll container of its own. -->
|
||||
<Table class="table-fixed" :container-class="stickyHeader && 'overflow-visible'">
|
||||
<Table class="table-fixed min-w-(--min-lg) max-md:min-w-(--min-md) max-sm:min-w-(--min-sm)" :style="minimums" :container-class="stickyHeader && 'overflow-visible'">
|
||||
<colgroup>
|
||||
<col v-for="column in shown" :key="column.id" :class="hidden(column)" :style="width(column)" />
|
||||
<col v-if="trailing" class="w-12" />
|
||||
|
||||
@@ -39,17 +39,17 @@ const tab = computed(() => (TABS.some((t) => t.id === route.query.tab) ? String(
|
||||
const show = (id: unknown) => void router.replace({ query: { ...route.query, tab: id === "rules" ? undefined : String(id) } });
|
||||
|
||||
const judgeColumns: DataTableColumn<Judge>[] = [
|
||||
{ id: "name", label: "Guard", fixed: true, width: "16rem", sort: (j) => j.name },
|
||||
{ id: "mode", label: "Mode", fixed: true, width: "9rem" },
|
||||
{ id: "latest", label: "Last evaluation", width: "auto" },
|
||||
{ id: "name", label: "Guard", fixed: true, width: "auto", sort: (j) => j.name },
|
||||
{ id: "mode", label: "Mode", fixed: true, width: "8rem" },
|
||||
{ id: "latest", label: "Last evaluation", hide: "md", width: "28rem" },
|
||||
];
|
||||
const classColumns: DataTableColumn<ActionClass>[] = [
|
||||
{ id: "action", label: "Action", fixed: true, width: "auto", sort: (c) => `${c.connector}.${c.action}` },
|
||||
{ id: "target", label: "Target", width: "14rem", sort: (c) => c.target_kind ?? "" },
|
||||
{ id: "level", label: "Level", fixed: true, width: "16rem", sort: (c) => c.level },
|
||||
{ id: "count", label: "Approved in a row", width: "11rem", sort: (c) => c.count },
|
||||
{ id: "decisions", label: "Decisions", hidden: true, width: "7rem", sort: (c) => c.decisions },
|
||||
{ id: "last", label: "Last decided", width: "9rem", sort: (c) => (c.last_decided_at ? Date.parse(c.last_decided_at) : 0) },
|
||||
{ id: "target", label: "Target", hide: "md", width: "14rem", sort: (c) => c.target_kind ?? "" },
|
||||
{ id: "level", label: "Level", fixed: true, width: "13rem", sort: (c) => c.level },
|
||||
{ id: "count", label: "Approved in a row", hide: "md", width: "11rem", sort: (c) => c.count },
|
||||
{ id: "decisions", label: "Decisions", hidden: true, hide: "md", width: "7rem", sort: (c) => c.decisions },
|
||||
{ id: "last", label: "Last decided", hide: "sm", width: "9rem", sort: (c) => (c.last_decided_at ? Date.parse(c.last_decided_at) : 0) },
|
||||
];
|
||||
|
||||
const resetError = ref("");
|
||||
|
||||
@@ -45,9 +45,9 @@ const linked = computed(() => String(route.query.event ?? ""));
|
||||
const time = (at?: string) => (at ? Date.parse(at) : 0);
|
||||
const columns: DataTableColumn<EventRecord>[] = [
|
||||
{ id: "type", label: "Type", fixed: true, width: "auto", sort: (e) => e.type },
|
||||
{ id: "source", label: "Source", fixed: true, width: "12rem", sort: (e) => e.source },
|
||||
{ id: "matched", label: "Trigger", width: "9rem", sort: (e) => (e.matched ? 1 : 0) },
|
||||
{ id: "received", label: "Received", fixed: true, width: "9rem", sort: (e) => time(e.received_at) },
|
||||
{ id: "source", label: "Source", fixed: true, hide: "sm", width: "12rem", sort: (e) => e.source },
|
||||
{ id: "matched", label: "Trigger", hide: "sm", width: "9rem", sort: (e) => (e.matched ? 1 : 0) },
|
||||
{ id: "received", label: "Received", fixed: true, width: "7.5rem", sort: (e) => time(e.received_at) },
|
||||
{ id: "occurred", label: "Occurred", hidden: true, width: "9rem", sort: (e) => time(e.occurred_at) },
|
||||
{ id: "linked", label: "Same as", hidden: true, width: "10rem" },
|
||||
];
|
||||
@@ -88,7 +88,7 @@ const columns: DataTableColumn<EventRecord>[] = [
|
||||
>
|
||||
<template #cell-received="{ row }"><Timestamp :at="row.received_at" /></template>
|
||||
<template #cell-source="{ row }"><span class="font-mono">{{ row.source }}</span></template>
|
||||
<template #cell-type="{ row }"><span class="font-mono">{{ row.type }}</span></template>
|
||||
<template #cell-type="{ row }"><span class="font-mono">{{ row.type }}</span><span class="block text-caption text-fg-muted sm:hidden">{{ row.source }}</span></template>
|
||||
<template #cell-matched="{ row }">
|
||||
<Badge :variant="row.matched ? 'ok' : 'idle'">{{ row.matched ? "Matched" : "Unmatched" }}</Badge>
|
||||
</template>
|
||||
|
||||
@@ -28,9 +28,9 @@ onMounted(() => {
|
||||
|
||||
const columns: DataTableColumn<EventSource_>[] = [
|
||||
{ id: "name", label: "Source", fixed: true, sort: (s) => s.name },
|
||||
{ id: "connector", label: "Connector", width: "12rem", sort: (s) => s.connector },
|
||||
{ id: "verification", label: "Verification", width: "14rem" },
|
||||
{ id: "key", label: "Grouped by", width: "16rem" },
|
||||
{ id: "connector", label: "Connector", hide: "sm", width: "12rem", sort: (s) => s.connector },
|
||||
{ id: "verification", label: "Verification", hide: "sm", width: "14rem" },
|
||||
{ id: "key", label: "Grouped by", hide: "md", width: "16rem" },
|
||||
];
|
||||
|
||||
// A put creates a source or rotates its token; either way the token is shown
|
||||
@@ -129,7 +129,7 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
|
||||
<Button size="icon-sm" variant="ghost" aria-label="Add source" title="Add source" @click="openAdd"><Plus /></Button>
|
||||
</div>
|
||||
<DataTable :columns="columns" :rows="data" :row-key="(s) => s.name" storage-key="sources">
|
||||
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span></template>
|
||||
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span><span class="block text-caption text-fg-muted sm:hidden">{{ row.connector }}</span></template>
|
||||
<template #cell-connector="{ row }">{{ row.connector }}</template>
|
||||
<template #cell-verification="{ row }">{{ row.verification === "hmac" ? `HMAC (${row.hmac_header})` : row.verification === "none" ? "None" : "Bearer token" }}</template>
|
||||
<template #cell-key="{ row }"><span class="font-mono text-caption">{{ (row.key_fields ?? []).join(", ") || "Connector default" }}</span></template>
|
||||
|
||||
@@ -38,9 +38,9 @@ const rows = computed(() => (data.value ?? []).filter((t) => !props.workflow ||
|
||||
|
||||
const columns = computed<DataTableColumn<Trigger>[]>(() => [
|
||||
{ id: "name", label: "Trigger", fixed: true, width: "auto", sort: (t) => t.name },
|
||||
{ id: "fires", label: "Fires on", fixed: true, width: "18rem" },
|
||||
...(props.workflow ? [] : [{ id: "workflow", label: "Workflow", width: "14rem", sort: (t: Trigger) => t.workflow }]),
|
||||
{ id: "filter", label: "Filter", hidden: true, width: "16rem" },
|
||||
{ id: "fires", label: "Fires on", fixed: true, hide: "sm", width: "18rem" },
|
||||
...(props.workflow ? [] : [{ id: "workflow", label: "Workflow", hide: "md" as const, width: "14rem", sort: (t: Trigger) => t.workflow }]),
|
||||
{ id: "filter", label: "Filter", hidden: true, hide: "md", width: "16rem" },
|
||||
{ id: "enabled", label: "On", fixed: true, width: "5rem" },
|
||||
]);
|
||||
|
||||
@@ -100,7 +100,7 @@ async function submit(): Promise<void> {
|
||||
<Button size="icon-sm" variant="ghost" aria-label="Add trigger" title="Add trigger" @click="open()"><Plus /></Button>
|
||||
</div>
|
||||
<DataTable :columns="columns" :rows="rows" :row-key="(t) => t.name" :storage-key="workflow ? 'workflow-triggers' : 'triggers'">
|
||||
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span></template>
|
||||
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span><span class="block text-caption text-fg-muted sm:hidden">{{ row.every ? `Every ${interval(row.every)}` : `${row.source} ${row.event_type}` }}</span></template>
|
||||
<template #cell-fires="{ row }">
|
||||
<template v-if="row.every">Every {{ interval(row.every) }}</template>
|
||||
<template v-else>{{ row.source }} <span class="font-mono text-caption text-fg-muted">{{ row.event_type }}</span></template>
|
||||
|
||||
@@ -17,11 +17,11 @@ const router = useRouter();
|
||||
const time = (at?: string) => (at ? Date.parse(at) : 0);
|
||||
const took = (run: Run) => (run.finished_at ? time(run.finished_at) - time(run.created_at) : -1);
|
||||
const columns: DataTableColumn<Run>[] = [
|
||||
...(props.withWorkflow ? [{ id: "workflow", label: "Workflow", fixed: true, width: "18rem", sort: (r: Run) => r.workflow }] : []),
|
||||
{ id: "state", label: "State", fixed: true, width: "11rem", sort: (r) => r.state },
|
||||
{ id: "created", label: "Started", width: "9rem", sort: (r) => time(r.created_at) },
|
||||
{ id: "duration", label: "Took", width: "8rem", sort: took },
|
||||
{ id: "error", label: "Error", width: "auto", hide: "md" },
|
||||
...(props.withWorkflow ? [{ id: "workflow", label: "Workflow", fixed: true, width: "auto", sort: (r: Run) => r.workflow }] : []),
|
||||
{ id: "state", label: "State", fixed: true, width: "9.5rem", sort: (r) => r.state },
|
||||
{ id: "created", label: "Started", hide: "sm", width: "8rem", sort: (r) => time(r.created_at) },
|
||||
{ id: "duration", label: "Took", hide: "sm", width: "6rem", sort: took },
|
||||
{ id: "error", label: "Error", width: "24rem", hide: "md" },
|
||||
{ id: "attempts", label: "Attempts", hidden: true, width: "7rem", sort: (r) => r.attempts },
|
||||
{ id: "id", label: "Run", hidden: true, width: "14rem" },
|
||||
];
|
||||
|
||||
@@ -34,8 +34,8 @@ onMounted(() => {
|
||||
|
||||
const columns: DataTableColumn<Credential>[] = [
|
||||
{ id: "name", label: "Credential", fixed: true, sort: (c) => c.name },
|
||||
{ id: "kind", label: "Kind", width: "10rem", sort: (c) => c.kind },
|
||||
{ id: "fields", label: "Fields", width: "24rem" },
|
||||
{ id: "kind", label: "Kind", hide: "sm", width: "10rem", sort: (c) => c.kind },
|
||||
{ id: "fields", label: "Fields", hide: "md", width: "24rem" },
|
||||
];
|
||||
|
||||
interface FieldForm { from: "value" | "engine"; value: string; engine: string; key: string }
|
||||
|
||||
@@ -32,10 +32,10 @@ onMounted(reload);
|
||||
const columns = computed<DataTableColumn<Extension>[]>(() => [
|
||||
{ id: "name", label: "Name", fixed: true, sort: (e) => e.name },
|
||||
{ id: "state", label: "State", fixed: true, width: "9rem", sort: (e) => e.state },
|
||||
{ id: "version", label: "Version", width: "8rem", sort: (e) => e.version ?? "" },
|
||||
...(props.kind === "connectors" ? [{ id: "capabilities", label: "Declares", width: "14rem" }] : []),
|
||||
{ id: "path", label: "Path", hidden: true, width: "18rem" },
|
||||
{ id: "egress", label: "Egress", hidden: true, width: "14rem" },
|
||||
{ id: "version", label: "Version", hide: "sm", width: "8rem", sort: (e) => e.version ?? "" },
|
||||
...(props.kind === "connectors" ? [{ id: "capabilities", label: "Declares", hide: "md" as const, width: "14rem" }] : []),
|
||||
{ id: "path", label: "Path", hidden: true, hide: "md", width: "18rem" },
|
||||
{ id: "egress", label: "Egress", hidden: true, hide: "md", width: "14rem" },
|
||||
]);
|
||||
|
||||
const CAPABILITY_GROUPS = [
|
||||
|
||||
Reference in new issue
Block a user