@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,4 +1,3 @@
1
- import type {Api} from "@reduxjs/toolkit/query/react";
2
1
  import {
3
2
  BooleanField,
4
3
  Box,
@@ -14,14 +13,22 @@ import {
14
13
  } from "@terreno/ui";
15
14
  import startCase from "lodash/startCase";
16
15
  import React, {useCallback, useMemo, useState} from "react";
16
+ import type {AdminApi} from "./types";
17
17
  import {useConfigurationApi} from "./useConfigurationApi";
18
18
 
19
+ /**
20
+ * Configuration field/section values are heterogeneous across consumer apps — each app
21
+ * registers its own configuration schema with arbitrary field types. We treat them as
22
+ * unknown shapes at this boundary and narrow when rendering individual fields.
23
+ */
24
+ type ConfigValue = unknown;
25
+
19
26
  interface ConfigFieldMeta {
20
27
  type: string;
21
28
  required: boolean;
22
29
  description?: string;
23
30
  enum?: string[];
24
- default?: any;
31
+ default?: ConfigValue;
25
32
  secret?: boolean;
26
33
  widget?: string;
27
34
  }
@@ -41,7 +48,7 @@ interface ConfigurationScreenProps {
41
48
  /** Base URL for configuration routes (e.g., "/configuration"). */
42
49
  basePath?: string;
43
50
  /** RTK Query API instance. */
44
- api: Api<any, any, any, any>;
51
+ api: AdminApi;
45
52
  /** Optional title override. Defaults to "Configuration". */
46
53
  title?: string;
47
54
  }
@@ -52,8 +59,8 @@ interface ConfigurationScreenProps {
52
59
  const ConfigField: React.FC<{
53
60
  fieldKey: string;
54
61
  fieldMeta: ConfigFieldMeta;
55
- value: any;
56
- onChange: (value: any) => void;
62
+ value: ConfigValue;
63
+ onChange: (value: ConfigValue) => void;
57
64
  sectionName: string;
58
65
  }> = ({fieldKey, fieldMeta, value, onChange, sectionName}) => {
59
66
  const label = startCase(fieldKey);
@@ -61,13 +68,10 @@ const ConfigField: React.FC<{
61
68
  const testID = `config-${sectionName}-${fieldKey}`;
62
69
 
63
70
  if (fieldMeta.type === "boolean") {
71
+ const boolValue =
72
+ typeof value === "boolean" ? value : ((fieldMeta.default as boolean) ?? false);
64
73
  return (
65
- <BooleanField
66
- helperText={helperText}
67
- onChange={onChange}
68
- title={label}
69
- value={value ?? fieldMeta.default ?? false}
70
- />
74
+ <BooleanField helperText={helperText} onChange={onChange} title={label} value={boolValue} />
71
75
  );
72
76
  }
73
77
 
@@ -76,8 +80,14 @@ const ConfigField: React.FC<{
76
80
  <TextField
77
81
  helperText={helperText}
78
82
  onChange={(text: string) => {
83
+ if (text === "") {
84
+ onChange("");
85
+ return;
86
+ }
79
87
  const num = Number(text);
80
- onChange(Number.isNaN(num) ? text : num);
88
+ if (!Number.isNaN(num)) {
89
+ onChange(num);
90
+ }
81
91
  }}
82
92
  testID={testID}
83
93
  title={label}
@@ -93,7 +103,7 @@ const ConfigField: React.FC<{
93
103
  onChange={onChange}
94
104
  testID={testID}
95
105
  title={label}
96
- value={value ?? ""}
106
+ value={typeof value === "string" ? value : ""}
97
107
  />
98
108
  );
99
109
  }
@@ -106,7 +116,7 @@ const ConfigField: React.FC<{
106
116
  testID={testID}
107
117
  title={`${label} (Secret)`}
108
118
  type="password"
109
- value={value ?? ""}
119
+ value={typeof value === "string" ? value : ""}
110
120
  />
111
121
  );
112
122
  }
@@ -117,7 +127,7 @@ const ConfigField: React.FC<{
117
127
  onChange={onChange}
118
128
  testID={testID}
119
129
  title={label}
120
- value={value ?? ""}
130
+ value={typeof value === "string" ? value : ""}
121
131
  />
122
132
  );
123
133
  };
@@ -130,10 +140,13 @@ const SectionDescription: React.FC<{description: string}> = ({description}) => (
130
140
 
131
141
  const SectionCard: React.FC<{
132
142
  section: ConfigSectionMeta;
133
- formState: Record<string, any>;
134
- onFieldChange: (sectionName: string, fieldKey: string, value: any) => void;
143
+ formState: Record<string, ConfigValue>;
144
+ onFieldChange: (sectionName: string, fieldKey: string, value: ConfigValue) => void;
135
145
  }> = ({section, formState, onFieldChange}) => {
136
- const sectionValues = section.name === "__root__" ? formState : (formState[section.name] ?? {});
146
+ const sectionValues =
147
+ section.name === "__root__"
148
+ ? formState
149
+ : ((formState[section.name] as Record<string, ConfigValue> | undefined) ?? {});
137
150
  return (
138
151
  <Card padding={4}>
139
152
  <Box gap={3}>
@@ -146,7 +159,7 @@ const SectionCard: React.FC<{
146
159
  fieldKey={fieldKey}
147
160
  fieldMeta={fieldMeta}
148
161
  key={fieldKey}
149
- onChange={(value: any) => onFieldChange(section.name, fieldKey, value)}
162
+ onChange={(value: ConfigValue) => onFieldChange(section.name, fieldKey, value)}
150
163
  sectionName={section.name}
151
164
  value={sectionValues[fieldKey]}
152
165
  />
@@ -190,7 +203,7 @@ export const ConfigurationScreen: React.FC<ConfigurationScreenProps> = ({
190
203
  const [updateConfig, {isLoading: isSaving}] = useUpdateMutation();
191
204
 
192
205
  // Tracks only the fields the user has explicitly edited. null = no edits yet.
193
- const [userEdits, setUserEdits] = useState<Record<string, any> | null>(null);
206
+ const [userEdits, setUserEdits] = useState<Record<string, ConfigValue> | null>(null);
194
207
  const [isDirty, setIsDirty] = useState(false);
195
208
 
196
209
  const toast = useToast();
@@ -198,26 +211,27 @@ export const ConfigurationScreen: React.FC<ConfigurationScreenProps> = ({
198
211
  const configMeta = meta as ConfigurationMetaResponse | undefined;
199
212
  // The baseQuery in emptyApi.ts unwraps {data: ...} responses, so valuesResponse
200
213
  // is already the config document — not a wrapper object.
201
- const configValues = valuesResponse as Record<string, any> | undefined;
214
+ const configValues = valuesResponse as Record<string, ConfigValue> | undefined;
202
215
 
203
216
  // Derived synchronously so the form is never blank when data is already cached.
204
- const serverValues = useMemo((): Record<string, any> => {
217
+ const serverValues = useMemo((): Record<string, ConfigValue> => {
205
218
  if (!configValues || !configMeta) return {};
206
219
  const emptyDefault = (fieldMeta: ConfigFieldMeta) =>
207
220
  fieldMeta.type === "boolean" ? false : "";
208
- const initial: Record<string, any> = {};
221
+ const initial: Record<string, ConfigValue> = {};
209
222
  for (const section of configMeta.sections) {
210
223
  if (section.name === "__root__") {
211
224
  for (const [key, fieldMeta] of Object.entries(section.fields)) {
212
225
  initial[key] = configValues[key] ?? fieldMeta.default ?? emptyDefault(fieldMeta);
213
226
  }
214
227
  } else {
215
- initial[section.name] = {};
216
- const sectionValues = (configValues[section.name] as Record<string, any>) ?? {};
228
+ const nestedInitial: Record<string, ConfigValue> = {};
229
+ const sectionValues =
230
+ (configValues[section.name] as Record<string, ConfigValue> | undefined) ?? {};
217
231
  for (const [key, fieldMeta] of Object.entries(section.fields)) {
218
- initial[section.name][key] =
219
- sectionValues[key] ?? fieldMeta.default ?? emptyDefault(fieldMeta);
232
+ nestedInitial[key] = sectionValues[key] ?? fieldMeta.default ?? emptyDefault(fieldMeta);
220
233
  }
234
+ initial[section.name] = nestedInitial;
221
235
  }
222
236
  }
223
237
  return initial;
@@ -226,7 +240,7 @@ export const ConfigurationScreen: React.FC<ConfigurationScreenProps> = ({
226
240
  const formState = userEdits ?? serverValues;
227
241
 
228
242
  const handleFieldChange = useCallback(
229
- (sectionName: string, fieldKey: string, value: any) => {
243
+ (sectionName: string, fieldKey: string, value: ConfigValue) => {
230
244
  setIsDirty(true);
231
245
  setUserEdits((prev) => {
232
246
  const base = prev ?? serverValues;
@@ -236,7 +250,7 @@ export const ConfigurationScreen: React.FC<ConfigurationScreenProps> = ({
236
250
  return {
237
251
  ...base,
238
252
  [sectionName]: {
239
- ...(base[sectionName] as Record<string, any>),
253
+ ...(base[sectionName] as Record<string, ConfigValue>),
240
254
  [fieldKey]: value,
241
255
  },
242
256
  };