@terpjs/react-core 0.30.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.
Files changed (82) hide show
  1. package/README.md +35 -14
  2. package/package.json +5 -5
  3. package/src/DashboardPage.tsx +34 -0
  4. package/src/Field.test.tsx +26 -1
  5. package/src/Field.tsx +15 -5
  6. package/src/HubPage.tsx +7 -2
  7. package/src/ModuleNav.test.tsx +29 -1
  8. package/src/ModuleNav.tsx +5 -1
  9. package/src/Page.test.tsx +192 -0
  10. package/src/Page.tsx +141 -55
  11. package/src/PageActions.test.tsx +64 -3
  12. package/src/PageActions.tsx +40 -15
  13. package/src/PageSequence.tsx +114 -0
  14. package/src/Stat.test.tsx +376 -0
  15. package/src/Stat.tsx +316 -0
  16. package/src/Timeline.test.tsx +74 -0
  17. package/src/Timeline.tsx +71 -0
  18. package/src/admin/AdminHub.tsx +233 -78
  19. package/src/admin/AuditLogAdmin.tsx +3 -1
  20. package/src/admin/GroupCreate.tsx +3 -1
  21. package/src/admin/GroupDetail.tsx +72 -67
  22. package/src/admin/GroupsAdmin.tsx +3 -1
  23. package/src/admin/ModuleAccessPanel.tsx +13 -12
  24. package/src/admin/RecordHistory.tsx +88 -0
  25. package/src/admin/UserCreate.tsx +3 -1
  26. package/src/admin/UserDetail.tsx +8 -1
  27. package/src/admin/UsersAdmin.tsx +3 -0
  28. package/src/admin/admin.test.tsx +389 -19
  29. package/src/bootstrap.test.tsx +31 -7
  30. package/src/bootstrap.tsx +30 -4
  31. package/src/charts/BarChart.tsx +74 -0
  32. package/src/charts/ProportionBar.tsx +118 -0
  33. package/src/charts/StatusHistory.tsx +75 -0
  34. package/src/charts/TrendChart.tsx +232 -0
  35. package/src/charts/charts.test.tsx +409 -0
  36. package/src/charts/scale.ts +103 -0
  37. package/src/currentInView.ts +28 -0
  38. package/src/dataview/DataView.test.tsx +303 -1
  39. package/src/dataview/DataView.tsx +53 -3
  40. package/src/dataview/DataViewCardList.tsx +21 -13
  41. package/src/dataview/DataViewTable.tsx +5 -6
  42. package/src/dataview/DataViewToolbar.tsx +4 -1
  43. package/src/dataview/README.md +18 -0
  44. package/src/dataview/index.ts +1 -0
  45. package/src/dataview/internal.tsx +112 -5
  46. package/src/dataview/types.ts +39 -10
  47. package/src/errorMessages.test.tsx +17 -0
  48. package/src/errorMessages.tsx +18 -0
  49. package/src/format.ts +15 -0
  50. package/src/index.ts +24 -1
  51. package/src/layout.manifest.json +2 -9
  52. package/src/layout.manifest.test.ts +4 -2
  53. package/src/layout.test.tsx +74 -6
  54. package/src/layout.tsx +85 -25
  55. package/src/layoutContract.test.tsx +239 -1
  56. package/src/layoutContract.ts +131 -5
  57. package/src/layoutDeclaration.test.ts +31 -10
  58. package/src/layoutDeclaration.ts +9 -4
  59. package/src/locale.tsx +28 -3
  60. package/src/markers.test.ts +70 -2
  61. package/src/router.test.tsx +15 -3
  62. package/src/router.tsx +11 -2
  63. package/src/ssr.test.tsx +18 -0
  64. package/src/styles.test.ts +288 -190
  65. package/src/styles.ts +1379 -361
  66. package/src/theme.test.tsx +44 -18
  67. package/src/theme.themes.test.ts +22 -2
  68. package/src/theme.tsx +22 -14
  69. package/src/themes.ts +39 -4
  70. package/src/tokens.guard.test.ts +13 -15
  71. package/src/typography.tsx +5 -1
  72. package/src/ui/Alert.test.tsx +24 -1
  73. package/src/ui/Alert.tsx +10 -1
  74. package/src/ui/Card.tsx +5 -4
  75. package/src/ui/Tabs.test.tsx +44 -0
  76. package/src/ui/Tabs.tsx +5 -2
  77. package/src/ui/Tooltip.test.tsx +171 -2
  78. package/src/ui/Tooltip.tsx +144 -8
  79. package/src/ui/controlMessages.tsx +20 -7
  80. package/src/uiText.test.tsx +16 -0
  81. package/src/uiText.tsx +105 -7
  82. package/src/viewerTimeZone.ts +15 -0
