@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.
Files changed (228) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -7
  3. package/src/App.tsx +31 -6
  4. package/src/api/application-evidence.ts +63 -0
  5. package/src/api/argoSync.test.ts +22 -0
  6. package/src/api/client.audit-gating.test.tsx +48 -0
  7. package/src/api/client.kueuePosition.test.ts +32 -0
  8. package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
  9. package/src/api/client.resource-identity.test.ts +3 -0
  10. package/src/api/client.resourceIssues.test.tsx +239 -0
  11. package/src/api/client.resourcePath.test.ts +3 -0
  12. package/src/api/client.ts +285 -55
  13. package/src/api/config.ts +21 -0
  14. package/src/api/diagnose.test.ts +33 -2
  15. package/src/api/diagnose.ts +97 -3
  16. package/src/api/radarFeatures.render.test.tsx +33 -1
  17. package/src/api/radarFeatures.test.ts +47 -0
  18. package/src/api/radarFeatures.ts +41 -1
  19. package/src/api/rbac.settled.test.tsx +42 -0
  20. package/src/api/rbac.test.ts +18 -0
  21. package/src/api/rbac.ts +37 -7
  22. package/src/api/traffic.ts +9 -4
  23. package/src/api/usage-data.fixtures.ts +3 -1
  24. package/src/api/usage-data.test.tsx +134 -0
  25. package/src/api/usage-data.ts +35 -7
  26. package/src/api/workloadPodsPolling.test.ts +26 -0
  27. package/src/components/CloudConnectFlow.test.tsx +86 -0
  28. package/src/components/CloudConnectFlow.tsx +65 -27
  29. package/src/components/CloudFunnelButton.test.tsx +140 -5
  30. package/src/components/CloudFunnelButton.tsx +50 -9
  31. package/src/components/ConnectionErrorView.test.tsx +34 -0
  32. package/src/components/ConnectionErrorView.tsx +35 -11
  33. package/src/components/ContextSwitcher.tsx +5 -2
  34. package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
  35. package/src/components/SwitchAwareConnectionError.tsx +85 -0
  36. package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
  37. package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
  38. package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
  39. package/src/components/capacity/CapacityDemand.tsx +3 -2
  40. package/src/components/capacity/demandSummary.test.ts +38 -0
  41. package/src/components/capacity/shared.tsx +12 -1
  42. package/src/components/cost/ApplicationCostTab.tsx +4 -0
  43. package/src/components/cost/CostTrendChart.tsx +2 -0
  44. package/src/components/cost/WorkloadCostTab.tsx +4 -0
  45. package/src/components/cost/source.test.ts +5 -0
  46. package/src/components/cost/source.ts +11 -0
  47. package/src/components/diagnose/AIMarkdown.tsx +4 -1
  48. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  49. package/src/components/diagnose/AgentControls.tsx +53 -6
  50. package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
  51. package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
  52. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  53. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  54. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  55. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  56. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  57. package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
  58. package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
  59. package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
  60. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  61. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  62. package/src/components/diagnose/DiagnoseContext.tsx +272 -10
  63. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  64. package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
  65. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  66. package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
  67. package/src/components/diagnose/Home.test.tsx +208 -5
  68. package/src/components/diagnose/Home.tsx +187 -36
  69. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  70. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  71. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  72. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  73. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  74. package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
  75. package/src/components/diagnose/InvestigationView.tsx +249 -54
  76. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
  77. package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
  78. package/src/components/diagnose/NextStepJump.test.tsx +92 -0
  79. package/src/components/diagnose/NextStepJump.tsx +75 -0
  80. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  81. package/src/components/diagnose/QuestionComposer.tsx +495 -0
  82. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  83. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  84. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  85. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  86. package/src/components/diagnose/assessmentCopy.ts +5 -0
  87. package/src/components/diagnose/exampleInvestigation.events.json +191 -0
  88. package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
  89. package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
  90. package/src/components/diagnose/exampleInvestigation.ts +121 -0
  91. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  92. package/src/components/diagnose/investigationCase.test.tsx +9 -1
  93. package/src/components/diagnose/investigationCase.ts +33 -1
  94. package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
  95. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  96. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
  97. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
  98. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  99. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  100. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  101. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  102. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  103. package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
  104. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  105. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  106. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  107. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  108. package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
  109. package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
  110. package/src/components/diagnose/investigationEvidence/types.ts +7 -0
  111. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  112. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  113. package/src/components/diagnose/investigationFocus.ts +132 -0
  114. package/src/components/diagnose/investigationState.ts +28 -0
  115. package/src/components/diagnose/lastInvestigation.test.ts +95 -0
  116. package/src/components/diagnose/lastInvestigation.ts +58 -0
  117. package/src/components/diagnose/launch.test.ts +125 -1
  118. package/src/components/diagnose/launch.ts +57 -10
  119. package/src/components/diagnose/parts.test.tsx +20 -0
  120. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  121. package/src/components/diagnose/questionSuggestions.ts +150 -0
  122. package/src/components/diagnose/storyParts.test.tsx +13 -0
  123. package/src/components/diagnose/target.test.ts +143 -2
  124. package/src/components/diagnose/target.ts +109 -7
  125. package/src/components/diagnose/testdata/story-runs.json +474 -0
  126. package/src/components/diagnose/toolCallLabel.test.ts +10 -4
  127. package/src/components/diagnose/verdictText.test.tsx +87 -0
  128. package/src/components/diagnose/verdictText.ts +68 -0
  129. package/src/components/execution/BatchExecutionView.tsx +24 -11
  130. package/src/components/execution/JobSetAdmission.test.tsx +42 -0
  131. package/src/components/execution/JobSetAdmission.tsx +18 -3
  132. package/src/components/execution/JobSetMemberComparison.tsx +2 -1
  133. package/src/components/execution/runState.test.ts +14 -0
  134. package/src/components/execution/runState.ts +8 -0
  135. package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
  136. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
  137. package/src/components/gitops/GitOpsView.tsx +86 -17
  138. package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
  139. package/src/components/gitops/destination-toast.test.ts +1 -1
  140. package/src/components/gitops/destination-toast.ts +2 -2
  141. package/src/components/home/ClusterHealthCard.tsx +13 -39
  142. package/src/components/home/HomeAgentBlock.test.tsx +141 -0
  143. package/src/components/home/HomeAgentBlock.tsx +103 -0
  144. package/src/components/home/HomeDiagramCard.tsx +47 -0
  145. package/src/components/home/HomeView.tsx +86 -47
  146. package/src/components/home/MCPSetupDialog.test.tsx +95 -5
  147. package/src/components/home/MCPSetupDialog.tsx +30 -5
  148. package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
  149. package/src/components/home/ProblemsPanel.test.tsx +3 -1
  150. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  151. package/src/components/home/RadarVersionLine.tsx +3 -28
  152. package/src/components/home/TopologyPreview.test.tsx +73 -0
  153. package/src/components/home/TopologyPreview.tsx +120 -233
  154. package/src/components/home/TrafficSummary.test.tsx +63 -0
  155. package/src/components/home/TrafficSummary.tsx +135 -138
  156. package/src/components/home/mcpToolCatalog.ts +23 -10
  157. package/src/components/issues/IssuesPane.test.ts +11 -0
  158. package/src/components/issues/IssuesPane.tsx +15 -5
  159. package/src/components/issues/uncheckedSources.test.ts +20 -1
  160. package/src/components/issues/uncheckedSources.ts +18 -0
  161. package/src/components/kueue/KueuePendingPosition.tsx +35 -0
  162. package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
  163. package/src/components/kueue/useRelatedReads.test.ts +56 -0
  164. package/src/components/kueue/useRelatedReads.ts +205 -0
  165. package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
  166. package/src/components/logs/MultiPodLogsTab.tsx +120 -0
  167. package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
  168. package/src/components/logs/PodLogsUnavailable.tsx +21 -0
  169. package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
  170. package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
  171. package/src/components/logs/RayClusterLogsTab.tsx +109 -0
  172. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
  173. package/src/components/logs/rayClusterPods.ts +32 -0
  174. package/src/components/outageSince.test.ts +21 -0
  175. package/src/components/outageSince.ts +10 -0
  176. package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
  177. package/src/components/resource/PrometheusCharts.tsx +3 -40
  178. package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
  179. package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
  180. package/src/components/resources/crd/host.tsx +14 -0
  181. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
  182. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
  183. package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
  184. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
  185. package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
  186. package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
  187. package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
  188. package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
  189. package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
  190. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
  191. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
  192. package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
  193. package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
  194. package/src/components/traffic/TrafficView.tsx +3 -3
  195. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  196. package/src/components/ui/Omnibar.tsx +47 -3
  197. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  198. package/src/components/ui/RadarOmnibar.tsx +11 -0
  199. package/src/components/ui/command-items-crd.test.tsx +23 -0
  200. package/src/components/ui/command-items.ts +2 -1
  201. package/src/components/useContextSwitchFlow.test.tsx +61 -0
  202. package/src/components/useContextSwitchFlow.tsx +21 -4
  203. package/src/components/whats-new/WhatsNew.test.ts +10 -3
  204. package/src/components/whats-new/WhatsNew.tsx +5 -1
  205. package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
  206. package/src/components/whats-new/releaseNotes.ts +136 -4
  207. package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
  208. package/src/components/workload/RelatedFindingsSection.tsx +80 -0
  209. package/src/components/workload/WorkloadView.test.ts +10 -1
  210. package/src/components/workload/WorkloadView.tsx +85 -98
  211. package/src/components/workload/issueResourceOpener.test.ts +20 -0
  212. package/src/components/workload/issueResourceOpener.ts +17 -0
  213. package/src/context/ConnectionContext.tsx +133 -60
  214. package/src/context/ConnectionProvider.retry.test.tsx +176 -0
  215. package/src/context/ContextSwitchContext.tsx +14 -1
  216. package/src/context/DiagnoseCustomization.tsx +3 -0
  217. package/src/context/clusterConnected.ts +10 -0
  218. package/src/contexts/CapabilitiesContext.tsx +6 -4
  219. package/src/hooks/useAgentSignin.test.tsx +190 -0
  220. package/src/hooks/useAgentSignin.ts +160 -0
  221. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
  222. package/src/hooks/useElementSize.ts +30 -0
  223. package/src/integrations/resourceHost.test.tsx +1 -0
  224. package/src/integrations/resourceHost.ts +5 -1
  225. package/src/integrations/resourceHosts.test.tsx +21 -4
  226. package/src/integrations/resourceHosts.tsx +12 -0
  227. package/src/main.tsx +5 -0
  228. package/src/utils/related-findings.ts +46 -0
