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:
Marc-André Bombeck committed 2026-10-20 10:04:11 +02:00
1 parent be79603d53
commit dc5120b59a
49 files changed
+574 -204

No files matched your search

@@ -32,7 +32,10 @@ function render(node: React.ReactNode, locale: "en" | "de" = "en") {
// Seed the embedded session + trusted-device + activity reads so the
// assembled cards paint without firing network.
client.setQueryData(queryKeys.sessions(), { sessions: [] });
client.setQueryData(queryKeys.securityActivity(), { events: [] });
client.setQueryData(queryKeys.securityActivity(), {
data: { events: [] },
cap: null,
});
// Seed a trusted device so the card paints (it hides itself when empty).
client.setQueryData(queryKeys.trustedDevices(), {
devices: [
@@ -80,7 +83,10 @@ describe("<PrivacySection> — assembled Data & Privacy dashboard", () => {
},
});
client.setQueryData(queryKeys.sessions(), { sessions: [] });
client.setQueryData(queryKeys.securityActivity(), { events: [] });
client.setQueryData(queryKeys.securityActivity(), {
data: { events: [] },
cap: null,
});
client.setQueryData(queryKeys.trustedDevices(), { devices: [] });
const html = renderToStaticMarkup(
<I18nProvider initialLocale="en">
@@ -32,7 +32,9 @@ function grantList(partial: Partial<GrantList> = {}): GrantList {
return { given: [], received: [], retentionDays: 365, ...partial };
}
const activityRef: { value: RecordActivity | undefined } = { value: undefined };
const activityRef: {
value: (RecordActivity & { cap: ListCap | null }) | undefined;
} = { value: undefined };
vi.mock("@/lib/queries/use-account-grants", async (importOriginal) => {
const actual =
@@ -64,6 +66,7 @@ vi.mock("@/hooks/use-account-switch", () => ({
import { GrantsGivenCard } from "../grants-given-card";
import { GrantsReceivedCard } from "../grants-received-card";
import { RecordActivityCard } from "../record-activity-card";
import type { ListCap } from "@/lib/api/list-cap-shape";
function render(node: React.ReactNode): string {
return renderToStaticMarkup(
@@ -205,7 +208,7 @@ describe("when my record was opened", () => {
// see would imply a completeness it does not have: somebody checking last
// spring would read an empty list as "no" when the honest answer is
// "further back than this reaches".
activityRef.value = { entries: [], retentionDays: 90, truncated: false };
activityRef.value = { entries: [], retentionDays: 90, cap: null };
const html = render(<RecordActivityCard />);
expect(html).toContain('data-slot="record-activity-retention"');
expect(html).toContain("last 90 days");
@@ -215,22 +218,26 @@ describe("when my record was opened", () => {
// The second completeness claim. The window bounds how far back; the row
// cap bounds how many, and a list that stopped at its ceiling in silence
// let the oldest visible line read as the beginning.
activityRef.value = { entries: [], retentionDays: 365, truncated: true };
activityRef.value = {
entries: [],
retentionDays: 365,
cap: { truncated: true, limit: 100 },
};
const capped = render(<RecordActivityCard />);
expect(capped).toContain('data-slot="record-activity-truncated"');
expect(capped).toContain("most recent activity");
expect(capped).toContain('data-slot="list-cap-notice"');
expect(capped).toContain("Showing the latest 100");
// And it is not an unconditional hedge: a caveat that is always on is one
// people learn to skip, which would cost the sentence its meaning on the
// one screen where it is true.
activityRef.value = { entries: [], retentionDays: 365, truncated: false };
activityRef.value = { entries: [], retentionDays: 365, cap: null };
const whole = render(<RecordActivityCard />);
expect(whole).not.toContain('data-slot="record-activity-truncated"');
expect(whole).not.toContain('data-slot="list-cap-notice"');
expect(whole).toContain('data-slot="record-activity-retention"');
});
it("prints the operator's window, never a compiled-in 365", () => {
activityRef.value = { entries: [], retentionDays: 30, truncated: false };
activityRef.value = { entries: [], retentionDays: 30, cap: null };
const html = render(<RecordActivityCard />);
expect(html).toContain("last 30 days");
expect(html).not.toContain("365");
@@ -247,7 +254,7 @@ describe("when my record was opened", () => {
it("counts the openings rather than listing them one by one", () => {
activityRef.value = {
retentionDays: 365,
truncated: false,
cap: null,
entries: [
{
id: "a1",
@@ -270,7 +277,7 @@ describe("when my record was opened", () => {
// it themselves.
activityRef.value = {
retentionDays: 365,
truncated: false,
cap: null,
entries: [
{
id: "a2",
@@ -285,3 +292,19 @@ describe("when my record was opened", () => {
expect(html).toContain("A deleted account");
});
});
describe("grant lists at their ceiling", () => {
it("say so under the list, and only when the server cut it", () => {
grantsRef.value = {
...grantList({ given: [BASE] }),
cap: { truncated: true, limit: 100 },
} as GrantList;
expect(render(<GrantsGivenCard />)).toContain(
'data-slot="list-cap-notice"',
);
grantsRef.value = grantList({ given: [BASE] });
expect(render(<GrantsGivenCard />)).not.toContain(
'data-slot="list-cap-notice"',
);
});
});
@@ -19,6 +19,7 @@ import {
useRevokeGrant,
type GrantRow,
} from "@/lib/queries/use-account-grants";
import { ListCapNotice } from "@/components/ui/list-cap-notice";
/**
* v1.36.0 — who can open this record.
@@ -87,6 +88,7 @@ export function GrantsGivenCard() {
))}
</ul>
)}
<ListCapNotice cap={data?.cap} />
</div>
</SettingsCard>
);
@@ -23,6 +23,7 @@ import {
useRenounceGrant,
type GrantRow,
} from "@/lib/queries/use-account-grants";
import { ListCapNotice } from "@/components/ui/list-cap-notice";
/**
* v1.36.0 — the records this account has been offered, and the ones it holds.
@@ -110,6 +111,7 @@ export function GrantsReceivedCard() {
))}
</ul>
)}
<ListCapNotice cap={data?.cap} />
</div>
</SettingsCard>
);
@@ -13,6 +13,7 @@ import {
useRecordActivity,
type RecordActivityEntry,
} from "@/lib/queries/use-account-grants";
import { ListCapNotice } from "@/components/ui/list-cap-notice";
/**
* v1.36.0 — when this record was opened, and by whom.
@@ -63,22 +64,12 @@ export function RecordActivityCard() {
{t("recordSharing.activity.retention", {
days: data.retentionDays,
})}
{/* The second completeness claim. The window says how far back
this can see; the cap says how many rows came back, and a list
that stopped at its ceiling without saying so lets the oldest
line read as the beginning. Rendered only when the ceiling was
actually hit — an unconditional hedge would teach people to
ignore it. */}
{data.truncated && (
<>
{" "}
<span data-slot="record-activity-truncated">
{t("recordSharing.activity.truncated")}
</span>
</>
)}
</p>
)}
{/* The second completeness claim: the window says how far back this
can see, the cap how many rows came back. Rendered only when the
ceiling was actually hit. */}
<ListCapNotice cap={data?.cap} />
{isLoading && (
<Loader2
@@ -18,8 +18,9 @@ import { EmptyState } from "@/components/ui/empty-state";
import { QueryErrorRow } from "@/components/ui/query-error-row";
import { useTranslations, useFormatters } from "@/lib/i18n/context";
import { queryKeys } from "@/lib/query-keys";
import { apiGet } from "@/lib/api/api-fetch";
import { apiGetList } from "@/lib/api/api-fetch";
import { cn } from "@/lib/utils";
import { ListCapNotice } from "@/components/ui/list-cap-notice";
interface ActivityRow {
action: string;
@@ -68,14 +69,20 @@ export function SecurityActivityCard({
const [open, setOpen] = useState(false);
const regionId = useId();
const { data, isLoading, isError, error, refetch } = useQuery({
const {
data: page,
isLoading,
isError,
error,
refetch,
} = useQuery({
queryKey: queryKeys.securityActivity(),
queryFn: () =>
apiGet<{ events: ActivityRow[] }>("/api/auth/me/security-activity"),
apiGetList<{ events: ActivityRow[] }>("/api/auth/me/security-activity"),
enabled: isAuthenticated,
});
const events = data?.events ?? [];
const events = page?.data.events ?? [];
return (
<SettingsCard data-slot="settings-security-activity-card">
@@ -152,6 +159,7 @@ export function SecurityActivityCard({
))}
</ul>
)}
<ListCapNotice cap={page?.cap} />
</div>
</SettingsCard>
);