@terreno/admin-frontend 0.13.0 → 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.
- 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 +12 -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 +15 -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 +7 -5
- 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 +9 -5
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminConfig.d.ts +2 -3
- package/dist/useAdminConfig.js +1 -0
- package/dist/useAdminConfig.js.map +1 -1
- package/dist/useAdminScripts.d.ts +2 -3
- package/dist/useAdminScripts.js +5 -3
- package/dist/useAdminScripts.js.map +1 -1
- package/dist/useConfigurationApi.d.ts +11 -8
- package/dist/useConfigurationApi.js +6 -4
- package/dist/useConfigurationApi.js.map +1 -1
- package/dist/useDocumentStorageApi.d.ts +2 -2
- package/dist/useDocumentStorageApi.js +8 -6
- package/dist/useDocumentStorageApi.js.map +1 -1
- package/package.json +2 -2
- package/src/AdminFieldRenderer.test.tsx +1 -0
- package/src/AdminFieldRenderer.tsx +18 -371
- package/src/AdminFieldRendererCore.tsx +356 -0
- package/src/AdminModelForm.test.tsx +1 -0
- package/src/AdminModelForm.tsx +22 -17
- package/src/AdminModelList.test.tsx +1 -0
- package/src/AdminModelList.tsx +5 -5
- package/src/AdminModelTable.test.tsx +1 -0
- package/src/AdminModelTable.tsx +11 -10
- package/src/AdminNestedArrayField.tsx +91 -26
- package/src/AdminObjectPicker.tsx +32 -16
- package/src/AdminPrimitiveArrayField.test.tsx +1 -0
- package/src/AdminPrimitiveArrayField.tsx +2 -3
- package/src/AdminScriptList.test.tsx +1 -0
- package/src/AdminScriptList.tsx +2 -3
- package/src/AdminScriptRunModal.test.tsx +3 -2
- package/src/AdminScriptRunModal.tsx +2 -3
- package/src/AdminVersionConfig.test.tsx +21 -0
- package/src/AdminVersionConfig.tsx +28 -5
- package/src/CheckboxListEditor.test.tsx +1 -0
- package/src/ConfigurationScreen.test.tsx +1 -0
- package/src/ConfigurationScreen.tsx +43 -29
- package/src/ConsentFormEditor.test.tsx +1 -0
- package/src/ConsentFormEditor.tsx +34 -18
- package/src/ConsentFormList.test.tsx +1 -0
- package/src/ConsentFormList.tsx +14 -2
- package/src/ConsentResponseViewer.test.tsx +1 -0
- package/src/ConsentResponseViewer.tsx +3 -2
- package/src/DocumentStorageBrowser.test.tsx +1 -0
- package/src/DocumentStorageBrowser.tsx +4 -4
- package/src/LocaleContentEditor.test.tsx +1 -0
- package/src/isolated/AdminFieldRenderer.isolated.tsx +1 -0
- package/src/isolated/AdminNestedArrayField.isolated.tsx +1 -0
- package/src/isolated/AdminObjectPicker.isolated.tsx +1 -0
- package/src/isolated/AdminRefField.isolated.tsx +1 -0
- package/src/isolated/AdminScriptRunModal.isolated.tsx +1 -0
- package/src/isolated/DocumentStorageBrowser.isolated.tsx +1 -0
- package/src/isolated/hooks.isolated.tsx +1 -0
- package/src/types.ts +34 -4
- package/src/useAdminApi.ts +22 -13
- package/src/useAdminConfig.ts +4 -4
- package/src/useAdminScripts.ts +8 -7
- package/src/useConfigurationApi.ts +25 -12
- package/src/useDocumentStorageApi.ts +11 -9
|
@@ -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 {
|
|
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,
|
|
18
|
-
onChange: (value: Record<string,
|
|
19
|
-
api:
|
|
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,
|
|
24
|
-
/** Forwarded to nested
|
|
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
|
-
|
|
29
|
-
|
|
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,
|
|
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:
|
|
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
|
-
|
|
168
|
-
api
|
|
169
|
-
baseUrl
|
|
170
|
-
fieldConfig
|
|
171
|
-
fieldKey
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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:
|
|
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:
|
|
30
|
+
const getDisplayValue = (item: PickerItem): string => {
|
|
19
31
|
for (const field of DISPLAY_FIELDS) {
|
|
20
|
-
|
|
21
|
-
|
|
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:
|
|
40
|
+
const getSecondaryText = (item: PickerItem, primaryField: string): string | undefined => {
|
|
28
41
|
for (const field of DISPLAY_FIELDS) {
|
|
29
|
-
|
|
30
|
-
|
|
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:
|
|
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:
|
|
90
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
77
91
|
[searchEndpointKey]: build.query({
|
|
78
92
|
query: (q: string) => ({
|
|
79
93
|
method: "GET",
|
|
@@ -93,8 +107,10 @@ 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
|
-
|
|
97
|
-
const
|
|
110
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
111
|
+
const enhanced = enhancedApi as any;
|
|
112
|
+
const useSearchQuery = enhanced[`use${capitalize(searchEndpointKey)}Query`];
|
|
113
|
+
const useReadQuery = enhanced[`use${capitalize(readEndpointKey)}Query`];
|
|
98
114
|
|
|
99
115
|
const {data: searchData, isFetching: isSearching} = useSearchQuery(debouncedQuery, {
|
|
100
116
|
skip: !debouncedQuery,
|
|
@@ -125,8 +141,8 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
|
|
|
125
141
|
}, []);
|
|
126
142
|
|
|
127
143
|
const handleSelect = useCallback(
|
|
128
|
-
(item:
|
|
129
|
-
onChange(item._id);
|
|
144
|
+
(item: PickerItem) => {
|
|
145
|
+
onChange(item._id ?? "");
|
|
130
146
|
setSelectedDisplay(getDisplayValue(item));
|
|
131
147
|
setSearchText("");
|
|
132
148
|
setDebouncedQuery("");
|
|
@@ -216,7 +232,7 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
|
|
|
216
232
|
)}
|
|
217
233
|
|
|
218
234
|
{!isSearching &&
|
|
219
|
-
results.map((item
|
|
235
|
+
(results as PickerItem[]).map((item) => {
|
|
220
236
|
const primaryField = getPrimaryField(item);
|
|
221
237
|
const secondary = getSecondaryText(item, primaryField);
|
|
222
238
|
return (
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {
|
|
3
2
|
BooleanField,
|
|
4
3
|
Box,
|
|
@@ -12,7 +11,7 @@ import {
|
|
|
12
11
|
import startCase from "lodash/startCase";
|
|
13
12
|
import React, {useCallback} from "react";
|
|
14
13
|
import {AdminRefField} from "./AdminRefField";
|
|
15
|
-
import type {RefRendererMap} from "./types";
|
|
14
|
+
import type {AdminApi, RefRendererMap} from "./types";
|
|
16
15
|
|
|
17
16
|
interface AdminPrimitiveArrayFieldProps {
|
|
18
17
|
title: string;
|
|
@@ -23,7 +22,7 @@ interface AdminPrimitiveArrayFieldProps {
|
|
|
23
22
|
itemRef?: string;
|
|
24
23
|
value: PrimitiveItem[];
|
|
25
24
|
onChange: (value: PrimitiveItem[]) => void;
|
|
26
|
-
api:
|
|
25
|
+
api: AdminApi;
|
|
27
26
|
baseUrl: string;
|
|
28
27
|
modelConfigs?: Array<{name: string; routePath: string}>;
|
|
29
28
|
/**
|
package/src/AdminScriptList.tsx
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {Box, Button, Card, Heading, Page, Spinner, Text} from "@terreno/ui";
|
|
3
2
|
import React, {useCallback, useState} from "react";
|
|
4
3
|
import {AdminScriptRunModal} from "./AdminScriptRunModal";
|
|
5
|
-
import type {AdminScriptConfig} from "./types";
|
|
4
|
+
import type {AdminApi, AdminScriptConfig} from "./types";
|
|
6
5
|
import {useAdminConfig} from "./useAdminConfig";
|
|
7
6
|
|
|
8
7
|
interface AdminScriptListProps {
|
|
9
8
|
baseUrl: string;
|
|
10
|
-
api:
|
|
9
|
+
api: AdminApi;
|
|
11
10
|
/** When false, the Run button is disabled. Defaults to true. */
|
|
12
11
|
isAdmin?: boolean;
|
|
13
12
|
}
|
|
@@ -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 * as terrenoUi from "@terreno/ui";
|
|
3
4
|
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
@@ -9,7 +10,7 @@ import {AdminScriptRunModal} from "./AdminScriptRunModal";
|
|
|
9
10
|
mock.module("@terreno/ui", () => ({
|
|
10
11
|
...terrenoUi,
|
|
11
12
|
Modal: ({children, visible}: {children?: React.ReactNode; visible?: boolean}) =>
|
|
12
|
-
visible ?
|
|
13
|
+
visible ? children : null,
|
|
13
14
|
}));
|
|
14
15
|
|
|
15
16
|
const mockRunScript = mock((_args: {name: string; wetRun: boolean}) => ({
|
|
@@ -21,7 +22,7 @@ const mockCancelTask = mock((_taskId: string) => ({
|
|
|
21
22
|
|
|
22
23
|
const mockUseAdminScripts = mock(() => ({
|
|
23
24
|
useCancelScriptTaskMutation: () => [mockCancelTask, {isLoading: false}],
|
|
24
|
-
useGetScriptTaskQuery: () => ({data: undefined,
|
|
25
|
+
useGetScriptTaskQuery: () => ({data: undefined, error: null, isLoading: false}),
|
|
25
26
|
useRunScriptMutation: () => [mockRunScript, {isLoading: false}],
|
|
26
27
|
}));
|
|
27
28
|
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {Badge, Box, Button, Heading, Icon, Modal, Spinner, Text} from "@terreno/ui";
|
|
3
2
|
import React, {useCallback, useEffect, useRef, useState} from "react";
|
|
4
|
-
import type {BackgroundTask} from "./types";
|
|
3
|
+
import type {AdminApi, BackgroundTask} from "./types";
|
|
5
4
|
import {useAdminScripts} from "./useAdminScripts";
|
|
6
5
|
|
|
7
6
|
interface AdminScriptRunModalProps {
|
|
8
7
|
baseUrl: string;
|
|
9
|
-
api:
|
|
8
|
+
api: AdminApi;
|
|
10
9
|
scriptName: string | null;
|
|
11
10
|
scriptDescription?: string;
|
|
12
11
|
visible: boolean;
|
|
@@ -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";
|
|
@@ -150,6 +151,7 @@ describe("AdminVersionConfig", () => {
|
|
|
150
151
|
apiState.data = {
|
|
151
152
|
mobileRequiredVersion: 1,
|
|
152
153
|
mobileWarningVersion: 2,
|
|
154
|
+
pollingIntervalMinutes: 120,
|
|
153
155
|
requiredMessage: "R",
|
|
154
156
|
updateUrl: " https://x.com ",
|
|
155
157
|
warningMessage: "W",
|
|
@@ -165,6 +167,25 @@ describe("AdminVersionConfig", () => {
|
|
|
165
167
|
});
|
|
166
168
|
expect(updateCalls.length).toBe(1);
|
|
167
169
|
expect(updateCalls[0].updateUrl).toBe("https://x.com");
|
|
170
|
+
expect(updateCalls[0].pollingIntervalMinutes).toBe(120);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("saves default pollingIntervalMinutes (1440) when not provided by backend", async () => {
|
|
174
|
+
apiState.data = {
|
|
175
|
+
mobileRequiredVersion: 0,
|
|
176
|
+
mobileWarningVersion: 0,
|
|
177
|
+
webRequiredVersion: 0,
|
|
178
|
+
webWarningVersion: 0,
|
|
179
|
+
};
|
|
180
|
+
const {getByText} = renderWithTheme(
|
|
181
|
+
<AdminVersionConfig api={makeApi() as any} baseUrl="/admin" />
|
|
182
|
+
);
|
|
183
|
+
await act(async () => {
|
|
184
|
+
fireEvent.press(getByText("Save"));
|
|
185
|
+
await new Promise((r) => setTimeout(r, 150));
|
|
186
|
+
});
|
|
187
|
+
expect(updateCalls.length).toBe(1);
|
|
188
|
+
expect(updateCalls[0].pollingIntervalMinutes).toBe(1440);
|
|
168
189
|
});
|
|
169
190
|
|
|
170
191
|
it("handles save failures gracefully", async () => {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
1
|
import {Box, Button, NumberField, Page, Spinner, Text, TextField, useToast} from "@terreno/ui";
|
|
3
2
|
import {router} from "expo-router";
|
|
4
3
|
import React, {useCallback, useEffect, useMemo, useState} from "react";
|
|
4
|
+
import type {AdminApi, EndpointBuilder} from "./types";
|
|
5
5
|
|
|
6
6
|
interface VersionConfigData {
|
|
7
7
|
mobileRequiredVersion?: number;
|
|
8
8
|
mobileWarningVersion?: number;
|
|
9
|
+
/** How often clients poll for version updates, in minutes. */
|
|
10
|
+
pollingIntervalMinutes?: number;
|
|
9
11
|
requiredMessage?: string;
|
|
10
12
|
updateUrl?: string | null;
|
|
11
13
|
webRequiredVersion?: number;
|
|
@@ -14,7 +16,7 @@ interface VersionConfigData {
|
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
interface AdminVersionConfigProps {
|
|
17
|
-
api:
|
|
19
|
+
api: AdminApi;
|
|
18
20
|
baseUrl: string;
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -27,7 +29,7 @@ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, base
|
|
|
27
29
|
|
|
28
30
|
const enhancedApi = useMemo(() => {
|
|
29
31
|
return api.injectEndpoints({
|
|
30
|
-
endpoints: (build:
|
|
32
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
31
33
|
[VERSION_CONFIG_ENDPOINT]: build.query({
|
|
32
34
|
query: () => ({
|
|
33
35
|
method: "GET",
|
|
@@ -46,8 +48,10 @@ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, base
|
|
|
46
48
|
});
|
|
47
49
|
}, [api, baseUrl]);
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
52
|
+
const enhanced = enhancedApi as any;
|
|
53
|
+
const useVersionConfigQuery = enhanced.useAdminVersionConfigQuery;
|
|
54
|
+
const [updateConfig] = enhanced.useUpdateVersionConfigMutation();
|
|
51
55
|
|
|
52
56
|
const {data, isLoading: isFetching, error: fetchError} = useVersionConfigQuery();
|
|
53
57
|
|
|
@@ -59,6 +63,7 @@ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, base
|
|
|
59
63
|
const defaults = {
|
|
60
64
|
mobileRequiredVersion: 0,
|
|
61
65
|
mobileWarningVersion: 0,
|
|
66
|
+
pollingIntervalMinutes: 1440,
|
|
62
67
|
requiredMessage: "This version is no longer supported. Please update to continue.",
|
|
63
68
|
updateUrl: "",
|
|
64
69
|
warningMessage: "A new version is available. Please update for the best experience.",
|
|
@@ -69,6 +74,7 @@ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, base
|
|
|
69
74
|
setFormState({
|
|
70
75
|
mobileRequiredVersion: data.mobileRequiredVersion ?? 0,
|
|
71
76
|
mobileWarningVersion: data.mobileWarningVersion ?? 0,
|
|
77
|
+
pollingIntervalMinutes: data.pollingIntervalMinutes ?? defaults.pollingIntervalMinutes,
|
|
72
78
|
requiredMessage: data.requiredMessage ?? defaults.requiredMessage,
|
|
73
79
|
updateUrl: data.updateUrl ?? "",
|
|
74
80
|
warningMessage: data.warningMessage ?? defaults.warningMessage,
|
|
@@ -94,6 +100,7 @@ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, base
|
|
|
94
100
|
await updateConfig({
|
|
95
101
|
mobileRequiredVersion: Number(formState.mobileRequiredVersion) || 0,
|
|
96
102
|
mobileWarningVersion: Number(formState.mobileWarningVersion) || 0,
|
|
103
|
+
pollingIntervalMinutes: Math.max(1, Number(formState.pollingIntervalMinutes) || 1440),
|
|
97
104
|
requiredMessage: formState.requiredMessage ?? "",
|
|
98
105
|
updateUrl: trimmedUpdateUrl || null,
|
|
99
106
|
warningMessage: formState.warningMessage ?? "",
|
|
@@ -202,6 +209,22 @@ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, base
|
|
|
202
209
|
/>
|
|
203
210
|
</Box>
|
|
204
211
|
|
|
212
|
+
<Box gap={2}>
|
|
213
|
+
<Text bold size="md">
|
|
214
|
+
Polling
|
|
215
|
+
</Text>
|
|
216
|
+
<NumberField
|
|
217
|
+
onChange={(v) => handleFieldChange("pollingIntervalMinutes", parseInt(v, 10) || 1440)}
|
|
218
|
+
title="Update check interval (minutes)"
|
|
219
|
+
type="number"
|
|
220
|
+
value={String(formState.pollingIntervalMinutes ?? 1440)}
|
|
221
|
+
/>
|
|
222
|
+
<Text color="secondaryDark" size="sm">
|
|
223
|
+
How often clients check for updates in the background. Default: 1440 (24 hours).
|
|
224
|
+
Minimum: 1.
|
|
225
|
+
</Text>
|
|
226
|
+
</Box>
|
|
227
|
+
|
|
205
228
|
<Box direction="row" gap={2}>
|
|
206
229
|
<Button onClick={handleBack} text="Back" variant="outline" />
|
|
207
230
|
<Button loading={isSaving} onClick={handleSave} text="Save" variant="primary" />
|