Simplify metrics overview and paginate breakdowns

This commit is contained in:
2026-10-06 19:02:02 -04:00
parent b8cccc5a98
commit 01d764946c
7 changed files with 353 additions and 227 deletions
+9
View File
@@ -30,3 +30,12 @@ export function compareMetricValues(left: number | null, right: number | null, d
if (a === null || b === null) return a === b ? 0 : a === null ? 1 : -1;
return (a - b) * (direction === 'asc' ? 1 : -1);
}
/** Clamp saved pages after filtering or polling changes the result count. */
export function metricPage<T>(rows: T[], requested: string | null, size = 15) {
const parsed = Number(requested);
const pages = Math.max(1, Math.ceil(rows.length / size));
const page = Math.min(pages, Number.isSafeInteger(parsed) && parsed > 0 ? parsed : 1);
const start = (page - 1) * size;
return { page, pages, rows: rows.slice(start, start + size), start: rows.length ? start + 1 : 0, end: Math.min(rows.length, start + size), total: rows.length };
}