@terreno/admin-frontend 0.16.1 → 0.17.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 (70) hide show
  1. package/dist/AdminFieldRenderer.js +3 -3
  2. package/dist/AdminFieldRenderer.js.map +1 -1
  3. package/dist/AdminFieldRendererCore.js +4 -4
  4. package/dist/AdminFieldRendererCore.js.map +1 -1
  5. package/dist/AdminModelForm.d.ts +6 -1
  6. package/dist/AdminModelForm.js +9 -4
  7. package/dist/AdminModelForm.js.map +1 -1
  8. package/dist/AdminModelList.d.ts +7 -2
  9. package/dist/AdminModelList.js +10 -4
  10. package/dist/AdminModelList.js.map +1 -1
  11. package/dist/AdminModelTable.d.ts +7 -2
  12. package/dist/AdminModelTable.js +14 -6
  13. package/dist/AdminModelTable.js.map +1 -1
  14. package/dist/AdminNestedArrayField.d.ts +6 -1
  15. package/dist/AdminNestedArrayField.js +8 -4
  16. package/dist/AdminNestedArrayField.js.map +1 -1
  17. package/dist/AdminPrimitiveArrayField.d.ts +6 -1
  18. package/dist/AdminPrimitiveArrayField.js +3 -3
  19. package/dist/AdminPrimitiveArrayField.js.map +1 -1
  20. package/dist/AdminScriptList.d.ts +7 -2
  21. package/dist/AdminScriptList.js +9 -3
  22. package/dist/AdminScriptList.js.map +1 -1
  23. package/dist/AdminScriptRunModal.d.ts +7 -2
  24. package/dist/AdminScriptRunModal.js +4 -2
  25. package/dist/AdminScriptRunModal.js.map +1 -1
  26. package/dist/AdminVersionConfig.d.ts +7 -2
  27. package/dist/AdminVersionConfig.js +6 -4
  28. package/dist/AdminVersionConfig.js.map +1 -1
  29. package/dist/ConsentFormEditor.d.ts +7 -2
  30. package/dist/ConsentFormEditor.js +4 -2
  31. package/dist/ConsentFormEditor.js.map +1 -1
  32. package/dist/ConsentFormList.d.ts +7 -2
  33. package/dist/ConsentFormList.js +4 -2
  34. package/dist/ConsentFormList.js.map +1 -1
  35. package/dist/ConsentResponseViewer.d.ts +7 -2
  36. package/dist/ConsentResponseViewer.js +4 -2
  37. package/dist/ConsentResponseViewer.js.map +1 -1
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.js +1 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/types.d.ts +41 -2
  42. package/dist/types.js +12 -0
  43. package/dist/types.js.map +1 -1
  44. package/dist/useAdminConfig.d.ts +2 -2
  45. package/dist/useAdminConfig.js +4 -4
  46. package/dist/useAdminScripts.d.ts +1 -1
  47. package/dist/useAdminScripts.js +5 -5
  48. package/package.json +2 -2
  49. package/src/AdminFieldRenderer.tsx +6 -0
  50. package/src/AdminFieldRendererCore.tsx +8 -0
  51. package/src/AdminModelForm.tsx +17 -4
  52. package/src/AdminModelList.test.tsx +41 -5
  53. package/src/AdminModelList.tsx +22 -5
  54. package/src/AdminModelTable.test.tsx +58 -5
  55. package/src/AdminModelTable.tsx +27 -7
  56. package/src/AdminNestedArrayField.tsx +21 -2
  57. package/src/AdminPrimitiveArrayField.tsx +12 -1
  58. package/src/AdminScriptList.tsx +22 -5
  59. package/src/AdminScriptRunModal.tsx +11 -3
  60. package/src/AdminVersionConfig.tsx +17 -6
  61. package/src/ConsentFormEditor.tsx +11 -3
  62. package/src/ConsentFormList.tsx +11 -3
  63. package/src/ConsentResponseViewer.tsx +16 -4
  64. package/src/index.tsx +1 -1
  65. package/src/isolated/AdminNestedArrayField.isolated.tsx +2 -2
  66. package/src/isolated/AdminScriptRunModal.isolated.tsx +108 -28
  67. package/src/types.ts +48 -2
  68. package/src/useAdminConfig.ts +4 -4
  69. package/src/useAdminScripts.ts +5 -5
  70. package/src/AdminScriptRunModal.test.tsx +0 -132
