@checkstack/ui 1.11.0 → 1.13.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/.storybook/main.ts +43 -0
- package/CHANGELOG.md +326 -0
- package/package.json +23 -18
- package/scripts/generate-stdlib-types.ts +23 -0
- package/src/components/Accordion.tsx +17 -9
- package/src/components/ActionCard.tsx +99 -11
- package/src/components/BrandIcon.tsx +57 -0
- package/src/components/CodeEditor/CodeEditor.tsx +159 -14
- package/src/components/CodeEditor/TypefoxEditor.tsx +537 -168
- package/src/components/CodeEditor/editorTheme.test.ts +41 -0
- package/src/components/CodeEditor/editorTheme.ts +26 -0
- package/src/components/CodeEditor/generated/builtin-modules.json +1 -0
- package/src/components/CodeEditor/importSpecifiers.test.ts +286 -0
- package/src/components/CodeEditor/importSpecifiers.ts +267 -0
- package/src/components/CodeEditor/index.ts +26 -0
- package/src/components/CodeEditor/monacoGuard.ts +76 -0
- package/src/components/CodeEditor/monacoTsService.ts +185 -0
- package/src/components/CodeEditor/popoutTitle.test.ts +37 -0
- package/src/components/CodeEditor/popoutTitle.ts +31 -0
- package/src/components/CodeEditor/scriptContext.test.ts +15 -7
- package/src/components/CodeEditor/scriptContext.ts +12 -18
- package/src/components/CodeEditor/scriptDiagnostics.test.ts +135 -0
- package/src/components/CodeEditor/scriptDiagnostics.ts +172 -0
- package/src/components/CodeEditor/types.ts +79 -0
- package/src/components/CodeEditor/validateScripts.ts +172 -0
- package/src/components/CodeEditor/vscodeServicesSignal.ts +72 -0
- package/src/components/ConfirmationModal.tsx +7 -1
- package/src/components/Dialog.tsx +32 -11
- package/src/components/DurationInput.tsx +121 -0
- package/src/components/DynamicForm/DynamicForm.tsx +119 -47
- package/src/components/DynamicForm/DynamicOptionsField.tsx +19 -14
- package/src/components/DynamicForm/FormField.tsx +183 -15
- package/src/components/DynamicForm/MultiTypeEditorField.tsx +78 -2
- package/src/components/DynamicForm/SecretEnvEditor.tsx +315 -0
- package/src/components/DynamicForm/index.ts +20 -0
- package/src/components/DynamicForm/secretEnv.logic.test.ts +126 -0
- package/src/components/DynamicForm/secretEnv.logic.ts +87 -0
- package/src/components/DynamicForm/types.ts +134 -1
- package/src/components/DynamicForm/utils.test.ts +38 -0
- package/src/components/DynamicForm/utils.ts +54 -0
- package/src/components/DynamicForm/validation.logic.test.ts +255 -0
- package/src/components/DynamicForm/validation.logic.ts +210 -0
- package/src/components/DynamicIcon.tsx +39 -17
- package/src/components/Markdown.tsx +68 -2
- package/src/components/Popover.tsx +6 -1
- package/src/components/ScriptTestPanel.logic.test.ts +139 -0
- package/src/components/ScriptTestPanel.logic.ts +137 -0
- package/src/components/ScriptTestPanel.tsx +394 -0
- package/src/components/Sheet.tsx +21 -6
- package/src/components/Spinner.tsx +56 -0
- package/src/components/StatusBadge.tsx +78 -0
- package/src/components/StrategyConfigCard.tsx +3 -3
- package/src/components/Tabs.tsx +7 -1
- package/src/components/TimeOfDayInput.tsx +116 -0
- package/src/components/UserMenu.logic.test.ts +37 -0
- package/src/components/UserMenu.logic.ts +30 -0
- package/src/components/UserMenu.tsx +40 -12
- package/src/components/comboboxInteraction.ts +39 -0
- package/src/components/iconRegistry.tsx +27 -0
- package/src/components/portalContainer.ts +24 -0
- package/src/index.ts +7 -0
- package/stories/ActionCard.stories.tsx +60 -0
- package/stories/CodeEditor.stories.tsx +47 -2
- package/stories/DurationInput.stories.tsx +59 -0
- package/stories/Introduction.mdx +1 -1
- package/stories/Markdown.stories.tsx +56 -0
- package/stories/ScriptTestPanel.stories.tsx +106 -0
- package/stories/SecretEnvEditor.stories.tsx +80 -0
- package/stories/Spinner.stories.tsx +90 -0
- package/stories/TimeOfDayInput.stories.tsx +34 -0
- package/tsconfig.json +4 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
Play,
|
|
4
|
+
ChevronDown,
|
|
5
|
+
ChevronRight,
|
|
6
|
+
CheckCircle2,
|
|
7
|
+
XCircle,
|
|
8
|
+
FlaskConical,
|
|
9
|
+
} from "lucide-react";
|
|
10
|
+
import { Button } from "./Button";
|
|
11
|
+
import { Badge } from "./Badge";
|
|
12
|
+
import { Input } from "./Input";
|
|
13
|
+
import { Label } from "./Label";
|
|
14
|
+
import { CodeEditor } from "./CodeEditor";
|
|
15
|
+
import { cn } from "../utils";
|
|
16
|
+
import { usePerformance } from "./PerformanceProvider";
|
|
17
|
+
import {
|
|
18
|
+
type ScriptTestPanelResult,
|
|
19
|
+
buildSecretOverrides,
|
|
20
|
+
distinctSecretNames,
|
|
21
|
+
formatReturnValue,
|
|
22
|
+
hasNoOutput,
|
|
23
|
+
isFailedResult,
|
|
24
|
+
rejectionResult,
|
|
25
|
+
validateSampleContextJson,
|
|
26
|
+
} from "./ScriptTestPanel.logic";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Result of a single in-UI script test run. Plugin-agnostic shape mirroring
|
|
30
|
+
* the backend `testScript` / `testCollectorScript` output so the panel can
|
|
31
|
+
* be reused by any script field (automation actions, healthcheck collectors,
|
|
32
|
+
* future surfaces). Re-exported from the pure-logic module so the public
|
|
33
|
+
* type stays at this path.
|
|
34
|
+
*/
|
|
35
|
+
export type { ScriptTestPanelResult } from "./ScriptTestPanel.logic";
|
|
36
|
+
|
|
37
|
+
/** Arguments handed to {@link ScriptTestPanelProps.onRun} for a single run. */
|
|
38
|
+
export interface ScriptTestRunArgs {
|
|
39
|
+
/**
|
|
40
|
+
* User-supplied per-secret-NAME override VALUES for this run (keyed by the
|
|
41
|
+
* secret name, never the env var), collected from the optional override
|
|
42
|
+
* inputs. Omitted when nothing was overridden. These are masked out of the
|
|
43
|
+
* result server-side and are NEVER the user's real secret — only an
|
|
44
|
+
* explicit test value the operator typed.
|
|
45
|
+
*/
|
|
46
|
+
secretOverrides?: Record<string, string>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ScriptTestPanelProps {
|
|
50
|
+
/**
|
|
51
|
+
* Runs the test. The owning feature page supplies this; it typically
|
|
52
|
+
* calls the plugin's `testScript` RPC with the current script + sample
|
|
53
|
+
* context (plus any {@link ScriptTestRunArgs.secretOverrides}) and resolves
|
|
54
|
+
* with the result. Rejecting surfaces as an error.
|
|
55
|
+
*/
|
|
56
|
+
onRun: (args: ScriptTestRunArgs) => Promise<ScriptTestPanelResult>;
|
|
57
|
+
/** Disables the Run button (e.g. while the script field is empty). */
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The script's declared secret → env mapping (`x-secret-env` sibling
|
|
61
|
+
* field). When non-empty, the panel renders an optional per-secret test
|
|
62
|
+
* override input so an operator can supply a realistic value for a run.
|
|
63
|
+
* Real secrets are NEVER resolved in the test path: with no override each
|
|
64
|
+
* secret is injected as a `__SECRET_<NAME>__` placeholder; an override is
|
|
65
|
+
* masked out of the captured output. Omit it and no override UI shows.
|
|
66
|
+
*/
|
|
67
|
+
secretEnv?: Record<string, string>;
|
|
68
|
+
/**
|
|
69
|
+
* Editable sample-context slot. Render a {@link ContextSampleEditor} (or
|
|
70
|
+
* any control) here; the panel just lays it out above the results.
|
|
71
|
+
*/
|
|
72
|
+
contextEditor?: React.ReactNode;
|
|
73
|
+
/**
|
|
74
|
+
* Note shown under the Run button. Defaults to the central-execution
|
|
75
|
+
* caveat. Pass `null` to hide it.
|
|
76
|
+
*/
|
|
77
|
+
note?: React.ReactNode;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the panel is expanded on first render. Defaults to `false`
|
|
80
|
+
* so a compact "Test script" affordance shows under every testable
|
|
81
|
+
* field and the sample-context editor + results only mount on demand.
|
|
82
|
+
* A successful/failed run auto-expands regardless of this.
|
|
83
|
+
*/
|
|
84
|
+
defaultOpen?: boolean;
|
|
85
|
+
className?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const DEFAULT_NOTE =
|
|
89
|
+
"Runs on the central backend. Real satellite runs may differ.";
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Inline script test panel: a Run button plus collapsible results
|
|
93
|
+
* (return value / stdout / stderr / exit code / duration / error).
|
|
94
|
+
*
|
|
95
|
+
* Purely presentational - it owns no RPC. The owning page wires `onRun`
|
|
96
|
+
* to the appropriate `testScript` mutation. Appears beneath any
|
|
97
|
+
* `x-script-testable` field via `MultiTypeEditorField`.
|
|
98
|
+
*/
|
|
99
|
+
export const ScriptTestPanel: React.FC<ScriptTestPanelProps> = ({
|
|
100
|
+
onRun,
|
|
101
|
+
disabled,
|
|
102
|
+
secretEnv,
|
|
103
|
+
contextEditor,
|
|
104
|
+
note = DEFAULT_NOTE,
|
|
105
|
+
defaultOpen = false,
|
|
106
|
+
className,
|
|
107
|
+
}) => {
|
|
108
|
+
const { isLowPower } = usePerformance();
|
|
109
|
+
const [running, setRunning] = React.useState(false);
|
|
110
|
+
// Whole-panel disclosure: collapsed by default so a testable field shows
|
|
111
|
+
// only a compact "Test script" affordance and the sample-context editor +
|
|
112
|
+
// results mount on demand. A run forces it open.
|
|
113
|
+
const [panelOpen, setPanelOpen] = React.useState(defaultOpen);
|
|
114
|
+
const [resultExpanded, setResultExpanded] = React.useState(true);
|
|
115
|
+
const [result, setResult] = React.useState<ScriptTestPanelResult | null>(null);
|
|
116
|
+
// Draft override values keyed by secret NAME. Kept client-side until an
|
|
117
|
+
// explicit run; an empty draft means "use the placeholder".
|
|
118
|
+
const [overrideDrafts, setOverrideDrafts] = React.useState<
|
|
119
|
+
Record<string, string>
|
|
120
|
+
>({});
|
|
121
|
+
|
|
122
|
+
const secretNames = React.useMemo(
|
|
123
|
+
() => distinctSecretNames(secretEnv),
|
|
124
|
+
[secretEnv],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const handleRun = React.useCallback(async () => {
|
|
128
|
+
setRunning(true);
|
|
129
|
+
try {
|
|
130
|
+
const res = await onRun({
|
|
131
|
+
secretOverrides: buildSecretOverrides({
|
|
132
|
+
secretEnv,
|
|
133
|
+
drafts: overrideDrafts,
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
setResult(res);
|
|
137
|
+
setResultExpanded(true);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
setResult(rejectionResult(error));
|
|
140
|
+
setResultExpanded(true);
|
|
141
|
+
} finally {
|
|
142
|
+
setRunning(false);
|
|
143
|
+
}
|
|
144
|
+
}, [onRun, secretEnv, overrideDrafts]);
|
|
145
|
+
|
|
146
|
+
const failed = result !== null && isFailedResult(result);
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<div
|
|
150
|
+
className={cn(
|
|
151
|
+
"rounded-lg border border-border/60 bg-muted/20",
|
|
152
|
+
className,
|
|
153
|
+
)}
|
|
154
|
+
>
|
|
155
|
+
<button
|
|
156
|
+
type="button"
|
|
157
|
+
onClick={() => setPanelOpen((prev) => !prev)}
|
|
158
|
+
className="flex w-full items-center justify-between gap-3 px-3 py-2 text-left"
|
|
159
|
+
aria-expanded={panelOpen}
|
|
160
|
+
>
|
|
161
|
+
<span className="flex items-center gap-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
|
|
162
|
+
<FlaskConical className="h-3.5 w-3.5" />
|
|
163
|
+
Test script
|
|
164
|
+
{/* When collapsed, surface the last run's outcome as a hint. */}
|
|
165
|
+
{!panelOpen && result !== null && (
|
|
166
|
+
<Badge
|
|
167
|
+
variant={failed ? "destructive" : "secondary"}
|
|
168
|
+
className="font-normal normal-case"
|
|
169
|
+
>
|
|
170
|
+
{failed ? "Failed" : "Success"}
|
|
171
|
+
</Badge>
|
|
172
|
+
)}
|
|
173
|
+
</span>
|
|
174
|
+
{panelOpen ? (
|
|
175
|
+
<ChevronDown className="h-4 w-4 shrink-0 text-muted-foreground" />
|
|
176
|
+
) : (
|
|
177
|
+
<ChevronRight className="h-4 w-4 shrink-0 text-muted-foreground" />
|
|
178
|
+
)}
|
|
179
|
+
</button>
|
|
180
|
+
|
|
181
|
+
{panelOpen && (
|
|
182
|
+
<div className="space-y-3 border-t border-border/60 p-3">
|
|
183
|
+
<div className="flex items-center justify-end">
|
|
184
|
+
<Button
|
|
185
|
+
type="button"
|
|
186
|
+
size="sm"
|
|
187
|
+
variant="secondary"
|
|
188
|
+
onClick={handleRun}
|
|
189
|
+
disabled={disabled || running}
|
|
190
|
+
>
|
|
191
|
+
<Play
|
|
192
|
+
className={cn(
|
|
193
|
+
"h-3.5 w-3.5",
|
|
194
|
+
running && !isLowPower && "animate-pulse",
|
|
195
|
+
)}
|
|
196
|
+
/>
|
|
197
|
+
{running ? "Running…" : "Run"}
|
|
198
|
+
</Button>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
{contextEditor}
|
|
202
|
+
|
|
203
|
+
{secretNames.length > 0 && (
|
|
204
|
+
<div className="space-y-2 rounded-md border border-border/60 bg-card p-3">
|
|
205
|
+
<div className="space-y-0.5">
|
|
206
|
+
<span className="text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
|
|
207
|
+
Secret test overrides
|
|
208
|
+
</span>
|
|
209
|
+
<p className="text-xs text-muted-foreground">
|
|
210
|
+
Optional. Left empty, each secret is injected as a{" "}
|
|
211
|
+
<code className="font-mono">__SECRET_NAME__</code> placeholder.
|
|
212
|
+
Any value you type is a test override only — masked from the
|
|
213
|
+
output and never your real secret.
|
|
214
|
+
</p>
|
|
215
|
+
</div>
|
|
216
|
+
{secretNames.map((name) => (
|
|
217
|
+
<div key={name} className="space-y-1">
|
|
218
|
+
<Label
|
|
219
|
+
htmlFor={`secret-override-${name}`}
|
|
220
|
+
className="font-mono text-xs"
|
|
221
|
+
>
|
|
222
|
+
{name}
|
|
223
|
+
</Label>
|
|
224
|
+
<Input
|
|
225
|
+
id={`secret-override-${name}`}
|
|
226
|
+
type="password"
|
|
227
|
+
value={overrideDrafts[name] ?? ""}
|
|
228
|
+
onChange={(e) =>
|
|
229
|
+
setOverrideDrafts((prev) => ({
|
|
230
|
+
...prev,
|
|
231
|
+
[name]: e.target.value,
|
|
232
|
+
}))
|
|
233
|
+
}
|
|
234
|
+
placeholder={`__SECRET_${name}__`}
|
|
235
|
+
className="font-mono text-sm"
|
|
236
|
+
/>
|
|
237
|
+
</div>
|
|
238
|
+
))}
|
|
239
|
+
</div>
|
|
240
|
+
)}
|
|
241
|
+
|
|
242
|
+
{note !== null && (
|
|
243
|
+
<p className="text-xs text-muted-foreground">{note}</p>
|
|
244
|
+
)}
|
|
245
|
+
|
|
246
|
+
{result !== null && (
|
|
247
|
+
<div className="rounded-md border border-border bg-card">
|
|
248
|
+
<button
|
|
249
|
+
type="button"
|
|
250
|
+
onClick={() => setResultExpanded((prev) => !prev)}
|
|
251
|
+
className="flex w-full items-center justify-between gap-2 px-3 py-2 text-left"
|
|
252
|
+
>
|
|
253
|
+
<span className="flex items-center gap-2 text-sm font-medium">
|
|
254
|
+
{failed ? (
|
|
255
|
+
<XCircle className="h-4 w-4 text-destructive" />
|
|
256
|
+
) : (
|
|
257
|
+
<CheckCircle2 className="h-4 w-4 text-emerald-500" />
|
|
258
|
+
)}
|
|
259
|
+
{failed ? "Failed" : "Success"}
|
|
260
|
+
<Badge variant="secondary" className="font-normal">
|
|
261
|
+
{result.durationMs}ms
|
|
262
|
+
</Badge>
|
|
263
|
+
{result.exitCode !== undefined && (
|
|
264
|
+
<Badge variant="secondary" className="font-normal">
|
|
265
|
+
exit {result.exitCode}
|
|
266
|
+
</Badge>
|
|
267
|
+
)}
|
|
268
|
+
</span>
|
|
269
|
+
{resultExpanded ? (
|
|
270
|
+
<ChevronDown className="h-4 w-4 text-muted-foreground" />
|
|
271
|
+
) : (
|
|
272
|
+
<ChevronRight className="h-4 w-4 text-muted-foreground" />
|
|
273
|
+
)}
|
|
274
|
+
</button>
|
|
275
|
+
|
|
276
|
+
{resultExpanded && (
|
|
277
|
+
<div className="space-y-3 border-t border-border px-3 py-3">
|
|
278
|
+
{result.error !== undefined && (
|
|
279
|
+
<ResultBlock
|
|
280
|
+
label="Error"
|
|
281
|
+
tone="error"
|
|
282
|
+
value={result.error}
|
|
283
|
+
/>
|
|
284
|
+
)}
|
|
285
|
+
{result.result !== undefined && (
|
|
286
|
+
<ResultBlock
|
|
287
|
+
label="Return value"
|
|
288
|
+
value={formatReturnValue(result.result)}
|
|
289
|
+
/>
|
|
290
|
+
)}
|
|
291
|
+
{result.stdout.length > 0 && (
|
|
292
|
+
<ResultBlock label="stdout" value={result.stdout} />
|
|
293
|
+
)}
|
|
294
|
+
{result.stderr.length > 0 && (
|
|
295
|
+
<ResultBlock
|
|
296
|
+
label="stderr"
|
|
297
|
+
tone="error"
|
|
298
|
+
value={result.stderr}
|
|
299
|
+
/>
|
|
300
|
+
)}
|
|
301
|
+
{hasNoOutput(result) && (
|
|
302
|
+
<p className="text-xs italic text-muted-foreground">
|
|
303
|
+
No output.
|
|
304
|
+
</p>
|
|
305
|
+
)}
|
|
306
|
+
</div>
|
|
307
|
+
)}
|
|
308
|
+
</div>
|
|
309
|
+
)}
|
|
310
|
+
</div>
|
|
311
|
+
)}
|
|
312
|
+
</div>
|
|
313
|
+
);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const ResultBlock: React.FC<{
|
|
317
|
+
label: string;
|
|
318
|
+
value: string;
|
|
319
|
+
tone?: "error";
|
|
320
|
+
}> = ({ label, value, tone }) => (
|
|
321
|
+
<div className="space-y-1">
|
|
322
|
+
<span className="text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
|
|
323
|
+
{label}
|
|
324
|
+
</span>
|
|
325
|
+
<pre
|
|
326
|
+
className={cn(
|
|
327
|
+
"max-h-48 overflow-auto rounded-md bg-muted/40 p-2 font-mono text-xs whitespace-pre-wrap break-words",
|
|
328
|
+
tone === "error" && "text-destructive",
|
|
329
|
+
)}
|
|
330
|
+
>
|
|
331
|
+
{value}
|
|
332
|
+
</pre>
|
|
333
|
+
</div>
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
// ─── Context sample editor ──────────────────────────────────────────────────
|
|
337
|
+
|
|
338
|
+
export interface ContextSampleEditorProps {
|
|
339
|
+
/** Current sample-context JSON string. */
|
|
340
|
+
value: string;
|
|
341
|
+
onChange: (value: string) => void;
|
|
342
|
+
/** Label above the editor. Defaults to "Sample context". */
|
|
343
|
+
label?: string;
|
|
344
|
+
disabled?: boolean;
|
|
345
|
+
/**
|
|
346
|
+
* Optional control rendered on the label row, e.g. a "Load from run"
|
|
347
|
+
* dropdown. The owning page supplies it (it owns the replay RPC); the
|
|
348
|
+
* editor stays plugin-agnostic and just lays it out.
|
|
349
|
+
*/
|
|
350
|
+
runPicker?: React.ReactNode;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Editable JSON sample-context editor for the test panel. Auto-seeding
|
|
355
|
+
* (from the field's schema / IntelliSense context) is the owning page's
|
|
356
|
+
* job - this component just renders + validates the JSON the user edits.
|
|
357
|
+
*
|
|
358
|
+
* Surfaces a parse error inline so an operator can fix malformed JSON
|
|
359
|
+
* before running. The optional `runPicker` slot lets a page add a "Load
|
|
360
|
+
* from run" dropdown that overwrites the sample with a real run's scope.
|
|
361
|
+
*/
|
|
362
|
+
export const ContextSampleEditor: React.FC<ContextSampleEditorProps> = ({
|
|
363
|
+
value,
|
|
364
|
+
onChange,
|
|
365
|
+
label = "Sample context",
|
|
366
|
+
disabled,
|
|
367
|
+
runPicker,
|
|
368
|
+
}) => {
|
|
369
|
+
const parseError = React.useMemo(
|
|
370
|
+
() => validateSampleContextJson(value),
|
|
371
|
+
[value],
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
return (
|
|
375
|
+
<div className="space-y-1.5">
|
|
376
|
+
<div className="flex items-center justify-between gap-3">
|
|
377
|
+
<span className="text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
|
|
378
|
+
{label}
|
|
379
|
+
</span>
|
|
380
|
+
{runPicker}
|
|
381
|
+
</div>
|
|
382
|
+
<CodeEditor
|
|
383
|
+
value={value}
|
|
384
|
+
onChange={onChange}
|
|
385
|
+
language="json"
|
|
386
|
+
minHeight="120px"
|
|
387
|
+
readOnly={disabled}
|
|
388
|
+
/>
|
|
389
|
+
{parseError !== null && (
|
|
390
|
+
<p className="text-xs text-destructive">Invalid JSON: {parseError}</p>
|
|
391
|
+
)}
|
|
392
|
+
</div>
|
|
393
|
+
);
|
|
394
|
+
};
|
package/src/components/Sheet.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
4
4
|
import { X } from "lucide-react";
|
|
5
5
|
import { cn } from "../utils";
|
|
6
6
|
import { usePerformance } from "./PerformanceProvider";
|
|
7
|
+
import { PortalContainerContext } from "./portalContainer";
|
|
7
8
|
|
|
8
9
|
const Sheet = DialogPrimitive.Root;
|
|
9
10
|
const SheetTrigger = DialogPrimitive.Trigger;
|
|
@@ -56,11 +57,23 @@ const SheetContent = React.forwardRef<
|
|
|
56
57
|
SheetContentProps
|
|
57
58
|
>(({ className, children, size, ...props }, ref) => {
|
|
58
59
|
const { isLowPower } = usePerformance();
|
|
60
|
+
// Expose the content element so popovers/comboboxes rendered inside the
|
|
61
|
+
// sheet portal INTO it — otherwise the modal scroll-lock blocks their
|
|
62
|
+
// internal scrolling (a popover portaled to body is outside the dialog).
|
|
63
|
+
const [content, setContent] = React.useState<HTMLDivElement | null>(null);
|
|
64
|
+
const setRefs = React.useCallback(
|
|
65
|
+
(node: HTMLDivElement | null) => {
|
|
66
|
+
setContent(node);
|
|
67
|
+
if (typeof ref === "function") ref(node);
|
|
68
|
+
else if (ref) ref.current = node;
|
|
69
|
+
},
|
|
70
|
+
[ref],
|
|
71
|
+
);
|
|
59
72
|
return (
|
|
60
73
|
<SheetPortal>
|
|
61
74
|
<SheetOverlay />
|
|
62
75
|
<DialogPrimitive.Content
|
|
63
|
-
ref={
|
|
76
|
+
ref={setRefs}
|
|
64
77
|
className={cn(
|
|
65
78
|
sheetContentVariants({ size }),
|
|
66
79
|
"inset-y-0 right-0 h-full",
|
|
@@ -70,11 +83,13 @@ const SheetContent = React.forwardRef<
|
|
|
70
83
|
)}
|
|
71
84
|
{...props}
|
|
72
85
|
>
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
<
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
<PortalContainerContext.Provider value={content}>
|
|
87
|
+
{children}
|
|
88
|
+
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2">
|
|
89
|
+
<X className="h-4 w-4" />
|
|
90
|
+
<span className="sr-only">Close</span>
|
|
91
|
+
</DialogPrimitive.Close>
|
|
92
|
+
</PortalContainerContext.Provider>
|
|
78
93
|
</DialogPrimitive.Content>
|
|
79
94
|
</SheetPortal>
|
|
80
95
|
);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Loader2 } from "lucide-react";
|
|
3
|
+
import { cn } from "../utils";
|
|
4
|
+
import { usePerformance } from "./PerformanceProvider";
|
|
5
|
+
|
|
6
|
+
const sizeClasses = {
|
|
7
|
+
sm: "h-4 w-4",
|
|
8
|
+
md: "h-5 w-5",
|
|
9
|
+
lg: "h-6 w-6",
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
export interface SpinnerProps
|
|
13
|
+
extends Omit<React.ComponentProps<typeof Loader2>, "ref"> {
|
|
14
|
+
/**
|
|
15
|
+
* Visual size of the spinner. Defaults to `sm` (`h-4 w-4`), the dominant
|
|
16
|
+
* inline-in-button need.
|
|
17
|
+
*/
|
|
18
|
+
size?: keyof typeof sizeClasses;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Spinner - a small INLINE loading indicator (e.g. next to button text or in a
|
|
24
|
+
* table cell). For a centered full-block loader, use `LoadingSpinner` instead.
|
|
25
|
+
*
|
|
26
|
+
* The `animate-spin` class is gated INTERNALLY behind
|
|
27
|
+
* `usePerformance().isLowPower`: on low-power devices the icon renders static
|
|
28
|
+
* (no spin), satisfying `.claude/rules/performance.md` so call sites inherit the
|
|
29
|
+
* guard without re-implementing it.
|
|
30
|
+
*
|
|
31
|
+
* Accessibility: decorative by default (`aria-hidden`), for the common case of
|
|
32
|
+
* sitting next to visible text like "Saving...". Pass `aria-label` to announce
|
|
33
|
+
* it on its own; that switches the icon to `role="status"` and drops
|
|
34
|
+
* `aria-hidden`.
|
|
35
|
+
*/
|
|
36
|
+
export const Spinner: React.FC<SpinnerProps> = ({
|
|
37
|
+
size = "sm",
|
|
38
|
+
className,
|
|
39
|
+
"aria-label": ariaLabel,
|
|
40
|
+
...props
|
|
41
|
+
}) => {
|
|
42
|
+
const { isLowPower } = usePerformance();
|
|
43
|
+
|
|
44
|
+
const accessibility =
|
|
45
|
+
ariaLabel === undefined
|
|
46
|
+
? { "aria-hidden": true }
|
|
47
|
+
: { "aria-label": ariaLabel, role: "status" as const };
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Loader2
|
|
51
|
+
className={cn(!isLowPower && "animate-spin", sizeClasses[size], className)}
|
|
52
|
+
{...accessibility}
|
|
53
|
+
{...props}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../utils";
|
|
3
|
+
|
|
4
|
+
export type StatusTone = "ok" | "warn" | "error" | "info" | "neutral";
|
|
5
|
+
|
|
6
|
+
const toneClass: Record<StatusTone, string> = {
|
|
7
|
+
ok: "bg-success/10 text-success",
|
|
8
|
+
warn: "bg-warning/10 text-warning",
|
|
9
|
+
error: "bg-destructive/10 text-destructive",
|
|
10
|
+
info: "bg-info/10 text-info",
|
|
11
|
+
neutral: "bg-secondary text-secondary-foreground",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Severity sort order via CSS flex `order`, so the most urgent signal always
|
|
16
|
+
* sits left regardless of plugin registration order: error (red) -> warn
|
|
17
|
+
* (yellow) -> info -> neutral -> ok. Only takes effect when badges share a
|
|
18
|
+
* flex container (every `SystemStateBadgesSlot` render site wraps them in one).
|
|
19
|
+
*/
|
|
20
|
+
const orderClass: Record<StatusTone, string> = {
|
|
21
|
+
error: "order-1",
|
|
22
|
+
warn: "order-2",
|
|
23
|
+
info: "order-3",
|
|
24
|
+
neutral: "order-4",
|
|
25
|
+
ok: "order-5",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface StatusBadgeProps {
|
|
29
|
+
/** Severity tone driving the (subtle, tinted) color. */
|
|
30
|
+
tone: StatusTone;
|
|
31
|
+
/** Lucide-style icon component. */
|
|
32
|
+
icon: React.ComponentType<{ className?: string }>;
|
|
33
|
+
/** Full description: shown on hover/focus and exposed to assistive tech. */
|
|
34
|
+
label: string;
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A compact, uniform status symbol: a small tinted chip holding an icon, with
|
|
40
|
+
* the full label revealed on hover/focus (and via `aria-label`). All system
|
|
41
|
+
* state badges (health, incident, SLO, maintenance, anomaly, dependency) render
|
|
42
|
+
* through this so a system's status reads as a tidy, consistent row of icons
|
|
43
|
+
* instead of a stack of differently-styled text pills.
|
|
44
|
+
*/
|
|
45
|
+
export const StatusBadge: React.FC<StatusBadgeProps> = ({
|
|
46
|
+
tone,
|
|
47
|
+
icon: Icon,
|
|
48
|
+
label,
|
|
49
|
+
className,
|
|
50
|
+
}) => {
|
|
51
|
+
return (
|
|
52
|
+
<span
|
|
53
|
+
className={cn(
|
|
54
|
+
"group/status-badge relative inline-flex shrink-0",
|
|
55
|
+
orderClass[tone],
|
|
56
|
+
className,
|
|
57
|
+
)}
|
|
58
|
+
>
|
|
59
|
+
<span
|
|
60
|
+
role="img"
|
|
61
|
+
aria-label={label}
|
|
62
|
+
tabIndex={0}
|
|
63
|
+
className={cn(
|
|
64
|
+
"inline-flex size-6 items-center justify-center rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
65
|
+
toneClass[tone],
|
|
66
|
+
)}
|
|
67
|
+
>
|
|
68
|
+
<Icon className="h-3.5 w-3.5" />
|
|
69
|
+
</span>
|
|
70
|
+
<span
|
|
71
|
+
role="tooltip"
|
|
72
|
+
className="pointer-events-none invisible absolute bottom-full left-1/2 z-[100] mb-1.5 -translate-x-1/2 whitespace-nowrap rounded border border-border bg-popover px-2 py-1 text-xs text-popover-foreground opacity-0 shadow-lg transition-opacity group-hover/status-badge:visible group-hover/status-badge:opacity-100 group-focus-within/status-badge:visible group-focus-within/status-badge:opacity-100"
|
|
73
|
+
>
|
|
74
|
+
{label}
|
|
75
|
+
</span>
|
|
76
|
+
</span>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
@@ -6,7 +6,7 @@ import { Badge, type BadgeProps } from "./Badge";
|
|
|
6
6
|
import { Toggle } from "./Toggle";
|
|
7
7
|
import { DynamicForm } from "./DynamicForm";
|
|
8
8
|
import type { OptionsResolver } from "./DynamicForm/types";
|
|
9
|
-
import { DynamicIcon, type
|
|
9
|
+
import { DynamicIcon, type IconName } from "./DynamicIcon";
|
|
10
10
|
import { MarkdownBlock } from "./Markdown";
|
|
11
11
|
import { cn } from "../utils";
|
|
12
12
|
|
|
@@ -38,8 +38,8 @@ export interface StrategyConfigCardData {
|
|
|
38
38
|
displayName: string;
|
|
39
39
|
/** Optional description shown below the title */
|
|
40
40
|
description?: string;
|
|
41
|
-
/**
|
|
42
|
-
icon?:
|
|
41
|
+
/** Icon name in PascalCase - a lucide icon or a vendored brand icon. */
|
|
42
|
+
icon?: IconName;
|
|
43
43
|
/** Whether the strategy is currently enabled */
|
|
44
44
|
enabled: boolean;
|
|
45
45
|
}
|
package/src/components/Tabs.tsx
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React, { useRef } from "react";
|
|
2
|
+
import { cn } from "../utils";
|
|
3
|
+
import { usePerformance } from "./PerformanceProvider";
|
|
2
4
|
|
|
3
5
|
export interface TabItem {
|
|
4
6
|
id: string;
|
|
@@ -126,13 +128,17 @@ export const TabPanel: React.FC<TabPanelProps> = ({
|
|
|
126
128
|
className = "",
|
|
127
129
|
}) => {
|
|
128
130
|
const isActive = activeTab === id;
|
|
131
|
+
const { isLowPower } = usePerformance();
|
|
129
132
|
|
|
130
133
|
return isActive ? (
|
|
131
134
|
<div
|
|
132
135
|
id={`tabpanel-${id}`}
|
|
133
136
|
role="tabpanel"
|
|
134
137
|
aria-labelledby={`tab-${id}`}
|
|
135
|
-
className={
|
|
138
|
+
className={cn(
|
|
139
|
+
!isLowPower && "animate-in fade-in-0 duration-200",
|
|
140
|
+
className,
|
|
141
|
+
)}
|
|
136
142
|
>
|
|
137
143
|
{children}
|
|
138
144
|
</div>
|