mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
Merge pull request #1071 from MBombeck/fix/v1397-mobile
Make the signed-in app work on a phone, starting with lab results
This commit is contained in:
19 files changed
+902
-143
No files matched your search
@@ -61,6 +61,8 @@ interface DialogCase {
|
||||
prepare?: (page: import("@playwright/test").Page) => Promise<void>;
|
||||
/** Something inside the dialog that proves it rendered its form, not a shell. */
|
||||
ready: string;
|
||||
/** Render in this locale instead of the suite's pinned English. */
|
||||
locale?: "de";
|
||||
}
|
||||
|
||||
const DIALOGS: DialogCase[] = [
|
||||
@@ -92,11 +94,23 @@ const DIALOGS: DialogCase[] = [
|
||||
trigger: /^add$/i,
|
||||
ready: '[data-slot="date-time-field"]',
|
||||
},
|
||||
// The labs sheet's footer holds three buttons (Cancel, Save & add another,
|
||||
// Save). They fit a phone row in English; the German labels are ~100px
|
||||
// wider and pushed Cancel off the sheet's left edge, at every width.
|
||||
{
|
||||
name: "labs add (German)",
|
||||
path: "/labs",
|
||||
trigger: /^hinzufügen$/i,
|
||||
ready: '[data-slot="date-time-field"]',
|
||||
locale: "de",
|
||||
},
|
||||
];
|
||||
|
||||
const VIEWPORTS = [
|
||||
{ label: "desktop 1280", width: 1280, height: 800 },
|
||||
{ label: "phone 390", width: 390, height: 844 },
|
||||
// The narrowest common Android width.
|
||||
{ label: "phone 360", width: 360, height: 780 },
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -200,7 +214,17 @@ test.describe("add/edit dialogs do not scroll sideways", () => {
|
||||
for (const dialog of DIALOGS) {
|
||||
test(`${dialog.name} fits its surface at ${vp.label}`, async ({
|
||||
page,
|
||||
}) => {
|
||||
context,
|
||||
}, testInfo) => {
|
||||
if (dialog.locale) {
|
||||
await context.addCookies([
|
||||
{
|
||||
name: "healthlog-locale",
|
||||
value: dialog.locale,
|
||||
url: testInfo.project.use.baseURL ?? "http://localhost:3000",
|
||||
},
|
||||
]);
|
||||
}
|
||||
await page.setViewportSize({ width: vp.width, height: vp.height });
|
||||
await page.goto(dialog.path, { waitUntil: "domcontentloaded" });
|
||||
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
import { readdirSync, statSync } from "node:fs";
|
||||
import { join, relative, sep } from "node:path";
|
||||
|
||||
import type { APIRequestContext } from "@playwright/test";
|
||||
|
||||
import { ADMIN_SECTION_SLUGS } from "@/components/admin/section-slugs";
|
||||
import { SETTINGS_SECTION_SLUGS } from "@/components/settings/section-slugs";
|
||||
|
||||
import { expect, test } from "./setup/test";
|
||||
import { MOBILE_ROUTES_STORAGE_STATE_PATH } from "./setup/global-setup";
|
||||
import { MOBILE_ROUTES_ANALYTE } from "./setup/mobile-routes-fixture";
|
||||
import {
|
||||
expectNoHorizontalOverflow,
|
||||
settleForOverflowMeasurement,
|
||||
} from "./utils/horizontal-overflow";
|
||||
|
||||
/**
|
||||
* Every signed-in route, at an iPhone width, does not scroll sideways.
|
||||
*
|
||||
* `mobile-horizontal-overflow.spec.ts` sweeps five widths over four
|
||||
* content-heavy routes. This file is the breadth half: one width, every route.
|
||||
* It exists because the lab list panned sideways on a phone for weeks while
|
||||
* the guard was green — `/labs` was simply not on the list. A hand-kept list
|
||||
* goes stale the day a route is added, so the routes here are read from
|
||||
* `src/app` itself, and a route this file cannot open fails the run instead of
|
||||
* dropping out silently:
|
||||
*
|
||||
* - a static route is visited as is;
|
||||
* - a dynamic route needs an entry in `DYNAMIC_ROUTES` that turns its
|
||||
* segments into concrete paths (a settings slug, a seeded record's id);
|
||||
* - a route that cannot be swept signed in (auth, invitation, public
|
||||
* share-link pages) is listed in `NOT_SIGNED_IN` with its reason.
|
||||
*
|
||||
* The account is `E2E_MOBILE_ROUTES`, which `globalSetup` fills with one or
|
||||
* two of everything (`mobile-routes-fixture.ts`): an empty page fits any
|
||||
* viewport and would prove nothing. It renders in German, the locale with the
|
||||
* longest common strings, and at 390 px — the iPhone width the lab list broke
|
||||
* at.
|
||||
*/
|
||||
|
||||
const APP_DIR = join(process.cwd(), "src", "app");
|
||||
const WIDTH = 390;
|
||||
|
||||
/** Route patterns that are not signed-in surfaces, and why. */
|
||||
const NOT_SIGNED_IN: Record<string, string> = {
|
||||
"/auth/login": "the sign-in page; a session redirects away from it",
|
||||
"/auth/register": "registration; a session redirects away from it",
|
||||
"/invite/[token]":
|
||||
"an invitation landing page for somebody without an account",
|
||||
"/c/[token]": "the clinician share-link page, opened without a session",
|
||||
"/confirm-access": "the re-proof page, reached only from a stale session",
|
||||
"/enroll-mfa": "the forced second-factor enrolment of a policy-bound account",
|
||||
"/onboarding": "the first-run setup flow; covered by setup-flow-*.spec.ts",
|
||||
"/onboarding/[step]":
|
||||
"the first-run setup flow; covered by setup-flow-*.spec.ts",
|
||||
};
|
||||
|
||||
type Resolver = (api: APIRequestContext) => Promise<string[]>;
|
||||
|
||||
async function readData<T>(api: APIRequestContext, path: string): Promise<T> {
|
||||
const res = await api.get(path);
|
||||
expect(res.ok(), `${path} answered ${res.status()}`).toBe(true);
|
||||
return ((await res.json()) as { data: T }).data;
|
||||
}
|
||||
|
||||
const firstId = (ids: Array<string | null | undefined>, what: string) => {
|
||||
const id = ids.find((value): value is string => Boolean(value));
|
||||
if (!id)
|
||||
throw new Error(`the fixture holds no ${what} — globalSetup seeds one`);
|
||||
return id;
|
||||
};
|
||||
|
||||
/** Every dynamic route pattern under `src/app`, turned into real paths. */
|
||||
const DYNAMIC_ROUTES: Record<string, Resolver> = {
|
||||
"/settings/[section]": async () =>
|
||||
SETTINGS_SECTION_SLUGS.map((slug) => `/settings/${slug}`),
|
||||
"/admin/[section]": async () =>
|
||||
ADMIN_SECTION_SLUGS.map((slug) => `/admin/${slug}`),
|
||||
// `LAYOUT_GROUP_IDS` lives beside React components the test runner cannot
|
||||
// load; `settings/layout/[module]` 404s an unknown group, so a stale entry
|
||||
// here fails on the status check below rather than passing quietly.
|
||||
"/settings/layout/[module]": async () =>
|
||||
[
|
||||
"dashboard",
|
||||
"insights",
|
||||
"medications",
|
||||
"mood",
|
||||
"labs",
|
||||
"illness",
|
||||
"vorsorge",
|
||||
].map((group) => `/settings/layout/${group}`),
|
||||
"/insights/scores/[metric]": async () =>
|
||||
["sleep", "readiness", "recovery", "stress", "strain"].map(
|
||||
(metric) => `/insights/scores/${metric}`,
|
||||
),
|
||||
"/insights/values/[type]": async () => [
|
||||
"/insights/values/WEIGHT",
|
||||
"/insights/values/BLOOD_PRESSURE_SYS",
|
||||
],
|
||||
"/labs/[biomarkerId]": async (api) => {
|
||||
const data = await readData<{
|
||||
results: Array<{ biomarkerId: string | null; analyte: string }>;
|
||||
}>(api, "/api/labs?limit=50");
|
||||
const id = firstId(
|
||||
data.results
|
||||
.filter((row) => row.analyte === MOBILE_ROUTES_ANALYTE)
|
||||
.map((row) => row.biomarkerId),
|
||||
"linked lab reading",
|
||||
);
|
||||
return [`/labs/${id}`];
|
||||
},
|
||||
"/labs/[biomarkerId]/values": async (api) =>
|
||||
(await DYNAMIC_ROUTES["/labs/[biomarkerId]"](api)).map(
|
||||
(path) => `${path}/values`,
|
||||
),
|
||||
"/medications/[id]": async (api) => {
|
||||
const meds = await readData<Array<{ id: string }>>(api, "/api/medications");
|
||||
return [
|
||||
`/medications/${firstId(
|
||||
meds.map((m) => m.id),
|
||||
"medication",
|
||||
)}`,
|
||||
];
|
||||
},
|
||||
"/medications/[id]/history": async (api) =>
|
||||
(await DYNAMIC_ROUTES["/medications/[id]"](api)).map(
|
||||
(path) => `${path}/history`,
|
||||
),
|
||||
"/illness/[id]": async (api) => {
|
||||
const episodes = await readData<Array<{ id: string }>>(
|
||||
api,
|
||||
"/api/illness/episodes",
|
||||
);
|
||||
return [
|
||||
`/illness/${firstId(
|
||||
episodes.map((e) => e.id),
|
||||
"illness episode",
|
||||
)}`,
|
||||
];
|
||||
},
|
||||
"/custom-metrics/[id]": async (api) => {
|
||||
const data = await readData<{ customMetrics: Array<{ id: string }> }>(
|
||||
api,
|
||||
"/api/custom-metrics",
|
||||
);
|
||||
const id = firstId(
|
||||
data.customMetrics.map((m) => m.id),
|
||||
"custom metric",
|
||||
);
|
||||
return [`/custom-metrics/${id}`];
|
||||
},
|
||||
"/custom-metrics/[id]/values": async (api) =>
|
||||
(await DYNAMIC_ROUTES["/custom-metrics/[id]"](api)).map(
|
||||
(path) => `${path}/values`,
|
||||
),
|
||||
"/insights/workouts/[id]": async (api) => {
|
||||
const data = await readData<{ workouts: Array<{ id: string }> }>(
|
||||
api,
|
||||
"/api/workouts?limit=1",
|
||||
);
|
||||
return [
|
||||
`/insights/workouts/${firstId(
|
||||
data.workouts.map((w) => w.id),
|
||||
"workout",
|
||||
)}`,
|
||||
];
|
||||
},
|
||||
// An ECG strip only arrives through a device sync; no route writes one. The
|
||||
// detail page is swept in its not-found state, which is still the frame,
|
||||
// header and back link a phone renders.
|
||||
"/insights/ecg/[id]": async () => ["/insights/ecg/unknown-recording"],
|
||||
};
|
||||
|
||||
/** Every `page.tsx` under `src/app`, as a route pattern (`/labs/[biomarkerId]`). */
|
||||
function discoverRoutePatterns(dir = APP_DIR): string[] {
|
||||
const patterns: string[] = [];
|
||||
for (const entry of readdirSync(dir)) {
|
||||
const full = join(dir, entry);
|
||||
if (statSync(full).isDirectory()) {
|
||||
if (entry === "api" || entry.startsWith("_") || entry === "__tests__")
|
||||
continue;
|
||||
patterns.push(...discoverRoutePatterns(full));
|
||||
} else if (entry === "page.tsx") {
|
||||
const rel = relative(APP_DIR, dir).split(sep).join("/");
|
||||
// Route groups `(name)` do not appear in the URL.
|
||||
const path = rel
|
||||
.split("/")
|
||||
.filter((segment) => segment && !/^\(.*\)$/.test(segment))
|
||||
.join("/");
|
||||
patterns.push(`/${path}`);
|
||||
}
|
||||
}
|
||||
return patterns.sort();
|
||||
}
|
||||
|
||||
const PATTERNS = discoverRoutePatterns();
|
||||
const isDynamic = (pattern: string) => pattern.includes("[");
|
||||
|
||||
test.describe("every signed-in route fits a phone", () => {
|
||||
test.use({ storageState: MOBILE_ROUTES_STORAGE_STATE_PATH });
|
||||
|
||||
test.beforeEach(async ({ context }, testInfo) => {
|
||||
test.skip(testInfo.project.name !== "chromium-mobile", "mobile-only spec");
|
||||
const baseURL = testInfo.project.use.baseURL ?? "http://localhost:3000";
|
||||
await context.addCookies([
|
||||
{ name: "healthlog-locale", value: "de", url: baseURL },
|
||||
]);
|
||||
});
|
||||
|
||||
/**
|
||||
* The bookkeeping the sweep depends on. A new dynamic route without a
|
||||
* resolver, a resolver for a route that no longer exists, or an exclusion
|
||||
* for a route that is gone each fail here by name.
|
||||
*/
|
||||
test("the swept routes are the routes the app has", () => {
|
||||
expect(PATTERNS.length, "no page.tsx found under src/app").toBeGreaterThan(
|
||||
50,
|
||||
);
|
||||
const unresolved = PATTERNS.filter(
|
||||
(p) => isDynamic(p) && !NOT_SIGNED_IN[p] && !DYNAMIC_ROUTES[p],
|
||||
);
|
||||
expect(
|
||||
unresolved,
|
||||
"dynamic route(s) with no entry in DYNAMIC_ROUTES or NOT_SIGNED_IN",
|
||||
).toEqual([]);
|
||||
const stale = [
|
||||
...Object.keys(DYNAMIC_ROUTES),
|
||||
...Object.keys(NOT_SIGNED_IN),
|
||||
].filter((p) => !PATTERNS.includes(p));
|
||||
expect(stale, "entries for routes that no longer exist").toEqual([]);
|
||||
});
|
||||
|
||||
for (const pattern of PATTERNS) {
|
||||
if (NOT_SIGNED_IN[pattern]) continue;
|
||||
|
||||
test(`${pattern} does not scroll sideways at ${WIDTH}px`, async ({
|
||||
page,
|
||||
}) => {
|
||||
test.slow();
|
||||
const paths = isDynamic(pattern)
|
||||
? await DYNAMIC_ROUTES[pattern](page.request)
|
||||
: [pattern];
|
||||
expect(paths.length, `${pattern} resolved to no path`).toBeGreaterThan(0);
|
||||
|
||||
await page.setViewportSize({ width: WIDTH, height: 844 });
|
||||
for (const path of paths) {
|
||||
const response = await page.goto(path, {
|
||||
waitUntil: "domcontentloaded",
|
||||
});
|
||||
expect(
|
||||
response?.status() ?? 0,
|
||||
`${path} answered ${response?.status()}`,
|
||||
).toBeLessThan(400);
|
||||
// A redirect away (a module switched off, a missing record) would
|
||||
// measure some other page and call it this one.
|
||||
expect(new URL(page.url()).pathname, `${path} redirected`).toBe(
|
||||
new URL(path, page.url()).pathname,
|
||||
);
|
||||
await settleForOverflowMeasurement(page);
|
||||
await expectNoHorizontalOverflow(page, `${path} @${WIDTH}px`);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The lab surfaces, asserted at the elements that broke rather than only at
|
||||
* the page width. The list's name column collapsed to nothing on a phone
|
||||
* while the fixed columns beside it pushed the row off the card; the values
|
||||
* table put its edit and delete buttons in a sideways-scrolling strip.
|
||||
*/
|
||||
test.describe("the lab surfaces stay readable on a phone", () => {
|
||||
test.use({ storageState: MOBILE_ROUTES_STORAGE_STATE_PATH });
|
||||
|
||||
test.beforeEach(async ({ page }, testInfo) => {
|
||||
test.skip(testInfo.project.name !== "chromium-mobile", "mobile-only spec");
|
||||
await page.setViewportSize({ width: WIDTH, height: 844 });
|
||||
});
|
||||
|
||||
test("the lab list shows each marker's name", async ({ page }) => {
|
||||
await page.goto("/labs", { waitUntil: "domcontentloaded" });
|
||||
const names = page.locator('[data-slot="lab-list-analyte"]');
|
||||
await expect(names.first()).toBeVisible();
|
||||
const widths = await names.evaluateAll((nodes) =>
|
||||
nodes.map((node) => Math.round(node.getBoundingClientRect().width)),
|
||||
);
|
||||
expect(widths.length).toBeGreaterThan(1);
|
||||
// A readable name, not the 0 px column the fixed columns left it.
|
||||
for (const width of widths) expect(width).toBeGreaterThan(60);
|
||||
});
|
||||
|
||||
test("the values list keeps its actions on screen", async ({ page }) => {
|
||||
const [path] = await DYNAMIC_ROUTES["/labs/[biomarkerId]/values"](
|
||||
page.request,
|
||||
);
|
||||
await page.goto(path, { waitUntil: "domcontentloaded" });
|
||||
const list = page.locator('[data-slot="lab-history-mobile-list"]');
|
||||
await expect(list).toBeVisible();
|
||||
await expect(page.locator('[data-slot="lab-history-table"]')).toBeHidden();
|
||||
|
||||
const buttons = list.locator("button");
|
||||
expect(await buttons.count()).toBeGreaterThan(1);
|
||||
const outside = await buttons.evaluateAll(
|
||||
(nodes) =>
|
||||
nodes
|
||||
.map((node) => node.getBoundingClientRect())
|
||||
.filter((r) => r.left < 0 || r.right > window.innerWidth + 1).length,
|
||||
);
|
||||
expect(outside, "a reading's action sits off-screen").toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -33,6 +33,8 @@ import {
|
||||
} from "@playwright/test";
|
||||
import pg from "pg";
|
||||
|
||||
import { seedMobileRoutesRecord } from "./mobile-routes-fixture";
|
||||
|
||||
// Resolve relative to the project root rather than __dirname/import.meta.url —
|
||||
// Playwright's TS loader runs files as CJS without `"type":"module"`, and
|
||||
// loading either dirname helper at module scope crashes the test runner.
|
||||
@@ -191,6 +193,27 @@ export const MODULES_STORAGE_STATE_PATH = resolve(
|
||||
"e2e/setup/storageStateModules.json",
|
||||
);
|
||||
|
||||
/**
|
||||
* The phone-width route sweep's own account (`mobile-route-overflow.spec.ts`).
|
||||
*
|
||||
* It holds one or two of everything a route can render
|
||||
* (`mobile-routes-fixture.ts`), because the sweep is only worth something
|
||||
* against populated pages, and writing that much into the shared account would
|
||||
* change what every other spec reads. An administrator, so the admin console
|
||||
* is swept too; `FEMALE`, so the cycle surfaces render without a switch.
|
||||
*/
|
||||
export const E2E_MOBILE_ROUTES = {
|
||||
email: "e2e-mobile-routes@healthlog.test",
|
||||
username: "e2e-mobile-routes",
|
||||
password: "Wd7!Kp3mTz9qRv2N",
|
||||
role: "ADMIN",
|
||||
} as const;
|
||||
|
||||
export const MOBILE_ROUTES_STORAGE_STATE_PATH = resolve(
|
||||
process.cwd(),
|
||||
"e2e/setup/storageStateMobileRoutes.json",
|
||||
);
|
||||
|
||||
/**
|
||||
* The AI-optional journeys' own account (`ai-optional-*.spec.ts`).
|
||||
*
|
||||
@@ -823,6 +846,43 @@ export default async function globalSetup(config: FullConfig): Promise<void> {
|
||||
],
|
||||
);
|
||||
|
||||
// The phone-width route sweep's account. Every opt-in module is on, so
|
||||
// the sweep reaches the glucose, documents, wellbeing, nutrients and
|
||||
// environment surfaces; its record is written after the login capture.
|
||||
await pool.query(
|
||||
`INSERT INTO users
|
||||
(id, username, email, password_hash, role, created_at, updated_at,
|
||||
height_cm, date_of_birth, gender,
|
||||
onboarding_completed_at, onboarding_tour_completed,
|
||||
module_preferences_json)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $6, 168, $7, 'FEMALE', $6, true,
|
||||
$8::jsonb)
|
||||
ON CONFLICT (username) DO UPDATE SET
|
||||
email = EXCLUDED.email,
|
||||
password_hash = EXCLUDED.password_hash,
|
||||
role = EXCLUDED.role,
|
||||
updated_at = EXCLUDED.updated_at,
|
||||
onboarding_completed_at = EXCLUDED.onboarding_completed_at,
|
||||
onboarding_tour_completed = EXCLUDED.onboarding_tour_completed,
|
||||
module_preferences_json = EXCLUDED.module_preferences_json`,
|
||||
[
|
||||
cuid(),
|
||||
E2E_MOBILE_ROUTES.username,
|
||||
E2E_MOBILE_ROUTES.email,
|
||||
await hashPassword(E2E_MOBILE_ROUTES.password),
|
||||
E2E_MOBILE_ROUTES.role,
|
||||
now,
|
||||
new Date("1988-04-12T00:00:00.000Z"),
|
||||
JSON.stringify({
|
||||
glucose: true,
|
||||
environment: true,
|
||||
inboundDocuments: true,
|
||||
mentalHealth: true,
|
||||
nutrients: true,
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
||||
// The AI-optional journeys' account. Its provider, stored briefing,
|
||||
// consent and Coach rows are set by `e2e/setup/ai-optional-fixture.ts`
|
||||
// before each journey.
|
||||
@@ -1441,6 +1501,11 @@ export default async function globalSetup(config: FullConfig): Promise<void> {
|
||||
// The module-surfaces journey's jar — see `E2E_MODULES`.
|
||||
await capture(E2E_MODULES, MODULES_STORAGE_STATE_PATH);
|
||||
|
||||
// The phone-width route sweep's jar, then its record — see
|
||||
// `E2E_MOBILE_ROUTES`.
|
||||
await capture(E2E_MOBILE_ROUTES, MOBILE_ROUTES_STORAGE_STATE_PATH);
|
||||
await seedMobileRoutesRecord(baseURL, MOBILE_ROUTES_STORAGE_STATE_PATH);
|
||||
|
||||
// The AI-optional journeys' jar — see `E2E_AI_OPTIONAL`.
|
||||
await capture(E2E_AI_OPTIONAL, AI_OPTIONAL_STORAGE_STATE_PATH);
|
||||
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* The record `mobile-route-overflow.spec.ts` measures.
|
||||
*
|
||||
* A phone-width overflow guard that visits an empty page proves nothing: an
|
||||
* empty list fits any viewport, and the lab list that panned sideways on a
|
||||
* phone only did so once it held a reading. So the account gets one or two of
|
||||
* everything a signed-in route can render — readings with reference ranges, a
|
||||
* medication, a mood entry, a visit, a vaccination, an illness episode, a
|
||||
* custom metric, a workout, a document — and every dynamic route has a real id
|
||||
* to open.
|
||||
*
|
||||
* Written through the app's own routes, once, from `globalSetup`, so the
|
||||
* parallel workers of the spec never race each other to seed it. An account
|
||||
* that already holds a lab reading is taken as seeded, which keeps a local
|
||||
* re-run against a reused database from doubling every row.
|
||||
*/
|
||||
import { request as playwrightRequest } from "@playwright/test";
|
||||
|
||||
/** Long on purpose: the names are what a narrow column has to give way to. */
|
||||
export const MOBILE_ROUTES_ANALYTE = "Glomeruläre Filtrationsrate (eGFR)";
|
||||
|
||||
export async function seedMobileRoutesRecord(
|
||||
baseURL: string,
|
||||
storageStatePath: string,
|
||||
): Promise<void> {
|
||||
const ctx = await playwrightRequest.newContext({
|
||||
baseURL,
|
||||
storageState: storageStatePath,
|
||||
});
|
||||
try {
|
||||
// The document is the last thing written, so its presence means a
|
||||
// complete record. A run that died half-way is finished by the next one:
|
||||
// a row it already wrote answers 409 and is skipped.
|
||||
const existing = await ctx.get("/api/documents/inbound");
|
||||
const existingBody = (await existing.json()) as {
|
||||
data: { documents?: unknown[] } | unknown[] | null;
|
||||
};
|
||||
const documents = Array.isArray(existingBody.data)
|
||||
? existingBody.data
|
||||
: (existingBody.data?.documents ?? []);
|
||||
if (documents.length > 0) return;
|
||||
|
||||
const post = async (path: string, data: unknown): Promise<unknown> => {
|
||||
const res = await ctx.post(path, { data });
|
||||
if (res.status() === 409) return null;
|
||||
if (!res.ok()) {
|
||||
throw new Error(
|
||||
`[mobile-routes-fixture] ${path} answered ${res.status()}: ${(await res.text()).slice(0, 200)}`,
|
||||
);
|
||||
}
|
||||
return ((await res.json()) as { data: unknown }).data;
|
||||
};
|
||||
const daysAgo = (days: number, hour = 8) => {
|
||||
const at = new Date(Date.now() - days * 86_400_000);
|
||||
at.setUTCHours(hour, 0, 0, 0);
|
||||
return at.toISOString();
|
||||
};
|
||||
|
||||
for (let day = 1; day <= 6; day += 1) {
|
||||
await post("/api/measurements", {
|
||||
type: "WEIGHT",
|
||||
value: 80 + day / 10,
|
||||
measuredAt: daysAgo(day, 7),
|
||||
});
|
||||
await post("/api/measurements", {
|
||||
type: "BLOOD_PRESSURE_SYS",
|
||||
value: 120 + day,
|
||||
measuredAt: daysAgo(day, 7),
|
||||
});
|
||||
await post("/api/measurements", {
|
||||
type: "BLOOD_PRESSURE_DIA",
|
||||
value: 78 + (day % 3),
|
||||
measuredAt: daysAgo(day, 7),
|
||||
});
|
||||
await post("/api/measurements", {
|
||||
type: "PULSE",
|
||||
value: 60 + day,
|
||||
measuredAt: daysAgo(day, 7),
|
||||
});
|
||||
await post("/api/measurements", {
|
||||
type: "BLOOD_GLUCOSE",
|
||||
value: 92 + day,
|
||||
glucoseContext: "FASTING",
|
||||
measuredAt: daysAgo(day, 6),
|
||||
});
|
||||
await post("/api/mood-entries", {
|
||||
mood: day % 2 ? "GUT" : "OKAY",
|
||||
moodLoggedAt: daysAgo(day, 20),
|
||||
});
|
||||
}
|
||||
|
||||
// Two readings of one marker, so the list row has a trend line and a
|
||||
// range bar, plus a qualitative one with neither.
|
||||
for (const [days, value] of [
|
||||
[40, 78],
|
||||
[5, 84],
|
||||
] as const) {
|
||||
await post("/api/labs", {
|
||||
analyte: MOBILE_ROUTES_ANALYTE,
|
||||
panel: "Nierenwerte und Elektrolyte",
|
||||
value,
|
||||
unit: "mL/min/1.73m²",
|
||||
referenceLow: 60,
|
||||
referenceHigh: 120,
|
||||
takenAt: daysAgo(days),
|
||||
});
|
||||
}
|
||||
await post("/api/labs", {
|
||||
analyte: "Hepatitis-B-Oberflächenantigen",
|
||||
valueText: "negativ",
|
||||
takenAt: daysAgo(5),
|
||||
});
|
||||
|
||||
await post("/api/medications", {
|
||||
name: "Ramipril",
|
||||
dose: "5 mg",
|
||||
schedules: [{ windowStart: "08:00", windowEnd: "09:00" }],
|
||||
});
|
||||
|
||||
const practitioner = (await post("/api/practitioners", {
|
||||
name: "Gemeinschaftspraxis für Allgemeinmedizin",
|
||||
specialty: "Allgemeinmedizin und Innere Medizin",
|
||||
})) as { id: string } | null;
|
||||
await post("/api/encounters", {
|
||||
occurredAt: daysAgo(20),
|
||||
practitionerId: practitioner?.id ?? null,
|
||||
reason: "Routinekontrolle Blutdruck und Blutbild",
|
||||
});
|
||||
await post("/api/vaccinations", {
|
||||
occurredAt: daysAgo(300),
|
||||
antigenSlug: "tetanus",
|
||||
doseNumber: 1,
|
||||
lotNumber: "AB1234-XY",
|
||||
practitionerId: practitioner?.id ?? null,
|
||||
});
|
||||
|
||||
await post("/api/illness/episodes", {
|
||||
label: "Erkältung mit Husten",
|
||||
type: "INFECTION",
|
||||
onsetAt: daysAgo(12),
|
||||
resolvedAt: daysAgo(6),
|
||||
});
|
||||
|
||||
const metric = (await post("/api/custom-metrics", {
|
||||
name: "Augeninnendruck rechts",
|
||||
unit: "mmHg",
|
||||
targetLow: 10,
|
||||
targetHigh: 21,
|
||||
decimals: 0,
|
||||
})) as { id: string } | null;
|
||||
const metricId =
|
||||
metric?.id ??
|
||||
(
|
||||
(await (await ctx.get("/api/custom-metrics")).json()) as {
|
||||
data: { customMetrics: Array<{ id: string }> };
|
||||
}
|
||||
).data.customMetrics[0]?.id;
|
||||
await post(`/api/custom-metrics/${metricId}/entries`, {
|
||||
value: 16,
|
||||
measuredAt: daysAgo(3),
|
||||
});
|
||||
|
||||
await post("/api/workouts/batch", {
|
||||
workouts: [
|
||||
{
|
||||
sportType: "running",
|
||||
startedAt: daysAgo(2, 6),
|
||||
endedAt: new Date(
|
||||
new Date(daysAgo(2, 6)).getTime() + 45 * 60_000,
|
||||
).toISOString(),
|
||||
source: "APPLE_HEALTH",
|
||||
externalId: "e2e-mobile-routes-run",
|
||||
activeEnergyKcal: 420,
|
||||
distanceM: 6500,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const pdf =
|
||||
"%PDF-1.4\n%e2e-mobile-routes\n" +
|
||||
"1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj\n" +
|
||||
"2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj\n" +
|
||||
"3 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 200 200]>>endobj\n" +
|
||||
"xref\n0 4\ntrailer<</Size 4/Root 1 0 R>>\n%%EOF\n";
|
||||
const doc = await ctx.post("/api/documents/inbound", {
|
||||
multipart: {
|
||||
file: {
|
||||
name: "laborbefund-hausarzt-mit-langem-dateinamen.pdf",
|
||||
mimeType: "application/pdf",
|
||||
buffer: Buffer.from(pdf),
|
||||
},
|
||||
title: "Laborbefund Hausarzt mit einem sehr langen Titel",
|
||||
kind: "LAB_RESULT",
|
||||
},
|
||||
});
|
||||
if (!doc.ok()) {
|
||||
throw new Error(
|
||||
`[mobile-routes-fixture] /api/documents/inbound answered ${doc.status()}`,
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
await ctx.dispose();
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,10 @@ export default function LabsPage() {
|
||||
title={t("labs.addResult")}
|
||||
description={t("labs.addDescription")}
|
||||
footer={
|
||||
<div ref={setAddFooterEl} className="flex w-full justify-end gap-2" />
|
||||
<div
|
||||
ref={setAddFooterEl}
|
||||
className="flex w-full flex-wrap justify-end gap-2"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<LabForm
|
||||
|
||||
@@ -201,6 +201,7 @@ export default function NotificationsPage() {
|
||||
title={t("notifications.title")}
|
||||
description={t("notifications.subtitle")}
|
||||
actions={headerActions}
|
||||
stackActionsOnPhone
|
||||
/>
|
||||
<EmptyState
|
||||
className="max-w-2xl"
|
||||
@@ -227,6 +228,7 @@ export default function NotificationsPage() {
|
||||
title={t("notifications.title")}
|
||||
description={t("notifications.subtitle")}
|
||||
actions={headerActions}
|
||||
stackActionsOnPhone
|
||||
/>
|
||||
|
||||
{/* Desktop: table layout */}
|
||||
|
||||
@@ -125,7 +125,7 @@ export function AppLogPreviewSection() {
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="min-h-11 sm:min-h-9"
|
||||
className="min-h-11 min-w-11 sm:min-h-9 sm:min-w-9"
|
||||
onClick={() => refetch()}
|
||||
disabled={isFetching}
|
||||
aria-label={t("admin.section.app-logs.refresh")}
|
||||
@@ -133,13 +133,12 @@ export function AppLogPreviewSection() {
|
||||
<RefreshCw
|
||||
className={`h-4 w-4 ${isFetching ? "animate-spin" : ""} motion-reduce:animate-none`}
|
||||
/>
|
||||
<p className="text-sm">
|
||||
{t("admin.section.app-logs.processDetail")}
|
||||
</p>
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
<p className="text-sm">{t("admin.section.app-logs.processDetail")}</p>
|
||||
|
||||
<div className="grid gap-2 md:grid-cols-2 lg:grid-cols-4">
|
||||
<Input
|
||||
type="search"
|
||||
|
||||
@@ -163,7 +163,10 @@ export function LabBiomarkerChart({
|
||||
const min = Math.min(...candidates);
|
||||
const max = Math.max(...candidates);
|
||||
const pad = (max - min || Math.abs(max) || 1) * 0.1;
|
||||
return [min - pad, max + pad];
|
||||
// A reference window that starts at 0 (LDL "0–130") must not drag the
|
||||
// axis below zero: a concentration cannot be negative, and a "-13" tick
|
||||
// reads as a value. The pad only stays below zero when the data already is.
|
||||
return [min >= 0 ? Math.max(0, min - pad) : min - pad, max + pad];
|
||||
}, [points, lowerBound, upperBound, sourceBand]);
|
||||
|
||||
const animate = !prefersReducedMotion();
|
||||
|
||||
@@ -368,6 +368,10 @@ export function LabForm({
|
||||
variant="outline"
|
||||
data-action="save-and-add-another"
|
||||
disabled={submitting}
|
||||
// Three buttons do not fit one phone-width row: the secondary save
|
||||
// takes a row of its own above Cancel + Save instead of pushing
|
||||
// Cancel off the left edge of the sheet.
|
||||
className="max-md:order-first max-md:w-full"
|
||||
>
|
||||
{pendingAction === "saveAndAddAnother" ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin motion-reduce:animate-none" />
|
||||
|
||||
@@ -311,103 +311,148 @@ export function LabHistoryList({ readings }: { readings: LabResultDto[] }) {
|
||||
});
|
||||
}, [readings, sortBy, sortDir]);
|
||||
|
||||
// One action pair per reading, shared by the phone list and the table.
|
||||
const renderActions = (r: LabResultDto) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
{canManageLabs && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
// v1.18.10 (W10) — 44px touch target on mobile (WCAG
|
||||
// 2.5.5), compact 36px on desktop.
|
||||
className="size-11 sm:size-9"
|
||||
onClick={() => void openEdit(r)}
|
||||
aria-label={t("labs.editReading")}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
<DeleteButton
|
||||
domain="labs"
|
||||
onConfirm={() => deleteMutation.mutate(r.id)}
|
||||
title={t("labs.deleteConfirmTitle")}
|
||||
description={t("labs.deleteConfirmDescription")}
|
||||
confirmLabel={t("labs.deleteReading")}
|
||||
className="size-11 sm:size-9"
|
||||
iconClassName="h-4 w-4"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<SortableHead
|
||||
column="value"
|
||||
label={t("labs.form.value")}
|
||||
currentSort={sortBy}
|
||||
currentDir={sortDir}
|
||||
onSort={toggleSort}
|
||||
/>
|
||||
<SortableHead
|
||||
column="takenAt"
|
||||
label={t("labs.form.takenAt")}
|
||||
currentSort={sortBy}
|
||||
currentDir={sortDir}
|
||||
onSort={toggleSort}
|
||||
/>
|
||||
<SortableHead
|
||||
column="range"
|
||||
label={t("labs.referenceLabel")}
|
||||
currentSort={sortBy}
|
||||
currentDir={sortDir}
|
||||
onSort={toggleSort}
|
||||
/>
|
||||
<SortableHead
|
||||
column="note"
|
||||
label={t("labs.hasNote")}
|
||||
currentSort={sortBy}
|
||||
currentDir={sortDir}
|
||||
onSort={toggleSort}
|
||||
/>
|
||||
<TableHead className="w-20 pr-4 text-right">
|
||||
<span className="sr-only">{t("labs.editReading")}</span>
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{ordered.map((r) => (
|
||||
<TableRow key={r.id}>
|
||||
<TableCell className="font-semibold tabular-nums">
|
||||
<div className="space-y-2">
|
||||
<span>{formatLabReading(r)}</span>
|
||||
<LabReferenceRangeBar
|
||||
value={r.value}
|
||||
referenceLow={r.referenceLow}
|
||||
referenceHigh={r.referenceHigh}
|
||||
unit={r.unit}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground text-sm whitespace-nowrap">
|
||||
{formatDateShort(r.takenAt, true)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col items-start gap-1">
|
||||
<ReferenceRangeBadge status={r.rangeStatus} />
|
||||
<SourceRangeNote
|
||||
reading={r}
|
||||
className="text-muted-foreground text-xs"
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground text-sm">
|
||||
{r.hasNote ? t("labs.hasNote") : ""}
|
||||
</TableCell>
|
||||
<TableCell className="pr-4 text-right">
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
{canManageLabs && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
// v1.18.10 (W10) — 44px touch target on mobile (WCAG
|
||||
// 2.5.5), compact 36px on desktop.
|
||||
className="size-11 sm:size-9"
|
||||
onClick={() => void openEdit(r)}
|
||||
aria-label={t("labs.editReading")}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
<DeleteButton
|
||||
domain="labs"
|
||||
onConfirm={() => deleteMutation.mutate(r.id)}
|
||||
title={t("labs.deleteConfirmTitle")}
|
||||
description={t("labs.deleteConfirmDescription")}
|
||||
confirmLabel={t("labs.deleteReading")}
|
||||
className="size-11 sm:size-9"
|
||||
iconClassName="h-4 w-4"
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
{/* Phones get one stacked row per reading. The table needs ~510 px for
|
||||
its five columns, so on a phone it panned sideways inside its
|
||||
container and parked the edit / delete buttons off-screen, while the
|
||||
range bar's end labels were clipped by the same container. */}
|
||||
<ul
|
||||
data-slot="lab-history-mobile-list"
|
||||
className="divide-border divide-y lg:hidden"
|
||||
>
|
||||
{ordered.map((r) => (
|
||||
<li key={r.id} className="flex items-start gap-3 py-3">
|
||||
<div className="min-w-0 flex-1 space-y-2">
|
||||
<div className="font-semibold tabular-nums">
|
||||
{formatLabReading(r)}
|
||||
</div>
|
||||
<LabReferenceRangeBar
|
||||
value={r.value}
|
||||
referenceLow={r.referenceLow}
|
||||
referenceHigh={r.referenceHigh}
|
||||
unit={r.unit}
|
||||
/>
|
||||
<div className="text-muted-foreground flex flex-wrap items-center gap-x-2 gap-y-1 text-sm">
|
||||
<span className="whitespace-nowrap">
|
||||
{formatDateShort(r.takenAt, true)}
|
||||
</span>
|
||||
<ReferenceRangeBadge status={r.rangeStatus} />
|
||||
{r.hasNote ? (
|
||||
<span className="text-xs">{t("labs.hasNote")}</span>
|
||||
) : null}
|
||||
</div>
|
||||
<SourceRangeNote
|
||||
reading={r}
|
||||
className="text-muted-foreground text-xs"
|
||||
/>
|
||||
</div>
|
||||
{renderActions(r)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<div data-slot="lab-history-table" className="max-lg:hidden">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<SortableHead
|
||||
column="value"
|
||||
label={t("labs.form.value")}
|
||||
currentSort={sortBy}
|
||||
currentDir={sortDir}
|
||||
onSort={toggleSort}
|
||||
/>
|
||||
<SortableHead
|
||||
column="takenAt"
|
||||
label={t("labs.form.takenAt")}
|
||||
currentSort={sortBy}
|
||||
currentDir={sortDir}
|
||||
onSort={toggleSort}
|
||||
/>
|
||||
<SortableHead
|
||||
column="range"
|
||||
label={t("labs.referenceLabel")}
|
||||
currentSort={sortBy}
|
||||
currentDir={sortDir}
|
||||
onSort={toggleSort}
|
||||
/>
|
||||
<SortableHead
|
||||
column="note"
|
||||
label={t("labs.hasNote")}
|
||||
currentSort={sortBy}
|
||||
currentDir={sortDir}
|
||||
onSort={toggleSort}
|
||||
/>
|
||||
<TableHead className="w-20 pr-4 text-right">
|
||||
<span className="sr-only">{t("labs.editReading")}</span>
|
||||
</TableHead>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{ordered.map((r) => (
|
||||
<TableRow key={r.id}>
|
||||
<TableCell className="font-semibold tabular-nums">
|
||||
<div className="space-y-2">
|
||||
<span>{formatLabReading(r)}</span>
|
||||
<LabReferenceRangeBar
|
||||
value={r.value}
|
||||
referenceLow={r.referenceLow}
|
||||
referenceHigh={r.referenceHigh}
|
||||
unit={r.unit}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground text-sm whitespace-nowrap">
|
||||
{formatDateShort(r.takenAt, true)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col items-start gap-1">
|
||||
<ReferenceRangeBadge status={r.rangeStatus} />
|
||||
<SourceRangeNote
|
||||
reading={r}
|
||||
className="text-muted-foreground text-xs"
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-muted-foreground text-sm">
|
||||
{r.hasNote ? t("labs.hasNote") : ""}
|
||||
</TableCell>
|
||||
<TableCell className="pr-4 text-right">
|
||||
{renderActions(r)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<ResponsiveSheet
|
||||
open={editingId !== null}
|
||||
|
||||
@@ -80,7 +80,7 @@ function groupReadings(results: LabResultDto[]): MarkerGroup[] {
|
||||
|
||||
function LabRangeBarSlot({ reading }: { reading: LabResultDto }) {
|
||||
return (
|
||||
<div className="w-48">
|
||||
<div className={cn("w-full lg:w-48", MOBILE_CELL.rangeBar)}>
|
||||
<LabReferenceRangeBar
|
||||
value={reading.value}
|
||||
referenceLow={reading.referenceLow}
|
||||
@@ -91,6 +91,35 @@ function LabRangeBarSlot({ reading }: { reading: LabResultDto }) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The compact list is a five-column table from `lg` up: name and reading, range
|
||||
* badge, range bar, trend, chevron. Below that the same five cells fold into
|
||||
* two lines per row, because the fixed columns alone (badge + 12rem bar + 72px
|
||||
* trend + gaps) are wider than a phone, and the only flexible column — the
|
||||
* name — was the one that gave way: it collapsed to nothing and the row
|
||||
* panned sideways off the card.
|
||||
*
|
||||
* Phone layout, per row:
|
||||
*
|
||||
* name / reading · date badge ›
|
||||
* range bar trend
|
||||
*
|
||||
* The placement classes are all `max-lg:` so the desktop table keeps exactly
|
||||
* the subgrid it had.
|
||||
*/
|
||||
const ROW_CLASS =
|
||||
"grid min-w-0 grid-cols-[minmax(0,1fr)_auto_auto] items-center gap-x-3 gap-y-2 px-4 py-2.5 lg:col-span-full lg:grid-cols-subgrid lg:gap-y-0";
|
||||
|
||||
const MOBILE_CELL = {
|
||||
reading: "max-lg:col-start-1 max-lg:row-start-1",
|
||||
badge: "max-lg:col-start-2 max-lg:row-start-1 max-lg:justify-self-end",
|
||||
rangeBar: "max-lg:col-start-1 max-lg:row-start-2 max-lg:empty:hidden",
|
||||
trend:
|
||||
"max-lg:col-start-2 max-lg:row-start-2 max-lg:justify-self-end max-lg:empty:hidden",
|
||||
end: "max-lg:col-start-3 max-lg:row-start-1",
|
||||
notLinked: "max-lg:col-span-full max-lg:row-start-3",
|
||||
} as const;
|
||||
|
||||
export function LabList({ onAddFirst }: { onAddFirst?: () => void } = {}) {
|
||||
const { t } = useTranslations();
|
||||
const { canWriteDomain } = useRecordCapabilities();
|
||||
@@ -212,12 +241,15 @@ export function LabList({ onAddFirst }: { onAddFirst?: () => void } = {}) {
|
||||
</p>
|
||||
) : null}
|
||||
<Card>
|
||||
<CardContent className="divide-border grid grid-cols-[minmax(0,1fr)_max-content_12rem_72px_auto] gap-x-3 divide-y p-0">
|
||||
<CardContent className="divide-border grid grid-cols-1 divide-y p-0 lg:grid-cols-[minmax(0,1fr)_max-content_12rem_72px_auto] lg:gap-x-3">
|
||||
{groups.map((group) => {
|
||||
const inner = (
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className={cn("min-w-0 flex-1", MOBILE_CELL.reading)}>
|
||||
<div className="flex flex-wrap items-baseline gap-x-2 text-sm">
|
||||
<span className="truncate font-medium">
|
||||
<span
|
||||
data-slot="lab-list-analyte"
|
||||
className="truncate font-medium"
|
||||
>
|
||||
{group.analyte}
|
||||
</span>
|
||||
</div>
|
||||
@@ -234,47 +266,57 @@ export function LabList({ onAddFirst }: { onAddFirst?: () => void } = {}) {
|
||||
<Link
|
||||
key={group.key}
|
||||
href={`/labs/${group.biomarkerId}`}
|
||||
className="hover:bg-muted/40 col-span-full grid min-w-0 grid-cols-subgrid items-center px-4 py-2.5 transition-colors"
|
||||
className={cn(
|
||||
ROW_CLASS,
|
||||
"hover:bg-muted/40 transition-colors",
|
||||
)}
|
||||
>
|
||||
{inner}
|
||||
<ReferenceRangeBadge
|
||||
status={group.latest.rangeStatus}
|
||||
compact
|
||||
className="w-full"
|
||||
className={cn("lg:w-full", MOBILE_CELL.badge)}
|
||||
/>
|
||||
<LabRangeBarSlot reading={group.latest} />
|
||||
<div className="w-[72px]">
|
||||
<div className={cn("w-[72px]", MOBILE_CELL.trend)}>
|
||||
<LabTrendSparkline
|
||||
values={group.readings.map((reading) => reading.value)}
|
||||
referenceLow={group.latest.referenceLow}
|
||||
referenceHigh={group.latest.referenceHigh}
|
||||
/>
|
||||
</div>
|
||||
<ChevronRight className="text-muted-foreground h-4 w-4 shrink-0" />
|
||||
<ChevronRight
|
||||
className={cn(
|
||||
"text-muted-foreground h-4 w-4 shrink-0",
|
||||
MOBILE_CELL.end,
|
||||
)}
|
||||
/>
|
||||
</Link>
|
||||
) : (
|
||||
// Un-linked group (not backfilled to a catalog biomarker):
|
||||
// render inert but say so, so it doesn't read as a broken
|
||||
// link next to its clickable neighbours.
|
||||
<div
|
||||
key={group.key}
|
||||
className="col-span-full grid min-w-0 grid-cols-subgrid items-center px-4 py-2.5"
|
||||
>
|
||||
<div key={group.key} className={ROW_CLASS}>
|
||||
{inner}
|
||||
<ReferenceRangeBadge
|
||||
status={group.latest.rangeStatus}
|
||||
compact
|
||||
className="w-full"
|
||||
className={cn("lg:w-full", MOBILE_CELL.badge)}
|
||||
/>
|
||||
<LabRangeBarSlot reading={group.latest} />
|
||||
<div className="w-[72px]">
|
||||
<div className={cn("w-[72px]", MOBILE_CELL.trend)}>
|
||||
<LabTrendSparkline
|
||||
values={group.readings.map((reading) => reading.value)}
|
||||
referenceLow={group.latest.referenceLow}
|
||||
referenceHigh={group.latest.referenceHigh}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-muted-foreground shrink-0 text-xs italic">
|
||||
<span
|
||||
className={cn(
|
||||
"text-muted-foreground shrink-0 text-xs italic",
|
||||
MOBILE_CELL.notLinked,
|
||||
)}
|
||||
>
|
||||
{t("labs.notLinkedYet")}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -129,9 +129,17 @@ export function OcrRowEditor({
|
||||
{fieldError("analyte", "labs.ocr.errorAnalyte")}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{row.biomarkerMatch === "existing" ? (
|
||||
<Badge variant="outline" className="text-muted-foreground">
|
||||
// The chip repeats the analyte, so a long panel name ran past
|
||||
// the row on a phone; it truncates inside the row instead.
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="text-muted-foreground max-w-full"
|
||||
title={t("labs.ocr.linksExisting", { name: row.analyte })}
|
||||
>
|
||||
<Link2 aria-hidden />
|
||||
{t("labs.ocr.linksExisting", { name: row.analyte })}
|
||||
<span className="truncate">
|
||||
{t("labs.ocr.linksExisting", { name: row.analyte })}
|
||||
</span>
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="outline" className="text-muted-foreground">
|
||||
|
||||
@@ -89,7 +89,12 @@ export function SettingsCardHeader({
|
||||
{titleAccessory}
|
||||
</div>
|
||||
{status ? (
|
||||
<div className="flex shrink-0 items-center gap-2">{status}</div>
|
||||
// `max-w-full` caps the slot at the row once it wraps under the
|
||||
// title, so a status line longer than a phone row wraps inside
|
||||
// the card instead of widening the page.
|
||||
<div className="flex max-w-full shrink-0 items-center gap-2">
|
||||
{status}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
{/* One sentence, one text run. This slot deliberately carries no
|
||||
|
||||
@@ -294,7 +294,7 @@ function AddProviderControl({
|
||||
const [picked, setPicked] = useState<string>(addable[0] ?? "");
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<NativeSelect
|
||||
aria-label={t("settings.ai.providerChain.addProvider")}
|
||||
value={picked}
|
||||
|
||||
@@ -869,7 +869,7 @@ function SortableWidgetRow({
|
||||
style={style}
|
||||
data-slot="widget-row"
|
||||
data-dragging={isDragging ? "true" : undefined}
|
||||
className={`border-border bg-background/30 flex min-h-12 items-center gap-2 rounded-md border px-3 py-2 ${
|
||||
className={`border-border bg-background/30 flex min-h-12 flex-wrap items-center gap-2 rounded-md border px-3 py-2 sm:flex-nowrap ${
|
||||
isDragging ? "ring-primary z-10 opacity-90 shadow-lg ring-2" : ""
|
||||
}`}
|
||||
>
|
||||
@@ -898,7 +898,12 @@ function SortableWidgetRow({
|
||||
<span className="flex-1 truncate text-sm" title={labels.widgetLabel}>
|
||||
{labels.widgetLabel}
|
||||
</span>
|
||||
<div className="flex w-12 justify-center">
|
||||
{/* On a phone the two switches and two arrows (~250 px) left the name
|
||||
five characters ("Gewic…"). Below `sm` the controls wrap onto a
|
||||
second line, right-aligned under the column heads, and the name
|
||||
keeps the first line to itself. */}
|
||||
<span className="basis-full sm:hidden" aria-hidden="true" />
|
||||
<div className="flex w-12 justify-center max-sm:ml-auto">
|
||||
<Switch
|
||||
checked={tileChecked}
|
||||
onCheckedChange={(v) => onToggleTile(widget.id, v)}
|
||||
|
||||
@@ -234,8 +234,6 @@ export function LowStockCard({
|
||||
disabled={!isAuthenticated || saving}
|
||||
aria-label={t("notifications.lowStock.toggleAria")}
|
||||
/>
|
||||
<p className="text-sm">{t("notifications.lowStock.detail")}</p>
|
||||
|
||||
<span className="text-muted-foreground text-xs">
|
||||
{enabled
|
||||
? t("notifications.lowStock.statusOn")
|
||||
@@ -244,6 +242,7 @@ export function LowStockCard({
|
||||
</label>
|
||||
}
|
||||
/>
|
||||
<p className="text-sm">{t("notifications.lowStock.detail")}</p>
|
||||
{enabled && (
|
||||
<div className="flex min-h-11 items-center gap-3">
|
||||
<label htmlFor="low-stock-days" className="text-sm font-medium">
|
||||
|
||||
@@ -193,8 +193,6 @@ export function MoodReminderCard({
|
||||
disabled={!isAuthenticated || saving}
|
||||
aria-label={t("notifications.moodReminder.toggleAria")}
|
||||
/>
|
||||
<p className="text-sm">{t("notifications.moodReminder.detail")}</p>
|
||||
|
||||
<span className="text-muted-foreground text-xs">
|
||||
{enabled
|
||||
? t("notifications.moodReminder.statusOn")
|
||||
@@ -203,6 +201,7 @@ export function MoodReminderCard({
|
||||
</label>
|
||||
}
|
||||
/>
|
||||
<p className="text-sm">{t("notifications.moodReminder.detail")}</p>
|
||||
{enabled && (
|
||||
<div className="flex min-h-11 items-center gap-3">
|
||||
<label htmlFor="mood-reminder-hour" className="text-sm font-medium">
|
||||
|
||||
@@ -112,8 +112,11 @@ export function ReportScopePicker({
|
||||
{/* The one-click way to a complete report. An inline action row
|
||||
(UI-STANDARDS §11): the sentence wraps, the action stays beside it.
|
||||
It is offered, never applied — and it stays offered so a person can
|
||||
come back to the standard set after experimenting. */}
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
come back to the standard set after experimenting. On a phone the
|
||||
action's own label is wider than half the row, so beside it the
|
||||
sentence shrank to a one-word column and the button ran past the
|
||||
card edge: there the action drops under the sentence instead. */}
|
||||
<div className="flex items-start justify-between gap-3 max-sm:flex-col">
|
||||
<p
|
||||
id={hintId}
|
||||
className="text-muted-foreground min-w-0 flex-1 text-xs"
|
||||
|
||||
@@ -26,6 +26,15 @@ import { cn } from "@/lib/utils";
|
||||
* shells hand-rolled the whole block to get the second copy, which is how
|
||||
* they drifted apart from every module page in the first place.
|
||||
*/
|
||||
/**
|
||||
* A one-word German title ("Krankheitstagebuch") is wider than the column a
|
||||
* phone leaves beside the actions, and without a break opportunity it ran
|
||||
* underneath them. `hyphens-auto` breaks it by the page's `lang`; the
|
||||
* `wrap-break-word` floor covers a word the hyphenation dictionary does not.
|
||||
*/
|
||||
const HEADING_CLASS =
|
||||
"min-w-0 text-2xl font-bold tracking-tight hyphens-auto wrap-break-word";
|
||||
|
||||
export function PageHeader({
|
||||
title,
|
||||
titleId,
|
||||
@@ -34,6 +43,7 @@ export function PageHeader({
|
||||
backLink,
|
||||
topSlot,
|
||||
actions,
|
||||
stackActionsOnPhone = false,
|
||||
className,
|
||||
}: {
|
||||
title: ReactNode;
|
||||
@@ -44,37 +54,65 @@ export function PageHeader({
|
||||
/** Optional block above the title (e.g. a hub back-link the shell owns). */
|
||||
topSlot?: ReactNode;
|
||||
actions?: ReactNode;
|
||||
/**
|
||||
* Below `sm`, move the actions onto their own row under the description.
|
||||
* For text-labelled actions (two outline links, say): beside the title they
|
||||
* left the H1 a column narrower than its own word. Icon actions fit beside
|
||||
* the title and leave this off.
|
||||
*/
|
||||
stackActionsOnPhone?: boolean;
|
||||
className?: string;
|
||||
}) {
|
||||
const heading =
|
||||
headingAs === "div" ? (
|
||||
<div
|
||||
id={titleId}
|
||||
role="heading"
|
||||
aria-level={1}
|
||||
className="text-2xl font-bold tracking-tight"
|
||||
>
|
||||
<div id={titleId} role="heading" aria-level={1} className={HEADING_CLASS}>
|
||||
{title}
|
||||
</div>
|
||||
) : (
|
||||
<h1 id={titleId} className="text-2xl font-bold tracking-tight">
|
||||
<h1 id={titleId} className={HEADING_CLASS}>
|
||||
{title}
|
||||
</h1>
|
||||
);
|
||||
|
||||
// Title, description and actions share one grid. On a phone the
|
||||
// description spans the full row under the title + actions: a header with
|
||||
// three or four icon actions otherwise left the sentence a ~130 px column
|
||||
// that wrapped five or six times. From `sm` up the actions span both rows,
|
||||
// so the description sits beside them exactly as before.
|
||||
return (
|
||||
<div className={cn("space-y-1.5", className)}>
|
||||
{backLink ? <BackLink {...backLink} /> : null}
|
||||
{topSlot}
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0 space-y-1.5">
|
||||
{heading}
|
||||
{description ? (
|
||||
<p className="text-muted-foreground text-sm">{description}</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div
|
||||
data-slot="page-header-row"
|
||||
className={cn(
|
||||
"grid items-start gap-x-3 gap-y-1.5",
|
||||
actions ? "grid-cols-[minmax(0,1fr)_auto]" : "grid-cols-1",
|
||||
actions && stackActionsOnPhone && "max-sm:grid-cols-1",
|
||||
)}
|
||||
>
|
||||
{heading}
|
||||
{actions ? (
|
||||
<div className="flex shrink-0 items-center gap-2">{actions}</div>
|
||||
<div
|
||||
className={cn(
|
||||
"col-start-2 row-start-1 flex shrink-0 items-center gap-2",
|
||||
description && "sm:row-span-2",
|
||||
stackActionsOnPhone &&
|
||||
"max-sm:col-span-full max-sm:col-start-1 max-sm:row-start-3 max-sm:flex-wrap",
|
||||
)}
|
||||
>
|
||||
{actions}
|
||||
</div>
|
||||
) : null}
|
||||
{description ? (
|
||||
<p
|
||||
className={cn(
|
||||
"text-muted-foreground text-sm",
|
||||
actions && "col-span-full sm:col-span-1",
|
||||
)}
|
||||
>
|
||||
{description}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user