@@ -23,7 +23,12 @@ interface AdminPrimitiveArrayFieldProps {
23
23
  value: PrimitiveItem[];
24
24
  onChange: (value: PrimitiveItem[]) => void;
25
25
  api: AdminApi;
26
- baseUrl: string;
26
+ /** @deprecated Use `apiBase`/`routeBase`. Kept as a backward-compatible alias. */
27
+ baseUrl?: string;
28
+ /** Base path where admin API requests are sent. Falls back to `baseUrl`. */
29
+ apiBase?: string;
30
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
31
+ routeBase?: string;
27
32
  modelConfigs?: Array<{name: string; routePath: string}>;
28
33
  /**
29
34
  * Optional map of custom ref-field renderers keyed by referenced model name. When
@@ -61,6 +66,8 @@ export const AdminPrimitiveArrayField: React.FC<AdminPrimitiveArrayFieldProps> =
61
66
  onChange,
62
67
  api,
63
68
  baseUrl,
69
+ apiBase,
70
+ routeBase,
64
71
  modelConfigs,
65
72
  refRenderers,
66
73
  }) => {
@@ -115,9 +122,11 @@ export const AdminPrimitiveArrayField: React.FC<AdminPrimitiveArrayFieldProps> =
115
122
  return (
116
123
  <CustomRenderer
117
124
  api={api}
125
+ apiBase={apiBase}
118
126
  baseUrl={baseUrl}
119
127
  onChange={(val: string) => handleUpdate(index, val)}
120
128
  refModelName={itemRef}
129
+ routeBase={routeBase}
121
130
  routePath={refModel?.routePath ?? ""}
122
131
  title=""
123
132
  value={item != null ? String(item) : ""}
@@ -128,9 +137,11 @@ export const AdminPrimitiveArrayField: React.FC<AdminPrimitiveArrayFieldProps> =
128
137
  return (
129
138
  <AdminRefField
130
139
  api={api}
140
+ apiBase={apiBase}
131
141
  baseUrl={baseUrl}
132
142
  onChange={(val: string) => handleUpdate(index, val)}
133
143
  refModelName={refModel.name}
144
+ routeBase={routeBase}
134
145
  routePath={refModel.routePath}
135
146
  title=""
136
147
  value={item != null ? String(item) : ""}
@@ -1,18 +1,34 @@
1
1
  import {Box, Button, Card, Heading, Page, Spinner, Text} from "@terreno/ui";
2
2
  import React, {useCallback, useState} from "react";
3
3
  import {AdminScriptRunModal} from "./AdminScriptRunModal";
4
- import type {AdminApi, AdminScriptConfig} from "./types";
4
+ import {type AdminApi, type AdminScriptConfig, resolveAdminBases} from "./types";
5
5
  import {useAdminConfig} from "./useAdminConfig";
6
6
 
7
7
  interface AdminScriptListProps {
8
- baseUrl: string;
8
+ /** @deprecated Use `apiBase`/`routeBase`. Kept as a backward-compatible alias. */
9
+ baseUrl?: string;
10
+ /** Base path where admin API requests are sent. Falls back to `baseUrl`. */
11
+ apiBase?: string;
12
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
13
+ routeBase?: string;
9
14
  api: AdminApi;
10
15
  /** When false, the Run button is disabled. Defaults to true. */
11
16
  isAdmin?: boolean;
12
17
  }
13
18
 
