@terpjs/react-core 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/package.json +5 -5
- package/src/Breadcrumbs.test.tsx +78 -0
- package/src/Breadcrumbs.tsx +38 -5
- package/src/Page.tsx +16 -3
- package/src/WorkspacePage.test.tsx +69 -0
- package/src/WorkspacePage.tsx +103 -0
- package/src/admin/GroupDetail.tsx +1 -1
- package/src/admin/UserDetail.tsx +1 -1
- package/src/admin/admin.test.tsx +52 -0
- package/src/charts/TrendChart.tsx +24 -18
- package/src/charts/charts.test.tsx +11 -0
- package/src/index.ts +2 -0
- package/src/layoutContract.test.tsx +62 -1
- package/src/layoutContract.ts +12 -0
- package/src/markers.test.ts +4 -0
- package/src/router.test.tsx +1 -1
- package/src/router.tsx +19 -1
- package/src/styles.test.ts +175 -2
- package/src/styles.ts +142 -25
- package/src/trailMemory.ts +56 -0
package/README.md
CHANGED
|
@@ -72,8 +72,8 @@ also carries JSDoc, so your editor shows the same guidance inline. **Never deep-
|
|
|
72
72
|
## Page archetypes (the three-level screen pattern)
|
|
73
73
|
|
|
74
74
|
Every routed view **must** render one of the archetypes (`Page`, or `OverviewPage` /
|
|
75
|
-
`DetailPage` / `HubPage` / `DashboardPage` / `FormPage` / `SettingsPage` / `SplitPage
|
|
76
|
-
compose it) — `buildAppRouter` refuses an unframed view at
|
|
75
|
+
`DetailPage` / `HubPage` / `DashboardPage` / `FormPage` / `SettingsPage` / `SplitPage` /
|
|
76
|
+
`WorkspacePage`, which compose it) — `buildAppRouter` refuses an unframed view at
|
|
77
77
|
runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/error frame.
|
|
78
78
|
|
|
79
79
|
| Export | Use |
|
|
@@ -99,6 +99,7 @@ runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/erro
|
|
|
99
99
|
| `FormPage` | A create-or-edit screen. `measure="narrow"` by default, so the whole frame — header, actions and all — caps at 32rem over a single column of controls. Its body slot takes the form container (`Stack as="form"`), plus `Grid` / `Card` / `Divider` / `Text`; a bare `Field` at the top level is refused, because a run of fields has no `<form>` and cannot be submitted. |
|
|
100
100
|
| `SettingsPage` | Preferences and account screens: `Card` sections, also `measure="narrow"`. No `DataView`, `DetailList` or `Tabs` — a settings screen whose body is a collection is an overview with the wrong chrome. `parents` is optional, unlike `FormPage`'s. |
|
|
101
101
|
| `SplitPage`, `SplitPane` | A list beside the record it selects. The archetype owns the pane row and admits **only** `SplitPane` in it (`HubPage`'s shape, not `DetailPage`'s), so the panes are the governed thing. `listWidth` is a step — `sm` / `md` / `lg` — not a length; a draggable divider waits for the preference seam. Each pane is a named `<section>`, and below the mobile breakpoint they stack list-first, so the reading order and the tab order agree at both widths. |
|
|
102
|
+
| `WorkspacePage`, `CanvasHost` | One canvas that fills the screen, for work done on a surface: a diagram of nodes and connections, a plan, a board (ADR 0179). The page keeps its band, with its trail as `parents`; below it the body takes every pixel the shell leaves, and its slot admits **one** `CanvasHost`, a framework state while it loads or fails (which fills the same box, so the frame does not jump), and a `ConfirmDialog`. The host is a named `<section>` painted from tokens, clipped, with a 24rem floor outside a shell, and it takes the full track in a measured shell. It takes **one** canvas child, drawn in an inner layer of a definite size at 100% of it, so an `<svg>` scales by its `viewBox` and a canvas library's root that sizes itself to its container gets all of it; a second child would land below the first and be clipped. A canvas that takes keyboard focus shows the framework's focus ring on the host, where the clip cannot cut it. Nothing on the page needs a style to be sized. |
|
|
102
103
|
| `Breadcrumbs` | The trail itself (used by the archetypes; rarely composed directly). Ancestor crumbs use the router's `Link` by default — `renderLink` is only for rendering outside a Terp router. |
|
|
103
104
|
| `NavLinkContext`, `useNavLink` | The ambient link renderer `buildAppRouter` publishes (and the layout components default to); provide it yourself in a standalone story/test tree or a bespoke shell. |
|
|
104
105
|
| `useRouteParam` | Read one route param, fail closed: the declared param comes back as a string, an undeclared name throws a directive error instead of silently yielding `undefined`. Replaces the unchecked `useParams({ strict: false }) as {…}` cast (ADR 0092). Checked against the generated route table when the app has one. |
|
|
@@ -217,7 +218,7 @@ marker, counted by the escape-hatch budget.
|
|
|
217
218
|
| Export | Use |
|
|
218
219
|
|---|---|
|
|
219
220
|
| `Button` | Token-styled command: `variant` (primary / secondary / danger / ghost), `size` (sm / md / lg, composing with density), `loading` (spinner in the icon slot, `aria-busy`, and disabled so a second click cannot start the request twice), `fullWidth` to fill the container instead of the label, and an optional leading `icon`. Content-sized by default. |
|
|
220
|
-
| `Input`, `Select`, `Textarea` | Token-styled controls with stable framework typography, independent of surrounding display text (raw elements are lint-refused). Numeric inputs suppress unthemeable browser steppers. `Input type="password"` grows a reveal toggle — the type decides, so there is no second export and no prop; an app could not add one itself, because the toggle needs a positioned wrapper and
|
|
221
|
+
| `Input`, `Select`, `Textarea` | Token-styled controls with stable framework typography, independent of surrounding display text (raw elements are lint-refused). Numeric inputs suppress unthemeable browser steppers. `Input type="password"` grows a reveal toggle — the type decides, so there is no second export and no prop; an app could not add one itself, because the toggle needs a positioned wrapper and app source may use neither `style` nor `className`. |
|
|
221
222
|
| `Select` options (`SelectOption<T>`) | Two forms. Pass `options={[{ value, label, disabled? }]}` with `onValueChange` when the choices are data — `T` is inferred from the list, so a closed enum is checked at both ends and the `event.target.value as Status` cast goes away; `placeholder` renders the disabled empty-valued leading row. Or pass `<option>` children as before. The two are mutually exclusive at the type level, so neither can silently ignore the other. |
|
|
222
223
|
| `Combobox` | Accessible autocomplete/typeahead single-select: filterable options, controlled or uncontrolled value, loading state, disabled state, and ARIA combobox/listbox keyboard navigation. |
|
|
223
224
|
| `DatePicker`, `DateRangePicker` | Locale-aware calendar popover controls with keyboard-navigable month grids, min/max bounds, and range selection for ERP date filters. |
|
|
@@ -245,8 +246,8 @@ marker, counted by the escape-hatch budget.
|
|
|
245
246
|
|
|
246
247
|
## Layout
|
|
247
248
|
|
|
248
|
-
|
|
249
|
-
attribute in `src
|
|
249
|
+
App code never writes `style={}` or CSS — the boundary lint refuses the `style`
|
|
250
|
+
attribute anywhere in `src/**` (ADR 0175). Layout comes from these primitives (gaps index the
|
|
250
251
|
token spacing scale, so spacing is themed centrally):
|
|
251
252
|
|
|
252
253
|
| Export | Use |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terpjs/react-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Terp React stack core — typed @terpjs/contract client provider, auth session, capability gates, TanStack Router adapter, app shell, page archetypes, DataView and token-styled UI primitives. First frontend stack; see README.md for the component catalog.",
|
|
6
6
|
"exports": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"test": "vitest run"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tanstack/react-router": "^1.170.
|
|
18
|
-
"@terpjs/contract": "^0.
|
|
17
|
+
"@tanstack/react-router": "^1.170.41",
|
|
18
|
+
"@terpjs/contract": "^0.34.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": "^19.0.0",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"react": "^19.3.0",
|
|
32
32
|
"react-dom": "^19.3.0",
|
|
33
33
|
"typescript": "^5.9.3",
|
|
34
|
-
"vite": "^8.3.
|
|
35
|
-
"vitest": "^5.0.
|
|
34
|
+
"vite": "^8.3.2",
|
|
35
|
+
"vitest": "^5.0.3"
|
|
36
36
|
},
|
|
37
37
|
"license": "Apache-2.0",
|
|
38
38
|
"repository": {
|
package/src/Breadcrumbs.test.tsx
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
4
4
|
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
|
|
5
7
|
import { Breadcrumbs } from "./Breadcrumbs";
|
|
8
|
+
import { TrailMemoryContext, trailMemory } from "./trailMemory";
|
|
6
9
|
|
|
7
10
|
afterEach(cleanup);
|
|
8
11
|
|
|
@@ -97,3 +100,78 @@ describe("Breadcrumbs", () => {
|
|
|
97
100
|
expect(container.querySelectorAll('[aria-current="page"]')).toHaveLength(3);
|
|
98
101
|
});
|
|
99
102
|
});
|
|
103
|
+
|
|
104
|
+
// A trail that keeps what it knows (ADR 0173): a label not known yet is never a stand-in, the
|
|
105
|
+
// trail recalls what it said at a path before, and a crumb is updated in place rather than
|
|
106
|
+
// replaced, so going deeper only adds a crumb.
|
|
107
|
+
describe("a trail that keeps what it knows", () => {
|
|
108
|
+
function within(pathname: string, labels: Map<string, string>, node: ReactNode) {
|
|
109
|
+
return (
|
|
110
|
+
<TrailMemoryContext.Provider value={trailMemory(labels, pathname)}>{node}</TrailMemoryContext.Provider>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
it("shows a placeholder, read as loading, for a leaf never seen before", () => {
|
|
115
|
+
render(<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: null }]} currentAs="h1" />);
|
|
116
|
+
const heading = screen.getByRole("heading", { level: 1 });
|
|
117
|
+
// Mutation: the parent's name as the stand-in, which is a wrong title for as long as it shows.
|
|
118
|
+
expect(heading).toHaveTextContent("Loading...");
|
|
119
|
+
expect(heading).not.toHaveTextContent("Users");
|
|
120
|
+
expect(heading).toHaveAttribute("aria-busy", "true");
|
|
121
|
+
expect(heading.querySelector('[data-terp="breadcrumbs-pending"]')).not.toBeNull();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("recalls the leaf's last label at its path while the page reloads it", () => {
|
|
125
|
+
const labels = new Map<string, string>();
|
|
126
|
+
const { rerender } = render(within("/users/u1", labels, <Breadcrumbs items={[{ label: "Jane" }]} />));
|
|
127
|
+
// The same place, mounted again (a tab of the detail, or coming back): its record loads again.
|
|
128
|
+
rerender(within("/users/u1/", labels, <Breadcrumbs items={[{ label: "" }]} />));
|
|
129
|
+
expect(screen.getByText("Jane")).toHaveAttribute("aria-current", "page");
|
|
130
|
+
expect(document.querySelector('[data-terp="breadcrumbs-pending"]')).toBeNull();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("recalls a parent one level down, where only the child page has loaded", () => {
|
|
134
|
+
const labels = new Map([["/users/u1", "Jane"]]);
|
|
135
|
+
render(
|
|
136
|
+
within(
|
|
137
|
+
"/users/u1/history",
|
|
138
|
+
labels,
|
|
139
|
+
<Breadcrumbs
|
|
140
|
+
items={[{ label: "Users", to: "/users" }, { label: null, to: "/users/u1?tab=a" }, { label: "History" }]}
|
|
141
|
+
/>,
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
// Mutation: a pending ancestor looked up by its raw `to`, query and all.
|
|
145
|
+
expect(screen.getByRole("link", { name: "Jane" })).toHaveAttribute("href", "/users/u1?tab=a");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("does not remember one place's label for another", () => {
|
|
149
|
+
const labels = new Map<string, string>();
|
|
150
|
+
const { rerender } = render(within("/users/u1", labels, <Breadcrumbs items={[{ label: "Jane" }]} />));
|
|
151
|
+
rerender(within("/users/u2", labels, <Breadcrumbs items={[{ label: null }]} />));
|
|
152
|
+
expect(screen.queryByText("Jane")).toBeNull();
|
|
153
|
+
expect(screen.getByText("Loading...")).toBeInTheDocument();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("updates a crumb in place when its label arrives", () => {
|
|
157
|
+
const { rerender } = render(<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: null }]} />);
|
|
158
|
+
const [, leaf] = screen.getAllByRole("listitem");
|
|
159
|
+
rerender(<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: "Jane" }]} />);
|
|
160
|
+
// Mutation: keyed by its text, which replaced the crumb when the words arrived.
|
|
161
|
+
expect(screen.getAllByRole("listitem")[1]).toBe(leaf);
|
|
162
|
+
expect(leaf).toHaveTextContent("Jane");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("only adds a crumb when the trail goes one level deeper", () => {
|
|
166
|
+
const { rerender } = render(<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: "Jane" }]} />);
|
|
167
|
+
const [root, jane] = screen.getAllByRole("listitem");
|
|
168
|
+
rerender(
|
|
169
|
+
<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: "Jane", to: "/users/u1" }, { label: "History" }]} />,
|
|
170
|
+
);
|
|
171
|
+
const after = screen.getAllByRole("listitem");
|
|
172
|
+
expect(after).toHaveLength(3);
|
|
173
|
+
expect(after[0]).toBe(root);
|
|
174
|
+
expect(after[1]).toBe(jane);
|
|
175
|
+
expect(screen.getByRole("link", { name: "Jane" })).toHaveAttribute("href", "/users/u1");
|
|
176
|
+
});
|
|
177
|
+
});
|
package/src/Breadcrumbs.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { injectTerpStyles } from "./styles";
|
|
4
4
|
import { useNavLink } from "./navLink";
|
|
5
|
+
import { useTrailMemory } from "./trailMemory";
|
|
5
6
|
import { useStrings, useUiText } from "./uiText";
|
|
6
7
|
import type { UiText } from "./uiText";
|
|
7
8
|
|
|
@@ -9,8 +10,13 @@ injectTerpStyles();
|
|
|
9
10
|
|
|
10
11
|
/** One breadcrumb: a label plus, for ancestor levels, the path it links back to. */
|
|
11
12
|
export interface BreadcrumbItem {
|
|
12
|
-
/**
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The crumb text (e.g. the module title, or the record's display name). `null` (or `""`)
|
|
15
|
+
* while it is not known yet, such as a record still loading: the crumb then shows the last
|
|
16
|
+
* label it had at its path (ADR 0173), or a placeholder where it never had one. Never a
|
|
17
|
+
* stand-in such as the parent's name, which is a wrong name for as long as it shows.
|
|
18
|
+
*/
|
|
19
|
+
label: UiText | null;
|
|
14
20
|
/** Destination path for ancestor crumbs; the current page's crumb omits it. */
|
|
15
21
|
to?: string;
|
|
16
22
|
}
|
|
@@ -80,15 +86,42 @@ export function Breadcrumbs({ items, renderLink, currentAs = "span" }: Breadcrum
|
|
|
80
86
|
: (item: { label: string; to: string }) => navLink({ to: item.to, children: item.label }));
|
|
81
87
|
const strings = useStrings();
|
|
82
88
|
const resolve = useUiText();
|
|
89
|
+
const memory = useTrailMemory();
|
|
90
|
+
// Not known yet: a quiet bar of fixed width, read as "Loading" by assistive technology.
|
|
91
|
+
const pending = (
|
|
92
|
+
<span data-terp="breadcrumbs-pending">
|
|
93
|
+
<span data-terp="breadcrumbs-pending-text">{strings.loading}</span>
|
|
94
|
+
</span>
|
|
95
|
+
);
|
|
83
96
|
return (
|
|
84
97
|
<nav aria-label={strings.breadcrumbsLabel} data-terp="breadcrumbs">
|
|
85
98
|
<ol>
|
|
86
99
|
{items.map((item, index) => {
|
|
87
100
|
const isLast = index === items.length - 1;
|
|
88
|
-
|
|
101
|
+
// The place a crumb names: its link, or for the leaf the page the reader is on.
|
|
102
|
+
const path = item.to ?? (isLast ? memory?.pathname : undefined);
|
|
103
|
+
const given = item.label === null ? "" : resolve(item.label);
|
|
104
|
+
if (given !== "" && path !== undefined) memory?.remember(path, given);
|
|
105
|
+
const label = given !== "" ? given : path === undefined ? "" : (memory?.recall(path) ?? "");
|
|
89
106
|
return (
|
|
90
|
-
|
|
91
|
-
|
|
107
|
+
// Keyed by position, never by text: a label that arrives, or changes, is the same
|
|
108
|
+
// crumb with new words, so React updates it in place rather than replacing it.
|
|
109
|
+
<li key={index}>
|
|
110
|
+
{label === "" ? (
|
|
111
|
+
isLast && currentAs === "h1" ? (
|
|
112
|
+
<h1 aria-current="page" aria-busy="true" data-terp="page-title">
|
|
113
|
+
{pending}
|
|
114
|
+
</h1>
|
|
115
|
+
) : isLast ? (
|
|
116
|
+
<span aria-current="page" aria-busy="true" data-terp="breadcrumbs-current">
|
|
117
|
+
{pending}
|
|
118
|
+
</span>
|
|
119
|
+
) : (
|
|
120
|
+
// An ancestor not known yet is not a link either: a link with no words is
|
|
121
|
+
// one a screen reader announces as nothing.
|
|
122
|
+
<span>{pending}</span>
|
|
123
|
+
)
|
|
124
|
+
) : !isLast && item.to !== undefined ? (
|
|
92
125
|
renderCrumbLink({ label, to: item.to })
|
|
93
126
|
) : isLast && currentAs === "h1" ? (
|
|
94
127
|
// Two spelled-out branches rather than one element with a computed tag and a
|
package/src/Page.tsx
CHANGED
|
@@ -21,8 +21,13 @@ import { resolveUiTextNode, useUiText } from "./uiText";
|
|
|
21
21
|
import type { UiText, UiTextNode } from "./uiText";
|
|
22
22
|
|
|
23
23
|
export interface PageProps {
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The page heading (rendered as the single `h1`). `null` while it is not known yet — a
|
|
26
|
+
* detail page's record still loading: the heading then keeps the name it had at this path,
|
|
27
|
+
* or a placeholder on a first visit (ADR 0173). Pass `record?.name ?? null`, never the
|
|
28
|
+
* parent's name as a stand-in, which is a wrong heading for as long as it shows.
|
|
29
|
+
*/
|
|
30
|
+
title: UiText | null;
|
|
26
31
|
/** Ancestor breadcrumb trail, outermost first; the current page's crumb is appended automatically. */
|
|
27
32
|
breadcrumbs?: readonly BreadcrumbItem[];
|
|
28
33
|
/** Link renderer for ancestor crumbs; defaults to the surrounding router's `Link` (see {@link Breadcrumbs}). */
|
|
@@ -271,13 +276,21 @@ export function Page({
|
|
|
271
276
|
// branch, and a conditional written at the attribute is the form the marker scanner reads
|
|
272
277
|
// every string literal out of.
|
|
273
278
|
const measureAttribute = measure === "narrow" ? "narrow" : undefined;
|
|
279
|
+
// A workspace fills the height the shell leaves it (ADR 0179). Read from the slot owner the
|
|
280
|
+
// archetype already provides, so there is no prop for any other page to set.
|
|
281
|
+
const fillAttribute = slotOwner === "WorkspacePage" ? "workspace" : undefined;
|
|
274
282
|
// The same renderability test as the band's meta: `summary={figures && <StatGroup/>}` hands
|
|
275
283
|
// this `false` before the figures arrive, and an empty band would still take its padding.
|
|
276
284
|
const hasSummary =
|
|
277
285
|
showsBody && summary !== undefined && summary !== null && summary !== false && summary !== "";
|
|
278
286
|
return (
|
|
279
287
|
<HeadlineContext.Provider value={headlineRegistry}>
|
|
280
|
-
<article
|
|
288
|
+
<article
|
|
289
|
+
ref={articleRef}
|
|
290
|
+
data-terp="page"
|
|
291
|
+
data-measure={measureAttribute}
|
|
292
|
+
data-fill={fillAttribute}
|
|
293
|
+
>
|
|
281
294
|
{/* A <header> ELEMENT, and it has to stay one. The slot check above drops the header
|
|
282
295
|
from the body set by tagName, so re-rendering this as a marked <div> would put it
|
|
283
296
|
back in and fail every governed OverviewPage / DetailPage closed. The marker is
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { DashboardPage } from "./DashboardPage";
|
|
6
|
+
import { Page } from "./Page";
|
|
7
|
+
import { CanvasHost, WorkspacePage } from "./WorkspacePage";
|
|
8
|
+
|
|
9
|
+
afterEach(cleanup);
|
|
10
|
+
|
|
11
|
+
describe("WorkspacePage (ADR 0179)", () => {
|
|
12
|
+
it("marks its page as the one that fills the shell", () => {
|
|
13
|
+
const { container } = render(
|
|
14
|
+
<WorkspacePage title="Network">
|
|
15
|
+
<CanvasHost label="Network diagram">
|
|
16
|
+
<svg viewBox="0 0 10 10" />
|
|
17
|
+
</CanvasHost>
|
|
18
|
+
</WorkspacePage>,
|
|
19
|
+
);
|
|
20
|
+
const page = container.querySelector('[data-terp="page"]');
|
|
21
|
+
expect(page?.getAttribute("data-fill")).toBe("workspace");
|
|
22
|
+
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("Network");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("leaves every other page as it was", () => {
|
|
26
|
+
// Mutation: stamp data-fill on every page, and every main becomes a flex column.
|
|
27
|
+
for (const page of [
|
|
28
|
+
<Page key="page" title="Plain">body</Page>,
|
|
29
|
+
<DashboardPage key="dashboard" title="Overview">body</DashboardPage>,
|
|
30
|
+
]) {
|
|
31
|
+
const { container, unmount } = render(page);
|
|
32
|
+
expect(container.querySelector('[data-terp="page"]')?.hasAttribute("data-fill")).toBe(false);
|
|
33
|
+
unmount();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("takes its parent trail as parents, as DashboardPage does", () => {
|
|
38
|
+
render(
|
|
39
|
+
<WorkspacePage title="Network" parents={[{ label: "Sites", to: "/sites" }]}>
|
|
40
|
+
<CanvasHost label="Network diagram">
|
|
41
|
+
<svg viewBox="0 0 10 10" />
|
|
42
|
+
</CanvasHost>
|
|
43
|
+
</WorkspacePage>,
|
|
44
|
+
);
|
|
45
|
+
expect(screen.getByRole("link", { name: "Sites" }).getAttribute("href")).toBe("/sites");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("CanvasHost", () => {
|
|
50
|
+
it("is a named region carrying the canvas", () => {
|
|
51
|
+
render(
|
|
52
|
+
<CanvasHost label={{ id: "network.canvas", message: "Network diagram" }}>
|
|
53
|
+
<svg data-testid="drawing" viewBox="0 0 10 10" />
|
|
54
|
+
</CanvasHost>,
|
|
55
|
+
);
|
|
56
|
+
const region = screen.getByRole("region", { name: "Network diagram" });
|
|
57
|
+
expect(region.getAttribute("data-terp")).toBe("canvas-host");
|
|
58
|
+
// The canvas sits in the host's one layer, which is what gives it a definite box.
|
|
59
|
+
// Mutation: render the children straight into the section, and a canvas root that sizes
|
|
60
|
+
// to its container resolves its percentage height against a flex-grown box.
|
|
61
|
+
const layer = region.firstElementChild;
|
|
62
|
+
expect(region.children).toHaveLength(1);
|
|
63
|
+
expect(layer?.getAttribute("data-terp")).toBe("canvas-host-layer");
|
|
64
|
+
expect(layer?.firstElementChild).toBe(screen.getByTestId("drawing"));
|
|
65
|
+
// It renders no inline style: its geometry is the stylesheet's.
|
|
66
|
+
expect(region.hasAttribute("style")).toBe(false);
|
|
67
|
+
expect(layer?.hasAttribute("style")).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import type { BreadcrumbItem } from "./Breadcrumbs";
|
|
4
|
+
import { LayoutSlotContext } from "./layoutContract";
|
|
5
|
+
import { Page } from "./Page";
|
|
6
|
+
import type { PageProps } from "./Page";
|
|
7
|
+
import { injectTerpStyles } from "./styles";
|
|
8
|
+
import { useUiText } from "./uiText";
|
|
9
|
+
import type { UiText } from "./uiText";
|
|
10
|
+
|
|
11
|
+
injectTerpStyles();
|
|
12
|
+
|
|
13
|
+
export type WorkspacePageProps = Omit<PageProps, "breadcrumbs" | "measure"> & {
|
|
14
|
+
/** Optional parent layers for a workspace nested below a hub or an area. */
|
|
15
|
+
parents?: readonly (BreadcrumbItem & { to: string })[];
|
|
16
|
+
/**
|
|
17
|
+
* The workspace: one {@link CanvasHost}, or a framework state while it loads or fails, and a
|
|
18
|
+
* `ConfirmDialog` for an action taken on it.
|
|
19
|
+
*
|
|
20
|
+
* The body takes every pixel the shell leaves below the band, and the canvas takes the
|
|
21
|
+
* body. Under a layout contract nothing else is admitted, because a second block beside the
|
|
22
|
+
* canvas would have to share a height nobody declared. One host, too: two would split the
|
|
23
|
+
* height between them.
|
|
24
|
+
*/
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The workspace archetype: one canvas that fills the screen (ADR 0179).
|
|
30
|
+
*
|
|
31
|
+
* For the screen whose work IS a surface rather than a list or a record: a diagram of nodes
|
|
32
|
+
* and the connections between them, a floor plan, a planning board. Every other archetype
|
|
33
|
+
* lays its body out as blocks that take the height of their content, and a canvas has no
|
|
34
|
+
* content height of its own — it takes the box it is given — so before this a canvas could
|
|
35
|
+
* only be sized with an inline style, which app code may not write.
|
|
36
|
+
*
|
|
37
|
+
* The frame is the ordinary page band, trail, actions and summary included. Below it the body
|
|
38
|
+
* fills the rest of the shell's content column: the shell's main area becomes a flex column
|
|
39
|
+
* when it holds a workspace (the same `:has()` scoping the page-sequence bar uses, so no other
|
|
40
|
+
* page changes), the page grows into it, and the {@link CanvasHost} grows into the page. A
|
|
41
|
+
* loading, error or empty state in the canvas's place grows the same way, so the frame does
|
|
42
|
+
* not jump when the canvas arrives. Standalone, outside a shell, the canvas keeps a floor of
|
|
43
|
+
* 24rem.
|
|
44
|
+
*
|
|
45
|
+
* It takes its trail as `parents` and provides `LayoutSlotContext`, as `DashboardPage` does:
|
|
46
|
+
* `Page` verifies the body's children against the contract's `WorkspacePage` slot and stamps
|
|
47
|
+
* `data-fill` on the article when it is the workspace's.
|
|
48
|
+
*/
|
|
49
|
+
export function WorkspacePage({ parents, ...page }: WorkspacePageProps): ReactNode {
|
|
50
|
+
return (
|
|
51
|
+
<LayoutSlotContext.Provider value="WorkspacePage">
|
|
52
|
+
<Page {...page} breadcrumbs={parents} />
|
|
53
|
+
</LayoutSlotContext.Provider>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface CanvasHostProps {
|
|
58
|
+
/**
|
|
59
|
+
* The canvas's accessible name.
|
|
60
|
+
*
|
|
61
|
+
* Required: the host is a `<section>`, so a landmark, and an unnamed one is an entry in a
|
|
62
|
+
* screen reader's landmark list that says nothing about what is on it.
|
|
63
|
+
*/
|
|
64
|
+
label: UiText;
|
|
65
|
+
/**
|
|
66
|
+
* The canvas itself: ONE `<svg>` the app draws, or the root of ONE canvas component.
|
|
67
|
+
*
|
|
68
|
+
* The host lays an inner layer over its whole box, absolutely at inset 0, so the layer has a
|
|
69
|
+
* definite size whatever the page around it does, and the child is sized to 100% of that
|
|
70
|
+
* layer. So an `<svg>` fills the box and scales its drawing by its `viewBox`, and a canvas
|
|
71
|
+
* component whose root sizes itself to its container gets all of it. Every child takes the
|
|
72
|
+
* whole layer, which is why the host takes one: a second sibling does not share the box, it
|
|
73
|
+
* lands below the first, outside the visible area, and is clipped. A `ConfirmDialog` is the
|
|
74
|
+
* exception and is left at its own size.
|
|
75
|
+
*
|
|
76
|
+
* The host's subtree is the app's to compose, as a `Card`'s body is: the contract governs the
|
|
77
|
+
* workspace's direct children, not what is drawn on the canvas.
|
|
78
|
+
*/
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The surface a {@link WorkspacePage} fills: a named, bounded region that takes the page's
|
|
84
|
+
* remaining height and lays its one canvas over the whole of it. A workspace holds one host.
|
|
85
|
+
*
|
|
86
|
+
* It paints from tokens only — the surface fill, the hairline and the radius a `Card` uses —
|
|
87
|
+
* so it reads as a block of the page in every theme, and it clips what is drawn on it, so a
|
|
88
|
+
* canvas panned past its edge does not paint over the band. Because it clips, a focus ring
|
|
89
|
+
* drawn around the canvas would be clipped with it, so the host draws the framework's focus
|
|
90
|
+
* ring on itself while the canvas has keyboard focus. It renders no inline style.
|
|
91
|
+
*/
|
|
92
|
+
export function CanvasHost({ label, children }: CanvasHostProps) {
|
|
93
|
+
const resolve = useUiText();
|
|
94
|
+
return (
|
|
95
|
+
<section data-terp="canvas-host" aria-label={resolve(label)}>
|
|
96
|
+
{/* The layer is what gives the canvas a definite box. The host's own height comes from
|
|
97
|
+
flex growth, which a child's percentage height cannot resolve against, and a canvas
|
|
98
|
+
library's root is positioned by the library's own sheet rather than by ours. The
|
|
99
|
+
layer is ours alone, absolutely positioned at inset 0, so its size is definite. */}
|
|
100
|
+
<div data-terp="canvas-host-layer">{children}</div>
|
|
101
|
+
</section>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
@@ -346,7 +346,7 @@ export function GroupDetail() {
|
|
|
346
346
|
const record = group.item;
|
|
347
347
|
return (
|
|
348
348
|
<DetailPage
|
|
349
|
-
title={record?.name ??
|
|
349
|
+
title={record?.name ?? null}
|
|
350
350
|
parents={[
|
|
351
351
|
{ ...adminCrumb(strings), to: "/admin" },
|
|
352
352
|
{ label: strings.adminGroups, to: "/admin/groups" },
|
package/src/admin/UserDetail.tsx
CHANGED
|
@@ -129,7 +129,7 @@ export function UserDetail() {
|
|
|
129
129
|
|
|
130
130
|
return (
|
|
131
131
|
<DetailPage
|
|
132
|
-
title={record?.email ??
|
|
132
|
+
title={record?.email ?? null}
|
|
133
133
|
parents={[
|
|
134
134
|
{ ...adminCrumb(strings), to: "/admin" },
|
|
135
135
|
{ label: strings.adminUsers, to: "/admin/users" },
|
package/src/admin/admin.test.tsx
CHANGED
|
@@ -673,6 +673,58 @@ describe("the packaged admin area", () => {
|
|
|
673
673
|
expect(figure("Active accounts")?.caption).toBe("0 deactivated");
|
|
674
674
|
});
|
|
675
675
|
|
|
676
|
+
it("titles a user being read by nothing yet, then by the user, and by the user on a return (ADR 0173)", async () => {
|
|
677
|
+
const { fetchMock, router } = renderAdminApp("/admin/users/u1");
|
|
678
|
+
const answer = fetchMock.getMockImplementation()!;
|
|
679
|
+
let release!: () => void;
|
|
680
|
+
let held: Promise<void> = new Promise((resolve) => (release = resolve));
|
|
681
|
+
fetchMock.mockImplementation(async (input, init) => {
|
|
682
|
+
const request = input as Request;
|
|
683
|
+
if (new URL(request.url).pathname.endsWith("/api/v1/users/u1") && request.method === "GET") {
|
|
684
|
+
await held;
|
|
685
|
+
}
|
|
686
|
+
return answer(input, init);
|
|
687
|
+
});
|
|
688
|
+
// While the user is read: a placeholder, never the parent's name as a stand-in title.
|
|
689
|
+
const loading = await screen.findByRole("heading", { level: 1 });
|
|
690
|
+
expect(loading).toHaveTextContent("Loading...");
|
|
691
|
+
expect(loading).not.toHaveTextContent("Users");
|
|
692
|
+
await act(async () => release());
|
|
693
|
+
await waitFor(() =>
|
|
694
|
+
expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("jane.doe@example.com"),
|
|
695
|
+
);
|
|
696
|
+
// Away and back, and this time the read never answers: the trail still knows the place.
|
|
697
|
+
held = new Promise(() => {});
|
|
698
|
+
await act(async () => {
|
|
699
|
+
await router.navigate({ to: "/admin/users" });
|
|
700
|
+
});
|
|
701
|
+
await act(async () => {
|
|
702
|
+
await router.navigate({ to: "/admin/users/u1" });
|
|
703
|
+
});
|
|
704
|
+
// The detail's own trail, where Users is an ancestor link again.
|
|
705
|
+
const trail = await screen.findByRole("navigation", { name: "Breadcrumb" });
|
|
706
|
+
await waitFor(() => expect(within(trail).getByRole("link", { name: "Users" })).toBeInTheDocument());
|
|
707
|
+
// Mutation: no memory in the shell, which put the placeholder back on every visit.
|
|
708
|
+
expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("jane.doe@example.com");
|
|
709
|
+
expect(document.querySelector('[data-terp="breadcrumbs-pending"]')).toBeNull();
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
it("titles a group being read by nothing yet, never by its parent", async () => {
|
|
713
|
+
const { fetchMock } = renderAdminApp("/admin/groups/g1");
|
|
714
|
+
const answer = fetchMock.getMockImplementation()!;
|
|
715
|
+
fetchMock.mockImplementation(async (input, init) => {
|
|
716
|
+
const request = input as Request;
|
|
717
|
+
if (new URL(request.url).pathname.endsWith("/api/v1/groups/g1") && request.method === "GET") {
|
|
718
|
+
return new Promise<Response>(() => {});
|
|
719
|
+
}
|
|
720
|
+
return answer(input, init);
|
|
721
|
+
});
|
|
722
|
+
const heading = await screen.findByRole("heading", { level: 1 });
|
|
723
|
+
// Mutation: `record?.name ?? strings.adminGroups`, the parent's name as a stand-in title.
|
|
724
|
+
expect(heading).toHaveTextContent("Loading...");
|
|
725
|
+
expect(heading).not.toHaveTextContent("Groups");
|
|
726
|
+
});
|
|
727
|
+
|
|
676
728
|
it("drops the access card with the access section, the one a full hub always drew", async () => {
|
|
677
729
|
// The selective hub replaced the full one only when users, groups or audit was dropped, so
|
|
678
730
|
// `{ access: false }` alone removed the route and kept the card that leads to it.
|
|
@@ -208,25 +208,31 @@ export function TrendChart({ label, series, comparison, mark = "line", format }:
|
|
|
208
208
|
)}
|
|
209
209
|
</span>
|
|
210
210
|
</div>
|
|
211
|
-
{/* Named by the same caption rather than a <caption> of its own, so it is not read twice.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
<th scope="row">{labelAt(index)}</th>
|
|
224
|
-
<td>{formatNumber(points[index]?.value, format)}</td>
|
|
225
|
-
{comparison !== undefined && <td>{formatNumber(earlier[index]?.value, format)}</td>}
|
|
211
|
+
{/* Named by the same caption rather than a <caption> of its own, so it is not read twice.
|
|
212
|
+
Hidden by a wrapper, never by the table itself: a table's width and height are
|
|
213
|
+
minimums, so the visually-hidden rule could not shrink one, and the full-size table
|
|
214
|
+
hung below the chart, stretched the page and let a page that fitted scroll. A block
|
|
215
|
+
takes the 1px box, and its overflow clip holds the table inside it. */}
|
|
216
|
+
<div data-terp="chart-table">
|
|
217
|
+
<table aria-labelledby={captionId}>
|
|
218
|
+
<thead>
|
|
219
|
+
<tr>
|
|
220
|
+
<td />
|
|
221
|
+
<th scope="col">{resolve(series.label)}</th>
|
|
222
|
+
{comparison !== undefined && <th scope="col">{resolve(comparison.label)}</th>}
|
|
226
223
|
</tr>
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
224
|
+
</thead>
|
|
225
|
+
<tbody>
|
|
226
|
+
{indices.map((index) => (
|
|
227
|
+
<tr key={index}>
|
|
228
|
+
<th scope="row">{labelAt(index)}</th>
|
|
229
|
+
<td>{formatNumber(points[index]?.value, format)}</td>
|
|
230
|
+
{comparison !== undefined && <td>{formatNumber(earlier[index]?.value, format)}</td>}
|
|
231
|
+
</tr>
|
|
232
|
+
))}
|
|
233
|
+
</tbody>
|
|
234
|
+
</table>
|
|
235
|
+
</div>
|
|
230
236
|
</figure>
|
|
231
237
|
);
|
|
232
238
|
}
|
|
@@ -80,6 +80,17 @@ describe("TrendChart", () => {
|
|
|
80
80
|
{ label: "W3", value: 180 },
|
|
81
81
|
];
|
|
82
82
|
|
|
83
|
+
it("hides its table through a block, which the visually-hidden rule can shrink", () => {
|
|
84
|
+
// A table's width and height are minimums, so marking the table itself left a full-size box
|
|
85
|
+
// hanging below the chart that stretched the page. Mutation: put the marker back on the
|
|
86
|
+
// <table>, and the hidden part is a table again.
|
|
87
|
+
renderIn("en", <TrendChart label="Rows synced" series={{ label: "This month", points: WEEKS }} />);
|
|
88
|
+
const hidden = part("chart-table")!;
|
|
89
|
+
expect(hidden.tagName).toBe("DIV");
|
|
90
|
+
expect(hidden.children).toHaveLength(1);
|
|
91
|
+
expect(hidden.firstElementChild?.tagName).toBe("TABLE");
|
|
92
|
+
});
|
|
93
|
+
|
|
83
94
|
it("is a captioned figure whose picture is hidden and whose data is a table", () => {
|
|
84
95
|
renderIn("en", <TrendChart label="Rows synced" series={{ label: "This month", points: WEEKS }} />);
|
|
85
96
|
const figure = screen.getByRole("figure", { name: "Rows synced" });
|
package/src/index.ts
CHANGED
|
@@ -88,6 +88,8 @@ export type {
|
|
|
88
88
|
SplitPaneRole,
|
|
89
89
|
SplitListWidth,
|
|
90
90
|
} from "./SplitPage";
|
|
91
|
+
export { CanvasHost, WorkspacePage } from "./WorkspacePage";
|
|
92
|
+
export type { CanvasHostProps, WorkspacePageProps } from "./WorkspacePage";
|
|
91
93
|
export { HubPage, HubCard } from "./HubPage";
|
|
92
94
|
export type { HubPageProps, HubCardProps, RenderHubCardLink } from "./HubPage";
|
|
93
95
|
export {
|