@skyhook-io/radar-app 1.18.2 → 1.19.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 (78) hide show
  1. package/package.json +4 -4
  2. package/src/App.tsx +0 -1
  3. package/src/api/diagnose.test.ts +33 -2
  4. package/src/api/diagnose.ts +93 -3
  5. package/src/api/radarFeatures.ts +1 -0
  6. package/src/components/diagnose/AIMarkdown.tsx +1 -1
  7. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  8. package/src/components/diagnose/AgentControls.tsx +53 -6
  9. package/src/components/diagnose/AgentSetupNotice.tsx +1 -1
  10. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  11. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  12. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  13. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  14. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  15. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  16. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  17. package/src/components/diagnose/DiagnoseContext.tsx +205 -9
  18. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  19. package/src/components/diagnose/DiagnoseSurface.tsx +93 -21
  20. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  21. package/src/components/diagnose/Home.test.tsx +182 -5
  22. package/src/components/diagnose/Home.tsx +168 -36
  23. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  24. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  25. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  26. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  27. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  28. package/src/components/diagnose/InvestigationEvidenceSections.tsx +5 -1
  29. package/src/components/diagnose/InvestigationView.tsx +156 -29
  30. package/src/components/diagnose/LocalDiagnoseAction.tsx +23 -16
  31. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  32. package/src/components/diagnose/QuestionComposer.tsx +487 -0
  33. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  34. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  35. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  36. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  37. package/src/components/diagnose/assessmentCopy.ts +5 -0
  38. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  39. package/src/components/diagnose/investigationCase.ts +33 -1
  40. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  41. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +8 -0
  42. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  43. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  44. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  45. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  46. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  47. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  48. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  49. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  50. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  51. package/src/components/diagnose/investigationEvidence/types.ts +2 -0
  52. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  53. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  54. package/src/components/diagnose/investigationFocus.ts +132 -0
  55. package/src/components/diagnose/parts.test.tsx +20 -0
  56. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  57. package/src/components/diagnose/questionSuggestions.ts +150 -0
  58. package/src/components/diagnose/storyParts.test.tsx +13 -0
  59. package/src/components/diagnose/target.test.ts +143 -2
  60. package/src/components/diagnose/target.ts +109 -7
  61. package/src/components/diagnose/testdata/story-runs.json +474 -0
  62. package/src/components/diagnose/verdictText.test.tsx +87 -0
  63. package/src/components/diagnose/verdictText.ts +68 -0
  64. package/src/components/home/ClusterHealthCard.tsx +13 -39
  65. package/src/components/home/HomeAgentBlock.test.tsx +113 -0
  66. package/src/components/home/HomeAgentBlock.tsx +94 -0
  67. package/src/components/home/HomeView.tsx +5 -6
  68. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  69. package/src/components/home/RadarVersionLine.tsx +3 -28
  70. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  71. package/src/components/ui/Omnibar.tsx +47 -3
  72. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  73. package/src/components/ui/RadarOmnibar.tsx +11 -0
  74. package/src/components/whats-new/WhatsNewDialog.test.tsx +3 -3
  75. package/src/components/whats-new/releaseNotes.ts +60 -1
  76. package/src/hooks/useAgentSignin.test.tsx +190 -0
  77. package/src/hooks/useAgentSignin.ts +160 -0
  78. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
