@skyhook-io/radar-app 1.22.1 → 1.23.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 (234) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +131 -38
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/RadarApp.tsx +5 -0
  6. package/src/api/agentSandbox.ts +259 -0
  7. package/src/api/client.autoPromConnect.test.tsx +43 -0
  8. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  9. package/src/api/client.ts +128 -25
  10. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  11. package/src/api/diagnose.ts +4 -0
  12. package/src/api/kagent.test.ts +82 -0
  13. package/src/api/kagent.ts +230 -0
  14. package/src/api/prometheusCharts.ts +5 -0
  15. package/src/api/radarFeatures.test.ts +9 -0
  16. package/src/api/radarFeatures.ts +13 -0
  17. package/src/api/substrateWorkspace.test.ts +72 -0
  18. package/src/api/substrateWorkspace.ts +1394 -0
  19. package/src/api/vulnerabilities.ts +207 -9
  20. package/src/api/workloadSource.test.tsx +1172 -0
  21. package/src/api/workloadSource.ts +408 -0
  22. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  23. package/src/components/APIUnreachableBanner.tsx +20 -0
  24. package/src/components/CloudConnectFlow.tsx +46 -7
  25. package/src/components/CloudFunnelButton.test.tsx +193 -7
  26. package/src/components/CloudFunnelButton.tsx +127 -32
  27. package/src/components/ConnectionErrorView.test.tsx +63 -2
  28. package/src/components/ConnectionErrorView.tsx +88 -68
  29. package/src/components/SelfManagedStart.tsx +12 -2
  30. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  31. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  32. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  33. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  34. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  35. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  36. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  37. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  38. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  39. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  40. package/src/components/agentsandbox/data.ts +135 -0
  41. package/src/components/agentsandbox/host.test.ts +27 -0
  42. package/src/components/agentsandbox/host.tsx +85 -0
  43. package/src/components/agentsandbox/labels.test.ts +42 -0
  44. package/src/components/agentsandbox/labels.ts +146 -0
  45. package/src/components/agentsandbox/listFilters.ts +85 -0
  46. package/src/components/agentsandbox/lists.ts +52 -0
  47. package/src/components/agentsandbox/routes.ts +23 -0
  48. package/src/components/agentsandbox/shared.tsx +321 -0
  49. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  50. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  51. package/src/components/agentsandbox/workspace.tsx +258 -0
  52. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  53. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  54. package/src/components/applications/ApplicationsView.tsx +156 -3
  55. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  56. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  57. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  58. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  59. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  60. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  61. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  62. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  63. package/src/components/cloudHints/cloudHints.ts +131 -0
  64. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  65. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  66. package/src/components/cloudHints/cloudLinks.ts +31 -0
  67. package/src/components/cloudHints/hintStorage.ts +28 -0
  68. package/src/components/cnpg/CNPGView.tsx +4 -7
  69. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  70. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  71. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  72. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  73. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  74. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  75. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  76. package/src/components/diagnose/Home.test.tsx +6 -0
  77. package/src/components/diagnose/Home.tsx +10 -3
  78. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  79. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  80. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  81. package/src/components/diagnose/InvestigationView.tsx +120 -23
  82. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  83. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  84. package/src/components/diagnose/investigationState.ts +9 -0
  85. package/src/components/diagnose/parts.test.tsx +11 -3
  86. package/src/components/diagnose/toolCallLabel.ts +3 -0
  87. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  88. package/src/components/home/ActivitySummary.tsx +3 -8
  89. package/src/components/home/ClusterHealthCard.tsx +91 -17
  90. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  91. package/src/components/home/HomeAgentBlock.tsx +2 -0
  92. package/src/components/home/HomeView.tsx +9 -29
  93. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  94. package/src/components/home/MCPSetupDialog.tsx +6 -2
  95. package/src/components/home/McpCloudLine.test.tsx +162 -0
  96. package/src/components/home/McpCloudLine.tsx +95 -0
  97. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  98. package/src/components/home/TopologyPreview.test.tsx +31 -30
  99. package/src/components/home/TopologyPreview.tsx +19 -28
  100. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  101. package/src/components/home/mcpToolCatalog.ts +7 -7
  102. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  103. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  104. package/src/components/issues/IssuesPane.tsx +181 -23
  105. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  106. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  107. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  108. package/src/components/issues/sinceLastVisit.ts +439 -0
  109. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  110. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  111. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  112. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  113. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  114. package/src/components/kagent/KagentLists.tsx +412 -0
  115. package/src/components/kagent/KagentOverview.tsx +234 -0
  116. package/src/components/kagent/KagentPages.tsx +690 -0
  117. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  118. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  119. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  120. package/src/components/kagent/KagentView.tsx +109 -0
  121. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  122. package/src/components/kagent/host.tsx +144 -0
  123. package/src/components/kagent/routes.ts +31 -0
  124. package/src/components/kagent/shared.tsx +336 -0
  125. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  126. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  127. package/src/components/kagent/workspace.fixtures.ts +108 -0
  128. package/src/components/kagent/workspaceRoute.ts +18 -0
  129. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  130. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  131. package/src/components/resource/PrometheusCharts.tsx +10 -1
  132. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  133. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  134. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  135. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  136. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  137. package/src/components/resources/ResourcesView.tsx +2 -6
  138. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  139. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  140. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  141. package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
  142. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  143. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  144. package/src/components/settings/SettingsDialog.tsx +84 -16
  145. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  146. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  147. package/src/components/settings/SubstrateSettings.tsx +544 -0
  148. package/src/components/settings/settings-state.test.ts +21 -3
  149. package/src/components/settings/settings-state.ts +13 -3
  150. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  151. package/src/components/share/ShareLinkButton.tsx +391 -0
  152. package/src/components/share/openShareInCloud.test.ts +29 -0
  153. package/src/components/share/openShareInCloud.ts +10 -0
  154. package/src/components/share/shareLink.test.ts +129 -0
  155. package/src/components/share/shareLink.ts +175 -0
  156. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  157. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  158. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  159. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  160. package/src/components/substrate/SubstrateActors.tsx +612 -0
  161. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  162. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  163. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  164. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  165. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  166. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  167. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  168. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  169. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  170. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  171. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  172. package/src/components/substrate/SubstrateView.tsx +173 -0
  173. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  174. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  175. package/src/components/substrate/attention.ts +81 -0
  176. package/src/components/substrate/contextPin.tsx +69 -0
  177. package/src/components/substrate/host.tsx +83 -0
  178. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  179. package/src/components/substrate/readings.test.ts +484 -0
  180. package/src/components/substrate/readings.ts +997 -0
  181. package/src/components/substrate/routes.ts +103 -0
  182. package/src/components/substrate/shared.tsx +426 -0
  183. package/src/components/substrate/substrate.fixtures.ts +325 -0
  184. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  185. package/src/components/substrate/workspaceRoute.ts +23 -0
  186. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  187. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  188. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  189. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  190. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  191. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  192. package/src/components/traffic/TrafficGraph.tsx +17 -14
  193. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  194. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  195. package/src/components/traffic/TrafficView.tsx +26 -56
  196. package/src/components/traffic/trafficFilters.test.ts +61 -1
  197. package/src/components/traffic/trafficFilters.ts +68 -8
  198. package/src/components/velero/VeleroOverview.tsx +2 -2
  199. package/src/components/velero/VeleroView.tsx +3 -6
  200. package/src/components/vulnerabilities/columns.tsx +132 -0
  201. package/src/components/vulnerabilities/filters.tsx +317 -0
  202. package/src/components/vulnerabilities/owner.test.ts +54 -0
  203. package/src/components/vulnerabilities/owner.tsx +163 -0
  204. package/src/components/vulnerabilities/parts.test.ts +126 -12
  205. package/src/components/vulnerabilities/parts.tsx +612 -52
  206. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  207. package/src/components/vulnerabilities/traffic.tsx +40 -0
  208. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  209. package/src/components/workload/WorkloadView.tsx +119 -14
  210. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  211. package/src/components/workspace/layout.tsx +13 -7
  212. package/src/components/workspace/sidebar.test.ts +48 -0
  213. package/src/components/workspace/sidebar.ts +73 -3
  214. package/src/components/workspace/table.ts +2 -1
  215. package/src/context/ConnectionContext.tsx +24 -5
  216. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  217. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  218. package/src/context/DiagnoseCustomization.tsx +20 -2
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/hooks/useEventSource.test.tsx +275 -4
  222. package/src/hooks/useEventSource.ts +278 -51
  223. package/src/index.ts +1 -0
  224. package/src/integrations/resourceHost.ts +12 -6
  225. package/src/integrations/resourceHosts.test.tsx +27 -1
  226. package/src/integrations/resourceHosts.tsx +15 -7
  227. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  228. package/src/integrations/sidebarWorkspaces.ts +41 -0
  229. package/src/integrations/workspaceRoute.ts +1 -1
  230. package/src/integrations/workspaceRoutes.ts +7 -1
  231. package/src/integrations/workspaceScreens.tsx +6 -0
  232. package/src/utils/navigation.test.ts +1 -6
  233. package/src/utils/navigation.ts +9 -44
  234. package/src/utils/network-policy-navigation.test.ts +21 -36
