@terreno/admin-frontend 57.20.0 → 57.21.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/CHANGELOG.md +50 -0
- package/dist/AdminFilterDrawer.d.ts.map +1 -1
- package/dist/AdminFilterDrawer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -3
- package/src/AdminBreadcrumbs.test.tsx +1 -1
- package/src/AdminFieldRenderer.test.tsx +2 -1
- package/src/AdminFilterDrawer.tsx +1 -2
- package/src/AdminHome.test.tsx +2 -1
- package/src/AdminModelTable.test.tsx +16 -12
- package/src/AdminModelTable.windowed.test.tsx +11 -5
- package/src/AdminPrimitiveArrayField.test.tsx +3 -3
- package/src/AdminProvider.test.tsx +11 -6
- package/src/AdminRolesList.test.tsx +22 -13
- package/src/AdminScreenPage.test.tsx +1 -1
- package/src/AdminScreenRouter.test.tsx +15 -5
- package/src/AdminScriptList.test.tsx +9 -2
- package/src/AdminShell.test.tsx +1 -1
- package/src/AdminVersionConfig.test.tsx +4 -4
- package/src/AnnouncementOverviewScreenWidget.test.tsx +6 -1
- package/src/CheckboxListEditor.test.tsx +11 -9
- package/src/ConfigurationScreen.test.tsx +2 -2
- package/src/adminRequest.test.ts +3 -3
- package/src/adminWindowedTable.test.ts +4 -2
- package/src/comms/CommsDashboardScreen.test.tsx +5 -5
- package/src/comms/CommsMessageDetail.test.tsx +1 -1
- package/src/index.tsx +2 -0
- package/src/isolated/AdminFieldRenderer.isolated.tsx +11 -6
- package/src/isolated/AdminFilterDrawer.isolated.tsx +8 -6
- package/src/isolated/AdminFilterDrawerMobile.isolated.tsx +3 -1
- package/src/isolated/AdminHomeWidgets.isolated.tsx +2 -0
- package/src/isolated/AdminNestedArrayField.isolated.tsx +10 -9
- package/src/isolated/AdminObjectPicker.isolated.tsx +9 -10
- package/src/isolated/AiPromptsListScreen.isolated.tsx +1 -1
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +16 -8
- package/src/isolated/RecentActivityWidget.isolated.tsx +2 -0
- package/src/isolated/adminWidgets.isolated.tsx +46 -6
- package/src/isolated/aiObservabilityScreens.isolated.tsx +18 -9
- package/src/isolated/generateConsentHistoryPdf.isolated.ts +30 -10
- package/src/isolated/generateConsentPdfsMobile.isolated.ts +24 -3
- package/src/isolated/hooks.isolated.tsx +84 -60
- package/src/isolated/rpcDualRun.isolated.tsx +9 -2
- package/src/jobs/JobsDashboardScreen.test.tsx +3 -3
- package/src/jobs/JobsHomeWidget.test.tsx +1 -1
- package/src/jobs/JobsJobDetail.test.tsx +1 -1
- package/src/orgs/OrgManagementScreens.test.tsx +1 -1
- package/src/orgs/adminModelEndpoints.test.ts +1 -1
- package/src/testing/useAdminApiDouble.ts +2 -1
- package/src/types.ts +2 -0
- package/src/useAdminRpc.test.tsx +3 -3
- package/src/widgets/AIRequestsScreenWidget.test.tsx +20 -3
- package/src/widgets/ModelsGridWidget.test.tsx +25 -5
- package/src/widgets/aiObservability/datasets/AiDatasetDetailView.test.tsx +4 -2
- package/src/widgets/aiObservability/datasets/datasetTypes.test.ts +0 -1
- package/src/widgets/aiObservability/evaluators/AiEvaluatorPanels.test.tsx +89 -23
- package/src/widgets/aiObservability/experiments/AiExperimentNewView.test.tsx +4 -0
- package/src/widgets/aiObservability/shell/ObservabilityTable.test.tsx +7 -1
- package/src/widgets/builtInFieldWidgets.test.tsx +16 -3
|
@@ -18,6 +18,7 @@ import {Provider} from "react-redux";
|
|
|
18
18
|
import {renderWithTheme} from "../../../ui/src/test-utils";
|
|
19
19
|
import {adminOrgScopedArg} from "../orgs/adminModelEndpoints";
|
|
20
20
|
import {OrgContextProvider, useOrgContext} from "../orgs/useOrgContext";
|
|
21
|
+
import type {AdminApi} from "../types";
|
|
21
22
|
import {useAdminApi} from "../useAdminApi";
|
|
22
23
|
import {useAdminBackgroundTaskMutation} from "../useAdminBackgroundTask";
|
|
23
24
|
import {useAdminConfig} from "../useAdminConfig";
|
|
@@ -26,19 +27,50 @@ import {useAdminScripts} from "../useAdminScripts";
|
|
|
26
27
|
import {useConfigurationApi} from "../useConfigurationApi";
|
|
27
28
|
import {useDocumentStorageApi} from "../useDocumentStorageApi";
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
/** What an injected endpoint's `query` returns: an RTK Query request description. */
|
|
31
|
+
interface QuerySpec {
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
method?: string;
|
|
34
|
+
responseHandler?: (response: unknown) => Promise<unknown>;
|
|
35
|
+
url?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type TagsFn = (result: unknown, error: unknown, arg: unknown) => unknown;
|
|
39
|
+
|
|
40
|
+
/** An endpoint definition as captured by the mock builder. */
|
|
41
|
+
interface CapturedEndpoint {
|
|
42
|
+
__kind?: "query" | "mutation";
|
|
43
|
+
query: (arg?: unknown) => QuerySpec;
|
|
32
44
|
providesTags?: unknown;
|
|
33
45
|
invalidatesTags?: unknown;
|
|
34
|
-
|
|
46
|
+
serializeQueryArgs?: (args: {endpointName: string; queryArgs: unknown}) => string;
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
type CapturedEndpoints = Record<string, CapturedEndpoint>;
|
|
50
|
+
|
|
51
|
+
/** The proxy double handed to the hooks, plus what it recorded. */
|
|
52
|
+
type MockAdminApi = AdminApi & {
|
|
53
|
+
readonly __injected: CapturedEndpoints;
|
|
54
|
+
readonly __tagTypes: string[];
|
|
55
|
+
};
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
/** Calls an endpoint's function-form `providesTags` / `invalidatesTags` for `arg`. */
|
|
58
|
+
const callTags = (tags: unknown, arg: unknown): unknown => {
|
|
59
|
+
if (typeof tags !== "function") {
|
|
60
|
+
throw new Error("Expected a tag function");
|
|
61
|
+
}
|
|
62
|
+
return (tags as TagsFn)(null, null, arg);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Calls an endpoint's `serializeQueryArgs`, failing when the endpoint has none. */
|
|
66
|
+
const serializeArgs = (endpoint: CapturedEndpoint, endpointName: string, queryArgs: unknown) => {
|
|
67
|
+
if (!endpoint.serializeQueryArgs) {
|
|
68
|
+
throw new Error(`${endpointName} has no serializeQueryArgs`);
|
|
69
|
+
}
|
|
70
|
+
return endpoint.serializeQueryArgs({endpointName, queryArgs});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const makeMockApi = (): MockAdminApi => {
|
|
42
74
|
const injected: CapturedEndpoints = {};
|
|
43
75
|
const enhancedTagTypes: string[] = [];
|
|
44
76
|
|
|
@@ -75,16 +107,15 @@ const makeMockApi = () => {
|
|
|
75
107
|
};
|
|
76
108
|
}
|
|
77
109
|
if (prop === "injectEndpoints") {
|
|
78
|
-
return ({endpoints}: {endpoints: (build: unknown) =>
|
|
110
|
+
return ({endpoints}: {endpoints: (build: unknown) => CapturedEndpoints}) => {
|
|
79
111
|
const build = {
|
|
80
|
-
mutation: (spec:
|
|
81
|
-
query: (spec:
|
|
112
|
+
mutation: (spec: CapturedEndpoint): CapturedEndpoint => ({...spec, __kind: "mutation"}),
|
|
113
|
+
query: (spec: CapturedEndpoint): CapturedEndpoint => ({...spec, __kind: "query"}),
|
|
82
114
|
};
|
|
83
115
|
const defs = endpoints(build);
|
|
84
116
|
for (const [key, def] of Object.entries(defs)) {
|
|
85
117
|
injected[key] = def;
|
|
86
|
-
const kind =
|
|
87
|
-
(def as Record<string, unknown>).__kind === "mutation" ? "mutation" : "query";
|
|
118
|
+
const kind = def.__kind === "mutation" ? "mutation" : "query";
|
|
88
119
|
addHookFor(key, kind);
|
|
89
120
|
}
|
|
90
121
|
return apiProxy;
|
|
@@ -100,7 +131,8 @@ const makeMockApi = () => {
|
|
|
100
131
|
},
|
|
101
132
|
});
|
|
102
133
|
|
|
103
|
-
|
|
134
|
+
// Test double: the proxy answers only the Api members the hooks touch.
|
|
135
|
+
return apiProxy as unknown as MockAdminApi;
|
|
104
136
|
};
|
|
105
137
|
|
|
106
138
|
const runHook = <T,>(fn: () => T): T => {
|
|
@@ -118,7 +150,7 @@ describe("useAdminApi", () => {
|
|
|
118
150
|
const api = makeMockApi();
|
|
119
151
|
const result = runHook(() => useAdminApi(api, "/admin/users", "User"));
|
|
120
152
|
|
|
121
|
-
const injected =
|
|
153
|
+
const injected = api.__injected;
|
|
122
154
|
expect(injected.adminList_User).toBeDefined();
|
|
123
155
|
expect(injected.adminRead_User).toBeDefined();
|
|
124
156
|
expect(injected.adminCreate_User).toBeDefined();
|
|
@@ -126,7 +158,7 @@ describe("useAdminApi", () => {
|
|
|
126
158
|
expect(injected.adminDelete_User).toBeDefined();
|
|
127
159
|
|
|
128
160
|
// tag types include the admin_<model>
|
|
129
|
-
expect(
|
|
161
|
+
expect(api.__tagTypes).toContain("admin_User");
|
|
130
162
|
|
|
131
163
|
// Each endpoint's query fn produces expected URL/method
|
|
132
164
|
const listDef = injected.adminList_User;
|
|
@@ -147,7 +179,7 @@ describe("useAdminApi", () => {
|
|
|
147
179
|
method: "GET",
|
|
148
180
|
url: "/admin/users/abc",
|
|
149
181
|
});
|
|
150
|
-
expect(readDef.providesTags
|
|
182
|
+
expect(callTags(readDef.providesTags, "abc")).toEqual([{id: "abc", type: "admin_User"}]);
|
|
151
183
|
|
|
152
184
|
const createDef = injected.adminCreate_User;
|
|
153
185
|
expect(createDef.query({name: "x"})).toEqual({
|
|
@@ -165,7 +197,7 @@ describe("useAdminApi", () => {
|
|
|
165
197
|
method: "PATCH",
|
|
166
198
|
url: "/admin/users/123",
|
|
167
199
|
});
|
|
168
|
-
expect(updateDef.invalidatesTags
|
|
200
|
+
expect(callTags(updateDef.invalidatesTags, {id: "123"})).toEqual([
|
|
169
201
|
{id: "123", type: "admin_User"},
|
|
170
202
|
"admin_User",
|
|
171
203
|
]);
|
|
@@ -197,7 +229,7 @@ describe("useAdminApi", () => {
|
|
|
197
229
|
it("pins list/read/create/update/delete/bulk-patch URLs for String-_id routePath", () => {
|
|
198
230
|
const api = makeMockApi();
|
|
199
231
|
const result = runHook(() => useAdminApi(api, "/admin/todos", "Todo"));
|
|
200
|
-
const injected =
|
|
232
|
+
const injected = api.__injected;
|
|
201
233
|
|
|
202
234
|
expect(
|
|
203
235
|
injected.adminList_Todo.query({limit: 20, page: 1, q: "Alpha", sort: "-created"})
|
|
@@ -295,11 +327,7 @@ describe("useAdminApi organization switches", () => {
|
|
|
295
327
|
it("keys list and read entries by the organization carried in the argument", () => {
|
|
296
328
|
const api = makeMockApi();
|
|
297
329
|
runHook(() => useAdminApi(api, "/admin/users", "User"));
|
|
298
|
-
const injected =
|
|
299
|
-
[key: string]: {
|
|
300
|
-
serializeQueryArgs: (args: {endpointName: string; queryArgs: unknown}) => string;
|
|
301
|
-
};
|
|
302
|
-
};
|
|
330
|
+
const injected = api.__injected;
|
|
303
331
|
const read = injected.adminRead_User;
|
|
304
332
|
const list = injected.adminList_User;
|
|
305
333
|
|
|
@@ -308,26 +336,20 @@ describe("useAdminApi organization switches", () => {
|
|
|
308
336
|
method: "GET",
|
|
309
337
|
url: "/admin/users/abc",
|
|
310
338
|
});
|
|
311
|
-
expect(read.providesTags
|
|
339
|
+
expect(callTags(read.providesTags, adminOrgScopedArg("abc", "org-b"))).toEqual([
|
|
312
340
|
{id: "abc", type: "admin_User"},
|
|
313
341
|
]);
|
|
314
|
-
expect(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
queryArgs: adminOrgScopedArg("abc", "org-b"),
|
|
318
|
-
})
|
|
319
|
-
).toBe("adminRead_User:org-b:abc");
|
|
342
|
+
expect(serializeArgs(read, "adminRead_User", adminOrgScopedArg("abc", "org-b"))).toBe(
|
|
343
|
+
"adminRead_User:org-b:abc"
|
|
344
|
+
);
|
|
320
345
|
expect(list.query(adminOrgScopedArg({limit: 1}, undefined))).toEqual({
|
|
321
346
|
headers: undefined,
|
|
322
347
|
method: "GET",
|
|
323
348
|
url: "/admin/users?limit=1",
|
|
324
349
|
});
|
|
325
|
-
expect(
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
queryArgs: adminOrgScopedArg({limit: 1}, "org-b"),
|
|
329
|
-
})
|
|
330
|
-
).toBe('adminList_User:org-b:{"limit":1}');
|
|
350
|
+
expect(serializeArgs(list, "adminList_User", adminOrgScopedArg({limit: 1}, "org-b"))).toBe(
|
|
351
|
+
'adminList_User:org-b:{"limit":1}'
|
|
352
|
+
);
|
|
331
353
|
});
|
|
332
354
|
});
|
|
333
355
|
|
|
@@ -336,7 +358,7 @@ describe("useAdminConfig", () => {
|
|
|
336
358
|
const api = makeMockApi();
|
|
337
359
|
const result = runHook(() => useAdminConfig(api, "/admin"));
|
|
338
360
|
|
|
339
|
-
const injected =
|
|
361
|
+
const injected = api.__injected;
|
|
340
362
|
expect(injected.adminConfig).toBeDefined();
|
|
341
363
|
const def = injected.adminConfig;
|
|
342
364
|
expect(def.query()).toEqual({method: "GET", url: "/admin/config"});
|
|
@@ -354,7 +376,7 @@ describe("useAdminScripts", () => {
|
|
|
354
376
|
const api = makeMockApi();
|
|
355
377
|
const result = runHook(() => useAdminScripts(api, "/admin"));
|
|
356
378
|
|
|
357
|
-
const injected =
|
|
379
|
+
const injected = api.__injected;
|
|
358
380
|
expect(injected.adminRunScript).toBeDefined();
|
|
359
381
|
expect(injected.adminGetScriptTask).toBeDefined();
|
|
360
382
|
expect(injected.adminCancelScriptTask).toBeDefined();
|
|
@@ -399,7 +421,9 @@ describe("useAdminScripts", () => {
|
|
|
399
421
|
it("returns safe script hooks when endpoint injection is unavailable", async () => {
|
|
400
422
|
const result = runHook(() => useAdminScripts({} as never, "/admin"));
|
|
401
423
|
|
|
402
|
-
|
|
424
|
+
// The no-op fallback resolves to an empty object rather than a typed task response.
|
|
425
|
+
const cancelled: unknown = await result.useCancelScriptTaskMutation()[0]("task-1").unwrap();
|
|
426
|
+
expect(cancelled).toEqual({});
|
|
403
427
|
expect(result.useGetScriptTaskQuery("task-1")).toEqual({
|
|
404
428
|
data: undefined,
|
|
405
429
|
error: null,
|
|
@@ -421,7 +445,7 @@ describe("useAdminRoles", () => {
|
|
|
421
445
|
it("injects RBAC endpoints outside the admin base", () => {
|
|
422
446
|
const api = makeMockApi();
|
|
423
447
|
const result = runHook(() => useAdminRoles(api, "/admin"));
|
|
424
|
-
const injected =
|
|
448
|
+
const injected = api.__injected;
|
|
425
449
|
|
|
426
450
|
expect(
|
|
427
451
|
injected.adminCreateRbacRole.query({
|
|
@@ -489,7 +513,7 @@ describe("useAdminBackgroundTaskMutation", () => {
|
|
|
489
513
|
it("injects a background-task request at a normalized admin root", () => {
|
|
490
514
|
const api = makeMockApi();
|
|
491
515
|
const result = runHook(() => useAdminBackgroundTaskMutation(api, "/admin/"));
|
|
492
|
-
const injected =
|
|
516
|
+
const injected = api.__injected;
|
|
493
517
|
|
|
494
518
|
expect(
|
|
495
519
|
injected.adminPostBackgroundTask.query({
|
|
@@ -517,33 +541,29 @@ describe("useConfigurationApi", () => {
|
|
|
517
541
|
const api = makeMockApi();
|
|
518
542
|
const result = runHook(() => useConfigurationApi({api, basePath: "/admin/configuration"}));
|
|
519
543
|
|
|
520
|
-
const injected =
|
|
544
|
+
const injected = api.__injected;
|
|
521
545
|
expect(injected.configMeta).toBeDefined();
|
|
522
546
|
expect(injected.configValues).toBeDefined();
|
|
523
547
|
expect(injected.configUpdate).toBeDefined();
|
|
524
548
|
expect(injected.configRefreshSecrets).toBeDefined();
|
|
525
|
-
expect(
|
|
549
|
+
expect(api.__tagTypes).toContain("configuration");
|
|
526
550
|
|
|
527
|
-
expect(
|
|
551
|
+
expect(injected.configMeta.query()).toEqual({
|
|
528
552
|
method: "GET",
|
|
529
553
|
url: "/admin/configuration/meta",
|
|
530
554
|
});
|
|
531
|
-
expect(
|
|
555
|
+
expect(injected.configValues.query()).toEqual({
|
|
532
556
|
method: "GET",
|
|
533
557
|
url: "/admin/configuration",
|
|
534
558
|
});
|
|
535
|
-
expect(
|
|
536
|
-
|
|
537
|
-
]);
|
|
538
|
-
expect((injected.configUpdate as BuildSpec & Record<string, unknown>).query({a: 1})).toEqual({
|
|
559
|
+
expect(injected.configValues.providesTags).toEqual(["configuration"]);
|
|
560
|
+
expect(injected.configUpdate.query({a: 1})).toEqual({
|
|
539
561
|
body: {a: 1},
|
|
540
562
|
method: "PATCH",
|
|
541
563
|
url: "/admin/configuration",
|
|
542
564
|
});
|
|
543
|
-
expect(
|
|
544
|
-
|
|
545
|
-
]);
|
|
546
|
-
expect((injected.configRefreshSecrets as BuildSpec & Record<string, unknown>).query()).toEqual({
|
|
565
|
+
expect(injected.configUpdate.invalidatesTags).toEqual(["configuration"]);
|
|
566
|
+
expect(injected.configRefreshSecrets.query()).toEqual({
|
|
547
567
|
method: "POST",
|
|
548
568
|
url: "/admin/configuration/refresh-secrets",
|
|
549
569
|
});
|
|
@@ -560,7 +580,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
560
580
|
const api = makeMockApi();
|
|
561
581
|
const result = runHook(() => useDocumentStorageApi(api, "/documents"));
|
|
562
582
|
|
|
563
|
-
const injected =
|
|
583
|
+
const injected = api.__injected;
|
|
564
584
|
expect(injected.documentStorageList).toBeDefined();
|
|
565
585
|
expect(injected.documentStorageUpload).toBeDefined();
|
|
566
586
|
expect(injected.documentStorageDownload).toBeDefined();
|
|
@@ -614,6 +634,10 @@ describe("useDocumentStorageApi", () => {
|
|
|
614
634
|
expect(dlSpec.url).toBe("/documents/download/my%20folder%2Ffile.pdf");
|
|
615
635
|
expect(dlSpec.method).toBe("GET");
|
|
616
636
|
expect(typeof dlSpec.responseHandler).toBe("function");
|
|
637
|
+
const responseHandler = dlSpec.responseHandler;
|
|
638
|
+
if (!responseHandler) {
|
|
639
|
+
throw new Error("download endpoint has no responseHandler");
|
|
640
|
+
}
|
|
617
641
|
|
|
618
642
|
// responseHandler returns the blob on ok
|
|
619
643
|
const okBlob = {size: 5, type: "text/plain"};
|
|
@@ -624,7 +648,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
624
648
|
status: 200,
|
|
625
649
|
statusText: "OK",
|
|
626
650
|
};
|
|
627
|
-
return
|
|
651
|
+
return responseHandler(okResp).then(async (blob: unknown) => {
|
|
628
652
|
expect(blob).toBe(okBlob);
|
|
629
653
|
|
|
630
654
|
// non-ok JSON response
|
|
@@ -636,7 +660,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
636
660
|
statusText: "Bad Request",
|
|
637
661
|
text: async () => errJson,
|
|
638
662
|
};
|
|
639
|
-
const parsed = await
|
|
663
|
+
const parsed = await responseHandler(jsonResp);
|
|
640
664
|
expect(parsed).toEqual({detail: "Bad", status: 400});
|
|
641
665
|
|
|
642
666
|
// non-ok non-JSON response (fallback)
|
|
@@ -647,7 +671,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
647
671
|
statusText: "err",
|
|
648
672
|
text: async () => "boom",
|
|
649
673
|
};
|
|
650
|
-
const textParsed = await
|
|
674
|
+
const textParsed = await responseHandler(textResp);
|
|
651
675
|
expect(textParsed).toEqual({detail: "boom", status: 500});
|
|
652
676
|
|
|
653
677
|
// Delete endpoints
|
|
@@ -684,7 +708,7 @@ describe("useAdminBackgroundTaskMutation", () => {
|
|
|
684
708
|
it("posts to the background-tasks collection under the admin root", () => {
|
|
685
709
|
const api = makeMockApi();
|
|
686
710
|
const result = runHook(() => useAdminBackgroundTaskMutation(api as never, "/admin/"));
|
|
687
|
-
const injected =
|
|
711
|
+
const injected = api.__injected;
|
|
688
712
|
expect(injected.adminPostBackgroundTask.query({ids: ["a"], kind: "reindex"})).toEqual({
|
|
689
713
|
body: {ids: ["a"], kind: "reindex"},
|
|
690
714
|
method: "POST",
|
|
@@ -707,7 +731,7 @@ describe("useAdminRoles", () => {
|
|
|
707
731
|
it("injects rbac list and mutation endpoints at the API root", () => {
|
|
708
732
|
const api = makeMockApi();
|
|
709
733
|
const result = runHook(() => useAdminRoles(api as never, "/v1/admin"));
|
|
710
|
-
const injected =
|
|
734
|
+
const injected = api.__injected;
|
|
711
735
|
expect(injected.adminListRbacRoles.query()).toEqual({method: "GET", url: "/v1/rbac/roles"});
|
|
712
736
|
expect(injected.adminListRbacStatements.query()).toEqual({
|
|
713
737
|
method: "GET",
|
|
@@ -7,7 +7,7 @@ import {AdminObjectPicker} from "../AdminObjectPicker";
|
|
|
7
7
|
import {AdminProvider} from "../AdminProvider";
|
|
8
8
|
import {AdminVersionConfig} from "../AdminVersionConfig";
|
|
9
9
|
import {useCommsDashboardApi} from "../comms/useCommsDashboardApi";
|
|
10
|
-
import type {AdminApi} from "../types";
|
|
10
|
+
import type {AdminApi, AdminConfigResponse} from "../types";
|
|
11
11
|
import {useAdminBackgroundTaskMutation} from "../useAdminBackgroundTask";
|
|
12
12
|
import {useAdminConfig} from "../useAdminConfig";
|
|
13
13
|
import {useAdminRoles} from "../useAdminRoles";
|
|
@@ -18,6 +18,8 @@ import {useConsentHistory} from "../useConsentHistory";
|
|
|
18
18
|
import {useDocumentStorageApi} from "../useDocumentStorageApi";
|
|
19
19
|
import {AIRequestsScreenWidget} from "../widgets/AIRequestsScreenWidget";
|
|
20
20
|
|
|
21
|
+
const emptyConfig: AdminConfigResponse = {customScreens: [], models: [], scripts: []};
|
|
22
|
+
|
|
21
23
|
const makeApi = (): AdminApi => {
|
|
22
24
|
const api: Record<string, unknown> = {};
|
|
23
25
|
const hooks = new Proxy(
|
|
@@ -332,7 +334,12 @@ describe("admin RPC dual-run", () => {
|
|
|
332
334
|
credentials="same-origin"
|
|
333
335
|
getAuthHeaders={() => ({})}
|
|
334
336
|
>
|
|
335
|
-
<AIRequestsScreenWidget
|
|
337
|
+
<AIRequestsScreenWidget
|
|
338
|
+
api={makeApi()}
|
|
339
|
+
config={emptyConfig}
|
|
340
|
+
routeBase="/admin"
|
|
341
|
+
screenName="aiRequests"
|
|
342
|
+
/>
|
|
336
343
|
</AdminProvider>
|
|
337
344
|
);
|
|
338
345
|
await flushEffects();
|
|
@@ -5,7 +5,7 @@ import React from "react";
|
|
|
5
5
|
import {renderWithTheme} from "../../../ui/src/test-utils";
|
|
6
6
|
import type {AdminApi} from "../types";
|
|
7
7
|
|
|
8
|
-
const pushMock = mock(() => {});
|
|
8
|
+
const pushMock = mock((_href: unknown) => {});
|
|
9
9
|
mock.module("expo-router", () => ({
|
|
10
10
|
router: {push: pushMock, replace: mock(() => {})},
|
|
11
11
|
useLocalSearchParams: () => ({}),
|
|
@@ -162,7 +162,7 @@ describe("JobsDashboardScreen", () => {
|
|
|
162
162
|
schedulesState.data = [
|
|
163
163
|
{cron: "0 0 * * *", enabled: true, id: "sched-1", name: "nightly", timezone: "UTC"},
|
|
164
164
|
];
|
|
165
|
-
const onFiltersChange = mock(() => {});
|
|
165
|
+
const onFiltersChange = mock((_next: unknown) => {});
|
|
166
166
|
const {UNSAFE_root, getByTestId} = renderWithTheme(
|
|
167
167
|
<JobsDashboardScreen
|
|
168
168
|
api={createJobsApi()}
|
|
@@ -203,7 +203,7 @@ describe("JobsDashboardScreen", () => {
|
|
|
203
203
|
|
|
204
204
|
it("pages through results without dropping the active filters", async () => {
|
|
205
205
|
listState.data = {data: [deadRow], more: true, page: 1, total: 60};
|
|
206
|
-
const onFiltersChange = mock(() => {});
|
|
206
|
+
const onFiltersChange = mock((_next: unknown) => {});
|
|
207
207
|
const {getByTestId} = renderWithTheme(
|
|
208
208
|
<JobsDashboardScreen
|
|
209
209
|
api={createJobsApi()}
|
|
@@ -5,7 +5,7 @@ import React from "react";
|
|
|
5
5
|
import {renderWithTheme} from "../../../ui/src/test-utils";
|
|
6
6
|
import type {AdminApi, AdminConfigResponse} from "../types";
|
|
7
7
|
|
|
8
|
-
const pushMock = mock(() => {});
|
|
8
|
+
const pushMock = mock((_href: unknown) => {});
|
|
9
9
|
mock.module("expo-router", () => ({
|
|
10
10
|
router: {push: pushMock, replace: mock(() => {})},
|
|
11
11
|
}));
|
|
@@ -4,7 +4,7 @@ import React from "react";
|
|
|
4
4
|
import {renderWithTheme} from "../../../ui/src/test-utils";
|
|
5
5
|
import type {AdminApi} from "../types";
|
|
6
6
|
|
|
7
|
-
const pushMock = mock(() => {});
|
|
7
|
+
const pushMock = mock((_href: unknown) => {});
|
|
8
8
|
mock.module("expo-router", () => ({
|
|
9
9
|
router: {push: pushMock, replace: mock(() => {})},
|
|
10
10
|
}));
|
|
@@ -21,7 +21,7 @@ const updateOrganization = mock(() => ({unwrap: async () => ({})}));
|
|
|
21
21
|
const attachMember = mock(() => ({unwrap: async () => ({})}));
|
|
22
22
|
const updateMember = mock(() => ({unwrap: async () => ({})}));
|
|
23
23
|
const removeMember = mock(() => ({unwrap: async () => ({})}));
|
|
24
|
-
const routerPush = mock(() => {});
|
|
24
|
+
const routerPush = mock((_href: unknown) => {});
|
|
25
25
|
|
|
26
26
|
mock.module("expo-router", () => ({router: {push: routerPush}}));
|
|
27
27
|
|
|
@@ -143,7 +143,7 @@ describe("adminModelEndpoints", () => {
|
|
|
143
143
|
"adminRead_Food:org-1:food-1"
|
|
144
144
|
);
|
|
145
145
|
assert.equal(
|
|
146
|
-
buildFoodEndpoints(undefined).adminList_Food.serializeQueryArgs?.({
|
|
146
|
+
(buildFoodEndpoints(undefined).adminList_Food as EndpointDefinition).serializeQueryArgs?.({
|
|
147
147
|
endpointName: "adminList_Food",
|
|
148
148
|
queryArgs: undefined,
|
|
149
149
|
}),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {mock} from "bun:test";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// `never[]` lets overrides declare the real hook argument types; the proxy only hands them out.
|
|
4
|
+
type HookFactory = (...args: never[]) => unknown;
|
|
4
5
|
|
|
5
6
|
const hookOverrides = new Map<string, HookFactory>();
|
|
6
7
|
|
package/src/types.ts
CHANGED
|
@@ -125,6 +125,8 @@ export interface AdminModelConfig {
|
|
|
125
125
|
field: string;
|
|
126
126
|
kind: string;
|
|
127
127
|
label?: string;
|
|
128
|
+
/** Referenced model for `kind: "ref"` filters; defaults to the field's own `ref`. */
|
|
129
|
+
refModel?: string;
|
|
128
130
|
}[];
|
|
129
131
|
group?: string;
|
|
130
132
|
hiddenFields?: string[];
|
package/src/useAdminRpc.test.tsx
CHANGED
|
@@ -57,7 +57,7 @@ describe("useAdminRpc", () => {
|
|
|
57
57
|
|
|
58
58
|
it("loads GET data, surfaces errors, and refetches", async () => {
|
|
59
59
|
let calls = 0;
|
|
60
|
-
globalThis.fetch = (async () => {
|
|
60
|
+
globalThis.fetch = (async (_url: string) => {
|
|
61
61
|
calls += 1;
|
|
62
62
|
if (calls === 1) {
|
|
63
63
|
return new Response(JSON.stringify({ok: true}), {
|
|
@@ -107,7 +107,7 @@ describe("useAdminRpc", () => {
|
|
|
107
107
|
it("drops the previous body and reports loading when the URL changes", async () => {
|
|
108
108
|
let gets = 0;
|
|
109
109
|
let resolveNext: ((response: Response) => void) | undefined;
|
|
110
|
-
globalThis.fetch = (async () => {
|
|
110
|
+
globalThis.fetch = (async (_url: string) => {
|
|
111
111
|
gets += 1;
|
|
112
112
|
if (gets > 1) {
|
|
113
113
|
return await new Promise<Response>((resolve) => {
|
|
@@ -170,7 +170,7 @@ describe("useAdminRpc", () => {
|
|
|
170
170
|
|
|
171
171
|
it("reports loading when returning to a URL before the other one finishes", async () => {
|
|
172
172
|
let gets = 0;
|
|
173
|
-
globalThis.fetch = (async () => {
|
|
173
|
+
globalThis.fetch = (async (_url: string) => {
|
|
174
174
|
gets += 1;
|
|
175
175
|
if (gets > 1) {
|
|
176
176
|
return await new Promise<Response>(() => undefined);
|
|
@@ -102,7 +102,12 @@ describe("AIRequestsScreenWidget", () => {
|
|
|
102
102
|
|
|
103
103
|
it("requests explorer data with the current page and filters", () => {
|
|
104
104
|
const {getByText} = renderWithTheme(
|
|
105
|
-
<AIRequestsScreenWidget
|
|
105
|
+
<AIRequestsScreenWidget
|
|
106
|
+
api={makeExplorerApi()}
|
|
107
|
+
config={emptyConfig}
|
|
108
|
+
routeBase="/admin"
|
|
109
|
+
screenName="aiRequests"
|
|
110
|
+
/>
|
|
106
111
|
);
|
|
107
112
|
|
|
108
113
|
expect(getByText("21 total requests")).toBeTruthy();
|
|
@@ -118,7 +123,14 @@ describe("AIRequestsScreenWidget", () => {
|
|
|
118
123
|
});
|
|
119
124
|
|
|
120
125
|
it("resets page to 1 when filters change and forwards updated query args", async () => {
|
|
121
|
-
renderWithTheme(
|
|
126
|
+
renderWithTheme(
|
|
127
|
+
<AIRequestsScreenWidget
|
|
128
|
+
api={makeExplorerApi()}
|
|
129
|
+
config={emptyConfig}
|
|
130
|
+
routeBase="/admin"
|
|
131
|
+
screenName="aiRequests"
|
|
132
|
+
/>
|
|
133
|
+
);
|
|
122
134
|
assert.isDefined(explorerProps);
|
|
123
135
|
|
|
124
136
|
await act(async () => {
|
|
@@ -143,7 +155,12 @@ describe("AIRequestsScreenWidget", () => {
|
|
|
143
155
|
explorerLoading = true;
|
|
144
156
|
explorerData = {data: [], total: 45};
|
|
145
157
|
const {getByText} = renderWithTheme(
|
|
146
|
-
<AIRequestsScreenWidget
|
|
158
|
+
<AIRequestsScreenWidget
|
|
159
|
+
api={makeExplorerApi()}
|
|
160
|
+
config={emptyConfig}
|
|
161
|
+
routeBase="/admin"
|
|
162
|
+
screenName="aiRequests"
|
|
163
|
+
/>
|
|
147
164
|
);
|
|
148
165
|
|
|
149
166
|
assert.isTrue(explorerProps?.isLoading);
|
|
@@ -5,10 +5,12 @@ import {act, fireEvent} from "@testing-library/react-native";
|
|
|
5
5
|
import {assert} from "chai";
|
|
6
6
|
import React from "react";
|
|
7
7
|
import {renderWithTheme} from "../../../ui/src/test-utils";
|
|
8
|
-
import type {AdminApi, AdminModelConfig} from "../types";
|
|
8
|
+
import type {AdminApi, AdminConfigResponse, AdminModelConfig} from "../types";
|
|
9
9
|
import {ModelsGridWidget} from "./ModelsGridWidget";
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const emptyConfig: AdminConfigResponse = {customScreens: [], models: [], scripts: []};
|
|
12
|
+
|
|
13
|
+
const routerPush = mock((_href: unknown) => {});
|
|
12
14
|
mock.module("expo-router", () => ({
|
|
13
15
|
router: {push: routerPush},
|
|
14
16
|
}));
|
|
@@ -49,7 +51,13 @@ describe("ModelsGridWidget", () => {
|
|
|
49
51
|
|
|
50
52
|
it("renders model cards with field and row counts", () => {
|
|
51
53
|
const {getByTestId, getByText} = renderWithTheme(
|
|
52
|
-
<ModelsGridWidget
|
|
54
|
+
<ModelsGridWidget
|
|
55
|
+
api={mockApi}
|
|
56
|
+
apiBase="/admin"
|
|
57
|
+
config={emptyConfig}
|
|
58
|
+
models={[model]}
|
|
59
|
+
routeBase="/admin/"
|
|
60
|
+
/>
|
|
53
61
|
);
|
|
54
62
|
|
|
55
63
|
expect(getByTestId("admin-home-widget-modelsGrid")).toBeTruthy();
|
|
@@ -59,7 +67,13 @@ describe("ModelsGridWidget", () => {
|
|
|
59
67
|
|
|
60
68
|
it("navigates to list and create routes from model actions", async () => {
|
|
61
69
|
const {getByTestId} = renderWithTheme(
|
|
62
|
-
<ModelsGridWidget
|
|
70
|
+
<ModelsGridWidget
|
|
71
|
+
api={mockApi}
|
|
72
|
+
apiBase="/admin"
|
|
73
|
+
config={emptyConfig}
|
|
74
|
+
models={[model]}
|
|
75
|
+
routeBase="/admin/"
|
|
76
|
+
/>
|
|
63
77
|
);
|
|
64
78
|
|
|
65
79
|
await act(async () => {
|
|
@@ -82,7 +96,13 @@ describe("ModelsGridWidget", () => {
|
|
|
82
96
|
permissions: {create: false},
|
|
83
97
|
};
|
|
84
98
|
const {queryByTestId, getByTestId} = renderWithTheme(
|
|
85
|
-
<ModelsGridWidget
|
|
99
|
+
<ModelsGridWidget
|
|
100
|
+
api={mockApi}
|
|
101
|
+
apiBase="/admin"
|
|
102
|
+
config={emptyConfig}
|
|
103
|
+
models={[readOnlyModel]}
|
|
104
|
+
routeBase="/admin"
|
|
105
|
+
/>
|
|
86
106
|
);
|
|
87
107
|
|
|
88
108
|
expect(queryByTestId("admin-home-model-add-AuditLog")).toBeNull();
|
|
@@ -43,6 +43,8 @@ const items: DatasetItemRecord[] = [
|
|
|
43
43
|
},
|
|
44
44
|
];
|
|
45
45
|
|
|
46
|
+
type OnAddItem = React.ComponentProps<typeof AiDatasetDetailView>["onAddItem"];
|
|
47
|
+
|
|
46
48
|
describe("AiDatasetDetailView items table", () => {
|
|
47
49
|
it("opens complete item details from a row while keeping wide content readable", async () => {
|
|
48
50
|
const baseItem = items[0];
|
|
@@ -127,7 +129,7 @@ describe("AiDatasetDetailView tabs", () => {
|
|
|
127
129
|
it("shows needs review count badge and wires actions", async () => {
|
|
128
130
|
const onOpenExperiment = mock(() => undefined);
|
|
129
131
|
const onOpenTrace = mock(() => undefined);
|
|
130
|
-
const onAddItem = mock(async () => undefined);
|
|
132
|
+
const onAddItem = mock<OnAddItem>(async () => undefined);
|
|
131
133
|
const view = renderWithTheme(
|
|
132
134
|
<AiDatasetDetailView
|
|
133
135
|
dataset={dataset}
|
|
@@ -177,7 +179,7 @@ describe("AiDatasetDetailView tabs", () => {
|
|
|
177
179
|
});
|
|
178
180
|
|
|
179
181
|
it("surfaces add-item errors and dismisses the modal on success", async () => {
|
|
180
|
-
const onAddItem = mock(async () => "Invalid JSON in input.");
|
|
182
|
+
const onAddItem = mock<OnAddItem>(async () => "Invalid JSON in input.");
|
|
181
183
|
const view = renderWithTheme(
|
|
182
184
|
<AiDatasetDetailView
|
|
183
185
|
dataset={dataset}
|
|
@@ -22,7 +22,6 @@ const dataset: DatasetRecord = {
|
|
|
22
22
|
const item = (partial: Partial<DatasetItemRecord> & {id: string}): DatasetItemRecord => ({
|
|
23
23
|
created: "2026-01-01T00:00:00.000Z",
|
|
24
24
|
datasetId: "ds-1",
|
|
25
|
-
id: partial.id,
|
|
26
25
|
input: {q: "hi"},
|
|
27
26
|
origin: "manual",
|
|
28
27
|
proofread: true,
|