@skyhook-io/radar-app 1.18.2 → 1.20.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/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +31 -6
- package/src/api/application-evidence.ts +63 -0
- package/src/api/argoSync.test.ts +22 -0
- package/src/api/client.audit-gating.test.tsx +48 -0
- package/src/api/client.kueuePosition.test.ts +32 -0
- package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
- package/src/api/client.resource-identity.test.ts +3 -0
- package/src/api/client.resourceIssues.test.tsx +239 -0
- package/src/api/client.resourcePath.test.ts +3 -0
- package/src/api/client.ts +285 -55
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.test.ts +33 -2
- package/src/api/diagnose.ts +97 -3
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +41 -1
- package/src/api/rbac.settled.test.tsx +42 -0
- package/src/api/rbac.test.ts +18 -0
- package/src/api/rbac.ts +37 -7
- package/src/api/traffic.ts +9 -4
- package/src/api/usage-data.fixtures.ts +3 -1
- package/src/api/usage-data.test.tsx +134 -0
- package/src/api/usage-data.ts +35 -7
- package/src/api/workloadPodsPolling.test.ts +26 -0
- package/src/components/CloudConnectFlow.test.tsx +86 -0
- package/src/components/CloudConnectFlow.tsx +65 -27
- package/src/components/CloudFunnelButton.test.tsx +140 -5
- package/src/components/CloudFunnelButton.tsx +50 -9
- package/src/components/ConnectionErrorView.test.tsx +34 -0
- package/src/components/ConnectionErrorView.tsx +35 -11
- package/src/components/ContextSwitcher.tsx +5 -2
- package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
- package/src/components/SwitchAwareConnectionError.tsx +85 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
- package/src/components/capacity/CapacityDemand.tsx +3 -2
- package/src/components/capacity/demandSummary.test.ts +38 -0
- package/src/components/capacity/shared.tsx +12 -1
- package/src/components/cost/ApplicationCostTab.tsx +4 -0
- package/src/components/cost/CostTrendChart.tsx +2 -0
- package/src/components/cost/WorkloadCostTab.tsx +4 -0
- package/src/components/cost/source.test.ts +5 -0
- package/src/components/cost/source.ts +11 -0
- package/src/components/diagnose/AIMarkdown.tsx +4 -1
- package/src/components/diagnose/ActivityTurn.tsx +34 -14
- package/src/components/diagnose/AgentControls.tsx +53 -6
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
- package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
- package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
- package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
- package/src/components/diagnose/AnalysisStory.tsx +17 -4
- package/src/components/diagnose/AssessmentCard.tsx +39 -8
- package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
- package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
- package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
- package/src/components/diagnose/DiagnoseContext.tsx +272 -10
- package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
- package/src/components/diagnose/EvidenceCard.tsx +67 -14
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +208 -5
- package/src/components/diagnose/Home.tsx +187 -36
- package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
- package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
- package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
- package/src/components/diagnose/InvestigationView.tsx +249 -54
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
- package/src/components/diagnose/QuestionComposer.tsx +495 -0
- package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
- package/src/components/diagnose/QuestionFocus.tsx +123 -0
- package/src/components/diagnose/ResourcePicker.tsx +206 -0
- package/src/components/diagnose/StoryExcerpt.tsx +12 -3
- package/src/components/diagnose/assessmentCopy.ts +5 -0
- package/src/components/diagnose/exampleInvestigation.events.json +191 -0
- package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
- package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
- package/src/components/diagnose/exampleInvestigation.ts +121 -0
- package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
- package/src/components/diagnose/investigationCase.test.tsx +9 -1
- package/src/components/diagnose/investigationCase.ts +33 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
- package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
- package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
- package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
- package/src/components/diagnose/investigationEvidence/index.ts +1 -1
- package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
- package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
- package/src/components/diagnose/investigationEvidence/types.ts +7 -0
- package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
- package/src/components/diagnose/investigationFocus.test.ts +271 -0
- package/src/components/diagnose/investigationFocus.ts +132 -0
- package/src/components/diagnose/investigationState.ts +28 -0
- package/src/components/diagnose/lastInvestigation.test.ts +95 -0
- package/src/components/diagnose/lastInvestigation.ts +58 -0
- package/src/components/diagnose/launch.test.ts +125 -1
- package/src/components/diagnose/launch.ts +57 -10
- package/src/components/diagnose/parts.test.tsx +20 -0
- package/src/components/diagnose/questionSuggestions.test.ts +111 -0
- package/src/components/diagnose/questionSuggestions.ts +150 -0
- package/src/components/diagnose/storyParts.test.tsx +13 -0
- package/src/components/diagnose/target.test.ts +143 -2
- package/src/components/diagnose/target.ts +109 -7
- package/src/components/diagnose/testdata/story-runs.json +474 -0
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/diagnose/verdictText.test.tsx +87 -0
- package/src/components/diagnose/verdictText.ts +68 -0
- package/src/components/execution/BatchExecutionView.tsx +24 -11
- package/src/components/execution/JobSetAdmission.test.tsx +42 -0
- package/src/components/execution/JobSetAdmission.tsx +18 -3
- package/src/components/execution/JobSetMemberComparison.tsx +2 -1
- package/src/components/execution/runState.test.ts +14 -0
- package/src/components/execution/runState.ts +8 -0
- package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
- package/src/components/gitops/GitOpsView.tsx +86 -17
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
- package/src/components/gitops/destination-toast.test.ts +1 -1
- package/src/components/gitops/destination-toast.ts +2 -2
- package/src/components/home/ClusterHealthCard.tsx +13 -39
- package/src/components/home/HomeAgentBlock.test.tsx +141 -0
- package/src/components/home/HomeAgentBlock.tsx +103 -0
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +86 -47
- package/src/components/home/MCPSetupDialog.test.tsx +95 -5
- package/src/components/home/MCPSetupDialog.tsx +30 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/RadarVersionLine.test.tsx +0 -14
- package/src/components/home/RadarVersionLine.tsx +3 -28
- package/src/components/home/TopologyPreview.test.tsx +73 -0
- package/src/components/home/TopologyPreview.tsx +120 -233
- package/src/components/home/TrafficSummary.test.tsx +63 -0
- package/src/components/home/TrafficSummary.tsx +135 -138
- package/src/components/home/mcpToolCatalog.ts +23 -10
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +20 -1
- package/src/components/issues/uncheckedSources.ts +18 -0
- package/src/components/kueue/KueuePendingPosition.tsx +35 -0
- package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
- package/src/components/kueue/useRelatedReads.test.ts +56 -0
- package/src/components/kueue/useRelatedReads.ts +205 -0
- package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
- package/src/components/logs/MultiPodLogsTab.tsx +120 -0
- package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
- package/src/components/logs/PodLogsUnavailable.tsx +21 -0
- package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
- package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
- package/src/components/logs/RayClusterLogsTab.tsx +109 -0
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
- package/src/components/logs/rayClusterPods.ts +32 -0
- package/src/components/outageSince.test.ts +21 -0
- package/src/components/outageSince.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
- package/src/components/resource/PrometheusCharts.tsx +3 -40
- package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
- package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
- package/src/components/resources/crd/host.tsx +14 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
- package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
- package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
- package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
- package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
- package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
- package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
- package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
- package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
- package/src/components/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
- package/src/components/ui/Omnibar.tsx +47 -3
- package/src/components/ui/RadarOmnibar.test.tsx +1 -0
- package/src/components/ui/RadarOmnibar.tsx +11 -0
- package/src/components/ui/command-items-crd.test.tsx +23 -0
- package/src/components/ui/command-items.ts +2 -1
- package/src/components/useContextSwitchFlow.test.tsx +61 -0
- package/src/components/useContextSwitchFlow.tsx +21 -4
- package/src/components/whats-new/WhatsNew.test.ts +10 -3
- package/src/components/whats-new/WhatsNew.tsx +5 -1
- package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
- package/src/components/whats-new/releaseNotes.ts +136 -4
- package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
- package/src/components/workload/RelatedFindingsSection.tsx +80 -0
- package/src/components/workload/WorkloadView.test.ts +10 -1
- package/src/components/workload/WorkloadView.tsx +85 -98
- package/src/components/workload/issueResourceOpener.test.ts +20 -0
- package/src/components/workload/issueResourceOpener.ts +17 -0
- package/src/context/ConnectionContext.tsx +133 -60
- package/src/context/ConnectionProvider.retry.test.tsx +176 -0
- package/src/context/ContextSwitchContext.tsx +14 -1
- package/src/context/DiagnoseCustomization.tsx +3 -0
- package/src/context/clusterConnected.ts +10 -0
- package/src/contexts/CapabilitiesContext.tsx +6 -4
- package/src/hooks/useAgentSignin.test.tsx +190 -0
- package/src/hooks/useAgentSignin.ts +160 -0
- package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
- package/src/hooks/useElementSize.ts +30 -0
- package/src/integrations/resourceHost.test.tsx +1 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +21 -4
- package/src/integrations/resourceHosts.tsx +12 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
|
@@ -1,12 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type KeyboardEvent as ReactKeyboardEvent,
|
|
3
|
+
type ReactNode,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { createPortal } from "react-dom";
|
|
11
|
+
import { clsx } from "clsx";
|
|
1
12
|
import { Loader2, Sparkles } from "lucide-react";
|
|
13
|
+
import { formatRelativeAgeTime } from "@skyhook-io/k8s-ui/utils/format";
|
|
2
14
|
import {
|
|
3
15
|
type DiagnoseSetup,
|
|
4
16
|
useDiagnose,
|
|
5
17
|
useDiagnoseLayout,
|
|
6
18
|
} from "./DiagnoseContext";
|
|
7
|
-
import { runTargetKey } from "./target";
|
|
19
|
+
import { canonicalKind, runTargetKey } from "./target";
|
|
20
|
+
import { type LastInvestigation, sameObject } from "./lastInvestigation";
|
|
8
21
|
import { Tooltip } from "../ui/Tooltip";
|
|
22
|
+
import { useAnimatedUnmount } from "../../hooks/useAnimatedUnmount";
|
|
23
|
+
import {
|
|
24
|
+
TRANSITION_MENU,
|
|
25
|
+
overlayExitMs,
|
|
26
|
+
overlayTransitionStyle,
|
|
27
|
+
} from "../../utils/animation";
|
|
9
28
|
import type { RenderDiagnoseAction } from "../../context/DiagnoseCustomization";
|
|
29
|
+
import { recordUsageEvent } from "../../api/usage-data";
|
|
10
30
|
|
|
11
31
|
// The per-resource AI entry point. It no longer owns a panel — it just dispatches
|
|
12
32
|
// to the single app-level AI surface (DiagnoseContext), opening a new investigation
|
|
@@ -20,29 +40,42 @@ import type { RenderDiagnoseAction } from "../../context/DiagnoseCustomization";
|
|
|
20
40
|
// implies "something is wrong here" on a healthy resource. The tooltip leads with
|
|
21
41
|
// the BYO framing (the user's OWN agent, locally) — unless the agent is hosted,
|
|
22
42
|
// where those claims would be false.
|
|
43
|
+
//
|
|
44
|
+
// When the resource was investigated recently, the button shows it (filled
|
|
45
|
+
// sparkle, light tint) and a click first shows what that investigation found,
|
|
46
|
+
// with the usual action beside it. Hosted agents keep their own shared history, so they skip this.
|
|
23
47
|
function DiagnoseResourceButton({
|
|
24
48
|
kind,
|
|
25
49
|
group,
|
|
26
50
|
namespace,
|
|
27
51
|
name,
|
|
28
52
|
health,
|
|
53
|
+
createdAt,
|
|
29
54
|
}: {
|
|
30
55
|
kind: string;
|
|
31
56
|
group?: string;
|
|
32
57
|
namespace: string;
|
|
33
58
|
name: string;
|
|
34
59
|
health?: "problem" | "healthy" | "unknown";
|
|
60
|
+
createdAt?: string;
|
|
35
61
|
}) {
|
|
36
62
|
const d = useDiagnose();
|
|
37
|
-
const {
|
|
63
|
+
const { runningRunIds } = useDiagnoseLayout();
|
|
64
|
+
const last = useRecentInvestigation(kind, group, namespace, name, createdAt);
|
|
65
|
+
const [historyOpen, setHistoryOpen] = useState(false);
|
|
66
|
+
const closeHistory = useCallback(() => setHistoryOpen(false), []);
|
|
38
67
|
// Hidden only when the feature can't work here (auth/cloud/--no-mcp). When it's
|
|
39
68
|
// supported but no agent is installed we KEEP the button — clicking opens the
|
|
40
69
|
// setup notice so the feature is discoverable rather than silently absent.
|
|
41
70
|
if (d.setupState === "off" || d.setupState === "unknown") return null;
|
|
42
71
|
const ready = d.available;
|
|
43
72
|
const problem = health === "problem";
|
|
44
|
-
const
|
|
45
|
-
|
|
73
|
+
const runningRunId = ready
|
|
74
|
+
? runningRunIds.get(runTargetKey(kind, namespace, name, group ?? ""))
|
|
75
|
+
: undefined;
|
|
76
|
+
const running = !!runningRunId;
|
|
77
|
+
// A live run hides the panel; it shouldn't come back by itself afterwards.
|
|
78
|
+
if (historyOpen && !last) setHistoryOpen(false);
|
|
46
79
|
const tooltip = !ready
|
|
47
80
|
? notReadyTooltip(d)
|
|
48
81
|
: running
|
|
@@ -53,23 +86,40 @@ function DiagnoseResourceButton({
|
|
|
53
86
|
: `Ask ${d.agentLabel} about this resource — reads its spec, events & logs.`
|
|
54
87
|
: problem
|
|
55
88
|
? `Investigate with your own ${d.agentLabel} — runs locally and reads this resource's spec, events & logs.`
|
|
56
|
-
:
|
|
89
|
+
: d.questions
|
|
90
|
+
? `Ask your own ${d.agentLabel} a question about this resource — runs locally, reads its spec, events & logs.`
|
|
91
|
+
: `Ask your own ${d.agentLabel} about this resource — runs locally, reads its spec, events & logs.`;
|
|
57
92
|
// While an investigation is live, the button advertises it (and clicking focuses
|
|
58
93
|
// the existing run rather than starting a new one — openInvestigation dedups).
|
|
59
94
|
const showLabel = problem || running;
|
|
60
|
-
|
|
61
|
-
|
|
95
|
+
const asks = d.questions && !problem && !running;
|
|
96
|
+
// Asking about a resource with no live problem means saying what to ask; a
|
|
97
|
+
// problem, or a run already live, opens straight away.
|
|
98
|
+
const act = () => {
|
|
99
|
+
const target = { kind, group: group ?? "", namespace, name };
|
|
100
|
+
if (!ready) d.openHome();
|
|
101
|
+
else if (runningRunId) d.openRun(runningRunId);
|
|
102
|
+
else if (asks)
|
|
103
|
+
d.openQuestion({
|
|
104
|
+
pin: { ...target, kind: canonicalKind(kind, group ?? "") },
|
|
105
|
+
});
|
|
106
|
+
else d.openInvestigation(target);
|
|
107
|
+
};
|
|
108
|
+
const button = (
|
|
109
|
+
<Tooltip
|
|
110
|
+
content={
|
|
111
|
+
last
|
|
112
|
+
? `Investigated ${formatRelativeAgeTime(last.assessedAt)} — click to see what it found.`
|
|
113
|
+
: tooltip
|
|
114
|
+
}
|
|
115
|
+
position="bottom"
|
|
116
|
+
disabled={historyOpen}
|
|
117
|
+
preserveWrapperWhenDisabled
|
|
118
|
+
>
|
|
62
119
|
<button
|
|
63
|
-
onClick={() =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
kind,
|
|
67
|
-
group: group ?? "",
|
|
68
|
-
namespace,
|
|
69
|
-
name,
|
|
70
|
-
})
|
|
71
|
-
: d.openHome()
|
|
72
|
-
}
|
|
120
|
+
onClick={() => (last ? setHistoryOpen((o) => !o) : act())}
|
|
121
|
+
aria-haspopup={last ? "dialog" : undefined}
|
|
122
|
+
aria-expanded={last ? historyOpen : undefined}
|
|
73
123
|
aria-label={
|
|
74
124
|
!ready
|
|
75
125
|
? notReadyTooltip(d)
|
|
@@ -79,21 +129,239 @@ function DiagnoseResourceButton({
|
|
|
79
129
|
? "Investigate with AI"
|
|
80
130
|
: "Ask AI about this resource"
|
|
81
131
|
}
|
|
82
|
-
className={
|
|
132
|
+
className={clsx(
|
|
133
|
+
"inline-flex items-center rounded-lg border",
|
|
83
134
|
showLabel
|
|
84
|
-
? "
|
|
85
|
-
: "
|
|
86
|
-
|
|
135
|
+
? "gap-1.5 px-2.5 py-1.5 text-sm font-medium text-accent"
|
|
136
|
+
: "p-1.5 text-theme-text-secondary",
|
|
137
|
+
showLabel
|
|
138
|
+
? last
|
|
139
|
+
? "border-accent/50 bg-accent/10 hover:bg-accent/15"
|
|
140
|
+
: "border-accent/40 bg-accent/5 hover:bg-accent/10"
|
|
141
|
+
: last
|
|
142
|
+
? HISTORY_TINT
|
|
143
|
+
: "border-theme-border hover:bg-theme-hover hover:text-theme-text-primary",
|
|
144
|
+
)}
|
|
87
145
|
>
|
|
88
146
|
{running ? (
|
|
89
147
|
<Loader2 className="h-3.5 w-3.5 animate-spin text-accent" />
|
|
90
148
|
) : (
|
|
91
|
-
<Sparkles
|
|
149
|
+
<Sparkles
|
|
150
|
+
className="h-3.5 w-3.5 text-accent"
|
|
151
|
+
fill={last ? "currentColor" : "none"}
|
|
152
|
+
/>
|
|
92
153
|
)}
|
|
93
154
|
{running ? "Investigating…" : problem && "Investigate"}
|
|
94
155
|
</button>
|
|
95
156
|
</Tooltip>
|
|
96
157
|
);
|
|
158
|
+
if (!last) return button;
|
|
159
|
+
return (
|
|
160
|
+
<LastInvestigationPopover
|
|
161
|
+
last={last}
|
|
162
|
+
open={historyOpen}
|
|
163
|
+
onClose={closeHistory}
|
|
164
|
+
onOpenRun={() => d.openRun(last.id)}
|
|
165
|
+
actionLabel={
|
|
166
|
+
problem ? "Investigate again" : asks ? "Ask a question" : "Investigate"
|
|
167
|
+
}
|
|
168
|
+
onAction={act}
|
|
169
|
+
>
|
|
170
|
+
{button}
|
|
171
|
+
</LastInvestigationPopover>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// The resource's last investigation worth pointing at: local agents only,
|
|
176
|
+
// nothing while one is live, and not when the object was recreated since.
|
|
177
|
+
function useRecentInvestigation(
|
|
178
|
+
kind: string,
|
|
179
|
+
group: string | undefined,
|
|
180
|
+
namespace: string,
|
|
181
|
+
name: string,
|
|
182
|
+
createdAt?: string,
|
|
183
|
+
): LastInvestigation | undefined {
|
|
184
|
+
const d = useDiagnose();
|
|
185
|
+
const { runningRunIds, lastInvestigations } = useDiagnoseLayout();
|
|
186
|
+
const key = runTargetKey(kind, namespace, name, group ?? "");
|
|
187
|
+
const last = lastInvestigations.get(key);
|
|
188
|
+
return d.available &&
|
|
189
|
+
!d.hosted &&
|
|
190
|
+
!runningRunIds.has(key) &&
|
|
191
|
+
last &&
|
|
192
|
+
sameObject(last, createdAt)
|
|
193
|
+
? last
|
|
194
|
+
: undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// A resource with a recent investigation shows it the way a toggle shows it's
|
|
198
|
+
// on: a filled sparkle on a light accent tint, rather than a badge that would
|
|
199
|
+
// read as something unread.
|
|
200
|
+
const HISTORY_TINT =
|
|
201
|
+
"border-accent/30 bg-accent/5 hover:bg-accent/10 hover:text-theme-text-primary";
|
|
202
|
+
|
|
203
|
+
const POPOVER_WIDTH = 320;
|
|
204
|
+
const GUTTER = 16;
|
|
205
|
+
|
|
206
|
+
// Rendered in a portal at a fixed position: issue rows clip their contents,
|
|
207
|
+
// and Home's list scrolls. React events still bubble to the host row, so the
|
|
208
|
+
// panel stops them before they toggle it.
|
|
209
|
+
function LastInvestigationPopover({
|
|
210
|
+
last,
|
|
211
|
+
open,
|
|
212
|
+
onClose,
|
|
213
|
+
onOpenRun,
|
|
214
|
+
actionLabel,
|
|
215
|
+
onAction,
|
|
216
|
+
children,
|
|
217
|
+
}: {
|
|
218
|
+
last: LastInvestigation;
|
|
219
|
+
open: boolean;
|
|
220
|
+
onClose: () => void;
|
|
221
|
+
onOpenRun: () => void;
|
|
222
|
+
actionLabel: string;
|
|
223
|
+
onAction: () => void;
|
|
224
|
+
children: ReactNode;
|
|
225
|
+
}) {
|
|
226
|
+
const anchorRef = useRef<HTMLSpanElement>(null);
|
|
227
|
+
const panelRef = useRef<HTMLDivElement>(null);
|
|
228
|
+
const closeToTrigger = useCallback(() => {
|
|
229
|
+
onClose();
|
|
230
|
+
anchorRef.current?.querySelector<HTMLButtonElement>("button")?.focus();
|
|
231
|
+
}, [onClose]);
|
|
232
|
+
const { shouldRender, isOpen } = useAnimatedUnmount(
|
|
233
|
+
open,
|
|
234
|
+
overlayExitMs("menu"),
|
|
235
|
+
);
|
|
236
|
+
// Below the button, ending at its right edge, shifted to stay on screen: a
|
|
237
|
+
// phone's wrapped header can put the button anywhere along the row. Above
|
|
238
|
+
// it when there isn't room below (a bottom row).
|
|
239
|
+
const [position, setPosition] = useState({ top: 0, left: 0 });
|
|
240
|
+
useLayoutEffect(() => {
|
|
241
|
+
if (!open || !shouldRender || !anchorRef.current) return;
|
|
242
|
+
const anchor = anchorRef.current.getBoundingClientRect();
|
|
243
|
+
const width = Math.min(POPOVER_WIDTH, window.innerWidth - 2 * GUTTER);
|
|
244
|
+
const height = panelRef.current?.offsetHeight ?? 0;
|
|
245
|
+
const below = anchor.bottom + 6;
|
|
246
|
+
const above = anchor.top - 6 - height;
|
|
247
|
+
setPosition({
|
|
248
|
+
top:
|
|
249
|
+
below + height > window.innerHeight - GUTTER && above >= GUTTER
|
|
250
|
+
? above
|
|
251
|
+
: below,
|
|
252
|
+
left: Math.min(
|
|
253
|
+
Math.max(anchor.right - width, GUTTER),
|
|
254
|
+
window.innerWidth - GUTTER - width,
|
|
255
|
+
),
|
|
256
|
+
});
|
|
257
|
+
}, [open, shouldRender]);
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
if (!open) return;
|
|
260
|
+
const inside = (target: EventTarget | null) =>
|
|
261
|
+
target instanceof Node &&
|
|
262
|
+
(!!anchorRef.current?.contains(target) ||
|
|
263
|
+
!!panelRef.current?.contains(target));
|
|
264
|
+
const onPointer = (e: MouseEvent) => {
|
|
265
|
+
if (!inside(e.target)) onClose();
|
|
266
|
+
};
|
|
267
|
+
// Captured on window so Escape closes only this, not the drawer under it.
|
|
268
|
+
const onKey = (e: KeyboardEvent) => {
|
|
269
|
+
if (e.key !== "Escape") return;
|
|
270
|
+
e.stopPropagation();
|
|
271
|
+
e.preventDefault();
|
|
272
|
+
closeToTrigger();
|
|
273
|
+
};
|
|
274
|
+
// Its position is measured once on open, so moving the page closes it.
|
|
275
|
+
// Keyboard focus inside it goes back to the button, which stays put.
|
|
276
|
+
const dismiss = () => {
|
|
277
|
+
if (panelRef.current?.contains(document.activeElement)) {
|
|
278
|
+
onClose();
|
|
279
|
+
anchorRef.current
|
|
280
|
+
?.querySelector<HTMLButtonElement>("button")
|
|
281
|
+
?.focus({ preventScroll: true });
|
|
282
|
+
} else onClose();
|
|
283
|
+
};
|
|
284
|
+
const onScroll = (e: Event) => {
|
|
285
|
+
if (!inside(e.target)) dismiss();
|
|
286
|
+
};
|
|
287
|
+
document.addEventListener("mousedown", onPointer, true);
|
|
288
|
+
window.addEventListener("keydown", onKey, true);
|
|
289
|
+
window.addEventListener("resize", dismiss);
|
|
290
|
+
window.addEventListener("scroll", onScroll, true);
|
|
291
|
+
return () => {
|
|
292
|
+
document.removeEventListener("mousedown", onPointer, true);
|
|
293
|
+
window.removeEventListener("keydown", onKey, true);
|
|
294
|
+
window.removeEventListener("resize", dismiss);
|
|
295
|
+
window.removeEventListener("scroll", onScroll, true);
|
|
296
|
+
};
|
|
297
|
+
}, [open, onClose, closeToTrigger]);
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
if (open && shouldRender)
|
|
300
|
+
panelRef.current?.querySelector<HTMLButtonElement>("button")?.focus();
|
|
301
|
+
}, [open, shouldRender]);
|
|
302
|
+
// The panel sits at the end of the page in DOM order, so tabbing out of it
|
|
303
|
+
// goes back to the button rather than to wherever the portal landed.
|
|
304
|
+
const onPanelKeyDown = (e: ReactKeyboardEvent) => {
|
|
305
|
+
e.stopPropagation();
|
|
306
|
+
if (e.key !== "Tab") return;
|
|
307
|
+
const buttons = panelRef.current?.querySelectorAll("button");
|
|
308
|
+
if (!buttons?.length) return;
|
|
309
|
+
const edge = e.shiftKey ? buttons[0] : buttons[buttons.length - 1];
|
|
310
|
+
if (document.activeElement !== edge) return;
|
|
311
|
+
e.preventDefault();
|
|
312
|
+
closeToTrigger();
|
|
313
|
+
};
|
|
314
|
+
const choose = (fn: () => void) => () => {
|
|
315
|
+
onClose();
|
|
316
|
+
fn();
|
|
317
|
+
};
|
|
318
|
+
return (
|
|
319
|
+
<span ref={anchorRef} className="inline-flex">
|
|
320
|
+
{children}
|
|
321
|
+
{shouldRender &&
|
|
322
|
+
createPortal(
|
|
323
|
+
<div
|
|
324
|
+
ref={panelRef}
|
|
325
|
+
role="dialog"
|
|
326
|
+
aria-label="Last investigation"
|
|
327
|
+
inert={!open || undefined}
|
|
328
|
+
onClick={(e) => e.stopPropagation()}
|
|
329
|
+
onKeyDown={onPanelKeyDown}
|
|
330
|
+
className={clsx(
|
|
331
|
+
"fixed z-50 w-80 max-w-[calc(100vw-2rem)] origin-top-right rounded-lg border border-theme-border bg-theme-surface p-3 text-left shadow-theme-lg",
|
|
332
|
+
TRANSITION_MENU,
|
|
333
|
+
isOpen ? "scale-100 opacity-100" : "scale-[0.97] opacity-0",
|
|
334
|
+
!open && "pointer-events-none",
|
|
335
|
+
)}
|
|
336
|
+
style={{ ...overlayTransitionStyle(isOpen, "menu"), ...position }}
|
|
337
|
+
>
|
|
338
|
+
<div className="text-xs text-theme-text-tertiary">
|
|
339
|
+
Investigated {formatRelativeAgeTime(last.assessedAt)}
|
|
340
|
+
</div>
|
|
341
|
+
<p className="mt-1 line-clamp-4 text-sm text-theme-text-primary">
|
|
342
|
+
{last.preview}
|
|
343
|
+
</p>
|
|
344
|
+
<div className="mt-3 flex items-center gap-2">
|
|
345
|
+
<button
|
|
346
|
+
type="button"
|
|
347
|
+
onClick={choose(onOpenRun)}
|
|
348
|
+
className="btn-brand rounded-md px-2.5 py-1 text-xs font-medium"
|
|
349
|
+
>
|
|
350
|
+
Open investigation
|
|
351
|
+
</button>
|
|
352
|
+
<button
|
|
353
|
+
type="button"
|
|
354
|
+
onClick={choose(onAction)}
|
|
355
|
+
className="rounded-md border border-theme-border px-2.5 py-1 text-xs text-theme-text-secondary hover:bg-theme-hover hover:text-theme-text-primary"
|
|
356
|
+
>
|
|
357
|
+
{actionLabel}
|
|
358
|
+
</button>
|
|
359
|
+
</div>
|
|
360
|
+
</div>,
|
|
361
|
+
document.body,
|
|
362
|
+
)}
|
|
363
|
+
</span>
|
|
364
|
+
);
|
|
97
365
|
}
|
|
98
366
|
|
|
99
367
|
export const defaultDiagnoseAction: RenderDiagnoseAction = ({
|
|
@@ -102,6 +370,7 @@ export const defaultDiagnoseAction: RenderDiagnoseAction = ({
|
|
|
102
370
|
namespace,
|
|
103
371
|
name,
|
|
104
372
|
health,
|
|
373
|
+
createdAt,
|
|
105
374
|
}) => (
|
|
106
375
|
<DiagnoseResourceButton
|
|
107
376
|
kind={kind}
|
|
@@ -109,61 +378,118 @@ export const defaultDiagnoseAction: RenderDiagnoseAction = ({
|
|
|
109
378
|
namespace={namespace}
|
|
110
379
|
name={name}
|
|
111
380
|
health={health}
|
|
381
|
+
createdAt={createdAt}
|
|
112
382
|
/>
|
|
113
383
|
);
|
|
114
384
|
|
|
385
|
+
// Whether the per-issue Investigate action renders here at all, for hosts
|
|
386
|
+
// that lay out around it.
|
|
387
|
+
export function useIssueDiagnoseShown(): boolean {
|
|
388
|
+
const d = useDiagnose();
|
|
389
|
+
return d.setupState !== "off" && d.setupState !== "unknown";
|
|
390
|
+
}
|
|
391
|
+
|
|
115
392
|
// Compact per-issue "Investigate" action for the Issues queue — launches an
|
|
116
393
|
// investigation for the issue's subject from where the problem is surfaced.
|
|
117
|
-
// stopPropagation so it doesn't toggle the issue row it lives in.
|
|
394
|
+
// stopPropagation so it doesn't toggle the issue row it lives in. `compact`
|
|
395
|
+
// fits a single line of a dense list (Home's Active Issues); without hover it
|
|
396
|
+
// keeps a finger-sized target. A resource investigated recently gets the same
|
|
397
|
+
// marking and panel as the resource view's button.
|
|
118
398
|
export function IssueDiagnoseButton({
|
|
119
399
|
kind,
|
|
120
400
|
group,
|
|
121
401
|
namespace,
|
|
122
402
|
name,
|
|
403
|
+
size = "default",
|
|
123
404
|
}: {
|
|
124
405
|
kind: string;
|
|
125
406
|
group?: string;
|
|
126
407
|
namespace: string;
|
|
127
408
|
name: string;
|
|
409
|
+
size?: "default" | "compact";
|
|
128
410
|
}) {
|
|
129
411
|
const d = useDiagnose();
|
|
130
|
-
|
|
412
|
+
const shown = useIssueDiagnoseShown();
|
|
413
|
+
const last = useRecentInvestigation(kind, group, namespace, name);
|
|
414
|
+
const [historyOpen, setHistoryOpen] = useState(false);
|
|
415
|
+
const closeHistory = useCallback(() => setHistoryOpen(false), []);
|
|
416
|
+
if (historyOpen && !last) setHistoryOpen(false);
|
|
417
|
+
if (!shown) return null;
|
|
131
418
|
const ready = d.available;
|
|
132
|
-
|
|
419
|
+
const investigate = () => {
|
|
420
|
+
recordUsageEvent({ type: "ui", name: "issue_action:investigate" });
|
|
421
|
+
if (ready)
|
|
422
|
+
d.openInvestigation({ kind, group: group ?? "", namespace, name });
|
|
423
|
+
else d.openHome();
|
|
424
|
+
};
|
|
425
|
+
const button = (
|
|
133
426
|
<Tooltip
|
|
134
427
|
content={
|
|
135
428
|
!ready
|
|
136
429
|
? notReadyTooltip(d)
|
|
137
|
-
:
|
|
138
|
-
? `
|
|
139
|
-
:
|
|
430
|
+
: last
|
|
431
|
+
? `Investigated ${formatRelativeAgeTime(last.assessedAt)} — click to see what it found.`
|
|
432
|
+
: d.hosted
|
|
433
|
+
? `Sends this resource's context to ${d.agentLabel} for investigation`
|
|
434
|
+
: `Runs ${d.agentLabel} on your machine to investigate this resource`
|
|
140
435
|
}
|
|
141
436
|
position="left"
|
|
437
|
+
disabled={historyOpen}
|
|
438
|
+
preserveWrapperWhenDisabled
|
|
142
439
|
>
|
|
143
440
|
<button
|
|
144
441
|
onClick={(e) => {
|
|
145
442
|
e.stopPropagation();
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
kind,
|
|
149
|
-
group: group ?? "",
|
|
150
|
-
namespace,
|
|
151
|
-
name,
|
|
152
|
-
});
|
|
153
|
-
else d.openHome();
|
|
443
|
+
if (last) setHistoryOpen((o) => !o);
|
|
444
|
+
else investigate();
|
|
154
445
|
}}
|
|
155
|
-
|
|
446
|
+
aria-haspopup={last ? "dialog" : undefined}
|
|
447
|
+
aria-expanded={last ? historyOpen : undefined}
|
|
448
|
+
className={clsx(
|
|
449
|
+
"flex shrink-0 items-center gap-1 border text-theme-text-secondary",
|
|
450
|
+
size === "compact"
|
|
451
|
+
? "h-4 rounded px-1.5 text-[10.5px] leading-none [@media(hover:none)]:h-7 [@media(hover:none)]:rounded-md [@media(hover:none)]:px-2.5 [@media(hover:none)]:text-xs"
|
|
452
|
+
: "rounded-md px-2 py-1 text-xs",
|
|
453
|
+
last
|
|
454
|
+
? HISTORY_TINT
|
|
455
|
+
: clsx(
|
|
456
|
+
"border-theme-border hover:text-theme-text-primary",
|
|
457
|
+
size === "compact"
|
|
458
|
+
? "hover:bg-theme-surface"
|
|
459
|
+
: "hover:bg-theme-hover",
|
|
460
|
+
),
|
|
461
|
+
)}
|
|
156
462
|
>
|
|
157
|
-
<Sparkles
|
|
463
|
+
<Sparkles
|
|
464
|
+
className={
|
|
465
|
+
size === "compact"
|
|
466
|
+
? "h-2.5 w-2.5 text-accent"
|
|
467
|
+
: "h-3 w-3 text-accent"
|
|
468
|
+
}
|
|
469
|
+
fill={last ? "currentColor" : "none"}
|
|
470
|
+
/>
|
|
158
471
|
Investigate
|
|
159
472
|
</button>
|
|
160
473
|
</Tooltip>
|
|
161
474
|
);
|
|
475
|
+
if (!last) return button;
|
|
476
|
+
return (
|
|
477
|
+
<LastInvestigationPopover
|
|
478
|
+
last={last}
|
|
479
|
+
open={historyOpen}
|
|
480
|
+
onClose={closeHistory}
|
|
481
|
+
onOpenRun={() => d.openRun(last.id)}
|
|
482
|
+
actionLabel="Investigate again"
|
|
483
|
+
onAction={investigate}
|
|
484
|
+
>
|
|
485
|
+
{button}
|
|
486
|
+
</LastInvestigationPopover>
|
|
487
|
+
);
|
|
162
488
|
}
|
|
163
489
|
|
|
164
490
|
// The tooltip every AI entry point shows while investigations aren't runnable.
|
|
165
491
|
// It gives the same reason as the setup notice the button opens.
|
|
166
|
-
function notReadyTooltip(d: {
|
|
492
|
+
export function notReadyTooltip(d: {
|
|
167
493
|
cliOverride: boolean;
|
|
168
494
|
setupState: DiagnoseSetup;
|
|
169
495
|
}): string {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import type { Diagnosis } from "../../api/diagnose";
|
|
5
|
+
import { NextStepJump, recommendedStepHeadline } from "./NextStepJump";
|
|
6
|
+
|
|
7
|
+
function diagnosis(steps: string[], recommendedIndex = 1): Diagnosis {
|
|
8
|
+
return {
|
|
9
|
+
rootCause: "cause",
|
|
10
|
+
remediation: steps,
|
|
11
|
+
steps: steps.map((text) => ({ text, kind: "mitigate" })),
|
|
12
|
+
recommendedIndex,
|
|
13
|
+
} as Diagnosis;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const long =
|
|
17
|
+
"Confirm with the owner, or in the manifest source, what `read-a/api` is supposed to route to, because the live route points at a Service that no longer exists. Then fix it.";
|
|
18
|
+
|
|
19
|
+
describe("recommendedStepHeadline", () => {
|
|
20
|
+
it("keeps a short first sentence and drops the dangling colon", () => {
|
|
21
|
+
expect(
|
|
22
|
+
recommendedStepHeadline(
|
|
23
|
+
diagnosis(["Move web off the broken node:\n`kubectl drain node-1`"]),
|
|
24
|
+
),
|
|
25
|
+
).toBe("Move web off the broken node");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("keeps a ~60-character sentence whole instead of cutting it", () => {
|
|
29
|
+
expect(
|
|
30
|
+
recommendedStepHeadline(
|
|
31
|
+
diagnosis([
|
|
32
|
+
"Stop new pods landing on the broken node and move this one: `kubectl cordon n1`",
|
|
33
|
+
]),
|
|
34
|
+
),
|
|
35
|
+
).toBe("Stop new pods landing on the broken node and move this one");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("keeps a very long first sentence whole, without its markdown or later sentences", () => {
|
|
39
|
+
const headline = recommendedStepHeadline(diagnosis([long]));
|
|
40
|
+
expect(headline).toBe(
|
|
41
|
+
"Confirm with the owner, or in the manifest source, what read-a/api is supposed to route to, because the live route points at a Service that no longer exists.",
|
|
42
|
+
);
|
|
43
|
+
expect(headline).not.toContain("…");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("names the recommended step, not the first", () => {
|
|
47
|
+
expect(
|
|
48
|
+
recommendedStepHeadline(
|
|
49
|
+
diagnosis(
|
|
50
|
+
["Read the AWS CNI logs on the node.", "Restart aws-node."],
|
|
51
|
+
2,
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
).toBe("Restart aws-node.");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("has nothing to name without a step", () => {
|
|
58
|
+
expect(recommendedStepHeadline(undefined)).toBeUndefined();
|
|
59
|
+
expect(recommendedStepHeadline(diagnosis([]))).toBeUndefined();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("NextStepJump", () => {
|
|
64
|
+
it("renders the whole sentence under a two-line clamp with the arrow outside it", () => {
|
|
65
|
+
const headline = recommendedStepHeadline(diagnosis([long]))!;
|
|
66
|
+
const html = renderToStaticMarkup(
|
|
67
|
+
createElement(NextStepJump, { headline, onClick: () => {} }),
|
|
68
|
+
);
|
|
69
|
+
expect(html).toContain(`Next: ${headline}`);
|
|
70
|
+
expect(html).toMatch(/class="line-clamp-2[^"]*">Next: /);
|
|
71
|
+
expect(html).toMatch(/aria-hidden="true"[^>]*>↓<\/span><\/button>/);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("uses the given label for an earlier plan", () => {
|
|
75
|
+
const html = renderToStaticMarkup(
|
|
76
|
+
createElement(NextStepJump, {
|
|
77
|
+
label: "Earlier proposed steps",
|
|
78
|
+
headline: "Move web off the broken node",
|
|
79
|
+
onClick: () => {},
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
82
|
+
expect(html).toContain("Earlier proposed steps");
|
|
83
|
+
expect(html).not.toContain("Move web");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("falls back to the section name without a headline", () => {
|
|
87
|
+
const html = renderToStaticMarkup(
|
|
88
|
+
createElement(NextStepJump, { onClick: () => {} }),
|
|
89
|
+
);
|
|
90
|
+
expect(html).toContain(">Next steps<");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import type { Diagnosis } from "../../api/diagnose";
|
|
3
|
+
import { Tooltip } from "../ui/Tooltip";
|
|
4
|
+
import { remediationHeadline } from "./AssessmentCard";
|
|
5
|
+
|
|
6
|
+
/** The first sentence of the step Apply would perform, or of the first step. */
|
|
7
|
+
export function recommendedStepHeadline(
|
|
8
|
+
diagnosis: Diagnosis | null | undefined,
|
|
9
|
+
): string | undefined {
|
|
10
|
+
if (!diagnosis) return undefined;
|
|
11
|
+
const index = diagnosis.recommendedIndex ? diagnosis.recommendedIndex - 1 : 0;
|
|
12
|
+
const text =
|
|
13
|
+
diagnosis.steps?.[index]?.text ??
|
|
14
|
+
diagnosis.remediation?.[index] ??
|
|
15
|
+
diagnosis.remediation?.[0];
|
|
16
|
+
return text ? remediationHeadline(text) || undefined : undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The assessment's jump link to Next steps. It names the decision it leads
|
|
21
|
+
* to in one whole sentence; the clamp keeps a long sentence from growing the
|
|
22
|
+
* card, and the full sentence is on hover only when the clamp hid some of it.
|
|
23
|
+
*/
|
|
24
|
+
export function NextStepJump({
|
|
25
|
+
label,
|
|
26
|
+
headline,
|
|
27
|
+
onClick,
|
|
28
|
+
}: {
|
|
29
|
+
label?: string;
|
|
30
|
+
headline?: string;
|
|
31
|
+
onClick: () => void;
|
|
32
|
+
}) {
|
|
33
|
+
const textRef = useRef<HTMLSpanElement>(null);
|
|
34
|
+
const [clamped, setClamped] = useState(false);
|
|
35
|
+
useLayoutEffect(() => {
|
|
36
|
+
const el = textRef.current;
|
|
37
|
+
if (!el) return;
|
|
38
|
+
const measure = () =>
|
|
39
|
+
setClamped(
|
|
40
|
+
el.scrollHeight > el.clientHeight + 1 ||
|
|
41
|
+
el.scrollWidth > el.clientWidth + 1,
|
|
42
|
+
);
|
|
43
|
+
measure();
|
|
44
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
45
|
+
const observer = new ResizeObserver(measure);
|
|
46
|
+
observer.observe(el);
|
|
47
|
+
return () => observer.disconnect();
|
|
48
|
+
}, [headline, label]);
|
|
49
|
+
|
|
50
|
+
const text = label ?? (headline ? `Next: ${headline}` : "Next steps");
|
|
51
|
+
return (
|
|
52
|
+
<Tooltip
|
|
53
|
+
content={headline}
|
|
54
|
+
disabled={!clamped || !headline || label !== undefined}
|
|
55
|
+
preserveWrapperWhenDisabled
|
|
56
|
+
wrapperClassName="block"
|
|
57
|
+
>
|
|
58
|
+
<button
|
|
59
|
+
type="button"
|
|
60
|
+
onClick={onClick}
|
|
61
|
+
className="flex max-w-md items-start gap-1 rounded-md px-2 py-1 text-left text-xs font-medium text-accent-text hover:bg-theme-hover"
|
|
62
|
+
>
|
|
63
|
+
<span
|
|
64
|
+
ref={textRef}
|
|
65
|
+
className="line-clamp-2 min-w-0 [overflow-wrap:anywhere]"
|
|
66
|
+
>
|
|
67
|
+
{text}
|
|
68
|
+
</span>
|
|
69
|
+
<span aria-hidden="true" className="shrink-0">
|
|
70
|
+
↓
|
|
71
|
+
</span>
|
|
72
|
+
</button>
|
|
73
|
+
</Tooltip>
|
|
74
|
+
);
|
|
75
|
+
}
|