ui: enable pagination on Activity page and fix table reactivity
- add showPagination to Activity route's ActivityTable - fix pagination reactivity: reassign pagination object in onPaginationChange so TanStack's effect.pre detects the change, and reset to first page only when pageSize changes - move data-change page reset into untrack to avoid clobbering navigation - render Cached/Prompt/Drafted headers with a dotted underline trigger instead of a separate info icon
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { untrack } from "svelte";
|
||||||
import type { ActivityLogEntry, ReqRespCapture } from "../lib/types";
|
import type { ActivityLogEntry, ReqRespCapture } from "../lib/types";
|
||||||
import { getCapture } from "../stores/api";
|
import { getCapture } from "../stores/api";
|
||||||
import { persistentStore } from "../stores/persistent";
|
import { persistentStore } from "../stores/persistent";
|
||||||
@@ -135,23 +136,21 @@
|
|||||||
// svelte-ignore state_referenced_locally
|
// svelte-ignore state_referenced_locally
|
||||||
const storedPageSize = persistentStore<number>(`${storagePrefix}-page-size`, 10);
|
const storedPageSize = persistentStore<number>(`${storagePrefix}-page-size`, 10);
|
||||||
|
|
||||||
|
// When not paginating, use a large page size so all rows render in one page.
|
||||||
// svelte-ignore state_referenced_locally
|
// svelte-ignore state_referenced_locally
|
||||||
let pagination = $state<PaginationState>({
|
let pagination = $state<PaginationState>({
|
||||||
pageIndex: 0,
|
pageIndex: 0,
|
||||||
pageSize: showPagination ? $storedPageSize : 1,
|
pageSize: showPagination ? $storedPageSize : Number.MAX_SAFE_INTEGER,
|
||||||
});
|
|
||||||
|
|
||||||
// When not paginating, show every row; reset page on data/pageSize change.
|
|
||||||
$effect(() => {
|
|
||||||
if (!showPagination) {
|
|
||||||
pagination.pageSize = metrics.length || 1;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reset to the first page when the data source changes. We deliberately do
|
||||||
|
// NOT track pagination here — page-size changes reset pageIndex inside
|
||||||
|
// onPaginationChange instead, to avoid clobbering page navigation.
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
metrics;
|
metrics;
|
||||||
pagination.pageSize;
|
untrack(() => {
|
||||||
pagination.pageIndex = 0;
|
pagination = { ...pagination, pageIndex: 0 };
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let selectedCapture = $state<ReqRespCapture | null>(null);
|
let selectedCapture = $state<ReqRespCapture | null>(null);
|
||||||
@@ -286,8 +285,16 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
onPaginationChange: (updater) => {
|
onPaginationChange: (updater) => {
|
||||||
|
const prev = pagination;
|
||||||
|
const next =
|
||||||
|
typeof updater === "function" ? updater(prev) : updater;
|
||||||
|
// Reassign so the table's $effect.pre (which reads state.pagination)
|
||||||
|
// picks up the new value. Reset to first page when the page size
|
||||||
|
// changes so we don't land on an empty page.
|
||||||
pagination =
|
pagination =
|
||||||
typeof updater === "function" ? updater(pagination) : updater;
|
next.pageSize !== prev.pageSize
|
||||||
|
? { pageIndex: 0, pageSize: next.pageSize }
|
||||||
|
: next;
|
||||||
if (showPagination) storedPageSize.set(pagination.pageSize);
|
if (showPagination) storedPageSize.set(pagination.pageSize);
|
||||||
},
|
},
|
||||||
onColumnVisibilityChange: (updater) => {
|
onColumnVisibilityChange: (updater) => {
|
||||||
|
|||||||
@@ -9,9 +9,13 @@
|
|||||||
let { label, tooltip }: Props = $props();
|
let { label, tooltip }: Props = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{label}{#if tooltip}
|
{#if tooltip}
|
||||||
<Tooltip.Root>
|
<Tooltip.Root>
|
||||||
<Tooltip.Trigger class="cursor-help align-middle normal-case">ⓘ</Tooltip.Trigger>
|
<Tooltip.Trigger class="cursor-help border-b border-dotted border-current align-middle">
|
||||||
|
{label}
|
||||||
|
</Tooltip.Trigger>
|
||||||
<Tooltip.Content>{tooltip}</Tooltip.Content>
|
<Tooltip.Content>{tooltip}</Tooltip.Content>
|
||||||
</Tooltip.Root>
|
</Tooltip.Root>
|
||||||
|
{:else}
|
||||||
|
{label}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
metrics={sortedMetrics}
|
metrics={sortedMetrics}
|
||||||
storagePrefix="activity"
|
storagePrefix="activity"
|
||||||
showModelColumn={true}
|
showModelColumn={true}
|
||||||
|
showPagination={true}
|
||||||
cardClass="min-h-[30rem] overflow-auto"
|
cardClass="min-h-[30rem] overflow-auto"
|
||||||
emptyMessage="No activity recorded"
|
emptyMessage="No activity recorded"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user