@@ -1,118 +1,273 @@
1
1
  import { Link } from "@tanstack/react-router";
2
2
  import { useEffect, useState } from "react";
3
3
 
4
- import { HubCard, HubPage } from "../HubPage";
4
+ import type { components } from "@terpjs/contract";
5
+
6
+ import { ProportionBar } from "../charts/ProportionBar";
7
+ import { TrendChart } from "../charts/TrendChart";
8
+ import type { ChartPoint } from "../charts/TrendChart";
9
+ import { DashboardPage } from "../DashboardPage";
10
+ import { useFormatDate, useFormatNumber } from "../format";
11
+ import { HubCard } from "../HubPage";
5
12
  import type { RenderHubCardLink } from "../HubPage";
6
13
  import type { AdminAreaSections } from "../bootstrap";
7
14
  import { NavIcon } from "../icons";
15
+ import { Grid } from "../layout";
16
+ import type { GridTemplate } from "../layout";
17
+ import { Stat, StatGroup } from "../Stat";
8
18
  import { useTerpClient } from "../TerpProvider";
9
19
  import { unwrap } from "../unwrap";
10
- import { useStrings } from "../uiText";
20
+ import { fillPlaceholders, useStrings } from "../uiText";
21
+ import { viewerTimeZone } from "../viewerTimeZone";
22
+ import { auditActionTone, auditActionWord } from "./RecordHistory";
23
+
24
+ type AuditActivityRead = components["schemas"]["AuditActivityRead"];
25
+ type AuditDayCount = components["schemas"]["AuditDayCount"];
11
26
 
12
27
  const renderLink: RenderHubCardLink = ({ to, children }) => <Link to={to}>{children}</Link>;
13
28
 
