@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.
Files changed (117) hide show
  1. package/.ai/guidelines/core.md +10 -0
  2. package/dist/AdminBreadcrumbs.d.ts +13 -0
  3. package/dist/AdminBreadcrumbs.js +22 -0
  4. package/dist/AdminBreadcrumbs.js.map +1 -0
  5. package/dist/AdminFieldRenderer.js +3 -3
  6. package/dist/AdminFieldRenderer.js.map +1 -1
  7. package/dist/AdminFieldRendererCore.d.ts +2 -0
  8. package/dist/AdminFieldRendererCore.js +28 -18
  9. package/dist/AdminFieldRendererCore.js.map +1 -1
  10. package/dist/AdminHome.d.ts +22 -0
  11. package/dist/AdminHome.js +189 -0
  12. package/dist/AdminHome.js.map +1 -0
  13. package/dist/AdminModelForm.d.ts +24 -1
  14. package/dist/AdminModelForm.js +185 -14
  15. package/dist/AdminModelForm.js.map +1 -1
  16. package/dist/AdminModelList.d.ts +4 -0
  17. package/dist/AdminModelList.js +19 -4
  18. package/dist/AdminModelList.js.map +1 -1
  19. package/dist/AdminModelTable.d.ts +2 -27
  20. package/dist/AdminModelTable.js +316 -60
  21. package/dist/AdminModelTable.js.map +1 -1
  22. package/dist/AdminNestedArrayField.d.ts +1 -0
  23. package/dist/AdminNestedArrayField.js +26 -6
  24. package/dist/AdminNestedArrayField.js.map +1 -1
  25. package/dist/AdminObjectPicker.d.ts +1 -0
  26. package/dist/AdminObjectPicker.js +6 -2
  27. package/dist/AdminObjectPicker.js.map +1 -1
  28. package/dist/AdminPrimitiveArrayField.d.ts +1 -0
  29. package/dist/AdminPrimitiveArrayField.js +9 -8
  30. package/dist/AdminPrimitiveArrayField.js.map +1 -1
  31. package/dist/AdminRefField.js +2 -2
  32. package/dist/AdminRefField.js.map +1 -1
  33. package/dist/AdminScriptList.js +114 -7
  34. package/dist/AdminScriptList.js.map +1 -1
  35. package/dist/AdminScriptRunModal.d.ts +5 -0
  36. package/dist/AdminScriptRunModal.js +136 -30
  37. package/dist/AdminScriptRunModal.js.map +1 -1
  38. package/dist/AdminShell.d.ts +39 -0
  39. package/dist/AdminShell.js +80 -0
  40. package/dist/AdminShell.js.map +1 -0
  41. package/dist/AdminShellLayout.d.ts +23 -0
  42. package/dist/AdminShellLayout.js +32 -0
  43. package/dist/AdminShellLayout.js.map +1 -0
  44. package/dist/AdminVersionConfig.d.ts +5 -0
  45. package/dist/AdminVersionConfig.js +15 -5
  46. package/dist/AdminVersionConfig.js.map +1 -1
  47. package/dist/ConfigurationScreen.js +3 -3
  48. package/dist/ConfigurationScreen.js.map +1 -1
  49. package/dist/ConsentFormEditor.js +2 -2
  50. package/dist/ConsentFormEditor.js.map +1 -1
  51. package/dist/ConsentFormList.js +1 -1
  52. package/dist/ConsentFormList.js.map +1 -1
  53. package/dist/ConsentResponseViewer.js +3 -3
  54. package/dist/ConsentResponseViewer.js.map +1 -1
  55. package/dist/DocumentStorageBrowser.js +1 -1
  56. package/dist/DocumentStorageBrowser.js.map +1 -1
  57. package/dist/adminModelListQueryParams.d.ts +14 -0
  58. package/dist/adminModelListQueryParams.js +51 -0
  59. package/dist/adminModelListQueryParams.js.map +1 -0
  60. package/dist/adminShellNav.d.ts +10 -0
  61. package/dist/adminShellNav.js +29 -0
  62. package/dist/adminShellNav.js.map +1 -0
  63. package/dist/index.d.ts +6 -1
  64. package/dist/index.js +5 -0
  65. package/dist/index.js.map +1 -1
  66. package/dist/scriptRunUtils.d.ts +36 -0
  67. package/dist/scriptRunUtils.js +121 -0
  68. package/dist/scriptRunUtils.js.map +1 -0
  69. package/dist/types.d.ts +70 -0
  70. package/dist/types.js.map +1 -1
  71. package/dist/useAdminApi.d.ts +1 -0
  72. package/dist/useAdminApi.js +11 -0
  73. package/dist/useAdminApi.js.map +1 -1
  74. package/dist/useAdminBackgroundTask.d.ts +12 -0
  75. package/dist/useAdminBackgroundTask.js +26 -0
  76. package/dist/useAdminBackgroundTask.js.map +1 -0
  77. package/dist/useAdminScripts.d.ts +19 -1
  78. package/dist/useAdminScripts.js +33 -4
  79. package/dist/useAdminScripts.js.map +1 -1
  80. package/package.json +4 -3
  81. package/src/AdminBreadcrumbs.test.tsx +27 -0
  82. package/src/AdminBreadcrumbs.tsx +63 -0
  83. package/src/AdminFieldRenderer.tsx +3 -0
  84. package/src/AdminFieldRendererCore.tsx +59 -1
  85. package/src/AdminHome.test.tsx +208 -0
  86. package/src/AdminHome.tsx +474 -0
  87. package/src/AdminModelForm.test.tsx +81 -1
  88. package/src/AdminModelForm.tsx +282 -34
  89. package/src/AdminModelList.test.tsx +1 -1
  90. package/src/AdminModelList.tsx +72 -39
  91. package/src/AdminModelTable.test.tsx +11 -0
  92. package/src/AdminModelTable.tsx +530 -92
  93. package/src/AdminNestedArrayField.tsx +59 -9
  94. package/src/AdminObjectPicker.tsx +19 -1
  95. package/src/AdminPrimitiveArrayField.tsx +30 -15
  96. package/src/AdminRefField.tsx +2 -0
  97. package/src/AdminScriptList.tsx +307 -30
  98. package/src/AdminScriptRunModal.tsx +410 -95
  99. package/src/AdminShell.tsx +296 -0
  100. package/src/AdminShellLayout.tsx +34 -0
  101. package/src/AdminVersionConfig.tsx +120 -76
  102. package/src/ConfigurationScreen.tsx +4 -2
  103. package/src/ConsentFormEditor.tsx +3 -1
  104. package/src/ConsentFormList.tsx +1 -1
  105. package/src/ConsentResponseViewer.tsx +3 -3
  106. package/src/DocumentStorageBrowser.tsx +1 -1
  107. package/src/adminModelListQueryParams.ts +61 -0
  108. package/src/adminShellNav.test.ts +29 -0
  109. package/src/adminShellNav.ts +33 -0
  110. package/src/index.tsx +6 -1
  111. package/src/isolated/AdminScriptRunModal.isolated.tsx +152 -1
  112. package/src/scriptRunUtils.test.ts +146 -0
  113. package/src/scriptRunUtils.ts +149 -0
  114. package/src/types.ts +69 -0
  115. package/src/useAdminApi.ts +11 -0
  116. package/src/useAdminBackgroundTask.ts +40 -0
  117. package/src/useAdminScripts.ts +56 -5
