@terpjs/react-core 0.31.0 → 0.33.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/ModuleNav.test.tsx +29 -1
- package/src/ModuleNav.tsx +5 -1
- package/src/Page.tsx +16 -3
- package/src/Stat.test.tsx +35 -0
- package/src/Stat.tsx +3 -1
- package/src/WorkspacePage.test.tsx +69 -0
- package/src/WorkspacePage.tsx +103 -0
- package/src/admin/AdminHub.tsx +233 -86
- package/src/admin/GroupDetail.tsx +1 -1
- package/src/admin/RecordHistory.tsx +5 -0
- package/src/admin/UserDetail.tsx +1 -1
- package/src/admin/admin.test.tsx +233 -14
- package/src/charts/TrendChart.tsx +24 -18
- package/src/charts/charts.test.tsx +11 -0
- package/src/currentInView.ts +28 -0
- package/src/dataview/DataView.test.tsx +48 -1
- package/src/dataview/DataView.tsx +18 -3
- package/src/dataview/DataViewToolbar.tsx +4 -1
- package/src/index.ts +2 -0
- package/src/layoutContract.test.tsx +62 -1
- package/src/layoutContract.ts +12 -0
- package/src/locale.tsx +8 -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 +241 -2
- package/src/styles.ts +234 -39
- package/src/trailMemory.ts +56 -0
- package/src/ui/Tabs.test.tsx +44 -0
- package/src/ui/Tabs.tsx +5 -2
- package/src/uiText.tsx +30 -1
- package/src/viewerTimeZone.ts +15 -0
package/src/admin/admin.test.tsx
CHANGED
|
@@ -155,6 +155,33 @@ function LogInOnMount() {
|
|
|
155
155
|
|
|
156
156
|
const emptyPage = { items: [], total: 0, skip: 0, limit: 1 };
|
|
157
157
|
|
|
158
|
+
/** A day of the hub's activity fixture: `offset` days after 5 September 2026. */
|
|
159
|
+
function activityDay(offset: number, count: number) {
|
|
160
|
+
return { date: new Date(Date.UTC(2026, 8, 5 + offset)).toISOString().slice(0, 10), count };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The trail's activity as the hub reads it: thirty days ending 4 October. The last week sums to
|
|
165
|
+
* 21 and the week before to 16, so the figure reads 21, 5 up. The days before the last week
|
|
166
|
+
* count 1, 2, 3, 4 in turn: with one change on each, any seven of them summed to 7, and a
|
|
167
|
+
* comparison read a day off still printed the right delta.
|
|
168
|
+
*/
|
|
169
|
+
const LAST_WEEK = [5, 4, 6, 3, 2, 0, 1];
|
|
170
|
+
const ACTIVITY = {
|
|
171
|
+
time_zone: "Europe/Amsterdam",
|
|
172
|
+
days: Array.from({ length: 30 }, (_, index) =>
|
|
173
|
+
activityDay(index, index >= 23 ? LAST_WEEK[index - 23]! : (index % 4) + 1),
|
|
174
|
+
),
|
|
175
|
+
previous_days: Array.from({ length: 30 }, (_, index) => activityDay(index - 30, 2)),
|
|
176
|
+
by_action: [
|
|
177
|
+
{ action: "updated", count: 30 },
|
|
178
|
+
{ action: "created", count: 12 },
|
|
179
|
+
{ action: "deleted", count: 2 },
|
|
180
|
+
],
|
|
181
|
+
by_target_type: [{ target_type: "User", count: 44 }],
|
|
182
|
+
total: 44,
|
|
183
|
+
};
|
|
184
|
+
|
|
158
185
|
/**
|
|
159
186
|
* Held open, the access-model response does not land. Set by the one test that needs the
|
|
160
187
|
* role ladder to still be in flight while it looks at the form, so the window in which the
|
|
@@ -275,6 +302,10 @@ function stubAdminFetch() {
|
|
|
275
302
|
limit: 20,
|
|
276
303
|
});
|
|
277
304
|
}
|
|
305
|
+
// The hub counts its active accounts as a total under the status filter.
|
|
306
|
+
if (url.searchParams.get("is_active") === "true") {
|
|
307
|
+
return jsonResponse({ items: [], total: 5, skip: 0, limit: 1 });
|
|
308
|
+
}
|
|
278
309
|
return jsonResponse({
|
|
279
310
|
items: [
|
|
280
311
|
{
|
|
@@ -368,6 +399,9 @@ function stubAdminFetch() {
|
|
|
368
399
|
limit: 10,
|
|
369
400
|
});
|
|
370
401
|
}
|
|
402
|
+
if (path.endsWith("/api/v1/audit/activity")) {
|
|
403
|
+
return jsonResponse(ACTIVITY);
|
|
404
|
+
}
|
|
371
405
|
if (path.endsWith("/api/v1/audit/")) {
|
|
372
406
|
// One row, and it earns its place rather than padding the fixture: the audit screen's
|
|
373
407
|
// expanded panel is the only place the payload renders, so with an empty page that
|
|
@@ -469,6 +503,20 @@ function renderAdminApp(
|
|
|
469
503
|
* to wait on. This is that thing, and it is the condition that actually gates the click
|
|
470
504
|
* rather than a proxy for it.
|
|
471
505
|
*/
|
|
506
|
+
/** A figure on the page, read by its label: its value, caption, delta and whether it leads. */
|
|
507
|
+
function figure(label: string) {
|
|
508
|
+
const stat = [...document.querySelectorAll('[data-terp="stat"]')].find(
|
|
509
|
+
(node) => node.querySelector('[data-terp="stat-label"]')?.textContent === label,
|
|
510
|
+
);
|
|
511
|
+
if (stat === undefined) return undefined;
|
|
512
|
+
return {
|
|
513
|
+
value: stat.querySelector('[data-terp="stat-value"]')?.textContent,
|
|
514
|
+
caption: stat.querySelector('[data-terp="stat-caption"]')?.textContent,
|
|
515
|
+
delta: stat.querySelector('[data-terp="stat-change"]')?.textContent,
|
|
516
|
+
headline: stat.hasAttribute("data-headline"),
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
|
|
472
520
|
async function enabledSubmitControl(): Promise<HTMLElement> {
|
|
473
521
|
const control = await screen.findByRole("button", { name: "Provision user" });
|
|
474
522
|
await waitFor(() => expect(control).toBeEnabled());
|
|
@@ -476,34 +524,205 @@ async function enabledSubmitControl(): Promise<HTMLElement> {
|
|
|
476
524
|
}
|
|
477
525
|
|
|
478
526
|
describe("the packaged admin area", () => {
|
|
479
|
-
it("serves the hub at /admin
|
|
480
|
-
renderAdminApp("/admin");
|
|
527
|
+
it("serves the hub at /admin as a dashboard: the figures, the areas, then the trail", async () => {
|
|
528
|
+
const { fetchMock } = renderAdminApp("/admin");
|
|
481
529
|
await waitFor(() =>
|
|
482
530
|
expect(screen.getByRole("heading", { level: 1, name: "Admin" })).toBeInTheDocument(),
|
|
483
531
|
);
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
//
|
|
488
|
-
|
|
489
|
-
|
|
532
|
+
for (const area of [/Users/, /Groups/, /Audit log/, /^Access/]) {
|
|
533
|
+
expect(screen.getByRole("link", { name: area })).toBeInTheDocument();
|
|
534
|
+
}
|
|
535
|
+
// The summary band's figures, each read by its label: the active accounts as a total under
|
|
536
|
+
// the status filter, with the rest deactivated; the groups; and the trail's last week
|
|
537
|
+
// against the week before, from one activity read.
|
|
538
|
+
await waitFor(() => expect(figure("Changes, last 7 days")?.value).toBe("21"));
|
|
539
|
+
expect(figure("Active accounts")).toMatchObject({ value: "5", caption: "2 deactivated", headline: true });
|
|
540
|
+
expect(figure("Groups")?.value).toBe("3");
|
|
541
|
+
// 21 against the 16 of the seven days just before. Mutation: those seven read a day off.
|
|
542
|
+
expect(figure("Changes, last 7 days")?.delta).toMatch(/(^|\D)5(\D|$)/);
|
|
543
|
+
// Then the trail per day against the days before, and the kinds of change in the app's words.
|
|
544
|
+
expect(screen.getByText("Changes per day")).toBeInTheDocument();
|
|
545
|
+
expect(screen.getByText("Changes by kind, last 30 days")).toBeInTheDocument();
|
|
546
|
+
expect(screen.getAllByText("Changed").length).toBeGreaterThan(0);
|
|
547
|
+
const reads = fetchMock.mock.calls.map((call) => new URL((call[0] as Request).url));
|
|
548
|
+
const activity = reads.find((url) => url.pathname.endsWith("/api/v1/audit/activity"))!;
|
|
549
|
+
expect(activity.searchParams.get("days")).toBe("30");
|
|
550
|
+
expect(activity.searchParams.get("time_zone")).toBe(
|
|
551
|
+
Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
552
|
+
);
|
|
490
553
|
// The sidebar carries the single admin-gated entry.
|
|
491
554
|
expect(screen.getByRole("link", { name: "Admin" })).toBeInTheDocument();
|
|
492
555
|
});
|
|
493
556
|
|
|
494
|
-
it("serves a capability-selective hub: dropped sections lose card,
|
|
495
|
-
const { fetchMock } = renderAdminApp("/admin", 30, { groups: false });
|
|
557
|
+
it("serves a capability-selective hub: dropped sections lose card, figure and read", async () => {
|
|
558
|
+
const { fetchMock } = renderAdminApp("/admin", 30, { groups: false, audit: false });
|
|
496
559
|
await waitFor(() =>
|
|
497
560
|
expect(screen.getByRole("heading", { level: 1, name: "Admin" })).toBeInTheDocument(),
|
|
498
561
|
);
|
|
499
562
|
expect(screen.getByRole("link", { name: /Users/ })).toBeInTheDocument();
|
|
500
|
-
expect(screen.getByRole("link", { name: /Audit log/ })).toBeInTheDocument();
|
|
501
563
|
expect(screen.queryByRole("link", { name: /Groups/ })).not.toBeInTheDocument();
|
|
502
|
-
|
|
503
|
-
//
|
|
504
|
-
|
|
564
|
+
expect(screen.queryByRole("link", { name: /Audit log/ })).not.toBeInTheDocument();
|
|
565
|
+
// The users figure still arrives; the groups and the trail are never read (their
|
|
566
|
+
// capabilities may not be mounted at all), and the audit section takes its charts along.
|
|
567
|
+
await waitFor(() => expect(figure("Active accounts")?.value).toBe("5"));
|
|
568
|
+
expect(figure("Groups")).toBeUndefined();
|
|
569
|
+
expect(figure("Changes, last 7 days")).toBeUndefined();
|
|
570
|
+
expect(screen.queryByText("Changes per day")).not.toBeInTheDocument();
|
|
505
571
|
const probed = fetchMock.mock.calls.map((call) => (call[0] as Request).url);
|
|
506
572
|
expect(probed.some((url) => url.includes("/api/v1/groups/"))).toBe(false);
|
|
573
|
+
expect(probed.some((url) => url.includes("/api/v1/audit/"))).toBe(false);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
it("keeps every other figure when one read fails (ADR 0171)", async () => {
|
|
577
|
+
const { fetchMock } = renderAdminApp("/admin");
|
|
578
|
+
const answer = fetchMock.getMockImplementation()!;
|
|
579
|
+
// The failing read lands last, after the others have drawn their figures, so a failure
|
|
580
|
+
// that took the page's other reads down with it shows here rather than being overwritten.
|
|
581
|
+
let fail!: () => void;
|
|
582
|
+
const failing = new Promise<void>((resolve) => (fail = resolve));
|
|
583
|
+
fetchMock.mockImplementation(async (input, init) => {
|
|
584
|
+
if (!new URL((input as Request).url).pathname.endsWith("/api/v1/groups/")) {
|
|
585
|
+
return answer(input, init);
|
|
586
|
+
}
|
|
587
|
+
await failing;
|
|
588
|
+
return jsonResponse({ detail: "unavailable" }, 503);
|
|
589
|
+
});
|
|
590
|
+
await waitFor(() => expect(figure("Changes, last 7 days")?.value).toBe("21"));
|
|
591
|
+
await waitFor(() => expect(figure("Active accounts")?.value).toBe("5"));
|
|
592
|
+
await act(async () => {
|
|
593
|
+
fail();
|
|
594
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
595
|
+
});
|
|
596
|
+
// Mutation: the reads awaited together behind one catch, so one failure dashed them all.
|
|
597
|
+
expect(figure("Changes, last 7 days")?.value).toBe("21");
|
|
598
|
+
expect(figure("Active accounts")?.value).toBe("5");
|
|
599
|
+
expect(figure("Groups")?.value).toBe("—");
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it("draws the days before as the comparison, not the last thirty again", async () => {
|
|
603
|
+
renderAdminApp("/admin");
|
|
604
|
+
const chart = await screen.findByRole("figure", { name: "Changes per day" });
|
|
605
|
+
const comparison = within(chart)
|
|
606
|
+
.getAllByRole("row")
|
|
607
|
+
.slice(1)
|
|
608
|
+
.map((row) => within(row).getAllByRole("cell").at(-1)!.textContent);
|
|
609
|
+
// Every day before counts 2 in the fixture; the last thirty never do all at once.
|
|
610
|
+
expect(comparison).toHaveLength(30);
|
|
611
|
+
expect(new Set(comparison)).toEqual(new Set(["2"]));
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it("counts the trail in the viewer's zone, whatever the host running the test is in", async () => {
|
|
615
|
+
const real = Intl.DateTimeFormat.prototype.resolvedOptions;
|
|
616
|
+
vi.spyOn(Intl.DateTimeFormat.prototype, "resolvedOptions").mockImplementation(function (
|
|
617
|
+
this: Intl.DateTimeFormat,
|
|
618
|
+
) {
|
|
619
|
+
return { ...real.call(this), timeZone: "Pacific/Chatham" };
|
|
620
|
+
});
|
|
621
|
+
const { fetchMock } = renderAdminApp("/admin");
|
|
622
|
+
await waitFor(() => expect(figure("Changes, last 7 days")?.value).toBe("21"));
|
|
623
|
+
const activity = fetchMock.mock.calls
|
|
624
|
+
.map((call) => new URL((call[0] as Request).url))
|
|
625
|
+
.find((url) => url.pathname.endsWith("/api/v1/audit/activity"))!;
|
|
626
|
+
expect(activity.searchParams.get("time_zone")).toBe("Pacific/Chatham");
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it("counts in UTC rather than drawing nothing when the server refuses the viewer's zone", async () => {
|
|
630
|
+
const real = Intl.DateTimeFormat.prototype.resolvedOptions;
|
|
631
|
+
vi.spyOn(Intl.DateTimeFormat.prototype, "resolvedOptions").mockImplementation(function (
|
|
632
|
+
this: Intl.DateTimeFormat,
|
|
633
|
+
) {
|
|
634
|
+
return { ...real.call(this), timeZone: "Etc/Unknown" };
|
|
635
|
+
});
|
|
636
|
+
const { fetchMock } = renderAdminApp("/admin");
|
|
637
|
+
const answer = fetchMock.getMockImplementation()!;
|
|
638
|
+
fetchMock.mockImplementation(async (input, init) => {
|
|
639
|
+
const url = new URL((input as Request).url);
|
|
640
|
+
return url.pathname.endsWith("/api/v1/audit/activity") &&
|
|
641
|
+
url.searchParams.get("time_zone") === "Etc/Unknown"
|
|
642
|
+
? jsonResponse({ detail: "'Etc/Unknown' is not a time zone this server knows." }, 400)
|
|
643
|
+
: answer(input, init);
|
|
644
|
+
});
|
|
645
|
+
// Mutation: no second read, and the figure keeps its dash with both charts gone.
|
|
646
|
+
await waitFor(() => expect(figure("Changes, last 7 days")?.value).toBe("21"));
|
|
647
|
+
expect(screen.getByRole("figure", { name: "Changes per day" })).toBeInTheDocument();
|
|
648
|
+
const zones = fetchMock.mock.calls
|
|
649
|
+
.map((call) => new URL((call[0] as Request).url))
|
|
650
|
+
.filter((url) => url.pathname.endsWith("/api/v1/audit/activity"))
|
|
651
|
+
.map((url) => url.searchParams.get("time_zone"));
|
|
652
|
+
expect(zones).toEqual(["Etc/Unknown", "UTC"]);
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
it("lays the area cards out on as many tracks as there are cards", async () => {
|
|
656
|
+
// Two cards on a fixed three left a blank third column; one card took a third of the row.
|
|
657
|
+
renderAdminApp("/admin", 30, { groups: false, audit: false });
|
|
658
|
+
const users = await screen.findByRole("link", { name: /Users/ });
|
|
659
|
+
expect(users.closest('[data-terp="grid"]')).toHaveAttribute("data-template", "1:1");
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
it("never counts fewer than no deactivated accounts", async () => {
|
|
663
|
+
// The total and the active count are two reads; an account made between them made -1.
|
|
664
|
+
const { fetchMock } = renderAdminApp("/admin", 30, { groups: false, audit: false });
|
|
665
|
+
const answer = fetchMock.getMockImplementation()!;
|
|
666
|
+
fetchMock.mockImplementation(async (input, init) => {
|
|
667
|
+
const url = new URL((input as Request).url);
|
|
668
|
+
return url.pathname.endsWith("/api/v1/users/") && url.searchParams.get("is_active") === "true"
|
|
669
|
+
? jsonResponse({ items: [], total: 8, skip: 0, limit: 1 })
|
|
670
|
+
: answer(input, init);
|
|
671
|
+
});
|
|
672
|
+
await waitFor(() => expect(figure("Active accounts")?.value).toBe("8"));
|
|
673
|
+
expect(figure("Active accounts")?.caption).toBe("0 deactivated");
|
|
674
|
+
});
|
|
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");
|
|
507
726
|
});
|
|
508
727
|
|
|
509
728
|
it("drops the access card with the access section, the one a full hub always drew", async () => {
|
|
@@ -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" });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import type { RefObject } from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Keeps a scrolling strip's current item in the strip's view: the strip scrolls, the page never
|
|
6
|
+
* does. Tab strips are one line that scrolls sideways where they do not fit (the sheet's Tabs and
|
|
7
|
+
* Module navigation notes), so a current tab can sit past the strip's edge, as the third of three
|
|
8
|
+
* on a phone does; this brings it back whenever the current item changes.
|
|
9
|
+
*
|
|
10
|
+
* Measured rather than delegated to `scrollIntoView`, which scrolls every scrollable ancestor up
|
|
11
|
+
* to the page. Where nothing is laid out (jsdom, a strip that fits) the boxes agree and it does
|
|
12
|
+
* nothing.
|
|
13
|
+
*/
|
|
14
|
+
export function useCurrentInView(
|
|
15
|
+
strip: RefObject<HTMLElement | null>,
|
|
16
|
+
current: string | undefined,
|
|
17
|
+
selector: string,
|
|
18
|
+
): void {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const list = strip.current;
|
|
21
|
+
const item = list?.querySelector<HTMLElement>(selector);
|
|
22
|
+
if (!list || !item) return;
|
|
23
|
+
const bounds = list.getBoundingClientRect();
|
|
24
|
+
const box = item.getBoundingClientRect();
|
|
25
|
+
if (box.left < bounds.left) list.scrollLeft -= bounds.left - box.left;
|
|
26
|
+
else if (box.right > bounds.right) list.scrollLeft += box.right - bounds.right;
|
|
27
|
+
}, [strip, current, selector]);
|
|
28
|
+
}
|
|
@@ -600,10 +600,16 @@ describe("DataView localisation", () => {
|
|
|
600
600
|
});
|
|
601
601
|
|
|
602
602
|
it("speaks the app's locale without a strings prop, and follows a switch", async () => {
|
|
603
|
+
// A smallest page of two, so four rows have pages and the page-size control is offered.
|
|
603
604
|
render(
|
|
604
605
|
<LocaleProvider locales={{ en: LOCALE_EN, nl: LOCALE_NL }}>
|
|
605
606
|
<LanguageSwitcher />
|
|
606
|
-
<DataView
|
|
607
|
+
<DataView
|
|
608
|
+
repository={inMemoryRepo()}
|
|
609
|
+
columns={COLUMNS}
|
|
610
|
+
pageSizeOptions={[2, 10]}
|
|
611
|
+
initialPageSize={10}
|
|
612
|
+
/>
|
|
607
613
|
</LocaleProvider>,
|
|
608
614
|
);
|
|
609
615
|
expect(await screen.findByText("1–4 of 4 results")).toBeInTheDocument();
|
|
@@ -938,3 +944,44 @@ describe("DataView's status history cell (ADR 0169 §6)", () => {
|
|
|
938
944
|
expect(histories[0]!.querySelector('[data-terp="status-history-latest"]')!.textContent).toBe("Failed");
|
|
939
945
|
});
|
|
940
946
|
});
|
|
947
|
+
|
|
948
|
+
describe("DataView page size", () => {
|
|
949
|
+
it("offers no page size for a collection that fits on its smallest page", async () => {
|
|
950
|
+
render(<DataView repository={inMemoryRepo()} columns={COLUMNS} />);
|
|
951
|
+
await screen.findByText("Broken printer");
|
|
952
|
+
// Four rows against a smallest page of ten: the control changed nothing. Mutation:
|
|
953
|
+
// offering it at any size.
|
|
954
|
+
expect(screen.queryByRole("button", { name: "Rows per page" })).not.toBeInTheDocument();
|
|
955
|
+
// The controls that work at any size stay.
|
|
956
|
+
expect(screen.getByRole("button", { name: "View options" })).toBeInTheDocument();
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
it("offers it where the rows are more than the smallest page holds", async () => {
|
|
960
|
+
render(<DataView repository={inMemoryRepo()} columns={COLUMNS} pageSizeOptions={[3, 10]} />);
|
|
961
|
+
await screen.findByText("Broken printer");
|
|
962
|
+
// Mutation: comparing with the largest option. (The page in force is 3 here too, so the
|
|
963
|
+
// test below is the one that tells it apart from the smallest option.)
|
|
964
|
+
expect(screen.getByRole("button", { name: "Rows per page" })).toBeInTheDocument();
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
it("offers it while the page in force is smaller than every option, and the view pages", async () => {
|
|
968
|
+
// Four rows on pages of three: two pages, and the default options all start at ten.
|
|
969
|
+
// Mutation: comparing with the smallest option alone, which hid the control and left the
|
|
970
|
+
// view paging with no way to show the rows at once.
|
|
971
|
+
render(<DataView repository={inMemoryRepo()} columns={COLUMNS} initialPageSize={3} />);
|
|
972
|
+
await screen.findByText("Broken printer");
|
|
973
|
+
expect(screen.getByRole("button", { name: "Rows per page" })).toBeInTheDocument();
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
it("keeps it while the total is not known yet", () => {
|
|
977
|
+
const repository: DataViewRepository<Ticket> = {
|
|
978
|
+
query: () => new Promise(() => {}),
|
|
979
|
+
getRowId: (ticket) => ticket.id,
|
|
980
|
+
capabilities: { serverSide: true, search: false, searchScope: false },
|
|
981
|
+
};
|
|
982
|
+
render(<DataView repository={repository} columns={COLUMNS} />);
|
|
983
|
+
// Mutation: reading an unknown total as none, which takes the control away during every
|
|
984
|
+
// first load and puts it back when a large collection arrives.
|
|
985
|
+
expect(screen.getByRole("button", { name: "Rows per page" })).toBeInTheDocument();
|
|
986
|
+
});
|
|
987
|
+
});
|
|
@@ -11,7 +11,7 @@ import { DataViewCardList } from "./DataViewCardList";
|
|
|
11
11
|
import { DataViewPagination } from "./DataViewPagination";
|
|
12
12
|
import type { DataViewRowActionsLayout } from "./DataViewRowActions";
|
|
13
13
|
import { DataViewTable } from "./DataViewTable";
|
|
14
|
-
import { DataViewToolbar } from "./DataViewToolbar";
|
|
14
|
+
import { DATA_VIEW_PAGE_SIZES, DataViewToolbar } from "./DataViewToolbar";
|
|
15
15
|
import { useDataViewQuery } from "./hooks/useDataViewQuery";
|
|
16
16
|
import { useDataViewState } from "./hooks/useDataViewState";
|
|
17
17
|
import type { DataViewControlledQuery } from "./hooks/useDataViewState";
|
|
@@ -485,6 +485,19 @@ function DataViewInner<T>(props: DataViewProps<T>) {
|
|
|
485
485
|
);
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
+
// A collection that fits on its smallest page has nothing to page through, so it is offered no
|
|
489
|
+
// page size: above a one-row table the control changed nothing and still led the toolbar.
|
|
490
|
+
// Only once the total is known, so the control does not blink out while the first page loads;
|
|
491
|
+
// the view and column controls stay at every size, since they work on any collection and a
|
|
492
|
+
// toolbar that rearranged itself as a filter narrowed the rows would move under the pointer.
|
|
493
|
+
// The page in force counts too: `initialPageSize`, a restored view or a server query can set
|
|
494
|
+
// one smaller than every option, and a view that pages must keep the control that ends it.
|
|
495
|
+
const smallestPage = Math.min(
|
|
496
|
+
...(props.pageSizeOptions ?? DATA_VIEW_PAGE_SIZES),
|
|
497
|
+
state.pagination.pageSize,
|
|
498
|
+
);
|
|
499
|
+
const fitsSmallestPage = totalCount !== undefined && totalCount <= smallestPage;
|
|
500
|
+
|
|
488
501
|
return (
|
|
489
502
|
<div data-terp="dataview" data-variant={variantAttribute} data-density={densityAttribute}>
|
|
490
503
|
{heading}
|
|
@@ -507,8 +520,10 @@ function DataViewInner<T>(props: DataViewProps<T>) {
|
|
|
507
520
|
onLayoutChange={setManualLayout}
|
|
508
521
|
pageSize={state.pagination.pageSize}
|
|
509
522
|
pageSizeOptions={props.pageSizeOptions}
|
|
510
|
-
onPageSizeChange={
|
|
511
|
-
|
|
523
|
+
onPageSizeChange={
|
|
524
|
+
fitsSmallestPage
|
|
525
|
+
? undefined
|
|
526
|
+
: (pageSize) => state.setPagination({ pageIndex: 0, pageSize })
|
|
512
527
|
}
|
|
513
528
|
selectedCount={selectedIds.size}
|
|
514
529
|
totalCount={totalCount ?? 0}
|
|
@@ -44,6 +44,9 @@ export interface DataViewToolbarProps<T> {
|
|
|
44
44
|
trailing?: ReactNode;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** The page sizes a view offers when its caller names none. */
|
|
48
|
+
export const DATA_VIEW_PAGE_SIZES: readonly number[] = [10, 25, 50, 100];
|
|
49
|
+
|
|
47
50
|
/**
|
|
48
51
|
* The DataView toolbar. In its normal mode it hosts search, caller filter controls,
|
|
49
52
|
* the page-size selector, the table/cards toggle and the column-settings menu; when
|
|
@@ -201,7 +204,7 @@ export function DataViewToolbar<T>(props: DataViewToolbarProps<T>) {
|
|
|
201
204
|
}
|
|
202
205
|
>
|
|
203
206
|
{(close) =>
|
|
204
|
-
(props.pageSizeOptions ??
|
|
207
|
+
(props.pageSizeOptions ?? DATA_VIEW_PAGE_SIZES).map((option) => (
|
|
205
208
|
<DataViewMenuItem
|
|
206
209
|
key={option}
|
|
207
210
|
label={String(option)}
|
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 {
|
|
@@ -11,6 +11,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
|
|
11
11
|
import * as lintLayouts from "../../eslint-boundaries/src/layouts.js";
|
|
12
12
|
|
|
13
13
|
import { BarChart } from "./charts/BarChart";
|
|
14
|
+
import { ConfirmDialog } from "./ConfirmDialog";
|
|
14
15
|
import { TrendChart } from "./charts/TrendChart";
|
|
15
16
|
import { DashboardPage } from "./DashboardPage";
|
|
16
17
|
import { DetailPage } from "./DetailPage";
|
|
@@ -32,6 +33,7 @@ import { Stat, StatGroup } from "./Stat";
|
|
|
32
33
|
import { StatusHistory } from "./charts/StatusHistory";
|
|
33
34
|
import { Badge } from "./ui/Badge";
|
|
34
35
|
import { OverviewPage } from "./OverviewPage";
|
|
36
|
+
import { CanvasHost, WorkspacePage } from "./WorkspacePage";
|
|
35
37
|
|
|
36
38
|
// The public surface, as source: the archetype-coverage check below derives its list from
|
|
37
39
|
// the entry point's own exports rather than restating one. `raw.d.ts` declares the ambient
|
|
@@ -185,6 +187,7 @@ describe("every archetype the package exports is governed, or says it is not", (
|
|
|
185
187
|
"Page",
|
|
186
188
|
"SettingsPage",
|
|
187
189
|
"SplitPage",
|
|
190
|
+
"WorkspacePage",
|
|
188
191
|
]);
|
|
189
192
|
});
|
|
190
193
|
|
|
@@ -432,10 +435,11 @@ describe("layout contract survives the roots the styling migration renames", ()
|
|
|
432
435
|
),
|
|
433
436
|
);
|
|
434
437
|
// The dashboard's body (ADR 0169 §4) added the figure and chart families -- the run history
|
|
435
|
-
// among the charts -- and the timeline.
|
|
438
|
+
// among the charts -- and the timeline. The workspace (ADR 0179) added its canvas host.
|
|
436
439
|
expect([...named].sort()).toEqual([
|
|
437
440
|
"alert",
|
|
438
441
|
"bar-chart",
|
|
442
|
+
"canvas-host",
|
|
439
443
|
"card",
|
|
440
444
|
"dataview",
|
|
441
445
|
"detail-list",
|
|
@@ -822,3 +826,60 @@ describe("the dashboard's body (ADR 0169 §4)", () => {
|
|
|
822
826
|
});
|
|
823
827
|
});
|
|
824
828
|
});
|
|
829
|
+
|
|
830
|
+
describe("the workspace's body (ADR 0179)", () => {
|
|
831
|
+
it("passes one canvas, whatever is drawn on it", async () => {
|
|
832
|
+
underContract(
|
|
833
|
+
<WorkspacePage title="Network">
|
|
834
|
+
<CanvasHost label="Network diagram">
|
|
835
|
+
{/* The host's subtree is the app's: an svg, or a canvas library's root. */}
|
|
836
|
+
<svg viewBox="0 0 100 100" role="img" aria-label="Two nodes">
|
|
837
|
+
<circle cx="20" cy="50" r="8" />
|
|
838
|
+
</svg>
|
|
839
|
+
</CanvasHost>
|
|
840
|
+
</WorkspacePage>,
|
|
841
|
+
);
|
|
842
|
+
await expectAccepted();
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
it("passes a framework state in the canvas's place", async () => {
|
|
846
|
+
underContract(
|
|
847
|
+
<WorkspacePage title="Network">
|
|
848
|
+
<EmptyState title="No nodes yet" />
|
|
849
|
+
</WorkspacePage>,
|
|
850
|
+
);
|
|
851
|
+
await expectAccepted();
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
it("passes a confirm dialog beside the canvas, for an action taken on it", async () => {
|
|
855
|
+
// Mutation: drop ConfirmDialog from the slot table, and deleting a node has nowhere to ask.
|
|
856
|
+
underContract(
|
|
857
|
+
<WorkspacePage title="Network">
|
|
858
|
+
<CanvasHost label="Network diagram">
|
|
859
|
+
<svg viewBox="0 0 100 100" role="img" aria-label="Two nodes" />
|
|
860
|
+
</CanvasHost>
|
|
861
|
+
<ConfirmDialog
|
|
862
|
+
open={false}
|
|
863
|
+
onOpenChange={() => {}}
|
|
864
|
+
onConfirm={() => {}}
|
|
865
|
+
title="Delete this node?"
|
|
866
|
+
/>
|
|
867
|
+
</WorkspacePage>,
|
|
868
|
+
);
|
|
869
|
+
await expectAccepted();
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
it("refuses anything beside or instead of the canvas, with the directive message", async () => {
|
|
873
|
+
// Mutation: drop the WorkspacePage slot table, and the workspace's body is unconstrained.
|
|
874
|
+
underContract(
|
|
875
|
+
<WorkspacePage title="Network">
|
|
876
|
+
<div>a canvas sized by hand</div>
|
|
877
|
+
</WorkspacePage>,
|
|
878
|
+
);
|
|
879
|
+
await waitFor(() => {
|
|
880
|
+
expect(screen.getByTestId("refused").textContent).toBe(
|
|
881
|
+
slotViolationMessage("standard", "WorkspacePage", "<div>"),
|
|
882
|
+
);
|
|
883
|
+
});
|
|
884
|
+
});
|
|
885
|
+
});
|
package/src/layoutContract.ts
CHANGED
|
@@ -50,6 +50,8 @@ export const LAYOUT_CONTRACTS: Readonly<Record<string, LayoutContractSpec>> = {
|
|
|
50
50
|
"collection; a split " +
|
|
51
51
|
"body is two SplitPanes and nothing else; and a dashboard body is its figures and " +
|
|
52
52
|
"charts in Grid sections, the collection they summarise and the framework states. " +
|
|
53
|
+
"A workspace body is one CanvasHost, the surface that fills the screen, the " +
|
|
54
|
+
"framework states and a ConfirmDialog. " +
|
|
53
55
|
"A screen that needs no contract " +
|
|
54
56
|
"composes the plain Page, whose body this contract deliberately leaves unconstrained. " +
|
|
55
57
|
"Every page, the plain one included, keeps two rules of its frame: its summary band " +
|
|
@@ -128,6 +130,16 @@ export const LAYOUT_CONTRACTS: Readonly<Record<string, LayoutContractSpec>> = {
|
|
|
128
130
|
ConfirmDialog: "dialog",
|
|
129
131
|
},
|
|
130
132
|
},
|
|
133
|
+
WorkspacePage: {
|
|
134
|
+
components: {
|
|
135
|
+
CanvasHost: "canvas-host",
|
|
136
|
+
EmptyState: "empty-state",
|
|
137
|
+
ErrorState: "error-state",
|
|
138
|
+
LoadingState: "loading-state",
|
|
139
|
+
Alert: "alert",
|
|
140
|
+
ConfirmDialog: "dialog",
|
|
141
|
+
},
|
|
142
|
+
},
|
|
131
143
|
DetailPage: {
|
|
132
144
|
components: {
|
|
133
145
|
DetailList: "detail-list",
|