@terreno/admin-frontend 0.13.3 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +12 -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 +15 -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 +7 -5
  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 +9 -5
  44. package/dist/useAdminApi.js.map +1 -1
  45. package/dist/useAdminConfig.d.ts +2 -3
  46. package/dist/useAdminConfig.js +1 -0
  47. package/dist/useAdminConfig.js.map +1 -1
  48. package/dist/useAdminScripts.d.ts +2 -3
  49. package/dist/useAdminScripts.js +5 -3
  50. package/dist/useAdminScripts.js.map +1 -1
  51. package/dist/useConfigurationApi.d.ts +11 -8
  52. package/dist/useConfigurationApi.js +6 -4
  53. package/dist/useConfigurationApi.js.map +1 -1
  54. package/dist/useDocumentStorageApi.d.ts +2 -2
  55. package/dist/useDocumentStorageApi.js +8 -6
  56. package/dist/useDocumentStorageApi.js.map +1 -1
  57. package/package.json +2 -2
  58. package/src/AdminFieldRenderer.test.tsx +1 -0
  59. package/src/AdminFieldRenderer.tsx +18 -371
  60. package/src/AdminFieldRendererCore.tsx +356 -0
  61. package/src/AdminModelForm.test.tsx +1 -0
  62. package/src/AdminModelForm.tsx +22 -17
  63. package/src/AdminModelList.test.tsx +1 -0
  64. package/src/AdminModelList.tsx +5 -5
  65. package/src/AdminModelTable.test.tsx +1 -0
  66. package/src/AdminModelTable.tsx +11 -10
  67. package/src/AdminNestedArrayField.tsx +91 -26
  68. package/src/AdminObjectPicker.tsx +32 -16
  69. package/src/AdminPrimitiveArrayField.test.tsx +1 -0
  70. package/src/AdminPrimitiveArrayField.tsx +2 -3
  71. package/src/AdminScriptList.test.tsx +1 -0
  72. package/src/AdminScriptList.tsx +2 -3
  73. package/src/AdminScriptRunModal.test.tsx +1 -0
  74. package/src/AdminScriptRunModal.tsx +2 -3
  75. package/src/AdminVersionConfig.test.tsx +21 -0
  76. package/src/AdminVersionConfig.tsx +28 -5
  77. package/src/CheckboxListEditor.test.tsx +1 -0
  78. package/src/ConfigurationScreen.test.tsx +1 -0
  79. package/src/ConfigurationScreen.tsx +43 -29
  80. package/src/ConsentFormEditor.test.tsx +1 -0
  81. package/src/ConsentFormEditor.tsx +34 -18
  82. package/src/ConsentFormList.test.tsx +1 -0
  83. package/src/ConsentFormList.tsx +14 -2
  84. package/src/ConsentResponseViewer.test.tsx +1 -0
  85. package/src/ConsentResponseViewer.tsx +3 -2
  86. package/src/DocumentStorageBrowser.test.tsx +1 -0
  87. package/src/DocumentStorageBrowser.tsx +4 -4
  88. package/src/LocaleContentEditor.test.tsx +1 -0
  89. package/src/isolated/AdminFieldRenderer.isolated.tsx +1 -0
  90. package/src/isolated/AdminNestedArrayField.isolated.tsx +1 -0
  91. package/src/isolated/AdminObjectPicker.isolated.tsx +1 -0
  92. package/src/isolated/AdminRefField.isolated.tsx +1 -0
  93. package/src/isolated/AdminScriptRunModal.isolated.tsx +1 -0
  94. package/src/isolated/DocumentStorageBrowser.isolated.tsx +1 -0
  95. package/src/isolated/hooks.isolated.tsx +1 -0
  96. package/src/types.ts +34 -4
  97. package/src/useAdminApi.ts +22 -13
  98. package/src/useAdminConfig.ts +4 -4
  99. package/src/useAdminScripts.ts +8 -7
  100. package/src/useConfigurationApi.ts +25 -12
  101. package/src/useDocumentStorageApi.ts +11 -9
