Give the caregiver a front door and a receipt

Sharing lived in a settings panel and a menu three levels deep. That is where
a grant is managed and not where it is used: somebody who opens this app every
morning to check on a parent does not go through settings to do it, and the
design standards draw the same line, settings being account utilities rather
than feature destinations. So the dashboard carries one compact card listing
the records shared with this account, each row a one-tap switch through the
existing flow.

It is a doorway and not a preview. No numbers, no last reading. A slice of
somebody else's record on the delegate's own dashboard would sit outside the
one frame the design leans on, the banner naming the record you are inside.
An account nobody has shared with sees nothing at all.

The other half is the receipt: a reading, a lab result or a dose recorded
under a switch now says which record it landed in, because "Saved" alone is
the confirmation somebody acting for another person does not need. The undo
on the dose toast goes at the same time, since a delegate cannot remove what
they recorded and an undo they can see is one the server refuses.

Also here: the lines the owner's activity view owes each admitted verb, as a
translated mapping with a fallback, so a later release filing a verb it has
never heard of still renders a sentence rather than a blank row.
This commit is contained in:
Marc-André Bombeck committed 2026-08-03 12:12:08 +02:00
1 parent ab53d42874
commit d5a9360c52
14 files changed
+604 -10

No files matched your search

@@ -0,0 +1,77 @@
/**
* The owner's ledger says what was done, not that something was.
*
* Mutation checks, run:
* - drop the `medications.intake.update` case → "each admitted verb has its
* own line" goes red on that action.
* - make the default arm throw instead of falling back → "an action this
* release has never heard of still renders" goes red.
*/
import { describe, expect, it } from "vitest";
import enMessages from "../../../../messages/en.json";
import { recordActivityVerbLine } from "../activity-verb";
/** Resolve a dotted key against the real EN bundle, params interpolated. */
function translate(
key: string,
params?: Record<string, string | number>,
): string {
const value = key
.split(".")
.reduce<unknown>(
(node, part) =>
node && typeof node === "object"
? (node as Record<string, unknown>)[part]
: undefined,
enMessages,
);
if (typeof value !== "string") throw new Error(`missing key: ${key}`);
return Object.entries(params ?? {}).reduce(
(text, [k, v]) => text.replaceAll(`{${k}}`, String(v)),
value,
);
}
/**
* Every action the eleven admitted write verbs can file, with the audit
* strings the handlers actually pass to `auditLog()`.
*/
const ADMITTED_ACTIONS = [
"measurement.create",
"labResult.create",
"allergy.create",
"family-history.create",
"illness.episode.create",
"biomarker.create",
"customMetricEntry.create",
"medication.sideEffect.create",
"medication.create",
"medications.intake.update",
] as const;
describe("recordActivityVerbLine", () => {
it("each admitted verb has its own line", () => {
const generic = translate("recordSharing.activity.acted", { name: "Anna" });
const lines = ADMITTED_ACTIONS.map((action) =>
recordActivityVerbLine(translate, action, "Anna"),
);
for (const line of lines) {
// The point of the map: none of them may fall through to "made a
// change", which is the line the owner already had.
expect(line).not.toBe(generic);
expect(line).toContain("Anna");
}
// And no two verbs share a line — a map that answered "added something"
// ten times would pass the check above and say nothing.
expect(new Set(lines).size).toBe(ADMITTED_ACTIONS.length);
});
it("an action this release has never heard of still renders", () => {
// Audit rows outlive this map: a later release files verbs it does not
// know, and older rows sit in the same table. Vague beats blank.
expect(
recordActivityVerbLine(translate, "future.thing.create", "Anna"),
).toBe(translate("recordSharing.activity.acted", { name: "Anna" }));
});
});
+62
View File
@@ -0,0 +1,62 @@
/** The `t` from `useTranslations()`, injected so this stays pure. */
type Translator = (
key: string,
params?: Record<string, string | number>,
) => string;
/**
* What somebody did in your record, in a sentence.
*
* ## Why this exists
*
* The activity view renders every non-read row as one generic line: "somebody
* made a change in your record". That was honest while sharing was read-only
* and no delegate could make one. Now a delegate can enter a reading, a lab
* result, an allergy, a family-history entry, an illness entry, a biomarker,
* a tracked value, a side effect, a medication, and can mark a dose taken —
* and "made a change" for ten different things is a way of answering nothing.
* An owner reading this at breakfast wants the verb.
*
* ## Why unknown actions fall back rather than fail
*
* The action string comes from the audit row, which outlives this map: a
* release that admits a twelfth verb writes rows this map has never heard of,
* and rows written by an older image sit in the same table. So an unmapped
* action renders the generic line it renders today. A blank row would be the
* one outcome worse than a vague one.
*
* Pure and translator-injected so the mapping can be pinned without rendering
* a card, and so the keys stay literal for the i18n call-site guard.
*/
export function recordActivityVerbLine(
t: Translator,
action: string,
name: string,
): string {
switch (action) {
case "measurement.create":
return t("recordSharing.activityVerb.measurementCreate", { name });
case "labResult.create":
return t("recordSharing.activityVerb.labResultCreate", { name });
case "allergy.create":
return t("recordSharing.activityVerb.allergyCreate", { name });
case "family-history.create":
return t("recordSharing.activityVerb.familyHistoryCreate", { name });
case "illness.episode.create":
return t("recordSharing.activityVerb.illnessEpisodeCreate", { name });
case "biomarker.create":
return t("recordSharing.activityVerb.biomarkerCreate", { name });
case "customMetricEntry.create":
return t("recordSharing.activityVerb.customMetricEntryCreate", { name });
case "medication.sideEffect.create":
return t("recordSharing.activityVerb.medicationSideEffectCreate", {
name,
});
case "medication.create":
return t("recordSharing.activityVerb.medicationCreate", { name });
case "medications.intake.update":
return t("recordSharing.activityVerb.medicationIntake", { name });
default:
return t("recordSharing.activity.acted", { name });
}
}