refactor(day): share one window for date-only columns

The day view, the day index and the visit preparation each built the
UTC calendar window for a date-only column by hand (documents had a
fourth copy). `dateOnlyWindow()` beside the other date-only helpers
replaces them. The report name select becomes one spread, the share
page builds its calendar formatter outside the view, and the PDF
section reads it off the context, so the functions these fixes touched
stay within their size budget; `DocumentRecordLinks` drops under it.
This commit is contained in:
Marc-André Bombeck committed 2026-11-11 20:12:44 +01:00
1 parent bdfecfa70e
commit da671f74aa
12 files changed
+90 -74

No files matched your search

+11 -6
View File
@@ -134,6 +134,15 @@ interface ClinicianViewProps {
dateFormat: DateFormatPreference;
}
/**
* A date-only value (a date of birth, a dose date) as its calendar date in
* the owner's date order, the same in every zone. Read as an instant in the
* owner's zone it fell on the previous day west of UTC.
*/
function calendarDateIn(dateFormat: DateFormatPreference, locale: Locale) {
return (iso: string) => formatDate(iso.slice(0, 10), dateFormat, locale);
}
export function ClinicianView({
t,
label,
@@ -154,10 +163,6 @@ export function ClinicianView({
// Owner hour cycle + date order ride along (issue #922).
const fmt = makeFormatters(locale, timezone, timeFormat, dateFormat);
const fmtDate = (iso: string) => fmt.date(new Date(iso));
// A date-only value (a date of birth, a dose date) is its calendar date in
// every zone; read as an instant it fell on the previous day west of UTC.
const fmtCalendarDate = (iso: string) =>
formatDate(iso.slice(0, 10), dateFormat, locale);
const fmtDateTime = (iso: string) => fmt.dateTime(new Date(iso));
// Two decimals at most, in the owner's locale: a German reader gets
// "80,5", not the "80.5" a bare number prints.
@@ -204,7 +209,7 @@ export function ClinicianView({
t={t}
report={report}
scope={scope}
fmtCalendarDate={fmtCalendarDate}
fmtCalendarDate={calendarDateIn(dateFormat, locale)}
/>
{/* ── measurements ─────────────────────────────────────── */}
@@ -303,7 +308,7 @@ export function ClinicianView({
t={t}
report={report}
scope={scope}
fmtCalendarDate={fmtCalendarDate}
fmtCalendarDate={calendarDateIn(dateFormat, locale)}
/>
<AllergiesSection t={t} report={report} scope={scope} />
@@ -188,10 +188,7 @@ export function DocumentRecordLinks({
const [visitIds, setVisitIds] = useState<string[] | null>(null);
const [doseIds, setDoseIds] = useState<string[] | null>(null);
const labels = {
suggested: t("links.picker.suggested"),
date: (iso: string) => format.date(iso),
};
const suggested = t("links.picker.suggested");
const visitOptions = recordOptions(
[...encounters.items]
@@ -205,9 +202,8 @@ export function DocumentRecordLinks({
href: visitHref(visit.id),
})),
anchor,
labels,
{ suggested, date: format.date },
);
// A dose date is a calendar date at UTC midnight, never an instant.
const doseOptions = recordOptions(
(vaccinations.data?.vaccinations ?? []).map((dose) => ({
id: dose.id,
@@ -216,7 +212,7 @@ export function DocumentRecordLinks({
href: doseHref(dose.id),
})),
anchor,
{ ...labels, date: calendarDate },
{ suggested, date: calendarDate }, // a dose date is a calendar date
);
const showDoses = vaccinationsOn && doc.vaccinationLinks !== null;