@@ -0,0 +1,356 @@
1
+ import {
2
+ BooleanField,
3
+ DateTimeField,
4
+ MarkdownEditorField,
5
+ SelectField,
6
+ TextField,
7
+ } from "@terreno/ui";
8
+ import startCase from "lodash/startCase";
9
+ import React from "react";
10
+ import {AdminPrimitiveArrayField} from "./AdminPrimitiveArrayField";
11
+ import {AdminRefField} from "./AdminRefField";
12
+ import {CheckboxListEditor} from "./CheckboxListEditor";
13
+ import {LocaleContentEditor} from "./LocaleContentEditor";
14
+ import type {AdminFieldConfig, AdminFieldValue, AdminScreenProps, RefRendererMap} from "./types";
15
+
16
+ // Attempts to parse a string as JSON, returning the parsed value or the raw string
17
+ const parseJsonValue = (text: string): AdminFieldValue => {
18
+ const trimmed = text.trim();
19
+ if (trimmed === "") {
20
+ return undefined;
21
+ }
22
+ try {
23
+ return JSON.parse(trimmed);
24
+ } catch {
25
+ return trimmed;
26
+ }
27
+ };
28
+
29
+ // Serializes any value to a display string for the JSON editor
30
+ const serializeJsonValue = (val: AdminFieldValue): string => {
31
+ if (val == null) {
32
+ return "";
33
+ }
34
+ if (typeof val === "string") {
35
+ return val;
36
+ }
37
+ return JSON.stringify(val, null, 2);
38
+ };
39
+
40
+ export interface AdminFieldRendererCoreProps extends AdminScreenProps {
41
+ fieldKey: string;
42
+ fieldConfig: AdminFieldConfig;
43
+ value: AdminFieldValue;
44
+ onChange: (value: AdminFieldValue) => void;
45
+ errorText?: string;
46
+ modelConfigs?: Array<{name: string; routePath: string}>;
47
+ /** Parent document form state, used to derive dynamic options for sub-fields */
48
+ parentFormState?: Record<string, AdminFieldValue>;
49
+ /**
50
+ * Optional map of custom ref-field renderers keyed by referenced model name.
51
+ * Forwarded to {@link AdminPrimitiveArrayField} so nested fields participate in the override.
52
+ */
53
+ refRenderers?: RefRendererMap;
54
+ }
55
+
56
+ /**
57
+ * Renders admin form fields for all types except arrays of sub-documents.
58
+ * Nested sub-document arrays are handled by {@link AdminNestedArrayField} via
59
+ * {@link AdminFieldRenderer} to avoid a circular import.
60
+ */
61
+ export const AdminFieldRendererCore: React.FC<AdminFieldRendererCoreProps> = ({
62
+ fieldKey,
63
+ fieldConfig,
64
+ value,
65
+ onChange,
66
+ errorText,
67
+ baseUrl,
68
+ api,
69
+ modelConfigs,
70
+ parentFormState,
71
+ refRenderers,
72
+ }) => {
73
+ const label = startCase(fieldKey);
74
+ const helperText = fieldConfig.description;
75
+
76
+ // Dynamic enum: look for a sibling array field whose items have a `key` property.
77
+ if (!fieldConfig.enum && parentFormState && fieldConfig.type === "string") {
78
+ const pluralKey = `${fieldKey}s`;
79
+ const siblingArray = parentFormState[pluralKey];
80
+ if (Array.isArray(siblingArray) && siblingArray.length > 0 && siblingArray[0]?.key != null) {
81
+ const dynamicOptions = (siblingArray as Array<{key?: string}>)
82
+ .map((item) => item.key)
83
+ .filter(Boolean)
84
+ .map((k) => ({label: k as string, value: k as string}));
85
+ if (dynamicOptions.length > 0) {
86
+ return (
87
+ <SelectField
88
+ errorText={errorText}
89
+ helperText={helperText}
90
+ onChange={onChange}
91
+ options={dynamicOptions}
92
+ title={label}
93
+ value={typeof value === "string" ? value : ""}
94
+ />
95
+ );
96
+ }
97
+ }
98
+ }
99
+
100
+ // ObjectId with ref -> reference field (skip arrays — those go to AdminPrimitiveArrayField)
101
+ if (fieldConfig.ref && fieldConfig.type !== "array") {
102
+ const CustomRenderer = refRenderers?.[fieldConfig.ref];
103
+ const refModel = modelConfigs?.find((m) => m.name === fieldConfig.ref);
104
+ if (CustomRenderer) {
105
+ return (
106
+ <CustomRenderer
107
+ api={api}
108
+ baseUrl={baseUrl}
109
+ errorText={errorText}
110
+ helperText={helperText}
111
+ onChange={onChange}
112
+ refModelName={fieldConfig.ref}
113
+ routePath={refModel?.routePath ?? ""}
114
+ title={label}
115
+ value={typeof value === "string" ? value : ""}
116
+ />
117
+ );
118
+ }
119
+ if (refModel) {
120
+ return (
121
+ <AdminRefField
122
+ api={api}
123
+ baseUrl={baseUrl}
124
+ errorText={errorText}
125
+ helperText={helperText}
126
+ onChange={onChange}
127
+ refModelName={fieldConfig.ref}
128
+ routePath={refModel.routePath}
129
+ title={label}
130
+ value={typeof value === "string" ? value : ""}
131
+ />
132
+ );
133
+ }
134
+ }
135
+
136
+ if (fieldConfig.type === "boolean") {
137
+ return (
138
+ <BooleanField
139
+ errorText={errorText}
140
+ helperText={helperText}
141
+ onChange={onChange}
142
+ title={label}
143
+ value={typeof value === "boolean" ? value : false}
144
+ />
145
+ );
146
+ }
147
+
148
+ if (fieldConfig.enum && fieldConfig.enum.length > 0) {
149
+ const includesNullOption = fieldConfig.enum.some((enumValue) => enumValue == null);
150
+ const enumOptions = fieldConfig.enum
151
+ .filter((enumValue): enumValue is string => typeof enumValue === "string")
152
+ .map((v: string) => ({label: startCase(v), value: v}));
153
+ const options = includesNullOption ? [{label: "None", value: ""}, ...enumOptions] : enumOptions;
154
+ return (
155
+ <SelectField
156
+ errorText={errorText}
157
+ helperText={helperText}
158
+ onChange={(nextValue: string) => onChange(nextValue === "" ? undefined : nextValue)}
159
+ options={options}
160
+ title={label}
161
+ value={typeof value === "string" ? value : ""}
162
+ />
163
+ );
164
+ }
165
+
166
+ if (
167
+ fieldConfig.type === "date" ||
168
+ fieldConfig.type === "datetime" ||
169
+ (fieldConfig.type === "string" && fieldKey.toLowerCase().includes("date"))
170
+ ) {
171
+ return (
172
+ <DateTimeField
173
+ errorText={errorText}
174
+ helperText={helperText}
175
+ onChange={onChange}
176
+ testID={`admin-field-${fieldKey}`}
177
+ title={label}
178
+ type="datetime"
179
+ value={typeof value === "string" ? value : ""}
180
+ />
181
+ );
182
+ }
183
+
184
+ if (fieldConfig.type === "number") {
185
+ return (
186
+ <TextField
187
+ errorText={errorText}
188
+ helperText={helperText}
189
+ onChange={(text: string) => {
190
+ const num = Number(text);
191
+ onChange(Number.isNaN(num) ? text : num);
192
+ }}
193
+ testID={`admin-field-${fieldKey}`}
194
+ title={label}
195
+ value={value != null ? String(value) : ""}
196
+ />
197
+ );
198
+ }
199
+
200
+ if (fieldConfig.widget === "locale-content") {
201
+ const localeValue =
202
+ value && typeof value === "object" && !Array.isArray(value)
203
+ ? (value as Record<string, string>)
204
+ : {};
205
+ return (
206
+ <LocaleContentEditor
207
+ errorText={errorText}
208
+ helperText={helperText}
209
+ onChange={onChange}
210
+ title={label}
211
+ value={localeValue}
212
+ />
213
+ );
214
+ }
215
+
216
+ if (fieldConfig.widget === "locale-default") {
217
+ const contentMap = parentFormState?.content;
218
+ const localeKeys =
219
+ contentMap && typeof contentMap === "object" && !Array.isArray(contentMap)
220
+ ? Object.keys(contentMap)
221
+ : [];
222
+ const hasLocales = localeKeys.length > 0;
223
+ const options = localeKeys.map((k) => ({label: k.toUpperCase(), value: k}));
224
+ return (
225
+ <SelectField
226
+ disabled={!hasLocales}
227
+ errorText={errorText}
228
+ helperText={
229
+ hasLocales
230
+ ? helperText
231
+ : "Add at least one locale with content before setting a default locale."
232
+ }
233
+ onChange={onChange}
234
+ options={options}
235
+ title={label}
236
+ value={typeof value === "string" ? value : ""}
237
+ />
238
+ );
239
+ }
240
+
241
+ if (fieldConfig.type === "object" || fieldConfig.type === "mixed") {
242
+ const displayValue = serializeJsonValue(value);
243
+ return (
244
+ <TextField
245
+ errorText={errorText}
246
+ helperText={helperText ?? "JSON value (string, number, boolean, object, or array)"}
247
+ onChange={(text: string) => {
248
+ onChange(parseJsonValue(text));
249
+ }}
250
+ testID={`admin-field-${fieldKey}`}
251
+ title={label}
252
+ value={displayValue}
253
+ />
254
+ );
255
+ }
256
+
257
+ if (fieldConfig.type === "array" && fieldConfig.itemType && !fieldConfig.items) {
258
+ return (
259
+ <AdminPrimitiveArrayField
260
+ api={api}
261
+ baseUrl={baseUrl}
262
+ errorText={errorText}
263
+ helperText={helperText}
264
+ itemEnum={fieldConfig.itemEnum}
265
+ itemRef={fieldConfig.itemRef}
266
+ itemType={fieldConfig.itemType}
267
+ modelConfigs={modelConfigs}
268
+ onChange={onChange}
269
+ refRenderers={refRenderers}
270
+ title={label}
271
+ value={Array.isArray(value) ? value : []}
272
+ />
273
+ );
274
+ }
275
+
276
+ if (fieldConfig.type === "array") {
277
+ const jsonValue =
278
+ value != null ? (typeof value === "string" ? value : JSON.stringify(value, null, 2)) : "[]";
279
+ return (
280
+ <TextField
281
+ errorText={errorText}
282
+ grow
283
+ helperText={helperText ?? "Enter valid JSON array"}
284
+ multiline
285
+ onChange={(text: string) => {
286
+ try {
287
+ onChange(JSON.parse(text));
288
+ } catch {
289
+ onChange(text);
290
+ }
291
+ }}
292
+ rows={4}
293
+ testID={`admin-field-${fieldKey}`}
294
+ title={label}
295
+ value={jsonValue}
296
+ />
297
+ );
298
+ }
299
+
300
+ if (fieldConfig.widget === "markdown") {
301
+ return (
302
+ <MarkdownEditorField
303
+ errorText={errorText}
304
+ helperText={helperText}
305
+ onChange={onChange}
306
+ testID={`admin-field-${fieldKey}`}
307
+ title={label}
308
+ value={typeof value === "string" ? value : ""}
309
+ />
310
+ );
311
+ }
312
+
313
+ if (fieldConfig.widget === "checkbox-list") {
314
+ return (
315
+ <CheckboxListEditor
316
+ errorText={errorText}
317
+ helperText={helperText}
318
+ onChange={onChange}
319
+ title={label}
320
+ value={
321
+ Array.isArray(value)
322
+ ? (value as React.ComponentProps<typeof CheckboxListEditor>["value"])
323
+ : []
324
+ }
325
+ />
326
+ );
327
+ }
328
+
329
+ if (fieldConfig.widget === "textarea") {
330
+ return (
331
+ <TextField
332
+ errorText={errorText}
333
+ grow
334
+ helperText={helperText}
335
+ multiline
336
+ onChange={onChange}
337
+ rows={6}
338
+ testID={`admin-field-${fieldKey}`}
339
+ title={label}
340
+ value={typeof value === "string" ? value : ""}
341
+ />
342
+ );
343
+ }
344
+
345
+ // Default: string -> TextField
346
+ return (
347
+ <TextField
348
+ errorText={errorText}
349
+ helperText={helperText}
350
+ onChange={onChange}
351
+ testID={`admin-field-${fieldKey}`}
352
+ title={label}
353
+ value={typeof value === "string" ? value : ""}
354
+ />
355
+ );
356
+ };
@@ -1,3 +1,4 @@
1
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
1
2
  import {beforeEach, describe, expect, it, mock} from "bun:test";