14
- export const AdminScriptList: React.FC<AdminScriptListProps> = ({baseUrl, api, isAdmin = true}) => {
15
- const {config, isLoading, error} = useAdminConfig(api, baseUrl);
19
+ export const AdminScriptList: React.FC<AdminScriptListProps> = ({
20
+ baseUrl,
21
+ apiBase,
22
+ routeBase,
23
+ api,
24
+ isAdmin = true,
25
+ }) => {
26
+ const {apiBase: resolvedApiBase, routeBase: resolvedRouteBase} = resolveAdminBases({
27
+ apiBase,
28
+ baseUrl,
29
+ routeBase,
30
+ });
31
+ const {config, isLoading, error} = useAdminConfig(api, resolvedApiBase);
16
32
  const [selectedScript, setSelectedScript] = useState<AdminScriptConfig | null>(null);
17
33
  const [modalVisible, setModalVisible] = useState(false);
18
34
 
@@ -85,8 +101,9 @@ export const AdminScriptList: React.FC<AdminScriptListProps> = ({baseUrl, api, i
85
101
 
86
102
  <AdminScriptRunModal
87
103
  api={api}
88
- baseUrl={baseUrl}
104
+ apiBase={resolvedApiBase}
89
105
  onDismiss={handleDismiss}
106
+ routeBase={resolvedRouteBase}
90
107
  scriptDescription={selectedScript?.description}
91
108
  scriptName={selectedScript?.name ?? null}
92
109
  visible={modalVisible}
@@ -1,10 +1,15 @@
1
1
  import {Badge, Box, Button, Heading, Icon, Modal, Spinner, Text} from "@terreno/ui";
2
2
  import React, {useCallback, useEffect, useRef, useState} from "react";
3
- import type {AdminApi, BackgroundTask} from "./types";
3
+ import {type AdminApi, type BackgroundTask, resolveAdminBases} from "./types";
4
4
  import {useAdminScripts} from "./useAdminScripts";
5
5
 
6
6
  interface AdminScriptRunModalProps {
7
- baseUrl: string;
7
+ /** @deprecated Use `apiBase`/`routeBase`. Kept as a backward-compatible alias. */
8
+ baseUrl?: string;
9
+ /** Base path where admin API requests are sent. Falls back to `baseUrl`. */
10
+ apiBase?: string;
11
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
12
+ routeBase?: string;
8
13
  api: AdminApi;
9
14
  scriptName: string | null;
10
15
  scriptDescription?: string;
@@ -23,6 +28,8 @@ type Phase = "confirm" | "running" | "done";
23
28
 
24
29
  export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
25
30
  baseUrl,
31
+ apiBase,
32
+ routeBase,
26
33
  api,
27
34
  scriptName,
28
35
  scriptDescription,
@@ -30,6 +37,7 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
30
37
  onDismiss,
31
38
  dryRunOnly = false,
32
39
  }) => {
40
+ const {apiBase: resolvedApiBase} = resolveAdminBases({apiBase, baseUrl, routeBase});
33
41
  const [taskId, setTaskId] = useState<string | null>(null);
34
42
  const [phase, setPhase] = useState<Phase>("confirm");
35
43
  const [isDryRun, setIsDryRun] = useState(false);
@@ -37,7 +45,7 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
37
45
  const startingRef = useRef(false);
38
46
 
39
47
  const {useRunScriptMutation, useGetScriptTaskQuery, useCancelScriptTaskMutation} =
40
- useAdminScripts(api, baseUrl);
48
+ useAdminScripts(api, resolvedApiBase);
41
49
 
42
50
  const [runScript] = useRunScriptMutation();
43
51
  const [cancelTask, {isLoading: isCancelling}] = useCancelScriptTaskMutation();
@@ -1,7 +1,7 @@
1
1
  import {Box, Button, NumberField, Page, Spinner, Text, TextField, useToast} from "@terreno/ui";
2
2
  import {router} from "expo-router";
3
3
  import React, {useCallback, useEffect, useMemo, useState} from "react";
4
- import type {AdminApi, EndpointBuilder} from "./types";
4
+ import {type AdminApi, type EndpointBuilder, resolveAdminBases} from "./types";
5
5
 
6
6
  interface VersionConfigData {
7
7
  mobileRequiredVersion?: number;
@@ -17,12 +17,23 @@ interface VersionConfigData {
17
17
 
18
18
  interface AdminVersionConfigProps {
19
19
  api: AdminApi;
20
- baseUrl: string;
20
+ /** @deprecated Use `apiBase`/`routeBase`. Kept as a backward-compatible alias. */
21
+ baseUrl?: string;
22
+ /** Base path where admin API requests are sent. Falls back to `baseUrl`. */
23
+ apiBase?: string;
24
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
25
+ routeBase?: string;
21
26
  }
22
27
 
23
28
  const VERSION_CONFIG_ENDPOINT = "adminVersionConfig";
24
29
 
25
- export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, baseUrl}) => {
30
+ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({
31
+ api,
32
+ baseUrl,
33
+ apiBase,
34
+ routeBase,
35
+ }) => {
36
+ const {apiBase: resolvedApiBase} = resolveAdminBases({apiBase, baseUrl, routeBase});
26
37
  const [formState, setFormState] = useState<VersionConfigData>({});
27
38
  const [isSaving, setIsSaving] = useState(false);
28
39
  const toast = useToast();
@@ -33,20 +44,20 @@ export const AdminVersionConfig: React.FC<AdminVersionConfigProps> = ({api, base
33
44
  [VERSION_CONFIG_ENDPOINT]: build.query({
34
45
  query: () => ({
35
46
  method: "GET",
36
- url: `${baseUrl}/version-config`,
47
+ url: `${resolvedApiBase}/version-config`,
37
48
  }),
38
49
  }),
39
50
  updateVersionConfig: build.mutation({
40
51
  query: (body: VersionConfigData) => ({
41
52
  body,
42
53
  method: "PUT",
43
- url: `${baseUrl}/version-config`,
54
+ url: `${resolvedApiBase}/version-config`,
44
55
  }),
45
56
  }),
46
57
  }),
47
58
  overrideExisting: true,
48
59
  });
49
- }, [api, baseUrl]);
60
+ }, [api, resolvedApiBase]);
50
61
 
