@terreno/admin-frontend 0.13.3 → 0.14.1
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/AdminFieldRenderer.d.ts +5 -53
- package/dist/AdminFieldRenderer.js +6 -168
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.d.ts +26 -0
- package/dist/AdminFieldRendererCore.js +138 -0
- package/dist/AdminFieldRendererCore.js.map +1 -0
- package/dist/AdminModelForm.d.ts +6 -7
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +2 -3
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +2 -2
- package/dist/AdminModelTable.js +2 -1
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +6 -7
- package/dist/AdminNestedArrayField.js +26 -2
- package/dist/AdminNestedArrayField.js.map +1 -1
- package/dist/AdminObjectPicker.d.ts +2 -2
- package/dist/AdminObjectPicker.js +13 -7
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +2 -3
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminScriptList.d.ts +2 -2
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +2 -2
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/dist/AdminVersionConfig.d.ts +2 -2
- package/dist/AdminVersionConfig.js +16 -10
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConfigurationScreen.d.ts +2 -2
- package/dist/ConfigurationScreen.js +18 -9
- package/dist/ConfigurationScreen.js.map +1 -1
- package/dist/ConsentFormEditor.d.ts +27 -2
- package/dist/ConsentFormEditor.js +48 -32
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/ConsentFormList.d.ts +2 -1
- package/dist/ConsentFormList.js.map +1 -1
- package/dist/ConsentResponseViewer.d.ts +2 -1
- package/dist/ConsentResponseViewer.js.map +1 -1
- package/dist/DocumentStorageBrowser.js.map +1 -1
- package/dist/types.d.ts +29 -4
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.d.ts +2 -2
- package/dist/useAdminApi.js +8 -5
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminConfig.d.ts +2 -3
- package/dist/useAdminConfig.js +2 -0
- package/dist/useAdminConfig.js.map +1 -1
- package/dist/useAdminScripts.d.ts +2 -3
- package/dist/useAdminScripts.js +6 -3
- package/dist/useAdminScripts.js.map +1 -1
- package/dist/useConfigurationApi.d.ts +11 -8
- package/dist/useConfigurationApi.js +7 -4
- package/dist/useConfigurationApi.js.map +1 -1
- package/dist/useDocumentStorageApi.d.ts +2 -2
- package/dist/useDocumentStorageApi.js +9 -6
- package/dist/useDocumentStorageApi.js.map +1 -1
- package/package.json +2 -2
- package/src/AdminFieldRenderer.test.tsx +48 -22
- package/src/AdminFieldRenderer.tsx +18 -371
- package/src/AdminFieldRendererCore.tsx +356 -0
- package/src/AdminModelForm.test.tsx +146 -40
- package/src/AdminModelForm.tsx +22 -17
- package/src/AdminModelList.test.tsx +14 -5
- package/src/AdminModelList.tsx +5 -5
- package/src/AdminModelTable.test.tsx +58 -31
- package/src/AdminModelTable.tsx +11 -10
- package/src/AdminNestedArrayField.tsx +91 -26
- package/src/AdminObjectPicker.tsx +33 -16
- package/src/AdminPrimitiveArrayField.test.tsx +14 -10
- package/src/AdminPrimitiveArrayField.tsx +2 -3
- package/src/AdminScriptList.test.tsx +7 -4
- package/src/AdminScriptList.tsx +2 -3
- package/src/AdminScriptRunModal.test.tsx +5 -2
- package/src/AdminScriptRunModal.tsx +2 -3
- package/src/AdminVersionConfig.test.tsx +47 -21
- package/src/AdminVersionConfig.tsx +29 -5
- package/src/CheckboxListEditor.test.tsx +9 -6
- package/src/ConfigurationScreen.test.tsx +16 -11
- package/src/ConfigurationScreen.tsx +43 -29
- package/src/ConsentFormEditor.test.tsx +95 -75
- package/src/ConsentFormEditor.tsx +76 -49
- package/src/ConsentFormList.test.tsx +28 -10
- package/src/ConsentFormList.tsx +14 -2
- package/src/ConsentResponseViewer.test.tsx +15 -12
- package/src/ConsentResponseViewer.tsx +3 -2
- package/src/DocumentStorageBrowser.test.tsx +69 -42
- package/src/DocumentStorageBrowser.tsx +4 -4
- package/src/LocaleContentEditor.test.tsx +28 -18
- package/src/isolated/AdminFieldRenderer.isolated.tsx +5 -2
- package/src/isolated/AdminNestedArrayField.isolated.tsx +49 -36
- package/src/isolated/AdminObjectPicker.isolated.tsx +31 -26
- package/src/isolated/AdminRefField.isolated.tsx +4 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +24 -17
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +80 -63
- package/src/isolated/hooks.isolated.tsx +40 -33
- package/src/types.ts +34 -4
- package/src/useAdminApi.ts +21 -13
- package/src/useAdminConfig.ts +5 -4
- package/src/useAdminScripts.ts +9 -7
- package/src/useConfigurationApi.ts +26 -12
- package/src/useDocumentStorageApi.ts +12 -9
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// noExplicitAny: RTK Query API proxy uses dynamic property access and type-erased endpoint builders
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
3
|
/**
|
|
2
4
|
* Tests for admin-frontend hooks: useAdminApi, useAdminConfig,
|
|
3
5
|
* useAdminScripts, useConfigurationApi, useDocumentStorageApi.
|
|
@@ -32,7 +34,7 @@ const makeMockApi = () => {
|
|
|
32
34
|
const injected: CapturedEndpoints = {};
|
|
33
35
|
const enhancedTagTypes: string[] = [];
|
|
34
36
|
|
|
35
|
-
const fakeHooks: Record<string,
|
|
37
|
+
const fakeHooks: Record<string, unknown> = {};
|
|
36
38
|
|
|
37
39
|
const addHookFor = (key: string, type: "query" | "mutation") => {
|
|
38
40
|
const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
@@ -51,12 +53,12 @@ const makeMockApi = () => {
|
|
|
51
53
|
}
|
|
52
54
|
};
|
|
53
55
|
|
|
54
|
-
const base:
|
|
56
|
+
const base: Record<string, unknown> = {};
|
|
55
57
|
Object.defineProperty(base, "__fakeHooks", {value: fakeHooks});
|
|
56
58
|
Object.defineProperty(base, "__injected", {value: injected});
|
|
57
59
|
Object.defineProperty(base, "__tagTypes", {value: enhancedTagTypes});
|
|
58
60
|
|
|
59
|
-
const apiProxy:
|
|
61
|
+
const apiProxy: Record<string, unknown> = new Proxy(base, {
|
|
60
62
|
get(target, prop: string) {
|
|
61
63
|
if (prop === "enhanceEndpoints") {
|
|
62
64
|
return ({addTagTypes}: {addTagTypes: string[]}) => {
|
|
@@ -65,7 +67,7 @@ const makeMockApi = () => {
|
|
|
65
67
|
};
|
|
66
68
|
}
|
|
67
69
|
if (prop === "injectEndpoints") {
|
|
68
|
-
return ({endpoints}: {endpoints: (build:
|
|
70
|
+
return ({endpoints}: {endpoints: (build: unknown) => Record<string, BuildSpec>}) => {
|
|
69
71
|
const build = {
|
|
70
72
|
mutation: (spec: BuildSpec) => ({...spec, __kind: "mutation"}),
|
|
71
73
|
query: (spec: BuildSpec) => ({...spec, __kind: "query"}),
|
|
@@ -73,7 +75,8 @@ const makeMockApi = () => {
|
|
|
73
75
|
const defs = endpoints(build);
|
|
74
76
|
for (const [key, def] of Object.entries(defs)) {
|
|
75
77
|
injected[key] = def;
|
|
76
|
-
const kind =
|
|
78
|
+
const kind =
|
|
79
|
+
(def as Record<string, unknown>).__kind === "mutation" ? "mutation" : "query";
|
|
77
80
|
addHookFor(key, kind);
|
|
78
81
|
}
|
|
79
82
|
return apiProxy;
|
|
@@ -107,7 +110,7 @@ describe("useAdminApi", () => {
|
|
|
107
110
|
const api = makeMockApi();
|
|
108
111
|
const result = runHook(() => useAdminApi(api, "/admin/users", "User"));
|
|
109
112
|
|
|
110
|
-
const injected = (api as
|
|
113
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
111
114
|
expect(injected.adminList_User).toBeDefined();
|
|
112
115
|
expect(injected.adminRead_User).toBeDefined();
|
|
113
116
|
expect(injected.adminCreate_User).toBeDefined();
|
|
@@ -115,10 +118,10 @@ describe("useAdminApi", () => {
|
|
|
115
118
|
expect(injected.adminDelete_User).toBeDefined();
|
|
116
119
|
|
|
117
120
|
// tag types include the admin_<model>
|
|
118
|
-
expect((api as
|
|
121
|
+
expect((api as Record<string, unknown>).__tagTypes).toContain("admin_User");
|
|
119
122
|
|
|
120
123
|
// Each endpoint's query fn produces expected URL/method
|
|
121
|
-
const listDef
|
|
124
|
+
const listDef = injected.adminList_User;
|
|
122
125
|
expect(listDef.query({limit: 1})).toEqual({
|
|
123
126
|
method: "GET",
|
|
124
127
|
params: {limit: 1},
|
|
@@ -130,14 +133,14 @@ describe("useAdminApi", () => {
|
|
|
130
133
|
url: "/admin/users",
|
|
131
134
|
});
|
|
132
135
|
|
|
133
|
-
const readDef
|
|
136
|
+
const readDef = injected.adminRead_User;
|
|
134
137
|
expect(readDef.query("abc")).toEqual({
|
|
135
138
|
method: "GET",
|
|
136
139
|
url: "/admin/users/abc",
|
|
137
140
|
});
|
|
138
141
|
expect(readDef.providesTags(null, null, "abc")).toEqual([{id: "abc", type: "admin_User"}]);
|
|
139
142
|
|
|
140
|
-
const createDef
|
|
143
|
+
const createDef = injected.adminCreate_User;
|
|
141
144
|
expect(createDef.query({name: "x"})).toEqual({
|
|
142
145
|
body: {name: "x"},
|
|
143
146
|
method: "POST",
|
|
@@ -145,7 +148,7 @@ describe("useAdminApi", () => {
|
|
|
145
148
|
});
|
|
146
149
|
expect(createDef.invalidatesTags).toEqual(["admin_User"]);
|
|
147
150
|
|
|
148
|
-
const updateDef
|
|
151
|
+
const updateDef = injected.adminUpdate_User;
|
|
149
152
|
expect(updateDef.query({body: {x: 1}, id: "123"})).toEqual({
|
|
150
153
|
body: {x: 1},
|
|
151
154
|
method: "PATCH",
|
|
@@ -156,7 +159,7 @@ describe("useAdminApi", () => {
|
|
|
156
159
|
"admin_User",
|
|
157
160
|
]);
|
|
158
161
|
|
|
159
|
-
const deleteDef
|
|
162
|
+
const deleteDef = injected.adminDelete_User;
|
|
160
163
|
expect(deleteDef.query("123")).toEqual({
|
|
161
164
|
method: "DELETE",
|
|
162
165
|
url: "/admin/users/123",
|
|
@@ -176,9 +179,9 @@ describe("useAdminConfig", () => {
|
|
|
176
179
|
const api = makeMockApi();
|
|
177
180
|
const result = runHook(() => useAdminConfig(api, "/admin"));
|
|
178
181
|
|
|
179
|
-
const injected = (api as
|
|
182
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
180
183
|
expect(injected.adminConfig).toBeDefined();
|
|
181
|
-
const def
|
|
184
|
+
const def = injected.adminConfig;
|
|
182
185
|
expect(def.query()).toEqual({method: "GET", url: "/admin/config"});
|
|
183
186
|
|
|
184
187
|
expect(result).toMatchObject({
|
|
@@ -194,25 +197,25 @@ describe("useAdminScripts", () => {
|
|
|
194
197
|
const api = makeMockApi();
|
|
195
198
|
const result = runHook(() => useAdminScripts(api, "/admin"));
|
|
196
199
|
|
|
197
|
-
const injected = (api as
|
|
200
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
198
201
|
expect(injected.adminRunScript).toBeDefined();
|
|
199
202
|
expect(injected.adminGetScriptTask).toBeDefined();
|
|
200
203
|
expect(injected.adminCancelScriptTask).toBeDefined();
|
|
201
204
|
|
|
202
|
-
const runDef
|
|
205
|
+
const runDef = injected.adminRunScript;
|
|
203
206
|
expect(runDef.query({name: "migrate", wetRun: false})).toEqual({
|
|
204
207
|
method: "POST",
|
|
205
208
|
url: "/admin/scripts/migrate/run?wetRun=false",
|
|
206
209
|
});
|
|
207
210
|
|
|
208
|
-
const getDef
|
|
211
|
+
const getDef = injected.adminGetScriptTask;
|
|
209
212
|
expect(getDef.query("task-1")).toEqual({
|
|
210
213
|
method: "GET",
|
|
211
214
|
url: "/admin/scripts/tasks/task-1",
|
|
212
215
|
});
|
|
213
216
|
expect(getDef.providesTags).toEqual(["admin_scriptTask"]);
|
|
214
217
|
|
|
215
|
-
const cancelDef
|
|
218
|
+
const cancelDef = injected.adminCancelScriptTask;
|
|
216
219
|
expect(cancelDef.query("task-1")).toEqual({
|
|
217
220
|
method: "DELETE",
|
|
218
221
|
url: "/admin/scripts/tasks/task-1",
|
|
@@ -230,29 +233,33 @@ describe("useConfigurationApi", () => {
|
|
|
230
233
|
const api = makeMockApi();
|
|
231
234
|
const result = runHook(() => useConfigurationApi({api, basePath: "/admin/configuration"}));
|
|
232
235
|
|
|
233
|
-
const injected = (api as
|
|
236
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
234
237
|
expect(injected.configMeta).toBeDefined();
|
|
235
238
|
expect(injected.configValues).toBeDefined();
|
|
236
239
|
expect(injected.configUpdate).toBeDefined();
|
|
237
240
|
expect(injected.configRefreshSecrets).toBeDefined();
|
|
238
|
-
expect((api as
|
|
241
|
+
expect((api as Record<string, unknown>).__tagTypes).toContain("configuration");
|
|
239
242
|
|
|
240
|
-
expect((injected.configMeta as
|
|
243
|
+
expect((injected.configMeta as BuildSpec & Record<string, unknown>).query()).toEqual({
|
|
241
244
|
method: "GET",
|
|
242
245
|
url: "/admin/configuration/meta",
|
|
243
246
|
});
|
|
244
|
-
expect((injected.configValues as
|
|
247
|
+
expect((injected.configValues as BuildSpec & Record<string, unknown>).query()).toEqual({
|
|
245
248
|
method: "GET",
|
|
246
249
|
url: "/admin/configuration",
|
|
247
250
|
});
|
|
248
|
-
expect((injected.configValues as
|
|
249
|
-
|
|
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({
|
|
250
255
|
body: {a: 1},
|
|
251
256
|
method: "PATCH",
|
|
252
257
|
url: "/admin/configuration",
|
|
253
258
|
});
|
|
254
|
-
expect((injected.configUpdate as
|
|
255
|
-
|
|
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({
|
|
256
263
|
method: "POST",
|
|
257
264
|
url: "/admin/configuration/refresh-secrets",
|
|
258
265
|
});
|
|
@@ -269,7 +276,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
269
276
|
const api = makeMockApi();
|
|
270
277
|
const result = runHook(() => useDocumentStorageApi(api, "/documents"));
|
|
271
278
|
|
|
272
|
-
const injected = (api as
|
|
279
|
+
const injected = (api as Record<string, unknown>).__injected as CapturedEndpoints;
|
|
273
280
|
expect(injected.documentStorageList).toBeDefined();
|
|
274
281
|
expect(injected.documentStorageUpload).toBeDefined();
|
|
275
282
|
expect(injected.documentStorageDownload).toBeDefined();
|
|
@@ -277,7 +284,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
277
284
|
expect(injected.documentStorageDeleteFolder).toBeDefined();
|
|
278
285
|
expect(injected.documentStorageCreateFolder).toBeDefined();
|
|
279
286
|
|
|
280
|
-
const listDef
|
|
287
|
+
const listDef = injected.documentStorageList;
|
|
281
288
|
expect(listDef.query()).toEqual({
|
|
282
289
|
method: "GET",
|
|
283
290
|
params: {},
|
|
@@ -291,7 +298,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
291
298
|
expect(listDef.providesTags).toEqual(["documentStorage"]);
|
|
292
299
|
|
|
293
300
|
// Upload appends prefix to formData when provided
|
|
294
|
-
const uploadDef
|
|
301
|
+
const uploadDef = injected.documentStorageUpload;
|
|
295
302
|
const fd: {append: (k: string, v: string) => void; entries: string[]} = {
|
|
296
303
|
append(k: string, v: string) {
|
|
297
304
|
this.entries.push(`${k}=${v}`);
|
|
@@ -318,7 +325,7 @@ describe("useDocumentStorageApi", () => {
|
|
|
318
325
|
expect(fd2.entries.length).toBe(0);
|
|
319
326
|
|
|
320
327
|
// Download returns a URL with encoded path and a responseHandler
|
|
321
|
-
const downloadDef
|
|
328
|
+
const downloadDef = injected.documentStorageDownload;
|
|
322
329
|
const dlSpec = downloadDef.query("my folder/file.pdf");
|
|
323
330
|
expect(dlSpec.url).toBe("/documents/download/my%20folder%2Ffile.pdf");
|
|
324
331
|
expect(dlSpec.method).toBe("GET");
|
|
@@ -360,18 +367,18 @@ describe("useDocumentStorageApi", () => {
|
|
|
360
367
|
expect(textParsed).toEqual({detail: "boom", status: 500});
|
|
361
368
|
|
|
362
369
|
// Delete endpoints
|
|
363
|
-
const deleteDef
|
|
370
|
+
const deleteDef = injected.documentStorageDelete;
|
|
364
371
|
expect(deleteDef.query("a b.pdf")).toEqual({
|
|
365
372
|
method: "DELETE",
|
|
366
373
|
url: "/documents/a%20b.pdf",
|
|
367
374
|
});
|
|
368
|
-
const deleteFolderDef
|
|
375
|
+
const deleteFolderDef = injected.documentStorageDeleteFolder;
|
|
369
376
|
expect(deleteFolderDef.query("subdir/")).toEqual({
|
|
370
377
|
method: "DELETE",
|
|
371
378
|
url: "/documents/folder/subdir%2F",
|
|
372
379
|
});
|
|
373
380
|
|
|
374
|
-
const createDef
|
|
381
|
+
const createDef = injected.documentStorageCreateFolder;
|
|
375
382
|
expect(createDef.query({folderName: "new", prefix: "a/"})).toEqual({
|
|
376
383
|
body: {folderName: "new", prefix: "a/"},
|
|
377
384
|
method: "POST",
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
2
|
import type React from "react";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Type alias for an RTK Query API instance with type-erased generic parameters.
|
|
6
|
+
*
|
|
7
|
+
* The admin panel dynamically injects endpoints into the consumer's RTK Query API at
|
|
8
|
+
* runtime via `api.injectEndpoints()`. The consumer's API is built from a generated
|
|
9
|
+
* OpenAPI SDK with thousands of distinct endpoint types — there is no shared base
|
|
10
|
+
* type we can constrain to, so the generic parameters are erased.
|
|
11
|
+
*/
|
|
12
|
+
// biome-ignore lint/suspicious/noExplicitAny: RTK Query's Api generics are erased at the dynamic endpoint injection boundary
|
|
13
|
+
export type AdminApi = Api<any, any, any, any>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Generic field/document value used throughout the admin panel.
|
|
17
|
+
*
|
|
18
|
+
* Admin screens operate over arbitrary Mongoose documents whose field types are not
|
|
19
|
+
* known statically — they are discovered at runtime via the `/admin/config` endpoint.
|
|
20
|
+
* Read sites must narrow with `typeof` checks before passing to typed UI components.
|
|
21
|
+
*/
|
|
22
|
+
export type AdminFieldValue = unknown;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* RTK Query's `build` argument from `api.injectEndpoints({ endpoints: (build) => ... })`.
|
|
26
|
+
*
|
|
27
|
+
* The build helper is generic over the full endpoint set; since the admin panel injects
|
|
28
|
+
* endpoints dynamically into a consumer-supplied API, the endpoint shapes are not
|
|
29
|
+
* statically expressible here.
|
|
30
|
+
*/
|
|
31
|
+
// biome-ignore lint/suspicious/noExplicitAny: build helper from RTK Query's dynamic injectEndpoints API
|
|
32
|
+
export type EndpointBuilder = any;
|
|
33
|
+
|
|
4
34
|
export interface AdminFieldConfig {
|
|
5
35
|
type: string;
|
|
6
36
|
required: boolean;
|
|
7
37
|
description?: string;
|
|
8
38
|
enum?: string[];
|
|
9
|
-
default?:
|
|
39
|
+
default?: AdminFieldValue;
|
|
10
40
|
ref?: string;
|
|
11
41
|
searchable?: boolean;
|
|
12
42
|
widget?: string;
|
|
@@ -78,7 +108,7 @@ export interface BackgroundTask {
|
|
|
78
108
|
|
|
79
109
|
export interface AdminScreenProps {
|
|
80
110
|
baseUrl: string;
|
|
81
|
-
api:
|
|
111
|
+
api: AdminApi;
|
|
82
112
|
}
|
|
83
113
|
|
|
84
114
|
/**
|
|
@@ -86,7 +116,7 @@ export interface AdminScreenProps {
|
|
|
86
116
|
* custom renderer is a drop-in replacement.
|
|
87
117
|
*/
|
|
88
118
|
export interface RefFieldRendererProps {
|
|
89
|
-
api:
|
|
119
|
+
api: AdminApi;
|
|
90
120
|
baseUrl: string;
|
|
91
121
|
routePath: string;
|
|
92
122
|
refModelName: string;
|
|
@@ -125,7 +155,7 @@ export interface DocumentListResponse {
|
|
|
125
155
|
}
|
|
126
156
|
|
|
127
157
|
export interface DocumentStorageBrowserProps {
|
|
128
|
-
api:
|
|
158
|
+
api: AdminApi;
|
|
129
159
|
basePath: string;
|
|
130
160
|
title?: string;
|
|
131
161
|
allowDelete?: boolean;
|
package/src/useAdminApi.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {useMemo} from "react";
|
|
2
|
+
import type {AdminApi, EndpointBuilder} from "./types";
|
|
3
|
+
|
|
4
|
+
// biome-ignore lint/suspicious/noExplicitAny: payload bodies vary across admin models — handled at runtime
|
|
5
|
+
type AdminPayload = any;
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: RTK Query tag callback args have a complex generic shape we erase here
|
|
7
|
+
type TagArg = any;
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Hook that generates RTK Query CRUD hooks for a specific admin model.
|
|
@@ -44,7 +49,7 @@ import {useMemo} from "react";
|
|
|
44
49
|
* @see useAdminConfig for fetching model configurations
|
|
45
50
|
* @see AdminModelTable for usage in the table view
|
|
46
51
|
*/
|
|
47
|
-
export const useAdminApi = (api:
|
|
52
|
+
export const useAdminApi = (api: AdminApi, routePath: string, modelName: string) => {
|
|
48
53
|
const enhancedApi = useMemo(() => {
|
|
49
54
|
const listKey = `adminList_${modelName}`;
|
|
50
55
|
const readKey = `adminRead_${modelName}`;
|
|
@@ -54,17 +59,17 @@ export const useAdminApi = (api: Api<any, any, any, any>, routePath: string, mod
|
|
|
54
59
|
|
|
55
60
|
const tagType = `admin_${modelName}`;
|
|
56
61
|
return api.enhanceEndpoints({addTagTypes: [tagType]}).injectEndpoints({
|
|
57
|
-
endpoints: (build:
|
|
62
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
58
63
|
[listKey]: build.query({
|
|
59
64
|
providesTags: [`admin_${modelName}`],
|
|
60
|
-
query: (params:
|
|
65
|
+
query: (params: Record<string, unknown> | undefined) => ({
|
|
61
66
|
method: "GET",
|
|
62
67
|
params: params ?? {},
|
|
63
68
|
url: routePath,
|
|
64
69
|
}),
|
|
65
70
|
}),
|
|
66
71
|
[readKey]: build.query({
|
|
67
|
-
providesTags: (_result:
|
|
72
|
+
providesTags: (_result: TagArg, _error: TagArg, id: string) => [
|
|
68
73
|
{id, type: `admin_${modelName}`},
|
|
69
74
|
],
|
|
70
75
|
query: (id: string) => ({
|
|
@@ -74,18 +79,18 @@ export const useAdminApi = (api: Api<any, any, any, any>, routePath: string, mod
|
|
|
74
79
|
}),
|
|
75
80
|
[createKey]: build.mutation({
|
|
76
81
|
invalidatesTags: [`admin_${modelName}`],
|
|
77
|
-
query: (body:
|
|
82
|
+
query: (body: AdminPayload) => ({
|
|
78
83
|
body,
|
|
79
84
|
method: "POST",
|
|
80
85
|
url: routePath,
|
|
81
86
|
}),
|
|
82
87
|
}),
|
|
83
88
|
[updateKey]: build.mutation({
|
|
84
|
-
invalidatesTags: (_result:
|
|
89
|
+
invalidatesTags: (_result: TagArg, _error: TagArg, {id}: {id: string}) => [
|
|
85
90
|
{id, type: `admin_${modelName}`},
|
|
86
91
|
`admin_${modelName}`,
|
|
87
92
|
],
|
|
88
|
-
query: ({id, body}: {id: string; body:
|
|
93
|
+
query: ({id, body}: {id: string; body: AdminPayload}) => ({
|
|
89
94
|
body,
|
|
90
95
|
method: "PATCH",
|
|
91
96
|
url: `${routePath}/${id}`,
|
|
@@ -111,11 +116,14 @@ export const useAdminApi = (api: Api<any, any, any, any>, routePath: string, mod
|
|
|
111
116
|
const updateKey = `adminUpdate_${modelName}`;
|
|
112
117
|
const deleteKey = `adminDelete_${modelName}`;
|
|
113
118
|
|
|
119
|
+
// noExplicitAny: RTK Query generates hook names dynamically from endpoint keys; not statically expressible
|
|
120
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
121
|
+
const enhanced = enhancedApi as any;
|
|
114
122
|
return {
|
|
115
|
-
useCreateMutation:
|
|
116
|
-
useDeleteMutation:
|
|
117
|
-
useListQuery:
|
|
118
|
-
useReadQuery:
|
|
119
|
-
useUpdateMutation:
|
|
123
|
+
useCreateMutation: enhanced[`use${capitalize(createKey)}Mutation`],
|
|
124
|
+
useDeleteMutation: enhanced[`use${capitalize(deleteKey)}Mutation`],
|
|
125
|
+
useListQuery: enhanced[`use${capitalize(listKey)}Query`],
|
|
126
|
+
useReadQuery: enhanced[`use${capitalize(readKey)}Query`],
|
|
127
|
+
useUpdateMutation: enhanced[`use${capitalize(updateKey)}Mutation`],
|
|
120
128
|
};
|
|
121
129
|
};
|
package/src/useAdminConfig.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {useMemo} from "react";
|
|
3
|
-
import type {AdminConfigResponse} from "./types";
|
|
2
|
+
import type {AdminApi, AdminConfigResponse, EndpointBuilder} from "./types";
|
|
4
3
|
|
|
5
4
|
const ENDPOINT_NAME = "adminConfig";
|
|
6
5
|
|
|
@@ -33,10 +32,10 @@ const ENDPOINT_NAME = "adminConfig";
|
|
|
33
32
|
* @see AdminConfigResponse for the returned configuration structure
|
|
34
33
|
* @see AdminModelList for usage in the model list screen
|
|
35
34
|
*/
|
|
36
|
-
export const useAdminConfig = (api:
|
|
35
|
+
export const useAdminConfig = (api: AdminApi, baseUrl: string) => {
|
|
37
36
|
const enhancedApi = useMemo(() => {
|
|
38
37
|
return api.injectEndpoints({
|
|
39
|
-
endpoints: (build:
|
|
38
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
40
39
|
[ENDPOINT_NAME]: build.query({
|
|
41
40
|
query: () => ({
|
|
42
41
|
method: "GET",
|
|
@@ -48,6 +47,8 @@ export const useAdminConfig = (api: Api<any, any, any, any>, baseUrl: string) =>
|
|
|
48
47
|
});
|
|
49
48
|
}, [api, baseUrl]);
|
|
50
49
|
|
|
50
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
51
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
51
52
|
const useConfigQuery = (enhancedApi as any).useAdminConfigQuery;
|
|
52
53
|
|
|
53
54
|
const {data, isLoading, error} = useConfigQuery();
|
package/src/useAdminScripts.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {useMemo} from "react";
|
|
3
|
-
import type {BackgroundTask} from "./types";
|
|
2
|
+
import type {AdminApi, BackgroundTask, EndpointBuilder} from "./types";
|
|
4
3
|
|
|
5
|
-
export const useAdminScripts = (api:
|
|
4
|
+
export const useAdminScripts = (api: AdminApi, baseUrl: string) => {
|
|
6
5
|
const enhancedApi = useMemo(() => {
|
|
7
6
|
return api.injectEndpoints({
|
|
8
|
-
endpoints: (build:
|
|
7
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
9
8
|
adminCancelScriptTask: build.mutation({
|
|
10
9
|
invalidatesTags: ["admin_scriptTask"],
|
|
11
10
|
query: (taskId: string) => ({
|
|
@@ -31,16 +30,19 @@ export const useAdminScripts = (api: Api<any, any, any, any>, baseUrl: string) =
|
|
|
31
30
|
});
|
|
32
31
|
}, [api, baseUrl]);
|
|
33
32
|
|
|
33
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
34
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
35
|
+
const enhanced = enhancedApi as any;
|
|
34
36
|
return {
|
|
35
|
-
useCancelScriptTaskMutation:
|
|
37
|
+
useCancelScriptTaskMutation: enhanced.useAdminCancelScriptTaskMutation as () => [
|
|
36
38
|
(taskId: string) => {unwrap: () => Promise<{task: BackgroundTask; message: string}>},
|
|
37
39
|
{isLoading: boolean},
|
|
38
40
|
],
|
|
39
|
-
useGetScriptTaskQuery:
|
|
41
|
+
useGetScriptTaskQuery: enhanced.useAdminGetScriptTaskQuery as (
|
|
40
42
|
taskId: string,
|
|
41
43
|
options?: {skip?: boolean; pollingInterval?: number}
|
|
42
44
|
) => {data: {task: BackgroundTask} | undefined; isLoading: boolean; error: unknown},
|
|
43
|
-
useRunScriptMutation:
|
|
45
|
+
useRunScriptMutation: enhanced.useAdminRunScriptMutation as () => [
|
|
44
46
|
(args: {name: string; wetRun: boolean}) => {unwrap: () => Promise<{taskId: string}>},
|
|
45
47
|
{isLoading: boolean},
|
|
46
48
|
],
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {useMemo} from "react";
|
|
2
|
+
import type {AdminApi, EndpointBuilder} from "./types";
|
|
3
|
+
|
|
4
|
+
// The configuration document shape varies per consumer — different apps register different
|
|
5
|
+
// configuration sections via @terreno/api's Configuration model.
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: configuration values are heterogeneous per consumer
|
|
7
|
+
type ConfigBody = any;
|
|
8
|
+
// biome-ignore lint/suspicious/noExplicitAny: RTK Query's hook return shape varies per endpoint
|
|
9
|
+
type RtkHookResult = any;
|
|
10
|
+
// biome-ignore lint/suspicious/noExplicitAny: RTK Query's mutation trigger has a complex generic shape
|
|
11
|
+
type RtkMutationTrigger = any;
|
|
12
|
+
// biome-ignore lint/suspicious/noExplicitAny: RTK Query's error union type erases at the hook boundary
|
|
13
|
+
type RtkError = any;
|
|
3
14
|
|
|
4
15
|
interface UseConfigurationApiOptions {
|
|
5
|
-
api:
|
|
16
|
+
api: AdminApi;
|
|
6
17
|
basePath: string;
|
|
7
18
|
}
|
|
8
19
|
|
|
9
20
|
interface UseConfigurationApiResult {
|
|
10
|
-
useMetaQuery: () => {data:
|
|
11
|
-
useRefreshSecretsMutation: () => [
|
|
12
|
-
useUpdateMutation: () => [
|
|
13
|
-
useValuesQuery: () => {data:
|
|
21
|
+
useMetaQuery: () => {data: RtkHookResult; isLoading: boolean; error: RtkError};
|
|
22
|
+
useRefreshSecretsMutation: () => [RtkMutationTrigger, {isLoading: boolean}];
|
|
23
|
+
useUpdateMutation: () => [RtkMutationTrigger, {isLoading: boolean}];
|
|
24
|
+
useValuesQuery: () => {data: RtkHookResult; isLoading: boolean; error: RtkError};
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
/**
|
|
@@ -28,7 +39,7 @@ export const useConfigurationApi = ({
|
|
|
28
39
|
}: UseConfigurationApiOptions): UseConfigurationApiResult => {
|
|
29
40
|
const enhancedApi = useMemo(() => {
|
|
30
41
|
return api.enhanceEndpoints({addTagTypes: ["configuration"]}).injectEndpoints({
|
|
31
|
-
endpoints: (build:
|
|
42
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
32
43
|
configMeta: build.query({
|
|
33
44
|
query: () => ({
|
|
34
45
|
method: "GET",
|
|
@@ -43,7 +54,7 @@ export const useConfigurationApi = ({
|
|
|
43
54
|
}),
|
|
44
55
|
configUpdate: build.mutation({
|
|
45
56
|
invalidatesTags: ["configuration"],
|
|
46
|
-
query: (body:
|
|
57
|
+
query: (body: ConfigBody) => ({
|
|
47
58
|
body,
|
|
48
59
|
method: "PATCH",
|
|
49
60
|
url: basePath,
|
|
@@ -61,10 +72,13 @@ export const useConfigurationApi = ({
|
|
|
61
72
|
});
|
|
62
73
|
}, [api, basePath]);
|
|
63
74
|
|
|
75
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
76
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
77
|
+
const enhanced = enhancedApi as any;
|
|
64
78
|
return {
|
|
65
|
-
useMetaQuery:
|
|
66
|
-
useRefreshSecretsMutation:
|
|
67
|
-
useUpdateMutation:
|
|
68
|
-
useValuesQuery:
|
|
79
|
+
useMetaQuery: enhanced.useConfigMetaQuery,
|
|
80
|
+
useRefreshSecretsMutation: enhanced.useConfigRefreshSecretsMutation,
|
|
81
|
+
useUpdateMutation: enhanced.useConfigUpdateMutation,
|
|
82
|
+
useValuesQuery: enhanced.useConfigValuesQuery,
|
|
69
83
|
};
|
|
70
84
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {useMemo} from "react";
|
|
2
|
+
import type {AdminApi, EndpointBuilder} from "./types";
|
|
3
3
|
|
|
4
|
-
export const useDocumentStorageApi = (api:
|
|
4
|
+
export const useDocumentStorageApi = (api: AdminApi, basePath: string) => {
|
|
5
5
|
const enhancedApi = useMemo(() => {
|
|
6
6
|
return api.injectEndpoints({
|
|
7
|
-
endpoints: (build:
|
|
7
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
8
8
|
documentStorageCreateFolder: build.mutation({
|
|
9
9
|
invalidatesTags: ["documentStorage"],
|
|
10
10
|
query: ({folderName, prefix}: {folderName: string; prefix?: string}) => ({
|
|
@@ -85,12 +85,15 @@ export const useDocumentStorageApi = (api: Api<any, any, any, any>, basePath: st
|
|
|
85
85
|
});
|
|
86
86
|
}, [api, basePath]);
|
|
87
87
|
|
|
88
|
+
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
89
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
90
|
+
const enhanced = enhancedApi as any;
|
|
88
91
|
return {
|
|
89
|
-
useCreateFolderMutation:
|
|
90
|
-
useDeleteFolderMutation:
|
|
91
|
-
useDeleteMutation:
|
|
92
|
-
useLazyDownloadQuery:
|
|
93
|
-
useListQuery:
|
|
94
|
-
useUploadMutation:
|
|
92
|
+
useCreateFolderMutation: enhanced.useDocumentStorageCreateFolderMutation,
|
|
93
|
+
useDeleteFolderMutation: enhanced.useDocumentStorageDeleteFolderMutation,
|
|
94
|
+
useDeleteMutation: enhanced.useDocumentStorageDeleteMutation,
|
|
95
|
+
useLazyDownloadQuery: enhanced.useLazyDocumentStorageDownloadQuery,
|
|
96
|
+
useListQuery: enhanced.useDocumentStorageListQuery,
|
|
97
|
+
useUploadMutation: enhanced.useDocumentStorageUploadMutation,
|
|
95
98
|
};
|
|
96
99
|
};
|