mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
feat(documents): choose how the vault is laid out, and confirm every delete
The wrench beside Upload opens Settings, Appearance, Documents, the way the illness journal offers its display options: preview cards or a compact list, and months stacked as blocks or flowing across the full width with the month name inline above the document that opens it. The choice is stored per account in `users.documents_layout_json` behind GET/PUT /api/documents/inbound/layout (preserve-when-absent, module gated, the read delegable like the rest of the vault), carried in the account-settings backup and cleared by the data wipe. Deleting from the vault now always asks first. The bulk bar's Delete and a focused card's Delete key both go through one confirmation on the page, and the detail sheet's Delete opens its own; before, all three deleted on the spot with only an undo toast behind them. The selection bar is two tight lines: the count with an X at its right edge, then one action row with Delete alone at the right in the destructive style. Below 1024 px the verbs are icon-only at the 44 px tap floor, so the row stays one line at 360 px. The bar carries the selection-bar slot the Coach launcher already steps aside for.
This commit is contained in:
1 parent
ce6d2fe72a
commit
4273af231e
39 files changed
+1661
-209
No files matched your search
@@ -29,7 +29,7 @@ function render(
|
||||
onLinkEpisode={() => {}}
|
||||
onLinkEncounter={() => {}}
|
||||
onShare={() => {}}
|
||||
onDelete={() => {}}
|
||||
onRequestDelete={() => {}}
|
||||
onClear={() => {}}
|
||||
/>
|
||||
</I18nProvider>,
|
||||
@@ -51,6 +51,51 @@ describe("<DocumentBulkBar>", () => {
|
||||
expect(html).toContain("Clear selection");
|
||||
});
|
||||
|
||||
it("clears with an X icon at the right of the count line, not a text button", () => {
|
||||
const html = render([{ id: "ep1", label: "Knee" }]);
|
||||
const countLine = html.slice(
|
||||
html.indexOf('data-slot="document-bulk-count"'),
|
||||
html.indexOf('data-slot="document-bulk-actions"'),
|
||||
);
|
||||
// The clear control lives on the count line, before the action row…
|
||||
expect(countLine).toContain('data-slot="document-bulk-clear"');
|
||||
expect(countLine).toContain('aria-label="Clear selection"');
|
||||
// …and carries no visible label: the name rides on aria-label and title.
|
||||
expect(countLine).not.toContain(">Clear selection<");
|
||||
});
|
||||
|
||||
it("keeps every verb in ONE action row with Delete alone at its right edge", () => {
|
||||
const html = render([{ id: "ep1", label: "Knee" }]);
|
||||
const actions = html.slice(
|
||||
html.indexOf('data-slot="document-bulk-actions"'),
|
||||
);
|
||||
const order = [
|
||||
"document-bulk-set-kind",
|
||||
"document-bulk-link-condition",
|
||||
"document-bulk-link-visit",
|
||||
"document-bulk-share",
|
||||
"document-bulk-delete",
|
||||
].map((slot) => actions.indexOf(`data-slot="${slot}"`));
|
||||
expect(order.every((index) => index >= 0)).toBe(true);
|
||||
expect([...order].sort((a, b) => a - b)).toEqual(order);
|
||||
// The row never wraps into a second line, and Delete is pushed right.
|
||||
const rowTag = /<div[^>]*data-slot="document-bulk-actions"[^>]*>/.exec(
|
||||
html,
|
||||
);
|
||||
expect(rowTag?.[0]).not.toContain("flex-wrap");
|
||||
const deleteTag = /<button[^>]*data-slot="document-bulk-delete"[^>]*>/.exec(
|
||||
html,
|
||||
);
|
||||
expect(deleteTag?.[0]).toContain("ml-auto");
|
||||
});
|
||||
|
||||
it("carries the selection-bar slot the Coach launcher steps aside for", () => {
|
||||
const html = render([{ id: "ep1", label: "Knee" }]);
|
||||
expect(html).toMatch(
|
||||
/^<div data-slot="selection-action-bar" class="contents">/,
|
||||
);
|
||||
});
|
||||
|
||||
it("omits the link-condition verb when the account has no episodes", () => {
|
||||
const html = render([]);
|
||||
expect(html).not.toContain("Link condition");
|
||||
|
||||
@@ -7,12 +7,50 @@ import { describe, expect, it } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import type { InboundDocumentDto } from "@/lib/validations/inbound-documents";
|
||||
import {
|
||||
columnsForWidth,
|
||||
DocumentMonthHeading,
|
||||
DocumentMonthRow,
|
||||
estimatedRowHeight,
|
||||
listColumnsForWidth,
|
||||
} from "../document-month-grid";
|
||||
|
||||
function doc(id: string): InboundDocumentDto {
|
||||
return {
|
||||
id,
|
||||
kind: "DOCTOR_REPORT",
|
||||
title: `Letter ${id}`,
|
||||
filename: null,
|
||||
mimeType: "application/pdf",
|
||||
byteSize: 1024,
|
||||
status: "STORED",
|
||||
documentDate: "2026-03-10",
|
||||
createdAt: "2026-03-10T10:00:00Z",
|
||||
conditionLinks: [],
|
||||
servingClass: "inline",
|
||||
hasThumbnail: false,
|
||||
hasContentIndex: true,
|
||||
} as unknown as InboundDocumentDto;
|
||||
}
|
||||
|
||||
function renderRow(props: Partial<Parameters<typeof DocumentMonthRow>[0]>) {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<DocumentMonthRow
|
||||
documents={[doc("a"), doc("b")]}
|
||||
columns={2}
|
||||
selectedIds={new Set()}
|
||||
onOpen={() => {}}
|
||||
highlightId={null}
|
||||
rovingId="a"
|
||||
onCardFocus={() => {}}
|
||||
{...props}
|
||||
/>
|
||||
</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("columnsForWidth", () => {
|
||||
it("lays a 390 px phone out in two columns, the narrowest screens in one", () => {
|
||||
// 390 viewport minus the shell's 16 px gutters.
|
||||
@@ -50,3 +88,40 @@ describe("<DocumentMonthHeading>", () => {
|
||||
expect(html).toMatch(/^<h2 [^>]*uppercase[^>]*>March 2026<\/h2>$/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("listColumnsForWidth", () => {
|
||||
it("keeps compact rows single-file on a phone and side by side on a desktop", () => {
|
||||
expect(listColumnsForWidth(358)).toBe(1);
|
||||
expect(listColumnsForWidth(1024 - 48)).toBe(2);
|
||||
expect(listColumnsForWidth(1280 - 48)).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("<DocumentMonthRow>", () => {
|
||||
it("renders preview tiles by default and compact rows in the list view", () => {
|
||||
expect(renderRow({})).toContain('data-variant="tile"');
|
||||
const list = renderRow({ view: "list" });
|
||||
expect(list).toContain('data-variant="row"');
|
||||
expect(list).not.toContain('data-variant="tile"');
|
||||
});
|
||||
|
||||
it("flowing: the month name rides inline above the document that opens it", () => {
|
||||
const html = renderRow({
|
||||
monthStarts: { b: "2026-02" },
|
||||
formatMonth: () => "February 2026",
|
||||
});
|
||||
expect(html.match(/data-slot="document-flow-month"/g)).toHaveLength(1);
|
||||
expect(html).toContain("February 2026");
|
||||
// The marker belongs to b's cell, not a's.
|
||||
expect(html.indexOf("February 2026")).toBeGreaterThan(
|
||||
html.indexOf('data-document-id="a"'),
|
||||
);
|
||||
expect(html.indexOf("February 2026")).toBeLessThan(
|
||||
html.indexOf('data-document-id="b"'),
|
||||
);
|
||||
});
|
||||
|
||||
it("stacked rows carry no inline month marker", () => {
|
||||
expect(renderRow({})).not.toContain('data-slot="document-flow-month"');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Every way of deleting from the vault asks first.
|
||||
*
|
||||
* Until v1.42 the bulk bar's Delete and a focused card's Delete key both
|
||||
* called the bulk delete straight away; only the transient undo toast stood
|
||||
* between a stray press and a medical document leaving the vault. The page now
|
||||
* routes both through one confirmation (`requestDelete` → `ConfirmDialog` →
|
||||
* `confirmDelete`), and the detail sheet's Delete opens its own.
|
||||
*
|
||||
* Structural rather than behavioural because the unit layer renders statically;
|
||||
* the e2e journey (`documents-qol.spec.ts`) clicks through the real dialog. The
|
||||
* matchers assert a non-zero count, so a rename that leaves them matching
|
||||
* nothing fails instead of passing quietly.
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dir = join(process.cwd(), "src/components/documents");
|
||||
const view = readFileSync(join(dir, "documents-view.tsx"), "utf8");
|
||||
const sheet = readFileSync(join(dir, "document-detail-sheet.tsx"), "utf8");
|
||||
const bar = readFileSync(join(dir, "document-bulk-bar.tsx"), "utf8");
|
||||
|
||||
describe("vault delete paths confirm before deleting", () => {
|
||||
it("the page calls the bulk delete only from the confirmation", () => {
|
||||
const calls = [...view.matchAll(/deleteBulk\(\s*([^)]*)\)/g)].map((m) =>
|
||||
m[1].trim(),
|
||||
);
|
||||
// One call site, and it is the confirmed id list.
|
||||
expect(calls).toEqual(["pendingDeleteIds"]);
|
||||
expect(view).toMatch(
|
||||
/const confirmDelete = useCallback\(\(\) => \{\s*if \(pendingDeleteIds\) deleteBulk\(pendingDeleteIds\);/,
|
||||
);
|
||||
expect(view).toContain("<ConfirmDialog");
|
||||
});
|
||||
|
||||
it("the bulk bar and the card key both go through requestDelete", () => {
|
||||
expect(view).toMatch(
|
||||
/onDelete=\{\s*canManageDocuments \? \(id\) => requestDelete\(\[id\]\)/,
|
||||
);
|
||||
expect(view).toMatch(
|
||||
/onRequestDelete=\{\(\) => requestDelete\(\[\.\.\.selectedIds\]\)\}/,
|
||||
);
|
||||
// The bar has no delete of its own to call.
|
||||
expect(bar).not.toMatch(/\bonDelete\b/);
|
||||
expect(bar).toMatch(/onClick=\{onRequestDelete\}/);
|
||||
});
|
||||
|
||||
it("the detail sheet's Delete opens a confirmation instead of deleting", () => {
|
||||
const mutateCalls = [...sheet.matchAll(/remove\.mutate\(/g)];
|
||||
expect(mutateCalls.length).toBe(1);
|
||||
expect(sheet).toMatch(/onConfirm=\{\(\) => remove\.mutate\(doc\.id\)\}/);
|
||||
expect(sheet).toMatch(/onClick=\{\(\) => setConfirmDeleteOpen\(true\)\}/);
|
||||
});
|
||||
});
|
||||
@@ -49,11 +49,18 @@ import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
import { DocumentsView } from "../documents-view";
|
||||
|
||||
function render(search: string, seedList?: { kinds?: never } | object) {
|
||||
function render(
|
||||
search: string,
|
||||
seedList?: { kinds?: never } | object,
|
||||
layout: object | null = { version: 1, view: "cards", arrangement: "stacked" },
|
||||
) {
|
||||
mockSearch = search;
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
});
|
||||
if (layout !== null) {
|
||||
queryClient.setQueryData(queryKeys.documentsLayout(), layout);
|
||||
}
|
||||
if (seedList !== undefined) {
|
||||
queryClient.setQueryData(queryKeys.inboundDocumentList(seedList), {
|
||||
pages: [{ documents: [], nextCursor: null }],
|
||||
@@ -80,6 +87,29 @@ describe("<DocumentsView> states", () => {
|
||||
expect(html).not.toContain("Your document vault is empty");
|
||||
});
|
||||
|
||||
it("header: a wrench opens the vault's display settings, left of Upload", () => {
|
||||
const html = render("", {});
|
||||
const wrench = html.indexOf('data-slot="documents-customize"');
|
||||
expect(wrench).toBeGreaterThan(-1);
|
||||
expect(html).toContain('href="/settings/layout/documents"');
|
||||
expect(html.indexOf("Upload", wrench)).toBeGreaterThan(wrench);
|
||||
});
|
||||
|
||||
it("first load waits for the presentation, then paints the list skeleton for a list reader", () => {
|
||||
// The presentation read is still out: the vault does not guess a shape.
|
||||
const pending = render("", {}, null);
|
||||
expect(pending).toContain('data-slot="documents-loading"');
|
||||
expect(pending).not.toContain("Your document vault is empty");
|
||||
|
||||
const listReader = render("", undefined, {
|
||||
version: 1,
|
||||
view: "list",
|
||||
arrangement: "flow",
|
||||
});
|
||||
expect(listReader).toContain('data-slot="documents-loading"');
|
||||
expect(listReader).not.toContain("aspect-[4/3]");
|
||||
});
|
||||
|
||||
it("filter bar: type facet is a compact dropdown, not an inline chip row", () => {
|
||||
const html = render("");
|
||||
// The type facet renders as a single dropdown trigger labelled by the
|
||||
|
||||
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
|
||||
import type { InboundDocumentDto } from "@/lib/validations/inbound-documents";
|
||||
import {
|
||||
buildProcedureChoices,
|
||||
buildFlowTimelineItems,
|
||||
buildTimelineItems,
|
||||
buildVaultListApiSearch,
|
||||
classifyUploadFailure,
|
||||
@@ -127,6 +128,28 @@ describe("API list search", () => {
|
||||
});
|
||||
|
||||
describe("timeline items", () => {
|
||||
it("flowing: rows run across month boundaries and mark where each month opens", () => {
|
||||
const docs = [
|
||||
doc({ id: "a", documentDate: "2026-03-20" }),
|
||||
doc({ id: "b", documentDate: "2026-03-15" }),
|
||||
doc({ id: "c", documentDate: "2026-02-28" }),
|
||||
doc({ id: "d", documentDate: "2026-02-10" }),
|
||||
doc({ id: "e", documentDate: "2026-01-05" }),
|
||||
];
|
||||
const items = buildFlowTimelineItems(docs, 3, "UTC");
|
||||
// No row is spent on a month: five documents in three columns are two rows.
|
||||
expect(items.map((i) => i.type)).toEqual(["row", "row"]);
|
||||
expect(items[0]).toMatchObject({
|
||||
documents: [docs[0], docs[1], docs[2]],
|
||||
monthStarts: { a: "2026-03", c: "2026-02" },
|
||||
});
|
||||
// February continues into the second row without a second marker.
|
||||
expect(items[1]).toMatchObject({
|
||||
documents: [docs[3], docs[4]],
|
||||
monthStarts: { e: "2026-01" },
|
||||
});
|
||||
});
|
||||
|
||||
it("buckets by month and chunks rows to the column count", () => {
|
||||
const docs = [
|
||||
doc({ id: "a", documentDate: "2026-03-20" }),
|
||||
|
||||
Reference in new issue
Block a user