2
3
  import {renderWithTheme} from "@terreno/ui/src/test-utils";
3
4
  import React from "react";
@@ -1,28 +1,33 @@
1
- import type {Api} from "@reduxjs/toolkit/query/react";
2
1
  import {Box, Button, Page, Spinner, Text, useToast} from "@terreno/ui";
3
2
  import {router, useNavigation} from "expo-router";
4
3
  import React, {useCallback, useEffect, useMemo, useState} from "react";
5
4
  import {AdminFieldRenderer} from "./AdminFieldRenderer";
6
- import type {AdminFieldConfig, AdminModelConfig, RefRendererMap} from "./types";
5
+ import type {
6
+ AdminApi,
7
+ AdminFieldConfig,
8
+ AdminFieldValue,
9
+ AdminModelConfig,
10
+ RefRendererMap,
11
+ } from "./types";
7
12
  import {SYSTEM_FIELDS} from "./types";
8
13
  import {useAdminApi} from "./useAdminApi";
9
14
  import {useAdminConfig} from "./useAdminConfig";
10
15
 
11
16
  interface AdminModelFormProps {
12
17
  baseUrl: string;
13
- api: Api<any, any, any, any>;
18
+ api: AdminApi;
14
19
  modelName: string;
15
20
  mode: "create" | "edit";
16
21
  itemId?: string;
17
22
  footerContent?: React.ReactNode;
18
23
  transformPayload?: (params: {
19
24
  mode: "create" | "edit";
20
- payload: Record<string, any>;
21
- }) => Promise<Record<string, any>> | Record<string, any>;
25
+ payload: Record<string, AdminFieldValue>;
26
+ }) => Promise<Record<string, AdminFieldValue>> | Record<string, AdminFieldValue>;
22
27
  onSaveSuccess?: (params: {
23
28
  mode: "create" | "edit";
24
- payload: Record<string, any>;
25
- result: any;
29
+ payload: Record<string, AdminFieldValue>;
30
+ result: AdminFieldValue;
26
31
  itemId?: string;
27
32
  }) => Promise<void> | void;
