@terpjs/react-core 0.18.0 → 0.20.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 +11 -11
- package/src/Authorized.tsx +20 -5
- package/src/Field.tsx +11 -22
- package/src/TerpProvider.tsx +13 -2
- package/src/admin/AccessAdmin.tsx +118 -0
- package/src/admin/AdminHub.tsx +10 -0
- package/src/admin/GroupDetail.tsx +7 -0
- package/src/admin/ModuleAccessPanel.tsx +349 -0
- package/src/admin/UserCreate.tsx +16 -6
- package/src/admin/UserDetail.tsx +23 -16
- package/src/admin/UsersAdmin.tsx +9 -3
- package/src/admin/access.test.tsx +655 -0
- package/src/admin/accessModel.test.ts +210 -0
- package/src/admin/accessModel.ts +165 -0
- package/src/admin/accessTiles.tsx +65 -0
- package/src/admin/admin.test.tsx +95 -3
- package/src/admin/module.tsx +3 -0
- package/src/admin/roles.ts +29 -15
- package/src/admin/useAccessLadder.ts +102 -0
- package/src/async-budget.test.ts +24 -0
- package/src/bootstrap.tsx +10 -0
- package/src/capabilities.test.ts +20 -0
- package/src/capabilities.ts +13 -3
- package/src/index.ts +2 -0
- package/src/locale.tsx +29 -0
- package/src/markers.test.ts +7 -0
- package/src/styles.test.ts +1 -0
- package/src/styles.ts +64 -0
- package/src/ui/Checkbox.tsx +56 -22
- package/src/ui/Radio.tsx +25 -1
- package/src/ui/Switch.tsx +57 -23
- package/src/ui/TileGroup.test.tsx +185 -0
- package/src/ui/TileGroup.tsx +220 -0
- package/src/ui/controlMessages.test.tsx +136 -0
- package/src/ui/controlMessages.tsx +81 -0
- package/src/uiText.tsx +70 -0
- package/vite.config.ts +17 -0
- package/vitest.setup.ts +50 -0
package/src/uiText.tsx
CHANGED
|
@@ -160,6 +160,47 @@ export interface TerpStrings {
|
|
|
160
160
|
adminAudit: string;
|
|
161
161
|
/** Admin hub: audit card description. */
|
|
162
162
|
adminAuditDescription: string;
|
|
163
|
+
/** Access pane: the sidebar/hub entry and its one-line description. */
|
|
164
|
+
adminAccess: string;
|
|
165
|
+
adminAccessDescription: string;
|
|
166
|
+
/** Access pane: the tile for holding no rung in a module at all. */
|
|
167
|
+
accessNoRung: string;
|
|
168
|
+
/** Access pane: heading above what a rung adds over the one below it. */
|
|
169
|
+
accessAdds: string;
|
|
170
|
+
/** Access pane: the three kinds a delta is split into. */
|
|
171
|
+
accessKindRead: string;
|
|
172
|
+
accessKindWrite: string;
|
|
173
|
+
accessKindDelete: string;
|
|
174
|
+
/** Access pane: shown on a rung that grants nothing the rung below did not. */
|
|
175
|
+
accessAddsNothing: string;
|
|
176
|
+
/** Access pane: shown on a module that declares it is never per-module assignable. */
|
|
177
|
+
accessNeverAssignable: string;
|
|
178
|
+
/** Access pane: shown on a module that has not opted into per-module roles. */
|
|
179
|
+
accessNotAssignable: string;
|
|
180
|
+
/** Access pane: warns that some of the module's routes declared no operation. */
|
|
181
|
+
accessUnexplainedRoutes: string;
|
|
182
|
+
/** Access pane: the note that this screen shows the declared model, not who holds what. */
|
|
183
|
+
accessDeclaredOnly: string;
|
|
184
|
+
/** Assignment panel: the section heading on a person's or group's detail screen. */
|
|
185
|
+
moduleAccessTitle: string;
|
|
186
|
+
/** Assignment panel: what a rung here does, and the two things it can never do. */
|
|
187
|
+
moduleAccessDescription: string;
|
|
188
|
+
/** Assignment panel: shown when no module has opted into per-module roles at all. */
|
|
189
|
+
moduleAccessNoneAssignable: string;
|
|
190
|
+
/** Assignment panel: a rung reaching this subject through a group it belongs to. */
|
|
191
|
+
moduleAccessVia: string;
|
|
192
|
+
/** Assignment panel: a held rung the app's declarations no longer support. */
|
|
193
|
+
moduleAccessStale: string;
|
|
194
|
+
/** Assignment panel: why a rung at or below the subject's global role changes nothing. */
|
|
195
|
+
moduleAccessFloor: string;
|
|
196
|
+
/** Assignment panel: confirmation before handing someone the most privileged rung. */
|
|
197
|
+
moduleAccessConfirmTitle: string;
|
|
198
|
+
moduleAccessConfirm: string;
|
|
199
|
+
/** Assignment panel: confirmation of the rung being taken away again. */
|
|
200
|
+
moduleAccessRevokeTitle: string;
|
|
201
|
+
moduleAccessRevoke: string;
|
|
202
|
+
/** Assignment panel: a rung held in a module that no longer accepts one. */
|
|
203
|
+
moduleAccessOrphaned: string;
|
|
163
204
|
/** Generic "Status" column header. */
|
|
164
205
|
statusColumn: string;
|
|
165
206
|
/** Generic "Created" column header. */
|
|
@@ -323,6 +364,35 @@ export const DEFAULT_STRINGS: TerpStrings = {
|
|
|
323
364
|
adminGroupsDescription: "Bundle permissions; membership applies them",
|
|
324
365
|
adminAudit: "Audit log",
|
|
325
366
|
adminAuditDescription: "Every change: what, who, when",
|
|
367
|
+
adminAccess: "Access",
|
|
368
|
+
adminAccessDescription: "Which roles exist, and what each one may do per module",
|
|
369
|
+
accessNoRung: "No access",
|
|
370
|
+
accessAdds: "Adds over the tier below",
|
|
371
|
+
accessKindRead: "View",
|
|
372
|
+
accessKindWrite: "Change",
|
|
373
|
+
accessKindDelete: "Delete",
|
|
374
|
+
accessAddsNothing: "Nothing beyond the tier below",
|
|
375
|
+
accessNeverAssignable: "Never assignable per module",
|
|
376
|
+
accessNotAssignable: "Not assignable per module",
|
|
377
|
+
accessUnexplainedRoutes: "{count} action(s) in this module have no description yet",
|
|
378
|
+
accessDeclaredOnly:
|
|
379
|
+
"This is what the application declares. It does not show who holds which role — open a person to see that.",
|
|
380
|
+
moduleAccessTitle: "Access per module",
|
|
381
|
+
moduleAccessDescription:
|
|
382
|
+
"A role here applies in that one module and raises access, never lowers it. Modules that have not opted in are not listed.",
|
|
383
|
+
moduleAccessNoneAssignable:
|
|
384
|
+
"No module in this application accepts a role of its own, so there is nothing to set here.",
|
|
385
|
+
moduleAccessVia: "Also {role} here, through {name}",
|
|
386
|
+
moduleAccessStale: "Held, but has no effect: {reason}",
|
|
387
|
+
moduleAccessFloor: "{role} everywhere already, so anything up to here changes nothing",
|
|
388
|
+
moduleAccessConfirmTitle: "Give {role} in {module}?",
|
|
389
|
+
moduleAccessConfirm:
|
|
390
|
+
"This is the most far-reaching role the module has. Everything the tier below can do, plus what the tile lists.",
|
|
391
|
+
moduleAccessRevokeTitle: "Take away the role in {module}?",
|
|
392
|
+
moduleAccessRevoke:
|
|
393
|
+
"Access in this module falls back to what the person's role gives them everywhere else.",
|
|
394
|
+
moduleAccessOrphaned:
|
|
395
|
+
"Still set to {role} in {module}, which no longer accepts a role of its own. It has no effect, and removing it is the only change left to make.",
|
|
326
396
|
statusColumn: "Status",
|
|
327
397
|
createdColumn: "Created",
|
|
328
398
|
statusActive: "Active",
|
package/vite.config.ts
CHANGED
|
@@ -10,5 +10,22 @@ export default defineConfig({
|
|
|
10
10
|
environment: "node",
|
|
11
11
|
setupFiles: ["./vitest.setup.ts"],
|
|
12
12
|
include: ["src/**/*.test.ts", "src/**/*.test.tsx"],
|
|
13
|
+
// Above the `asyncUtilTimeout` the setup file configures, so a matcher that cannot
|
|
14
|
+
// find its element loses first and says which element. Equal budgets would let the
|
|
15
|
+
// test time out mid-wait and report nothing useful about the assertion. The ordering
|
|
16
|
+
// is held from the Python side in `test_frontend_async_budget.py`, which is why this
|
|
17
|
+
// comment names no number: an earlier version said "the 5s asyncUtilTimeout" while
|
|
18
|
+
// the setup file configured 3s, and a comment that misstates the code it explains is
|
|
19
|
+
// worse than none.
|
|
20
|
+
testTimeout: 15_000,
|
|
21
|
+
// These tests contend for the machine rather than with each other, and losing that
|
|
22
|
+
// contention is how they fail: four different fetch-bound assertions across four CI
|
|
23
|
+
// runs, always one file of eighty-one, each passing on its own. Widening the async
|
|
24
|
+
// budget was tried first and did not fix it (1s to 3s to 4s), and it has nowhere left
|
|
25
|
+
// to go -- a toast's 5s lifetime is the ceiling. So remove the cause rather than the
|
|
26
|
+
// tolerance: a jsdom + React + fetch file is heavy, a small runner has four vCPUs, and
|
|
27
|
+
// eighty-one of them at once starve each other's timers. It costs wall clock and buys
|
|
28
|
+
// a green that means something.
|
|
29
|
+
fileParallelism: false,
|
|
13
30
|
},
|
|
14
31
|
});
|
package/vitest.setup.ts
CHANGED
|
@@ -3,6 +3,37 @@
|
|
|
3
3
|
// the jsdom component tests.
|
|
4
4
|
import "@testing-library/jest-dom/vitest";
|
|
5
5
|
|
|
6
|
+
import { configure } from "@testing-library/dom";
|
|
7
|
+
|
|
8
|
+
// `findBy*` and `waitFor` default to a 1000ms budget, and the component tests spend it on
|
|
9
|
+
// a path that is not a render: a mocked fetch resolving, then the state it sets, then the
|
|
10
|
+
// re-render that finally puts the text on screen. One second is enough on an idle machine
|
|
11
|
+
// and not on a loaded one, so the suite failed intermittently — five times across one day,
|
|
12
|
+
// four different tests, every one passing alone and on a re-run, and one of them red in CI
|
|
13
|
+
// on a branch whose own change was fine.
|
|
14
|
+
//
|
|
15
|
+
// The budget is raised rather than the tests retried. A retry would hide a genuinely
|
|
16
|
+
// intermittent product bug, and these assertions are not flaky in what they claim: the
|
|
17
|
+
// text does appear, and a matcher that waits longer asserts exactly the same thing. What
|
|
18
|
+
// it costs is that a test which SHOULD fail now takes longer to say so, which is why
|
|
19
|
+
// `testTimeout` moves too — the matcher must lose before the test does, or the failure
|
|
20
|
+
// arrives as an unhelpful "test timed out" instead of naming the element it could not find.
|
|
21
|
+
//
|
|
22
|
+
// It has a CEILING, and the first attempt at this walked straight into it. A toast
|
|
23
|
+
// auto-dismisses after `DEFAULT_DURATION_MS` (5s, toast.tsx), and several admin tests wait
|
|
24
|
+
// for a field error and then assert the toast SYNCHRONOUSLY. Set the budget to 5s and a
|
|
25
|
+
// wait that takes long enough outlives the toast the next line is about to look for — one
|
|
26
|
+
// flake traded for another, and a worse one, because it looks like a product bug. So the
|
|
27
|
+
// budget sits between the two: comfortably past a fetch and a re-render, comfortably short
|
|
28
|
+
// of a toast's life. `async-budget.test.ts` holds both ends.
|
|
29
|
+
//
|
|
30
|
+
// Raised from 3s to 4s on 2026-09-08: 3s was still not enough under CI load. Two
|
|
31
|
+
// consecutive runs failed on two different fetch-bound tests, and main failed a third
|
|
32
|
+
// time in the same window -- always "unable to find element", always one file of
|
|
33
|
+
// eighty-one. 4s keeps a full second below the toast, which is the last of the
|
|
34
|
+
// headroom this lever has: the next move is less contention, not a longer wait.
|
|
35
|
+
configure({ asyncUtilTimeout: 4_000 });
|
|
36
|
+
|
|
6
37
|
// jsdom's File / Blob / FormData are structurally incompatible with Node's built-in
|
|
7
38
|
// (undici) fetch: a jsdom File inside a FormData body serializes as an empty, nameless
|
|
8
39
|
// part, and on Node >= 24 `Request.formData()` brand-checks reject jsdom instances
|
|
@@ -27,6 +58,25 @@ if (typeof window !== "undefined") {
|
|
|
27
58
|
).constructor as typeof FormData;
|
|
28
59
|
globalThis.FormData = NativeFormData;
|
|
29
60
|
window.FormData = NativeFormData;
|
|
61
|
+
|
|
62
|
+
// Vitest's jsdom environment installs a `Request` SUBCLASS whose constructor
|
|
63
|
+
// pre-processes `init.body` for jsdom's Blob internals (it reads `_buffer`).
|
|
64
|
+
// With the swap above that body is a Node FormData holding a Node File, so the
|
|
65
|
+
// shim throws on the one thing these tests exist to check — and handed a jsdom
|
|
66
|
+
// FormData instead it does not recognise it as form data at all and serialises
|
|
67
|
+
// the body as a string, so the request goes out as `text/plain` and the
|
|
68
|
+
// multipart assertion fails for a second, quieter reason. Unwrapping to the
|
|
69
|
+
// class it extends restores Node's own constructor, which serialises a Node
|
|
70
|
+
// FormData as multipart with a boundary.
|
|
71
|
+
//
|
|
72
|
+
// Guarded on the shim actually being there: a real `Request` is a base class,
|
|
73
|
+
// so its prototype is `Function.prototype`. If a later Vitest stops wrapping,
|
|
74
|
+
// this becomes a no-op rather than reaching for something that is not a class.
|
|
75
|
+
const RequestBase = Object.getPrototypeOf(globalThis.Request) as typeof Request;
|
|
76
|
+
if (typeof RequestBase === "function" && (RequestBase as unknown) !== Function.prototype) {
|
|
77
|
+
globalThis.Request = RequestBase;
|
|
78
|
+
window.Request = RequestBase;
|
|
79
|
+
}
|
|
30
80
|
}
|
|
31
81
|
|
|
32
82
|
// jsdom does not implement scrollTo, which TanStack Router calls on navigation; stub it so
|