51
62
  // noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
52
63
  // biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
@@ -15,7 +15,7 @@ import {
15
15
  useToast,
16
16
  } from "@terreno/ui";
17
17
  import React, {useCallback, useEffect, useMemo, useState} from "react";
18
- import type {AdminApi, EndpointBuilder} from "./types";
18
+ import {type AdminApi, type EndpointBuilder, resolveAdminBases} from "./types";
19
19
  import {useAdminApi} from "./useAdminApi";
20
20
 
21
21
  interface CheckboxConfig {
@@ -45,7 +45,12 @@ interface ConsentFormDocument {
45
45
  }
46
46
 
47
47
  interface ConsentFormEditorProps {
48
- baseUrl: string;
48
+ /** @deprecated Use `apiBase`/`routeBase`. Kept as a backward-compatible alias. */
49
+ baseUrl?: string;
50
+ /** Base path where admin API requests are sent. Falls back to `baseUrl`. */
51
+ apiBase?: string;
52
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
53
+ routeBase?: string;
49
54
  api: AdminApi;
50
55
  id?: string;
51
56
  supportedLocales?: string[];
@@ -118,6 +123,8 @@ const getEnhancedApi = (api: AdminApi): unknown => {
118
123
 
119
124
  export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
120
125
  baseUrl,
126
+ apiBase,
127
+ routeBase,
121
128
  api,
122
129
  id,
123
130
  supportedLocales = ["en"],
@@ -125,6 +132,7 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
125
132
  onSave,
126
133
  onCancel,
127
134
  }) => {
135
+ const {apiBase: resolvedApiBase} = resolveAdminBases({apiBase, baseUrl, routeBase});
128
136
  const isEditMode = Boolean(id);
129
137
  const toast = useToast();
130
138
 
@@ -167,7 +175,7 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
167
175
  const [generateDescription, setGenerateDescription] = useState("");
168
176
  const [generateType, setGenerateType] = useState(type);
169
177
 
170
- const routePath = `${baseUrl}${CONSENT_FORM_ROUTE}`;
178
+ const routePath = `${resolvedApiBase}${CONSENT_FORM_ROUTE}`;
171
179
 
172
180
  const {useReadQuery, useCreateMutation, useUpdateMutation} = useAdminApi(
173
181
  api,
@@ -12,11 +12,16 @@ import {
12
12
  Text,
13
13
  } from "@terreno/ui";
14
14
  import React, {useCallback, useMemo, useState} from "react";
15
- import type {AdminApi} from "./types";
15
+ import {type AdminApi, resolveAdminBases} from "./types";
16
16
  import {useAdminApi} from "./useAdminApi";
17
17
 
18
18
  interface ConsentFormListProps {
19
- baseUrl: string;
19
+ /** @deprecated Use `apiBase`/`routeBase`. Kept as a backward-compatible alias. */
20
+ baseUrl?: string;
21
+ /** Base path where admin API requests are sent. Falls back to `baseUrl`. */
22
+ apiBase?: string;
23
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
24
+ routeBase?: string;
20
25
  api: AdminApi;
21
26
  onCreateNew?: () => void;
22
27
  onRowClick?: (id: string) => void;
@@ -60,14 +65,17 @@ const buildSortString = (sort: ColumnSortInterface | undefined): string | undefi
60
65
 
61
66
  export const ConsentFormList: React.FC<ConsentFormListProps> = ({
62
67
  baseUrl,
68
+ apiBase,
69
+ routeBase,
63
70
  api,
64
71
  onCreateNew,
65
72
  onRowClick,
66
73
  }) => {
74
+ const {apiBase: resolvedApiBase} = resolveAdminBases({apiBase, baseUrl, routeBase});
67
75
  const [page, setPage] = useState(1);
68
76
  const [sortColumn, setSortColumn] = useState<ColumnSortInterface | undefined>();
69
77
 
70
- const routePath = `${baseUrl}/consent-forms`;
78
+ const routePath = `${resolvedApiBase}/consent-forms`;
71
79
  const {useListQuery} = useAdminApi(api, routePath, "ConsentForm");
72
80
 
73
81
  const sortString = buildSortString(sortColumn) ?? "-created";
@@ -3,11 +3,16 @@ import {DateTime} from "luxon";
3
3
  import React, {useCallback, useState} from "react";
4
4
  import {Image} from "react-native";
5
5
  import {generateConsentPdf} from "./generateConsentPdf";
6
- import type {AdminApi} from "./types";
6
+ import {type AdminApi, resolveAdminBases} from "./types";
7
7
  import {useAdminApi} from "./useAdminApi";
8
8
 
9
9
  interface ConsentResponseViewerProps {
10
- baseUrl: string;
10
+ /** @deprecated Use `apiBase`/`routeBase`. Kept as a backward-compatible alias. */
11
+ baseUrl?: string;
12
+ /** Base path where admin API requests are sent. Falls back to `baseUrl`. */
13
+ apiBase?: string;
14
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
15
+ routeBase?: string;
11
16
  api: AdminApi;
12
17
  id: string;
13
18
  }
@@ -23,8 +28,15 @@ const formatDate = (value: unknown): string => {
23
28
  return dt.toLocaleString(DateTime.DATETIME_FULL);
24
29
  };
25
30
 
26
- export const ConsentResponseViewer: React.FC<ConsentResponseViewerProps> = ({baseUrl, api, id}) => {
27
- const routePath = `${baseUrl}/consent-responses`;
31
+ export const ConsentResponseViewer: React.FC<ConsentResponseViewerProps> = ({
32
+ baseUrl,
33
+ apiBase,
34
+ routeBase,
35
+ api,
36
+ id,
37
+ }) => {
38
+ const {apiBase: resolvedApiBase} = resolveAdminBases({apiBase, baseUrl, routeBase});
39
+ const routePath = `${resolvedApiBase}/consent-responses`;
28
40
  const {useReadQuery} = useAdminApi(api, routePath, "ConsentResponse");
29
41
 
30
42
  const {data: response, isLoading} = useReadQuery(id, {skip: !id});
package/src/index.tsx CHANGED
@@ -30,7 +30,7 @@ export type {
30
30
  RefFieldRendererProps,
31
31
  RefRendererMap,
32
32
  } from "./types";
33
- export {SYSTEM_FIELDS} from "./types";
33
+ export {resolveAdminBases, SYSTEM_FIELDS} from "./types";
34
34
  export {useAdminApi} from "./useAdminApi";
35
35
  export {useAdminConfig} from "./useAdminConfig";
36
36
  export {useAdminScripts} from "./useAdminScripts";
@@ -18,7 +18,7 @@ mock.module("../AdminFieldRendererCore", () => ({
18
18
  React.createElement("AdminFieldRendererCore", {
19
19
  fieldKey,
20
20
  onChange,
21
- testID: `admin-field-renderer-${fieldKey}`,
21
+ testID: `admin-field-${fieldKey}`,
22
22
  }),
23
23
  }));
24
24
 
@@ -229,7 +229,7 @@ describe("AdminNestedArrayField", () => {
229
229
  ]}
230
230
  />
231
231
  );
232
- const nameFields = getAllByTestId("admin-field-renderer-name");
232
+ const nameFields = getAllByTestId("admin-field-name");
233
233
  (nameFields[1] as ReactTestInstance).props.onChange("new name");
234
234
  expect(onChange).toHaveBeenCalled();
235
235
  const next = onChange.mock.calls[0][0];
@@ -3,6 +3,7 @@
3
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
4
4
  import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
5
  import React from "react";
6
+ import type {ReactTestInstance} from "react-test-renderer";
6
7
  import {act, fireEvent} from "../../../ui/node_modules/@testing-library/react-native";
7
8
  import type {AdminApi} from "../types";
8
9
 
@@ -83,6 +84,13 @@ const waitTicks = async (ms = 40): Promise<void> => {
83
84
  });
84
85
  };
85
86
 
87
+ const pressDryRun = async (getByTestId: (id: string) => ReactTestInstance): Promise<void> => {
88
+ await act(async () => {
89
+ fireEvent.press(getByTestId("admin-script-dry-run-button"));
90
+ });
91
+ await waitTicks();
92
+ };
93
+
86
94
  describe("AdminScriptRunModal", () => {
87
95
  beforeEach(() => {
88
96
  runCalls.length = 0;
@@ -106,22 +114,112 @@ describe("AdminScriptRunModal", () => {
106
114
  expect(runCalls.length).toBe(0);
107
115
  });
108
116
 
117
+ it("shows confirm-phase Dry Run, Run, and Cancel buttons when visible", () => {
118
+ const {getByTestId} = renderWithTheme(
119
+ <AdminScriptRunModal
120
+ api={mockApi}
121
+ baseUrl="/admin"
122
+ onDismiss={() => undefined}
123
+ scriptName="my-script"
124
+ visible
125
+ />
126
+ );
127
+
128
+ expect(getByTestId("admin-script-dry-run-button")).toBeTruthy();
129
+ expect(getByTestId("admin-script-wet-run-button")).toBeTruthy();
130
+ expect(getByTestId("admin-script-confirm-cancel-button")).toBeTruthy();
131
+ expect(runCalls.length).toBe(0);
132
+ });
133
+
134
+ it("calls onDismiss from confirm Cancel without starting a run", async () => {
135
+ const onDismiss = mock(() => undefined);
136
+
137
+ const {getByTestId} = renderWithTheme(
138
+ <AdminScriptRunModal
139
+ api={mockApi}
140
+ baseUrl="/admin"
141
+ onDismiss={onDismiss}
142
+ scriptName="my-script"
143
+ visible
144
+ />
145
+ );
146
+
147
+ await act(async () => {
148
+ fireEvent.press(getByTestId("admin-script-confirm-cancel-button"));
149
+ });
150
+
151
+ expect(onDismiss).toHaveBeenCalled();
152
+ expect(runCalls.length).toBe(0);
153
+ });
154
+
155
+ it("starts a dry run when Dry Run is pressed", async () => {
156
+ const {getByTestId} = renderWithTheme(
157
+ <AdminScriptRunModal
158
+ api={mockApi}
159
+ baseUrl="/admin"
160
+ onDismiss={() => undefined}
161
+ scriptName="my-script"
162
+ visible
163
+ />
164
+ );
165
+
166
+ await pressDryRun(getByTestId);
167
+
168
+ expect(runCalls.length).toBe(1);
169
+ expect(runCalls[0]).toEqual({name: "my-script", wetRun: false});
170
+ });
171
+
109
172
  it("starts a wet run when the Run button is pressed", async () => {
110
173
  const {getByTestId} = renderWithTheme(
111
174
  <AdminScriptRunModal
112
175
  api={mockApi}
113
176
  baseUrl="/admin"
114
- onDismiss={() => {}}
115
- scriptName="test-script"
116
- visible={true}
177
+ onDismiss={() => undefined}
178
+ scriptName="my-script"
179
+ visible
117
180
  />
118
181
  );
182
+
119
183
  await act(async () => {
120
184
  fireEvent.press(getByTestId("admin-script-wet-run-button"));
121
185
  });
122
186
  await waitTicks();
187
+
123
188
  expect(runCalls.length).toBe(1);
124
- expect(runCalls[0]).toEqual({name: "test-script", wetRun: true});
189
+ expect(runCalls[0]).toEqual({name: "my-script", wetRun: true});
190
+ });
191
+
192
+ it("hides the wet-run button when dryRunOnly is true", () => {
193
+ const {getByTestId, queryByTestId} = renderWithTheme(
194
+ <AdminScriptRunModal
195
+ api={mockApi}
196
+ baseUrl="/admin"
197
+ dryRunOnly
198
+ onDismiss={() => undefined}
199
+ scriptName="my-script"
200
+ visible
201
+ />
202
+ );
203
+
204
+ expect(getByTestId("admin-script-dry-run-button")).toBeTruthy();
205
+ expect(getByTestId("admin-script-confirm-cancel-button")).toBeTruthy();
206
+ expect(queryByTestId("admin-script-wet-run-button")).toBeNull();
207
+ });
208
+
209
+ it("renders the script description in the confirm phase", () => {
210
+ const {getByText} = renderWithTheme(
211
+ <AdminScriptRunModal
212
+ api={mockApi}
213
+ baseUrl="/admin"
214
+ onDismiss={() => undefined}
215
+ scriptDescription="Migrates legacy records"
216
+ scriptName="migrate-data"
217
+ visible
218
+ />
219
+ );
220
+
221
+ expect(getByText("Migrates legacy records")).toBeTruthy();
222
+ expect(getByText("migrate-data")).toBeTruthy();
125
223
  });
126
224
 
127
225
  it("renders running phase with progress details", async () => {
@@ -263,10 +361,7 @@ describe("AdminScriptRunModal", () => {
263
361
  visible={true}
264
362
  />
265
363
  );
266
- await act(async () => {
267
- fireEvent.press(getByTestId("admin-script-dry-run-button"));
268
- });
269
- await waitTicks();
364
+ await pressDryRun(getByTestId);
270
365
  await act(async () => {
271
366
  fireEvent.press(getByTestId("admin-script-cancel-button"));
272
367
  await new Promise((r) => setTimeout(r, 20));
@@ -290,10 +385,7 @@ describe("AdminScriptRunModal", () => {
290
385
  visible={true}
291
386
  />
292
387
  );
293
- await act(async () => {
294
- fireEvent.press(getByTestId("admin-script-dry-run-button"));
295
- });
296
- await waitTicks();
388
+ await pressDryRun(getByTestId);
297
389
  await act(async () => {
298
390
  fireEvent.press(getByTestId("admin-script-cancel-button"));
299
391
  await new Promise((r) => setTimeout(r, 20));
@@ -314,10 +406,7 @@ describe("AdminScriptRunModal", () => {
314
406
  visible={true}
315
407
  />
316
408
  );
317
- await act(async () => {
318
- fireEvent.press(getByTestId("admin-script-dry-run-button"));
319
- });
320
- await waitTicks(200);
409
+ await pressDryRun(getByTestId);
321
410
  expect(runCalls.length).toBe(1);
322
411
  });
323
412
 
@@ -334,10 +423,7 @@ describe("AdminScriptRunModal", () => {
334
423
  visible={true}
335
424
  />
336
425
  );
337
- await act(async () => {
338
- fireEvent.press(getByTestId("admin-script-dry-run-button"));
339
- });
340
- await waitTicks(200);
426
+ await pressDryRun(getByTestId);
341
427
  expect(runCalls.length).toBe(1);
342
428
  });
343
429
 
@@ -354,10 +440,7 @@ describe("AdminScriptRunModal", () => {
354
440
  visible={true}
355
441
  />
356
442
  );
357
- await act(async () => {
358
- fireEvent.press(getByTestId("admin-script-dry-run-button"));
359
- });
360
- await waitTicks(200);
443
+ await pressDryRun(getByTestId);
361
444
  expect(runCalls.length).toBe(1);
362
445
  });
363
446
 
@@ -403,10 +486,7 @@ describe("AdminScriptRunModal", () => {
403
486
  visible={true}
404
487
  />
405
488
  );
406
- await act(async () => {
407
- fireEvent.press(getByTestId("admin-script-dry-run-button"));
408
- });
409
- await waitTicks();
489
+ await pressDryRun(getByTestId);
410
490
  await act(async () => {
411
491
  fireEvent.press(getByTestId("admin-script-cancel-button"));
412
492
  });
package/src/types.ts CHANGED
@@ -106,18 +106,64 @@ export interface BackgroundTask {
106
106
  updated: string;
107
107
  }
108
108
 
109
+ /**
110
+ * Common props for admin screens.
111
+ *
112
+ * The admin panel separates two distinct concepts:
113
+ * - `apiBase`: the base path where JSON/API requests are sent (e.g. "/admin").
114
+ * - `routeBase`: the base path used for in-app navigation (e.g. "/admin" when mounted
115
+ * inside an app, or "" for a standalone admin SPA whose navigation stays at its root).
116
+ *
117
+ * `baseUrl` is a backward-compatible alias: when only `baseUrl` is provided it is used
118
+ * for BOTH the API base and the route base, preserving the original behavior. When
119
+ * `apiBase`/`routeBase` are provided they take precedence over `baseUrl`. Use
120
+ * {@link resolveAdminBases} to resolve the effective bases.
121
+ */
109
122
  export interface AdminScreenProps {
110
- baseUrl: string;
123
+ /** @deprecated Use `apiBase` and `routeBase`. Kept as a backward-compatible alias. */
124
+ baseUrl?: string;
125
+ /** Base path where JSON/API requests are sent. Falls back to `baseUrl`. */
126
+ apiBase?: string;
127
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
128
+ routeBase?: string;
111
129
  api: AdminApi;
112
130
  }
113
131
 
132
+ /**
133
+ * Resolves the effective API and route bases from the (optional) `baseUrl`, `apiBase`,
134
+ * and `routeBase` props. When only `baseUrl` is provided, both resolved bases equal it,
135
+ * preserving the original single-prop behavior.
136
+ */
137
+ export const resolveAdminBases = ({
138
+ baseUrl,
139
+ apiBase,
140
+ routeBase,
141
+ }: {
142
+ baseUrl?: string;
143
+ apiBase?: string;
144
+ routeBase?: string;
145
+ }): {apiBase: string; routeBase: string} => {
146
+ return {
147
+ apiBase: apiBase ?? baseUrl ?? "",
148
+ routeBase: routeBase ?? baseUrl ?? "",
149
+ };
150
+ };
151
+
114
152
  /**
115
153
  * Props passed to a custom ref-field renderer. Matches AdminRefField's interface so a
116
154
  * custom renderer is a drop-in replacement.
155
+ *
156
+ * `routePath` is the API path used to fetch reference options (e.g. "/admin/users").
157
+ * `routeBase` is the base path for in-app navigation to the referenced item.
117
158
  */
118
159
  export interface RefFieldRendererProps {
119
160
  api: AdminApi;
120
- baseUrl: string;
161
+ /** @deprecated Use `apiBase`/`routeBase`. Kept as a backward-compatible alias. */
162
+ baseUrl?: string;
163
+ /** Base path where JSON/API requests are sent. Falls back to `baseUrl`. */
164
+ apiBase?: string;
165
+ /** Base path used for in-app navigation. Falls back to `baseUrl`. */
166
+ routeBase?: string;
121
167
  routePath: string;
122
168
  refModelName: string;
123
169
  title: string;
@@ -11,7 +11,7 @@ const ENDPOINT_NAME = "adminConfig";
11
11
  * field types, required fields, references, and display settings.
12
12
  *
13
13
  * @param api - RTK Query API instance to inject the endpoint into
14
- * @param baseUrl - Base URL for admin routes (e.g., "/admin")
14
+ * @param apiBase - Base URL where admin API requests are sent (e.g., "/admin")
15
15
  * @returns Object with `config` (model metadata), `isLoading`, and `error`
16
16
  *
17
17
  * @example
@@ -32,20 +32,20 @@ const ENDPOINT_NAME = "adminConfig";
32
32
  * @see AdminConfigResponse for the returned configuration structure
33
33
  * @see AdminModelList for usage in the model list screen
34
34
  */
35
- export const useAdminConfig = (api: AdminApi, baseUrl: string) => {
35
+ export const useAdminConfig = (api: AdminApi, apiBase: string) => {
36
36
  const enhancedApi = useMemo(() => {
37
37
  return api.injectEndpoints({
38
38
  endpoints: (build: EndpointBuilder) => ({
39
39
  [ENDPOINT_NAME]: build.query({
40
40
  query: () => ({
41
41
  method: "GET",
42
- url: `${baseUrl}/config`,
42
+ url: `${apiBase}/config`,
43
43
  }),
44
44
  }),
45
45
  }),
46
46
  overrideExisting: true,
47
47
  });
48
- }, [api, baseUrl]);
48
+ }, [api, apiBase]);
49
49
 
50
50
  // noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
51
51
  // biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API