14
- interface HubStats {
15
- users: number | null;
29
+ /** The days the hub's activity chart draws; the read returns as many days before them too. */
30
+ const ACTIVITY_DAYS = 30;
31
+
32
+ /** The days the activity figure sums, read from the end of the same days. */
33
+ const FIGURE_DAYS = 7;
34
+
35
+ /** The area cards' tracks, one per card; a single card takes the row (`columns={1}`). */
36
+ const CARD_TEMPLATES: Record<number, GridTemplate> = { 2: "1:1", 3: "1:1:1", 4: "1:1:1:1" };
37
+
38
+ interface HubData {
39
+ accounts: number | null;
40
+ activeAccounts: number | null;
16
41
  groups: number | null;
42
+ activity: AuditActivityRead | null;
43
+ }
44
+
45
+ /** A `YYYY-MM-DD` day as that day, wherever the browser is: `new Date(day)` would read UTC. */
46
+ function localDay(isoDate: string): Date {
47
+ const [year, month, day] = isoDate.split("-").map(Number);
48
+ return new Date(year!, month! - 1, day!);
17
49
  }
18
50
 
19
51
  /**
20
- * Live totals for the hub cards (a `limit=1` page carries the exact total).
21
- * A section the app dropped never fires its call — its capability may not be
22
- * mounted at all.
52
+ * The hub's figures and the trail's activity, each read on its own so one that fails leaves the
53
+ * others standing. A section the app dropped never fires its reads: its capability may not be
54
+ * mounted at all. The active accounts are a total under the status filter, and the activity is
55
+ * counted on the server, so nothing is counted from a page in the browser.
23
56
  */
24
- function useHubStats(sections: Required<AdminAreaSections>): HubStats {
57
+ function useHubData(sections: Required<AdminAreaSections>): HubData {
25
58
  const client = useTerpClient();
26
- const [stats, setStats] = useState<HubStats>({ users: null, groups: null });
27
- const { users: wantUsers, groups: wantGroups } = sections;
59
+ const [data, setData] = useState<HubData>({
60
+ accounts: null,
61
+ activeAccounts: null,
62
+ groups: null,
63
+ activity: null,
64
+ });
65
+ const { users: wantUsers, groups: wantGroups, audit: wantAudit } = sections;
28
66
  useEffect(() => {
29
67
  const controller = new AbortController();
30
- void (async () => {
31
- try {
32
- const [users, groups] = await Promise.all([
33
- wantUsers
34
- ? client.GET("/api/v1/users/", {
35
- params: { query: { limit: 1 } },
36
- signal: controller.signal,
37
- })
38
- : null,
39
- wantGroups
40
- ? client.GET("/api/v1/groups/", {
41
- params: { query: { limit: 1 } },
42
- signal: controller.signal,
43
- })
44
- : null,
45
- ]);
46
- setStats({
47
- users: users !== null ? unwrap(users).total : null,
48
- groups: groups !== null ? unwrap(groups).total : null,
49
- });
50
- } catch {
51
- // The cards stay navigable without their stat lines (e.g. offline, races).
52
- }
53
- })();
68
+ const signal = controller.signal;
69
+ const keep = <K extends keyof HubData>(key: K, read: () => Promise<HubData[K]>) => {
70
+ void read().then(
71
+ (value) => {
72
+ if (!signal.aborted) setData((current) => ({ ...current, [key]: value }));
73
+ },
74
+ // The page stays usable without the figure: it keeps its dash (offline, a race).
75
+ () => undefined,
76
+ );
77
+ };
78
+ if (wantUsers) {
79
+ keep("accounts", async () =>
80
+ unwrap(await client.GET("/api/v1/users/", { params: { query: { limit: 1 } }, signal })).total,
81
+ );
82
+ keep("activeAccounts", async () =>
83
+ unwrap(
84
+ await client.GET("/api/v1/users/", {
85
+ params: { query: { is_active: true, limit: 1 } },
86
+ signal,
87
+ }),
88
+ ).total,
89
+ );
90
+ }
91
+ if (wantGroups) {
92
+ keep("groups", async () =>
93
+ unwrap(await client.GET("/api/v1/groups/", { params: { query: { limit: 1 } }, signal })).total,
94
+ );
95
+ }
96
+ if (wantAudit) {
97
+ keep("activity", async () => {
98
+ const read = (time_zone: string) =>
99
+ client.GET("/api/v1/audit/activity", {
100
+ params: { query: { days: ACTIVITY_DAYS, time_zone } },
101
+ signal,
102
+ });
103
+ const zone = viewerTimeZone();
104
+ const answer = await read(zone);
105
+ // A zone the server's database does not know is refused (400). Counted in UTC the
106
+ // trail is a day off at worst; refused, the figure kept its dash and both charts were
107
+ // gone, with nothing on the page to say why.
108
+ if (answer.response.status === 400 && zone !== "UTC") return unwrap(await read("UTC"));
109
+ return unwrap(answer);
110
+ });
111
+ }
54
112
  return () => controller.abort();
55
- }, [client, wantUsers, wantGroups]);
56
- return stats;
113
+ }, [client, wantUsers, wantGroups, wantAudit]);
114
+ return data;
115
+ }
116
+
117
+ function sum(days: readonly AuditDayCount[]): number {
118
+ return days.reduce((total, day) => total + day.count, 0);
57
119
  }
58
120
 
