@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
@@ -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, baseUrl: string) => {
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: `${baseUrl}/scripts/tasks/${taskId}`,
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: `${baseUrl}/scripts/tasks/${taskId}`,
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: `${baseUrl}/scripts/${name}/run?wetRun=${wetRun}`,
25
+ url: `${apiBase}/scripts/${name}/run?wetRun=${wetRun}`,
26
26
  }),
27
27
  }),
28
28
  }),
29
29
  overrideExisting: true,
30
30
  });
31
- }, [api, baseUrl]);
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
- });