@terreno/admin-frontend 0.14.0 → 0.14.2
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/dist/AdminObjectPicker.js +1 -0
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminVersionConfig.js +1 -0
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConsentFormEditor.js +42 -28
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/useAdminApi.js +1 -2
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminConfig.js +1 -0
- package/dist/useAdminConfig.js.map +1 -1
- package/dist/useAdminScripts.js +1 -0
- package/dist/useAdminScripts.js.map +1 -1
- package/dist/useConfigurationApi.js +1 -0
- package/dist/useConfigurationApi.js.map +1 -1
- package/dist/useDocumentStorageApi.js +1 -0
- package/dist/useDocumentStorageApi.js.map +1 -1
- package/package.json +2 -2
- package/src/AdminFieldRenderer.test.tsx +47 -22
- package/src/AdminModelForm.test.tsx +145 -40
- package/src/AdminModelList.test.tsx +13 -5
- package/src/AdminModelTable.test.tsx +57 -31
- package/src/AdminObjectPicker.tsx +1 -0
- package/src/AdminPrimitiveArrayField.test.tsx +13 -10
- package/src/AdminScriptList.test.tsx +6 -4
- package/src/AdminScriptRunModal.test.tsx +4 -2
- package/src/AdminVersionConfig.test.tsx +28 -23
- package/src/AdminVersionConfig.tsx +1 -0
- package/src/CheckboxListEditor.test.tsx +8 -6
- package/src/ConfigurationScreen.test.tsx +15 -11
- package/src/ConsentFormEditor.test.tsx +94 -75
- package/src/ConsentFormEditor.tsx +44 -33
- package/src/ConsentFormList.test.tsx +27 -10
- package/src/ConsentResponseViewer.test.tsx +14 -12
- package/src/DocumentStorageBrowser.test.tsx +68 -42
- package/src/LocaleContentEditor.test.tsx +27 -18
- package/src/isolated/AdminFieldRenderer.isolated.tsx +4 -2
- package/src/isolated/AdminNestedArrayField.isolated.tsx +48 -36
- package/src/isolated/AdminObjectPicker.isolated.tsx +30 -26
- package/src/isolated/AdminRefField.isolated.tsx +3 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +23 -17
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +79 -63
- package/src/isolated/hooks.isolated.tsx +39 -33
- package/src/useAdminApi.ts +1 -2
- package/src/useAdminConfig.ts +1 -0
- package/src/useAdminScripts.ts +1 -0
- package/src/useConfigurationApi.ts +1 -0
- package/src/useDocumentStorageApi.ts +1 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// noExplicitAny: RTK Query API proxy uses dynamic property access and type-erased endpoint builders
|
|
1
2
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
3
|
/**
|
|
3
4
|
* Tests for admin-frontend hooks: useAdminApi, useAdminConfig,
|
|
@@ -33,7 +34,7 @@ const makeMockApi = () => {
|
|
|
33
34
|
const injected: CapturedEndpoints = {};
|
|
34
35
|
const enhancedTagTypes: string[] = [];
|
|
35
36
|
|
|
36
|
-
const fakeHooks: Record<string,
|
|
37
|
+
const fakeHooks: Record<string, unknown> = {};
|
|
37
38
|
|
|
38
39
|
const addHookFor = (key: string, type: "query" | "mutation") => {
|
|
39
40
|
const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
@@ -52,12 +53,12 @@ const makeMockApi = () => {
|
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
|
|
55
|
-
const base:
|
|
56
|
+
const base: Record<string, unknown> = {};
|
|
56
57
|
Object.defineProperty(base, "__fakeHooks", {value: fakeHooks});
|
|
57
58
|
Object.defineProperty(base, "__injected", {value: injected});
|
|
58
59
|
Object.defineProperty(base, "__tagTypes", {value: enhancedTagTypes});
|
|
59
60
|
|
|
60
|
-
const apiProxy:
|
|
61
|
+
const apiProxy: Record<string, unknown> = new Proxy(base, {
|
|
61
62
|
get(target, prop: string) {
|
|
62
63
|
if (prop === "enhanceEndpoints") {
|
|
63
64
|
return ({addTagTypes}: {addTagTypes: string[]}) => {
|
|
@@ -66,7 +67,7 @@ const makeMockApi = () => {
|
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
69
|
if (prop === "injectEndpoints") {
|
|
69
|
-
return ({endpoints}: {endpoints: (build:
|
|
70
|
+
return ({endpoints}: {endpoints: (build: unknown) => Record<string, BuildSpec>}) => {
|
|
70
71
|
const build = {
|
|
71
72
|
mutation: (spec: BuildSpec) => ({...spec, __kind: "mutation"}),
|
|
72
73
|
query: (spec: BuildSpec) => ({...spec, __kind: "query"}),
|
|
@@ -74,7 +75,8 @@ const makeMockApi = () => {
|
|
|
74
75
|
const defs = endpoints(build);
|
|
75
76
|
for (const [key, def] of Object.entries(defs)) {
|
|
76
77
|
injected[key] = def;
|
|
77
|
-
const kind =
|
|
78
|
+
const kind =
|
|
79
|
+
(def as Record<string, unknown>).__kind === "mutation" ? "mutation" : "query";
|
|
78
80
|
addHookFor(key, kind);
|
|
79
81
|
}
|
|
80
82
|
return apiProxy;
|
|
@@ -108,7 +110,7 @@ describe("useAdminApi", () => {
|
|
|
108
110
|
const api = makeMockApi();
|
|
109
111
|
const result = runHook(() => useAdminApi(api, "/admin/users", "User"));
|
|
110
112
|
|
|
111
|
-
const injected = (api as
|
|
113
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
112
114
|
expect(injected.adminList_User).toBeDefined();
|
|
113
115
|
expect(injected.adminRead_User).toBeDefined();
|
|
114
116
|
expect(injected.adminCreate_User).toBeDefined();
|
|
@@ -116,10 +118,10 @@ describe("useAdminApi", () => {
|
|
|
116
118
|
expect(injected.adminDelete_User).toBeDefined();
|
|
117
119
|
|
|
118
120
|
// tag types include the admin_<model>
|
|
119
|
-
expect((api as
|
|
121
|
+
expect((api as Record<string, unknown>).__tagTypes).toContain("admin_User");
|
|
120
122
|
|
|
121
123
|
// Each endpoint's query fn produces expected URL/method
|
|
122
|
-
const listDef
|
|
124
|
+
const listDef = injected.adminList_User;
|
|
123
125
|
expect(listDef.query({limit: 1})).toEqual({
|
|
124
126
|
method: "GET",
|
|
125
127
|
params: {limit: 1},
|
|
@@ -131,14 +133,14 @@ describe("useAdminApi", () => {
|
|
|
131
133
|
url: "/admin/users",
|
|
132
134
|
});
|
|
133
135
|
|
|
134
|
-
const readDef
|
|
136
|
+
const readDef = injected.adminRead_User;
|
|
135
137
|
expect(readDef.query("abc")).toEqual({
|
|
136
138
|
method: "GET",
|
|
137
139
|
url: "/admin/users/abc",
|
|
138
140
|
});
|
|
139
141
|
expect(readDef.providesTags(null, null, "abc")).toEqual([{id: "abc", type: "admin_User"}]);
|
|
140
142
|
|
|
141
|
-
const createDef
|
|
143
|
+
const createDef = injected.adminCreate_User;
|
|
142
144
|
expect(createDef.query({name: "x"})).toEqual({
|
|
143
145
|
body: {name: "x"},
|
|
144
146
|
method: "POST",
|
|
@@ -146,7 +148,7 @@ describe("useAdminApi", () => {
|
|
|
146
148
|
});
|
|
147
149
|
expect(createDef.invalidatesTags).toEqual(["admin_User"]);
|
|
148
150
|
|
|
149
|
-
const updateDef
|
|
151
|
+
const updateDef = injected.adminUpdate_User;
|
|
150
152
|
expect(updateDef.query({body: {x: 1}, id: "123"})).toEqual({
|
|
151
153
|
body: {x: 1},
|
|
152
154
|
method: "PATCH",
|
|
@@ -157,7 +159,7 @@ describe("useAdminApi", () => {
|
|
|
157
159
|
"admin_User",
|
|
158
160
|
]);
|
|
159
161
|
|
|
160
|
-
const deleteDef
|
|
162
|
+
const deleteDef = injected.adminDelete_User;
|
|
161
163
|
expect(deleteDef.query("123")).toEqual({
|
|
162
164
|
method: "DELETE",
|
|
163
165
|
url: "/admin/users/123",
|
|
@@ -177,9 +179,9 @@ describe("useAdminConfig", () => {
|
|
|
177
179
|
const api = makeMockApi();
|
|
178
180
|
const result = runHook(() => useAdminConfig(api, "/admin"));
|
|
179
181
|
|
|
180
|
-
const injected = (api as
|
|
182
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
181
183
|
expect(injected.adminConfig).toBeDefined();
|
|
182
|
-
const def
|
|
184
|
+
const def = injected.adminConfig;
|
|
183
185
|
expect(def.query()).toEqual({method: "GET", url: "/admin/config"});
|
|
184
186
|
|
|
185
187
|
expect(result).toMatchObject({
|
|
@@ -195,25 +197,25 @@ describe("useAdminScripts", () => {
|
|
|
195
197
|
const api = makeMockApi();
|
|
196
198
|
const result = runHook(() => useAdminScripts(api, "/admin"));
|
|
197
199
|
|
|
198
|
-
const injected = (api as
|
|
200
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
199
201
|
expect(injected.adminRunScript).toBeDefined();
|
|
200
202
|
expect(injected.adminGetScriptTask).toBeDefined();
|
|
201
203
|
expect(injected.adminCancelScriptTask).toBeDefined();
|
|
202
204
|
|
|
203
|
-
const runDef
|
|
205
|
+
const runDef = injected.adminRunScript;
|
|
204
206
|
expect(runDef.query({name: "migrate", wetRun: false})).toEqual({
|
|
205
207
|
method: "POST",
|
|
206
208
|
url: "/admin/scripts/migrate/run?wetRun=false",
|
|
207
209
|
});
|
|
208
210
|
|
|
209
|
-
const getDef
|
|
211
|
+
const getDef = injected.adminGetScriptTask;
|
|
210
212
|
expect(getDef.query("task-1")).toEqual({
|
|
211
213
|
method: "GET",
|
|
212
214
|
url: "/admin/scripts/tasks/task-1",
|
|
213
215
|
});
|
|
214
216
|
expect(getDef.providesTags).toEqual(["admin_scriptTask"]);
|
|
215
217
|
|
|
216
|
-
const cancelDef
|
|
218
|
+
const cancelDef = injected.adminCancelScriptTask;
|
|
217
219
|
expect(cancelDef.query("task-1")).toEqual({
|
|
218
220
|
method: "DELETE",
|
|
219
221
|
url: "/admin/scripts/tasks/task-1",
|
|
@@ -231,29 +233,33 @@ describe("useConfigurationApi", () => {
|
|
|
231
233
|
const api = makeMockApi();
|
|
232
234
|
const result = runHook(() => useConfigurationApi({api, basePath: "/admin/configuration"}));
|
|
233
235
|
|
|
234
|
-
const injected = (api as
|
|
236
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
235
237
|
expect(injected.configMeta).toBeDefined();
|
|
236
238
|
expect(injected.configValues).toBeDefined();
|
|
237
239
|
expect(injected.configUpdate).toBeDefined();
|
|
238
240
|
expect(injected.configRefreshSecrets).toBeDefined();
|
|
239
|
-
expect((api as
|
|
241
|
+
expect((api as Record<string, unknown>).__tagTypes).toContain("configuration");
|
|
240
242
|
|
|
241
|
-
expect((injected.configMeta as
|
|
243
|
+
expect((injected.configMeta as BuildSpec & Record<string, unknown>).query()).toEqual({
|
|
242
244
|
method: "GET",
|
|
243
245
|
url: "/admin/configuration/meta",
|
|
244
246
|
});
|
|
245
|
-
expect((injected.configValues as
|
|
247
|
+
expect((injected.configValues as BuildSpec & Record<string, unknown>).query()).toEqual({
|
|
246
248
|
method: "GET",
|
|
247
249
|
url: "/admin/configuration",
|
|
248
250
|
});
|
|
249
|
-
expect((injected.configValues as
|
|
250
|
-
|
|
251
|
+
expect((injected.configValues as BuildSpec & Record<string, unknown>).providesTags).toEqual([
|
|
252
|
+
"configuration",
|
|
253
|
+
]);
|
|
254
|
+
expect((injected.configUpdate as BuildSpec & Record<string, unknown>).query({a: 1})).toEqual({
|
|
251
255
|
body: {a: 1},
|
|
252
256
|
method: "PATCH",
|
|
253
257
|
url: "/admin/configuration",
|
|
254
258
|
});
|
|
255
|
-
expect((injected.configUpdate as
|
|
256
|
-
|
|
259
|
+
expect((injected.configUpdate as BuildSpec & Record<string, unknown>).invalidatesTags).toEqual([
|
|
260
|
+
"configuration",
|
|
261
|
+
]);
|
|
262
|
+
expect((injected.configRefreshSecrets as BuildSpec & Record<string, unknown>).query()).toEqual({
|
|
257
263
|
method: "POST",
|
|
258
264
|
url: "/admin/configuration/refresh-secrets",
|
|
259
265
|
});
|
|
@@ -270,7 +276,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
270
276
|
const api = makeMockApi();
|
|
271
277
|
const result = runHook(() => useDocumentStorageApi(api, "/documents"));
|
|
272
278
|
|
|
273
|
-
const injected = (api as
|
|
279
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
274
280
|
expect(injected.documentStorageList).toBeDefined();
|
|
275
281
|
expect(injected.documentStorageUpload).toBeDefined();
|
|
276
282
|
expect(injected.documentStorageDownload).toBeDefined();
|
|
@@ -278,7 +284,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
278
284
|
expect(injected.documentStorageDeleteFolder).toBeDefined();
|
|
279
285
|
expect(injected.documentStorageCreateFolder).toBeDefined();
|
|
280
286
|
|
|
281
|
-
const listDef
|
|
287
|
+
const listDef = injected.documentStorageList;
|
|
282
288
|
expect(listDef.query()).toEqual({
|
|
283
289
|
method: "GET",
|
|
284
290
|
params: {},
|
|
@@ -292,7 +298,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
292
298
|
expect(listDef.providesTags).toEqual(["documentStorage"]);
|
|
293
299
|
|
|
294
300
|
// Upload appends prefix to formData when provided
|
|
295
|
-
const uploadDef
|
|
301
|
+
const uploadDef = injected.documentStorageUpload;
|
|
296
302
|
const fd: {append: (k: string, v: string) => void; entries: string[]} = {
|
|
297
303
|
append(k: string, v: string) {
|
|
298
304
|
this.entries.push(`${k}=${v}`);
|
|
@@ -319,7 +325,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
319
325
|
expect(fd2.entries.length).toBe(0);
|
|
320
326
|
|
|
321
327
|
// Download returns a URL with encoded path and a responseHandler
|
|
322
|
-
const downloadDef
|
|
328
|
+
const downloadDef = injected.documentStorageDownload;
|
|
323
329
|
const dlSpec = downloadDef.query("my folder/file.pdf");
|
|
324
330
|
expect(dlSpec.url).toBe("/documents/download/my%20folder%2Ffile.pdf");
|
|
325
331
|
expect(dlSpec.method).toBe("GET");
|
|
@@ -361,18 +367,18 @@ describe("useDocumentStorageApi", () => {
|
|
|
361
367
|
expect(textParsed).toEqual({detail: "boom", status: 500});
|
|
362
368
|
|
|
363
369
|
// Delete endpoints
|
|
364
|
-
const deleteDef
|
|
370
|
+
const deleteDef = injected.documentStorageDelete;
|
|
365
371
|
expect(deleteDef.query("a b.pdf")).toEqual({
|
|
366
372
|
method: "DELETE",
|
|
367
373
|
url: "/documents/a%20b.pdf",
|
|
368
374
|
});
|
|
369
|
-
const deleteFolderDef
|
|
375
|
+
const deleteFolderDef = injected.documentStorageDeleteFolder;
|
|
370
376
|
expect(deleteFolderDef.query("subdir/")).toEqual({
|
|
371
377
|
method: "DELETE",
|
|
372
378
|
url: "/documents/folder/subdir%2F",
|
|
373
379
|
});
|
|
374
380
|
|
|
375
|
-
const createDef
|
|
381
|
+
const createDef = injected.documentStorageCreateFolder;
|
|
376
382
|
expect(createDef.query({folderName: "new", prefix: "a/"})).toEqual({
|
|
377
383
|
body: {folderName: "new", prefix: "a/"},
|
|
378
384
|
method: "POST",
|
package/src/useAdminApi.ts
CHANGED
|
@@ -116,8 +116,7 @@ export const useAdminApi = (api: AdminApi, routePath: string, modelName: string)
|
|
|
116
116
|
const updateKey = `adminUpdate_${modelName}`;
|
|
117
117
|
const deleteKey = `adminDelete_${modelName}`;
|
|
118
118
|
|
|
119
|
-
// RTK Query generates
|
|
120
|
-
// shape is not statically expressible through @reduxjs/toolkit's public types.
|
|
119
|
+
// noExplicitAny: RTK Query generates hook names dynamically from endpoint keys; not statically expressible
|
|
121
120
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
122
121
|
const enhanced = enhancedApi as any;
|
|
123
122
|
return {
|
package/src/useAdminConfig.ts
CHANGED
|
@@ -47,6 +47,7 @@ export const useAdminConfig = (api: AdminApi, baseUrl: string) => {
|
|
|
47
47
|
});
|
|
48
48
|
}, [api, baseUrl]);
|
|
49
49
|
|
|
50
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
50
51
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
51
52
|
const useConfigQuery = (enhancedApi as any).useAdminConfigQuery;
|
|
52
53
|
|
package/src/useAdminScripts.ts
CHANGED
|
@@ -30,6 +30,7 @@ export const useAdminScripts = (api: AdminApi, baseUrl: string) => {
|
|
|
30
30
|
});
|
|
31
31
|
}, [api, baseUrl]);
|
|
32
32
|
|
|
33
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
33
34
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
34
35
|
const enhanced = enhancedApi as any;
|
|
35
36
|
return {
|
|
@@ -72,6 +72,7 @@ export const useConfigurationApi = ({
|
|
|
72
72
|
});
|
|
73
73
|
}, [api, basePath]);
|
|
74
74
|
|
|
75
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
75
76
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
76
77
|
const enhanced = enhancedApi as any;
|
|
77
78
|
return {
|
|
@@ -85,6 +85,7 @@ export const useDocumentStorageApi = (api: AdminApi, basePath: string) => {
|
|
|
85
85
|
});
|
|
86
86
|
}, [api, basePath]);
|
|
87
87
|
|
|
88
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
88
89
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
89
90
|
const enhanced = enhancedApi as any;
|
|
90
91
|
return {
|