@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
@@ -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,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
- const useSearchQuery = (enhancedApi as any)[`use${capitalize(searchEndpointKey)}Query`];
97
- const useReadQuery = (enhancedApi as any)[`use${capitalize(readEndpointKey)}Query`];
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: any) => {
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: any) => {
235
+ (results as PickerItem[]).map((item) => {
220
236
  const primaryField = getPrimaryField(item);
221
237
  const secondary = getSecondaryText(item, primaryField);
222
238
  return (
@@ -1,3 +1,4 @@
1
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
1
2
  import {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
  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: Api<any, any, any, any>;
25
+ api: AdminApi;
27
26
  baseUrl: string;
28
27
  modelConfigs?: Array<{name: string; routePath: string}>;
29
28
  /**
@@ -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,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: Api<any, any, any, any>;
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";
@@ -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: Api<any, any, any, any>;
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: Api<any, any, any, any>;
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: any) => ({
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
- const useVersionConfigQuery = (enhancedApi as any).useAdminVersionConfigQuery;
50
- const [updateConfig] = (enhancedApi as any).useUpdateVersionConfigMutation();
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" />
@@ -1,3 +1,4 @@
1
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
1
2
  import {describe, expect, it, mock} from "bun:test";
2
3
  import {renderWithTheme} from "@terreno/ui/src/test-utils";
3
4
  import React from "react";
@@ -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
  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
  };