28
33
  /**
@@ -57,7 +62,7 @@ const getEditableFields = (
57
62
  return ordered;
58
63
  };
59
64
 
60
- const getFieldDefault = (fieldConfig: AdminFieldConfig): any => {
65
+ const getFieldDefault = (fieldConfig: AdminFieldConfig): AdminFieldValue => {
61
66
  if (fieldConfig.default !== undefined) {
62
67
  return fieldConfig.default;
63
68
  }
@@ -70,7 +75,7 @@ const getFieldDefault = (fieldConfig: AdminFieldConfig): any => {
70
75
  return "";
71
76
  };
72
77
 
73
- const sanitizePayloadValue = (value: any): any => {
78
+ const sanitizePayloadValue = (value: AdminFieldValue): AdminFieldValue => {
74
79
  if (value === null) {
75
80
  return undefined;
76
81
  }
@@ -78,7 +83,7 @@ const sanitizePayloadValue = (value: any): any => {
78
83
  return value.map((item) => sanitizePayloadValue(item)).filter((item) => item !== undefined);
79
84
  }
80
85
  if (value && typeof value === "object") {
81
- const nextValue: Record<string, any> = {};
86
+ const nextValue: Record<string, AdminFieldValue> = {};
82
87
  for (const [key, childValue] of Object.entries(value)) {
83
88
  const sanitizedChild = sanitizePayloadValue(childValue);
84
89
  if (sanitizedChild !== undefined) {
@@ -167,7 +172,7 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
167
172
  refRenderers,
168
173
  }) => {
169
174
  const {config, isLoading: isConfigLoading} = useAdminConfig(api, baseUrl);
170
- const [formState, setFormState] = useState<Record<string, any>>({});
175
+ const [formState, setFormState] = useState<Record<string, AdminFieldValue>>({});
171
176
  const [errors, setErrors] = useState<Record<string, string>>({});
172
177
  const [isInitialized, setIsInitialized] = useState(false);
173
178
  const navigation = useNavigation();
@@ -196,7 +201,7 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
196
201
  // Initialize form state from fetched item data in edit mode
197
202
  useEffect(() => {
198
203
  if (mode === "edit" && itemData && !isInitialized) {
199
- const initial: Record<string, any> = {};
204
+ const initial: Record<string, AdminFieldValue> = {};
200
205
  if (modelConfig) {
201
206
  for (const [key, fieldConfig] of getEditableFields(
202
207
  modelConfig.fields,
@@ -214,7 +219,7 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
214
219
  // Initialize form state with defaults in create mode
215
220
  useEffect(() => {
216
221
  if (mode === "create" && modelConfig && !isInitialized) {
217
- const initial: Record<string, any> = {};
222
+ const initial: Record<string, AdminFieldValue> = {};
218
223
  for (const [key, fieldConfig] of getEditableFields(
219
224
  modelConfig.fields,
220
225
  modelConfig.fieldOrder
@@ -226,7 +231,7 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
226
231
  }
227
232
  }, [mode, modelConfig, isInitialized]);
228
233
 
229
- const handleFieldChange = useCallback((fieldKey: string, value: any) => {
234
+ const handleFieldChange = useCallback((fieldKey: string, value: AdminFieldValue) => {
230
235
  setFormState((prev) => ({...prev, [fieldKey]: value}));
231
236
  setErrors((prev) => {
232
237
  const next = {...prev};
@@ -257,11 +262,11 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
257
262
  return;
258
263
  }
259
264
  try {
260
- const sanitizedPayload = sanitizePayloadValue(formState) as Record<string, any>;
265
+ const sanitizedPayload = sanitizePayloadValue(formState) as Record<string, AdminFieldValue>;
261
266
  const payload = transformPayload
262
267
  ? await transformPayload({mode, payload: sanitizedPayload})
263
268
  : sanitizedPayload;
264
- let result: any;
269
+ let result: AdminFieldValue;
265
270
  if (mode === "create") {
266
271
  result = await createItem(payload).unwrap();
267
272
  } else if (itemId) {
@@ -359,7 +364,7 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
359
364
  fieldKey={fieldKey}
360
365
  key={fieldKey}
361
366
  modelConfigs={modelConfigs}
362
- onChange={(value: any) => handleFieldChange(fieldKey, value)}
367
+ onChange={(value: AdminFieldValue) => handleFieldChange(fieldKey, value)}
363
368
  parentFormState={formState}
364
369
  refRenderers={refRenderers}
365
370
  value={formState[fieldKey]}
@@ -1,3 +1,4 @@
1
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
1
2
  import {beforeEach, describe, expect, it, mock} from "bun:test";
2
3
  import {renderWithTheme} from "@terreno/ui/src/test-utils";
3
4
  import React from "react";
@@ -1,13 +1,13 @@
1
- import type {Api} from "@reduxjs/toolkit/query/react";
2
1
  import {Box, Card, Heading, Page, Spinner, Text} from "@terreno/ui";
2
+ import type {Href} from "expo-router";
3
3
  import {router} from "expo-router";
4
4
  import React, {useCallback} from "react";
5
- import type {AdminCustomScreen, AdminModelConfig} from "./types";
5
+ import type {AdminApi, AdminCustomScreen, AdminModelConfig} from "./types";
6
6
  import {useAdminConfig} from "./useAdminConfig";
7
7
 
8
8
  interface AdminModelListProps {
9
9
  baseUrl: string;
10
- api: Api<any, any, any, any>;
10
+ api: AdminApi;
11
11
  /** Path to navigate to for the configuration screen. When provided, a Configuration card is shown. */
