@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,16 +1,20 @@
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, AdminConfigResponse} from "./types";
5
9
 
6
10
  const routerPush = mock(() => {});
7
- const setOptions = mock((_: any) => {});
11
+ const setOptions = mock((_: unknown) => {});
8
12
  mock.module("expo-router", () => ({
9
13
  router: {push: routerPush},
10
14
  useNavigation: () => ({setOptions}),
11
15
  }));
12
16
 
13
- const configState: {config: any; isLoading: boolean} = {
17
+ const configState: {config: AdminConfigResponse | null; isLoading: boolean} = {
14
18
  config: null,
15
19
  isLoading: false,
16
20
  };
@@ -22,7 +26,7 @@ mock.module("./useAdminConfig", () => ({
22
26
  }),
23
27
  }));
24
28
 
25
- const listState: {data: any; isLoading: boolean} = {
29
+ const listState: {data: unknown; isLoading: boolean} = {
26
30
  data: {data: [], total: 0},
27
31
  isLoading: false,
28
32
  };
@@ -79,7 +83,7 @@ describe("AdminModelTable", () => {
79
83
  it("renders loading page while config is loading", () => {
80
84
  configState.isLoading = true;
81
85
  const {toJSON} = renderWithTheme(
82
- <AdminModelTable api={{} as any} baseUrl="/admin" modelName="User" />
86
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
83
87
  );
84
88
  expect(toJSON()).toBeDefined();
85
89
  });
@@ -87,7 +91,7 @@ describe("AdminModelTable", () => {
87
91
  it("renders loading page when model config is missing", () => {
88
92
  configState.config = {customScreens: [], models: [], scripts: []};
89
93
  const {toJSON} = renderWithTheme(
90
- <AdminModelTable api={{} as any} baseUrl="/admin" modelName="User" />
94
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
91
95
  );
92
96
  expect(toJSON()).toBeDefined();
93
97
  });
@@ -95,7 +99,7 @@ describe("AdminModelTable", () => {
95
99
  it("renders empty state when no data present", () => {
96
100
  configState.config = fullConfig;
97
101
  const {toJSON} = renderWithTheme(
98
- <AdminModelTable api={{} as any} baseUrl="/admin" modelName="User" />
102
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
99
103
  );
100
104
  expect(toJSON()).toBeDefined();
101
105
  expect(setOptions).toHaveBeenCalled();
@@ -105,7 +109,7 @@ describe("AdminModelTable", () => {
105
109
  configState.config = fullConfig;
106
110
  listState.isLoading = true;
107
111
  const {toJSON} = renderWithTheme(
108
- <AdminModelTable api={{} as any} baseUrl="/admin" modelName="User" />
112
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
109
113
  );
110
114
  expect(toJSON()).toBeDefined();
111
115
  });
@@ -134,7 +138,7 @@ describe("AdminModelTable", () => {
134
138
  total: 2,
135
139
  };
136
140
  const {toJSON} = renderWithTheme(
137
- <AdminModelTable api={{} as any} baseUrl="/admin" modelName="User" />
141
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
138
142
  );
139
143
  expect(toJSON()).toBeDefined();
140
144
  });
@@ -146,7 +150,12 @@ describe("AdminModelTable", () => {
146
150
  total: 1,
147
151
  };
148
152
  const {toJSON} = renderWithTheme(
149
- <AdminModelTable api={{} as any} baseUrl="/admin" columns={["email"]} modelName="User" />
153
+ <AdminModelTable
154
+ api={{} as unknown as AdminApi}
155
+ baseUrl="/admin"
156
+ columns={["email"]}
157
+ modelName="User"
158
+ />
150
159
  );
151
160
  expect(toJSON()).toBeDefined();
152
161
  });
@@ -187,7 +196,7 @@ describe("AdminModelTable", () => {
187
196
  total: 1,
188
197
  };
189
198
  const {toJSON} = renderWithTheme(
190
- <AdminModelTable api={{} as any} baseUrl="/admin" modelName="Plain" />
199
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="Plain" />
191
200
  );
192
201
  expect(toJSON()).toBeDefined();
193
202
  });
@@ -195,12 +204,14 @@ describe("AdminModelTable", () => {
195
204
  it("renders the headerRight create button and pushes to the create route on click", async () => {
196
205
  configState.config = fullConfig;
197
206
  let headerRight: React.ReactElement | null = null;
198
- setOptions.mockImplementation((opts: any) => {
207
+ setOptions.mockImplementation((opts: Record<string, unknown>) => {
199
208
  if (opts?.headerRight) {
200
209
  headerRight = opts.headerRight();
201
210
  }
202
211
  });
203
- renderWithTheme(<AdminModelTable api={{} as any} baseUrl="/admin" modelName="User" />);
212
+ renderWithTheme(
213
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
214
+ );
204
215
  expect(headerRight).not.toBeNull();
205
216
  const header = renderWithTheme(headerRight as unknown as React.ReactElement);
206
217
  await act(async () => {
@@ -223,16 +234,16 @@ describe("AdminModelTable", () => {
223
234
  },
224
235
  }));
225
236
  const {UNSAFE_root} = renderWithTheme(
226
- <AdminModelTable api={{} as any} baseUrl="/admin" modelName="User" />
237
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
227
238
  );
228
239
  // Find the actions cellData.onDelete handler and invoke it directly.
229
- const nodes = UNSAFE_root.findAll((n: any) => {
240
+ const nodes = UNSAFE_root.findAll((n: ReactTestInstance) => {
230
241
  const v = n.props?.cellData?.value;
231
242
  return v && typeof v.onDelete === "function" && v.id === "u1";
232
243
  });
233
244
  expect(nodes.length).toBeGreaterThan(0);
234
245
  await act(async () => {
235
- (nodes[0] as any).props.cellData.value.onDelete("u1");
246
+ (nodes[0] as ReactTestInstance).props.cellData.value.onDelete("u1");
236
247
  await new Promise((r) => setTimeout(r, 50));
237
248
  });
238
249
  expect(deleteFn).toHaveBeenCalled();
@@ -243,16 +254,19 @@ describe("AdminModelTable", () => {
243
254
  listState.data = {data: [{_id: "u1", email: "a@b.com"}], total: 1};
244
255
  const {UNSAFE_root} = renderWithTheme(
245
256
  <AdminModelTable
246
- api={{} as any}
257
+ api={{} as unknown as AdminApi}
247
258
  baseUrl="/admin"
248
259
  columnWidths={{email: 999}}
249
260
  modelName="User"
250
261
  />
251
262
  );
252
- const tables = UNSAFE_root.findAll((n: any) => Array.isArray(n.props?.columns));
263
+ const tables = UNSAFE_root.findAll((n: ReactTestInstance) => Array.isArray(n.props?.columns));
253
264
  expect(tables.length).toBeGreaterThan(0);
254
- const cols = (tables[0] as any).props.columns;
255
- const emailCol = cols.find((c: any) => c.title === "Email");
265
+ const cols = (tables[0] as ReactTestInstance).props.columns as {
266
+ title: string;
267
+ width?: number;
268
+ }[];
269
+ const emailCol = cols.find((c) => c.title === "Email");
256
270
  expect(emailCol?.width).toBe(999);
257
271
  });
258
272
 
@@ -269,11 +283,14 @@ describe("AdminModelTable", () => {
269
283
  };
270
284
  listState.data = {data: [{_id: "u1", email: "a@b.com"}], total: 1};
271
285
  const {UNSAFE_root} = renderWithTheme(
272
- <AdminModelTable api={{} as any} baseUrl="/admin" modelName="User" />
286
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
273
287
  );
274
- const tables = UNSAFE_root.findAll((n: any) => Array.isArray(n.props?.columns));
275
- const cols = (tables[0] as any).props.columns;
276
- const emailCol = cols.find((c: any) => c.title === "Email");
288
+ const tables = UNSAFE_root.findAll((n: ReactTestInstance) => Array.isArray(n.props?.columns));
289
+ const cols = (tables[0] as ReactTestInstance).props.columns as {
290
+ title: string;
291
+ width?: number;
292
+ }[];
293
+ const emailCol = cols.find((c) => c.title === "Email");
277
294
  expect(emailCol?.width).toBe(555);
278
295
  });
279
296
 
@@ -291,15 +308,18 @@ describe("AdminModelTable", () => {
291
308
  listState.data = {data: [{_id: "u1", email: "a@b.com"}], total: 1};
292
309
  const {UNSAFE_root} = renderWithTheme(
293
310
  <AdminModelTable
294
- api={{} as any}
311
+ api={{} as unknown as AdminApi}
295
312
  baseUrl="/admin"
296
313
  columnWidths={{email: 200}}
297
314
  modelName="User"
298
315
  />
299
316
  );
300
- const tables = UNSAFE_root.findAll((n: any) => Array.isArray(n.props?.columns));
301
- const cols = (tables[0] as any).props.columns;
302
- const emailCol = cols.find((c: any) => c.title === "Email");
317
+ const tables = UNSAFE_root.findAll((n: ReactTestInstance) => Array.isArray(n.props?.columns));
318
+ const cols = (tables[0] as ReactTestInstance).props.columns as {
319
+ title: string;
320
+ width?: number;
321
+ }[];
322
+ const emailCol = cols.find((c) => c.title === "Email");
303
323
  expect(emailCol?.width).toBe(200);
304
324
  });
305
325
 
@@ -313,18 +333,25 @@ describe("AdminModelTable", () => {
313
333
  total: 1,
314
334
  };
315
335
  const {UNSAFE_root, toJSON} = renderWithTheme(
316
- <AdminModelTable api={{} as any} baseUrl="/admin" columns={["email"]} modelName="User" />
336
+ <AdminModelTable
337
+ api={{} as unknown as AdminApi}
338
+ baseUrl="/admin"
339
+ columns={["email"]}
340
+ modelName="User"
341
+ />
317
342
  );
318
343
  // Grab setSortColumn from the rendered DataTable and apply a sort with
319
344
  // direction "desc" on column 0 (valid) and then column 5 (out of range).
320
- const table = UNSAFE_root.findAll((n: any) => typeof n.props?.setSortColumn === "function");
345
+ const table = UNSAFE_root.findAll(
346
+ (n: ReactTestInstance) => typeof n.props?.setSortColumn === "function"
347
+ );
321
348
  expect(table.length).toBeGreaterThan(0);
322
349
  await act(async () => {
323
- (table[0] as any).props.setSortColumn({column: 0, direction: "desc"});
350
+ (table[0] as ReactTestInstance).props.setSortColumn({column: 0, direction: "desc"});
324
351
  await new Promise((r) => setTimeout(r, 10));
325
352
  });
326
353
  await act(async () => {
327
- (table[0] as any).props.setSortColumn({column: 99, direction: "asc"});
354
+ (table[0] as ReactTestInstance).props.setSortColumn({column: 99, direction: "asc"});
328
355
  await new Promise((r) => setTimeout(r, 10));
329
356
  });
330
357
  expect(toJSON()).toBeDefined();
@@ -1,4 +1,3 @@
1
- import type {Api} from "@reduxjs/toolkit/query/react";
2
1
  import {
3
2
  Box,
4
3
  Button,
@@ -14,16 +13,17 @@ import {
14
13
  Spinner,
15
14
  Text,
16
15
  } from "@terreno/ui";
16
+ import type {Href} from "expo-router";
17
17
  import {router, useNavigation} from "expo-router";
18
18
  import startCase from "lodash/startCase";
19
19
  import React, {useCallback, useEffect, useMemo, useState} from "react";
20
- import type {AdminFieldConfig, AdminModelConfig} from "./types";
20
+ import type {AdminApi, AdminFieldConfig, AdminFieldValue, AdminModelConfig} from "./types";
21
21
  import {useAdminApi} from "./useAdminApi";
22
22
  import {useAdminConfig} from "./useAdminConfig";
23
23
 
24
24
  interface AdminModelTableProps {
25
25
  baseUrl: string;
26
- api: Api<any, any, any, any>;
26
+ api: AdminApi;
27
27
  modelName: string;
28
28
  columns?: string[];
29
29
  /**
@@ -74,7 +74,7 @@ const getColumnWidth = (fieldKey: string, columnType: string): number => {
74
74
  return 200;
75
75
  };
76
76
 
77
- const formatCellValue = (value: any, columnType: string): string => {
77
+ const formatCellValue = (value: AdminFieldValue, columnType: string): string => {
78
78
  if (value == null) {
79
79
  return "";
80
80
  }
@@ -88,7 +88,7 @@ const formatCellValue = (value: any, columnType: string): string => {
88
88
  return `${value.length} item${value.length === 1 ? "" : "s"}`;
89
89
  }
90
90
  if (typeof value === "object") {
91
- return value._id ?? JSON.stringify(value);
91
+ return (value as {_id?: string})._id ?? JSON.stringify(value);
92
92
  }
93
93
  return String(value);
94
94
  };
@@ -111,7 +111,7 @@ const AdminLinkCell: React.FC<{column: DataTableColumn; cellData: DataTableCellD
111
111
  cellData,
112
112
  }) => {
113
113
  const {text, href} = cellData.value as {text: string; href: string};
114
- return <Link onClick={() => router.push(href as any)} text={text} />;
114
+ return <Link onClick={() => router.push(href as Href)} text={text} />;
115
115
  };
116
116
 
117
117
  const AdminActionsCell: React.FC<{column: DataTableColumn; cellData: DataTableCellData}> = ({
@@ -129,14 +129,14 @@ const AdminActionsCell: React.FC<{column: DataTableColumn; cellData: DataTableCe
129
129
  <IconButton
130
130
  accessibilityLabel="View"
131
131
  iconName="eye"
132
- onClick={() => router.push(href as any)}
132
+ onClick={() => router.push(href as Href)}
133
133
  tooltipText="View"
134
134
  variant="muted"
135
135
  />
136
136
  <IconButton
137
137
  accessibilityLabel="Edit"
138
138
  iconName="pen-to-square"
139
- onClick={() => router.push(href as any)}
139
+ onClick={() => router.push(href as Href)}
140
140
  tooltipText="Edit"
141
141
  variant="muted"
142
142
  />
@@ -219,7 +219,7 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
219
219
  headerRight: () => (
220
220
  <Box alignItems="center" justifyContent="center" marginRight={3}>
221
221
  <Button
222
- onClick={() => router.push(`${baseUrl}/${modelName}/create` as any)}
222
+ onClick={() => router.push(`${baseUrl}/${modelName}/create` as Href)}
223
223
  testID="admin-create-button"
224
224
  text="Create"
225
225
  variant="primary"
@@ -301,7 +301,8 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
301
301
  },
302
302
  ];
303
303
 
304
- const data = (listData?.data ?? []).map((item: any) => {
304
+ const listItems = (listData?.data ?? []) as Array<Record<string, AdminFieldValue>>;
305
+ const data = listItems.map((item) => {
305
306
  const fieldCells = displayFields.map((fieldKey, index) => {
306
307
  const fieldConfig = modelConfig.fields[fieldKey];
307
308
  const isFirst = index === 0;
@@ -1,8 +1,8 @@
1
- import type {Api} from "@reduxjs/toolkit/query/react";
2
1
  import {Box, Button, Card, DraggableList, Heading, IconButton, Text} from "@terreno/ui";
2
+ import startCase from "lodash/startCase";
3
3
  import React, {useCallback, useMemo, useRef} from "react";
4
- import {AdminFieldRenderer} from "./AdminFieldRenderer";
5
- import type {AdminFieldConfig, RefRendererMap} from "./types";
4
+ import {AdminFieldRendererCore} from "./AdminFieldRendererCore";
5
+ import type {AdminApi, AdminFieldConfig, AdminFieldValue, RefRendererMap} from "./types";
6
6
 
7
7
  const FIELD_HEIGHT_ESTIMATE = 76;
8
8
  const CARD_HEADER_HEIGHT = 44;
@@ -14,19 +14,84 @@ interface AdminNestedArrayFieldProps {
14
14
  helperText?: string;
15
15
  errorText?: string;
16
16
  items: Record<string, AdminFieldConfig>;
17
- value: Record<string, any>[];
18
- onChange: (value: Record<string, any>[]) => void;
19
- api: Api<any, any, any, any>;
17
+ value: Record<string, AdminFieldValue>[];
18
+ onChange: (value: Record<string, AdminFieldValue>[]) => void;
19
+ api: AdminApi;
20
20
  baseUrl: string;
21
21
  modelConfigs?: Array<{name: string; routePath: string}>;
22
22
  /** Parent document form state, used to derive dynamic options for sub-fields */
23
- parentFormState?: Record<string, any>;
24
- /** Forwarded to nested {@link AdminFieldRenderer} so refs in sub-documents can use custom renderers. */
23
+ parentFormState?: Record<string, AdminFieldValue>;
24
+ /** Forwarded to nested field renderers so refs in sub-documents can use custom renderers. */
25
25
  refRenderers?: RefRendererMap;
26
26
  }
27
27
 
28
- const buildDefaultItem = (items: Record<string, AdminFieldConfig>): Record<string, any> => {
29
- const newItem: Record<string, any> = {};
28
+ /**
29
+ * Renders a single sub-field of a nested array item. Nested arrays-of-subdocuments
30
+ * recurse into another {@link AdminNestedArrayField}; everything else is rendered
31
+ * by {@link AdminFieldRendererCore} directly so we avoid a require cycle through
32
+ * the AdminFieldRenderer wrapper.
33
+ */
34
+ const renderNestedSubField = ({
35
+ api,
36
+ baseUrl,
37
+ fieldKey,
38
+ fieldConfig,
39
+ fieldValue,
40
+ index,
41
+ modelConfigs,
42
+ onSubFieldChange,
43
+ parentFormState,
44
+ refRenderers,
45
+ }: {
46
+ api: AdminApi;
47
+ baseUrl: string;
48
+ fieldKey: string;
49
+ fieldConfig: AdminFieldConfig;
50
+ fieldValue: AdminFieldValue;
51
+ index: number;
52
+ modelConfigs?: Array<{name: string; routePath: string}>;
53
+ onSubFieldChange: (index: number, fieldKey: string, fieldValue: AdminFieldValue) => void;
54
+ parentFormState?: Record<string, AdminFieldValue>;
55
+ refRenderers?: RefRendererMap;
56
+ }): React.ReactElement => {
57
+ if (fieldConfig.type === "array" && fieldConfig.items) {
58
+ return (
59
+ <AdminNestedArrayField
60
+ api={api}
61
+ baseUrl={baseUrl}
62
+ helperText={fieldConfig.description}
63
+ items={fieldConfig.items}
64
+ key={fieldKey}
65
+ modelConfigs={modelConfigs}
66
+ onChange={(val) => onSubFieldChange(index, fieldKey, val)}
67
+ parentFormState={parentFormState}
68
+ refRenderers={refRenderers}
69
+ title={startCase(fieldKey)}
70
+ value={Array.isArray(fieldValue) ? (fieldValue as Record<string, AdminFieldValue>[]) : []}
71
+ />
72
+ );
73
+ }
74
+
75
+ return (
76
+ <AdminFieldRendererCore
77
+ api={api}
78
+ baseUrl={baseUrl}
79
+ fieldConfig={fieldConfig}
80
+ fieldKey={fieldKey}
81
+ key={fieldKey}
82
+ modelConfigs={modelConfigs}
83
+ onChange={(val) => onSubFieldChange(index, fieldKey, val)}
84
+ parentFormState={parentFormState}
85
+ refRenderers={refRenderers}
86
+ value={fieldValue}
87
+ />
88
+ );
89
+ };
90
+
91
+ const buildDefaultItem = (
92
+ items: Record<string, AdminFieldConfig>
93
+ ): Record<string, AdminFieldValue> => {
94
+ const newItem: Record<string, AdminFieldValue> = {};
30
95
  for (const [key, config] of Object.entries(items)) {
31
96
  if (config.default != null) {
32
97
  newItem[key] = config.default;
@@ -61,7 +126,7 @@ export const AdminNestedArrayField: React.FC<AdminNestedArrayFieldProps> = ({
61
126
  parentFormState,
62
127
  refRenderers,
63
128
  }) => {
64
- const arrayValue = useMemo((): Record<string, any>[] => {
129
+ const arrayValue = useMemo((): Record<string, AdminFieldValue>[] => {
65
130
  return Array.isArray(value) ? value : [];
66
131
  }, [value]);
67
132
 
@@ -112,7 +177,7 @@ export const AdminNestedArrayField: React.FC<AdminNestedArrayFieldProps> = ({
112
177
  );
113
178
 
114
179
  const handleSubFieldChange = useCallback(
115
- (index: number, fieldKey: string, fieldValue: any): void => {
180
+ (index: number, fieldKey: string, fieldValue: AdminFieldValue): void => {
116
181
  const next = arrayValue.map((item, i) => {
117
182
  if (i !== index) {
118
183
  return item;
@@ -163,20 +228,20 @@ export const AdminNestedArrayField: React.FC<AdminNestedArrayFieldProps> = ({
163
228
  variant="destructive"
164
229
  />
165
230
  </Box>
166
- {subFieldEntries.map(([fieldKey, fieldConfig]) => (
167
- <AdminFieldRenderer
168
- api={api}
169
- baseUrl={baseUrl}
170
- fieldConfig={fieldConfig}
171
- fieldKey={fieldKey}
172
- key={fieldKey}
173
- modelConfigs={modelConfigs}
174
- onChange={(val: any) => handleSubFieldChange(index, fieldKey, val)}
175
- parentFormState={parentFormState}
176
- refRenderers={refRenderers}
177
- value={itemData[fieldKey]}
178
- />
179
- ))}
231
+ {subFieldEntries.map(([fieldKey, fieldConfig]) =>
232
+ renderNestedSubField({
233
+ api,
234
+ baseUrl,
235
+ fieldConfig,
236
+ fieldKey,
237
+ fieldValue: itemData[fieldKey],
238
+ index,
239
+ modelConfigs,
240
+ onSubFieldChange: handleSubFieldChange,
241
+ parentFormState,
242
+ refRenderers,
243
+ })
244
+ )}
180
245
  </Box>
181
246
  </Card>
182
247
  );
@@ -1,9 +1,20 @@
1
- import type {Api} from "@reduxjs/toolkit/query/react";
2
1
  import {Box, IconButton, Spinner, Text, TextField} from "@terreno/ui";
3
2
  import React, {useCallback, useEffect, useMemo, useRef, useState} from "react";
3
+ import type {AdminApi, EndpointBuilder} from "./types";
4
+
5
+ /** Generic referenced document — admin can pick from any Mongoose model so the shape varies. */
6
+ interface PickerItem {
7
+ _id?: string;
8
+ name?: string;
9
+ title?: string;
10
+ email?: string;
11
+ label?: string;
12
+ displayName?: string;
13
+ [key: string]: unknown;
14
+ }
4
15
 
5
16
  interface AdminObjectPickerProps {
6
- api: Api<any, any, any, any>;
17
+ api: AdminApi;
7
18
  routePath: string;
8
19
  refModelName: string;
9
20
  title: string;
@@ -13,27 +24,30 @@ interface AdminObjectPickerProps {
13
24
  helperText?: string;
14
25
  }
15
26
 
16
- const DISPLAY_FIELDS = ["name", "title", "email", "label", "displayName"];
27
+ const DISPLAY_FIELDS = ["name", "title", "email", "label", "displayName"] as const;
28
+ type DisplayField = (typeof DISPLAY_FIELDS)[number];
17
29
 
18
- const getDisplayValue = (item: any): string => {
30
+ const getDisplayValue = (item: PickerItem): string => {
19
31
  for (const field of DISPLAY_FIELDS) {
20
- if (item[field]) {
21
- return String(item[field]);
32
+ const val = item[field];
33
+ if (val) {
34
+ return String(val);
22
35
  }
23
36
  }
24
37
  return item._id ?? String(item);
25
38
  };
26
39
 
27
- const getSecondaryText = (item: any, primaryField: string): string | undefined => {
40
+ const getSecondaryText = (item: PickerItem, primaryField: string): string | undefined => {
28
41
  for (const field of DISPLAY_FIELDS) {
29
- if (field !== primaryField && item[field]) {
30
- return String(item[field]);
42
+ const val = item[field];
43
+ if (field !== primaryField && val) {
44
+ return String(val);
31
45
  }
32
46
  }
33
47
  return undefined;
34
48
  };
35
49
 
36
- const getPrimaryField = (item: any): string => {
50
+ const getPrimaryField = (item: PickerItem): DisplayField | "_id" => {
37
51
  for (const field of DISPLAY_FIELDS) {
38
52
  if (item[field]) {
39
53
  return field;
@@ -73,7 +87,7 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
73
87
 
74
88
  const enhancedApi = useMemo(() => {
75
89
  return api.injectEndpoints({
76
- endpoints: (build: any) => ({
90
+ endpoints: (build: EndpointBuilder) => ({
77
91
  [searchEndpointKey]: build.query({
78
92
  query: (q: string) => ({
79
93
  method: "GET",
@@ -93,8 +107,11 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
93
107
  }, [api, routePath, searchEndpointKey, readEndpointKey]);
94
108
 
95
109
  const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
96
- const useSearchQuery = (enhancedApi as any)[`use${capitalize(searchEndpointKey)}Query`];
97
- const useReadQuery = (enhancedApi as any)[`use${capitalize(readEndpointKey)}Query`];
110
+ // noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
111
+ // biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
112
+ const enhanced = enhancedApi as any;
113
+ const useSearchQuery = enhanced[`use${capitalize(searchEndpointKey)}Query`];
114
+ const useReadQuery = enhanced[`use${capitalize(readEndpointKey)}Query`];
98
115
 
99
116
  const {data: searchData, isFetching: isSearching} = useSearchQuery(debouncedQuery, {
100
117
  skip: !debouncedQuery,
@@ -125,8 +142,8 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
125
142
  }, []);
126
143
 
127
144
  const handleSelect = useCallback(
128
- (item: any) => {
129
- onChange(item._id);
145
+ (item: PickerItem) => {
146
+ onChange(item._id ?? "");
130
147
  setSelectedDisplay(getDisplayValue(item));
131
148
  setSearchText("");
132
149
  setDebouncedQuery("");
@@ -216,7 +233,7 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
216
233
  )}
217
234
 
218
235
  {!isSearching &&
219
- results.map((item: any) => {
236
+ (results as PickerItem[]).map((item) => {
220
237
  const primaryField = getPrimaryField(item);
221
238
  const secondary = getSecondaryText(item, primaryField);
222
239
  return (
@@ -1,20 +1,24 @@
1
+ // noExplicitAny: test mocks use type-erased RTK Query API doubles and mock.calls access
2
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
1
3
  import {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";
5
8
  import {AdminPrimitiveArrayField} from "./AdminPrimitiveArrayField";
9
+ import type {AdminApi} from "./types";
6
10
 
7
- const press = async (el: any): Promise<void> => {
11
+ const press = async (el: ReactTestInstance): Promise<void> => {
8
12
  await act(async () => {
9
13
  fireEvent.press(el);
10
14
  await new Promise((r) => setTimeout(r, 150));
11
15
  });
12
16
  };
13
17
 
14
- const mockApi: any = {
18
+ const mockApi = {
15
19
  endpoints: {},
16
20
  reducerPath: "test",
17
- };
21
+ } as unknown as AdminApi;
18
22
 
19
23
  describe("AdminPrimitiveArrayField", () => {
20
24
  it("renders empty state when no items", () => {
@@ -63,7 +67,7 @@ describe("AdminPrimitiveArrayField", () => {
63
67
  );
64
68
  await press(getByTestId("admin-array-add-Tags"));
65
69
  expect(onChange).toHaveBeenCalled();
66
- const next = (onChange.mock.calls[0] as any)[0];
70
+ const next = (onChange.mock.calls[0] as unknown[])[0];
67
71
  expect(next).toEqual(["foo", ""]);
68
72
  });
69
73
 
@@ -81,7 +85,7 @@ describe("AdminPrimitiveArrayField", () => {
81
85
  );
82
86
  await press(getByTestId("admin-array-remove-1"));
83
87
  expect(onChange).toHaveBeenCalled();
84
- const next = (onChange.mock.calls[0] as any)[0];
88
+ const next = (onChange.mock.calls[0] as unknown[])[0];
85
89
  expect(next).toEqual(["a", "c"]);
86
90
  });
87
91
 
@@ -99,7 +103,7 @@ describe("AdminPrimitiveArrayField", () => {
99
103
  );
100
104
  fireEvent.changeText(getByTestId("admin-array-item-0"), "new");
101
105
  expect(onChange).toHaveBeenCalled();
102
- const next = (onChange.mock.calls[0] as any)[0];
106
+ const next = (onChange.mock.calls[0] as unknown[])[0];
103
107
  expect(next).toEqual(["new"]);
104
108
  });
105
109
 
@@ -116,7 +120,7 @@ describe("AdminPrimitiveArrayField", () => {
116
120
  />
117
121
  );
118
122
  fireEvent.changeText(getByTestId("admin-array-item-0"), "42");
119
- const next = (onChange.mock.calls[0] as any)[0];
123
+ const next = (onChange.mock.calls[0] as unknown[])[0];
120
124
  expect(next).toEqual([42, 2]);
121
125
  });
122
126
 
@@ -133,7 +137,7 @@ describe("AdminPrimitiveArrayField", () => {
133
137
  />
134
138
  );
135
139
  await press(getByTestId("admin-array-add-Flags"));
136
- const next = (onChange.mock.calls[0] as any)[0];
140
+ const next = (onChange.mock.calls[0] as unknown[])[0];
137
141
  expect(next).toEqual([false]);
138
142
  });
139
143
 
@@ -150,7 +154,7 @@ describe("AdminPrimitiveArrayField", () => {
150
154
  />
151
155
  );
152
156
  await press(getByTestId("admin-array-add-Scores"));
153
- const next = (onChange.mock.calls[0] as any)[0];
157
+ const next = (onChange.mock.calls[0] as unknown[])[0];
154
158
  expect(next).toEqual([0]);
155
159
  });
156
160
 
@@ -178,7 +182,7 @@ describe("AdminPrimitiveArrayField", () => {
178
182
  itemType="string"
179
183
  onChange={() => {}}
180
184
  title="Tags"
181
- value={undefined as any}
185
+ value={undefined as unknown as string[]}
182
186
  />
183
187
  );
184
188
  expect(toJSON()).toBeDefined();