Files
HealthLog/src/lib/query-keys/labs.ts
T
Marc-André Bombeck 13ee5e2df4 fix(labs): paginate the biomarker reading feed
The detail page fetched a single limit=500 window and sorted client-side,
silently truncating any marker that crossed 500 readings. Switch to an
offset-paginated useInfiniteQuery: it loads a page at a time, a 'Load more'
control reveals the rest, and the chart and stat strip render the
accumulated set so loading more extends the trend.
2026-06-28 18:30:39 +02:00

58 lines
1.9 KiB
TypeScript

/**
* v1.17.1 — TanStack Query keys for the structured lab-result store.
*
* `labResultsList` bakes the filter + pagination shape into the key so a
* filter change refetches without a same-key cache collision (the project's
* queryKey-factory invariant).
*/
export const labKeys = {
labResults: () => ["lab-results"] as const,
labResultsList: (params: {
biomarkerId?: string | undefined;
analyte: string | undefined;
panel: string | undefined;
from: string | undefined;
to: string | undefined;
page: number;
sortDir: string;
}) =>
[
"lab-results",
"list",
params.biomarkerId ?? null,
params.analyte ?? null,
params.panel ?? null,
params.from ?? null,
params.to ?? null,
params.page,
params.sortDir,
] as const,
// v1.25 — paginated (offset) reading feed for the biomarker detail page.
// Distinct from `labResultsList` (single-page key) so the infinite-query
// accumulation never collides with a single-page read. Shares the
// `["lab-results", …]` prefix so a result mutation's `labResults()`
// invalidation evicts it too.
labResultsInfinite: (params: { biomarkerId: string; sortDir: string }) =>
[
"lab-results",
"list",
"infinite",
params.biomarkerId,
params.sortDir,
] as const,
// v1.18.1 — user-scoped Biomarker catalog. The list feeds the picker and
// the manager; both invalidate `biomarkers()` after a mutation.
biomarkers: () => ["biomarkers"] as const,
biomarkerDetail: (id: string) => ["biomarkers", "detail", id] as const,
// v1.18.9 — Lab-OCR capability probe (drives whether the "Scan a report"
// affordance shows). Cheap GET; the dialog refetches it on open.
ocrCapability: () => ["lab-ocr", "capability"] as const,
// v1.18.10 — local (in-browser) OCR opt-in flag for text-only providers.
labsLocalOcr: () => ["labs", "local-ocr"] as const,
};