@terpjs/react-core 0.31.0 → 0.32.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/package.json +2 -2
- package/src/ModuleNav.test.tsx +29 -1
- package/src/ModuleNav.tsx +5 -1
- package/src/Stat.test.tsx +35 -0
- package/src/Stat.tsx +3 -1
- package/src/admin/AdminHub.tsx +233 -86
- package/src/admin/RecordHistory.tsx +5 -0
- package/src/admin/admin.test.tsx +181 -14
- 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/locale.tsx +8 -0
- package/src/styles.test.ts +66 -0
- package/src/styles.ts +92 -14
- 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,153 @@ 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");
|
|
507
674
|
});
|
|
508
675
|
|
|
509
676
|
it("drops the access card with the access section, the one a full hub always drew", async () => {
|
|
@@ -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/locale.tsx
CHANGED
|
@@ -225,6 +225,14 @@ export const LOCALE_NL: LocaleCatalog = {
|
|
|
225
225
|
statUnfavourable: "ongunstig",
|
|
226
226
|
statTrend: "Verloop: {points}",
|
|
227
227
|
adminHubTotal: "Totaal",
|
|
228
|
+
adminHubActiveAccounts: "Actieve accounts",
|
|
229
|
+
adminHubDeactivated: "{count} gedeactiveerd",
|
|
230
|
+
adminHubChangesWeek: "Wijzigingen, afgelopen {count} dagen",
|
|
231
|
+
adminHubVsWeekBefore: "t.o.v. de week ervoor",
|
|
232
|
+
adminHubChangesPerDay: "Wijzigingen per dag",
|
|
233
|
+
adminHubLastDays: "Afgelopen {count} dagen",
|
|
234
|
+
adminHubDaysBefore: "De {count} dagen ervoor",
|
|
235
|
+
adminHubChangesByKind: "Wijzigingen per soort, afgelopen {count} dagen",
|
|
228
236
|
statusHistoryRuns: "{label}, oudste eerst: {runs}",
|
|
229
237
|
recordHistory: "Geschiedenis",
|
|
230
238
|
auditActionCreated: "Aangemaakt",
|
package/src/styles.test.ts
CHANGED
|
@@ -2416,3 +2416,69 @@ describe("cascade structure", () => {
|
|
|
2416
2416
|
}
|
|
2417
2417
|
});
|
|
2418
2418
|
});
|
|
2419
|
+
|
|
2420
|
+
describe("what a review of the screens in use changed", () => {
|
|
2421
|
+
const base = layerBody("terp.base");
|
|
2422
|
+
const always = baseOnly(base);
|
|
2423
|
+
const ruleBody = (body: string, selector: string) => {
|
|
2424
|
+
const match = [...body.matchAll(/([^{}]+)\{([^{}]*)\}/g)].find(
|
|
2425
|
+
(rule) => rule[1]!.trim().replace(/\s+/g, " ") === selector,
|
|
2426
|
+
);
|
|
2427
|
+
expect(match, `${selector} has no rule of its own`).toBeDefined();
|
|
2428
|
+
return match![2]!;
|
|
2429
|
+
};
|
|
2430
|
+
|
|
2431
|
+
it("lays a tab strip out as one line that scrolls, never a wrap", () => {
|
|
2432
|
+
for (const selector of ['[data-terp="tab-list"]', '[data-terp="module-nav-list"]']) {
|
|
2433
|
+
const rule = ruleBody(always, selector);
|
|
2434
|
+
// Mutation: flex-wrap back to wrap, which splits the strip and its rule apart on a phone.
|
|
2435
|
+
expect(rule, selector).toContain("flex-wrap: nowrap");
|
|
2436
|
+
expect(rule, selector).toContain("overflow-x: auto");
|
|
2437
|
+
// The focus ring's room inside the scroll container, given back outside it.
|
|
2438
|
+
expect(rule, selector).toContain("padding: var(--space-1)");
|
|
2439
|
+
expect(rule, selector).toContain("margin: calc(-1 * var(--space-1))");
|
|
2440
|
+
}
|
|
2441
|
+
// The tab strip's rule is drawn inside its content box: a border would be clipped by the
|
|
2442
|
+
// scroll container, and the selected tab's edge with it.
|
|
2443
|
+
const tabList = ruleBody(always, '[data-terp="tab-list"]');
|
|
2444
|
+
expect(tabList).not.toContain("border-block-end");
|
|
2445
|
+
expect(tabList).toContain("linear-gradient(var(--color-neutral-200), var(--color-neutral-200))");
|
|
2446
|
+
expect(ruleBody(always, '[data-terp="tab"]')).not.toContain("margin-block-end: -1px");
|
|
2447
|
+
expect(ruleBody(always, '[data-terp="module-nav-link"]')).toContain("white-space: nowrap");
|
|
2448
|
+
});
|
|
2449
|
+
|
|
2450
|
+
it("lets a badge wrap inside its container, and keeps one line a pill", () => {
|
|
2451
|
+
const badge = ruleBody(always, '[data-terp="badge"]');
|
|
2452
|
+
// Mutation: nowrap back, or no cap, which let a long label run out of a phone's column.
|
|
2453
|
+
expect(badge).not.toContain("white-space: nowrap");
|
|
2454
|
+
expect(badge).toContain("max-inline-size: 100%");
|
|
2455
|
+
// A radius above half a one-line badge's height clamps to a full round; a full radius
|
|
2456
|
+
// would make a two-line badge a lozenge.
|
|
2457
|
+
expect(badge).toContain("border-radius: var(--radius-lg)");
|
|
2458
|
+
});
|
|
2459
|
+
|
|
2460
|
+
it("breaks a badge inside a word only when the word alone does not fit", () => {
|
|
2461
|
+
const badge = ruleBody(always, '[data-terp="badge"]');
|
|
2462
|
+
// Measured in Chromium: with `anywhere` a badge's narrowest width is one glyph, so a
|
|
2463
|
+
// squeezed auto-layout table split "Cancelled" mid-word into a 43x56 box; with
|
|
2464
|
+
// break-word on an inline block it stays the 75x23 pill. An inline flex keeps the
|
|
2465
|
+
// longest word too, but no longer breaks a single word wider than its column.
|
|
2466
|
+
expect(badge).toContain("overflow-wrap: break-word");
|
|
2467
|
+
expect(badge).toContain("display: inline-block");
|
|
2468
|
+
expect(badge).not.toContain("anywhere");
|
|
2469
|
+
});
|
|
2470
|
+
|
|
2471
|
+
it("closes up a band's rows of figures on a narrow screen, two to a line still", () => {
|
|
2472
|
+
const narrow = mediaBodies(base, NARROW_VIEWPORT);
|
|
2473
|
+
const group = ruleBody(narrow, '[data-terp="stat-group"]');
|
|
2474
|
+
// Mutations: the full gap kept between rows on a phone, or the band's full padding.
|
|
2475
|
+
expect(group).toContain("row-gap: var(--space-2)");
|
|
2476
|
+
expect(ruleBody(narrow, '[data-terp="page-summary"]')).toContain("padding-block: var(--space-3)");
|
|
2477
|
+
// Two to a line stays: a third column broke a figure like "4 m 12 s" over two lines.
|
|
2478
|
+
// Mutation: a narrower floor for the phone.
|
|
2479
|
+
expect(group).not.toContain("grid-template-columns");
|
|
2480
|
+
expect(ruleBody(always, '[data-terp="stat-group"]')).toContain(
|
|
2481
|
+
"grid-template-columns: repeat(auto-fit, minmax(min(9.5rem, 100%), 1fr))",
|
|
2482
|
+
);
|
|
2483
|
+
});
|
|
2484
|
+
});
|