59
121
  /**
60
- * The packaged admin hub (`/admin`): one card per administration area — users,
61
- * groups and the audit log — with live totals where they are cheap to know.
62
- * The sidebar's single "Admin" entry opens this hub; the overviews breadcrumb
63
- * back to it, keeping the hub -> overview -> detail layering every Terp screen
64
- * follows. `sections` (default: all) mirrors the app's `adminArea` selection —
65
- * a dropped section loses its card and its stat call.
122
+ * The packaged admin hub (`/admin`): a dashboard of the administration (ADR 0171). The summary
123
+ * band carries the active accounts — the headline — the groups and the trail's last week; the
124
+ * areas follow as cards, getting to one being the hub's first job; then the trail per day
125
+ * against the days before, and the kinds of change. The sidebar's single "Admin" entry opens
126
+ * it, and the overviews breadcrumb back to it, keeping the hub -> overview -> detail layering
127
+ * every Terp screen follows. `sections` (default: all) mirrors the app's `adminArea` selection:
128
+ * a dropped section loses its card, its figure, its reads and, for the audit log, its charts.
66
129
  */
67
130
  export function AdminHub({ sections }: { sections?: AdminAreaSections } = {}) {
68
131
  const strings = useStrings();
132
+ const formatDate = useFormatDate();
133
+ const formatNumber = useFormatNumber();
69
134
  const selected = {
70
135
  users: sections?.users !== false,
71
136
  groups: sections?.groups !== false,
72
137
  audit: sections?.audit !== false,
73
138
  access: sections?.access !== false,
74
139
  };
75
- const stats = useHubStats(selected);
140
+ const data = useHubData(selected);
141
+ const activity = data.activity;
142
+ const points = (days: readonly AuditDayCount[]): ChartPoint[] =>
143
+ days.map((day) => ({ label: formatDate(localDay(day.date)), value: day.count }));
144
+ const lastWeek = activity === null ? null : activity.days.slice(-FIGURE_DAYS);
145
+ const weekBefore =
146
+ activity === null ? null : activity.days.slice(-2 * FIGURE_DAYS, -FIGURE_DAYS);
147
+ // Two reads that run side by side, so an account made between them could make this -1.
148
+ const deactivated =
149
+ data.accounts === null || data.activeAccounts === null
150
+ ? null
151
+ : Math.max(0, data.accounts - data.activeAccounts);
152
+
153
+ const figures = [
154
+ selected.users && (
155
+ <Stat
156
+ key="accounts"
157
+ headline
158
+ label={strings.adminHubActiveAccounts}
159
+ value={data.activeAccounts}
160
+ caption={
161
+ deactivated === null
162
+ ? undefined
163
+ : fillPlaceholders(strings.adminHubDeactivated, { count: formatNumber(deactivated) })
164
+ }
165
+ />
166
+ ),
167
+ selected.groups && <Stat key="groups" label={strings.adminGroups} value={data.groups} />,
168
+ selected.audit && (
169
+ <Stat
170
+ key="changes"
171
+ label={fillPlaceholders(strings.adminHubChangesWeek, { count: formatNumber(FIGURE_DAYS) })}
172
+ value={lastWeek === null ? null : sum(lastWeek)}
173
+ delta={
174
+ lastWeek === null || weekBefore === null
175
+ ? undefined
176
+ : {
177
+ value: sum(lastWeek) - sum(weekBefore),
178
+ sentiment: "neutral",
179
+ label: strings.adminHubVsWeekBefore,
180
+ }
181
+ }
182
+ trend={lastWeek === null ? undefined : points(lastWeek)}
183
+ />
184
+ ),
185
+ ].filter(Boolean);
186
+
187
+ const cards = [
188
+ selected.users && (
189
+ <HubCard
190
+ key="users"
191
+ to="/admin/users"
192
+ title={strings.adminUsers}
193
+ description={strings.adminUsersDescription}
194
+ icon={<NavIcon name="users" label={strings.adminUsers} />}
195
+ renderLink={renderLink}
196
+ />
197
+ ),
198
+ selected.groups && (
199
+ <HubCard
200
+ key="groups"
201
+ to="/admin/groups"
202
+ title={strings.adminGroups}
203
+ description={strings.adminGroupsDescription}
204
+ icon={<NavIcon name="shield" label={strings.adminGroups} />}
205
+ renderLink={renderLink}
206
+ />
207
+ ),
208
+ selected.audit && (
209
+ <HubCard
210
+ key="audit"
211
+ to="/admin/audit"
212
+ title={strings.adminAudit}
213
+ description={strings.adminAuditDescription}
214
+ icon={<NavIcon name="audit" label={strings.adminAudit} />}
215
+ renderLink={renderLink}
216
+ />
217
+ ),
218
+ selected.access && (
219
+ <HubCard
220
+ key="access"
221
+ to="/admin/access"
222
+ title={strings.adminAccess}
223
+ description={strings.adminAccessDescription}
224
+ icon={<NavIcon name="shield" label={strings.adminAccess} />}
225
+ renderLink={renderLink}
226
+ />
227
+ ),
228
+ ].filter(Boolean);
229
+
76
230
  return (
77
- <HubPage title={strings.admin} parents={[{ label: strings.home, to: "/" }]}>
78
- {selected.users && (
79
- <HubCard
80
- to="/admin/users"
81
- title={strings.adminUsers}
82
- description={strings.adminUsersDescription}
83
- icon={<NavIcon name="users" label={strings.adminUsers} />}
84
- stat={stats.users !== null ? String(stats.users) : undefined}
85
- renderLink={renderLink}
86
- />
87
- )}
88
- {selected.groups && (
89
- <HubCard
90
- to="/admin/groups"
91
- title={strings.adminGroups}
92
- description={strings.adminGroupsDescription}
93
- icon={<NavIcon name="shield" label={strings.adminGroups} />}
94
- stat={stats.groups !== null ? String(stats.groups) : undefined}
95
- renderLink={renderLink}
96
- />
231
+ <DashboardPage
232
+ title={strings.admin}
233
+ parents={[{ label: strings.home, to: "/" }]}
234
+ summary={figures.length > 0 ? <StatGroup>{figures}</StatGroup> : undefined}
235
+ >
236
+ {/* As many tracks as cards: a fixed three left a blank column beside two cards and gave
237
+ one card a third of the row. */}
238
+ {cards.length > 1 ? (
239
+ <Grid as="ul" template={CARD_TEMPLATES[cards.length]}>
240
+ {cards}
241
+ </Grid>
242
+ ) : (
243
+ <Grid as="ul" columns={1}>
244
+ {cards}
245
+ </Grid>
97
246
  )}
98
- {selected.audit && (
99
- <HubCard
100
- to="/admin/audit"
101
- title={strings.adminAudit}
102
- description={strings.adminAuditDescription}
103
- icon={<NavIcon name="audit" label={strings.adminAudit} />}
104
- renderLink={renderLink}
247
+ {selected.audit && activity !== null && (
248
+ <TrendChart
249
+ label={strings.adminHubChangesPerDay}
250
+ mark="columns"
251
+ series={{
252
+ label: fillPlaceholders(strings.adminHubLastDays, { count: formatNumber(ACTIVITY_DAYS) }),
253
+ points: points(activity.days),
254
+ }}
255
+ comparison={{
256
+ label: fillPlaceholders(strings.adminHubDaysBefore, { count: formatNumber(ACTIVITY_DAYS) }),
257
+ points: points(activity.previous_days),
258
+ }}
105
259
  />
106
260
  )}
107
- {selected.access && (
108
- <HubCard
109
- to="/admin/access"
110
- title={strings.adminAccess}
111
- description={strings.adminAccessDescription}
112
- icon={<NavIcon name="shield" label={strings.adminAccess} />}
113
- renderLink={renderLink}
261
+ {selected.audit && activity !== null && activity.by_action.length > 0 && (
262
+ <ProportionBar
263
+ label={fillPlaceholders(strings.adminHubChangesByKind, { count: formatNumber(ACTIVITY_DAYS) })}
264
+ parts={activity.by_action.map((row) => ({
265
+ label: auditActionWord(strings, row.action),
266
+ value: row.count,
267
+ tone: auditActionTone(row.action),
268
+ }))}
114
269
  />
115
270
  )}
116
- </HubPage>
271
+ </DashboardPage>
117
272
  );
118
273
  }
@@ -13,6 +13,7 @@ import type { TerpStrings } from "../uiText";
13
13
  import { unwrap } from "../unwrap";
14
14
 
15
15
  import { adminCrumb, renderAdminCrumb } from "./crumbs";
16
+ import { auditActionWord } from "./RecordHistory";
16
17
 
17
18
  type AuditEventRead = components["schemas"]["AuditEventRead"];
18
19
 
@@ -31,7 +32,8 @@ function buildColumns(
31
32
  {
32
33
  id: "action",
33
34
  header: strings.actionColumn,
34
- accessor: (e) => e.action,
35
+ // The app's words for the four actions, as a record's history says them.
36
+ accessor: (e) => auditActionWord(strings, e.action),
35
37
  meta: { mobileSlot: "status", width: "xs" },
36
38
  },
37
39
  {
@@ -11,6 +11,7 @@ import { useTerpClient } from "../TerpProvider";
11
11
  import { useToast } from "../toast";
12
12
  import { Button } from "../ui/Button";
13
13
  import { Input } from "../ui/Input";
14
+ import { useErrorMessage } from "../errorMessages";
14
15
  import { useStrings } from "../uiText";
15
16
  import { unwrap } from "../unwrap";
16
17
 
@@ -27,6 +28,7 @@ export function GroupCreate() {
27
28
  const client = useTerpClient();
28
29
  const navigate = useNavigate();
29
30
  const strings = useStrings();
31
+ const messageForCode = useErrorMessage();
30
32
  const toast = useToast();
31
33
  const [name, setName] = useState("");
32
34
  const [description, setDescription] = useState("");
@@ -54,7 +56,7 @@ export function GroupCreate() {
54
56
  const { shown, leftover } = routeFieldErrors(error, RENDERED_FIELDS);
55
57
  setFieldErrors(shown);
56
58
  if (Object.keys(shown).length === 0 || leftover) {
57
- toast.warning(error instanceof Error ? error.message : strings.requestFailed);
59
+ toast.warning(messageForCode(error) ?? (error instanceof Error ? error.message : strings.requestFailed));
58
60
  }
59
61
  } finally {
60
62
  setCreating(false);
@@ -18,10 +18,12 @@ import { useToast } from "../toast";
18
18
  import { Button } from "../ui/Button";
19
19
  import { Input } from "../ui/Input";
20
20
  import { useFormatDate, useFormatDateTime } from "../format";
21
+ import { useErrorMessage } from "../errorMessages";
21
22
  import { useStrings } from "../uiText";
22
23
  import { ApiError, unwrap } from "../unwrap";
23
24
 
24
25
  import { ModuleAccessPanel } from "./ModuleAccessPanel";
26
+ import { RecordHistory } from "./RecordHistory";
25
27
  import { adminCrumb, renderAdminCrumb } from "./crumbs";
26
28
 
27
29
  type GroupRead = components["schemas"]["GroupRead"];
@@ -47,6 +49,7 @@ export function GroupDetail() {
47
49
  const navigate = useNavigate();
48
50
  const toast = useToast();
49
51
  const strings = useStrings();
52
+ const messageForCode = useErrorMessage();
50
53
  const suggestionsId = useId();
51
54
 
52
55
  const formatDate = useFormatDate();
@@ -193,7 +196,7 @@ export function GroupDetail() {
193
196
  );
194
197
 
195
198
  function failed(error: unknown): void {
196
- toast.warning(error instanceof Error ? error.message : strings.requestFailed);
199
+ toast.warning(messageForCode(error) ?? (error instanceof Error ? error.message : strings.requestFailed));
197
200
  }
198
201
 
199
202
  /**
@@ -366,7 +369,9 @@ export function GroupDetail() {
366
369
  >
367
370
  <Stack gap={6}>
368
371
  {record !== null && (
372
+ // The group's facts as a ruled sheet (ADR 0169 §5), above its access and collections.
369
373
  <DetailList
374
+ layout="grid"
370
375
  items={[
371
376
  { label: strings.description, value: record.description || "-" },
372
377
  { label: strings.members, value: record.member_count },
@@ -380,72 +385,72 @@ export function GroupDetail() {
380
385
  // members through the same expansion that already carries the group's grants.
381
386
  <ModuleAccessPanel subjectId={record.id} />
382
387
  )}
383
- <Stack gap={3}>
384
- <h2 data-terp="admin-section-title">
385
- {strings.members}
386
- </h2>
387
- <Stack as="form" direction="row" gap={2} align="end" wrap onSubmit={onAddMember}>
388
- <Field label={strings.userField} error={memberError}>
389
- <Input
390
- type="email"
391
- value={memberQuery}
392
- list={suggestionsId}
393
- placeholder={strings.email}
394
- onChange={(event) => setMemberQuery(event.target.value)}
395
- required
396
- />
397
- </Field>
398
- <datalist id={suggestionsId}>
399
- {suggestions.map((user) => (
400
- <option key={user.id} value={user.email} />
401
- ))}
402
- </datalist>
403
- <Button type="submit" disabled={adding || memberQuery.trim() === ""}>
404
- {adding ? strings.working : strings.addMember}
405
- </Button>
406
- </Stack>
407
- <DataView<GroupMemberRead>
408
- variant="embedded"
409
- repository={membersRepository}
410
- columns={memberColumns}
411
- rowActions={(member) => [
412
- {
413
- label: strings.removeMember,
414
- variant: "destructive",
415
- onClick: () => setPendingMember(member),
416
- },
417
- ]}
418
- />
419
- </Stack>
420
- <Stack gap={3}>
421
- <h2 data-terp="admin-section-title">
422
- {strings.permissions}
423
- </h2>
424
- <Stack as="form" direction="row" gap={2} align="end" wrap onSubmit={onGrant}>
425
- <Field label={strings.permission} error={permissionError}>
426
- <Input
427
- value={permission}
428
- onChange={(event) => setPermission(event.target.value)}
429
- required
430
- />
431
- </Field>
432
- <Button type="submit" disabled={granting}>
433
- {granting ? strings.working : strings.grantPermission}
434
- </Button>
435
- </Stack>
436
- <DataView<GrantRead>
437
- variant="embedded"
438
- repository={grantsRepository}
439
- columns={grantColumns}
440
- rowActions={(grant) => [
441
- {
442
- label: strings.revoke,
443
- variant: "destructive",
444
- onClick: () => setPendingGrant(grant),
445
- },
446
- ]}
447
- />
448
- </Stack>
388
+ {/* The collection names itself and counts itself (ADR 0169 §5), and the way to add to it
389
+ sits in its toolbar, between its name and its rows. */}
390
+ <DataView<GroupMemberRead>
391
+ title={strings.members}
392
+ variant="embedded"
393
+ repository={membersRepository}
394
+ columns={memberColumns}
395
+ rowActions={(member) => [
396
+ {
397
+ label: strings.removeMember,
398
+ variant: "destructive",
399
+ onClick: () => setPendingMember(member),
400
+ },
401
+ ]}
402
+ toolbarContent={
403
+ <Stack as="form" direction="row" gap={2} align="end" wrap onSubmit={onAddMember}>
404
+ <Field label={strings.userField} error={memberError}>
405
+ <Input
406
+ type="email"
407
+ value={memberQuery}
408
+ list={suggestionsId}
409
+ placeholder={strings.email}
410
+ onChange={(event) => setMemberQuery(event.target.value)}
411
+ required
412
+ />
413
+ </Field>
414
+ <datalist id={suggestionsId}>
415
+ {suggestions.map((user) => (
416
+ <option key={user.id} value={user.email} />
417
+ ))}
418
+ </datalist>
419
+ <Button type="submit" disabled={adding || memberQuery.trim() === ""}>
420
+ {adding ? strings.working : strings.addMember}
421
+ </Button>
422
+ </Stack>
423
+ }
424
+ />
425
+ <DataView<GrantRead>
426
+ title={strings.permissions}
427
+ variant="embedded"
428
+ repository={grantsRepository}
429
+ columns={grantColumns}
430
+ rowActions={(grant) => [
431
+ {
432
+ label: strings.revoke,
433
+ variant: "destructive",
434
+ onClick: () => setPendingGrant(grant),
435
+ },
436
+ ]}
437
+ toolbarContent={
438
+ <Stack as="form" direction="row" gap={2} align="end" wrap onSubmit={onGrant}>
439
+ <Field label={strings.permission} error={permissionError}>
440
+ <Input
441
+ value={permission}
442
+ onChange={(event) => setPermission(event.target.value)}
443
+ required
444
+ />
445
+ </Field>
446
+ <Button type="submit" disabled={granting}>
447
+ {granting ? strings.working : strings.grantPermission}
448
+ </Button>
449
+ </Stack>
450
+ }
451
+ />
452
+ {/* The group's own history from the audit trail, newest first (ADR 0169 §5). */}
453
+ {record !== null && <RecordHistory targetType="Group" targetId={record.id} />}
449
454
  </Stack>
450
455
  <ConfirmDialog
451
456
  open={deleteOpen}
@@ -34,7 +34,9 @@ function buildColumns(
34
34
  id: "member_count",
35
35
  header: strings.members,
36
36
  accessor: (g) => g.member_count,
37
- meta: { mobileSlot: "status", width: "sm" },
37
+ // Group sizes compared at a glance, each still printed (ADR 0169 §5).
38
+ bar: true,
39
+ meta: { mobileSlot: "status", width: "md" },
38
40
  },
39
41
  {
40
42
  id: "created_at",
@@ -292,7 +292,7 @@ export function ModuleAccessPanel({ subjectId, globalRank = null }: ModuleAccess
292
292
 
293
293
  return (
294
294
  <Stack gap={3}>
295
- <h2 data-terp="admin-section-title">{strings.moduleAccessTitle}</h2>
295
+ <h3 data-terp="admin-section-title">{strings.moduleAccessTitle}</h3>
296
296
  <span data-terp="tile-note">{strings.moduleAccessDescription}</span>
297
297
  {(loading || (settled < 0 && heldError === null)) && <LoadingState />}
298
298
  {!loading && error !== null && <Alert tone="danger">{error}</Alert>}
@@ -303,15 +303,12 @@ export function ModuleAccessPanel({ subjectId, globalRank = null }: ModuleAccess
303
303
  <Alert tone="danger">{heldError}</Alert>
304
304
  )}
305
305
  {orphaned.map((entry) => (
306
- <Stack key={`orphan:${entry.module}`} gap={2}>
307
- <Alert tone="warning">
308
- {strings.moduleAccessOrphaned
309
- .replace("{role}", entry.role ?? String(entry.role_rank))
310
- .replace("{module}", entry.module)}
311
- </Alert>
312
- <Stack direction="row" gap={2}>
313
- {/* The only action the declarations still permit here, so it is the only one
314
- offered — a strip would hold rungs the server would refuse to store. */}
306
+ <Alert
307
+ key={`orphan:${entry.module}`}
308
+ tone="warning"
309
+ actions={
310
+ // The only action the declarations still permit here, so it is the only one
311
+ // offered — a strip would hold rungs the server would refuse to store.
315
312
  <Button
316
313
  variant="danger"
317
314
  disabled={busy || settling}
@@ -321,8 +318,12 @@ export function ModuleAccessPanel({ subjectId, globalRank = null }: ModuleAccess
321
318
  >
322
319
  {strings.revoke}
323
320
  </Button>
324
- </Stack>
325
- </Stack>
321
+ }
322
+ >
323
+ {strings.moduleAccessOrphaned
324
+ .replace("{role}", entry.role ?? String(entry.role_rank))
325
+ .replace("{module}", entry.module)}
326
+ </Alert>
326
327
  ))}
327
328
  {!loading && settled >= 0 && error === null && assignable.length === 0 && (
328
329
  <Alert tone="info">{strings.moduleAccessNoneAssignable}</Alert>