@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,7 +1,8 @@
1
- import { useMemo } from 'react'
1
+ import { useId, useMemo } from 'react'
2
2
  import type { Topology } from '../../types'
3
- import { Network, ArrowRight } from 'lucide-react'
4
- import { clsx } from 'clsx'
3
+ import { Network } from 'lucide-react'
4
+ import { useElementSize } from '../../hooks/useElementSize'
5
+ import { HomeDiagramCard } from './HomeDiagramCard'
5
6
 
6
7
  interface TopologyPreviewProps {
7
8
  topology: Topology | null
@@ -9,257 +10,143 @@ interface TopologyPreviewProps {
9
10
  onNavigate: () => void
10
11
  }
11
12
 
12
- /**
13
- * Static schematic SVG that hints at the topology graph layout.
14
- * Two groups with interconnected nodes using real topology color palette.
15
- */
16
- function TopologySchematic() {
17
- // Colors matching the real topology graph
18
- const ingress = '#a78bfa' // violet-400
19
- const service = '#60a5fa' // blue-400
20
- const deploy = '#34d399' // emerald-400
21
- const pod = '#84cc16' // lime-500
22
- const config = '#fbbf24' // amber-400
23
- const groupBorder = 'rgba(59, 130, 246, 0.25)'
24
- const groupBg = 'rgba(59, 130, 246, 0.04)'
25
-
26
- // Edge color — use a concrete color so markers render reliably
27
- const ec = '#64748b' // slate-500
28
-
13
+ // One node drawn like a Topology card: surface, border, the status bar on the
14
+ // left, the kind as a caption and a bar standing in for the name. The bar is
15
+ // neutral: health drawn here would read as this cluster's.
16
+ function SchematicNode({ x, y, w = 46, label, dashed }: {
17
+ x: number; y: number; w?: number; label: string; dashed?: boolean
18
+ }) {
29
19
  return (
30
- <svg viewBox="0 0 160 120" className="w-full h-full" aria-hidden="true">
31
- <defs>
32
- <marker id="arr" viewBox="0 0 8 6" refX="7" refY="3"
33
- markerWidth="6" markerHeight="5" orient="auto">
34
- <path d="M 0 0 L 8 3 L 0 6 z" fill={ec} opacity="0.6" />
35
- </marker>
36
- <marker id="arr-f" viewBox="0 0 8 6" refX="7" refY="3"
37
- markerWidth="6" markerHeight="5" orient="auto">
38
- <path d="M 0 0 L 8 3 L 0 6 z" fill={ec} opacity="0.35" />
39
- </marker>
40
- </defs>
41
-
42
- {/* Group 1 — top: Ingress → Service → Deploys → Pods */}
43
- <rect x="4" y="4" width="100" height="52" rx="6"
44
- fill={groupBg} stroke={groupBorder} strokeWidth="1" strokeDasharray="3 2" />
45
-
46
- {/* Nodes */}
47
- <rect x="10" y="24" width="16" height="10" rx="3" fill={ingress} opacity="0.85" />
48
- <rect x="38" y="24" width="16" height="10" rx="3" fill={service} opacity="0.85" />
49
- <rect x="66" y="14" width="16" height="10" rx="3" fill={deploy} opacity="0.85" />
50
- <rect x="66" y="34" width="16" height="10" rx="3" fill={deploy} opacity="0.85" />
51
- <circle cx="96" cy="19" r="4.5" fill={pod} opacity="0.65" />
52
- <circle cx="96" cy="39" r="4.5" fill={pod} opacity="0.65" />
53
-
54
- {/* Edges — group 1 */}
55
- <line x1="26" y1="29" x2="37" y2="29" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
56
- <line x1="54" y1="29" x2="65" y2="20" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
57
- <line x1="54" y1="29" x2="65" y2="38" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
58
- <line x1="82" y1="19" x2="90" y2="19" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
59
- <line x1="82" y1="39" x2="90" y2="39" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
60
-
61
- {/* Group 2 — bottom: Service → Deploys → Pods + ConfigMap */}
62
- <rect x="30" y="64" width="126" height="52" rx="6"
63
- fill={groupBg} stroke={groupBorder} strokeWidth="1" strokeDasharray="3 2" />
64
-
65
- {/* Nodes */}
66
- <rect x="36" y="82" width="16" height="10" rx="3" fill={service} opacity="0.85" />
67
- <rect x="66" y="72" width="16" height="10" rx="3" fill={deploy} opacity="0.85" />
68
- <rect x="66" y="92" width="16" height="10" rx="3" fill={deploy} opacity="0.85" />
69
- <circle cx="96" cy="73" r="4.5" fill={pod} opacity="0.65" />
70
- <circle cx="96" cy="87" r="4.5" fill={pod} opacity="0.65" />
71
- <circle cx="96" cy="101" r="4.5" fill={pod} opacity="0.65" />
72
-
73
- {/* Config node */}
74
- <rect x="120" y="82" width="16" height="10" rx="3" fill={config} opacity="0.55" />
75
-
76
- {/* Edges — group 2 */}
77
- <line x1="52" y1="87" x2="65" y2="78" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
78
- <line x1="52" y1="87" x2="65" y2="96" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
79
- <line x1="82" y1="77" x2="90" y2="74" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
80
- <line x1="82" y1="77" x2="90" y2="87" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
81
- <line x1="82" y1="97" x2="90" y2="101" stroke={ec} strokeWidth="1" opacity="0.55" markerEnd="url(#arr)" />
82
-
83
- {/* Config dashed edge */}
84
- <line x1="82" y1="77" x2="119" y2="87" stroke={ec} strokeWidth="0.7" opacity="0.3" strokeDasharray="2 2" markerEnd="url(#arr-f)" />
85
-
86
- {/* Cross-group curved edge */}
87
- <path d="M 18 34 Q 18 64, 36 82" fill="none" stroke={ec} strokeWidth="0.8" opacity="0.3" markerEnd="url(#arr-f)" />
88
- </svg>
20
+ <g>
21
+ <rect x={x} y={y} width={w} height={17} rx={3.5} fill="var(--bg-surface)"
22
+ stroke="var(--border-light)" strokeWidth={0.7} strokeDasharray={dashed ? '2 1.5' : undefined} />
23
+ <rect x={x} y={y + 2.5} width={1.8} height={12} rx={0.9} fill="var(--text-tertiary)" opacity={0.6} />
24
+ <rect x={x + 4.8} y={y + 4.4} width={3.6} height={3.6} rx={0.9} fill="var(--text-tertiary)" opacity={0.55} />
25
+ <text x={x + 10.5} y={y + 7.8} fontSize={4.6} fontWeight={600} letterSpacing={0.3} fill="var(--text-tertiary)">{label}</text>
26
+ <rect x={x + 4.8} y={y + 10.8} width={w * 0.55} height={2.4} rx={1.2} fill="var(--text-tertiary)" opacity={0.35} />
27
+ </g>
89
28
  )
90
29
  }
91
30
 
92
- // Derive stats from real topology data
93
- function useTopologyStats(topology: Topology | null) {
94
- return useMemo(() => {
95
- if (!topology || topology.nodes.length === 0) return null
96
-
97
- const kindCounts: Record<string, number> = {}
98
- const healthCounts = { healthy: 0, degraded: 0, unhealthy: 0, unknown: 0 }
99
-
100
- for (const node of topology.nodes) {
101
- kindCounts[node.kind] = (kindCounts[node.kind] || 0) + 1
102
- if (node.status in healthCounts) {
103
- healthCounts[node.status as keyof typeof healthCounts]++
104
- }
105
- }
31
+ // The drawing's height in its own units. Its width follows the card, up to a
32
+ // limit, so the picture fills a wide card instead of floating in the middle.
33
+ const SCHEMATIC_H = 128
34
+ const SCHEMATIC_MIN_W = 296
35
+ const SCHEMATIC_MAX_W = 560
106
36
 
107
- // Top kinds sorted by display priority
108
- const kindPriority: Record<string, number> = {
109
- Deployment: 1, Rollout: 1, StatefulSet: 2, DaemonSet: 2,
110
- Service: 3, Ingress: 4, Gateway: 4,
111
- HTTPRoute: 4, GRPCRoute: 4, TCPRoute: 4, TLSRoute: 4, UDPRoute: 4,
112
- Pod: 5, PodGroup: 5,
113
- Job: 6, CronJob: 6, ConfigMap: 7, Secret: 7,
114
- }
115
- const topKinds = Object.entries(kindCounts)
116
- .filter(([kind]) => kind !== 'Internet')
117
- .sort(([a], [b]) => (kindPriority[a] || 99) - (kindPriority[b] || 99))
118
- .slice(0, 8)
119
-
120
- return { topKinds, healthCounts }
121
- }, [topology])
122
- }
37
+ // A static picture of what Topology draws: traffic entering an Ingress and
38
+ // fanning out through Services to workloads, in two namespace groups. It is a
39
+ // hint at the view, not a rendering of this cluster, so it never moves and
40
+ // looks the same whatever the cluster's size.
41
+ function TopologySchematic() {
42
+ const arrow = `${useId()}-arrow`
43
+ const [ref, size] = useElementSize<HTMLDivElement>({ width: SCHEMATIC_MIN_W, height: SCHEMATIC_H })
44
+ const width = Math.min(SCHEMATIC_MAX_W, Math.max(SCHEMATIC_MIN_W, (SCHEMATIC_H * size.width) / size.height))
45
+ // Extra width spreads the five columns (web, ingress, service, workload,
46
+ // pods) apart rather than stretching the nodes.
47
+ const extra = width - SCHEMATIC_MIN_W
48
+ const col = (c: number) => (extra * c) / 4
49
+ const X = { web: 4, ingress: 54 + col(1), service: 112 + col(2), workload: 170 + col(3), pods: 228 + col(4) }
50
+ const W = { node: 46, pods: 56 }
51
+
52
+ const edge = (x1: number, y1: number, x2: number, y2: number, dashed?: boolean) => {
53
+ const k = Math.max(10, (x2 - x1) * 0.6)
54
+ return (
55
+ <path d={`M ${x1} ${y1} C ${x1 + k} ${y1}, ${x2 - k} ${y2}, ${x2} ${y2}`} fill="none"
56
+ stroke="var(--text-tertiary)" strokeWidth={0.7} opacity={dashed ? 0.35 : 0.55}
57
+ strokeDasharray={dashed ? '2 1.5' : undefined} markerEnd={`url(#${arrow})`} />
58
+ )
59
+ }
60
+ const groupX = X.ingress - 8
61
+ const group = (y: number, h: number, name: string) => (
62
+ <g>
63
+ <rect x={groupX} y={y} width={X.pods + W.pods + 10 - groupX} height={h} rx={7} fill="var(--group-header-namespace)"
64
+ fillOpacity={0.45} stroke="var(--group-border-namespace)" strokeWidth={0.7} strokeDasharray="3 2" />
65
+ <text x={groupX + 6} y={y + 8} fontSize={4.6} fontFamily="var(--font-mono, monospace)" fill="var(--text-tertiary)">{name}</text>
66
+ </g>
67
+ )
68
+ const right = (x: number, w = W.node) => x + w
123
69
 
124
- const kindDotColors: Record<string, string> = {
125
- Deployment: 'bg-emerald-400', Rollout: 'bg-emerald-400',
126
- StatefulSet: 'bg-cyan-400', DaemonSet: 'bg-teal-400',
127
- Service: 'bg-blue-400', Ingress: 'bg-violet-400', Gateway: 'bg-violet-400',
128
- HTTPRoute: 'bg-purple-400', GRPCRoute: 'bg-purple-400', TCPRoute: 'bg-purple-400', TLSRoute: 'bg-purple-400', UDPRoute: 'bg-purple-400',
129
- Pod: 'bg-lime-500', PodGroup: 'bg-lime-500',
130
- Job: 'bg-purple-400', CronJob: 'bg-purple-400',
131
- ConfigMap: 'bg-amber-400', Secret: 'bg-red-400',
132
- ReplicaSet: 'bg-green-400', HPA: 'bg-pink-500', PVC: 'bg-cyan-400',
70
+ return (
71
+ <div ref={ref} className="w-full h-full">
72
+ <svg viewBox={`0 2 ${width} ${SCHEMATIC_H}`} className="w-full h-full" preserveAspectRatio="xMidYMid meet" aria-hidden="true">
73
+ <defs>
74
+ <marker id={arrow} viewBox="0 0 8 6" refX="7" refY="3" markerWidth="5" markerHeight="4" orient="auto">
75
+ <path d="M 0 0 L 8 3 L 0 6 z" fill="var(--text-tertiary)" opacity="0.7" />
76
+ </marker>
77
+ </defs>
78
+
79
+ {group(4, 62, 'storefront')}
80
+ {group(72, 56, 'payments')}
81
+
82
+ <rect x={X.web} y={54} width={32} height={16} rx={8} fill="var(--bg-surface)" stroke="var(--border-light)" strokeWidth={0.7} />
83
+ <circle cx={X.web + 7.5} cy={62} r={2.5} fill="none" stroke="var(--color-brand)" strokeWidth={0.8} />
84
+ <text x={X.web + 12} y={63.6} fontSize={4.6} fontWeight={600} fill="var(--text-tertiary)">WEB</text>
85
+
86
+ {edge(X.web + 32, 62, X.ingress, 36)}
87
+ {edge(right(X.ingress), 36, X.service, 36)}
88
+ {edge(right(X.ingress), 36, X.service, 102)}
89
+ {edge(right(X.service), 36, X.workload, 24)}
90
+ {edge(right(X.service), 36, X.workload, 48)}
91
+ {edge(right(X.workload), 24, X.pods, 24)}
92
+ {edge(right(X.workload), 48, X.pods, 48)}
93
+ {edge(right(X.service), 102, X.workload, 90)}
94
+ {edge(right(X.service), 102, X.workload, 112)}
95
+ {edge(right(X.workload), 90, X.pods, 90)}
96
+ {edge(right(X.workload), 112, X.pods, 112, true)}
97
+
98
+ <SchematicNode x={X.ingress} y={28} label="INGRESS" />
99
+ <SchematicNode x={X.service} y={28} label="SERVICE" />
100
+ <SchematicNode x={X.workload} y={16} label="DEPLOY" />
101
+ <SchematicNode x={X.workload} y={40} label="DEPLOY" />
102
+ <SchematicNode x={X.pods} y={16} w={W.pods} label="PODS ×3" />
103
+ <SchematicNode x={X.pods} y={40} w={W.pods} label="PODS ×2" />
104
+
105
+ <SchematicNode x={X.service} y={94} label="SERVICE" />
106
+ <SchematicNode x={X.workload} y={82} label="DEPLOY" />
107
+ <SchematicNode x={X.workload} y={104} label="STATEFUL" />
108
+ <SchematicNode x={X.pods} y={82} w={W.pods} label="PODS ×2" />
109
+ <SchematicNode x={X.pods} y={104} w={W.pods} label="CONFIG" dashed />
110
+ </svg>
111
+ </div>
112
+ )
133
113
  }
134
114
 
135
115
  export function TopologyPreview({ topology, namespaceSelected, onNavigate }: TopologyPreviewProps) {
136
- const stats = useTopologyStats(topology)
137
-
138
116
  // A large cluster with no namespace filter gets an empty graph carrying this
139
- // flag instead of a build. There is no graph to preview and there never will
140
- // be until the user filters, so the card says that rather than counting a
141
- // refusal as zero.
117
+ // flag instead of a build, and Topology asks for a namespace. The card keeps
118
+ // its drawing but states no counts, which would read the refusal as zero.
142
119
  //
143
120
  // With a pick already active the same flag means something else entirely: SSE
144
121
  // only learns to filter server-side after a flagged frame arrives, so a
145
122
  // cluster-wide refusal still reaches a viewer whose namespace is on its way
146
- // to the server. That resolves on its own, and asking for what the viewer
147
- // already chose is the wrong thing to say while it does.
123
+ // to the server. That resolves on its own, so the header keeps loading.
148
124
  const needsNamespaceFilter = topology?.requiresNamespaceFilter === true && !namespaceSelected
149
125
 
150
- // The graph this card draws is the only source for its caption. Node count is
151
- // not the test for whether a frame counts — the stream holds topology at null
152
- // until one lands and resets it there on reconnect and context switch, so a
153
- // delivered graph with no nodes is an empty scope and an honest zero.
126
+ // Node count is not the test for whether a frame counts — the stream holds
127
+ // topology at null until one lands and resets it there on reconnect and
128
+ // context switch, so a delivered graph with no nodes is an empty scope and an
129
+ // honest zero.
154
130
  const counts = useMemo(() => {
155
131
  if (!topology || topology.requiresNamespaceFilter) return null
156
132
  return { nodeCount: topology.nodes.length, edgeCount: topology.edges.length }
157
133
  }, [topology])
158
134
 
159
- return (
160
- <button
161
- onClick={onNavigate}
162
- className="group h-[260px] rounded-xl bg-theme-surface shadow-theme-sm hover:-translate-y-1 hover:shadow-theme-md transition-all duration-200 text-left overflow-hidden"
163
- >
164
- <div className="flex flex-col h-full w-full">
165
- <div className="flex items-center justify-between px-5 py-3 border-b border-theme-border/50">
166
- <div className="flex items-center gap-2">
167
- <Network className="w-4 h-4 text-theme-text-tertiary" />
168
- <span className="text-xs font-semibold uppercase tracking-wider text-theme-text-secondary">Topology</span>
169
- </div>
170
- {counts ? (
171
- <span className="text-[11px] text-theme-text-tertiary">
172
- {counts.nodeCount} resources &middot; {counts.edgeCount} conn
173
- </span>
174
- ) : needsNamespaceFilter ? null : (
175
- <span className="h-3 w-28 rounded bg-theme-text-tertiary/20 animate-pulse" />
176
- )}
177
- </div>
178
-
179
- {/* Stats (left) + Schematic (right) */}
180
- <div className="flex-1 flex items-stretch min-h-0 px-3 py-1.5 gap-2">
181
- {needsNamespaceFilter ? (
182
- <div className="flex-1 flex items-center justify-center px-4">
183
- <p className="text-[11px] leading-relaxed text-theme-text-tertiary text-center">
184
- This cluster is too large to graph every namespace.
185
- <br />
186
- <span className="text-theme-text-secondary font-medium">Select a namespace</span> to view the topology.
187
- </p>
188
- </div>
189
- ) : (
190
- <>
191
- {/* Left: compact stats */}
192
- <div className="flex flex-col justify-center gap-0.5 min-w-0 w-[105px] shrink-0">
193
- {stats ? (
194
- <>
195
- {stats.topKinds.map(([kind, count]) => (
196
- <div key={kind} className="flex items-center gap-1.5 text-[10px] leading-tight">
197
- <span className={clsx(
198
- 'w-1.5 h-1.5 rounded-full shrink-0',
199
- kindDotColors[kind] || 'bg-theme-text-tertiary',
200
- )} />
201
- <span className="text-theme-text-primary font-medium w-5 text-right tabular-nums">{count}</span>
202
- <span className="text-theme-text-tertiary truncate">{kind}</span>
203
- </div>
204
- ))}
205
-
206
- {(stats.healthCounts.degraded > 0 || stats.healthCounts.unhealthy > 0) && (
207
- <div className="flex items-center gap-1.5 text-[10px] text-theme-text-tertiary mt-0.5 pt-1 border-t border-theme-border/50">
208
- {stats.healthCounts.unhealthy > 0 && (
209
- <span className="flex items-center gap-0.5">
210
- <span className="w-1.5 h-1.5 rounded-full bg-red-500" />
211
- {stats.healthCounts.unhealthy}
212
- </span>
213
- )}
214
- {stats.healthCounts.degraded > 0 && (
215
- <span className="flex items-center gap-0.5">
216
- <span className="w-1.5 h-1.5 rounded-full bg-yellow-500" />
217
- {stats.healthCounts.degraded}
218
- </span>
219
- )}
220
- </div>
221
- )}
222
- </>
223
- ) : (
224
- // No graph yet, or one with nothing in scope. Until a frame lands
225
- // there is no honest number here — a zero would read as an empty
226
- // cluster, so pulse instead.
227
- <div className="flex flex-col gap-0.5">
228
- <div className="flex items-center gap-1.5 text-[10px] leading-tight">
229
- <span className={clsx('w-1.5 h-1.5 rounded-full shrink-0', counts ? 'bg-blue-400' : 'bg-theme-text-tertiary/30 animate-pulse')} />
230
- {counts ? (
231
- <span className="text-theme-text-primary font-medium w-5 text-right tabular-nums">{counts.nodeCount}</span>
232
- ) : (
233
- <span className="h-3 w-5 rounded bg-theme-text-tertiary/20 animate-pulse" />
234
- )}
235
- <span className="text-theme-text-tertiary">resources</span>
236
- </div>
237
- <div className="flex items-center gap-1.5 text-[10px] leading-tight">
238
- <span className={clsx('w-1.5 h-1.5 rounded-full shrink-0', counts ? 'bg-theme-text-tertiary' : 'bg-theme-text-tertiary/30 animate-pulse')} />
239
- {counts ? (
240
- <span className="text-theme-text-primary font-medium w-5 text-right tabular-nums">{counts.edgeCount}</span>
241
- ) : (
242
- <span className="h-3 w-5 rounded bg-theme-text-tertiary/10 animate-pulse" />
243
- )}
244
- <span className="text-theme-text-tertiary">connections</span>
245
- </div>
246
- </div>
247
- )}
248
- </div>
249
-
250
- {/* Right: schematic illustration */}
251
- <div className="flex-1 flex items-center min-w-0">
252
- <TopologySchematic />
253
- </div>
254
- </>
255
- )}
256
- </div>
135
+ const fact = counts ? (
136
+ <>{counts.nodeCount} resources &middot; {counts.edgeCount} relationships</>
137
+ ) : needsNamespaceFilter ? undefined : (
138
+ <span data-testid="topology-counts-loading" className="inline-block h-3 w-28 rounded bg-theme-text-tertiary/20 animate-pulse align-middle" />
139
+ )
257
140
 
258
- <div className="px-4 py-1.5 border-t border-theme-border/50 flex items-center justify-end gap-1.5 text-[10px] font-semibold uppercase tracking-wider text-theme-text-secondary group-hover:text-theme-text-primary transition-colors">
259
- Open Topology
260
- <ArrowRight className="w-3.5 h-3.5 transition-transform group-hover:translate-x-0.5" />
261
- </div>
262
- </div>
263
- </button>
141
+ return (
142
+ <HomeDiagramCard
143
+ icon={Network}
144
+ title="Topology"
145
+ fact={fact}
146
+ drawing={<TopologySchematic />}
147
+ caption="How ingresses, services and workloads connect, grouped by namespace."
148
+ footer="Open Topology"
149
+ onNavigate={onNavigate}
150
+ />
264
151
  )
265
152
  }
@@ -0,0 +1,63 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
+ import type { DashboardTrafficSummary } from '../../api/client'
6
+ import { TrafficSummary, trafficSourceName } from './TrafficSummary'
7
+
8
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
9
+
10
+ let container: HTMLDivElement
11
+ let root: Root
12
+
13
+ beforeEach(() => {
14
+ container = document.createElement('div')
15
+ document.body.appendChild(container)
16
+ root = createRoot(container)
17
+ })
18
+
19
+ afterEach(() => {
20
+ act(() => root.unmount())
21
+ container.remove()
22
+ })
23
+
24
+ function render(data: DashboardTrafficSummary | null, onNavigate = vi.fn()) {
25
+ act(() => root.render(<TrafficSummary data={data} onNavigate={onNavigate} />))
26
+ return onNavigate
27
+ }
28
+
29
+ const header = () => container.querySelector('button > div > div')!.textContent
30
+ const drawing = () => container.querySelector('svg')!.outerHTML
31
+
32
+ const observed: DashboardTrafficSummary = { source: 'hubble' }
33
+
34
+ describe('TrafficSummary', () => {
35
+ it('names no source until the server has detected one', () => {
36
+ render(null)
37
+ expect(header()).toBe('Live Traffic')
38
+ expect(container.textContent).not.toMatch(/Needs a traffic source|Nothing to show/)
39
+ })
40
+
41
+ it('names the detected source in the header', () => {
42
+ render(observed)
43
+ expect(header()).toBe('Live TrafficHubble')
44
+ })
45
+
46
+ it('draws the same picture with or without a detected source', () => {
47
+ render(null)
48
+ const empty = drawing()
49
+ render(observed)
50
+ expect(drawing()).toBe(empty)
51
+ })
52
+
53
+ it('opens Live Traffic from anywhere on the card', () => {
54
+ const onNavigate = render(null)
55
+ act(() => container.querySelector('button')!.click())
56
+ expect(onNavigate).toHaveBeenCalledOnce()
57
+ })
58
+
59
+ it('capitalises an unknown source name', () => {
60
+ expect(trafficSourceName('istio')).toBe('Istio')
61
+ expect(trafficSourceName('cilium')).toBe('Cilium')
62
+ })
63
+ })