12
12
  configurationPath?: string;
13
13
  /** Additional custom screens to display as cards. Merged with any custom screens from the backend config. */
@@ -126,7 +126,7 @@ export const AdminModelList: React.FC<AdminModelListProps> = ({
126
126
 
127
127
  const handlePress = useCallback(
128
128
  (modelName: string) => {
129
- router.push(`${baseUrl}/${modelName}` as any);
129
+ router.push(`${baseUrl}/${modelName}` as Href);
130
130
  },
131
131
  [baseUrl]
132
132
  );
@@ -172,7 +172,7 @@ export const AdminModelList: React.FC<AdminModelListProps> = ({
172
172
  <ScriptsCard count={scripts.length} onPress={() => handlePress("__scripts")} />
173
173
  )}
174
174
  {configurationPath && (
175
- <ConfigurationCard onPress={() => router.push(configurationPath as any)} />
175
+ <ConfigurationCard onPress={() => router.push(configurationPath as Href)} />
176
176
  )}
177
177
  </Box>
178
178
  )}
@@ -1,3 +1,4 @@
1
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
1
2
  import {beforeEach, describe, expect, it, mock} from "bun:test";
2
3
  import {renderWithTheme} from "@terreno/ui/src/test-utils";
3
4
  import React from "react";
@@ -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;