Merge branch 'release/v1.47.3' into release/v1.47.4

# Conflicts:
#	src/__tests__/baselines/source-file-lines.json
#	src/__tests__/baselines/source-function-lines.json
#	src/__tests__/baselines/test-as-never.json
#	src/__tests__/baselines/version-stamp-comments.json
This commit is contained in:
Marc-André Bombeck committed 2026-11-12 13:27:52 +01:00
commit 031379d966
384 files changed
+7908 -5710

No files matched your search

@@ -1,7 +1,12 @@
import { describe, it, expect, vi } from "vitest";
import type { QueryClient } from "@tanstack/react-query";
import { QueryClient, QueryObserver } from "@tanstack/react-query";
import { invalidateReminderReads } from "@/hooks/use-measurement-reminders";
import {
invalidateReminderReads,
putReminderRow,
type MeasurementReminder,
} from "@/hooks/use-measurement-reminders";
import { queryKeys } from "@/lib/query-keys";
/**
* v1.32.19 — a Vorsorge reminder marked done (or created / edited / deleted)
@@ -16,6 +21,7 @@ import { invalidateReminderReads } from "@/hooks/use-measurement-reminders";
function fakeQueryClient(): QueryClient {
return {
invalidateQueries: vi.fn().mockResolvedValue(undefined),
getQueryCache: () => ({ findAll: () => [] }),
} as unknown as QueryClient;
}
@@ -47,4 +53,45 @@ describe("invalidateReminderReads — the Vorsorge daily-rail freshness contract
expect(inactiveKeys).toContain(JSON.stringify(["dashboard", "snapshot"]));
expect(inactiveKeys).toContain(JSON.stringify(["daily", "digest"]));
});
it("refetches the Today rail while it is on screen", async () => {
// The dashboard: the check-up tile and the Today rail are both mounted,
// where the inactive pass alone fetches nothing.
const client = new QueryClient({
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
});
let reads = 0;
const observer = new QueryObserver(client, {
queryKey: queryKeys.dailyDigest(),
queryFn: async () => ++reads,
});
const unsubscribe = observer.subscribe(() => {});
await vi.waitFor(() => expect(reads).toBe(1));
await invalidateReminderReads(client);
expect(reads).toBe(2);
unsubscribe();
client.clear();
});
});
describe("putReminderRow", () => {
it("shows the answered row at once, so it no longer reads as due", () => {
const client = new QueryClient();
const due = {
id: "r1",
nextDueAt: "2026-11-11T08:00:00.000Z",
} as MeasurementReminder;
const other = { id: "r2" } as MeasurementReminder;
client.setQueryData(queryKeys.measurementReminders(), [due, other]);
const done = { ...due, nextDueAt: "2027-11-11T08:00:00.000Z" };
putReminderRow(client, done);
expect(client.getQueryData(queryKeys.measurementReminders())).toEqual([
done,
other,
]);
});
});
+16 -4
View File
@@ -26,6 +26,7 @@ import {
apiPatch,
apiPost,
} from "@/lib/api/api-fetch";
import { useIdempotentPost } from "@/lib/api/use-idempotent-post";
import { invalidateReminderReads } from "@/hooks/use-measurement-reminders";
import {
encounterDependentKeys,
@@ -166,17 +167,20 @@ export function useEncounterMutations() {
*
* So the fan-out is the visit roots PLUS the reminder reads, through the same
* helper the Vorsorge surfaces use, rather than a second sweep that could
* drift from it.
* drift from it. Not returned: a mutation would wait for every refetch
* before it settles, and the sheet would stay open until then.
*/
const invalidate = () =>
Promise.all([
void Promise.all([
invalidateKeys(qc, encounterDependentKeys),
invalidateReminderReads(qc),
]);
// One key for as long as the sheet that mounts this is open.
const post = useIdempotentPost();
const create = useMutation({
mutationKey: queryKeys.encounterCreate(),
mutationFn: (body: EncounterWriteBody) => apiPost<Encounter>(BASE, body),
mutationFn: (body: EncounterWriteBody) => post<Encounter>(BASE, body),
onSuccess: invalidate,
});
@@ -194,5 +198,13 @@ export function useEncounterMutations() {
onSuccess: invalidate,
});
return { create, update, remove };
// The Undo of a delete. A restored visit re-anchors its reminder only
// while its date is still ahead.
const restore = useMutation({
mutationKey: queryKeys.encounterRestore(),
mutationFn: (id: string) => apiPost<Encounter>(`${BASE}/${id}/restore`, {}),
onSuccess: invalidate,
});
return { create, update, remove, restore };
}
+41 -7
View File
@@ -17,7 +17,11 @@ import {
} from "@tanstack/react-query";
import { apiDelete, apiGet, apiPatch, apiPost } from "@/lib/api/api-fetch";
import { queryKeys, refetchInactiveDailyReads } from "@/lib/query-keys";
import {
invalidateKeys,
queryKeys,
refetchInactiveDailyReads,
} from "@/lib/query-keys";
/**
* v1.32.19 — the read fan-out every Vorsorge reminder mutation runs on
@@ -31,11 +35,21 @@ import { queryKeys, refetchInactiveDailyReads } from "@/lib/query-keys";
* (`refetchOnMount: false`) — the reminder lingered on the Today rail until
* the 120 s poll. Force the inactive daily reads to refetch alongside the
* reminders invalidation so the rail clears at once, the same freshness
* contract the medication intake surfaces use.
* contract the medication intake surfaces use. The inactive pass fetches
* nothing for a read that is on screen, though: marked done from the
* dashboard tile, the check-up stayed due on the Today rail above it. So
* the two daily reads are invalidated the ordinary way as well, which
* refetches them where they are mounted. A check-up marked done is also
* listed on its day.
*/
export function invalidateReminderReads(qc: QueryClient): Promise<unknown> {
return Promise.all([
qc.invalidateQueries({ queryKey: queryKeys.measurementReminders() }),
invalidateKeys(qc, [
queryKeys.measurementReminders(),
queryKeys.dailyDigest(),
queryKeys.dashboardSnapshot(),
queryKeys.dayRoot(),
]),
refetchInactiveDailyReads(qc),
]);
}
@@ -101,9 +115,29 @@ export function useMeasurementReminders(enabled = true) {
});
}
/**
* Write the row a satisfy, skip or snooze answered with into the cached list.
* The button re-enables as the call settles, and with only the refetch behind
* it the row still read as due, so a second tap marked it done twice.
*/
export function putReminderRow(
qc: QueryClient,
reminder: MeasurementReminder,
): void {
qc.setQueryData<MeasurementReminder[]>(
queryKeys.measurementReminders(),
(rows) => rows?.map((row) => (row.id === reminder.id ? reminder : row)),
);
}
export function useMeasurementReminderMutations() {
const qc = useQueryClient();
const invalidate = () => invalidateReminderReads(qc);
// Not returned: a mutation would wait for every refetch before it settles.
const invalidate = () => void invalidateReminderReads(qc);
const answered = (reminder: MeasurementReminder) => {
putReminderRow(qc, reminder);
invalidate();
};
const create = useMutation({
mutationKey: queryKeys.measurementReminderCreate(),
@@ -135,7 +169,7 @@ export function useMeasurementReminderMutations() {
mutationKey: queryKeys.measurementReminderSatisfy(),
mutationFn: (id: string) =>
apiPost<MeasurementReminder>(`${BASE}/${id}/satisfy`),
onSuccess: invalidate,
onSuccess: answered,
});
// v1.37.20 (#223) — honest skip: the interval restarts from the skip
@@ -146,7 +180,7 @@ export function useMeasurementReminderMutations() {
apiPost<{ skipped: boolean; reminder: MeasurementReminder }>(
`${BASE}/${id}/skip`,
),
onSuccess: invalidate,
onSuccess: ({ reminder }) => answered(reminder),
});
// v1.37.20 (#223) — snooze to a calendar day; the server resolves it to
@@ -157,7 +191,7 @@ export function useMeasurementReminderMutations() {
apiPost<{ reminder: MeasurementReminder }>(`${BASE}/${id}/snooze`, {
until,
}),
onSuccess: invalidate,
onSuccess: ({ reminder }) => answered(reminder),
});
return { create, update, remove, satisfy, skip, snooze };
+17 -5
View File
@@ -11,6 +11,7 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiDelete, apiGetList, apiPatch, apiPost } from "@/lib/api/api-fetch";
import { useIdempotentPost } from "@/lib/api/use-idempotent-post";
import {
encounterDependentKeys,
invalidateKeys,
@@ -62,17 +63,19 @@ export function usePractitionerMutations() {
const qc = useQueryClient();
// Renaming a practice changes the label a rail appointment renders under,
// and the daily reads are unmounted from the address book — pair the
// bundle invalidation with the forced inactive refetch.
// bundle invalidation with the forced inactive refetch. Not returned, so the
// sheet closes without waiting for the refetches.
const invalidate = () =>
Promise.all([
void Promise.all([
invalidateKeys(qc, encounterDependentKeys),
refetchInactiveDailyReads(qc),
]);
// One key for as long as the sheet that mounts this is open.
const post = useIdempotentPost();
const create = useMutation({
mutationKey: queryKeys.practitionerCreate(),
mutationFn: (body: PractitionerWriteBody) =>
apiPost<Practitioner>(BASE, body),
mutationFn: (body: PractitionerWriteBody) => post<Practitioner>(BASE, body),
onSuccess: invalidate,
});
@@ -90,5 +93,14 @@ export function usePractitionerMutations() {
onSuccess: invalidate,
});
return { create, update, remove };
// The Undo of a delete. It brings the entry back, not the links the
// delete cleared on the visits that named it.
const restore = useMutation({
mutationKey: queryKeys.practitionerRestore(),
mutationFn: (id: string) =>
apiPost<Practitioner>(`${BASE}/${id}/restore`, {}),
onSuccess: invalidate,
});
return { create, update, remove, restore };
}