@@ -1,5 +1,25 @@
1
- import {Badge, Box, Button, Heading, Icon, Modal, Spinner, Text} from "@terreno/ui";
2
- import React, {useCallback, useEffect, useRef, useState} from "react";
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 [taskId, setTaskId] = useState<string | null>(null);
42
- const [phase, setPhase] = useState<Phase>("confirm");
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 modal state whenever it becomes hidden
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
- if (!visible) {
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
- setStartError(null);
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} paddingY={4}>
117
- <Heading align="center" size="md">
118
- {scriptName}
119
- </Heading>
120
- {scriptDescription && (
121
- <Text align="center" color="secondaryDark">
122
- {scriptDescription}
123
- </Text>
124
- )}
125
- <Text align="center" size="sm">
126
- {dryRunOnly
127
- ? "Dry runs simulate the script without persisting any changes."
128
- : "Run a dry run first to preview changes, or run the script for real."}
129
- </Text>
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 alignItems="center" gap={4} paddingY={4}>
159
- <Heading align="center" size="md">
160
- {scriptName}
161
- </Heading>
162
- <Badge status={isDryRun ? "info" : "warning"} value={isDryRun ? "Dry Run" : "Live Run"} />
163
- <Spinner size="md" />
164
- {task?.progress?.message && <Text align="center">{task.progress.message}</Text>}
165
- {task?.progress?.stage && (
166
- <Text align="center" color="secondaryDark" size="sm">
167
- {task.progress.stage}
168
- </Text>
169
- )}
170
- {task?.progress?.percentage !== undefined && task.progress.percentage > 0 && (
171
- <Text align="center" color="secondaryDark" size="sm">
172
- {task.progress.percentage}%
173
- </Text>
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
- <Button
176
- disabled={isCancelling || !taskId}
177
- loading={isCancelling}
178
- onClick={handleCancelTask}
179
- testID="admin-script-cancel-button"
180
- text="Cancel"
181
- variant="destructive"
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 renderDone = (): React.ReactElement => {
187
- const status = task?.status ?? "failed";
188
- const iconName =
189
- status === "completed"
190
- ? "circle-check"
191
- : status === "cancelled"
192
- ? "circle-exclamation"
193
- : "circle-xmark";
194
- const iconColor =
195
- status === "completed" ? "success" : status === "cancelled" ? "warning" : "error";
196
- const statusLabel =
197
- status === "completed" ? "Completed" : status === "cancelled" ? "Cancelled" : "Failed";
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={4} paddingY={4}>
201
- <Heading align="center" size="md">
202
- {scriptName}
203
- </Heading>
204
- <Box alignItems="center" gap={2}>
205
- <Badge status={isDryRun ? "info" : "warning"} value={isDryRun ? "Dry Run" : "Live Run"} />
206
- <Icon color={iconColor} iconName={iconName} size="md" />
207
- <Text align="center" bold>
208
- {statusLabel}
209
- </Text>
210
- </Box>
211
-
212
- {(task?.error ?? startError) && (
213
- <Box color="error" padding={3} rounding="md">
214
- <Text color="inverted" size="sm">
215
- {task?.error ?? startError}
216
- </Text>
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
- {task?.result && task.result.length > 0 && (
221
- <Box gap={1} maxHeight={300} overflow="scrollY" padding={2}>
222
- <Text bold size="sm">
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
- {task.result.map((line, i) => (
226
- <Text color="secondaryDark" key={`${i}-${line.slice(0, 20)}`} size="sm">
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
- </Box>
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 = phase === "done";
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={200} padding={2}>
247
- {phase === "confirm" && renderConfirm()}
248
- {phase === "running" && renderRunning()}
249
- {phase === "done" && renderDone()}
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
  );