@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.
Files changed (101) hide show
  1. package/dist/AdminFieldRenderer.d.ts +5 -53
  2. package/dist/AdminFieldRenderer.js +6 -168
  3. package/dist/AdminFieldRenderer.js.map +1 -1
  4. package/dist/AdminFieldRendererCore.d.ts +26 -0
  5. package/dist/AdminFieldRendererCore.js +138 -0
  6. package/dist/AdminFieldRendererCore.js.map +1 -0
  7. package/dist/AdminModelForm.d.ts +6 -7
  8. package/dist/AdminModelForm.js.map +1 -1
  9. package/dist/AdminModelList.d.ts +2 -3
  10. package/dist/AdminModelList.js.map +1 -1
  11. package/dist/AdminModelTable.d.ts +2 -2
  12. package/dist/AdminModelTable.js +2 -1
  13. package/dist/AdminModelTable.js.map +1 -1
  14. package/dist/AdminNestedArrayField.d.ts +6 -7
  15. package/dist/AdminNestedArrayField.js +26 -2
  16. package/dist/AdminNestedArrayField.js.map +1 -1
  17. package/dist/AdminObjectPicker.d.ts +2 -2
  18. package/dist/AdminObjectPicker.js +13 -7
  19. package/dist/AdminObjectPicker.js.map +1 -1
  20. package/dist/AdminPrimitiveArrayField.d.ts +2 -3
  21. package/dist/AdminPrimitiveArrayField.js.map +1 -1
  22. package/dist/AdminScriptList.d.ts +2 -2
  23. package/dist/AdminScriptList.js.map +1 -1
  24. package/dist/AdminScriptRunModal.d.ts +2 -2
  25. package/dist/AdminScriptRunModal.js.map +1 -1
  26. package/dist/AdminVersionConfig.d.ts +2 -2
  27. package/dist/AdminVersionConfig.js +16 -10
  28. package/dist/AdminVersionConfig.js.map +1 -1
  29. package/dist/ConfigurationScreen.d.ts +2 -2
  30. package/dist/ConfigurationScreen.js +18 -9
  31. package/dist/ConfigurationScreen.js.map +1 -1
  32. package/dist/ConsentFormEditor.d.ts +27 -2
  33. package/dist/ConsentFormEditor.js +48 -32
  34. package/dist/ConsentFormEditor.js.map +1 -1
  35. package/dist/ConsentFormList.d.ts +2 -1
  36. package/dist/ConsentFormList.js.map +1 -1
  37. package/dist/ConsentResponseViewer.d.ts +2 -1
  38. package/dist/ConsentResponseViewer.js.map +1 -1
  39. package/dist/DocumentStorageBrowser.js.map +1 -1
  40. package/dist/types.d.ts +29 -4
  41. package/dist/types.js.map +1 -1
  42. package/dist/useAdminApi.d.ts +2 -2
  43. package/dist/useAdminApi.js +8 -5
  44. package/dist/useAdminApi.js.map +1 -1
  45. package/dist/useAdminConfig.d.ts +2 -3
  46. package/dist/useAdminConfig.js +2 -0
  47. package/dist/useAdminConfig.js.map +1 -1
  48. package/dist/useAdminScripts.d.ts +2 -3
  49. package/dist/useAdminScripts.js +6 -3
  50. package/dist/useAdminScripts.js.map +1 -1
  51. package/dist/useConfigurationApi.d.ts +11 -8
  52. package/dist/useConfigurationApi.js +7 -4
  53. package/dist/useConfigurationApi.js.map +1 -1
  54. package/dist/useDocumentStorageApi.d.ts +2 -2
  55. package/dist/useDocumentStorageApi.js +9 -6
  56. package/dist/useDocumentStorageApi.js.map +1 -1
  57. package/package.json +2 -2
  58. package/src/AdminFieldRenderer.test.tsx +48 -22
  59. package/src/AdminFieldRenderer.tsx +18 -371
  60. package/src/AdminFieldRendererCore.tsx +356 -0
  61. package/src/AdminModelForm.test.tsx +146 -40
  62. package/src/AdminModelForm.tsx +22 -17
  63. package/src/AdminModelList.test.tsx +14 -5
  64. package/src/AdminModelList.tsx +5 -5
  65. package/src/AdminModelTable.test.tsx +58 -31
  66. package/src/AdminModelTable.tsx +11 -10
  67. package/src/AdminNestedArrayField.tsx +91 -26
  68. package/src/AdminObjectPicker.tsx +33 -16
  69. package/src/AdminPrimitiveArrayField.test.tsx +14 -10
  70. package/src/AdminPrimitiveArrayField.tsx +2 -3
  71. package/src/AdminScriptList.test.tsx +7 -4
  72. package/src/AdminScriptList.tsx +2 -3
  73. package/src/AdminScriptRunModal.test.tsx +5 -2
  74. package/src/AdminScriptRunModal.tsx +2 -3
  75. package/src/AdminVersionConfig.test.tsx +47 -21
  76. package/src/AdminVersionConfig.tsx +29 -5
  77. package/src/CheckboxListEditor.test.tsx +9 -6
  78. package/src/ConfigurationScreen.test.tsx +16 -11
  79. package/src/ConfigurationScreen.tsx +43 -29
  80. package/src/ConsentFormEditor.test.tsx +95 -75
  81. package/src/ConsentFormEditor.tsx +76 -49
  82. package/src/ConsentFormList.test.tsx +28 -10
  83. package/src/ConsentFormList.tsx +14 -2
  84. package/src/ConsentResponseViewer.test.tsx +15 -12
  85. package/src/ConsentResponseViewer.tsx +3 -2
  86. package/src/DocumentStorageBrowser.test.tsx +69 -42
  87. package/src/DocumentStorageBrowser.tsx +4 -4
  88. package/src/LocaleContentEditor.test.tsx +28 -18
  89. package/src/isolated/AdminFieldRenderer.isolated.tsx +5 -2
  90. package/src/isolated/AdminNestedArrayField.isolated.tsx +49 -36
  91. package/src/isolated/AdminObjectPicker.isolated.tsx +31 -26
  92. package/src/isolated/AdminRefField.isolated.tsx +4 -1
  93. package/src/isolated/AdminScriptRunModal.isolated.tsx +24 -17
  94. package/src/isolated/DocumentStorageBrowser.isolated.tsx +80 -63
  95. package/src/isolated/hooks.isolated.tsx +40 -33
  96. package/src/types.ts +34 -4
  97. package/src/useAdminApi.ts +21 -13
  98. package/src/useAdminConfig.ts +5 -4
  99. package/src/useAdminScripts.ts +9 -7
  100. package/src/useConfigurationApi.ts +26 -12
  101. package/src/useDocumentStorageApi.ts +12 -9
