@terreno/admin-frontend 0.16.0 → 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.
- 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 +41 -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/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
|
-
});
|