@terreno/admin-frontend 0.20.2 → 0.22.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/.ai/guidelines/core.md +10 -0
- package/dist/AdminBreadcrumbs.d.ts +13 -0
- package/dist/AdminBreadcrumbs.js +22 -0
- package/dist/AdminBreadcrumbs.js.map +1 -0
- package/dist/AdminFieldRenderer.js +3 -3
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.d.ts +2 -0
- package/dist/AdminFieldRendererCore.js +28 -18
- package/dist/AdminFieldRendererCore.js.map +1 -1
- package/dist/AdminHome.d.ts +22 -0
- package/dist/AdminHome.js +189 -0
- package/dist/AdminHome.js.map +1 -0
- package/dist/AdminModelForm.d.ts +24 -1
- package/dist/AdminModelForm.js +185 -14
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +4 -0
- package/dist/AdminModelList.js +19 -4
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +2 -27
- package/dist/AdminModelTable.js +316 -60
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +1 -0
- package/dist/AdminNestedArrayField.js +26 -6
- package/dist/AdminNestedArrayField.js.map +1 -1
- package/dist/AdminObjectPicker.d.ts +1 -0
- package/dist/AdminObjectPicker.js +6 -2
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +1 -0
- package/dist/AdminPrimitiveArrayField.js +9 -8
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminRefField.js +2 -2
- package/dist/AdminRefField.js.map +1 -1
- package/dist/AdminScriptList.js +114 -7
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +5 -0
- package/dist/AdminScriptRunModal.js +136 -30
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/dist/AdminShell.d.ts +39 -0
- package/dist/AdminShell.js +80 -0
- package/dist/AdminShell.js.map +1 -0
- package/dist/AdminShellLayout.d.ts +23 -0
- package/dist/AdminShellLayout.js +32 -0
- package/dist/AdminShellLayout.js.map +1 -0
- package/dist/AdminVersionConfig.d.ts +5 -0
- package/dist/AdminVersionConfig.js +15 -5
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConfigurationScreen.js +3 -3
- package/dist/ConfigurationScreen.js.map +1 -1
- package/dist/ConsentFormEditor.js +2 -2
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/ConsentFormList.js +1 -1
- package/dist/ConsentFormList.js.map +1 -1
- package/dist/ConsentResponseViewer.js +3 -3
- package/dist/ConsentResponseViewer.js.map +1 -1
- package/dist/DocumentStorageBrowser.js +1 -1
- package/dist/DocumentStorageBrowser.js.map +1 -1
- package/dist/adminModelListQueryParams.d.ts +14 -0
- package/dist/adminModelListQueryParams.js +51 -0
- package/dist/adminModelListQueryParams.js.map +1 -0
- package/dist/adminShellNav.d.ts +10 -0
- package/dist/adminShellNav.js +29 -0
- package/dist/adminShellNav.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/scriptRunUtils.d.ts +36 -0
- package/dist/scriptRunUtils.js +121 -0
- package/dist/scriptRunUtils.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.d.ts +1 -0
- package/dist/useAdminApi.js +11 -0
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminBackgroundTask.d.ts +12 -0
- package/dist/useAdminBackgroundTask.js +26 -0
- package/dist/useAdminBackgroundTask.js.map +1 -0
- package/dist/useAdminScripts.d.ts +19 -1
- package/dist/useAdminScripts.js +33 -4
- package/dist/useAdminScripts.js.map +1 -1
- package/package.json +4 -3
- package/src/AdminBreadcrumbs.test.tsx +27 -0
- package/src/AdminBreadcrumbs.tsx +63 -0
- package/src/AdminFieldRenderer.tsx +3 -0
- package/src/AdminFieldRendererCore.tsx +59 -1
- package/src/AdminHome.test.tsx +208 -0
- package/src/AdminHome.tsx +474 -0
- package/src/AdminModelForm.test.tsx +81 -1
- package/src/AdminModelForm.tsx +282 -34
- package/src/AdminModelList.test.tsx +1 -1
- package/src/AdminModelList.tsx +72 -39
- package/src/AdminModelTable.test.tsx +11 -0
- package/src/AdminModelTable.tsx +530 -92
- package/src/AdminNestedArrayField.tsx +59 -9
- package/src/AdminObjectPicker.tsx +19 -1
- package/src/AdminPrimitiveArrayField.tsx +30 -15
- package/src/AdminRefField.tsx +2 -0
- package/src/AdminScriptList.tsx +307 -30
- package/src/AdminScriptRunModal.tsx +410 -95
- package/src/AdminShell.tsx +296 -0
- package/src/AdminShellLayout.tsx +34 -0
- package/src/AdminVersionConfig.tsx +120 -76
- package/src/ConfigurationScreen.tsx +4 -2
- package/src/ConsentFormEditor.tsx +3 -1
- package/src/ConsentFormList.tsx +1 -1
- package/src/ConsentResponseViewer.tsx +3 -3
- package/src/DocumentStorageBrowser.tsx +1 -1
- package/src/adminModelListQueryParams.ts +61 -0
- package/src/adminShellNav.test.ts +29 -0
- package/src/adminShellNav.ts +33 -0
- package/src/index.tsx +6 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +152 -1
- package/src/scriptRunUtils.test.ts +146 -0
- package/src/scriptRunUtils.ts +149 -0
- package/src/types.ts +69 -0
- package/src/useAdminApi.ts +11 -0
- package/src/useAdminBackgroundTask.ts +40 -0
- package/src/useAdminScripts.ts +56 -5
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
Badge,
|
|
3
|
+
Banner,
|
|
4
|
+
Box,
|
|
5
|
+
Button,
|
|
6
|
+
Heading,
|
|
7
|
+
Icon,
|
|
8
|
+
type IconName,
|
|
9
|
+
Modal,
|
|
10
|
+
Spinner,
|
|
11
|
+
Text,
|
|
12
|
+
TextField,
|
|
13
|
+
} from "@terreno/ui";
|
|
14
|
+
import React, {useCallback, useEffect, useMemo, useRef, useState} from "react";
|
|
15
|
+
import {
|
|
16
|
+
buildExport,
|
|
17
|
+
formatDuration,
|
|
18
|
+
isErrorLine,
|
|
19
|
+
relativeTime,
|
|
20
|
+
statusMeta,
|
|
21
|
+
summarizeOutput,
|
|
22
|
+
} from "./scriptRunUtils";
|
|
3
23
|
import {type AdminApi, type BackgroundTask, resolveAdminBases} from "./types";
|
|
4
24
|
import {useAdminScripts} from "./useAdminScripts";
|
|
5
25
|
|
|
@@ -17,6 +37,11 @@ interface AdminScriptRunModalProps {
|
|
|
17
37
|
onDismiss: () => void;
|
|
18
38
|
/** When true, skip the confirmation step and only allow a dry run. */
|
|
19
39
|
dryRunOnly?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* When set, the modal opens read-only on a previously-recorded run (from the run
|
|
42
|
+
* history) instead of starting a new one.
|
|
43
|
+
*/
|
|
44
|
+
historyTaskId?: string;
|
|
20
45
|
}
|
|
21
46
|
|
|
22
47
|
const POLL_INTERVAL_MS = 2000;
|
|
@@ -26,6 +51,58 @@ const isTerminalStatus = (status?: string): boolean =>
|
|
|
26
51
|
|
|
27
52
|
type Phase = "confirm" | "running" | "done";
|
|
28
53
|
|
|
54
|
+
type OutputFilter = "all" | "errors";
|
|
55
|
+
|
|
56
|
+
const downloadFile = (filename: string, content: string, mimeType: string): void => {
|
|
57
|
+
if (typeof document === "undefined" || typeof URL?.createObjectURL !== "function") {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const blob = new Blob([content], {type: mimeType});
|
|
61
|
+
const url = URL.createObjectURL(blob);
|
|
62
|
+
const anchor = document.createElement("a");
|
|
63
|
+
anchor.href = url;
|
|
64
|
+
anchor.download = filename;
|
|
65
|
+
anchor.click();
|
|
66
|
+
URL.revokeObjectURL(url);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** Small labelled count with an icon, used in the run summary. */
|
|
70
|
+
const CountStat: React.FC<{
|
|
71
|
+
iconColor: "success" | "error" | "secondaryDark";
|
|
72
|
+
iconName: IconName;
|
|
73
|
+
label: string;
|
|
74
|
+
value: number;
|
|
75
|
+
}> = ({iconColor, iconName, label, value}) => (
|
|
76
|
+
<Box gap={1}>
|
|
77
|
+
<Box alignItems="center" direction="row" gap={2}>
|
|
78
|
+
<Icon color={iconColor} iconName={iconName} size="sm" />
|
|
79
|
+
<Heading size="sm">{value.toLocaleString()}</Heading>
|
|
80
|
+
</Box>
|
|
81
|
+
<Text color="secondaryDark" size="sm">
|
|
82
|
+
{label}
|
|
83
|
+
</Text>
|
|
84
|
+
</Box>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
/** Proportional success/error bar mirroring the prototype's segment bar. */
|
|
88
|
+
const SegmentBar: React.FC<{errorCount: number; successCount: number; total: number}> = ({
|
|
89
|
+
errorCount,
|
|
90
|
+
successCount,
|
|
91
|
+
total,
|
|
92
|
+
}) => {
|
|
93
|
+
if (total <= 0) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const successPct = Math.round((successCount / total) * 100);
|
|
97
|
+
const errorPct = 100 - successPct;
|
|
98
|
+
return (
|
|
99
|
+
<Box direction="row" height={10} overflow="hidden" rounding="lg" width="100%">
|
|
100
|
+
{successCount > 0 && <Box color="success" width={`${successPct}%`} />}
|
|
101
|
+
{errorCount > 0 && <Box color="error" width={`${errorPct}%`} />}
|
|
102
|
+
</Box>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
29
106
|
export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
30
107
|
baseUrl,
|
|
31
108
|
apiBase,
|
|
@@ -36,12 +113,16 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
36
113
|
visible,
|
|
37
114
|
onDismiss,
|
|
38
115
|
dryRunOnly = false,
|
|
116
|
+
historyTaskId,
|
|
39
117
|
}) => {
|
|
40
118
|
const {apiBase: resolvedApiBase} = resolveAdminBases({apiBase, baseUrl, routeBase});
|
|
41
|
-
const
|
|
42
|
-
const [
|
|
119
|
+
const isHistory = Boolean(historyTaskId);
|
|
120
|
+
const [taskId, setTaskId] = useState<string | null>(historyTaskId ?? null);
|
|
121
|
+
const [phase, setPhase] = useState<Phase>(isHistory ? "running" : "confirm");
|
|
43
122
|
const [isDryRun, setIsDryRun] = useState(false);
|
|
44
123
|
const [startError, setStartError] = useState<string | null>(null);
|
|
124
|
+
const [outputFilter, setOutputFilter] = useState<OutputFilter>("all");
|
|
125
|
+
const [search, setSearch] = useState("");
|
|
45
126
|
const startingRef = useRef(false);
|
|
46
127
|
|
|
47
128
|
const {useRunScriptMutation, useGetScriptTaskQuery, useCancelScriptTaskMutation} =
|
|
@@ -57,24 +138,53 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
57
138
|
});
|
|
58
139
|
|
|
59
140
|
const task: BackgroundTask | undefined = taskData?.task;
|
|
141
|
+
const effectiveIsDryRun = isHistory ? Boolean(task?.isDryRun) : isDryRun;
|
|
142
|
+
|
|
143
|
+
// Derive the rendered phase straight from the task's terminal status so a completed
|
|
144
|
+
// run always shows the done view — even if the status-change effect below is delayed
|
|
145
|
+
// or missed (which otherwise leaves the spinner up at "Done · 100%").
|
|
146
|
+
const taskIsTerminal = Boolean(task && isTerminalStatus(task.status));
|
|
147
|
+
const displayPhase: Phase =
|
|
148
|
+
phase === "confirm" && !isHistory
|
|
149
|
+
? "confirm"
|
|
150
|
+
: taskIsTerminal || startError
|
|
151
|
+
? "done"
|
|
152
|
+
: "running";
|
|
153
|
+
|
|
154
|
+
// After a completed dry run, offer a live run straight from the done view.
|
|
155
|
+
const canRunLiveFromDone =
|
|
156
|
+
!isHistory && !dryRunOnly && effectiveIsDryRun && task?.status === "completed";
|
|
60
157
|
|
|
61
|
-
// Reset
|
|
158
|
+
// Reset to a clean slate whenever the modal opens (or the target script changes),
|
|
159
|
+
// and bind to a history task when opened read-only. Keyed on `visible`/`scriptName`
|
|
160
|
+
// (not just `!visible`) so a previous run's results never linger on reopen.
|
|
62
161
|
useEffect(() => {
|
|
63
|
-
|
|
162
|
+
setStartError(null);
|
|
163
|
+
setOutputFilter("all");
|
|
164
|
+
setSearch("");
|
|
165
|
+
startingRef.current = false;
|
|
166
|
+
if (historyTaskId) {
|
|
167
|
+
setTaskId(historyTaskId);
|
|
168
|
+
setPhase("running");
|
|
169
|
+
} else {
|
|
64
170
|
setTaskId(null);
|
|
65
|
-
setPhase("confirm");
|
|
66
171
|
setIsDryRun(false);
|
|
67
|
-
|
|
68
|
-
startingRef.current = false;
|
|
172
|
+
setPhase("confirm");
|
|
69
173
|
}
|
|
70
|
-
}, [visible]);
|
|
174
|
+
}, [visible, historyTaskId, scriptName]);
|
|
71
175
|
|
|
72
|
-
// Transition to done when task reaches terminal status
|
|
176
|
+
// Transition to done when the task reaches a terminal status (stops polling). Skipped
|
|
177
|
+
// during the confirm step so a stale cached task can't pull us out of it.
|
|
73
178
|
useEffect(() => {
|
|
179
|
+
if (phase === "confirm" && !isHistory) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
74
182
|
if (task && isTerminalStatus(task.status)) {
|
|
75
183
|
setPhase("done");
|
|
184
|
+
} else if (isHistory && task && !isTerminalStatus(task.status)) {
|
|
185
|
+
setPhase("running");
|
|
76
186
|
}
|
|
77
|
-
}, [task?.status]);
|
|
187
|
+
}, [task?.status, isHistory, phase]);
|
|
78
188
|
|
|
79
189
|
const startRun = useCallback(
|
|
80
190
|
async (wetRun: boolean) => {
|
|
@@ -85,6 +195,8 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
85
195
|
setIsDryRun(!wetRun);
|
|
86
196
|
setTaskId(null);
|
|
87
197
|
setStartError(null);
|
|
198
|
+
setOutputFilter("all");
|
|
199
|
+
setSearch("");
|
|
88
200
|
setPhase("running");
|
|
89
201
|
try {
|
|
90
202
|
const result = await runScript({name: scriptName, wetRun}).unwrap();
|
|
@@ -112,23 +224,83 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
112
224
|
}
|
|
113
225
|
}, [taskId, cancelTask]);
|
|
114
226
|
|
|
227
|
+
const resultLines = task?.result ?? [];
|
|
228
|
+
const summary = useMemo(() => summarizeOutput(task), [task]);
|
|
229
|
+
|
|
230
|
+
const filteredLines = useMemo(() => {
|
|
231
|
+
const query = search.trim().toLowerCase();
|
|
232
|
+
return resultLines.filter((line) => {
|
|
233
|
+
if (outputFilter === "errors" && !isErrorLine(line)) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (query && !line.toLowerCase().includes(query)) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
return true;
|
|
240
|
+
});
|
|
241
|
+
}, [resultLines, outputFilter, search]);
|
|
242
|
+
|
|
243
|
+
const handleExport = useCallback(
|
|
244
|
+
(kind: "csv" | "json") => {
|
|
245
|
+
if (resultLines.length === 0) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const {content, mimeType} = buildExport(resultLines, kind);
|
|
249
|
+
downloadFile(`${scriptName ?? "script"}_results.${kind}`, content, mimeType);
|
|
250
|
+
},
|
|
251
|
+
[resultLines, scriptName]
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
const renderHeader = (): React.ReactElement => (
|
|
255
|
+
<Box direction="row" gap={3}>
|
|
256
|
+
<Box
|
|
257
|
+
alignItems="center"
|
|
258
|
+
color="secondaryDark"
|
|
259
|
+
height={44}
|
|
260
|
+
justifyContent="center"
|
|
261
|
+
rounding="md"
|
|
262
|
+
width={44}
|
|
263
|
+
>
|
|
264
|
+
<Icon color="inverted" iconName="terminal" size="md" />
|
|
265
|
+
</Box>
|
|
266
|
+
<Box flex="grow" gap={1}>
|
|
267
|
+
<Box alignItems="center" direction="row" gap={2} wrap>
|
|
268
|
+
<Heading size="md">{scriptName}</Heading>
|
|
269
|
+
{(phase !== "confirm" || isHistory) && (
|
|
270
|
+
<Badge
|
|
271
|
+
status={effectiveIsDryRun ? "info" : "warning"}
|
|
272
|
+
value={effectiveIsDryRun ? "DRY" : "LIVE"}
|
|
273
|
+
/>
|
|
274
|
+
)}
|
|
275
|
+
</Box>
|
|
276
|
+
{scriptDescription && (
|
|
277
|
+
<Text color="secondaryDark" size="sm">
|
|
278
|
+
{scriptDescription}
|
|
279
|
+
</Text>
|
|
280
|
+
)}
|
|
281
|
+
</Box>
|
|
282
|
+
</Box>
|
|
283
|
+
);
|
|
284
|
+
|
|
115
285
|
const renderConfirm = (): React.ReactElement => (
|
|
116
|
-
<Box gap={4}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
286
|
+
<Box gap={4}>
|
|
287
|
+
{renderHeader()}
|
|
288
|
+
<Box color="secondaryLight" direction="row" gap={3} padding={3} rounding="md">
|
|
289
|
+
<Icon color="secondaryDark" iconName="flask" size="sm" />
|
|
290
|
+
<Box flex="grow" gap={1}>
|
|
291
|
+
<Text bold size="sm">
|
|
292
|
+
Start with a dry run
|
|
293
|
+
</Text>
|
|
294
|
+
<Text color="secondaryDark" size="sm">
|
|
295
|
+
{dryRunOnly
|
|
296
|
+
? "Dry runs simulate the script without persisting any changes."
|
|
297
|
+
: "A dry run simulates the script without writing. Run the live script once you've confirmed a dry run looks right."}
|
|
298
|
+
</Text>
|
|
299
|
+
</Box>
|
|
300
|
+
</Box>
|
|
130
301
|
<Box direction="row" gap={2} justifyContent="center" wrap>
|
|
131
302
|
<Button
|
|
303
|
+
iconName="flask"
|
|
132
304
|
onClick={() => startRun(false)}
|
|
133
305
|
testID="admin-script-dry-run-button"
|
|
134
306
|
text="Dry Run"
|
|
@@ -137,9 +309,10 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
137
309
|
{!dryRunOnly && (
|
|
138
310
|
<Button
|
|
139
311
|
confirmationText={`Run "${scriptName}" for real? This will persist changes.`}
|
|
312
|
+
iconName="bolt"
|
|
140
313
|
onClick={() => startRun(true)}
|
|
141
314
|
testID="admin-script-wet-run-button"
|
|
142
|
-
text="Run"
|
|
315
|
+
text="Run live"
|
|
143
316
|
variant="primary"
|
|
144
317
|
withConfirmation
|
|
145
318
|
/>
|
|
@@ -155,85 +328,226 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
155
328
|
);
|
|
156
329
|
|
|
157
330
|
const renderRunning = (): React.ReactElement => (
|
|
158
|
-
<Box
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
331
|
+
<Box gap={4}>
|
|
332
|
+
{renderHeader()}
|
|
333
|
+
<Box alignItems="center" gap={3} paddingY={4}>
|
|
334
|
+
<Spinner size="md" />
|
|
335
|
+
{task?.progress?.message && <Text align="center">{task.progress.message}</Text>}
|
|
336
|
+
{task?.progress?.stage && (
|
|
337
|
+
<Text align="center" color="secondaryDark" size="sm">
|
|
338
|
+
{task.progress.stage}
|
|
339
|
+
</Text>
|
|
340
|
+
)}
|
|
341
|
+
{task?.progress?.percentage !== undefined && task.progress.percentage > 0 && (
|
|
342
|
+
<Text align="center" color="secondaryDark" size="sm">
|
|
343
|
+
{task.progress.percentage}%
|
|
344
|
+
</Text>
|
|
345
|
+
)}
|
|
346
|
+
</Box>
|
|
347
|
+
{!isHistory && (
|
|
348
|
+
<Box alignItems="center">
|
|
349
|
+
<Button
|
|
350
|
+
disabled={isCancelling || !taskId}
|
|
351
|
+
iconName="stop"
|
|
352
|
+
loading={isCancelling}
|
|
353
|
+
onClick={handleCancelTask}
|
|
354
|
+
testID="admin-script-cancel-button"
|
|
355
|
+
text="Cancel run"
|
|
356
|
+
variant="destructive"
|
|
357
|
+
/>
|
|
358
|
+
</Box>
|
|
174
359
|
)}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
360
|
+
</Box>
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
const renderSummary = (): React.ReactElement => (
|
|
364
|
+
<Box border="default" gap={3} padding={3} rounding="md">
|
|
365
|
+
<Box alignItems="center" direction="row" gap={2}>
|
|
366
|
+
<Badge
|
|
367
|
+
status={effectiveIsDryRun ? "info" : "warning"}
|
|
368
|
+
value={effectiveIsDryRun ? "DRY" : "LIVE"}
|
|
369
|
+
/>
|
|
370
|
+
<Text bold>{effectiveIsDryRun ? "Dry run" : "Live run"}</Text>
|
|
371
|
+
<Box flex="grow" />
|
|
372
|
+
{isHistory && task?.created && (
|
|
373
|
+
<Text color="secondaryDark" size="sm">
|
|
374
|
+
{relativeTime(task.created)}
|
|
375
|
+
</Text>
|
|
376
|
+
)}
|
|
377
|
+
</Box>
|
|
378
|
+
<Box direction="row" gap={5} wrap>
|
|
379
|
+
<CountStat
|
|
380
|
+
iconColor="success"
|
|
381
|
+
iconName="circle-check"
|
|
382
|
+
label="Success"
|
|
383
|
+
value={summary.successCount}
|
|
384
|
+
/>
|
|
385
|
+
<CountStat
|
|
386
|
+
iconColor="error"
|
|
387
|
+
iconName="circle-xmark"
|
|
388
|
+
label="Errors"
|
|
389
|
+
value={summary.errorCount}
|
|
390
|
+
/>
|
|
391
|
+
<CountStat
|
|
392
|
+
iconColor="secondaryDark"
|
|
393
|
+
iconName="layer-group"
|
|
394
|
+
label="Total lines"
|
|
395
|
+
value={summary.total}
|
|
396
|
+
/>
|
|
397
|
+
</Box>
|
|
398
|
+
<SegmentBar
|
|
399
|
+
errorCount={summary.errorCount}
|
|
400
|
+
successCount={summary.successCount}
|
|
401
|
+
total={summary.total}
|
|
182
402
|
/>
|
|
183
403
|
</Box>
|
|
184
404
|
);
|
|
185
405
|
|
|
186
|
-
const
|
|
187
|
-
const status = task?.status ?? "failed";
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
406
|
+
const renderGateBanner = (): React.ReactElement | null => {
|
|
407
|
+
const status = task?.status ?? (startError ? "failed" : undefined);
|
|
408
|
+
if (startError) {
|
|
409
|
+
return <Banner status="alert" text={startError} />;
|
|
410
|
+
}
|
|
411
|
+
if (status === "completed") {
|
|
412
|
+
return (
|
|
413
|
+
<Banner
|
|
414
|
+
status={summary.errorCount > 0 ? "warning" : "info"}
|
|
415
|
+
text={
|
|
416
|
+
summary.errorCount > 0
|
|
417
|
+
? `Completed with ${summary.errorCount} error${summary.errorCount === 1 ? "" : "s"}.`
|
|
418
|
+
: effectiveIsDryRun
|
|
419
|
+
? "Dry run completed cleanly."
|
|
420
|
+
: "Live run completed successfully."
|
|
421
|
+
}
|
|
422
|
+
/>
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
if (status === "failed") {
|
|
426
|
+
return <Banner status="alert" text={task?.error ?? "Script failed."} />;
|
|
427
|
+
}
|
|
428
|
+
if (status === "cancelled") {
|
|
429
|
+
return <Banner status="warning" text="Run was cancelled." />;
|
|
430
|
+
}
|
|
431
|
+
return null;
|
|
432
|
+
};
|
|
198
433
|
|
|
434
|
+
const renderResults = (): React.ReactElement | null => {
|
|
435
|
+
if (resultLines.length === 0) {
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
199
438
|
return (
|
|
200
|
-
<Box gap={
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
<
|
|
208
|
-
{
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
{
|
|
216
|
-
|
|
439
|
+
<Box gap={2}>
|
|
440
|
+
<Box alignItems="center" direction="row" gap={2} wrap>
|
|
441
|
+
<Button
|
|
442
|
+
onClick={() => setOutputFilter("all")}
|
|
443
|
+
text={`All (${summary.total})`}
|
|
444
|
+
variant={outputFilter === "all" ? "secondary" : "muted"}
|
|
445
|
+
/>
|
|
446
|
+
<Button
|
|
447
|
+
onClick={() => setOutputFilter("errors")}
|
|
448
|
+
text={`Errors (${summary.errorCount})`}
|
|
449
|
+
variant={outputFilter === "errors" ? "secondary" : "muted"}
|
|
450
|
+
/>
|
|
451
|
+
<Box flex="grow" minWidth={160}>
|
|
452
|
+
<TextField
|
|
453
|
+
iconName="magnifying-glass"
|
|
454
|
+
onChange={setSearch}
|
|
455
|
+
placeholder="Search output"
|
|
456
|
+
type="search"
|
|
457
|
+
value={search}
|
|
458
|
+
/>
|
|
217
459
|
</Box>
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
Results ({task.result.length}):
|
|
460
|
+
</Box>
|
|
461
|
+
<Box border="default" gap={1} maxHeight={280} overflow="scrollY" padding={2} rounding="md">
|
|
462
|
+
{filteredLines.length === 0 ? (
|
|
463
|
+
<Text color="secondaryDark" size="sm">
|
|
464
|
+
No output lines match this filter.
|
|
224
465
|
</Text>
|
|
225
|
-
|
|
226
|
-
|
|
466
|
+
) : (
|
|
467
|
+
filteredLines.map((line, index) => (
|
|
468
|
+
<Text
|
|
469
|
+
color={isErrorLine(line) ? "error" : "secondaryDark"}
|
|
470
|
+
key={`${index}-${line.slice(0, 24)}`}
|
|
471
|
+
size="sm"
|
|
472
|
+
>
|
|
227
473
|
{line}
|
|
228
474
|
</Text>
|
|
229
|
-
))
|
|
230
|
-
|
|
231
|
-
|
|
475
|
+
))
|
|
476
|
+
)}
|
|
477
|
+
</Box>
|
|
478
|
+
</Box>
|
|
479
|
+
);
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
const renderDone = (): React.ReactElement => {
|
|
483
|
+
const meta = statusMeta(task?.status ?? "failed");
|
|
484
|
+
const duration = formatDuration(task?.startedAt, task?.completedAt);
|
|
485
|
+
const iconColor =
|
|
486
|
+
meta.badgeStatus === "success" ||
|
|
487
|
+
meta.badgeStatus === "error" ||
|
|
488
|
+
meta.badgeStatus === "warning"
|
|
489
|
+
? meta.badgeStatus
|
|
490
|
+
: "secondaryDark";
|
|
491
|
+
return (
|
|
492
|
+
<Box gap={3}>
|
|
493
|
+
{renderHeader()}
|
|
494
|
+
{renderSummary()}
|
|
495
|
+
{renderGateBanner()}
|
|
496
|
+
{renderResults()}
|
|
497
|
+
<Box alignItems="center" direction="row" gap={2} wrap>
|
|
498
|
+
<Icon color={iconColor} iconName={meta.iconName} size="sm" />
|
|
499
|
+
<Text bold size="sm">
|
|
500
|
+
{meta.label}
|
|
501
|
+
</Text>
|
|
502
|
+
{duration ? (
|
|
503
|
+
<Text color="secondaryDark" size="sm">
|
|
504
|
+
· {duration}
|
|
505
|
+
</Text>
|
|
506
|
+
) : null}
|
|
507
|
+
<Box flex="grow" />
|
|
508
|
+
<Button
|
|
509
|
+
disabled={resultLines.length === 0}
|
|
510
|
+
iconName="file-csv"
|
|
511
|
+
onClick={() => handleExport("csv")}
|
|
512
|
+
text="Export CSV"
|
|
513
|
+
variant="outline"
|
|
514
|
+
/>
|
|
515
|
+
<Button
|
|
516
|
+
disabled={resultLines.length === 0}
|
|
517
|
+
iconName="file-code"
|
|
518
|
+
onClick={() => handleExport("json")}
|
|
519
|
+
text="Export JSON"
|
|
520
|
+
variant="outline"
|
|
521
|
+
/>
|
|
522
|
+
{canRunLiveFromDone ? (
|
|
523
|
+
<>
|
|
524
|
+
<Button
|
|
525
|
+
iconName="rotate-right"
|
|
526
|
+
onClick={() => startRun(false)}
|
|
527
|
+
text="Re-run dry"
|
|
528
|
+
variant="muted"
|
|
529
|
+
/>
|
|
530
|
+
<Button
|
|
531
|
+
confirmationText={`Run "${scriptName}" for real? This will persist changes.`}
|
|
532
|
+
disabled={summary.errorCount > 0}
|
|
533
|
+
iconName="bolt"
|
|
534
|
+
onClick={() => startRun(true)}
|
|
535
|
+
testID="admin-script-done-wet-run-button"
|
|
536
|
+
text="Run live"
|
|
537
|
+
tooltipText={
|
|
538
|
+
summary.errorCount > 0 ? "Resolve errors before running live" : undefined
|
|
539
|
+
}
|
|
540
|
+
variant="primary"
|
|
541
|
+
withConfirmation
|
|
542
|
+
/>
|
|
543
|
+
</>
|
|
544
|
+
) : null}
|
|
545
|
+
</Box>
|
|
232
546
|
</Box>
|
|
233
547
|
);
|
|
234
548
|
};
|
|
235
549
|
|
|
236
|
-
const isComplete =
|
|
550
|
+
const isComplete = displayPhase === "done";
|
|
237
551
|
|
|
238
552
|
return (
|
|
239
553
|
<Modal
|
|
@@ -241,12 +555,13 @@ export const AdminScriptRunModal: React.FC<AdminScriptRunModalProps> = ({
|
|
|
241
555
|
persistOnBackgroundClick={!isComplete}
|
|
242
556
|
primaryButtonOnClick={isComplete ? onDismiss : undefined}
|
|
243
557
|
primaryButtonText={isComplete ? "Close" : undefined}
|
|
558
|
+
size="lg"
|
|
244
559
|
visible={visible}
|
|
245
560
|
>
|
|
246
|
-
<Box minHeight={
|
|
247
|
-
{
|
|
248
|
-
{
|
|
249
|
-
{
|
|
561
|
+
<Box gap={2} minHeight={220} padding={2}>
|
|
562
|
+
{displayPhase === "confirm" && renderConfirm()}
|
|
563
|
+
{displayPhase === "running" && renderRunning()}
|
|
564
|
+
{displayPhase === "done" && renderDone()}
|
|
250
565
|
</Box>
|
|
251
566
|
</Modal>
|
|
252
567
|
);
|