@terreno/admin-frontend 0.13.3 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AdminFieldRenderer.d.ts +5 -53
- package/dist/AdminFieldRenderer.js +6 -168
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.d.ts +26 -0
- package/dist/AdminFieldRendererCore.js +138 -0
- package/dist/AdminFieldRendererCore.js.map +1 -0
- package/dist/AdminModelForm.d.ts +6 -7
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +2 -3
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +2 -2
- package/dist/AdminModelTable.js +2 -1
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +6 -7
- package/dist/AdminNestedArrayField.js +26 -2
- package/dist/AdminNestedArrayField.js.map +1 -1
- package/dist/AdminObjectPicker.d.ts +2 -2
- package/dist/AdminObjectPicker.js +13 -7
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +2 -3
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminScriptList.d.ts +2 -2
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +2 -2
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/dist/AdminVersionConfig.d.ts +2 -2
- package/dist/AdminVersionConfig.js +16 -10
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConfigurationScreen.d.ts +2 -2
- package/dist/ConfigurationScreen.js +18 -9
- package/dist/ConfigurationScreen.js.map +1 -1
- package/dist/ConsentFormEditor.d.ts +27 -2
- package/dist/ConsentFormEditor.js +48 -32
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/ConsentFormList.d.ts +2 -1
- package/dist/ConsentFormList.js.map +1 -1
- package/dist/ConsentResponseViewer.d.ts +2 -1
- package/dist/ConsentResponseViewer.js.map +1 -1
- package/dist/DocumentStorageBrowser.js.map +1 -1
- package/dist/types.d.ts +29 -4
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.d.ts +2 -2
- package/dist/useAdminApi.js +8 -5
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminConfig.d.ts +2 -3
- package/dist/useAdminConfig.js +2 -0
- package/dist/useAdminConfig.js.map +1 -1
- package/dist/useAdminScripts.d.ts +2 -3
- package/dist/useAdminScripts.js +6 -3
- package/dist/useAdminScripts.js.map +1 -1
- package/dist/useConfigurationApi.d.ts +11 -8
- package/dist/useConfigurationApi.js +7 -4
- package/dist/useConfigurationApi.js.map +1 -1
- package/dist/useDocumentStorageApi.d.ts +2 -2
- package/dist/useDocumentStorageApi.js +9 -6
- package/dist/useDocumentStorageApi.js.map +1 -1
- package/package.json +2 -2
- package/src/AdminFieldRenderer.test.tsx +48 -22
- package/src/AdminFieldRenderer.tsx +18 -371
- package/src/AdminFieldRendererCore.tsx +356 -0
- package/src/AdminModelForm.test.tsx +146 -40
- package/src/AdminModelForm.tsx +22 -17
- package/src/AdminModelList.test.tsx +14 -5
- package/src/AdminModelList.tsx +5 -5
- package/src/AdminModelTable.test.tsx +58 -31
- package/src/AdminModelTable.tsx +11 -10
- package/src/AdminNestedArrayField.tsx +91 -26
- package/src/AdminObjectPicker.tsx +33 -16
- package/src/AdminPrimitiveArrayField.test.tsx +14 -10
- package/src/AdminPrimitiveArrayField.tsx +2 -3
- package/src/AdminScriptList.test.tsx +7 -4
- package/src/AdminScriptList.tsx +2 -3
- package/src/AdminScriptRunModal.test.tsx +5 -2
- package/src/AdminScriptRunModal.tsx +2 -3
- package/src/AdminVersionConfig.test.tsx +47 -21
- package/src/AdminVersionConfig.tsx +29 -5
- package/src/CheckboxListEditor.test.tsx +9 -6
- package/src/ConfigurationScreen.test.tsx +16 -11
- package/src/ConfigurationScreen.tsx +43 -29
- package/src/ConsentFormEditor.test.tsx +95 -75
- package/src/ConsentFormEditor.tsx +76 -49
- package/src/ConsentFormList.test.tsx +28 -10
- package/src/ConsentFormList.tsx +14 -2
- package/src/ConsentResponseViewer.test.tsx +15 -12
- package/src/ConsentResponseViewer.tsx +3 -2
- package/src/DocumentStorageBrowser.test.tsx +69 -42
- package/src/DocumentStorageBrowser.tsx +4 -4
- package/src/LocaleContentEditor.test.tsx +28 -18
- package/src/isolated/AdminFieldRenderer.isolated.tsx +5 -2
- package/src/isolated/AdminNestedArrayField.isolated.tsx +49 -36
- package/src/isolated/AdminObjectPicker.isolated.tsx +31 -26
- package/src/isolated/AdminRefField.isolated.tsx +4 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +24 -17
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +80 -63
- package/src/isolated/hooks.isolated.tsx +40 -33
- package/src/types.ts +34 -4
- package/src/useAdminApi.ts +21 -13
- package/src/useAdminConfig.ts +5 -4
- package/src/useAdminScripts.ts +9 -7
- package/src/useConfigurationApi.ts +26 -12
- package/src/useDocumentStorageApi.ts +12 -9
|
@@ -1,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?:
|
|
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:
|
|
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:
|
|
56
|
-
onChange: (value:
|
|
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
|
-
|
|
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,
|
|
134
|
-
onFieldChange: (sectionName: string, fieldKey: string, value:
|
|
143
|
+
formState: Record<string, ConfigValue>;
|
|
144
|
+
onFieldChange: (sectionName: string, fieldKey: string, value: ConfigValue) => void;
|
|
135
145
|
}> = ({section, formState, onFieldChange}) => {
|
|
136
|
-
const sectionValues =
|
|
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:
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
216
|
-
const sectionValues =
|
|
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
|
-
|
|
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:
|
|
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,
|
|
253
|
+
...(base[sectionName] as Record<string, ConfigValue>),
|
|
240
254
|
[fieldKey]: value,
|
|
241
255
|
},
|
|
242
256
|
};
|