@@ -1,32 +1,41 @@
1
+ // noExplicitAny: test mocks use type-erased RTK Query API doubles and UNSAFE_root traversal
2
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
1
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
2
4
  import {renderWithTheme} from "@terreno/ui/src/test-utils";
3
5
  import React from "react";
6
+ import type {ReactTestInstance} from "react-test-renderer";
4
7
  import {act, fireEvent} from "../../ui/node_modules/@testing-library/react-native";
8
+ import type {AdminApi} from "./types";
5
9
 
6
10
  interface State {
7
- formData: any;
11
+ formData: Record<string, unknown> | null;
8
12
  isFormLoading: boolean;
9
13
  }
10
14
  const state: State = {formData: null, isFormLoading: false};
11
- const createCalls: any[] = [];
12
- const updateCalls: any[] = [];
15
+ const createCalls: unknown[] = [];
16
+ const updateCalls: unknown[] = [];
13
17
  const publishCalls: string[] = [];
14
- const generateCalls: any[] = [];
15
- const translateCalls: any[] = [];
16
- let createImpl: (body: any) => Promise<any> = async (b) => ({_id: "new-id", ...b});
17
- let updateImpl: (args: any) => Promise<any> = async (a) => ({_id: a.id});
18
- let publishImpl: (id: string) => Promise<any> = async () => ({});
19
- let generateImpl: (body: any) => Promise<any> = async () => ({
18
+ const generateCalls: unknown[] = [];
19
+ const translateCalls: unknown[] = [];
20
+ let createImpl: (body: unknown) => Promise<unknown> = async (b) => ({
21
+ _id: "new-id",
22
+ ...(b as Record<string, unknown>),
23
+ });
24
+ let updateImpl: (args: unknown) => Promise<unknown> = async (a) => ({
25
+ _id: (a as Record<string, unknown>).id,
26
+ });
27
+ let publishImpl: (id: string) => Promise<unknown> = async () => ({});
28
+ let generateImpl: (body: unknown) => Promise<unknown> = async () => ({
20
29
  data: {content: "generated"},
21
30
  });
22
- let translateImpl: (body: any) => Promise<any> = async () => ({
31
+ let translateImpl: (body: unknown) => Promise<unknown> = async () => ({
23
32
  data: {content: "translated"},
24
33
  });
25
34
 
26
35
  mock.module("./useAdminApi", () => ({
27
36
  useAdminApi: () => ({
28
37
  useCreateMutation: () => [
29
- (body: any) => ({
38
+ (body: unknown) => ({
30
39
  unwrap: async () => {
31
40
  createCalls.push(body);
32
41
  return createImpl(body);
@@ -41,7 +50,7 @@ mock.module("./useAdminApi", () => ({
41
50
  return {data: state.formData, isLoading: state.isFormLoading};
42
51
  },
43
52
  useUpdateMutation: () => [
44
- (args: any) => ({
53
+ (args: unknown) => ({
45
54
  unwrap: async () => {
46
55
  updateCalls.push(args);
47
56
  return updateImpl(args);
@@ -52,11 +61,11 @@ mock.module("./useAdminApi", () => ({
52
61
  }),
53
62
  }));
54
63
 
55
- const mutationSpecs: any[] = [];
64
+ const mutationSpecs: unknown[] = [];
56
65
  const makeApi = () => ({
57
- injectEndpoints: ({endpoints}: {endpoints: (b: any) => Record<string, any>}) => {
66
+ injectEndpoints: ({endpoints}: {endpoints: (b: unknown) => Record<string, unknown>}) => {
58
67
  endpoints({
59
- mutation: (spec: any) => {
68
+ mutation: (spec: Record<string, unknown>) => {
60
69
  // Invoke the mutation query lambda with both an object body and a string
61
70
  // id so we exercise the URL + body builders for every mutation shape
62
71
  // (generate/translate take a body object, publish takes an id string).
@@ -75,11 +84,11 @@ const makeApi = () => ({
75
84
  }
76
85
  return spec;
77
86
  },
78
- query: (spec: any) => spec,
87
+ query: (spec: unknown) => spec,
79
88
  });
80
89
  return {
81
90
  useGenerateConsentContentMutation: () => [
82
- (body: any) => ({
91
+ (body: unknown) => ({
83
92
  unwrap: async () => {
84
93
  generateCalls.push(body);
85
94
  return generateImpl(body);
@@ -97,7 +106,7 @@ const makeApi = () => ({
97
106
  {isLoading: false},
98
107
  ],
99
108
  useTranslateConsentContentMutation: () => [
100
- (body: any) => ({
109
+ (body: unknown) => ({
101
110
  unwrap: async () => {
102
111
  translateCalls.push(body);
103
112
  return translateImpl(body);
@@ -111,7 +120,7 @@ const makeApi = () => ({
111
120
 
112
121
  import {ConsentFormEditor} from "./ConsentFormEditor";
113
122
 
114
- const press = async (el: any): Promise<void> => {
123
+ const press = async (el: ReactTestInstance): Promise<void> => {
115
124
  await act(async () => {
116
125
  fireEvent.press(el);
117
126
  await new Promise((r) => setTimeout(r, 150));
@@ -128,8 +137,8 @@ describe("ConsentFormEditor", () => {
128
137
  generateCalls.length = 0;
129
138
  translateCalls.length = 0;
130
139
  mutationSpecs.length = 0;
131
- createImpl = async (b) => ({_id: "new-id", ...b});
132
- updateImpl = async (a) => ({_id: a.id});
140
+ createImpl = async (b) => ({_id: "new-id", ...(b as Record<string, unknown>)});
141
+ updateImpl = async (a) => ({_id: (a as Record<string, unknown>).id});
133
142
  publishImpl = async () => ({});
134
143
  generateImpl = async () => ({data: {content: "generated"}});
135
144
  translateImpl = async () => ({data: {content: "translated"}});
@@ -138,7 +147,7 @@ describe("ConsentFormEditor", () => {
138
147
  it("renders loading state in edit mode", () => {
139
148
  state.isFormLoading = true;
140
149
  const {toJSON} = renderWithTheme(
141
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" id="f1" />
150
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" id="f1" />
142
151
  );
143
152
  expect(toJSON()).toBeDefined();
144
153
  });
@@ -153,7 +162,7 @@ describe("ConsentFormEditor", () => {
153
162
  state.isFormLoading = true;
154
163
  const {rerender, getByTestId} = renderWithTheme(
155
164
  <ConsentFormEditor
156
- api={makeApi() as any}
165
+ api={makeApi() as unknown as AdminApi}
157
166
  baseUrl="/admin"
158
167
  id="f1"
159
168
  supportedLocales={supportedLocales}
@@ -179,7 +188,7 @@ describe("ConsentFormEditor", () => {
179
188
  };
180
189
  rerender(
181
190
  <ConsentFormEditor
182
- api={makeApi() as any}
191
+ api={makeApi() as unknown as AdminApi}
183
192
  baseUrl="/admin"
184
193
  id="f1"
185
194
  supportedLocales={supportedLocales}
@@ -191,23 +200,23 @@ describe("ConsentFormEditor", () => {
191
200
 
192
201
  it("renders create mode with default values", () => {
193
202
  const {getByTestId} = renderWithTheme(
194
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" />
203
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
195
204
  );
196
205
  expect(getByTestId("consent-form-title-input")).toBeDefined();
197
206
  });
198
207
 
199
208
  it("fails validation without title or slug", async () => {
200
209
  const {getByTestId} = renderWithTheme(
201
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" />
210
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
202
211
  );
203
212
  await press(getByTestId("consent-form-save-button"));
204
213
  expect(createCalls.length).toBe(0);
205
214
  });
206
215
 
207
216
  it("auto-slugs titles and creates a form on save", async () => {
208
- const onSave = mock((_: any) => undefined);
217
+ const onSave = mock((_: unknown) => undefined);
209
218
  const {getByTestId} = renderWithTheme(
210
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" onSave={onSave} />
219
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" onSave={onSave} />
211
220
  );
212
221
  await act(async () => {
213
222
  fireEvent.changeText(getByTestId("consent-form-title-input"), "Hello World");
@@ -215,7 +224,7 @@ describe("ConsentFormEditor", () => {
215
224
  });
216
225
  await press(getByTestId("consent-form-save-button"));
217
226
  expect(createCalls.length).toBe(1);
218
- expect(createCalls[0].slug).toBe("hello-world");
227
+ expect((createCalls[0] as Record<string, unknown>).slug).toBe("hello-world");
219
228
  expect(onSave).toHaveBeenCalled();
220
229
  });
221
230
 
@@ -224,7 +233,7 @@ describe("ConsentFormEditor", () => {
224
233
  throw new Error("conflict");
225
234
  };
226
235
  const {getByTestId} = renderWithTheme(
227
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" />
236
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
228
237
  );
229
238
  await act(async () => {
230
239
  fireEvent.changeText(getByTestId("consent-form-title-input"), "Title");
@@ -236,7 +245,7 @@ describe("ConsentFormEditor", () => {
236
245
  });
237
246
  await press(getByTestId("consent-form-save-button"));
238
247
  expect(createCalls.length).toBe(1);
239
- expect(createCalls[0].slug).toBe("custom-slug");
248
+ expect((createCalls[0] as Record<string, unknown>).slug).toBe("custom-slug");
240
249
  });
241
250
 
242
251
  it("loads form data in edit mode and saves an update", async () => {
@@ -258,7 +267,7 @@ describe("ConsentFormEditor", () => {
258
267
  };
259
268
  const {getByTestId} = renderWithTheme(
260
269
  <ConsentFormEditor
261
- api={makeApi() as any}
270
+ api={makeApi() as unknown as AdminApi}
262
271
  baseUrl="/admin"
263
272
  hasAiSupport
264
273
  id="f1"
@@ -267,14 +276,16 @@ describe("ConsentFormEditor", () => {
267
276
  );
268
277
  await press(getByTestId("consent-form-save-button"));
269
278
  expect(updateCalls.length).toBe(1);
270
- expect(updateCalls[0].id).toBe("f1");
271
- expect(updateCalls[0].body.title).toBe("Privacy");
279
+ expect((updateCalls[0] as Record<string, unknown>).id).toBe("f1");
280
+ expect(
281
+ ((updateCalls[0] as Record<string, unknown>).body as Record<string, unknown>).title
282
+ ).toBe("Privacy");
272
283
  });
273
284
 
274
285
  it("publishes a form on publish press", async () => {
275
286
  state.formData = {slug: "s", title: "T"};
276
287
  const {getByTestId} = renderWithTheme(
277
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" id="f1" />
288
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" id="f1" />
278
289
  );
279
290
  await press(getByTestId("consent-form-publish-button"));
280
291
  expect(publishCalls).toEqual(["f1"]);
@@ -286,7 +297,7 @@ describe("ConsentFormEditor", () => {
286
297
  throw new Error("fail");
287
298
  };
288
299
  const {getByTestId} = renderWithTheme(
289
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" id="f1" />
300
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" id="f1" />
290
301
  );
291
302
  await press(getByTestId("consent-form-publish-button"));
292
303
  expect(publishCalls.length).toBe(1);
@@ -294,7 +305,7 @@ describe("ConsentFormEditor", () => {
294
305
 
295
306
  it("opens the AI generate modal in create mode", async () => {
296
307
  const {getByTestId, toJSON} = renderWithTheme(
297
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" hasAiSupport />
308
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" hasAiSupport />
298
309
  );
299
310
  await press(getByTestId("consent-form-generate-button"));
300
311
  expect(toJSON()).toBeDefined();
@@ -302,7 +313,7 @@ describe("ConsentFormEditor", () => {
302
313
 
303
314
  it("adds, edits, and removes checkboxes", async () => {
304
315
  const {getByTestId, queryByTestId} = renderWithTheme(
305
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" />
316
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
306
317
  );
307
318
  await press(getByTestId("consent-form-add-checkbox-button"));
308
319
  expect(getByTestId("consent-form-checkbox-0")).toBeDefined();
@@ -326,7 +337,7 @@ describe("ConsentFormEditor", () => {
326
337
  title: "T",
327
338
  };
328
339
  const {getByTestId} = renderWithTheme(
329
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" id="f1" />
340
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" id="f1" />
330
341
  );
331
342
  expect(getByTestId("consent-form-decline-button-text-input")).toBeDefined();
332
343
  });
@@ -334,7 +345,7 @@ describe("ConsentFormEditor", () => {
334
345
  it("renders and switches segmented control in multi-locale mode", async () => {
335
346
  const {toJSON} = renderWithTheme(
336
347
  <ConsentFormEditor
337
- api={makeApi() as any}
348
+ api={makeApi() as unknown as AdminApi}
338
349
  baseUrl="/admin"
339
350
  hasAiSupport
340
351
  supportedLocales={["en", "es"]}
@@ -346,7 +357,11 @@ describe("ConsentFormEditor", () => {
346
357
  it("calls onCancel when cancel is pressed", async () => {
347
358
  const onCancel = mock(() => undefined);
348
359
  const {getByTestId} = renderWithTheme(
349
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" onCancel={onCancel} />
360
+ <ConsentFormEditor
361
+ api={makeApi() as unknown as AdminApi}
362
+ baseUrl="/admin"
363
+ onCancel={onCancel}
364
+ />
350
365
  );
351
366
  await press(getByTestId("consent-form-cancel-button"));
352
367
  expect(onCancel).toHaveBeenCalled();
@@ -356,16 +371,18 @@ describe("ConsentFormEditor", () => {
356
371
  // Create mode has no id → publish button shouldn't exist, but exercising
357
372
  // the handler via the save flow at least touches the non-id path.
358
373
  const {queryByTestId} = renderWithTheme(
359
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" hasAiSupport />
374
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" hasAiSupport />
360
375
  );
361
376
  expect(queryByTestId("consent-form-publish-button")).toBeNull();
362
377
  });
363
378
 
364
379
  it("wires all three mutations (generate/publish/translate) to the right URLs", () => {
365
- renderWithTheme(<ConsentFormEditor api={makeApi() as any} baseUrl="/admin" hasAiSupport />);
380
+ renderWithTheme(
381
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" hasAiSupport />
382
+ );
366
383
  // The mock invokes each mutation's query lambda, so mutationSpecs contains
367
384
  // the resolved request descriptors for generate, publish, and translate.
368
- const urls = mutationSpecs.map((s: any) => s.url).sort();
385
+ const urls = mutationSpecs.map((s: unknown) => (s as Record<string, unknown>).url).sort();
369
386
  expect(urls).toContain("/consent-forms/generate");
370
387
  expect(urls).toContain("/consent-forms/form-id/publish");
371
388
  expect(urls).toContain("/consent-forms/translate");
@@ -373,7 +390,7 @@ describe("ConsentFormEditor", () => {
373
390
 
374
391
  it("refuses to save without a slug even when title is present", async () => {
375
392
  const {getByTestId} = renderWithTheme(
376
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" />
393
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" />
377
394
  );
378
395
  // Set a title so slug would auto-generate.
379
396
  await act(async () => {
@@ -391,23 +408,23 @@ describe("ConsentFormEditor", () => {
391
408
 
392
409
  it("generates AI content into the active locale and closes the modal", async () => {
393
410
  const {getByTestId, UNSAFE_root} = renderWithTheme(
394
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" hasAiSupport />
411
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" hasAiSupport />
395
412
  );
396
413
  await press(getByTestId("consent-form-generate-button"));
397
414
  // Find the Modal's primary "Generate" button and invoke it directly. The
398
415
  // description input lives inside the Modal's portal and may not be
399
416
  // mounted; invoking primaryButtonOnClick still exercises handleGenerate.
400
417
  const modals = UNSAFE_root.findAll(
401
- (n: any) => typeof n.props?.primaryButtonOnClick === "function"
418
+ (n: ReactTestInstance) => typeof n.props?.primaryButtonOnClick === "function"
402
419
  );
403
420
  expect(modals.length).toBeGreaterThan(0);
404
421
  await act(async () => {
405
- (modals[0] as any).props.primaryButtonOnClick();
422
+ (modals[0] as ReactTestInstance).props.primaryButtonOnClick();
406
423
  await new Promise((r) => setTimeout(r, 150));
407
424
  });
408
425
  expect(generateCalls.length).toBe(1);
409
- expect(generateCalls[0].locale).toBe("en");
410
- expect(generateCalls[0].type).toBe("agreement");
426
+ expect((generateCalls[0] as Record<string, unknown>).locale).toBe("en");
427
+ expect((generateCalls[0] as Record<string, unknown>).type).toBe("agreement");
411
428
  });
412
429
 
413
430
  it("surfaces generation errors via toast.catch", async () => {
@@ -415,14 +432,14 @@ describe("ConsentFormEditor", () => {
415
432
  throw new Error("boom");
416
433
  };
417
434
  const {getByTestId, UNSAFE_root} = renderWithTheme(
418
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" hasAiSupport />
435
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" hasAiSupport />
419
436
  );
420
437
  await press(getByTestId("consent-form-generate-button"));
421
438
  const modals = UNSAFE_root.findAll(
422
- (n: any) => typeof n.props?.primaryButtonOnClick === "function"
439
+ (n: ReactTestInstance) => typeof n.props?.primaryButtonOnClick === "function"
423
440
  );
424
441
  await act(async () => {
425
- (modals[0] as any).props.primaryButtonOnClick();
442
+ (modals[0] as ReactTestInstance).props.primaryButtonOnClick();
426
443
  await new Promise((r) => setTimeout(r, 150));
427
444
  });
428
445
  expect(generateCalls.length).toBe(1);
@@ -437,7 +454,7 @@ describe("ConsentFormEditor", () => {
437
454
  };
438
455
  const {UNSAFE_root} = renderWithTheme(
439
456
  <ConsentFormEditor
440
- api={makeApi() as any}
457
+ api={makeApi() as unknown as AdminApi}
441
458
  baseUrl="/admin"
442
459
  hasAiSupport
443
460
  id="f1"
@@ -446,25 +463,26 @@ describe("ConsentFormEditor", () => {
446
463
  );
447
464
  // Switch to non-default locale (es) so the Translate button appears.
448
465
  const segmented = UNSAFE_root.findAll(
449
- (n: any) => typeof n.props?.onChange === "function" && Array.isArray(n.props?.items)
466
+ (n: ReactTestInstance) =>
467
+ typeof n.props?.onChange === "function" && Array.isArray(n.props?.items)
450
468
  );
451
469
  expect(segmented.length).toBeGreaterThan(0);
452
470
  await act(async () => {
453
- (segmented[0] as any).props.onChange(1);
471
+ (segmented[0] as ReactTestInstance).props.onChange(1);
454
472
  await new Promise((r) => setTimeout(r, 50));
455
473
  });
456
- // Now find the translate button and press it.
474
+ // Find the translate button and press it
457
475
  const translateButton = UNSAFE_root.findAll(
458
- (n: any) => n.props?.testID === "consent-form-translate-es-button"
476
+ (n: ReactTestInstance) => n.props?.testID === "consent-form-translate-es-button"
459
477
  );
460
478
  expect(translateButton.length).toBeGreaterThan(0);
461
479
  await act(async () => {
462
- (translateButton[0] as any).props.onClick();
480
+ (translateButton[0] as ReactTestInstance).props.onClick();
463
481
  await new Promise((r) => setTimeout(r, 150));
464
482
  });
465
483
  expect(translateCalls.length).toBe(1);
466
- expect(translateCalls[0].toLocale).toBe("es");
467
- expect(translateCalls[0].content).toBe("Hello world");
484
+ expect((translateCalls[0] as Record<string, unknown>).toLocale).toBe("es");
485
+ expect((translateCalls[0] as Record<string, unknown>).content).toBe("Hello world");
468
486
  });
469
487
 
470
488
  it("short-circuits translation when source locale has empty content", async () => {
@@ -476,7 +494,7 @@ describe("ConsentFormEditor", () => {
476
494
  };
477
495
  const {UNSAFE_root} = renderWithTheme(
478
496
  <ConsentFormEditor
479
- api={makeApi() as any}
497
+ api={makeApi() as unknown as AdminApi}
480
498
  baseUrl="/admin"
481
499
  hasAiSupport
482
500
  id="f1"
@@ -484,17 +502,18 @@ describe("ConsentFormEditor", () => {
484
502
  />
485
503
  );
486
504
  const segmented = UNSAFE_root.findAll(
487
- (n: any) => typeof n.props?.onChange === "function" && Array.isArray(n.props?.items)
505
+ (n: ReactTestInstance) =>
506
+ typeof n.props?.onChange === "function" && Array.isArray(n.props?.items)
488
507
  );
489
508
  await act(async () => {
490
- (segmented[0] as any).props.onChange(1);
509
+ (segmented[0] as ReactTestInstance).props.onChange(1);
491
510
  await new Promise((r) => setTimeout(r, 50));
492
511
  });
493
512
  const translateButton = UNSAFE_root.findAll(
494
- (n: any) => n.props?.testID === "consent-form-translate-es-button"
513
+ (n: ReactTestInstance) => n.props?.testID === "consent-form-translate-es-button"
495
514
  );
496
515
  await act(async () => {
497
- (translateButton[0] as any).props.onClick();
516
+ (translateButton[0] as ReactTestInstance).props.onClick();
498
517
  await new Promise((r) => setTimeout(r, 150));
499
518
  });
500
519
  expect(translateCalls.length).toBe(0);
@@ -512,7 +531,7 @@ describe("ConsentFormEditor", () => {
512
531
  };
513
532
  const {UNSAFE_root} = renderWithTheme(
514
533
  <ConsentFormEditor
515
- api={makeApi() as any}
534
+ api={makeApi() as unknown as AdminApi}
516
535
  baseUrl="/admin"
517
536
  hasAiSupport
518
537
  id="f1"
@@ -520,17 +539,18 @@ describe("ConsentFormEditor", () => {
520
539
  />
521
540
  );
522
541
  const segmented = UNSAFE_root.findAll(
523
- (n: any) => typeof n.props?.onChange === "function" && Array.isArray(n.props?.items)
542
+ (n: ReactTestInstance) =>
543
+ typeof n.props?.onChange === "function" && Array.isArray(n.props?.items)
524
544
  );
525
545
  await act(async () => {
526
- (segmented[0] as any).props.onChange(1);
546
+ (segmented[0] as ReactTestInstance).props.onChange(1);
527
547
  await new Promise((r) => setTimeout(r, 50));
528
548
  });
529
549
  const translateButton = UNSAFE_root.findAll(
530
- (n: any) => n.props?.testID === "consent-form-translate-es-button"
550
+ (n: ReactTestInstance) => n.props?.testID === "consent-form-translate-es-button"
531
551
  );
532
552
  await act(async () => {
533
- (translateButton[0] as any).props.onClick();
553
+ (translateButton[0] as ReactTestInstance).props.onClick();
534
554
  await new Promise((r) => setTimeout(r, 150));
535
555
  });
536
556
  expect(translateCalls.length).toBe(1);
@@ -538,19 +558,19 @@ describe("ConsentFormEditor", () => {
538
558
 
539
559
  it("dismisses the generate modal via secondary action", async () => {
540
560
  const {getByTestId, UNSAFE_root} = renderWithTheme(
541
- <ConsentFormEditor api={makeApi() as any} baseUrl="/admin" hasAiSupport />
561
+ <ConsentFormEditor api={makeApi() as unknown as AdminApi} baseUrl="/admin" hasAiSupport />
542
562
  );
543
563
  await press(getByTestId("consent-form-generate-button"));
544
564
  const modals = UNSAFE_root.findAll(
545
- (n: any) => typeof n.props?.secondaryButtonOnClick === "function"
565
+ (n: ReactTestInstance) => typeof n.props?.secondaryButtonOnClick === "function"
546
566
  );
547
567
  expect(modals.length).toBeGreaterThan(0);
548
568
  await act(async () => {
549
- (modals[0] as any).props.secondaryButtonOnClick();
569
+ (modals[0] as ReactTestInstance).props.secondaryButtonOnClick();
550
570
  await new Promise((r) => setTimeout(r, 50));
551
571
  });
552
572
  await act(async () => {
553
- (modals[0] as any).props.onDismiss?.();
573
+ (modals[0] as ReactTestInstance).props.onDismiss?.();
554
574
  await new Promise((r) => setTimeout(r, 50));
555
575
  });
556
576
  expect(generateCalls.length).toBe(0);
@@ -15,6 +15,7 @@ import {
15
15
  useToast,
16
16
  } from "@terreno/ui";
17
17
  import React, {useCallback, useEffect, useMemo, useState} from "react";
18
+ import type {AdminApi, EndpointBuilder} from "./types";
18
19
  import {useAdminApi} from "./useAdminApi";
19
20
 
20
21
  interface CheckboxConfig {
@@ -23,13 +24,33 @@ interface CheckboxConfig {
23
24
  confirmationPrompt?: string;
24
25
  }
25
26
 
27
+ /** Consent form document — shape comes from the consumer's Mongoose model. */
28
+ interface ConsentFormDocument {
29
+ _id?: string;
30
+ title?: string;
31
+ slug?: string;
32
+ type?: string;
33
+ order?: number;
34
+ required?: boolean;
35
+ active?: boolean;
36
+ captureSignature?: boolean;
37
+ requireScrollToBottom?: boolean;
38
+ defaultLocale?: string;
39
+ agreeButtonText?: string;
40
+ allowDecline?: boolean;
41
+ declineButtonText?: string;
42
+ content?: Record<string, string>;
43
+ checkboxes?: CheckboxConfig[];
44
+ [key: string]: unknown;
45
+ }
46
+
26
47
  interface ConsentFormEditorProps {
27
48
  baseUrl: string;
28
- api: any;
49
+ api: AdminApi;
29
50
  id?: string;
30
51
  supportedLocales?: string[];
31
52
  hasAiSupport?: boolean;
32
- onSave?: (form: any) => void;
53
+ onSave?: (form: ConsentFormDocument | undefined) => void;
33
54
  onCancel?: () => void;
34
55
  }
35
56
 
@@ -52,6 +73,49 @@ const slugify = (text: string): string => {
52
73
  .replace(/^-+|-+$/g, "");
53
74
  };
54
75
 
76
+ /**
77
+ * Cache the enhanced api per api object. `injectEndpoints` is a side-effecting
78
+ * operation against the global RTK Query slice — calling it on every render of
79
+ * every editor instance is wasteful, and with `overrideExisting: false` would
80
+ * log a re-injection warning. WeakMap-by-api lets the GC reclaim entries when
81
+ * the api is unreachable.
82
+ */
83
+ const enhancedApiCache = new WeakMap<AdminApi, unknown>();
84
+
85
+ const getEnhancedApi = (api: AdminApi): unknown => {
86
+ const cached = enhancedApiCache.get(api);
87
+ if (cached) {
88
+ return cached;
89
+ }
90
+ const enhanced = api.injectEndpoints({
91
+ endpoints: (build: EndpointBuilder) => ({
92
+ generateConsentContent: build.mutation({
93
+ query: (body: {type: string; description: string; locale: string}) => ({
94
+ body,
95
+ method: "POST",
96
+ url: `${CONSENT_FORM_ROUTE}/generate`,
97
+ }),
98
+ }),
99
+ publishConsentForm: build.mutation({
100
+ query: (formId: string) => ({
101
+ method: "POST",
102
+ url: `${CONSENT_FORM_ROUTE}/${formId}/publish`,
103
+ }),
104
+ }),
105
+ translateConsentContent: build.mutation({
106
+ query: (body: {content: string; fromLocale: string; toLocale: string}) => ({
107
+ body,
108
+ method: "POST",
109
+ url: `${CONSENT_FORM_ROUTE}/translate`,
110
+ }),
111
+ }),
112
+ }),
113
+ overrideExisting: false,
114
+ });
115
+ enhancedApiCache.set(api, enhanced);
116
+ return enhanced;
117
+ };
118
+
55
119
  export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
56
120
  baseUrl,
57
121
  api,
@@ -104,8 +168,6 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
104
168
  const [generateType, setGenerateType] = useState(type);
105
169
 
106
170
  const routePath = `${baseUrl}${CONSENT_FORM_ROUTE}`;
107
- // publish/generate/translate are registered directly under /consent-forms, not the admin base path
108
- const consentApiPath = CONSENT_FORM_ROUTE;
109
171
 
110
172
  const {useReadQuery, useCreateMutation, useUpdateMutation} = useAdminApi(
111
173
  api,
@@ -113,47 +175,12 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
113
175
  "ConsentForm"
114
176
  );
115
177
 
116
- const enhancedApi = useMemo(
117
- () =>
118
- api.injectEndpoints({
119
- endpoints: (build: any) => ({
120
- generateConsentContent: build.mutation({
121
- query: (body: {type: string; description: string; locale: string}) => ({
122
- body,
123
- method: "POST",
124
- url: `${consentApiPath}/generate`,
125
- }),
126
- }),
127
- publishConsentForm: build.mutation({
128
- query: (formId: string) => ({
129
- method: "POST",
130
- url: `${consentApiPath}/${formId}/publish`,
131
- }),
132
- }),
133
- translateConsentContent: build.mutation({
134
- query: (body: {content: string; fromLocale: string; toLocale: string}) => ({
135
- body,
136
- method: "POST",
137
- url: `${consentApiPath}/translate`,
138
- }),
139
- }),
140
- }),
141
- overrideExisting: true,
142
- }),
143
- [api, consentApiPath]
144
- );
145
-
146
- const [publishConsentForm, {isLoading: isPublishing}] = (
147
- enhancedApi as any
148
- ).usePublishConsentFormMutation();
149
-
150
- const [generateContent, {isLoading: isGenerating}] = (
151
- enhancedApi as any
152
- ).useGenerateConsentContentMutation();
153
-
154
- const [translateContent, {isLoading: isTranslating}] = (
155
- enhancedApi as any
156
- ).useTranslateConsentContentMutation();
178
+ // biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
179
+ const enhanced = getEnhancedApi(api) as any;
180
+ const [publishConsentForm, {isLoading: isPublishing}] = enhanced.usePublishConsentFormMutation();
181
+ const [generateContent, {isLoading: isGenerating}] = enhanced.useGenerateConsentContentMutation();
182
+ const [translateContent, {isLoading: isTranslating}] =
183
+ enhanced.useTranslateConsentContentMutation();
157
184
 
158
185
  const {data: formData, isLoading: isFormLoading} = useReadQuery(id ?? "", {
159
186
  skip: !isEditMode || !id,
@@ -224,7 +251,7 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
224
251
  }, []);
225
252
 
226
253
  const handleCheckboxChange = useCallback(
227
- (index: number, field: keyof CheckboxConfig, value: any) => {
254
+ (index: number, field: keyof CheckboxConfig, value: string | boolean) => {
228
255
  setCheckboxes((prev) => {
229
256
  const updated = [...prev];
230
257
  updated[index] = {...updated[index], [field]: value};
@@ -285,11 +312,11 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
285
312
  const payload = buildPayload();
286
313
 
287
314
  try {
288
- let result: any;
315
+ let result: ConsentFormDocument | undefined;
289
316
  if (isEditMode && id) {
290
- result = await updateForm({body: payload, id}).unwrap();
317
+ result = (await updateForm({body: payload, id}).unwrap()) as ConsentFormDocument;
291
318
  } else {
292
- result = await createForm(payload).unwrap();
319
+ result = (await createForm(payload).unwrap()) as ConsentFormDocument;
293
320
  }
294
321
  console.info("Consent form saved", {id: result?._id ?? id});
295
322
  onSave?.(result);