@@ -0,0 +1,487 @@
1
+ // The free-form way into an investigation: the engineer says what they are
2
+ // seeing, where to start and since when, and optionally pins the resource it
3
+ // is about. It starts the same investigation, with the same Findings page, as
4
+ // Investigate on a resource; it is not a chat.
5
+ import { useEffect, useMemo, useRef, useState } from "react";
6
+ import {
7
+ AlertOctagon,
8
+ AlertTriangle,
9
+ ArrowRight,
10
+ AtSign,
11
+ CornerDownLeft,
12
+ X,
13
+ } from "lucide-react";
14
+ import {
15
+ Collapse,
16
+ ISSUE_SEVERITY_LABEL,
17
+ ISSUE_SEVERITY_TEXT_CLASS,
18
+ } from "@skyhook-io/k8s-ui";
19
+
20
+ import {
21
+ useContexts,
22
+ useIssues,
23
+ useNamespaceScope,
24
+ useResourceIssues,
25
+ } from "../../api/client";
26
+ import { kindToPluralWithGroup } from "../../utils/navigation";
27
+ import { useDiagnose } from "./DiagnoseContext";
28
+ import {
29
+ suggestionsForPin,
30
+ suggestionsFromIssues,
31
+ type QuestionPin,
32
+ type QuestionSuggestion,
33
+ } from "./questionSuggestions";
34
+ import { ResourcePicker } from "./ResourcePicker";
35
+ import { Tooltip } from "../ui/Tooltip";
36
+ import { formatInvestigationTarget } from "./target";
37
+
38
+ export const LOOK_BACKS = ["15m", "1h", "6h", "24h"] as const;
39
+ const DEFAULT_LOOK_BACK = "1h";
40
+ const MAX_START_NAMESPACES = 20;
41
+ // Radar refuses a longer question; a pasted or handed-over one can arrive
42
+ // past the box's own limit.
43
+ const MAX_QUESTION_LENGTH = 2000;
44
+
45
+ // Chips state what the question carries; actions change it. They must not
46
+ // look alike, or a scope chip reads as a menu and an action as a value.
47
+ const chipClass =
48
+ "inline-flex max-w-full items-center gap-1 rounded-md border border-theme-border bg-theme-elevated px-2 py-0.5 text-xs text-theme-text-secondary";
49
+ const actionClass =
50
+ "inline-flex items-center gap-1 rounded-md border border-dashed border-theme-border px-2 py-0.5 text-xs text-theme-text-tertiary hover:border-theme-text-tertiary hover:text-theme-text-primary";
51
+
52
+ export function QuestionComposer({
53
+ onBrowseIssues,
54
+ }: {
55
+ onBrowseIssues?: () => void;
56
+ }) {
57
+ const { openInvestigation, agentLabel, questionDraft, saveQuestionDraft } =
58
+ useDiagnose();
59
+ // The draft outlives this component: it starts from it, and gives back
60
+ // whatever is unsent when it unmounts (opening a run, a resource).
61
+ const [text, setText] = useState(questionDraft?.text ?? "");
62
+ const [pin, setPin] = useState<QuestionPin | null>(
63
+ questionDraft?.pin ?? null,
64
+ );
65
+ const [lookBack, setLookBack] = useState<string>(
66
+ questionDraft?.lookBack ?? DEFAULT_LOOK_BACK,
67
+ );
68
+ // A handed-over question keeps when it was first asked until it is edited.
69
+ const [inherited, setInherited] = useState(
70
+ questionDraft?.askedAt && questionDraft.text
71
+ ? { text: questionDraft.text.trim(), askedAt: questionDraft.askedAt }
72
+ : null,
73
+ );
74
+ const [pickerOpen, setPickerOpen] = useState(!!questionDraft?.pickResource);
75
+ const textRef = useRef<HTMLTextAreaElement>(null);
76
+ const pickerInputRef = useRef<HTMLInputElement>(null);
77
+ // Focus now so typing straight away lands in the box; once new text has
78
+ // rendered, put the caret after it so the engineer can keep writing.
79
+ const focusText = () => {
80
+ const caretToEnd = () => {
81
+ const box = textRef.current;
82
+ box?.setSelectionRange(box.value.length, box.value.length);
83
+ };
84
+ textRef.current?.focus();
85
+ caretToEnd();
86
+ requestAnimationFrame(caretToEnd);
87
+ };
88
+
89
+ // A pin and chosen namespaces name things in one cluster. After a cluster
90
+ // switch they would name same-named things somewhere else, so they go; the
91
+ // words stay.
92
+ const { data: contexts } = useContexts();
93
+ const currentContext = contexts?.find((context) => context.isCurrent)?.name;
94
+ const [chosenIn, setChosenIn] = useState(questionDraft?.context);
95
+ const [droppedForCluster, setDroppedForCluster] = useState(false);
96
+
97
+ // Where to start follows the namespace picker until the engineer edits it.
98
+ const { data: scope } = useNamespaceScope();
99
+ const [namespaces, setNamespaces] = useState<string[] | null>(
100
+ questionDraft?.namespaces ?? null,
101
+ );
102
+ const picked = namespaces ?? scope?.actives ?? [];
103
+ // Past a handful of namespaces, the whole cluster is the honest place to
104
+ // start, and the backend accepts at most MAX_START_NAMESPACES.
105
+ const tooMany = picked.length > MAX_START_NAMESPACES;
106
+ const startIn = tooMany ? [] : picked;
107
+
108
+ // Suggestions follow what the question is about: the pinned resource's
109
+ // own issues, or the issues where the namespaces say to start.
110
+ const { data: issuesData } = useIssues(startIn, !pin);
111
+ const { data: pinIssues } = useResourceIssues(
112
+ pin ? kindToPluralWithGroup(pin.kind, pin.group) : "",
113
+ pin?.group || undefined,
114
+ pin?.namespace ?? "",
115
+ pin?.name ?? "",
116
+ !!pin,
117
+ );
118
+ const asked = text.trim();
119
+ const suggestions = useMemo(
120
+ () =>
121
+ (pin
122
+ ? suggestionsForPin(pinIssues ?? [], pin)
123
+ : suggestionsFromIssues(issuesData?.issues ?? [])
124
+ ).filter((suggestion) => !asked.includes(suggestion.question)),
125
+ [pin, pinIssues, issuesData, asked],
126
+ );
127
+
128
+ useEffect(() => {
129
+ if (pickerOpen) pickerInputRef.current?.focus();
130
+ }, [pickerOpen]);
131
+
132
+ useEffect(() => {
133
+ if (!currentContext) return;
134
+ if (chosenIn && chosenIn !== currentContext && (pin || namespaces)) {
135
+ setPin(null);
136
+ setNamespaces(null);
137
+ setDroppedForCluster(true);
138
+ }
139
+ if (chosenIn !== currentContext) setChosenIn(currentContext);
140
+ }, [currentContext, chosenIn, pin, namespaces]);
141
+
142
+ const unsent = useRef({
143
+ text,
144
+ pin,
145
+ namespaces,
146
+ lookBack,
147
+ inherited,
148
+ chosenIn,
149
+ });
150
+ unsent.current = { text, pin, namespaces, lookBack, inherited, chosenIn };
151
+ // A submitted question belongs to its start, not the draft; the start gives
152
+ // it back if it never becomes a run.
153
+ const submitted = useRef(false);
154
+ useEffect(
155
+ () => () => {
156
+ if (submitted.current) {
157
+ saveQuestionDraft({});
158
+ return;
159
+ }
160
+ const draft = unsent.current;
161
+ saveQuestionDraft({
162
+ askedAt:
163
+ draft.inherited?.text === draft.text.trim()
164
+ ? draft.inherited.askedAt
165
+ : undefined,
166
+ text: draft.text,
167
+ pin: draft.pin ?? undefined,
168
+ namespaces: draft.namespaces ?? undefined,
169
+ lookBack: draft.lookBack,
170
+ context: draft.chosenIn,
171
+ });
172
+ },
173
+ [saveQuestionDraft],
174
+ );
175
+
176
+ // A new hand-off (Ask about a resource, a start that never became a run)
177
+ // replaces what is here; the draft this composer started from does not.
178
+ const appliedSeq = useRef(questionDraft?.seq);
179
+ useEffect(() => {
180
+ if (!questionDraft || questionDraft.seq === appliedSeq.current) return;
181
+ appliedSeq.current = questionDraft.seq;
182
+ if (questionDraft.restore && unsent.current.text.trim()) return;
183
+ submitted.current = false;
184
+ if (!questionDraft.keepWords) {
185
+ setText(questionDraft.text ?? "");
186
+ setInherited(
187
+ questionDraft.askedAt && questionDraft.text
188
+ ? { text: questionDraft.text.trim(), askedAt: questionDraft.askedAt }
189
+ : null,
190
+ );
191
+ }
192
+ setPin(questionDraft.pin ?? null);
193
+ setNamespaces(questionDraft.namespaces ?? null);
194
+ setChosenIn(questionDraft.context ?? currentContext);
195
+ setDroppedForCluster(false);
196
+ setLookBack(questionDraft.lookBack ?? DEFAULT_LOOK_BACK);
197
+ setPickerOpen(!!questionDraft.pickResource);
198
+ if (!questionDraft.pickResource) focusText();
199
+ }, [questionDraft, currentContext]);
200
+
201
+ // A hand-off that mounts this composer (the Omnibar row, Ask about a
202
+ // resource, Back to your question) lands in the box, ready for Enter.
203
+ useEffect(() => {
204
+ if (questionDraft?.seq && !questionDraft.pickResource) focusText();
205
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- mount only
206
+ }, []);
207
+
208
+ const question = text.trim();
209
+ const tooLong = [...question].length > MAX_QUESTION_LENGTH;
210
+ const submit = () => {
211
+ if (!question || tooLong) return;
212
+ submitted.current = true;
213
+ openInvestigation({
214
+ fromComposer: true,
215
+ kind: pin?.kind ?? "",
216
+ group: pin?.group ?? "",
217
+ namespace: pin?.namespace ?? "",
218
+ name: pin?.name ?? "",
219
+ question,
220
+ namespaces: pin ? [] : startIn,
221
+ lookBack,
222
+ askedAt: inherited?.text === question ? inherited.askedAt : undefined,
223
+ });
224
+ };
225
+
226
+ // What the engineer already typed is their question; a suggestion then only
227
+ // says where to start.
228
+ const applySuggestion = (suggestion: QuestionSuggestion) => {
229
+ if (!text.trim()) setText(suggestion.question);
230
+ setPin(suggestion.pin ?? null);
231
+ setNamespaces(suggestion.namespaces);
232
+ focusText();
233
+ };
234
+
235
+ const addable =
236
+ startIn.length >= MAX_START_NAMESPACES
237
+ ? []
238
+ : (scope?.accessibleNamespaces ?? []).filter(
239
+ (ns) => !startIn.includes(ns),
240
+ );
241
+
242
+ return (
243
+ <section className="mx-auto w-full max-w-2xl">
244
+ <h1 className="text-xl font-semibold text-theme-text-primary">
245
+ What are you seeing?
246
+ </h1>
247
+ <p className="mt-1 text-sm text-theme-text-tertiary">
248
+ Describe a problem, or ask whether something looks right. {agentLabel}{" "}
249
+ investigates it with Radar’s read-only tools and shows what it found,
250
+ with the evidence.
251
+ </p>
252
+
253
+ <form
254
+ className="mt-4 rounded-lg border border-theme-border bg-theme-surface shadow-theme-sm focus-within:border-accent"
255
+ onSubmit={(event) => {
256
+ event.preventDefault();
257
+ submit();
258
+ }}
259
+ >
260
+ <textarea
261
+ ref={textRef}
262
+ value={text}
263
+ onChange={(event) => setText(event.target.value)}
264
+ onKeyDown={(event) => {
265
+ // "@" starting a word opens the picker; one inside a word (an
266
+ // email, an image digest) is just text.
267
+ if (event.key === "@" && !pin && !pickerOpen) {
268
+ const box = event.currentTarget;
269
+ const before = box.value.slice(0, box.selectionStart ?? 0);
270
+ if (before === "" || /\s$/.test(before)) {
271
+ event.preventDefault();
272
+ setPickerOpen(true);
273
+ return;
274
+ }
275
+ }
276
+ if (
277
+ event.key === "Enter" &&
278
+ !event.shiftKey &&
279
+ !event.nativeEvent.isComposing
280
+ ) {
281
+ event.preventDefault();
282
+ submit();
283
+ }
284
+ }}
285
+ rows={3}
286
+ maxLength={MAX_QUESTION_LENGTH}
287
+ aria-label="What are you seeing?"
288
+ placeholder={
289
+ "e.g. checkout returns 502s since the last deploy\ne.g. is catalog's memory use normal?"
290
+ }
291
+ className="block w-full resize-none rounded-t-lg bg-transparent px-3 py-2.5 text-sm text-theme-text-primary placeholder:text-theme-text-tertiary focus:outline-none"
292
+ />
293
+ <div className="flex flex-wrap items-center gap-1.5 border-t border-theme-border-subtle px-3 py-2">
294
+ {pin ? (
295
+ <span className={chipClass}>
296
+ <span className="text-theme-text-tertiary">About</span>
297
+ <span className="truncate font-medium text-theme-text-primary">
298
+ {formatInvestigationTarget(pin)}
299
+ </span>
300
+ <button
301
+ type="button"
302
+ onClick={() => setPin(null)}
303
+ aria-label="Unpin resource"
304
+ className="rounded text-theme-text-tertiary hover:text-theme-text-primary"
305
+ >
306
+ <X className="h-3 w-3" />
307
+ </button>
308
+ </span>
309
+ ) : (
310
+ <>
311
+ <span className="text-xs text-theme-text-tertiary">Start in</span>
312
+ {startIn.length === 0 ? (
313
+ <Tooltip
314
+ disabled={!tooMany}
315
+ content={`${picked.length} namespaces are selected; investigations start across the cluster past ${MAX_START_NAMESPACES}.`}
316
+ >
317
+ <span className={chipClass}>
318
+ All namespaces
319
+ {tooMany ? ` (${picked.length} selected)` : ""}
320
+ </span>
321
+ </Tooltip>
322
+ ) : (
323
+ startIn.map((ns) => (
324
+ <span key={ns} className={chipClass}>
325
+ <span className="truncate">{ns}</span>
326
+ <button
327
+ type="button"
328
+ onClick={() =>
329
+ setNamespaces(startIn.filter((n) => n !== ns))
330
+ }
331
+ aria-label={`Remove namespace ${ns}`}
332
+ className="rounded text-theme-text-tertiary hover:text-theme-text-primary"
333
+ >
334
+ <X className="h-3 w-3" />
335
+ </button>
336
+ </span>
337
+ ))
338
+ )}
339
+ {addable.length > 0 && (
340
+ <select
341
+ value=""
342
+ onChange={(event) =>
343
+ event.target.value &&
344
+ setNamespaces([...startIn, event.target.value])
345
+ }
346
+ aria-label="Add a namespace to start in"
347
+ className="w-28 cursor-pointer rounded-md border border-dashed border-theme-border bg-transparent px-1.5 py-0.5 text-xs text-theme-text-tertiary hover:border-theme-text-tertiary hover:text-theme-text-primary"
348
+ >
349
+ <option value="">+ namespace</option>
350
+ {addable.map((ns) => (
351
+ <option key={ns} value={ns}>
352
+ {ns}
353
+ </option>
354
+ ))}
355
+ </select>
356
+ )}
357
+ <button
358
+ type="button"
359
+ onClick={() => setPickerOpen((open) => !open)}
360
+ aria-expanded={pickerOpen}
361
+ className={actionClass}
362
+ >
363
+ <AtSign className="h-3 w-3" />
364
+ Pin a resource
365
+ </button>
366
+ </>
367
+ )}
368
+ <span className="ml-auto flex items-center gap-1">
369
+ <span className="text-xs text-theme-text-tertiary">
370
+ Started within
371
+ </span>
372
+ <span
373
+ role="group"
374
+ aria-label="Started within"
375
+ className="inline-flex rounded-md border border-theme-border"
376
+ >
377
+ {LOOK_BACKS.map((value) => (
378
+ <button
379
+ key={value}
380
+ type="button"
381
+ aria-pressed={lookBack === value}
382
+ onClick={() => setLookBack(value)}
383
+ className={`px-1.5 py-0.5 text-xs first:rounded-l-md last:rounded-r-md ${
384
+ lookBack === value
385
+ ? "bg-accent-muted text-accent-text"
386
+ : "text-theme-text-tertiary hover:bg-theme-hover"
387
+ }`}
388
+ >
389
+ {value}
390
+ </button>
391
+ ))}
392
+ </span>
393
+ <button
394
+ type="submit"
395
+ disabled={!question || tooLong}
396
+ className="btn-brand ml-1 inline-flex items-center gap-1 rounded-md px-2.5 py-1 text-xs font-medium disabled:opacity-50"
397
+ >
398
+ Investigate
399
+ <ArrowRight className="h-3.5 w-3.5" />
400
+ </button>
401
+ </span>
402
+ </div>
403
+ {tooLong && (
404
+ <p className="border-t border-theme-border-subtle px-3 py-1.5 text-[11px] text-theme-text-tertiary">
405
+ Questions can be up to {MAX_QUESTION_LENGTH} characters; this one
406
+ has {[...question].length}.
407
+ </p>
408
+ )}
409
+ {droppedForCluster && !pin && namespaces === null && (
410
+ <p className="border-t border-theme-border-subtle px-3 py-1.5 text-[11px] text-theme-text-tertiary">
411
+ The cluster changed, so the pinned resource and chosen namespaces
412
+ were cleared. Your words are kept.
413
+ </p>
414
+ )}
415
+ <Collapse open={pickerOpen && !pin} unmountOnExit>
416
+ <ResourcePicker
417
+ inputRef={pickerInputRef}
418
+ onPick={(picked) => {
419
+ setPin(picked);
420
+ setPickerOpen(false);
421
+ textRef.current?.focus();
422
+ }}
423
+ onCancel={() => {
424
+ setPickerOpen(false);
425
+ textRef.current?.focus();
426
+ }}
427
+ />
428
+ </Collapse>
429
+ </form>
430
+
431
+ {suggestions.length > 0 && (
432
+ <div className="mt-5">
433
+ <h2 className="text-xs font-medium text-theme-text-tertiary">
434
+ From what Radar sees now
435
+ </h2>
436
+ <ul className="mt-1.5 divide-y divide-theme-border-subtle overflow-hidden rounded-lg border border-theme-border bg-theme-surface">
437
+ {suggestions.map((suggestion) => {
438
+ const SeverityIcon =
439
+ suggestion.severity === "critical"
440
+ ? AlertOctagon
441
+ : AlertTriangle;
442
+ return (
443
+ <li key={suggestion.key}>
444
+ <button
445
+ type="button"
446
+ onClick={() => applySuggestion(suggestion)}
447
+ aria-label={`${ISSUE_SEVERITY_LABEL[suggestion.severity]}: ${suggestion.title}, ${suggestion.where}. ${text.trim() ? "Pins it to your question." : `Puts “${suggestion.question}” in the box.`}`}
448
+ className="group flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm hover:bg-theme-hover focus-visible:bg-theme-hover focus-visible:outline-none"
449
+ >
450
+ <SeverityIcon
451
+ aria-hidden
452
+ className={`h-4 w-4 shrink-0 ${ISSUE_SEVERITY_TEXT_CLASS[suggestion.severity]}`}
453
+ />
454
+ <span className="min-w-0 flex-1 truncate">
455
+ <span className="font-medium text-theme-text-primary">
456
+ {suggestion.title}
457
+ </span>
458
+ <span className="ml-2 text-theme-text-tertiary">
459
+ {suggestion.where}
460
+ </span>
461
+ </span>
462
+ <span className="flex shrink-0 items-center gap-1 text-xs text-theme-text-tertiary group-hover:text-theme-text-secondary group-focus-visible:text-theme-text-secondary">
463
+ <span className="opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100">
464
+ Use
465
+ </span>
466
+ <CornerDownLeft aria-hidden className="h-3.5 w-3.5" />
467
+ </span>
468
+ </button>
469
+ </li>
470
+ );
471
+ })}
472
+ </ul>
473
+ </div>
474
+ )}
475
+ {onBrowseIssues && (
476
+ <button
477
+ type="button"
478
+ onClick={onBrowseIssues}
479
+ className="mt-4 inline-flex items-center gap-1 text-xs text-theme-text-tertiary hover:text-theme-text-primary"
480
+ >
481
+ Or pick a problem from Issues
482
+ <ArrowRight className="h-3 w-3" />
483
+ </button>
484
+ )}
485
+ </section>
486
+ );
487
+ }
@@ -0,0 +1,38 @@
1
+ import { renderToStaticMarkup } from "react-dom/server";
2
+ import { describe, expect, it, vi } from "vitest";
3
+
4
+ import { QuestionFocus } from "./QuestionFocus";
5
+
6
+ const focus = [
7
+ { kind: "Deployment", group: "apps", namespace: "shop", name: "api" },
8
+ ];
9
+
10
+ describe("QuestionFocus", () => {
11
+ it("offers to investigate the resource or choose another", () => {
12
+ const html = renderToStaticMarkup(
13
+ <QuestionFocus
14
+ focus={focus}
15
+ onOpenResource={vi.fn()}
16
+ onInvestigate={vi.fn()}
17
+ onChooseResource={vi.fn()}
18
+ />,
19
+ );
20
+ expect(html).toContain("Investigate this resource");
21
+ expect(html).toContain("Choose another resource");
22
+ });
23
+
24
+ it("offers nothing to act on for a run about another cluster", () => {
25
+ const html = renderToStaticMarkup(
26
+ <QuestionFocus
27
+ focus={focus}
28
+ stale
29
+ onOpenResource={vi.fn()}
30
+ onInvestigate={vi.fn()}
31
+ onChooseResource={vi.fn()}
32
+ />,
33
+ );
34
+ expect(html).toContain("Deployment shop/api");
35
+ expect(html).not.toContain("<button");
36
+ expect(html).toContain("connect to that cluster and find");
37
+ });
38
+ });
@@ -0,0 +1,123 @@
1
+ import { ArrowRight } from "lucide-react";
2
+
3
+ import type { DiagnosisResourceRef } from "./diagnoseEvidenceTypes";
4
+ import {
5
+ formatInvestigationTarget,
6
+ type InvestigationTargetIdentity,
7
+ } from "./target";
8
+
9
+ // Where a question-only investigation came to rest. Investigating one of these
10
+ // starts a run about that resource with the same question, which is where a
11
+ // fix can be confirmed and applied. The earlier verdict is not carried over:
12
+ // it was written from cluster data, and the new run's question must stay the
13
+ // engineer's own words.
14
+ export function QuestionFocus({
15
+ focus,
16
+ onOpenResource,
17
+ onInvestigate,
18
+ onChooseResource,
19
+ disabled,
20
+ stale = false,
21
+ }: {
22
+ focus: InvestigationTargetIdentity[];
23
+ onOpenResource?: (ref: DiagnosisResourceRef) => void;
24
+ onInvestigate: (resource: InvestigationTargetIdentity) => void;
25
+ /** Ask the same question about a resource the engineer picks. */
26
+ onChooseResource: () => void;
27
+ disabled?: boolean;
28
+ /** The run is about another cluster: its resources can't be opened or
29
+ * investigated from this one. */
30
+ stale?: boolean;
31
+ }) {
32
+ if (stale) {
33
+ return focus.length > 0 ? (
34
+ <section aria-label="Focused on" className="card-inner px-3 py-2">
35
+ <h3 className="text-xs font-medium text-theme-text-tertiary">
36
+ Focused on
37
+ </h3>
38
+ <ul className="mt-1 space-y-1 text-sm text-theme-text-primary">
39
+ {focus.map((resource) => (
40
+ <li key={formatInvestigationTarget(resource)} className="truncate">
41
+ {formatInvestigationTarget(resource)}
42
+ </li>
43
+ ))}
44
+ </ul>
45
+ <p className="mt-1.5 text-[11px] text-theme-text-tertiary">
46
+ In the cluster this investigation ran against. This investigation
47
+ ended when Radar switched clusters; connect to that cluster and find
48
+ them there to investigate one.
49
+ </p>
50
+ </section>
51
+ ) : null;
52
+ }
53
+ const choose = (
54
+ <button
55
+ type="button"
56
+ disabled={disabled}
57
+ onClick={onChooseResource}
58
+ className="text-xs text-accent-text hover:underline disabled:opacity-50"
59
+ >
60
+ {focus.length > 0
61
+ ? "Choose another resource…"
62
+ : "Choose a resource to investigate…"}
63
+ </button>
64
+ );
65
+ if (focus.length === 0) {
66
+ return (
67
+ <section aria-label="Focused on" className="card-inner px-3 py-2">
68
+ <p className="text-xs text-theme-text-tertiary">
69
+ This assessment didn’t single out one resource Radar read. A fix is
70
+ applied from an investigation of the resource it changes.
71
+ </p>
72
+ <div className="mt-1">{choose}</div>
73
+ </section>
74
+ );
75
+ }
76
+ return (
77
+ <section aria-label="Focused on" className="card-inner px-3 py-2">
78
+ <h3 className="text-xs font-medium text-theme-text-tertiary">
79
+ Focused on
80
+ </h3>
81
+ <ul className="mt-1 space-y-1">
82
+ {focus.map((resource) => {
83
+ const label = formatInvestigationTarget(resource);
84
+ return (
85
+ <li
86
+ key={label}
87
+ className="flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-sm"
88
+ >
89
+ {onOpenResource ? (
90
+ <button
91
+ type="button"
92
+ onClick={() => onOpenResource(resource)}
93
+ className="min-w-0 truncate text-left text-theme-text-primary hover:underline"
94
+ >
95
+ {label}
96
+ </button>
97
+ ) : (
98
+ <span className="min-w-0 truncate text-theme-text-primary">
99
+ {label}
100
+ </span>
101
+ )}
102
+ <button
103
+ type="button"
104
+ disabled={disabled}
105
+ onClick={() => onInvestigate(resource)}
106
+ className="inline-flex shrink-0 items-center gap-1 text-xs text-accent-text hover:underline disabled:opacity-50"
107
+ >
108
+ Investigate this resource
109
+ <ArrowRight className="h-3 w-3" />
110
+ </button>
111
+ </li>
112
+ );
113
+ })}
114
+ </ul>
115
+ <div className="mt-1.5 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1">
116
+ <p className="text-[11px] text-theme-text-tertiary">
117
+ A fix is applied from an investigation of the resource it changes.
118
+ </p>
119
+ {choose}
120
+ </div>
121
+ </section>
122
+ );
123
+ }