@terreno/admin-frontend 0.16.1 → 0.18.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.js +3 -3
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.js +4 -4
- package/dist/AdminFieldRendererCore.js.map +1 -1
- package/dist/AdminModelForm.d.ts +6 -1
- package/dist/AdminModelForm.js +9 -4
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +7 -2
- package/dist/AdminModelList.js +10 -4
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +7 -2
- package/dist/AdminModelTable.js +14 -6
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +6 -1
- package/dist/AdminNestedArrayField.js +8 -4
- package/dist/AdminNestedArrayField.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +6 -1
- package/dist/AdminPrimitiveArrayField.js +3 -3
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminScriptList.d.ts +7 -2
- package/dist/AdminScriptList.js +9 -3
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +7 -2
- package/dist/AdminScriptRunModal.js +4 -2
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/dist/AdminVersionConfig.d.ts +7 -2
- package/dist/AdminVersionConfig.js +6 -4
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConsentFormEditor.d.ts +7 -2
- package/dist/ConsentFormEditor.js +4 -2
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/ConsentFormList.d.ts +7 -2
- package/dist/ConsentFormList.js +4 -2
- package/dist/ConsentFormList.js.map +1 -1
- package/dist/ConsentResponseViewer.d.ts +7 -2
- package/dist/ConsentResponseViewer.js +4 -2
- package/dist/ConsentResponseViewer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +41 -2
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -1
- package/dist/useAdminConfig.d.ts +2 -2
- package/dist/useAdminConfig.js +4 -4
- package/dist/useAdminScripts.d.ts +1 -1
- package/dist/useAdminScripts.js +5 -5
- package/package.json +2 -2
- package/src/AdminFieldRenderer.tsx +6 -0
- package/src/AdminFieldRendererCore.tsx +8 -0
- package/src/AdminModelForm.tsx +17 -4
- package/src/AdminModelList.test.tsx +69 -5
- package/src/AdminModelList.tsx +22 -5
- package/src/AdminModelTable.test.tsx +58 -5
- package/src/AdminModelTable.tsx +27 -7
- package/src/AdminNestedArrayField.tsx +21 -2
- package/src/AdminPrimitiveArrayField.tsx +12 -1
- package/src/AdminScriptList.tsx +22 -5
- package/src/AdminScriptRunModal.tsx +11 -3
- package/src/AdminVersionConfig.tsx +17 -6
- package/src/ConsentFormEditor.tsx +11 -3
- package/src/ConsentFormList.tsx +11 -3
- package/src/ConsentResponseViewer.tsx +16 -4
- package/src/index.tsx +1 -1
- package/src/isolated/AdminNestedArrayField.isolated.tsx +2 -2
- package/src/isolated/AdminScriptRunModal.isolated.tsx +108 -28
- package/src/types.ts +48 -2
- package/src/useAdminConfig.ts +4 -4
- package/src/useAdminScripts.ts +5 -5
- package/src/AdminScriptRunModal.test.tsx +0 -132
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
|
-
|
|
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
|
-
|
|
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;
|
package/src/useAdminConfig.ts
CHANGED
|
@@ -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
|
|
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,
|
|
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: `${
|
|
42
|
+
url: `${apiBase}/config`,
|
|
43
43
|
}),
|
|
44
44
|
}),
|
|
45
45
|
}),
|
|
46
46
|
overrideExisting: true,
|
|
47
47
|
});
|
|
48
|
-
}, [api,
|
|
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
|
package/src/useAdminScripts.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useMemo} from "react";
|
|
2
2
|
import type {AdminApi, BackgroundTask, EndpointBuilder} from "./types";
|
|
3
3
|
|
|
4
|
-
export const useAdminScripts = (api: AdminApi,
|
|
4
|
+
export const useAdminScripts = (api: AdminApi, apiBase: string) => {
|
|
5
5
|
const enhancedApi = useMemo(() => {
|
|
6
6
|
return api.injectEndpoints({
|
|
7
7
|
endpoints: (build: EndpointBuilder) => ({
|
|
@@ -9,26 +9,26 @@ export const useAdminScripts = (api: AdminApi, baseUrl: string) => {
|
|
|
9
9
|
invalidatesTags: ["admin_scriptTask"],
|
|
10
10
|
query: (taskId: string) => ({
|
|
11
11
|
method: "DELETE",
|
|
12
|
-
url: `${
|
|
12
|
+
url: `${apiBase}/scripts/tasks/${taskId}`,
|
|
13
13
|
}),
|
|
14
14
|
}),
|
|
15
15
|
adminGetScriptTask: build.query({
|
|
16
16
|
providesTags: ["admin_scriptTask"],
|
|
17
17
|
query: (taskId: string) => ({
|
|
18
18
|
method: "GET",
|
|
19
|
-
url: `${
|
|
19
|
+
url: `${apiBase}/scripts/tasks/${taskId}`,
|
|
20
20
|
}),
|
|
21
21
|
}),
|
|
22
22
|
adminRunScript: build.mutation({
|
|
23
23
|
query: ({name, wetRun}: {name: string; wetRun: boolean}) => ({
|
|
24
24
|
method: "POST",
|
|
25
|
-
url: `${
|
|
25
|
+
url: `${apiBase}/scripts/${name}/run?wetRun=${wetRun}`,
|
|
26
26
|
}),
|
|
27
27
|
}),
|
|
28
28
|
}),
|
|
29
29
|
overrideExisting: true,
|
|
30
30
|
});
|
|
31
|
-
}, [api,
|
|
31
|
+
}, [api, apiBase]);
|
|
32
32
|
|
|
33
33
|
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
34
34
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// noExplicitAny: test mocks use type-erased RTK Query API doubles and dynamic mock returns
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
|
-
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
4
|
-
import * as terrenoUi from "@terreno/ui";
|
|
5
|
-
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
6
|
-
import React from "react";
|
|
7
|
-
import {act, fireEvent} from "../../ui/node_modules/@testing-library/react-native";
|
|
8
|
-
import {AdminScriptRunModal} from "./AdminScriptRunModal";
|
|
9
|
-
import type {AdminApi} from "./types";
|
|
10
|
-
|
|
11
|
-
// Render Modal children inline so we can interact with them in tests
|
|
12
|
-
mock.module("@terreno/ui", () => ({
|
|
13
|
-
...terrenoUi,
|
|
14
|
-
Modal: ({children, visible}: {children?: React.ReactNode; visible?: boolean}) =>
|
|
15
|
-
visible ? children : null,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
const mockRunScript = mock((_args: {name: string; wetRun: boolean}) => ({
|
|
19
|
-
unwrap: async () => ({taskId: "task-123"}),
|
|
20
|
-
}));
|
|
21
|
-
const mockCancelTask = mock((_taskId: string) => ({
|
|
22
|
-
unwrap: async () => ({}),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
const mockUseAdminScripts = mock(() => ({
|
|
26
|
-
useCancelScriptTaskMutation: () => [mockCancelTask, {isLoading: false}],
|
|
27
|
-
useGetScriptTaskQuery: () => ({data: undefined, error: null, isLoading: false}),
|
|
28
|
-
useRunScriptMutation: () => [mockRunScript, {isLoading: false}],
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
mock.module("./useAdminScripts", () => ({
|
|
32
|
-
useAdminScripts: (...args: unknown[]) => mockUseAdminScripts(...args),
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
const mockApi = {} as unknown as AdminApi;
|
|
36
|
-
|
|
37
|
-
describe("AdminScriptRunModal", () => {
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
mockRunScript.mockClear();
|
|
40
|
-
mockCancelTask.mockClear();
|
|
41
|
-
mockUseAdminScripts.mockClear();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("renders Dry Run, Run, and Cancel buttons in confirm phase", () => {
|
|
45
|
-
const {getByTestId} = renderWithTheme(
|
|
46
|
-
<AdminScriptRunModal
|
|
47
|
-
api={mockApi}
|
|
48
|
-
baseUrl="/admin"
|
|
49
|
-
onDismiss={() => undefined}
|
|
50
|
-
scriptName="my-script"
|
|
51
|
-
visible
|
|
52
|
-
/>
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
expect(getByTestId("admin-script-dry-run-button")).toBeTruthy();
|
|
56
|
-
expect(getByTestId("admin-script-wet-run-button")).toBeTruthy();
|
|
57
|
-
expect(getByTestId("admin-script-confirm-cancel-button")).toBeTruthy();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("calls onDismiss when Cancel is pressed without invoking runScript", async () => {
|
|
61
|
-
const onDismiss = mock(() => undefined);
|
|
62
|
-
|
|
63
|
-
const {getByTestId} = renderWithTheme(
|
|
64
|
-
<AdminScriptRunModal
|
|
65
|
-
api={mockApi}
|
|
66
|
-
baseUrl="/admin"
|
|
67
|
-
onDismiss={onDismiss}
|
|
68
|
-
scriptName="my-script"
|
|
69
|
-
visible
|
|
70
|
-
/>
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
await act(async () => {
|
|
74
|
-
fireEvent.press(getByTestId("admin-script-confirm-cancel-button"));
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
expect(onDismiss).toHaveBeenCalled();
|
|
78
|
-
expect(mockRunScript).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("dispatches a dry run when the Dry Run button is pressed", async () => {
|
|
82
|
-
const {getByTestId} = renderWithTheme(
|
|
83
|
-
<AdminScriptRunModal
|
|
84
|
-
api={mockApi}
|
|
85
|
-
baseUrl="/admin"
|
|
86
|
-
onDismiss={() => undefined}
|
|
87
|
-
scriptName="my-script"
|
|
88
|
-
visible
|
|
89
|
-
/>
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
await act(async () => {
|
|
93
|
-
fireEvent.press(getByTestId("admin-script-dry-run-button"));
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
expect(mockRunScript).toHaveBeenCalledTimes(1);
|
|
97
|
-
expect(mockRunScript.mock.calls[0]?.[0]).toEqual({name: "my-script", wetRun: false});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("hides the wet-run button when dryRunOnly is true", () => {
|
|
101
|
-
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
102
|
-
<AdminScriptRunModal
|
|
103
|
-
api={mockApi}
|
|
104
|
-
baseUrl="/admin"
|
|
105
|
-
dryRunOnly
|
|
106
|
-
onDismiss={() => undefined}
|
|
107
|
-
scriptName="my-script"
|
|
108
|
-
visible
|
|
109
|
-
/>
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
expect(getByTestId("admin-script-dry-run-button")).toBeTruthy();
|
|
113
|
-
expect(getByTestId("admin-script-confirm-cancel-button")).toBeTruthy();
|
|
114
|
-
expect(queryByTestId("admin-script-wet-run-button")).toBeNull();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("renders the script description in the confirm phase", () => {
|
|
118
|
-
const {getByText} = renderWithTheme(
|
|
119
|
-
<AdminScriptRunModal
|
|
120
|
-
api={mockApi}
|
|
121
|
-
baseUrl="/admin"
|
|
122
|
-
onDismiss={() => undefined}
|
|
123
|
-
scriptDescription="Migrates legacy records"
|
|
124
|
-
scriptName="migrate-data"
|
|
125
|
-
visible
|
|
126
|
-
/>
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
expect(getByText("Migrates legacy records")).toBeTruthy();
|
|
130
|
-
expect(getByText("migrate-data")).toBeTruthy();
|
|
131
|
-
});
|
|
132
|
-
});
|