@terreno/admin-frontend 0.11.7 → 0.11.9
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/AdminScriptList.js +1 -1
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +3 -0
- package/dist/AdminScriptRunModal.js +42 -34
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/package.json +2 -2
- package/src/AdminScriptList.tsx +1 -0
- package/src/AdminScriptRunModal.test.tsx +129 -0
- package/src/AdminScriptRunModal.tsx +91 -33
package/dist/AdminScriptList.js
CHANGED
|
@@ -26,6 +26,6 @@ export const AdminScriptList = ({ baseUrl, api, isAdmin = true }) => {
|
|
|
26
26
|
if (scripts.length === 0) {
|
|
27
27
|
return (_jsx(Page, { maxWidth: "100%", title: "Scripts", children: _jsx(Box, { alignItems: "center", padding: 6, children: _jsx(Text, { color: "secondaryDark", children: "No scripts registered." }) }) }));
|
|
28
28
|
}
|
|
29
|
-
return (_jsxs(Page, { maxWidth: "100%", scroll: true, title: "Scripts", children: [_jsx(Box, { gap: 3, padding: 4, children: scripts.map((script) => (_jsx(Card, { padding: 4, testID: `admin-script-card-${script.name}`, children: _jsxs(Box, { alignItems: "center", direction: "row", gap: 4, justifyContent: "between", children: [_jsxs(Box, { flex: "grow", gap: 1, children: [_jsx(Heading, { size: "sm", children: script.name }), _jsx(Text, { color: "secondaryDark", size: "sm", children: script.description })] }), _jsx(Button, { disabled: !isAdmin, onClick: () => handleRunScript(script), testID: `admin-script-run-${script.name}`, text: "Run", tooltipText: !isAdmin ? "Only admins can run scripts" : undefined, variant: "primary" })] }) }, script.name))) }), _jsx(AdminScriptRunModal, { api: api, baseUrl: baseUrl, onDismiss: handleDismiss, scriptName: (_b = selectedScript === null || selectedScript === void 0 ? void 0 : selectedScript.name) !== null && _b !== void 0 ? _b : null, visible: modalVisible })] }));
|
|
29
|
+
return (_jsxs(Page, { maxWidth: "100%", scroll: true, title: "Scripts", children: [_jsx(Box, { gap: 3, padding: 4, children: scripts.map((script) => (_jsx(Card, { padding: 4, testID: `admin-script-card-${script.name}`, children: _jsxs(Box, { alignItems: "center", direction: "row", gap: 4, justifyContent: "between", children: [_jsxs(Box, { flex: "grow", gap: 1, children: [_jsx(Heading, { size: "sm", children: script.name }), _jsx(Text, { color: "secondaryDark", size: "sm", children: script.description })] }), _jsx(Button, { disabled: !isAdmin, onClick: () => handleRunScript(script), testID: `admin-script-run-${script.name}`, text: "Run", tooltipText: !isAdmin ? "Only admins can run scripts" : undefined, variant: "primary" })] }) }, script.name))) }), _jsx(AdminScriptRunModal, { api: api, baseUrl: baseUrl, onDismiss: handleDismiss, scriptDescription: selectedScript === null || selectedScript === void 0 ? void 0 : selectedScript.description, scriptName: (_b = selectedScript === null || selectedScript === void 0 ? void 0 : selectedScript.name) !== null && _b !== void 0 ? _b : null, visible: modalVisible })] }));
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=AdminScriptList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdminScriptList.js","sourceRoot":"","sources":["../src/AdminScriptList.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,aAAa,CAAC;AAC5E,OAAc,EAAC,WAAW,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACnD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAShD,MAAM,CAAC,MAAM,eAAe,GAAmC,CAAC,EAAC,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,EAAC,EAAE,EAAE;;IAChG,MAAM,EAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAC,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAChE,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,EAAE,CAAC,EAAE,cAAc,EAAC,SAAS,aACvE,MAAC,GAAG,IAAC,IAAI,EAAC,MAAM,EAAC,GAAG,EAAE,CAAC,aACrB,KAAC,OAAO,IAAC,IAAI,EAAC,IAAI,YAAE,MAAM,CAAC,IAAI,GAAW,EAC1C,KAAC,IAAI,IAAC,KAAK,EAAC,eAAe,EAAC,IAAI,EAAC,IAAI,YAClC,MAAM,CAAC,WAAW,GACd,IACH,EACN,KAAC,MAAM,IACL,QAAQ,EAAE,CAAC,OAAO,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,EACtC,MAAM,EAAE,oBAAoB,MAAM,CAAC,IAAI,EAAE,EACzC,IAAI,EAAC,KAAK,EACV,WAAW,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,SAAS,EACjE,OAAO,EAAC,SAAS,GACjB,IACE,IAhBG,MAAM,CAAC,IAAI,CAiBf,CACR,CAAC,GACE,EAEN,KAAC,mBAAmB,IAClB,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,aAAa,EACxB,iBAAiB,EAAE,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,WAAW,EAC9C,UAAU,EAAE,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,mCAAI,IAAI,EACxC,OAAO,EAAE,YAAY,GACrB,IACG,CACR,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -4,8 +4,11 @@ interface AdminScriptRunModalProps {
|
|
|
4
4
|
baseUrl: string;
|
|
5
5
|
api: Api<any, any, any, any>;
|
|
6
6
|
scriptName: string | null;
|
|
7
|
+
scriptDescription?: string;
|
|
7
8
|
visible: boolean;
|
|
8
9
|
onDismiss: () => void;
|
|
10
|
+
/** When true, skip the confirmation step and only allow a dry run. */
|
|
11
|
+
dryRunOnly?: boolean;
|
|
9
12
|
}
|
|
10
13
|
export declare const AdminScriptRunModal: React.FC<AdminScriptRunModalProps>;
|
|
11
14
|
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Box, Button, Heading, Icon, Modal, Spinner, Text } from "@terreno/ui";
|
|
2
|
+
import { Badge, Box, Button, Heading, Icon, Modal, Spinner, Text } from "@terreno/ui";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { useAdminScripts } from "./useAdminScripts";
|
|
5
5
|
const POLL_INTERVAL_MS = 2000;
|
|
6
6
|
const isTerminalStatus = (status) => status === "completed" || status === "failed" || status === "cancelled";
|
|
7
|
-
export const AdminScriptRunModal = ({ baseUrl, api, scriptName, visible, onDismiss, }) => {
|
|
7
|
+
export const AdminScriptRunModal = ({ baseUrl, api, scriptName, scriptDescription, visible, onDismiss, dryRunOnly = false, }) => {
|
|
8
8
|
const [taskId, setTaskId] = useState(null);
|
|
9
|
-
const [phase, setPhase] = useState("
|
|
9
|
+
const [phase, setPhase] = useState("confirm");
|
|
10
|
+
const [isDryRun, setIsDryRun] = useState(false);
|
|
10
11
|
const [startError, setStartError] = useState(null);
|
|
11
|
-
const
|
|
12
|
+
const startingRef = useRef(false);
|
|
12
13
|
const { useRunScriptMutation, useGetScriptTaskQuery, useCancelScriptTaskMutation } = useAdminScripts(api, baseUrl);
|
|
13
14
|
const [runScript] = useRunScriptMutation();
|
|
14
15
|
const [cancelTask, { isLoading: isCancelling }] = useCancelScriptTaskMutation();
|
|
@@ -18,34 +19,14 @@ export const AdminScriptRunModal = ({ baseUrl, api, scriptName, visible, onDismi
|
|
|
18
19
|
skip: !taskId,
|
|
19
20
|
});
|
|
20
21
|
const task = taskData === null || taskData === void 0 ? void 0 : taskData.task;
|
|
21
|
-
//
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
if (!visible || !scriptName || hasStartedRef.current) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
hasStartedRef.current = true;
|
|
27
|
-
setTaskId(null);
|
|
28
|
-
setPhase("running");
|
|
29
|
-
setStartError(null);
|
|
30
|
-
void (async () => {
|
|
31
|
-
var _a, _b;
|
|
32
|
-
try {
|
|
33
|
-
const result = await runScript({ name: scriptName, wetRun: true }).unwrap();
|
|
34
|
-
setTaskId(result.taskId);
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
const errData = err === null || err === void 0 ? void 0 : err.data;
|
|
38
|
-
const message = (_b = (_a = errData === null || errData === void 0 ? void 0 : errData.detail) !== null && _a !== void 0 ? _a : errData === null || errData === void 0 ? void 0 : errData.title) !== null && _b !== void 0 ? _b : "Failed to start script";
|
|
39
|
-
setStartError(message);
|
|
40
|
-
setPhase("done");
|
|
41
|
-
hasStartedRef.current = false;
|
|
42
|
-
}
|
|
43
|
-
})();
|
|
44
|
-
}, [visible, scriptName, runScript]);
|
|
45
|
-
// Reset when modal closes
|
|
22
|
+
// Reset modal state whenever it becomes hidden
|
|
46
23
|
useEffect(() => {
|
|
47
24
|
if (!visible) {
|
|
48
|
-
|
|
25
|
+
setTaskId(null);
|
|
26
|
+
setPhase("confirm");
|
|
27
|
+
setIsDryRun(false);
|
|
28
|
+
setStartError(null);
|
|
29
|
+
startingRef.current = false;
|
|
49
30
|
}
|
|
50
31
|
}, [visible]);
|
|
51
32
|
// Transition to done when task reaches terminal status
|
|
@@ -54,7 +35,31 @@ export const AdminScriptRunModal = ({ baseUrl, api, scriptName, visible, onDismi
|
|
|
54
35
|
setPhase("done");
|
|
55
36
|
}
|
|
56
37
|
}, [task === null || task === void 0 ? void 0 : task.status]);
|
|
57
|
-
const
|
|
38
|
+
const startRun = useCallback(async (wetRun) => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
if (!scriptName || startingRef.current) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
startingRef.current = true;
|
|
44
|
+
setIsDryRun(!wetRun);
|
|
45
|
+
setTaskId(null);
|
|
46
|
+
setStartError(null);
|
|
47
|
+
setPhase("running");
|
|
48
|
+
try {
|
|
49
|
+
const result = await runScript({ name: scriptName, wetRun }).unwrap();
|
|
50
|
+
setTaskId(result.taskId);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const errData = err === null || err === void 0 ? void 0 : err.data;
|
|
54
|
+
const message = (_b = (_a = errData === null || errData === void 0 ? void 0 : errData.detail) !== null && _a !== void 0 ? _a : errData === null || errData === void 0 ? void 0 : errData.title) !== null && _b !== void 0 ? _b : "Failed to start script";
|
|
55
|
+
setStartError(message);
|
|
56
|
+
setPhase("done");
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
startingRef.current = false;
|
|
60
|
+
}
|
|
61
|
+
}, [scriptName, runScript]);
|
|
62
|
+
const handleCancelTask = useCallback(async () => {
|
|
58
63
|
if (!taskId) {
|
|
59
64
|
return;
|
|
60
65
|
}
|
|
@@ -65,9 +70,12 @@ export const AdminScriptRunModal = ({ baseUrl, api, scriptName, visible, onDismi
|
|
|
65
70
|
// Cancellation failed, task may already be done
|
|
66
71
|
}
|
|
67
72
|
}, [taskId, cancelTask]);
|
|
73
|
+
const renderConfirm = () => (_jsxs(Box, { gap: 4, paddingY: 4, children: [_jsx(Heading, { align: "center", size: "md", children: scriptName }), scriptDescription && (_jsx(Text, { align: "center", color: "secondaryDark", children: scriptDescription })), _jsx(Text, { align: "center", size: "sm", children: dryRunOnly
|
|
74
|
+
? "Dry runs simulate the script without persisting any changes."
|
|
75
|
+
: "Run a dry run first to preview changes, or run the script for real." }), _jsxs(Box, { direction: "row", gap: 2, justifyContent: "center", wrap: true, children: [_jsx(Button, { onClick: () => startRun(false), testID: "admin-script-dry-run-button", text: "Dry Run", variant: dryRunOnly ? "primary" : "secondary" }), !dryRunOnly && (_jsx(Button, { confirmationText: `Run "${scriptName}" for real? This will persist changes.`, onClick: () => startRun(true), testID: "admin-script-wet-run-button", text: "Run", variant: "primary", withConfirmation: true })), _jsx(Button, { onClick: onDismiss, testID: "admin-script-confirm-cancel-button", text: "Cancel", variant: "muted" })] })] }));
|
|
68
76
|
const renderRunning = () => {
|
|
69
77
|
var _a, _b, _c;
|
|
70
|
-
return (_jsxs(Box, { alignItems: "center", gap: 4, paddingY: 4, children: [_jsx(Heading, { align: "center", size: "md", children: scriptName }), _jsx(Spinner, { size: "md" }), ((_a = task === null || task === void 0 ? void 0 : task.progress) === null || _a === void 0 ? void 0 : _a.message) && _jsx(Text, { align: "center", children: task.progress.message }), ((_b = task === null || task === void 0 ? void 0 : task.progress) === null || _b === void 0 ? void 0 : _b.stage) && (_jsx(Text, { align: "center", color: "secondaryDark", size: "sm", children: task.progress.stage })), ((_c = task === null || task === void 0 ? void 0 : task.progress) === null || _c === void 0 ? void 0 : _c.percentage) !== undefined && task.progress.percentage > 0 && (_jsxs(Text, { align: "center", color: "secondaryDark", size: "sm", children: [task.progress.percentage, "%"] })), _jsx(Button, { disabled: isCancelling, loading: isCancelling, onClick:
|
|
78
|
+
return (_jsxs(Box, { alignItems: "center", gap: 4, paddingY: 4, children: [_jsx(Heading, { align: "center", size: "md", children: scriptName }), _jsx(Badge, { status: isDryRun ? "info" : "warning", value: isDryRun ? "Dry Run" : "Live Run" }), _jsx(Spinner, { size: "md" }), ((_a = task === null || task === void 0 ? void 0 : task.progress) === null || _a === void 0 ? void 0 : _a.message) && _jsx(Text, { align: "center", children: task.progress.message }), ((_b = task === null || task === void 0 ? void 0 : task.progress) === null || _b === void 0 ? void 0 : _b.stage) && (_jsx(Text, { align: "center", color: "secondaryDark", size: "sm", children: task.progress.stage })), ((_c = task === null || task === void 0 ? void 0 : task.progress) === null || _c === void 0 ? void 0 : _c.percentage) !== undefined && task.progress.percentage > 0 && (_jsxs(Text, { align: "center", color: "secondaryDark", size: "sm", children: [task.progress.percentage, "%"] })), _jsx(Button, { disabled: isCancelling || !taskId, loading: isCancelling, onClick: handleCancelTask, testID: "admin-script-cancel-button", text: "Cancel", variant: "destructive" })] }));
|
|
71
79
|
};
|
|
72
80
|
const renderDone = () => {
|
|
73
81
|
var _a, _b, _c;
|
|
@@ -79,9 +87,9 @@ export const AdminScriptRunModal = ({ baseUrl, api, scriptName, visible, onDismi
|
|
|
79
87
|
: "circle-xmark";
|
|
80
88
|
const iconColor = status === "completed" ? "success" : status === "cancelled" ? "warning" : "error";
|
|
81
89
|
const statusLabel = status === "completed" ? "Completed" : status === "cancelled" ? "Cancelled" : "Failed";
|
|
82
|
-
return (_jsxs(Box, { gap: 4, paddingY: 4, children: [_jsx(Heading, { align: "center", size: "md", children: scriptName }), _jsxs(Box, { alignItems: "center", gap: 2, children: [_jsx(Icon, { color: iconColor, iconName: iconName, size: "md" }), _jsx(Text, { align: "center", bold: true, children: statusLabel })] }), ((_b = task === null || task === void 0 ? void 0 : task.error) !== null && _b !== void 0 ? _b : startError) && (_jsx(Box, { color: "error", padding: 3, rounding: "md", children: _jsx(Text, { color: "inverted", size: "sm", children: (_c = task === null || task === void 0 ? void 0 : task.error) !== null && _c !== void 0 ? _c : startError }) })), (task === null || task === void 0 ? void 0 : task.result) && task.result.length > 0 && (_jsxs(Box, { gap: 1, maxHeight: 300, overflow: "scrollY", padding: 2, children: [_jsxs(Text, { bold: true, size: "sm", children: ["Results (", task.result.length, "):"] }), task.result.map((line, i) => (_jsx(Text, { color: "secondaryDark", size: "sm", children: line }, `${i}-${line.slice(0, 20)}`)))] }))] }));
|
|
90
|
+
return (_jsxs(Box, { gap: 4, paddingY: 4, children: [_jsx(Heading, { align: "center", size: "md", children: scriptName }), _jsxs(Box, { alignItems: "center", gap: 2, children: [_jsx(Badge, { status: isDryRun ? "info" : "warning", value: isDryRun ? "Dry Run" : "Live Run" }), _jsx(Icon, { color: iconColor, iconName: iconName, size: "md" }), _jsx(Text, { align: "center", bold: true, children: statusLabel })] }), ((_b = task === null || task === void 0 ? void 0 : task.error) !== null && _b !== void 0 ? _b : startError) && (_jsx(Box, { color: "error", padding: 3, rounding: "md", children: _jsx(Text, { color: "inverted", size: "sm", children: (_c = task === null || task === void 0 ? void 0 : task.error) !== null && _c !== void 0 ? _c : startError }) })), (task === null || task === void 0 ? void 0 : task.result) && task.result.length > 0 && (_jsxs(Box, { gap: 1, maxHeight: 300, overflow: "scrollY", padding: 2, children: [_jsxs(Text, { bold: true, size: "sm", children: ["Results (", task.result.length, "):"] }), task.result.map((line, i) => (_jsx(Text, { color: "secondaryDark", size: "sm", children: line }, `${i}-${line.slice(0, 20)}`)))] }))] }));
|
|
83
91
|
};
|
|
84
92
|
const isComplete = phase === "done";
|
|
85
|
-
return (_jsx(Modal, { onDismiss: onDismiss, persistOnBackgroundClick: !isComplete, primaryButtonOnClick: onDismiss, primaryButtonText: isComplete ? "Close" : undefined, visible: visible, children: _jsxs(Box, { minHeight: 200, padding: 2, children: [phase === "running" && renderRunning(), phase === "done" && renderDone()] }) }));
|
|
93
|
+
return (_jsx(Modal, { onDismiss: onDismiss, persistOnBackgroundClick: !isComplete, primaryButtonOnClick: isComplete ? onDismiss : undefined, primaryButtonText: isComplete ? "Close" : undefined, visible: visible, children: _jsxs(Box, { minHeight: 200, padding: 2, children: [phase === "confirm" && renderConfirm(), phase === "running" && renderRunning(), phase === "done" && renderDone()] }) }));
|
|
86
94
|
};
|
|
87
95
|
//# sourceMappingURL=AdminScriptRunModal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdminScriptRunModal.js","sourceRoot":"","sources":["../src/AdminScriptRunModal.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"AdminScriptRunModal.js","sourceRoot":"","sources":["../src/AdminScriptRunModal.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,I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ED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@terreno/ui": "0.11.
|
|
3
|
+
"@terreno/ui": "0.11.9",
|
|
4
4
|
"expo-router": "~6.0.19",
|
|
5
5
|
"jspdf": "^4.2.0",
|
|
6
6
|
"lodash": "^4.17.23",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"test:coverage": "bun run ../scripts/check-coverage.ts"
|
|
52
52
|
},
|
|
53
53
|
"types": "dist/index.d.ts",
|
|
54
|
-
"version": "0.11.
|
|
54
|
+
"version": "0.11.9"
|
|
55
55
|
}
|
package/src/AdminScriptList.tsx
CHANGED
|
@@ -88,6 +88,7 @@ export const AdminScriptList: React.FC<AdminScriptListProps> = ({baseUrl, api, i
|
|
|
88
88
|
api={api}
|
|
89
89
|
baseUrl={baseUrl}
|
|
90
90
|
onDismiss={handleDismiss}
|
|
91
|
+
scriptDescription={selectedScript?.description}
|
|
91
92
|
scriptName={selectedScript?.name ?? null}
|
|
92
93
|
visible={modalVisible}
|
|
93
94
|
/>
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import * as terrenoUi from "@terreno/ui";
|
|
3
|
+
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import {act, fireEvent} from "../../ui/node_modules/@testing-library/react-native";
|
|
6
|
+
import {AdminScriptRunModal} from "./AdminScriptRunModal";
|
|
7
|
+
|
|
8
|
+
// Render Modal children inline so we can interact with them in tests
|
|
9
|
+
mock.module("@terreno/ui", () => ({
|
|
10
|
+
...terrenoUi,
|
|
11
|
+
Modal: ({children, visible}: {children?: React.ReactNode; visible?: boolean}) =>
|
|
12
|
+
visible ? <>{children}</> : null,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const mockRunScript = mock((_args: {name: string; wetRun: boolean}) => ({
|
|
16
|
+
unwrap: async () => ({taskId: "task-123"}),
|
|
17
|
+
}));
|
|
18
|
+
const mockCancelTask = mock((_taskId: string) => ({
|
|
19
|
+
unwrap: async () => ({}),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const mockUseAdminScripts = mock(() => ({
|
|
23
|
+
useCancelScriptTaskMutation: () => [mockCancelTask, {isLoading: false}],
|
|
24
|
+
useGetScriptTaskQuery: () => ({data: undefined, isLoading: false, error: null}),
|
|
25
|
+
useRunScriptMutation: () => [mockRunScript, {isLoading: false}],
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
mock.module("./useAdminScripts", () => ({
|
|
29
|
+
useAdminScripts: (...args: any[]) => mockUseAdminScripts(...args),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const mockApi = {} as any;
|
|
33
|
+
|
|
34
|
+
describe("AdminScriptRunModal", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
mockRunScript.mockClear();
|
|
37
|
+
mockCancelTask.mockClear();
|
|
38
|
+
mockUseAdminScripts.mockClear();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("renders Dry Run, Run, and Cancel buttons in confirm phase", () => {
|
|
42
|
+
const {getByTestId} = renderWithTheme(
|
|
43
|
+
<AdminScriptRunModal
|
|
44
|
+
api={mockApi}
|
|
45
|
+
baseUrl="/admin"
|
|
46
|
+
onDismiss={() => undefined}
|
|
47
|
+
scriptName="my-script"
|
|
48
|
+
visible
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(getByTestId("admin-script-dry-run-button")).toBeTruthy();
|
|
53
|
+
expect(getByTestId("admin-script-wet-run-button")).toBeTruthy();
|
|
54
|
+
expect(getByTestId("admin-script-confirm-cancel-button")).toBeTruthy();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("calls onDismiss when Cancel is pressed without invoking runScript", async () => {
|
|
58
|
+
const onDismiss = mock(() => undefined);
|
|
59
|
+
|
|
60
|
+
const {getByTestId} = renderWithTheme(
|
|
61
|
+
<AdminScriptRunModal
|
|
62
|
+
api={mockApi}
|
|
63
|
+
baseUrl="/admin"
|
|
64
|
+
onDismiss={onDismiss}
|
|
65
|
+
scriptName="my-script"
|
|
66
|
+
visible
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
await act(async () => {
|
|
71
|
+
fireEvent.press(getByTestId("admin-script-confirm-cancel-button"));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(onDismiss).toHaveBeenCalled();
|
|
75
|
+
expect(mockRunScript).not.toHaveBeenCalled();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("dispatches a dry run when the Dry Run button is pressed", async () => {
|
|
79
|
+
const {getByTestId} = renderWithTheme(
|
|
80
|
+
<AdminScriptRunModal
|
|
81
|
+
api={mockApi}
|
|
82
|
+
baseUrl="/admin"
|
|
83
|
+
onDismiss={() => undefined}
|
|
84
|
+
scriptName="my-script"
|
|
85
|
+
visible
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
await act(async () => {
|
|
90
|
+
fireEvent.press(getByTestId("admin-script-dry-run-button"));
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(mockRunScript).toHaveBeenCalledTimes(1);
|
|
94
|
+
expect(mockRunScript.mock.calls[0]?.[0]).toEqual({name: "my-script", wetRun: false});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("hides the wet-run button when dryRunOnly is true", () => {
|
|
98
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
99
|
+
<AdminScriptRunModal
|
|
100
|
+
api={mockApi}
|
|
101
|
+
baseUrl="/admin"
|
|
102
|
+
dryRunOnly
|
|
103
|
+
onDismiss={() => undefined}
|
|
104
|
+
scriptName="my-script"
|
|
105
|
+
visible
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
expect(getByTestId("admin-script-dry-run-button")).toBeTruthy();
|
|
110
|
+
expect(getByTestId("admin-script-confirm-cancel-button")).toBeTruthy();
|
|
111
|
+
expect(queryByTestId("admin-script-wet-run-button")).toBeNull();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("renders the script description in the confirm phase", () => {
|
|
115
|
+
const {getByText} = renderWithTheme(
|
|
116
|
+
<AdminScriptRunModal
|
|
117
|
+
api={mockApi}
|
|
118
|
+
baseUrl="/admin"
|
|
119
|
+
onDismiss={() => undefined}
|
|
120
|
+
scriptDescription="Migrates legacy records"
|
|
121
|
+
scriptName="migrate-data"
|
|
122
|
+
visible
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(getByText("Migrates legacy records")).toBeTruthy();
|
|
127
|
+
expect(getByText("migrate-data")).toBeTruthy();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {Api} from "@reduxjs/toolkit/query/react";
|
|
2
|
-
import {Box, Button, Heading, Icon, Modal, Spinner, Text} from "@terreno/ui";
|
|
2
|
+
import {Badge, Box, Button, Heading, Icon, Modal, Spinner, Text} from "@terreno/ui";
|
|
3
3
|
import React, {useCallback, useEffect, useRef, useState} from "react";
|
|
4
4
|
import type {BackgroundTask} from "./types";
|
|
5
5
|
import {useAdminScripts} from "./useAdminScripts";
|
|
@@ -8,8 +8,11 @@ interface AdminScriptRunModalProps {
|
|
|
8
8
|
baseUrl: string;
|
|
9
9
|
api: Api<any, any, any, any>;
|
|
10
10
|
scriptName: string | null;
|
|
11
|
+
scriptDescription?: string;
|
|
11
12
|
visible: boolean;
|
|
12
13
|
onDismiss: () => void;
|
|
14
|
+
/** When true, skip the confirmation step and only allow a dry run. */
|
|
15
|
+
dryRunOnly?: boolean;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
const POLL_INTERVAL_MS = 2000;
|
|
@@ -17,17 +20,22 @@ const POLL_INTERVAL_MS = 2000;
|
|
|
17
20
|
const isTerminalStatus = (status?: string): boolean =>
|
|
18
21
|
status === "completed" || status === "failed" || status === "cancelled";
|
|
19
22
|
|
|
23
|
+
type Phase = "confirm" | "running" | "done";
|
|
24
|
+
|
|
20
25
|
export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
21
26
|
baseUrl,
|
|
22
27
|
api,
|
|
23
28
|
scriptName,
|
|
29
|
+
scriptDescription,
|
|
24
30
|
visible,
|
|
25
31
|
onDismiss,
|
|
32
|
+
dryRunOnly = false,
|
|
26
33
|
}) => {
|
|
27
34
|
const [taskId, setTaskId] = useState<string | null>(null);
|
|
28
|
-
const [phase, setPhase] = useState<
|
|
35
|
+
const [phase, setPhase] = useState<Phase>("confirm");
|
|
36
|
+
const [isDryRun, setIsDryRun] = useState(false);
|
|
29
37
|
const [startError, setStartError] = useState<string | null>(null);
|
|
30
|
-
const
|
|
38
|
+
const startingRef = useRef(false);
|
|
31
39
|
|
|
32
40
|
const {useRunScriptMutation, useGetScriptTaskQuery, useCancelScriptTaskMutation} =
|
|
33
41
|
useAdminScripts(api, baseUrl);
|
|
@@ -43,34 +51,14 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
43
51
|
|
|
44
52
|
const task: BackgroundTask | undefined = taskData?.task;
|
|
45
53
|
|
|
46
|
-
//
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
if (!visible || !scriptName || hasStartedRef.current) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
hasStartedRef.current = true;
|
|
52
|
-
setTaskId(null);
|
|
53
|
-
setPhase("running");
|
|
54
|
-
setStartError(null);
|
|
55
|
-
|
|
56
|
-
void (async () => {
|
|
57
|
-
try {
|
|
58
|
-
const result = await runScript({name: scriptName, wetRun: true}).unwrap();
|
|
59
|
-
setTaskId(result.taskId);
|
|
60
|
-
} catch (err: unknown) {
|
|
61
|
-
const errData = (err as {data?: {title?: string; detail?: string}})?.data;
|
|
62
|
-
const message = errData?.detail ?? errData?.title ?? "Failed to start script";
|
|
63
|
-
setStartError(message);
|
|
64
|
-
setPhase("done");
|
|
65
|
-
hasStartedRef.current = false;
|
|
66
|
-
}
|
|
67
|
-
})();
|
|
68
|
-
}, [visible, scriptName, runScript]);
|
|
69
|
-
|
|
70
|
-
// Reset when modal closes
|
|
54
|
+
// Reset modal state whenever it becomes hidden
|
|
71
55
|
useEffect(() => {
|
|
72
56
|
if (!visible) {
|
|
73
|
-
|
|
57
|
+
setTaskId(null);
|
|
58
|
+
setPhase("confirm");
|
|
59
|
+
setIsDryRun(false);
|
|
60
|
+
setStartError(null);
|
|
61
|
+
startingRef.current = false;
|
|
74
62
|
}
|
|
75
63
|
}, [visible]);
|
|
76
64
|
|
|
@@ -81,7 +69,32 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
81
69
|
}
|
|
82
70
|
}, [task?.status]);
|
|
83
71
|
|
|
84
|
-
const
|
|
72
|
+
const startRun = useCallback(
|
|
73
|
+
async (wetRun: boolean) => {
|
|
74
|
+
if (!scriptName || startingRef.current) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
startingRef.current = true;
|
|
78
|
+
setIsDryRun(!wetRun);
|
|
79
|
+
setTaskId(null);
|
|
80
|
+
setStartError(null);
|
|
81
|
+
setPhase("running");
|
|
82
|
+
try {
|
|
83
|
+
const result = await runScript({name: scriptName, wetRun}).unwrap();
|
|
84
|
+
setTaskId(result.taskId);
|
|
85
|
+
} catch (err: unknown) {
|
|
86
|
+
const errData = (err as {data?: {title?: string; detail?: string}})?.data;
|
|
87
|
+
const message = errData?.detail ?? errData?.title ?? "Failed to start script";
|
|
88
|
+
setStartError(message);
|
|
89
|
+
setPhase("done");
|
|
90
|
+
} finally {
|
|
91
|
+
startingRef.current = false;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
[scriptName, runScript]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const handleCancelTask = useCallback(async () => {
|
|
85
98
|
if (!taskId) {
|
|
86
99
|
return;
|
|
87
100
|
}
|
|
@@ -92,11 +105,54 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
92
105
|
}
|
|
93
106
|
}, [taskId, cancelTask]);
|
|
94
107
|
|
|
108
|
+
const renderConfirm = (): React.ReactElement => (
|
|
109
|
+
<Box gap={4} paddingY={4}>
|
|
110
|
+
<Heading align="center" size="md">
|
|
111
|
+
{scriptName}
|
|
112
|
+
</Heading>
|
|
113
|
+
{scriptDescription && (
|
|
114
|
+
<Text align="center" color="secondaryDark">
|
|
115
|
+
{scriptDescription}
|
|
116
|
+
</Text>
|
|
117
|
+
)}
|
|
118
|
+
<Text align="center" size="sm">
|
|
119
|
+
{dryRunOnly
|
|
120
|
+
? "Dry runs simulate the script without persisting any changes."
|
|
121
|
+
: "Run a dry run first to preview changes, or run the script for real."}
|
|
122
|
+
</Text>
|
|
123
|
+
<Box direction="row" gap={2} justifyContent="center" wrap>
|
|
124
|
+
<Button
|
|
125
|
+
onClick={() => startRun(false)}
|
|
126
|
+
testID="admin-script-dry-run-button"
|
|
127
|
+
text="Dry Run"
|
|
128
|
+
variant={dryRunOnly ? "primary" : "secondary"}
|
|
129
|
+
/>
|
|
130
|
+
{!dryRunOnly && (
|
|
131
|
+
<Button
|
|
132
|
+
confirmationText={`Run "${scriptName}" for real? This will persist changes.`}
|
|
133
|
+
onClick={() => startRun(true)}
|
|
134
|
+
testID="admin-script-wet-run-button"
|
|
135
|
+
text="Run"
|
|
136
|
+
variant="primary"
|
|
137
|
+
withConfirmation
|
|
138
|
+
/>
|
|
139
|
+
)}
|
|
140
|
+
<Button
|
|
141
|
+
onClick={onDismiss}
|
|
142
|
+
testID="admin-script-confirm-cancel-button"
|
|
143
|
+
text="Cancel"
|
|
144
|
+
variant="muted"
|
|
145
|
+
/>
|
|
146
|
+
</Box>
|
|
147
|
+
</Box>
|
|
148
|
+
);
|
|
149
|
+
|
|
95
150
|
const renderRunning = (): React.ReactElement => (
|
|
96
151
|
<Box alignItems="center" gap={4} paddingY={4}>
|
|
97
152
|
<Heading align="center" size="md">
|
|
98
153
|
{scriptName}
|
|
99
154
|
</Heading>
|
|
155
|
+
<Badge status={isDryRun ? "info" : "warning"} value={isDryRun ? "Dry Run" : "Live Run"} />
|
|
100
156
|
<Spinner size="md" />
|
|
101
157
|
{task?.progress?.message && <Text align="center">{task.progress.message}</Text>}
|
|
102
158
|
{task?.progress?.stage && (
|
|
@@ -110,9 +166,9 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
110
166
|
</Text>
|
|
111
167
|
)}
|
|
112
168
|
<Button
|
|
113
|
-
disabled={isCancelling}
|
|
169
|
+
disabled={isCancelling || !taskId}
|
|
114
170
|
loading={isCancelling}
|
|
115
|
-
onClick={
|
|
171
|
+
onClick={handleCancelTask}
|
|
116
172
|
testID="admin-script-cancel-button"
|
|
117
173
|
text="Cancel"
|
|
118
174
|
variant="destructive"
|
|
@@ -139,6 +195,7 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
139
195
|
{scriptName}
|
|
140
196
|
</Heading>
|
|
141
197
|
<Box alignItems="center" gap={2}>
|
|
198
|
+
<Badge status={isDryRun ? "info" : "warning"} value={isDryRun ? "Dry Run" : "Live Run"} />
|
|
142
199
|
<Icon color={iconColor} iconName={iconName} size="md" />
|
|
143
200
|
<Text align="center" bold>
|
|
144
201
|
{statusLabel}
|
|
@@ -175,11 +232,12 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
175
232
|
<Modal
|
|
176
233
|
onDismiss={onDismiss}
|
|
177
234
|
persistOnBackgroundClick={!isComplete}
|
|
178
|
-
primaryButtonOnClick={onDismiss}
|
|
235
|
+
primaryButtonOnClick={isComplete ? onDismiss : undefined}
|
|
179
236
|
primaryButtonText={isComplete ? "Close" : undefined}
|
|
180
237
|
visible={visible}
|
|
181
238
|
>
|
|
182
239
|
<Box minHeight={200} padding={2}>
|
|
240
|
+
{phase === "confirm" && renderConfirm()}
|
|
183
241
|
{phase === "running" && renderRunning()}
|
|
184
242
|
{phase === "done" && renderDone()}
|
|
185
243
|
</Box>
|