mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
feat(lists): read and show the list cap on every capped list
Twelve routes answer a capped list with meta.truncated / meta.limit on the envelope, and the web client read only data, so no surface said a list had stopped short. apiGetList / apiPostList are now the one client reader of the cap and ListCapNotice the one line that shows it; every capped list on the web reads its cap and shows the notice under the list, the paged readers (side effects, illness episodes) stop on the route's answer instead of a full-page guess, and the ECG list moves its five readers onto one hook. The record activity feed sent its cap twice, in data and on the envelope; it rides the envelope alone now. A guard derives the capped routes from the tree and binds each to a client that reads its cap.
This commit is contained in:
1 parent
be79603d53
commit
dc5120b59a
49 files changed
+574
-204
No files matched your search
@@ -142,13 +142,9 @@ export const GET = apiHandler(async () => {
|
||||
createdAt: row.createdAt.toISOString(),
|
||||
}));
|
||||
|
||||
// Exact: one row past the cap was asked for, so a list that is exactly
|
||||
// full no longer reads as cut.
|
||||
const truncated = cap.truncated;
|
||||
|
||||
annotate({
|
||||
action: { name: "sharing.activity.list" },
|
||||
meta: { entry_count: entries.length, truncated },
|
||||
meta: { entry_count: entries.length, truncated: cap.truncated },
|
||||
});
|
||||
|
||||
return apiListSuccess(
|
||||
@@ -157,11 +153,9 @@ export const GET = apiHandler(async () => {
|
||||
// The bound the view states out loud. Resolved here so the UI never has to
|
||||
// hardcode a number the operator can change.
|
||||
retentionDays,
|
||||
// Whether the list is everything inside that window, or its most recent
|
||||
// hundred rows. The view says which; silence would let the oldest line
|
||||
// read as the beginning.
|
||||
truncated,
|
||||
},
|
||||
// Whether the list is everything inside that window, or its most recent
|
||||
// hundred rows, rides the envelope like every capped list's (`meta`).
|
||||
cap,
|
||||
);
|
||||
});
|
||||
@@ -56,8 +56,11 @@ function render(node: React.ReactNode) {
|
||||
});
|
||||
// Seed the ECG list the cross-link reads so its data-availability gate opens.
|
||||
client.setQueryData(queryKeys.insightsEcgList(), {
|
||||
recordings: [{ id: "a", classification: null }],
|
||||
hasRecordings: true,
|
||||
data: {
|
||||
recordings: [{ id: "a", classification: null }],
|
||||
hasRecordings: true,
|
||||
},
|
||||
cap: null,
|
||||
});
|
||||
return renderToStaticMarkup(
|
||||
<QueryClientProvider client={client}>
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
type CatalogEntry,
|
||||
} from "@/lib/insights/metric-catalog";
|
||||
import type { ManagerGroup } from "@/lib/insights/sub-page-metric";
|
||||
import { useEcgList } from "@/components/insights/use-ecg-list";
|
||||
|
||||
/**
|
||||
* `/insights/catalog` — "what can HealthLog track" (2026-07-17
|
||||
@@ -252,11 +253,7 @@ export default function MetricCatalogPage() {
|
||||
enabled: isAuthenticated && nutrientsModuleEnabled,
|
||||
});
|
||||
|
||||
const ecgQuery = useQuery({
|
||||
queryKey: queryKeys.insightsEcgList(),
|
||||
queryFn: () => apiGet<{ hasRecordings: boolean }>("/api/insights/ecg"),
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
const ecgQuery = useEcgList();
|
||||
|
||||
const availability: InsightInputs | undefined = isAuthenticated
|
||||
? {
|
||||
@@ -319,7 +316,7 @@ export default function MetricCatalogPage() {
|
||||
|
||||
function isPresent(entry: CatalogEntry): boolean | null {
|
||||
if (entry.kind === "info") return null;
|
||||
if (entry.id === "ecg") return ecgQuery.data?.hasRecordings === true;
|
||||
if (entry.id === "ecg") return ecgQuery.data?.data.hasRecordings === true;
|
||||
if (!availability || !entry.metric) return false;
|
||||
return hasMetricData(entry.metric, availability);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ function render(data: { recordings: EcgRecord[]; hasRecordings: boolean }) {
|
||||
const client = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
|
||||
});
|
||||
client.setQueryData(queryKeys.insightsEcgList(), data);
|
||||
client.setQueryData(queryKeys.insightsEcgList(), { data, cap: null });
|
||||
return renderToStaticMarkup(
|
||||
<QueryClientProvider client={client}>
|
||||
<I18nProvider initialLocale="en">
|
||||
|
||||
@@ -2,17 +2,15 @@
|
||||
|
||||
import Link from "next/link";
|
||||
import { Activity } from "lucide-react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
import { apiGet } from "@/lib/api/api-fetch";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { QueryErrorCard } from "@/components/ui/query-error-card";
|
||||
import { SubPageShell } from "@/components/insights/sub-page-shell";
|
||||
import { MetricEmptyState } from "@/components/insights/metric-empty-state";
|
||||
import { EcgSection } from "@/components/insights/ecg-section";
|
||||
import { useEcgList } from "@/components/insights/use-ecg-list";
|
||||
|
||||
/**
|
||||
* v1.30 — `/insights/ecg` (UX/IA audit finding H1).
|
||||
@@ -39,11 +37,8 @@ export default function InsightsEcgPage() {
|
||||
// Reuse the SAME query cell `<EcgSection>` reads (`insightsEcgList`) so the
|
||||
// page and the section share one cache entry. The page only needs the
|
||||
// `hasRecordings` flag to choose between the empty state and the section.
|
||||
const { data, isLoading, isError, error, refetch } = useQuery({
|
||||
queryKey: queryKeys.insightsEcgList(),
|
||||
queryFn: () => apiGet<{ hasRecordings: boolean }>("/api/insights/ecg"),
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
const { data: page, isLoading, isError, error, refetch } = useEcgList();
|
||||
const data = page?.data;
|
||||
|
||||
// A read failure must be visible, not a heading over an empty body that
|
||||
// reads the same as "still loading" (§6). The section teaser below unmounts
|
||||
|
||||
Reference in new issue
Block a user