@@ -4,7 +4,8 @@ import { createRoot, type Root } from 'react-dom/client'
4
4
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
5
5
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
6
6
  import type { ConnectionStateType } from '../context/ConnectionContext'
7
- import { CloudFunnelButton } from './CloudFunnelButton'
7
+ import { CloudFunnelButton, openCloudFunnel } from './CloudFunnelButton'
8
+ import { OPEN_CLOUD_FUNNEL_EVENT } from './cloudHints/cloudHints'
8
9
 
9
10
  const connection = vi.hoisted(() => ({ state: 'connecting' as ConnectionStateType }))
10
11
  vi.mock('../context/ConnectionContext', () => ({ useConnection: () => ({ connection }) }))
@@ -12,12 +13,22 @@ vi.mock('./ui/Tooltip', () => ({ Tooltip: ({ children }: { children: ReactNode }
12
13
  const toast = vi.hoisted(() => ({ showApiError: vi.fn() }))
13
14
  vi.mock('./ui/Toast', () => toast)
14
15
  vi.mock('./CloudConnectFlow', () => ({
15
- CloudConnectFlow: ({ status, blocked, onExit }: { status: { state: string; prepareStep?: string }; blocked: unknown; onExit: () => void }) => (
16
- <div>
17
- Install flow [{blocked ? 'blocked' : status.state} {status.prepareStep ?? '-'}]
18
- <button onClick={onExit}>Leave flow</button>
19
- </div>
20
- ),
16
+ CloudConnectFlow: ({ status, blocked, onExit, connectedAction }: {
17
+ status: { state: string; prepareStep?: string; connected?: { clusterUrl: string } }
18
+ blocked: unknown
19
+ onExit: () => void
20
+ connectedAction?: (connected: { clusterUrl: string }) => { label: string; href: string } | null
21
+ }) => {
22
+ // The connected card's main link, as the real one picks it.
23
+ const action = status.connected && connectedAction?.(status.connected)
24
+ return (
25
+ <div>
26
+ Install flow [{blocked ? 'blocked' : status.state} {status.prepareStep ?? '-'}]
27
+ {status.connected && <a href={action?.href ?? status.connected.clusterUrl}>{action?.label ?? 'Open in Radar Cloud'}</a>}
28
+ <button onClick={onExit}>Leave flow</button>
29
+ </div>
30
+ )
31
+ },
21
32
  }))
22
33
 
23
34
  Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
@@ -107,6 +118,11 @@ async function startConnect() {
107
118
  await act(async () => { button('Connect this cluster…')!.click() })
108
119
  }
109
120
 
121
+ function closeButton() {
122
+ return document.querySelector<HTMLButtonElement>('[aria-label="Close"]')!
123
+ }
124
+
125
+
110
126
  function button(text: string) {
111
127
  return Array.from(document.querySelectorAll('button')).find(element => element.textContent === text)
112
128
  }
@@ -326,3 +342,173 @@ describe('Cloud connect preparation progress', () => {
326
342
  expect(toast.showApiError).not.toHaveBeenCalled()
327
343
  })
328
344
  })
345
+
346
+ describe('Cloud dialog opened from an in-context hint', () => {
347
+ async function renderReady() {
348
+ await render()
349
+ await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
350
+ }
351
+
352
+ function signupLink() {
353
+ return document.querySelector<HTMLAnchorElement>('a[href*="wizard-signup-button"]')
354
+ }
355
+
356
+ it('tags the links the person opens with the hint, and only for that open', async () => {
357
+ lane = 'wizard'
358
+ await renderReady()
359
+ await act(async () => openCloudFunnel('ai-setup'))
360
+ await until(() => expect(signupLink()).not.toBeNull())
361
+ expect(new URL(signupLink()!.href).searchParams.get('utm_term')).toBe('ai-setup')
362
+
363
+ await act(async () => { closeButton().click() })
364
+ await act(async () => { (document.querySelector('[aria-label="Radar Cloud"]') as HTMLButtonElement).click() })
365
+ await until(() => expect(signupLink()).not.toBeNull())
366
+ expect(new URL(signupLink()!.href).searchParams.has('utm_term')).toBe(false)
367
+ })
368
+
369
+ it('names the hint on the copy fetch, and nothing when the globe button opens it', async () => {
370
+ lane = 'wizard'
371
+ await renderReady()
372
+ await act(async () => openCloudFunnel('settings-ai'))
373
+ await until(() => expect(requests.some(r => r.startsWith('/api/connect/info') && r.includes('entry=settings-ai'))).toBe(true))
374
+ await act(async () => { closeButton().click() })
375
+ requests.length = 0
376
+ await act(async () => { (document.querySelector('[aria-label="Radar Cloud"]') as HTMLButtonElement).click() })
377
+ await until(() => expect(requests.some(r => r.startsWith('/api/connect/info'))).toBe(true))
378
+ expect(requests.filter(r => r.startsWith('/api/connect/info')).every(r => !r.includes('entry='))).toBe(true)
379
+ })
380
+
381
+ it('ignores a forged hint name from another script', async () => {
382
+ lane = 'wizard'
383
+ await renderReady()
384
+ await act(async () => {
385
+ window.dispatchEvent(new CustomEvent(OPEN_CLOUD_FUNNEL_EVENT, { detail: { entry: 'evil"&x=1' } }))
386
+ })
387
+ await until(() => expect(signupLink()).not.toBeNull())
388
+ expect(new URL(signupLink()!.href).searchParams.has('utm_term')).toBe(false)
389
+ })
390
+
391
+ it('opens Self-Managed when asked even while a hosted install awaits approval, and Back returns to it', async () => {
392
+ connection.state = 'connected'
393
+ flowState = 'awaiting_approval'
394
+ await render()
395
+ await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
396
+ await act(async () => openCloudFunnel('oss-poll', undefined, 'self-managed'))
397
+ await until(() => expect(document.querySelector('a[href*="self-managed-signup"]')).not.toBeNull())
398
+ expect(document.body.textContent).not.toContain('Install flow')
399
+ await act(async () => { button('Back to Radar Cloud')!.click() })
400
+ await until(() => expect(document.body.textContent).toContain('Install flow [awaiting_approval -]'))
401
+ })
402
+
403
+ it('opens the poll on Self-Managed, and its links name the poll as the campaign', async () => {
404
+ lane = 'wizard'
405
+ await renderReady()
406
+ await act(async () => openCloudFunnel('oss-poll', undefined, 'self-managed'))
407
+ const selfManagedLink = () => document.querySelector<HTMLAnchorElement>('a[href*="self-managed-signup"]')
408
+ await until(() => expect(selfManagedLink()).not.toBeNull())
409
+ const url = new URL(selfManagedLink()!.href)
410
+ expect(url.searchParams.get('utm_campaign')).toBe('oss-poll')
411
+ expect(url.searchParams.get('utm_content')).toBe('self-managed-signup')
412
+ expect(url.searchParams.get('utm_term')).toBe('oss-poll')
413
+ expect(url.searchParams.get('intent')).toBe('self-hosting')
414
+ expect(signupLink()).toBeNull()
415
+
416
+ // The poll's hosted line opens the pitch, still under the poll's campaign.
417
+ await act(async () => { document.querySelector<HTMLButtonElement>('[aria-label="Close"]')!.click() })
418
+ await act(async () => openCloudFunnel('oss-poll'))
419
+ await until(() => expect(signupLink()).not.toBeNull())
420
+ expect(new URL(signupLink()!.href).searchParams.get('utm_campaign')).toBe('oss-poll')
421
+
422
+ // Any other entry, and the globe button, keep the dialog's own campaign.
423
+ await act(async () => { closeButton().click() })
424
+ await act(async () => openCloudFunnel('settings-ai'))
425
+ await until(() => expect(signupLink()).not.toBeNull())
426
+ expect(new URL(signupLink()!.href).searchParams.get('utm_campaign')).toBe('cloud-modal')
427
+ })
428
+
429
+ it('shows the resource being shared instead of the general pitch', async () => {
430
+ lane = 'wizard'
431
+ await renderReady()
432
+ await act(async () =>
433
+ openCloudFunnel('share', { intent: 'share', kind: 'Pod', name: 'api-1', namespace: 'shop', context: 'test-cluster' }),
434
+ )
435
+ await until(() => expect(document.body.textContent).toContain('Share api-1 with your team'))
436
+ const text = document.body.textContent ?? ''
437
+ expect(text).toContain('Pod api-1')
438
+ expect(text).toContain('namespace shop')
439
+ expect(text).toContain('Connecting the cluster lets Radar Cloud store its event history, changes and investigation results.')
440
+ expect(text).not.toContain('Meet Radar Cloud')
441
+ expect(new URL(signupLink()!.href).searchParams.get('utm_term')).toBe('share')
442
+ // A feature dialog stays about the feature: no assurance ticks, so no
443
+ // free-tier line, and nothing tucked behind a disclosure.
444
+ expect(text).not.toContain('clusters free')
445
+ expect(text).not.toContain('SOC 2')
446
+ })
447
+ })
448
+
449
+ describe('Cloud dialog actions for a cluster already in Radar Cloud', () => {
450
+ it('shares the resource: the team link, under a share headline', async () => {
451
+ connection.state = 'connected'
452
+ discovery.connected = [{ namespace: 'radar', deployment: 'radar', clusterUrl: 'https://cloud.example/c/cl_123' }]
453
+ await render()
454
+ await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
455
+ await act(async () =>
456
+ openCloudFunnel('share', { intent: 'share', kind: 'Deployment', group: 'apps', name: 'checkout-api', namespace: 'shop', context: 'test-cluster' }),
457
+ )
458
+ await until(() => expect(document.body.textContent).toContain('This cluster is already connected to Radar Cloud.'))
459
+ const link = Array.from(document.querySelectorAll('a')).find((a) => a.textContent === 'Open checkout-api in Radar Cloud')
460
+ expect(new URL(link!.href).pathname).toBe('/c/cl_123/resources/deployments')
461
+ expect(new URL(link!.href).searchParams.get('utm_term')).toBe('share')
462
+ expect(document.body.textContent).toContain('Share checkout-api with your team')
463
+ expect(document.body.textContent).not.toContain('Connecting the cluster lets Radar Cloud store')
464
+ })
465
+
466
+ it('links the cluster, not the resource, when Radar has moved to another context', async () => {
467
+ connection.state = 'connected'
468
+ discovery.connected = [{ namespace: 'radar', deployment: 'radar', clusterUrl: 'https://cloud.example/c/cl_123' }]
469
+ await render()
470
+ await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
471
+ await act(async () =>
472
+ openCloudFunnel('share', { intent: 'share', kind: 'Deployment', group: 'apps', name: 'checkout-api', namespace: 'shop', context: 'another-cluster' }),
473
+ )
474
+ await until(() => expect(document.body.textContent).toContain('This cluster is already connected to Radar Cloud.'))
475
+ const links = Array.from(document.querySelectorAll('a'))
476
+ expect(links.find((a) => a.textContent === 'Open checkout-api in Radar Cloud')).toBeUndefined()
477
+ // The share body names the other cluster's resource, so it gives way to the pitch.
478
+ expect(document.body.textContent).not.toContain('Share checkout-api with your team')
479
+ expect(new URL(links.find((a) => a.textContent === 'Open in Radar Cloud')!.href).pathname).toBe('/c/cl_123')
480
+ })
481
+ // An install flow keeps the cluster it started on across a context switch,
482
+ // so its Cloud cluster is the subject's only when the flow ran on the
483
+ // subject's context, whatever context Radar is on now.
484
+ const connectedFlow = (contextName: string) => ({
485
+ state: 'connected',
486
+ flowId: 'f1',
487
+ plan: { mode: 'fresh', contextName, namespace: 'radar', release: 'radar', defaultClusterName: 'a', targetChartVersion: '1.0.0' },
488
+ connected: { clusterId: 'cl_a', clusterUrl: 'https://cloud.example/c/cl_a', trackCommand: 'kubectl get pods -n radar' },
489
+ })
490
+ const share = { intent: 'share' as const, kind: 'Deployment', group: 'apps', name: 'checkout-api', namespace: 'shop', context: 'test-cluster' }
491
+ const cloudLinks = () => Array.from(document.querySelectorAll('a')).filter((a) => a.href.startsWith('https://cloud.example/c/'))
492
+
493
+ it('links the resource from an install that ran on its cluster', async () => {
494
+ connection.state = 'connected'
495
+ statusBody = connectedFlow('test-cluster')
496
+ await render()
497
+ await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
498
+ await act(async () => openCloudFunnel('share', share))
499
+ await until(() => expect(cloudLinks().length).toBeGreaterThan(0))
500
+ const link = Array.from(document.querySelectorAll('a')).find((a) => a.textContent?.includes('Open checkout-api in Radar Cloud'))
501
+ expect(new URL(link!.href).pathname).toBe('/c/cl_a/resources/deployments')
502
+ })
503
+
504
+ it('links only the cluster when the install ran on another cluster', async () => {
505
+ connection.state = 'connected'
506
+ statusBody = connectedFlow('cluster-a')
507
+ await render()
508
+ await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
509
+ await act(async () => openCloudFunnel('share', share))
510
+ await until(() => expect(cloudLinks().length).toBeGreaterThan(0))
511
+ expect(cloudLinks().some((a) => new URL(a.href).pathname.includes('/resources/'))).toBe(false)
512
+ expect(document.body.textContent).not.toContain('Open checkout-api in Radar Cloud')
513
+ })
514
+ })
@@ -6,6 +6,14 @@ import { DialogPortal } from '@skyhook-io/k8s-ui/components/ui/DialogPortal'
6
6
  import { Tooltip } from './ui/Tooltip'
7
7
  import { CloudConnectFlow } from './CloudConnectFlow'
8
8
  import { SelfManagedStart } from './SelfManagedStart'
9
+ import {
10
+ type CloudHintEntry,
11
+ type CloudHintSubject,
12
+ OPEN_CLOUD_FUNNEL_EVENT,
13
+ readOpenRequest,
14
+ withCloudHintEntry,
15
+ } from './cloudHints/cloudHints'
16
+ import { cloudResourceUrl } from './cloudHints/cloudLinks'
9
17
  import {
10
18
  type Handoff,
11
19
  exitFor,
@@ -64,15 +72,8 @@ const DEFAULT_ASSURANCES = [
64
72
  'SOC 2 Type II · SSO & SCIM on Enterprise',
65
73
  '3 clusters free, no card required',
66
74
  ]
67
- // Other OSS surfaces (a GitOps app that deploys to another cluster, say)
68
- // point at Radar Cloud by asking this button to open its dialog, so there
69
- // is one pitch and one flow. The button is mounted whenever Radar runs
70
- // standalone; embedded hosts never mount it and never dispatch this.
71
- const OPEN_EVENT = 'radar:open-cloud-funnel'
72
-
73
- export function openCloudFunnel() {
74
- window.dispatchEvent(new Event(OPEN_EVENT))
75
- }
75
+ // Other surfaces open this dialog through openCloudFunnel (see cloudHints).
76
+ export { openCloudFunnel } from './cloudHints/cloudHints'
76
77
  const ABOUT_URL = 'https://radarhq.io/about'
77
78
  const BENCHMARK_URL = 'https://radarhq.io/benchmark'
78
79
  const PRICING_URL = 'https://radarhq.io/pricing'
@@ -126,6 +127,11 @@ export function CloudFunnelButton() {
126
127
  // and is reset below when the kubeconfig context changes — it must never
127
128
  // describe a cluster the user has switched away from.
128
129
  const [handoff, setHandoff] = useState<Handoff | null>(null)
130
+ // Which in-context hint opened the dialog, and for a share the resource it
131
+ // was about. Both last for one open: the globe button, or the next hint,
132
+ // starts clean.
133
+ const [entry, setEntry] = useState<CloudHintEntry | null>(null)
134
+ const [subject, setSubject] = useState<CloudHintSubject | null>(null)
129
135
  const prepareFailed = handoff?.retryable ?? false
130
136
 
131
137
  const capabilities = useCapabilities()
@@ -138,7 +144,8 @@ export function CloudFunnelButton() {
138
144
  // the user opens; Radar sends nothing on its own. Only the blocked card may
139
145
  // deep-link the install page (see exitFor); the pitch buttons and the
140
146
  // footer link go to signup.
141
- const signupUrl = buildSignupUrl(appUrl, 'wizard-signup-button')
147
+ const tag = (url: string) => withCloudHintEntry(url, entry)
148
+ const signupUrl = tag(buildSignupUrl(appUrl, 'wizard-signup-button'))
142
149
 
143
150
  // Only while the dialog is open — never on the capabilities poll. The Hub
144
151
  // learns that someone opened it, which is congruent with what the dialog is
@@ -146,6 +153,7 @@ export function CloudFunnelButton() {
146
153
  const connectInfo = useCloudConnectInfo(capabilities.data?.cloudConnect?.apiUrl, open, {
147
154
  lane: pitchLane,
148
155
  mode: capabilities.data?.deployment?.mode,
156
+ entry,
149
157
  })
150
158
 
151
159
  // In-cluster Radar can't install its own connection, but it knows exactly
@@ -225,9 +233,12 @@ export function CloudFunnelButton() {
225
233
  // a running install. Toast explicitly on the paths that are failures.
226
234
  })
227
235
 
228
- const openModal = () => {
236
+ const openModal = (event?: Event) => {
237
+ const request = event ? readOpenRequest(event) : { entry: null, subject: null, view: 'pitch' }
238
+ setEntry(request.entry)
239
+ setSubject(request.subject)
229
240
  setOpen(true)
230
- setSelfManaged(false)
241
+ setSelfManaged(request.view === 'self-managed')
231
242
  setSeen(true)
232
243
  markSeen()
233
244
  // Re-open lands on a live flow if one is running.
@@ -284,8 +295,8 @@ export function CloudFunnelButton() {
284
295
  }
285
296
 
286
297
  useEffect(() => {
287
- window.addEventListener(OPEN_EVENT, openModal)
288
- return () => window.removeEventListener(OPEN_EVENT, openModal)
298
+ window.addEventListener(OPEN_CLOUD_FUNNEL_EVENT, openModal)
299
+ return () => window.removeEventListener(OPEN_CLOUD_FUNNEL_EVENT, openModal)
289
300
  })
290
301
 
291
302
  // Re-attach to a server-owned flow whenever one is observed while the modal
@@ -312,6 +323,28 @@ export function CloudFunnelButton() {
312
323
  // flashing at a connected cluster's operator before that answer arrives.
313
324
  if (!capabilities.data?.cloudConnect) return null
314
325
 
326
+ const tagExit = (exit: ReturnType<typeof exitFor>) => ({ ...exit, href: tag(exit.href) })
327
+ // Opened to share one resource: once Radar knows the Radar Cloud cluster
328
+ // (already connected, or connected just now), the main action goes straight
329
+ // to that resource in Cloud instead of the cluster's front page. Only when
330
+ // that Cloud cluster is the subject's own: the same name on another cluster
331
+ // is a different resource. clusterContext is where clusterUrl came from:
332
+ // discovery runs on the current context, but an install flow keeps the
333
+ // context it started on across a switch.
334
+ const intentAction = (
335
+ clusterUrl: string | undefined,
336
+ clusterContext: string | undefined,
337
+ ): { label: string; href: string } | null => {
338
+ if (!subject || !clusterUrl || !clusterContext) return null
339
+ if (subject.context !== clusterContext) return null
340
+ const href = cloudResourceUrl(clusterUrl, subject)
341
+ return href ? { label: `Open ${subject.name} in Radar Cloud`, href: tag(href) } : null
342
+ }
343
+ const connectedIntent = intentAction(alreadyConnected?.clusterUrl, contextName)
344
+ // The share body describes the subject's cluster while the footer connects
345
+ // the current one, so after a switch the dialog falls back to the pitch.
346
+ const shareSubject = subject && subject.context === contextName ? subject : null
347
+
315
348
  const showFlow = inFlowView && (blocked !== null || prepare.isPending || flowLive)
316
349
  // The prepare POST can take tens of seconds (chart download + preflight);
317
350
  // until the status poll observes the server-side flow, synthesize the
@@ -340,7 +373,7 @@ export function CloudFunnelButton() {
340
373
  disabled={open}
341
374
  >
342
375
  <button
343
- onClick={openModal}
376
+ onClick={() => openModal()}
344
377
  aria-label="Radar Cloud"
345
378
  aria-haspopup="dialog"
346
379
  className="relative p-1.5 rounded-md bg-theme-elevated hover:bg-theme-hover text-theme-text-secondary hover:text-theme-text-primary transition-colors"
@@ -375,7 +408,9 @@ export function CloudFunnelButton() {
375
408
  {/* Only the body scrolls on short viewports — the close control and
376
409
  the footer CTA stay pinned so they never scroll away. This matters
377
410
  more with the connect flow, whose plan card is the tallest state. */}
378
- {showFlow && flowForView ? (
411
+ {/* A request for the Self-Managed view wins over a hosted install in
412
+ progress; that install continues, and Back returns to it. */}
413
+ {!selfManaged && showFlow && flowForView ? (
379
414
  <div className="min-h-0 overflow-y-auto">
380
415
  <div className="px-8 pt-7">
381
416
  <Eyebrow />
@@ -383,7 +418,9 @@ export function CloudFunnelButton() {
383
418
  <CloudConnectFlow
384
419
  status={flowForView}
385
420
  blocked={blocked}
386
- exit={exitFor(appUrl, 'driver-blocked-card-browser-link', outcomeOf(flowForView), clusterInfo.data?.context)}
421
+ exit={tagExit(exitFor(appUrl, 'driver-blocked-card-browser-link', outcomeOf(flowForView), clusterInfo.data?.context))}
422
+ tagUrl={tag}
423
+ connectedAction={(connected) => intentAction(connected.clusterUrl, flowForView.plan?.contextName)}
387
424
  where={{ context: clusterInfo.data?.context, cluster: clusterInfo.data?.cluster }}
388
425
  onStatus={applyStatus}
389
426
  onExit={() => exitFlow(outcomeOf(flowForView))}
@@ -394,12 +431,16 @@ export function CloudFunnelButton() {
394
431
  <div className="shrink-0 px-8 pt-7">
395
432
  <Eyebrow />
396
433
  </div>
397
- <SelfManagedStart appUrl={appUrl} onBack={() => setSelfManaged(false)} />
434
+ <SelfManagedStart appUrl={appUrl} tagUrl={tag} onBack={() => setSelfManaged(false)} />
398
435
  </>
399
436
  ) : (
400
437
  <>
401
438
  <div className="min-h-0 overflow-y-auto">
402
- <PitchBody lane={pitchLane} freeTier={connectInfo.data?.freeTier} />
439
+ {shareSubject ? (
440
+ <ShareBody subject={shareSubject} connected={lane === 'driver' && !!alreadyConnected} />
441
+ ) : (
442
+ <PitchBody lane={pitchLane} freeTier={connectInfo.data?.freeTier} />
443
+ )}
403
444
  </div>
404
445
  <ModalFooter
405
446
  lane={lane}
@@ -407,18 +448,20 @@ export function CloudFunnelButton() {
407
448
  signupUrl={signupUrl}
408
449
  // One link name whether or not an attempt preceded the click; the
409
450
  // outcome, when present, is what says an attempt happened.
410
- driverBrowserUrl={buildSignupUrl(appUrl, 'driver-footer-browser-link', handoff)}
451
+ driverBrowserUrl={tag(buildSignupUrl(appUrl, 'driver-footer-browser-link', handoff))}
411
452
  prepareFailed={prepareFailed}
412
453
  // A prepare error's reason, kept on the pitch after its toast is gone.
413
454
  prepareError={handoff?.detail}
414
455
  assurances={connectInfo.data?.assurances}
415
456
  notice={connectInfo.data?.notice}
416
- self={inCluster ? self.data : undefined}
457
+ self={inCluster && self.data ? { ...self.data, wizardUrl: self.data.wizardUrl && tag(self.data.wizardUrl) } : undefined}
417
458
  clusterName={clusterInfo.data?.context}
418
- alreadyConnected={alreadyConnected}
459
+ alreadyConnected={alreadyConnected && { ...alreadyConnected, clusterUrl: alreadyConnected.clusterUrl && tag(alreadyConnected.clusterUrl) }}
460
+ connectedIntent={connectedIntent}
461
+ quiet={!!shareSubject}
419
462
  connectedCount={alreadyConnected ? (discovered.data?.connected.length ?? 0) : 0}
420
463
  discoverPending={discoverPending}
421
- clustersUrl={`${appUrl}/clusters`}
464
+ clustersUrl={tag(`${appUrl}/clusters`)}
422
465
  // Also covers the capabilities query: until it resolves, lane
423
466
  // defaults to wizard and Radar does not yet know it is
424
467
  // in-cluster, so the CTA would escape before classification.
@@ -481,6 +524,8 @@ function ModalFooter({
481
524
  connectedCount = 0,
482
525
  discoverPending = false,
483
526
  clustersUrl,
527
+ connectedIntent,
528
+ quiet = false,
484
529
  onConnect,
485
530
  onSelfManaged,
486
531
  onLater,
@@ -514,6 +559,12 @@ function ModalFooter({
514
559
  // The configured Hub's clusters list — where to look when an install's
515
560
  // settings say it is connected but not where.
516
561
  clustersUrl?: string
562
+ // Opened to share a resource and this cluster is already in Radar Cloud: go
563
+ // straight to that resource there.
564
+ connectedIntent?: { label: string; href: string } | null
565
+ // Opened to share one resource: the dialog stays about that, so it carries
566
+ // no assurance ticks.
567
+ quiet?: boolean
517
568
  onConnect: () => void
518
569
  onSelfManaged: () => void
519
570
  onLater: () => void
@@ -606,12 +657,12 @@ function ModalFooter({
606
657
  // Another Hub is named, not linked: the link would open ours.
607
658
  !alreadyConnected.hubHost && (
608
659
  <a
609
- href={alreadyConnected.clusterUrl || clustersUrl}
660
+ href={connectedIntent?.href ?? (alreadyConnected.clusterUrl || clustersUrl)}
610
661
  target="_blank"
611
662
  rel="noopener noreferrer"
612
663
  className="whitespace-nowrap px-6 py-2.5 rounded-[10px] bg-emerald-500 hover:bg-emerald-400 text-emerald-950 text-[14px] font-bold shadow-[0_0_22px_rgba(16,185,129,0.35)] hover:shadow-[0_0_30px_rgba(16,185,129,0.5)] hover:-translate-y-px transition-all"
613
664
  >
614
- {alreadyConnected.clusterUrl ? 'Open in Radar Cloud' : 'Open Radar Cloud'}
665
+ {connectedIntent?.label ?? (alreadyConnected.clusterUrl ? 'Open in Radar Cloud' : 'Open Radar Cloud')}
615
666
  </a>
616
667
  )
617
668
  ) : lane === 'driver' && clusterConnected ? (
@@ -688,14 +739,58 @@ function ModalFooter({
688
739
  share a single row with the other three at this width, and flex
689
740
  wrapping strands it as a 3+1 orphan. Two balanced columns read as a
690
741
  designed layout at any chip length the Hub sends. */}
691
- <div className="mt-5 grid grid-cols-2 gap-x-3 gap-y-2 text-[11px] text-theme-text-tertiary">
692
- {assuranceItems(assurances).map((item) => (
693
- <span key={item} className="flex items-center gap-1">
694
- <Check className="w-3 h-3 shrink-0 text-emerald-600 dark:text-emerald-400" />
695
- {item}
696
- </span>
697
- ))}
742
+ {!quiet && (
743
+ <div className="mt-5 grid grid-cols-2 gap-x-3 gap-y-2 text-[11px] text-theme-text-tertiary">
744
+ {assuranceItems(assurances).map((item) => (
745
+ <span key={item} className="flex items-center gap-1">
746
+ <Check className="w-3 h-3 shrink-0 text-emerald-600 dark:text-emerald-400" />
747
+ {item}
748
+ </span>
749
+ ))}
750
+ </div>
751
+ )}
752
+ </div>
753
+ )
754
+ }
755
+
756
+ // Opened to share one resource: the same dialog and footer, with a body about
757
+ // sharing it instead of the general pitch. It says where the link works and
758
+ // for whom, and nothing about how the connection works; the footer carries
759
+ // that for the lane.
760
+ function ShareBody({ subject, connected }: { subject: CloudHintSubject; connected: boolean }) {
761
+ const chips = [
762
+ `${subject.kind} ${subject.name}`,
763
+ subject.namespace ? `namespace ${subject.namespace}` : undefined,
764
+ subject.context,
765
+ ].filter((c): c is string => !!c)
766
+ return (
767
+ <div className="px-8 pt-7 pb-4">
768
+ <Eyebrow />
769
+ <h3 className="flex items-center gap-2.5 text-[20px] font-semibold leading-tight tracking-tight text-theme-text-primary mb-4">
770
+ <Users className="w-5 h-5 shrink-0 text-emerald-600 dark:text-emerald-400" />
771
+ {`Share ${subject.name} with your team`}
772
+ </h3>
773
+ <div className="card-inner p-3 mb-4">
774
+ <div className="text-[10.5px] font-semibold uppercase tracking-[0.08em] text-theme-text-tertiary mb-2">Resource</div>
775
+ <div className="flex flex-wrap gap-1.5">
776
+ {chips.map((chip) => (
777
+ <span key={chip} className="rounded-md bg-theme-elevated px-2 py-0.5 text-[12px] text-theme-text-primary">
778
+ {chip}
779
+ </span>
780
+ ))}
781
+ </div>
698
782
  </div>
783
+ <p className="text-[13.5px] leading-relaxed text-theme-text-secondary">
784
+ In <b className="font-semibold text-theme-text-primary">Radar Cloud</b>, anyone on your team can open this link. They see what
785
+ their RBAC allows.
786
+ </p>
787
+ {/* Sharing starts by connecting the whole cluster, so say what that keeps,
788
+ as the general pitch does. */}
789
+ {!connected && (
790
+ <p className="mt-2.5 text-[12.5px] leading-relaxed text-theme-text-tertiary">
791
+ Connecting the cluster lets Radar Cloud store its event history, changes and investigation results.
792
+ </p>
793
+ )}
699
794
  </div>
700
795
  )
701
796
  }
@@ -30,6 +30,7 @@ vi.mock('./ui/Tooltip', () => ({
30
30
  Tooltip: ({ children }: { children: ReactNode }) => children,
31
31
  }))
32
32
 
33
+ import { NavCustomizationProvider } from '../context/NavCustomization'
33
34
  import {
34
35
  ConnectionErrorView,
35
36
  CopyableCommand,
@@ -177,8 +178,7 @@ describe('ConnectionErrorView kubeconfig guidance', () => {
177
178
  it('keeps the actionable error and context switch visible for a broken context', () => {
178
179
  const markup = renderError('config', 'prod')
179
180
 
180
- expect(markup).toContain('Cannot Load Cluster Configuration')
181
- expect(markup).toContain('Kubeconfig Problem')
181
+ expect(markup).toMatch(/<h2[^>]*>Kubeconfig Problem<\/h2>/)
182
182
  expect(markup).toContain('aria-expanded="false"')
183
183
  expect(markup).toContain('id="connection-raw-error"')
184
184
  expect(markup).toContain('safe error')
@@ -236,3 +236,64 @@ describe('ConnectionErrorView after a refused switch with a stuck credential plu
236
236
  expect(switchMarkup).toContain('use Retry Connection')
237
237
  })
238
238
  })
239
+
240
+ // The class of the button that comes first, and of the one with a given label.
241
+ function firstButtonClass(markup: string): string {
242
+ return markup.match(/<button[^>]*class="([^"]*)"[^>]*>(?:(?!<\/button>).)*?(Authenticate in terminal|Retry Connection|Back to [^<]*)/s)?.[1] ?? ''
243
+ }
244
+ function buttonClass(markup: string, label: string): string {
245
+ const at = markup.indexOf(label)
246
+ const open = markup.lastIndexOf('<button', at)
247
+ return markup.slice(open, at).match(/class="([^"]*)"/)?.[1] ?? ''
248
+ }
249
+
250
+ describe('ConnectionErrorView next step', () => {
251
+ it('leads a refused switch with the way back, says what still works, and keeps Retry', () => {
252
+ const markup = renderToStaticMarkup(
253
+ <ConnectionErrorView
254
+ connection={{ state: 'disconnected', context: 'staging-eu', errorType: 'timeout', error: 'safe error' }}
255
+ onRetry={() => {}}
256
+ isRetrying={false}
257
+ back={{ label: 'prod-us', onBack: () => {} }}
258
+ variant="switch"
259
+ />,
260
+ )
261
+ expect(markup).toContain('Couldn&#x27;t switch to')
262
+ expect(markup).toContain('You&#x27;re still on')
263
+ expect(firstButtonClass(markup)).toContain('btn-brand')
264
+ expect(buttonClass(markup, 'Back to prod-us')).toContain('btn-brand')
265
+ expect(buttonClass(markup, 'Retry Connection')).toContain('btn-secondary')
266
+ expect(markup.indexOf('Back to prod-us')).toBeLessThan(markup.indexOf('What to check'))
267
+ expect(markup).not.toContain('Switch context')
268
+ })
269
+
270
+ it('keeps Switch context beside Back when the host hides the header picker', () => {
271
+ const markup = renderToStaticMarkup(
272
+ <NavCustomizationProvider value={{ embedded: true }}>
273
+ <ConnectionErrorView
274
+ connection={{ state: 'disconnected', context: 'staging-eu', errorType: 'timeout', error: 'safe error' }}
275
+ onRetry={() => {}}
276
+ isRetrying={false}
277
+ back={{ label: 'prod-us', onBack: () => {} }}
278
+ variant="switch"
279
+ />
280
+ </NavCustomizationProvider>,
281
+ )
282
+ expect(markup).toContain('Back to prod-us')
283
+ expect(markup).toContain('Switch context')
284
+ })
285
+
286
+ it('leads expired credentials with the login, before the details, as the only primary button', () => {
287
+ const markup = renderError('auth', 'gke_project_us-east1_prod')
288
+ expect(buttonClass(markup, 'Authenticate in terminal')).toContain('btn-brand')
289
+ expect(buttonClass(markup, 'Retry Connection')).toContain('btn-secondary')
290
+ expect(markup.match(/btn-brand/g)).toHaveLength(1)
291
+ expect(markup.indexOf('Authenticate in terminal')).toBeLessThan(markup.indexOf('How to fix'))
292
+ })
293
+
294
+ it('leads with Retry when there is nothing to run and nowhere to go back to', () => {
295
+ const markup = renderError('timeout', 'prod')
296
+ expect(buttonClass(markup, 'Retry Connection')).toContain('btn-brand')
297
+ expect(markup.indexOf('Retry Connection')).toBeLessThan(markup.indexOf('What to check'))
298
+ })
299
+ })