@@ -1,5 +1,5 @@
1
- import { useEffect, useId, useState } from 'react'
2
- import { useMutation, useQueryClient } from '@tanstack/react-query'
1
+ import { useEffect, useId, useRef, useState } from 'react'
2
+ import { useIsMutating, useMutation, useQueryClient } from '@tanstack/react-query'
3
3
  import { Bell, Check, Cloud, Globe, History, Sparkles, Users, X } from 'lucide-react'
4
4
  import { Collapse, CollapseChevron } from '@skyhook-io/k8s-ui/components/ui/Collapse'
5
5
  import { DialogPortal } from '@skyhook-io/k8s-ui/components/ui/DialogPortal'
@@ -22,6 +22,7 @@ import {
22
22
  type CloudConnectSelf,
23
23
  type CloudInstallConnectedRadar,
24
24
  type CloudInstallBlocked,
25
+ type CloudInstallStage,
25
26
  type CloudInstallStatus,
26
27
  prepareCloudInstall,
27
28
  useCapabilities,
@@ -76,6 +77,7 @@ const ABOUT_URL = 'https://radarhq.io/about'
76
77
  const BENCHMARK_URL = 'https://radarhq.io/benchmark'
77
78
  const PRICING_URL = 'https://radarhq.io/pricing'
78
79
  const SEEN_KEY = 'radar.cloudFunnel.seen'
80
+ const PREPARE_MUTATION_KEY = ['cloud-install-prepare']
79
81
 
80
82
  // localStorage access can throw (SecurityError) where storage is denied —
81
83
  // sandboxed embeds, some privacy modes. This button mounts in the top bar
@@ -104,6 +106,17 @@ export function CloudFunnelButton() {
104
106
  const [inFlowView, setInFlowView] = useState(false)
105
107
  const [selfManaged, setSelfManaged] = useState(false)
106
108
  const [blocked, setBlocked] = useState<CloudInstallBlocked | null>(null)
109
+ // The server flow this attempt was seen preparing, and the furthest check it
110
+ // reached. A blocked preparation clears the flow before its request answers,
111
+ // so a poll in between reads idle; the synthesized view resumes at this
112
+ // step rather than the first. Only this flow can stand in for a prepare
113
+ // answer that was lost: a status from before the click, or another flow
114
+ // fetched late, says nothing about this attempt.
115
+ const [seenPreparing, setSeenPreparing] = useState<{ flowId: string; step?: CloudInstallStage } | null>(null)
116
+ // Identifies the latest Connect attempt. The status poll can show a plan
117
+ // before its prepare request answers, so the person may move on and start
118
+ // again; a late answer from an earlier attempt must not act on the new one.
119
+ const attemptRef = useRef(0)
107
120
  // Set once an in-app attempt has ended without connecting, naming what
108
121
  // happened (a flow failure kind, a blocked plan, a canceled plan, or the
109
122
  // prepare call itself failing) and whether it is worth trying again. It
@@ -157,7 +170,8 @@ export function CloudFunnelButton() {
157
170
 
158
171
  // The flow is server-owned: polling here both drives the live progress view
159
172
  // and re-attaches to an ongoing flow after a reload or modal close.
160
- const flowStatus = useCloudInstallStatus(lane === 'driver')
173
+ const preparing = useIsMutating({ mutationKey: PREPARE_MUTATION_KEY }) > 0
174
+ const flowStatus = useCloudInstallStatus(lane === 'driver', preparing)
161
175
  const flow = flowStatus.data
162
176
  const flowLive = cloudInstallActive(flow?.state) || flow?.state === 'connected' || flow?.state === 'failed'
163
177
 
@@ -167,13 +181,17 @@ export function CloudFunnelButton() {
167
181
  flowStatus.invalidate()
168
182
  }
169
183
 
170
- const prepare = useMutation({
171
- mutationFn: prepareCloudInstall,
172
- onSuccess: (st) => {
184
+ // The variable is the attempt id, read back in the callbacks.
185
+ const prepare = useMutation<CloudInstallStatus, Error, number>({
186
+ mutationKey: PREPARE_MUTATION_KEY,
187
+ mutationFn: () => prepareCloudInstall(),
188
+ onSuccess: (st, attempt) => {
189
+ if (attempt !== attemptRef.current) return
173
190
  if (st.state === 'blocked' && st.blocked) setBlocked(st.blocked)
174
191
  else applyStatus(st)
175
192
  },
176
- onError: (err) => {
193
+ onError: (err, attempt) => {
194
+ if (attempt !== attemptRef.current) return
177
195
  // A single-flight 409 is not a failure: its body IS the live flow (one
178
196
  // started in another tab, or before this tab's status cache refreshed).
179
197
  // Attach to it rather than showing an error over a running install.
@@ -182,6 +200,20 @@ export function CloudFunnelButton() {
182
200
  applyStatus(live)
183
201
  return
184
202
  }
203
+ // The status poll may already have seen this attempt's preparation
204
+ // finish (and the flow move on from there): only this request's answer
205
+ // was lost. Stay on what the server reports rather than calling a
206
+ // finished inspection a failure.
207
+ const polled = queryClient.getQueryData<CloudInstallStatus>(['cloud-install-status'])
208
+ if (
209
+ polled?.flowId &&
210
+ polled.flowId === seenPreparing?.flowId &&
211
+ polled.state !== 'idle' &&
212
+ polled.state !== 'preparing'
213
+ ) {
214
+ flowStatus.invalidate()
215
+ return
216
+ }
185
217
  // Anything else failed before a flow existed. Return to the pitch rather
186
218
  // than leaving the flow view armed, where a later status change would
187
219
  // pull the user into a screen they did not ask for.
@@ -205,8 +237,10 @@ export function CloudFunnelButton() {
205
237
  const startConnect = () => {
206
238
  setBlocked(null)
207
239
  setHandoff(null)
240
+ setSeenPreparing(null)
208
241
  setInFlowView(true)
209
- prepare.mutate()
242
+ attemptRef.current += 1
243
+ prepare.mutate(attemptRef.current)
210
244
  }
211
245
 
212
246
  // A flow that ended without connecting returns to a pitch whose CTA must
@@ -242,6 +276,13 @@ export function CloudFunnelButton() {
242
276
  return { outcome: 'install_plan_canceled', retryable: false }
243
277
  }
244
278
 
279
+ const observed = prepare.isPending && flow?.state === 'preparing' ? flow : undefined
280
+ if (observed?.flowId) {
281
+ const sameFlow = observed.flowId === seenPreparing?.flowId
282
+ const step = observed.prepareStep ?? (sameFlow ? seenPreparing?.step : undefined)
283
+ if (!sameFlow || step !== seenPreparing?.step) setSeenPreparing({ flowId: observed.flowId, step })
284
+ }
285
+
245
286
  useEffect(() => {
246
287
  window.addEventListener(OPEN_EVENT, openModal)
247
288
  return () => window.removeEventListener(OPEN_EVENT, openModal)
@@ -280,7 +321,7 @@ export function CloudFunnelButton() {
280
321
  // explanation back to the pitch.
281
322
  const flowForView: CloudInstallStatus | undefined =
282
323
  prepare.isPending && !flowLive
283
- ? { state: 'preparing' }
324
+ ? { state: 'preparing', prepareStep: seenPreparing?.step }
284
325
  : (flow ?? (blocked ? { state: 'blocked', blocked } : undefined))
285
326
 
286
327
  return (
@@ -191,3 +191,37 @@ describe('ConnectionErrorView kubeconfig guidance', () => {
191
191
  expect(markup).not.toContain('Switch context')
192
192
  })
193
193
  })
194
+
195
+ describe('ConnectionErrorView after a refused switch', () => {
196
+ const connection = { state: 'disconnected' as const, context: 'staging-eu', errorType: 'auth', error: 'safe error' }
197
+
198
+ it('offers a way back to the cluster the person was using', () => {
199
+ const markup = renderToStaticMarkup(
200
+ <ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} back={{ label: 'kind-radar-ph-video', onBack: () => {} }} variant="switch" />,
201
+ )
202
+ expect(markup).toContain('Back to kind-radar-ph-video')
203
+ })
204
+
205
+ it('does not promise background re-checks for a cluster it never connected to', () => {
206
+ const switchMarkup = renderToStaticMarkup(
207
+ <ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} variant="switch" />,
208
+ )
209
+ const connectionMarkup = renderToStaticMarkup(
210
+ <ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} />,
211
+ )
212
+ expect(connectionMarkup).toContain('re-checks in the background')
213
+ expect(switchMarkup).not.toContain('re-checks in the background')
214
+ expect(switchMarkup).not.toContain('Back to')
215
+ })
216
+ })
217
+
218
+ describe('ConnectionErrorView after a refused switch with a stuck credential plugin', () => {
219
+ it('does not say Radar keeps checking a cluster it never connected to', () => {
220
+ const connection = { state: 'disconnected' as const, context: 'prod', errorType: 'auth-plugin-stuck', error: 'safe error' }
221
+ const switchMarkup = renderToStaticMarkup(<ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} variant="switch" />)
222
+ const connectionMarkup = renderToStaticMarkup(<ConnectionErrorView connection={connection} onRetry={() => {}} isRetrying={false} />)
223
+ expect(connectionMarkup).toContain('keep checking in the background')
224
+ expect(switchMarkup).not.toContain('keep checking in the background')
225
+ expect(switchMarkup).toContain('use Retry Connection')
226
+ })
227
+ })
@@ -1,4 +1,4 @@
1
- import { ServerOff, RefreshCw, Loader2, Copy, Check, TerminalSquare } from 'lucide-react'
1
+ import { ServerOff, RefreshCw, Loader2, Copy, Check, TerminalSquare, ArrowLeft } from 'lucide-react'
2
2
  import { useEffect, useState } from 'react'
3
3
  import type { ConnectionState } from '../context/ConnectionContext'
4
4
  import { ContextSwitcher } from './ContextSwitcher'
@@ -11,11 +11,18 @@ import { Collapse, CollapseChevron } from '@skyhook-io/k8s-ui/components/ui/Coll
11
11
  import { allShellSafe, awsProfileFlag } from '../utils/shell-safe'
12
12
  import { apiUrl } from '../api/config'
13
13
  import { useCapabilitiesContext } from '../contexts/CapabilitiesContext'
14
+ import { outageSinceLabel } from './outageSince'
14
15
 
15
16
  interface ConnectionErrorViewProps {
16
17
  connection: ConnectionState
17
18
  onRetry: () => void
18
19
  isRetrying: boolean
20
+ // A one-click way back to the cluster the person was using.
21
+ back?: { label: string; onBack: () => void; disabled?: boolean }
22
+ // 'switch': a switch Radar refused before leaving the current cluster.
23
+ // Nothing re-checks that cluster in the background, so the note saying so
24
+ // is left out.
25
+ variant?: 'connection' | 'switch'
19
26
  }
20
27
 
21
28
  interface CommandHint {
@@ -167,13 +174,15 @@ export function getAuthRejectedHints(context: string, awsProfile?: string): Auth
167
174
  }
168
175
  }
169
176
 
170
- function getAuthPluginStuckHints(): AuthHints {
177
+ function getAuthPluginStuckHints(backgroundRecovery = true): AuthHints {
171
178
  return {
172
179
  title: 'Credential Plugin Stopped Responding',
173
180
  hints: [
174
181
  'The credential command configured by this kubeconfig did not return before the deadline.',
175
182
  'Check that your cloud-provider CLI and its identity-provider or network dependencies are responsive.',
176
- 'Radar will keep checking in the background and reconnect when the credential command recovers.',
183
+ backgroundRecovery
184
+ ? 'Radar will keep checking in the background and reconnect when the credential command recovers.'
185
+ : 'Once the credential command responds, use Retry Connection.',
177
186
  ],
178
187
  }
179
188
  }
@@ -334,7 +343,7 @@ export function CopyableCommand({ command, onRunInTerminal }: { command: string;
334
343
  )
335
344
  }
336
345
 
337
- export function selectConnectionHints(errorType: string | undefined, context: string, originalContext?: string, awsProfile?: string): AuthHints | null {
346
+ export function selectConnectionHints(errorType: string | undefined, context: string, originalContext?: string, awsProfile?: string, backgroundRecovery = true): AuthHints | null {
338
347
  const parsedContext = originalContext || context
339
348
  switch (errorType) {
340
349
  case 'auth':
@@ -342,7 +351,7 @@ export function selectConnectionHints(errorType: string | undefined, context: st
342
351
  case 'auth-rejected':
343
352
  return getAuthRejectedHints(parsedContext, awsProfile)
344
353
  case 'auth-plugin-stuck':
345
- return getAuthPluginStuckHints()
354
+ return getAuthPluginStuckHints(backgroundRecovery)
346
355
  case 'timeout':
347
356
  return getTimeoutHints(parsedContext, awsProfile)
348
357
  default:
@@ -350,7 +359,7 @@ export function selectConnectionHints(errorType: string | undefined, context: st
350
359
  }
351
360
  }
352
361
 
353
- export function ConnectionErrorView({ connection, onRetry, isRetrying }: ConnectionErrorViewProps) {
362
+ export function ConnectionErrorView({ connection, onRetry, isRetrying, back, variant = 'connection' }: ConnectionErrorViewProps) {
354
363
  // For auth errors, generate context-aware hints with a specific re-auth command
355
364
  const isAuth = connection.errorType === 'auth'
356
365
  const isAuthRejected = connection.errorType === 'auth-rejected'
@@ -360,7 +369,8 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
360
369
  const matchedContext = contexts?.find((context) => context.name === connection.context)
361
370
  const originalContext = matchedContext?.originalName
362
371
  const awsProfile = contextsLoading ? undefined : matchedContext?.awsProfile
363
- const commandInfo = selectConnectionHints(connection.errorType, connection.context || '', originalContext, awsProfile)
372
+ const since = outageSinceLabel(connection.disconnectedAt)
373
+ const commandInfo = selectConnectionHints(connection.errorType, connection.context || '', originalContext, awsProfile, variant === 'connection')
364
374
  const errorInfo = commandInfo || errorHints[connection.errorType || 'unknown'] || errorHints.unknown
365
375
  const openLocalTerminal = useOpenLocalTerminal()
366
376
  const { data: authMe } = useAuthMe()
@@ -378,7 +388,9 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
378
388
 
379
389
  const handleAuthInTerminal = () => {
380
390
  if (!commandInfo?.authCommand) return
381
- const cmd = authMe?.authEnabled === false
391
+ // The follow-up retry reconnects the current context, so it only belongs on
392
+ // the screen for a lost connection, not on one for a refused switch.
393
+ const cmd = authMe?.authEnabled === false && variant === 'connection'
382
394
  ? `${commandInfo.authCommand.command} && ${retryCmd}`
383
395
  : commandInfo.authCommand.command
384
396
  openLocalTerminal({
@@ -410,6 +422,7 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
410
422
  ) : (
411
423
  <span className="inline-code">(none)</span>
412
424
  )}
425
+ {since && <span>· since {since}</span>}
413
426
  </p>
414
427
 
415
428
  {connection.clusterName && (
@@ -475,11 +488,11 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
475
488
  )}
476
489
  </div>
477
490
 
478
- <div className="flex items-center gap-5">
491
+ <div className="flex flex-wrap items-center justify-center gap-3">
479
492
  <button
480
493
  onClick={onRetry}
481
494
  disabled={isRetrying}
482
- className="inline-flex items-center gap-2 px-4 py-2 btn-brand rounded-lg"
495
+ className="inline-flex items-center gap-2 px-4 py-2 btn-brand rounded-lg whitespace-nowrap"
483
496
  >
484
497
  {isRetrying ? (
485
498
  <>
@@ -494,10 +507,21 @@ export function ConnectionErrorView({ connection, onRetry, isRetrying }: Connect
494
507
  )}
495
508
  </button>
496
509
 
510
+ {back && (
511
+ <button
512
+ onClick={back.onBack}
513
+ disabled={back.disabled}
514
+ className="inline-flex items-center gap-2 px-4 py-2 rounded-lg border border-theme-border bg-theme-surface text-theme-text-primary hover:bg-theme-hover disabled:opacity-50 whitespace-nowrap"
515
+ >
516
+ <ArrowLeft className="w-4 h-4" />
517
+ Back to {back.label}
518
+ </button>
519
+ )}
520
+
497
521
  {connection.context && <ContextSwitcher triggerName="Switch context" />}
498
522
  </div>
499
523
 
500
- {isAuthError && (
524
+ {isAuthError && variant === 'connection' && (
501
525
  <p className="mt-4 text-xs text-theme-text-tertiary">
502
526
  {isAuthRejected
503
527
  ? 'Radar re-checks in the background — access changes are picked up automatically. Use Retry Connection to check immediately.'
@@ -6,6 +6,7 @@ import {
6
6
  import { useContexts, useClusterInfo, useCapabilities } from '../api/client'
7
7
  import type { ContextInfo } from '../types'
8
8
  import { useContextSwitchFlow } from './useContextSwitchFlow'
9
+ import { useContextSwitch } from '../context/ContextSwitchContext'
9
10
  import { parseContextForSwitcher, visibleContextQualifier, type ParsedContextName } from '../utils/context-name'
10
11
 
11
12
  interface ContextSwitcherProps {
@@ -29,6 +30,7 @@ export const ContextSwitcher = forwardRef<ContextSwitcherHandle, ContextSwitcher
29
30
  const { data: clusterInfo } = useClusterInfo()
30
31
  const { data: capabilities } = useCapabilities()
31
32
  const switchFlow = useContextSwitchFlow()
33
+ const { failedSwitch } = useContextSwitch()
32
34
 
33
35
  // Parse contexts and decide whether to render group headers (multi-account only).
34
36
  // hasMultipleSources gates the kubeconfig-source chip — only useful when 2+
@@ -134,10 +136,11 @@ export const ContextSwitcher = forwardRef<ContextSwitcherHandle, ContextSwitcher
134
136
  loading={switchFlow.isPending}
135
137
  disabled={contextsLoading || !capabilities || capabilities.configManagement === 'operator'}
136
138
  searchable={items.length > 1}
139
+ currentSelectable={!!failedSwitch}
137
140
  showGroupHeaders={hasMultipleAccounts}
138
141
  errorSlot={
139
- switchFlow.error ? (
140
- <span className="text-xs text-red-400">{switchFlow.error.message}</span>
142
+ switchFlow.errorText ? (
143
+ <span className="text-xs text-red-400">{switchFlow.errorText}</span>
141
144
  ) : undefined
142
145
  }
143
146
  />
@@ -0,0 +1,43 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+ import type { ContextInfo } from '../types'
4
+
5
+ const requestSwitch = vi.fn()
6
+ const contexts: ContextInfo[] = [
7
+ { name: 'kind-radar-ph-video', cluster: 'kind-radar-ph-video', user: 'u', namespace: '', isCurrent: false } as ContextInfo,
8
+ { name: 'gke_acme_europe-west1_staging-eu', cluster: 'staging-eu', user: 'u', namespace: '', isCurrent: true } as ContextInfo,
9
+ ]
10
+
11
+ vi.mock('../api/client', () => ({ useContexts: () => ({ data: contexts }) }))
12
+ vi.mock('./useContextSwitchFlow', () => ({ useContextSwitchFlow: () => ({ requestSwitch, isPending: false, confirmDialog: null }) }))
13
+ vi.mock('../context/ContextSwitchContext', () => ({ useContextSwitch: () => ({ failedSwitch: null, setFailedSwitch: vi.fn() }) }))
14
+ vi.mock('./ConnectionErrorView', () => ({
15
+ ConnectionErrorView: ({ back }: { back?: { label: string } }) => <div>{back ? `back:${back.label}` : 'no back'}</div>,
16
+ }))
17
+
18
+ const { DisconnectedView } = await import('./SwitchAwareConnectionError')
19
+
20
+ const down = { state: 'disconnected' as const, context: 'gke_acme_europe-west1_staging-eu', errorType: 'timeout' }
21
+
22
+ describe('DisconnectedView', () => {
23
+ it('offers the last connected cluster after a switch that left it', () => {
24
+ const markup = renderToStaticMarkup(
25
+ <DisconnectedView connection={down} onRetry={() => {}} isRetrying={false} lastConnectedContext="kind-radar-ph-video" />,
26
+ )
27
+ expect(markup).toContain('back:kind-radar-ph-video')
28
+ })
29
+
30
+ it('offers nothing when the cluster that is down is the one that last worked', () => {
31
+ const markup = renderToStaticMarkup(
32
+ <DisconnectedView connection={down} onRetry={() => {}} isRetrying={false} lastConnectedContext="gke_acme_europe-west1_staging-eu" />,
33
+ )
34
+ expect(markup).toContain('no back')
35
+ })
36
+
37
+ it('offers nothing before anything has connected', () => {
38
+ const markup = renderToStaticMarkup(
39
+ <DisconnectedView connection={down} onRetry={() => {}} isRetrying={false} lastConnectedContext={null} />,
40
+ )
41
+ expect(markup).toContain('no back')
42
+ })
43
+ })
@@ -0,0 +1,85 @@
1
+ import { useState } from 'react'
2
+ import { useContexts } from '../api/client'
3
+ import type { ConnectionState } from '../context/ConnectionContext'
4
+ import { useContextSwitch } from '../context/ContextSwitchContext'
5
+ import type { ContextInfo } from '../types'
6
+ import { parseContextForSwitcher } from '../utils/context-name'
7
+ import { ConnectionErrorView } from './ConnectionErrorView'
8
+ import { useContextSwitchFlow } from './useContextSwitchFlow'
9
+
10
+ function clusterLabel(contexts: ContextInfo[] | undefined, name: string): string {
11
+ const match = contexts?.find(context => context.name === name)
12
+ return match ? parseContextForSwitcher(match).clusterName : name
13
+ }
14
+
15
+ // A switch Radar refused before leaving the current cluster: the connection
16
+ // error screen for the cluster that didn't answer, with its fix steps. The
17
+ // current cluster is still connected underneath, so Back only closes this.
18
+ export function FailedSwitchView({ currentContext }: { currentContext: string }) {
19
+ const { failedSwitch, setFailedSwitch } = useContextSwitch()
20
+ const { data: contexts } = useContexts()
21
+ const { requestSwitch, isPending, confirmDialog } = useContextSwitchFlow()
22
+ // Retry checks for open sessions before the switch itself is pending; Back
23
+ // stays disabled through that, so it can't close the screen and then switch.
24
+ const [starting, setStarting] = useState(false)
25
+ if (!failedSwitch) return null
26
+ const target = contexts?.find(context => context.name === failedSwitch.context)
27
+ const busy = starting || isPending
28
+
29
+ return (
30
+ <>
31
+ <ConnectionErrorView
32
+ connection={{
33
+ state: 'disconnected',
34
+ context: failedSwitch.context,
35
+ error: failedSwitch.error,
36
+ errorType: failedSwitch.errorType,
37
+ }}
38
+ onRetry={() => {
39
+ if (!target || busy) return
40
+ setStarting(true)
41
+ void requestSwitch(target).finally(() => setStarting(false))
42
+ }}
43
+ isRetrying={busy}
44
+ back={{ label: clusterLabel(contexts, currentContext), onBack: () => setFailedSwitch(null), disabled: busy }}
45
+ variant="switch"
46
+ />
47
+ {confirmDialog}
48
+ </>
49
+ )
50
+ }
51
+
52
+ // Disconnected after leaving a cluster that worked (an older Radar server, or
53
+ // a new cluster that answered and then failed to load): Back switches to the
54
+ // last cluster that was connected.
55
+ export function DisconnectedView({
56
+ connection,
57
+ onRetry,
58
+ isRetrying,
59
+ lastConnectedContext,
60
+ }: {
61
+ connection: ConnectionState
62
+ onRetry: () => void
63
+ isRetrying: boolean
64
+ lastConnectedContext: string | null
65
+ }) {
66
+ const { data: contexts } = useContexts()
67
+ const { requestSwitch, isPending, confirmDialog } = useContextSwitchFlow()
68
+ const previous = lastConnectedContext && lastConnectedContext !== connection.context
69
+ ? contexts?.find(context => context.name === lastConnectedContext)
70
+ : undefined
71
+
72
+ return (
73
+ <>
74
+ <ConnectionErrorView
75
+ connection={connection}
76
+ onRetry={onRetry}
77
+ isRetrying={isRetrying}
78
+ back={previous
79
+ ? { label: parseContextForSwitcher(previous).clusterName, onBack: () => void requestSwitch(previous), disabled: isPending }
80
+ : undefined}
81
+ />
82
+ {confirmDialog}
83
+ </>
84
+ )
85
+ }