@skyhook-io/radar-app 1.17.1 → 1.18.1

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 (146) hide show
  1. package/README.md +6 -0
  2. package/package.json +10 -11
  3. package/src/App.tsx +36 -36
  4. package/src/api/client.gitops-destination.test.tsx +55 -0
  5. package/src/api/client.gitopsPoll.test.ts +99 -0
  6. package/src/api/client.helmPreview.test.tsx +48 -0
  7. package/src/api/client.resource-list.test.ts +76 -0
  8. package/src/api/client.resourceAvailability.test.ts +24 -0
  9. package/src/api/client.ts +396 -105
  10. package/src/api/client.workloadRuns.test.ts +53 -0
  11. package/src/api/config.test.ts +23 -1
  12. package/src/api/config.ts +7 -3
  13. package/src/api/diagnose.ts +4 -1
  14. package/src/api/drain-plan.test.ts +70 -40
  15. package/src/api/policy.ts +5 -5
  16. package/src/api/quotas.ts +9 -20
  17. package/src/api/radarFeatures.ts +3 -0
  18. package/src/api/resourceLists.test.ts +84 -0
  19. package/src/api/resourceLists.ts +71 -0
  20. package/src/api/traffic.scope.render.test.tsx +60 -0
  21. package/src/api/traffic.ts +3 -1
  22. package/src/components/cnpg/CNPGSummaryHost.tsx +4 -3
  23. package/src/components/cnpg/CNPGView.tsx +1 -0
  24. package/src/components/compare/CompareResourcePicker.test.tsx +58 -0
  25. package/src/components/compare/CompareViewRoute.tsx +5 -1
  26. package/src/components/compare/useCompareCandidates.ts +1 -1
  27. package/src/components/compare/useCompareLauncher.tsx +4 -2
  28. package/src/components/diagnose/DiagnoseSurface.tsx +3 -3
  29. package/src/components/diagnose/InvestigationChangesEvidence.test.tsx +352 -0
  30. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +101 -0
  31. package/src/components/diagnose/InvestigationView.tsx +2 -1
  32. package/src/components/diagnose/StoryExcerpt.tsx +24 -5
  33. package/src/components/diagnose/investigationEvidence/adapters/changes.test.ts +123 -0
  34. package/src/components/diagnose/investigationEvidence/adapters/changes.ts +192 -3
  35. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +73 -51
  36. package/src/components/diagnose/investigationEvidence/adapters/listCoverage.test.ts +415 -0
  37. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +64 -2
  38. package/src/components/diagnose/investigationEvidence/adapters/resource.test.ts +37 -0
  39. package/src/components/diagnose/investigationEvidence/adapters/resource.ts +107 -8
  40. package/src/components/diagnose/investigationEvidence/adapters/testdata/get-changes-created.json +323 -0
  41. package/src/components/diagnose/investigationEvidence/bodies/inventory.tsx +66 -16
  42. package/src/components/diagnose/investigationEvidence/bodies/streams.tsx +144 -15
  43. package/src/components/diagnose/investigationEvidence/builder.ts +13 -1
  44. package/src/components/diagnose/investigationEvidence/excerpt.ts +2 -0
  45. package/src/components/diagnose/investigationEvidence/observations.ts +21 -0
  46. package/src/components/diagnose/investigationEvidence/parse.ts +57 -1
  47. package/src/components/diagnose/investigationEvidence/projection.test.ts +131 -1
  48. package/src/components/diagnose/investigationEvidence/types.ts +26 -0
  49. package/src/components/diagnose/investigationEvidencePresentation.test.ts +18 -0
  50. package/src/components/diagnose/investigationState.test.ts +36 -1
  51. package/src/components/diagnose/investigationState.ts +8 -0
  52. package/src/components/diagnose/launch.ts +2 -2
  53. package/src/components/diagnose/toolCallLabel.test.ts +9 -0
  54. package/src/components/diagnose/toolCallLabel.ts +2 -0
  55. package/src/components/dock/BottomDock.tsx +6 -3
  56. package/src/components/dock/WorkloadLogsTab.tsx +3 -0
  57. package/src/components/execution/BatchExecutionView.image-browse.test.tsx +46 -0
  58. package/src/components/execution/BatchExecutionView.render.test.tsx +29 -1
  59. package/src/components/execution/BatchExecutionView.tsx +28 -11
  60. package/src/components/execution/cluster-template-runs.render.test.tsx +42 -0
  61. package/src/components/gitops/GitOpsView.identity.test.tsx +113 -0
  62. package/src/components/gitops/GitOpsView.tsx +69 -40
  63. package/src/components/gitops/useDestinationCluster.ts +2 -1
  64. package/src/components/helm/ArtifactHubSourceSearch.test.tsx +124 -0
  65. package/src/components/helm/ArtifactHubSourceSearch.tsx +240 -0
  66. package/src/components/helm/ChartBrowser.tsx +5 -4
  67. package/src/components/helm/HelmReleaseDrawer.tsx +139 -55
  68. package/src/components/helm/HelmReleaseNotes.test.tsx +42 -0
  69. package/src/components/helm/HelmReleaseNotes.tsx +26 -0
  70. package/src/components/helm/OwnedResources.tsx +2 -2
  71. package/src/components/helm/TrackChartSourceDialog.render.test.tsx +295 -50
  72. package/src/components/helm/TrackChartSourceDialog.test.ts +3 -2
  73. package/src/components/helm/TrackChartSourceDialog.tsx +614 -85
  74. package/src/components/helm/ValuesDiffPreview.tsx +4 -1
  75. package/src/components/home/ClusterHealthCard.tsx +4 -4
  76. package/src/components/home/CostCard.test.tsx +100 -0
  77. package/src/components/home/CostCard.tsx +2 -2
  78. package/src/components/home/HelmSummary.tsx +2 -2
  79. package/src/components/home/HomeView.tsx +15 -6
  80. package/src/components/home/MCPSetupDialog.test.tsx +30 -0
  81. package/src/components/home/MCPSetupDialog.tsx +13 -6
  82. package/src/components/home/ProblemsPanel.test.tsx +1 -0
  83. package/src/components/home/mcpToolCatalog.ts +28 -2
  84. package/src/components/issues/IssuesPane.render.test.tsx +21 -0
  85. package/src/components/issues/IssuesPane.tsx +31 -7
  86. package/src/components/issues/UncheckedSourceHelp.test.tsx +42 -0
  87. package/src/components/issues/UncheckedSourceHelp.tsx +24 -0
  88. package/src/components/issues/uncheckedSources.test.ts +43 -0
  89. package/src/components/issues/uncheckedSources.ts +58 -5
  90. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +4 -2
  91. package/src/components/resource/PrometheusCharts.overlays.test.ts +45 -0
  92. package/src/components/resource/PrometheusCharts.tsx +2 -2
  93. package/src/components/resources/ImageFilesystemModal.test.tsx +68 -0
  94. package/src/components/resources/ImageFilesystemModal.tsx +11 -4
  95. package/src/components/resources/PodFilesystemModal.tsx +2 -2
  96. package/src/components/resources/ResourcesView.scope.render.test.tsx +58 -0
  97. package/src/components/resources/ResourcesView.tsx +46 -69
  98. package/src/components/resources/renderers/FluxHelmReleaseRenderer.test.tsx +111 -0
  99. package/src/components/resources/renderers/FluxHelmReleaseRenderer.tsx +67 -0
  100. package/src/components/resources/renderers/KyvernoPolicyCoverage.scope.render.test.tsx +64 -0
  101. package/src/components/resources/renderers/KyvernoPolicyCoverage.tsx +6 -7
  102. package/src/components/resources/renderers/PodRenderer.tsx +4 -1
  103. package/src/components/settings/MyPermissionsDialog.tsx +12 -9
  104. package/src/components/settings/SettingsDialog.tsx +21 -15
  105. package/src/components/traffic/TrafficFilterSidebar.test.tsx +77 -0
  106. package/src/components/traffic/TrafficFilterSidebar.tsx +42 -31
  107. package/src/components/traffic/TrafficSourcePill.test.tsx +110 -0
  108. package/src/components/traffic/TrafficSourcePill.tsx +111 -0
  109. package/src/components/traffic/TrafficView.tsx +21 -67
  110. package/src/components/traffic/trafficFilters.test.ts +20 -1
  111. package/src/components/traffic/trafficFilters.ts +13 -0
  112. package/src/components/ui/DiagnosticsOverlay.test.ts +25 -0
  113. package/src/components/ui/DiagnosticsOverlay.tsx +2 -1
  114. package/src/components/ui/Omnibar.note.test.tsx +141 -0
  115. package/src/components/ui/Omnibar.tsx +89 -14
  116. package/src/components/ui/RadarOmnibar.test.tsx +183 -0
  117. package/src/components/ui/RadarOmnibar.tsx +38 -4
  118. package/src/components/ui/Toast.tsx +1 -1
  119. package/src/components/ui/UpdateNotification.manual.test.tsx +177 -0
  120. package/src/components/ui/UpdateNotification.test.tsx +2 -1
  121. package/src/components/ui/UpdateNotification.tsx +29 -5
  122. package/src/components/ui/omnibar-match.test.ts +37 -0
  123. package/src/components/ui/omnibar-match.ts +23 -0
  124. package/src/components/ui/searchCoverage.fixtures.ts +16 -0
  125. package/src/components/ui/searchCoverageNote.test.ts +245 -0
  126. package/src/components/ui/searchCoverageNote.ts +222 -0
  127. package/src/components/whats-new/WhatsNew.test.ts +10 -0
  128. package/src/components/whats-new/WhatsNew.tsx +5 -4
  129. package/src/components/whats-new/WhatsNewDialog.test.tsx +20 -0
  130. package/src/components/whats-new/releaseNotes.ts +57 -5
  131. package/src/components/workload/CronJobSchedulingEvidence.test.tsx +35 -0
  132. package/src/components/workload/CronJobSchedulingEvidence.tsx +37 -0
  133. package/src/components/workload/NodeDrainStatus.test.tsx +253 -0
  134. package/src/components/workload/NodeDrainStatus.tsx +55 -0
  135. package/src/components/workload/WorkloadView.tsx +43 -5
  136. package/src/context/ConnectionContext.test.ts +27 -1
  137. package/src/context/ConnectionContext.tsx +17 -7
  138. package/src/hooks/useResourceCounts.ts +2 -0
  139. package/src/index.css +2 -4
  140. package/src/index.ts +7 -0
  141. package/src/integrations/resourceHosts.test.tsx +1 -0
  142. package/src/integrations/resourceHosts.tsx +2 -0
  143. package/src/utils/artifacthub.test.ts +18 -0
  144. package/src/utils/artifacthub.ts +9 -0
  145. package/src/utils/navigation.ts +14 -0
  146. package/src/utils/wails-clipboard.ts +4 -2
@@ -0,0 +1,110 @@
1
+ // @vitest-environment jsdom
2
+ import { act, type ComponentProps } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
+ import { TrafficSourcePill } from './TrafficSourcePill'
6
+
7
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
8
+
9
+ type Props = ComponentProps<typeof TrafficSourcePill>
10
+
11
+ const props = (overrides: Partial<Props>): Props => ({
12
+ sources: ['hubble', 'istio'],
13
+ active: 'istio',
14
+ connection: 'connected',
15
+ onSwitch: vi.fn(),
16
+ onRetry: vi.fn(),
17
+ ...overrides,
18
+ })
19
+
20
+ let container: HTMLDivElement
21
+ let root: Root
22
+
23
+ beforeEach(() => {
24
+ container = document.createElement('div')
25
+ document.body.appendChild(container)
26
+ root = createRoot(container)
27
+ })
28
+
29
+ afterEach(() => {
30
+ act(() => root.unmount())
31
+ container.remove()
32
+ })
33
+
34
+ const render = (p: Props) => act(() => root.render(<TrafficSourcePill {...p} />))
35
+
36
+ const button = (label: string) =>
37
+ Array.from(container.querySelectorAll('button')).find((b) => b.textContent?.trim() === label)
38
+
39
+ const open = () => act(() => button('istio')!.click())
40
+
41
+ describe('TrafficSourcePill', () => {
42
+ it('switches source from the picker when connected', () => {
43
+ const p = props({})
44
+ render(p)
45
+ open()
46
+ act(() => button('hubble')!.click())
47
+ expect(p.onSwitch).toHaveBeenCalledWith('hubble')
48
+ })
49
+
50
+ it('keeps the picker available when the active source failed to connect', () => {
51
+ const p = props({ connection: 'error' })
52
+ render(p)
53
+ open()
54
+ act(() => button('hubble')!.click())
55
+ expect(p.onSwitch).toHaveBeenCalledWith('hubble')
56
+ })
57
+
58
+ it('offers retry next to the picker on error', () => {
59
+ const p = props({ connection: 'error' })
60
+ render(p)
61
+ act(() => button('retry')!.click())
62
+ expect(p.onRetry).toHaveBeenCalledTimes(1)
63
+ expect(button('istio')).toBeDefined()
64
+ })
65
+
66
+ it('does not switch when the active source is picked again', () => {
67
+ const p = props({})
68
+ render(p)
69
+ open()
70
+ act(() => container.querySelector<HTMLButtonElement>('[role="option"][aria-selected="true"]')!.click())
71
+ expect(p.onSwitch).not.toHaveBeenCalled()
72
+ })
73
+
74
+ it('shows no picker with a single available source', () => {
75
+ render(props({ sources: ['istio'] }))
76
+ expect(container.querySelector('button[aria-haspopup]')).toBeNull()
77
+ expect(container.textContent).toContain('istio')
78
+ })
79
+
80
+ it('shows no picker or retry while connecting', () => {
81
+ render(props({ connection: 'connecting' }))
82
+ expect(container.textContent).toContain('Connecting...')
83
+ expect(container.querySelector('button')).toBeNull()
84
+ })
85
+
86
+ it('does not reopen the menu after a retry made without a mouse', () => {
87
+ const p = props({ connection: 'error' })
88
+ render(p)
89
+ open()
90
+ expect(container.querySelector('[role="listbox"]')).not.toBeNull()
91
+ act(() => button('retry')!.click())
92
+ render({ ...p, connection: 'connecting' })
93
+ render({ ...p, connection: 'connected' })
94
+ const menu = container.querySelector('[role="listbox"]')
95
+ expect(menu === null || menu.hasAttribute('inert')).toBe(true)
96
+ expect(button('istio')!.getAttribute('aria-expanded')).toBe('false')
97
+ })
98
+
99
+ it('makes the menu inert while it animates closed, so its options cannot be activated', () => {
100
+ const p = props({})
101
+ render(p)
102
+ open()
103
+ expect(container.querySelector('[role="listbox"]')!.hasAttribute('inert')).toBe(false)
104
+ act(() => {
105
+ document.body.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }))
106
+ })
107
+ const closing = container.querySelector('[role="listbox"]')
108
+ expect(closing === null || closing.hasAttribute('inert')).toBe(true)
109
+ })
110
+ })
@@ -0,0 +1,111 @@
1
+ import { useEffect, useRef, useState } from 'react'
2
+ import { clsx } from 'clsx'
3
+ import { ChevronDown, Loader2 } from 'lucide-react'
4
+ import { StatusDot, toneTextClass } from '@skyhook-io/k8s-ui'
5
+ import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
6
+ import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '../../utils/animation'
7
+
8
+ export type TrafficSourceConnectionState = 'connecting' | 'error' | 'connected'
9
+
10
+ interface TrafficSourcePillProps {
11
+ sources: string[]
12
+ active: string
13
+ connection: TrafficSourceConnectionState
14
+ onSwitch: (name: string) => void
15
+ onRetry: () => void
16
+ }
17
+
18
+ // The picker is shown for every connection state except connecting: a source
19
+ // that cannot connect is the case where the user most needs to pick another.
20
+ export function TrafficSourcePill({ sources, active, connection, onSwitch, onRetry }: TrafficSourcePillProps) {
21
+ const [open, setOpen] = useState(false)
22
+ const pickerRef = useRef<HTMLDivElement>(null)
23
+ const canPick = sources.length > 1
24
+ const menuOpen = open && canPick && connection !== 'connecting'
25
+ const { shouldRender, isOpen } = useAnimatedUnmount(menuOpen, overlayExitMs('menu'))
26
+
27
+ // Capture phase so the handler runs before ReactFlow swallows the event.
28
+ useEffect(() => {
29
+ if (!open) return
30
+ const handler = (e: MouseEvent) => {
31
+ if (pickerRef.current && !pickerRef.current.contains(e.target as Node)) {
32
+ setOpen(false)
33
+ }
34
+ }
35
+ document.addEventListener('mousedown', handler, true)
36
+ return () => document.removeEventListener('mousedown', handler, true)
37
+ }, [open])
38
+
39
+ const choose = (name: string) => {
40
+ setOpen(false)
41
+ if (name !== active) onSwitch(name)
42
+ }
43
+
44
+ // Keyboard activation of retry fires no outside mousedown, so the menu has to
45
+ // be closed here or it would reappear once the attempt finishes.
46
+ const retry = () => {
47
+ setOpen(false)
48
+ onRetry()
49
+ }
50
+
51
+ return (
52
+ <div className="flex items-center gap-1.5 px-2 py-1 rounded-lg bg-theme-surface/90 backdrop-blur border border-theme-border text-[11px]">
53
+ {connection === 'connecting' ? (
54
+ <>
55
+ <Loader2 className="h-3 w-3 animate-spin text-accent" />
56
+ <span className="text-accent">Connecting...</span>
57
+ </>
58
+ ) : (
59
+ <>
60
+ <StatusDot tone={connection === 'error' ? 'degraded' : 'healthy'} size="md" />
61
+ {canPick ? (
62
+ <div className="relative" ref={pickerRef}>
63
+ <button
64
+ type="button"
65
+ onClick={() => setOpen(!open)}
66
+ aria-haspopup="listbox"
67
+ aria-expanded={menuOpen}
68
+ className="flex items-center gap-1 text-theme-text-secondary hover:text-theme-text-primary"
69
+ >
70
+ {active} <ChevronDown className="h-3 w-3" />
71
+ </button>
72
+ {shouldRender && (
73
+ <div
74
+ role="listbox"
75
+ inert={!menuOpen || undefined}
76
+ className={clsx(
77
+ 'absolute top-full left-0 mt-1 z-50 bg-theme-surface border border-theme-border rounded-md shadow-theme-lg py-1 min-w-[120px] origin-top-left',
78
+ TRANSITION_MENU,
79
+ isOpen ? 'opacity-100 scale-100' : 'opacity-0 scale-[0.97]',
80
+ !menuOpen && 'pointer-events-none',
81
+ )}
82
+ style={overlayTransitionStyle(isOpen, 'menu')}
83
+ >
84
+ {sources.map(name => (
85
+ <button
86
+ key={name}
87
+ type="button"
88
+ role="option"
89
+ aria-selected={name === active}
90
+ onClick={() => choose(name)}
91
+ className={clsx('w-full text-left px-3 py-1 text-xs hover:bg-theme-hover capitalize', name === active && 'text-accent')}
92
+ >
93
+ {name}
94
+ </button>
95
+ ))}
96
+ </div>
97
+ )}
98
+ </div>
99
+ ) : (
100
+ <span className="text-theme-text-secondary">{active}</span>
101
+ )}
102
+ {connection === 'error' && (
103
+ <button type="button" onClick={retry} className={clsx('font-medium hover:underline', toneTextClass('degraded'))}>
104
+ retry
105
+ </button>
106
+ )}
107
+ </>
108
+ )}
109
+ </div>
110
+ )
111
+ }
@@ -7,17 +7,17 @@ import { TrafficWizard } from './TrafficWizard'
7
7
  import { TrafficGraph, type TrafficGraphSelection } from './TrafficGraph'
8
8
  import { TrafficFilterSidebar } from './TrafficFilterSidebar'
9
9
  import { TrafficFlowListProvider } from './TrafficFlowListContext'
10
- import { Loader2, Filter, Plug, ChevronDown, List, Activity, AlertTriangle, Clock, Crosshair, X } from 'lucide-react'
10
+ import { Filter, Plug, List, Activity, AlertTriangle, Clock, Crosshair, X } from 'lucide-react'
11
11
  import { TrafficFocusSearch } from './TrafficFocusSearch'
12
+ import { TrafficSourcePill } from './TrafficSourcePill'
12
13
  import { TrafficGraphTooLarge } from './TrafficGraphTooLarge'
13
- import { clsx } from 'clsx'
14
14
  import { useQueryClient } from '@tanstack/react-query'
15
15
  import { useDock } from '../dock'
16
16
  import { AlertBanner, EmptyState, PaneLoader, FreshnessControl } from '@skyhook-io/k8s-ui'
17
17
  import { useConnection } from '../../context/ConnectionContext'
18
18
  import { Tooltip } from '../ui/Tooltip'
19
19
  import { SEVERITY_TEXT } from '@skyhook-io/k8s-ui/utils/badge-colors'
20
- import { matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, type VolumeUnit, isExternalKind, mergeFlowVolume, coverageLabel, type GraphFlow, endpointPair, graphEndpoint, graphEndpointId, mergeRawPairs, mergedEdgePort, selectedEdgeMatcher, selectionRawPairs, selectionMatch, graphSize, GRAPH_DRAW_BUDGET, GRAPH_DRAW_CEILING, parseFocus, focusParam, focusId, focusNeighborhood, touchesFocus, endpointSummaries, namespaceSummaries, type TrafficFocus } from './trafficFilters'
20
+ import { matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, type VolumeUnit, isExternalKind, mergeFlowVolume, coverageLabel, type GraphFlow, endpointPair, graphEndpoint, graphEndpointId, mergeRawPairs, mergedEdgePort, selectedEdgeMatcher, selectionRawPairs, selectionMatch, graphSize, GRAPH_DRAW_BUDGET, GRAPH_DRAW_CEILING, parseFocus, focusParam, focusId, focusNeighborhood, touchesFocus, endpointSummaries, namespaceSummaries, verdictChoices, type TrafficFocus } from './trafficFilters'
21
21
 
22
22
  // Consecutive 2s retries of an empty result that came with a transient warning.
23
23
  const MAX_EMPTY_RETRIES = 5
@@ -449,7 +449,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
449
449
  const [l7Protocol, setL7Protocol] = useState<string>('all')
450
450
  const [l7Methods, setL7Methods] = useState<Set<string>>(new Set())
451
451
  const [l7StatusRanges, setL7StatusRanges] = useState<Set<string>>(new Set())
452
- const [l7Verdicts, setL7Verdicts] = useState<Set<string>>(new Set())
452
+ const [verdicts, setVerdicts] = useState<Set<string>>(new Set())
453
453
  const [dnsPattern, setDnsPattern] = useState('')
454
454
  const [isConnecting, setIsConnecting] = useState(false)
455
455
  const [connectionError, setConnectionError] = useState<string | null>(null)
@@ -457,8 +457,6 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
457
457
  const connectMutation = useTrafficConnect()
458
458
  const setSourceMutation = useSetTrafficSource()
459
459
  const hasAutoConnectedRef = useRef(false)
460
- const [sourcePickerOpen, setSourcePickerOpen] = useState(false)
461
- const sourcePickerRef = useRef<HTMLDivElement>(null)
462
460
 
463
461
  // Track cluster context to reset state on cluster change
464
462
  const { data: clusterInfo } = useClusterInfo()
@@ -479,18 +477,6 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
479
477
  lastClusterRef.current = currentCluster
480
478
  }, [clusterInfo?.context, queryClient])
481
479
 
482
- // Close source picker on outside click (capture phase to beat ReactFlow)
483
- useEffect(() => {
484
- if (!sourcePickerOpen) return
485
- const handler = (e: MouseEvent) => {
486
- if (sourcePickerRef.current && !sourcePickerRef.current.contains(e.target as Node)) {
487
- setSourcePickerOpen(false)
488
- }
489
- }
490
- document.addEventListener('mousedown', handler, true)
491
- return () => document.removeEventListener('mousedown', handler, true)
492
- }, [sourcePickerOpen])
493
-
494
480
  const {
495
481
  data: sourcesData,
496
482
  isLoading: sourcesLoading,
@@ -576,7 +562,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
576
562
  // all, so offering 2xx or a DNS box would be a dead end.
577
563
  const l7Capabilities = useMemo(() => {
578
564
  const statuses = new Set<string>()
579
- const verdicts = new Set<string>()
565
+ const seenVerdicts = new Set<string>()
580
566
  let hasDNSQueries = false
581
567
  const methods = new Set<string>()
582
568
  for (const f of flowsData?.aggregated ?? []) {
@@ -586,7 +572,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
586
572
  // An error rate is a 5xx signal even where no status distribution exists.
587
573
  if ((f.errorCount ?? 0) > 0) statuses.add('5xx')
588
574
  for (const [verdict, count] of Object.entries(f.verdictCounts ?? {})) {
589
- if (count > 0) verdicts.add(verdict)
575
+ if (count > 0) seenVerdicts.add(verdict)
590
576
  }
591
577
  if (f.topDNSQueries?.length) hasDNSQueries = true
592
578
  for (const path of f.topHTTPPaths ?? []) {
@@ -595,7 +581,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
595
581
  }
596
582
  return {
597
583
  availableStatusRanges: ['2xx', '3xx', '4xx', '5xx'].filter(b => statuses.has(b)),
598
- availableVerdicts: ['forwarded', 'dropped', 'error'].filter(v => verdicts.has(v)),
584
+ availableVerdicts: verdictChoices(seenVerdicts),
599
585
  hasDNSQueries,
600
586
  availableHTTPMethods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'].filter(m => methods.has(m)),
601
587
  }
@@ -611,8 +597,8 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
611
597
  () => keepAvailable(l7Methods, l7Capabilities.availableHTTPMethods),
612
598
  [l7Methods, l7Capabilities.availableHTTPMethods])
613
599
  const activeVerdicts = useMemo(
614
- () => keepAvailable(l7Verdicts, l7Capabilities.availableVerdicts),
615
- [l7Verdicts, l7Capabilities.availableVerdicts])
600
+ () => keepAvailable(verdicts, l7Capabilities.availableVerdicts),
601
+ [verdicts, l7Capabilities.availableVerdicts])
616
602
  const activeDnsPattern = l7Capabilities.hasDNSQueries ? dnsPattern : ''
617
603
  const activeMinConnections = effectiveThreshold(minConnections, minConnectionsUnit, volumeUnit(isRateBased))
618
604
 
@@ -777,8 +763,8 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
777
763
  const toggleL7StatusRange = useCallback((range: string) => {
778
764
  setL7StatusRanges(prev => { const next = new Set(prev); if (next.has(range)) next.delete(range); else next.add(range); return next })
779
765
  }, [])
780
- const toggleL7Verdict = useCallback((verdict: string) => {
781
- setL7Verdicts(prev => { const next = new Set(prev); if (next.has(verdict)) next.delete(verdict); else next.add(verdict); return next })
766
+ const toggleVerdict = useCallback((verdict: string) => {
767
+ setVerdicts(prev => { const next = new Set(prev); if (next.has(verdict)) next.delete(verdict); else next.add(verdict); return next })
782
768
  }, [])
783
769
 
784
770
  // Toggle namespace visibility
@@ -1287,7 +1273,7 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1287
1273
  setL7Protocol('all')
1288
1274
  setL7Methods(new Set())
1289
1275
  setL7StatusRanges(new Set())
1290
- setL7Verdicts(new Set())
1276
+ setVerdicts(new Set())
1291
1277
  setDnsPattern('')
1292
1278
  }, [chooseMinConnections])
1293
1279
 
@@ -1430,8 +1416,8 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1430
1416
  onToggleL7Method={toggleL7Method}
1431
1417
  l7StatusRanges={l7StatusRanges}
1432
1418
  onToggleL7StatusRange={toggleL7StatusRange}
1433
- l7Verdicts={l7Verdicts}
1434
- onToggleL7Verdict={toggleL7Verdict}
1419
+ verdicts={verdicts}
1420
+ onToggleVerdict={toggleVerdict}
1435
1421
  dnsPattern={dnsPattern}
1436
1422
  setDnsPattern={setDnsPattern}
1437
1423
  namespaces={namespacesWithCounts}
@@ -1449,8 +1435,6 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1449
1435
  const activeSource = availableSources.find(s => s.name === activeName) || availableSources[0]
1450
1436
 
1451
1437
  const handleSwitchSource = (name: string) => {
1452
- if (name === activeSource?.name) { setSourcePickerOpen(false); return }
1453
- setSourcePickerOpen(false)
1454
1438
  setIsConnecting(true)
1455
1439
  setConnectionError(null)
1456
1440
  hasAutoConnectedRef.current = true
@@ -1509,43 +1493,13 @@ export function TrafficView({ namespaces, onSetNamespaces }: TrafficViewProps) {
1509
1493
  />
1510
1494
  )}
1511
1495
  {activeSource && (
1512
- <div className="flex items-center gap-1.5 px-2 py-1 rounded-lg bg-theme-surface/90 backdrop-blur border border-theme-border text-[11px]">
1513
- {isConnecting ? (
1514
- <>
1515
- <Loader2 className="h-3 w-3 animate-spin text-blue-400" />
1516
- <span className="text-blue-400">Connecting...</span>
1517
- </>
1518
- ) : connectionError ? (
1519
- <>
1520
- <span className="w-2 h-2 rounded-full bg-yellow-500" />
1521
- <span className="text-theme-text-secondary">{activeSource.name}</span>
1522
- <button onClick={() => handleConnect(true)} className="text-yellow-500 hover:text-yellow-400 font-medium">retry</button>
1523
- </>
1524
- ) : (
1525
- <>
1526
- <span className="w-2 h-2 rounded-full bg-green-500" />
1527
- {availableSources.length > 1 ? (
1528
- <div className="relative" ref={sourcePickerRef}>
1529
- <button onClick={() => setSourcePickerOpen(!sourcePickerOpen)} className="flex items-center gap-1 text-theme-text-secondary hover:text-theme-text-primary">
1530
- {activeSource.name} <ChevronDown className="h-3 w-3" />
1531
- </button>
1532
- {sourcePickerOpen && (
1533
- <div className="absolute top-full left-0 mt-1 z-50 bg-theme-surface border border-theme-border rounded-md shadow-lg py-1 min-w-[120px]">
1534
- {availableSources.map(source => (
1535
- <button key={source.name} onClick={() => handleSwitchSource(source.name)}
1536
- className={clsx('w-full text-left px-3 py-1 text-xs hover:bg-theme-hover capitalize', source.name === activeSource.name && 'text-blue-400')}>
1537
- {source.name}
1538
- </button>
1539
- ))}
1540
- </div>
1541
- )}
1542
- </div>
1543
- ) : (
1544
- <span className="text-theme-text-secondary">{activeSource.name}</span>
1545
- )}
1546
- </>
1547
- )}
1548
- </div>
1496
+ <TrafficSourcePill
1497
+ sources={availableSources.map(s => s.name)}
1498
+ active={activeSource.name}
1499
+ connection={isConnecting ? 'connecting' : connectionError ? 'error' : 'connected'}
1500
+ onSwitch={handleSwitchSource}
1501
+ onRetry={() => handleConnect(true)}
1502
+ />
1549
1503
  )}
1550
1504
  </div>
1551
1505
 
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect } from 'vitest'
2
2
  import type { AggregatedFlow, TrafficFlow } from '../../types'
3
- import { matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, isExternalKind, isPolicyDropReason, requestRateOf, errorRateOf, formatRate, displayVolume, mergeFlowVolume, dedupeHTTPPairs, coverageLabel, latencyWeightOf, endpointPair, selectionRawPairs, mergeRawPairs, graphEndpoint, graphSize, parseFocus, focusParam, focusId, touchesFocus, focusNeighborhood, endpointSummaries, searchEndpoints, namespaceSummaries, namespaceOverBudget, hasStatusData, connectionRows, selectionMatch, edgeCarriesPort, edgesOnPort, mergedEdgePort, selectedEdgeMatcher, type GraphFlow } from './trafficFilters'
3
+ import { matchesStatusRanges, bucketsFromCounts, bucketsFromStatus, isRateBasedSource, keepAvailable, effectiveThreshold, volumeUnit, isExternalKind, isPolicyDropReason, requestRateOf, errorRateOf, formatRate, displayVolume, mergeFlowVolume, dedupeHTTPPairs, coverageLabel, latencyWeightOf, endpointPair, selectionRawPairs, mergeRawPairs, graphEndpoint, graphSize, parseFocus, focusParam, focusId, touchesFocus, focusNeighborhood, endpointSummaries, searchEndpoints, namespaceSummaries, namespaceOverBudget, hasStatusData, connectionRows, selectionMatch, edgeCarriesPort, edgesOnPort, mergedEdgePort, selectedEdgeMatcher, verdictChoices, type GraphFlow } from './trafficFilters'
4
4
 
5
5
  describe('matchesStatusRanges', () => {
6
6
  it('does not filter when nothing is selected', () => {
@@ -678,3 +678,22 @@ describe('mergedEdgePort', () => {
678
678
  expect(mergedEdgePort(0, 0)).toBe(0)
679
679
  })
680
680
  })
681
+
682
+ describe('verdictChoices', () => {
683
+ it('offers forwarded and dropped when both are present', () => {
684
+ expect(verdictChoices(['forwarded', 'dropped'])).toEqual(['forwarded', 'dropped'])
685
+ })
686
+
687
+ it('offers forwarded and error from a source that reports errors', () => {
688
+ expect(verdictChoices(['error', 'forwarded'])).toEqual(['forwarded', 'error'])
689
+ })
690
+
691
+ it('offers nothing when every flow is forwarded, since the filter would match all', () => {
692
+ expect(verdictChoices(['forwarded'])).toEqual([])
693
+ expect(verdictChoices([])).toEqual([])
694
+ })
695
+
696
+ it('offers Forwarded when another verdict without a chip is present, since it then excludes something', () => {
697
+ expect(verdictChoices(['forwarded', 'redirected'])).toEqual(['forwarded'])
698
+ })
699
+ })
@@ -695,3 +695,16 @@ export function connectionRows<T extends AggregatedFlow>(flows: T[]): T[] {
695
695
  keyed.sort(byProblemsThenVolume)
696
696
  return keyed.map(k => k.flow)
697
697
  }
698
+
699
+ /**
700
+ * The verdict filter's choices, from the verdicts the flows contain. Caretta,
701
+ * Beyla and Istio report every flow forwarded unless they saw an error, so when
702
+ * forwarded is the only verdict present the filter would match everything and
703
+ * none is offered. Any other verdict, even one without a chip of its own (Hubble
704
+ * also reports redirected, audit and more), makes Forwarded a real choice.
705
+ */
706
+ export function verdictChoices(seen: Iterable<string>): string[] {
707
+ const present = new Set(seen)
708
+ if (present.size === 1 && present.has('forwarded')) return []
709
+ return ['forwarded', 'dropped', 'error'].filter(v => present.has(v))
710
+ }
@@ -27,6 +27,31 @@ const desktop: NonNullable<DiagnosticsSnapshot['desktop']> = {
27
27
  gpuPolicy: 'on-demand',
28
28
  }
29
29
 
30
+ describe('formatForGitHub profiling state', () => {
31
+ it.each([
32
+ [true, 'true'],
33
+ [false, 'false'],
34
+ [undefined, 'unknown'],
35
+ ] as const)('reports %s as %s', (pprof, expected) => {
36
+ const md = formatForGitHub({
37
+ ...baseSnapshot,
38
+ config: {
39
+ port: 9280,
40
+ devMode: false,
41
+ timelineStorage: 'memory',
42
+ historyLimit: 10000,
43
+ debugEvents: false,
44
+ mcpEnabled: true,
45
+ mcpReadOnly: false,
46
+ hasPrometheusURL: false,
47
+ hasPrometheusHeaders: false,
48
+ pprof,
49
+ },
50
+ }, undefined, false)
51
+ expect(md).toContain(`Pprof: ${expected}`)
52
+ })
53
+ })
54
+
30
55
  describe('formatEnvValue', () => {
31
56
  it('separates a variable that was never set from one set to empty', () => {
32
57
  // Only the second suppresses the desktop app's own WebKit defaults, so
@@ -622,6 +622,7 @@ function ConfigSection({ data }: { data: DiagnosticsSnapshot }) {
622
622
  <Section title="Config">
623
623
  <Row label="Port" value={cfg.port} />
624
624
  <Row label="Dev Mode" value={cfg.devMode ? 'Yes' : 'No'} />
625
+ <Row label="Profiling (pprof)" value={cfg.pprof === undefined ? 'Unknown' : cfg.pprof ? 'Yes' : 'No'} />
625
626
  {cfg.namespace && <Row label="Namespace Filter" value={cfg.namespace} />}
626
627
  <Row label="Timeline Storage" value={cfg.timelineStorage} />
627
628
  <Row label="History Limit" value={cfg.historyLimit.toLocaleString()} />
@@ -864,7 +865,7 @@ export function formatForGitHub(data: DiagnosticsSnapshot, frontendPerf?: K8sUIP
864
865
  if (data.config) {
865
866
  const cfg = data.config
866
867
  lines.push(`### Config`)
867
- lines.push(`- Port: ${cfg.port} | Dev: ${cfg.devMode} | Timeline: \`${cfg.timelineStorage}\` | History: ${cfg.historyLimit} | MCP: ${cfg.mcpEnabled} | Prometheus URL: ${cfg.hasPrometheusURL ? 'manual' : 'auto'}`)
868
+ lines.push(`- Port: ${cfg.port} | Dev: ${cfg.devMode} | Pprof: ${cfg.pprof ?? 'unknown'} | Timeline: \`${cfg.timelineStorage}\` | History: ${cfg.historyLimit} | MCP: ${cfg.mcpEnabled} | Prometheus URL: ${cfg.hasPrometheusURL ? 'manual' : 'auto'}`)
868
869
  lines.push(``)
869
870
  }
870
871
 
@@ -0,0 +1,141 @@
1
+ // @vitest-environment jsdom
2
+ import { act, createRef } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
5
+ import { Omnibar, type OmnibarHandle, type OmnibarNote } from './Omnibar'
6
+ import { searchCoverageNote } from './searchCoverageNote'
7
+ import { coverageOf } from './searchCoverage.fixtures'
8
+
9
+ vi.mock('../../api/usage-data', () => ({ recordUsageEvent: vi.fn() }))
10
+
11
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
12
+ let root: Root
13
+ let host: HTMLDivElement
14
+
15
+ beforeEach(() => {
16
+ vi.useFakeTimers()
17
+ // jsdom has no layout; the omnibar scrolls the selected row into view.
18
+ Element.prototype.scrollIntoView = vi.fn()
19
+ host = document.createElement('div')
20
+ document.body.appendChild(host)
21
+ root = createRoot(host)
22
+ })
23
+
24
+ afterEach(() => {
25
+ act(() => root.unmount())
26
+ host.remove()
27
+ document.body.innerHTML = ''
28
+ vi.useRealTimers()
29
+ })
30
+
31
+ function render(note: OmnibarNote | undefined, { isPlaceholderData = false, isFetching = false } = {}) {
32
+ act(() => {
33
+ root.render(<Omnibar onOpenResource={vi.fn()} commandItems={[]} searchData={{ hits: [] }} note={note} isPlaceholderData={isPlaceholderData} isFetching={isFetching} />)
34
+ })
35
+ }
36
+
37
+ function typeQuery(text: string) {
38
+ const input = host.querySelector('input')!
39
+ act(() => input.focus())
40
+ act(() => {
41
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, text)
42
+ input.dispatchEvent(new Event('input', { bubbles: true }))
43
+ })
44
+ act(() => { vi.advanceTimersByTime(200) })
45
+ }
46
+
47
+ const findButton = (label: string) => [...document.body.querySelectorAll('button')].find((b) => b.textContent === label)
48
+
49
+ describe('Omnibar note', () => {
50
+ const recoveryText = "Couldn't read Certificate; matches of that kind may be missing. Search kind:Certificate to re-check."
51
+ const namespace = searchCoverageNote(coverageOf([{ kind: '*', group: '', reason: 'radar_namespace_not_collected', namespaces: ['rel-owner'] }]), {})!
52
+ const loading = searchCoverageNote(coverageOf([{ kind: '*', group: '', reason: 'kind_sync_pending' }]), {})!
53
+
54
+ it.each([
55
+ ['alone', [], []],
56
+ ['before a namespace note', [], [namespace]],
57
+ ['after a namespace note', [namespace], []],
58
+ ['before a loading note', [], [loading]],
59
+ ['after a loading note', [loading], []],
60
+ ['between loading and namespace notes', [loading], [namespace]],
61
+ ['between namespace and loading notes', [namespace], [loading]],
62
+ ] as [string, OmnibarNote[], OmnibarNote[]][])(
63
+ 'renders the recovery action inside its sentence %s and adds its modifier', (_, before, after) => {
64
+ const ref = createRef<OmnibarHandle>()
65
+ const onQueryChange = vi.fn()
66
+ const recovery = searchCoverageNote(coverageOf([{ kind: 'Certificate', group: 'cert-manager.io', reason: 'read_error' }]), {
67
+ recheckKind: (kind) => ref.current?.addModifier({ key: 'kind', value: kind }),
68
+ })!
69
+ const parts = [...before, recovery, ...after]
70
+ const expected = [...before.map((part) => part.text), recoveryText, ...after.map((part) => part.text)].join(' ')
71
+ act(() => {
72
+ root.render(<Omnibar ref={ref} onOpenResource={vi.fn()} commandItems={[]} searchData={{ hits: [] }} onQueryChange={onQueryChange} note={parts.length === 1 ? recovery : { text: expected, parts }} />)
73
+ })
74
+ typeQuery('ns:prod')
75
+ act(() => host.querySelector('input')!.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true })))
76
+ typeQuery('renewal')
77
+ const button = findButton('kind:Certificate')!
78
+ expect(button).toBeDefined()
79
+ expect(button.parentElement!.textContent?.trim()).toBe(recoveryText)
80
+ expect(button.parentElement!.parentElement!.textContent).toBe(expected)
81
+ act(() => button.click())
82
+ act(() => { vi.advanceTimersByTime(300) })
83
+ expect(onQueryChange).toHaveBeenLastCalledWith('ns:prod kind:Certificate renewal', true)
84
+ expect(host.querySelector('input')!.value).toContain('renewal')
85
+ },
86
+ )
87
+
88
+ it('shows the host note under the empty results and runs its action on click, then closes', () => {
89
+ const onSelect = vi.fn()
90
+ render({ text: "Leases can't be searched.", action: { label: 'Open the Leases list instead.', onSelect } })
91
+ typeQuery('lease')
92
+ expect(document.body.textContent).toContain("Leases can't be searched.")
93
+
94
+ const action = findButton('Open the Leases list instead.')!
95
+ const mousedown = new MouseEvent('mousedown', { bubbles: true, cancelable: true })
96
+ act(() => { action.dispatchEvent(mousedown) })
97
+ expect(mousedown.defaultPrevented).toBe(true)
98
+ expect(onSelect).not.toHaveBeenCalled()
99
+
100
+ // Keyboard activation of a focused button dispatches click too.
101
+ act(() => action.click())
102
+ act(() => { vi.advanceTimersByTime(500) })
103
+ expect(onSelect).toHaveBeenCalledOnce()
104
+ expect(host.querySelector('input')!.value).toBe('')
105
+ expect(document.body.textContent).not.toContain("Leases can't be searched.")
106
+ })
107
+
108
+ it('hides a note that belongs to a previous query', () => {
109
+ render({ text: 'Still loading — results may change.' }, { isPlaceholderData: true })
110
+ typeQuery('lease')
111
+ expect(document.body.textContent).not.toContain('Still loading')
112
+ })
113
+
114
+ it('shows the note above the results, where a full page of hits cannot push it out of view', () => {
115
+ const hits = Array.from({ length: 20 }, (_, i) => ({ score: 1, kind: 'Certificate', group: 'cert-manager.io', namespace: 'a', name: `lease-${i}` }))
116
+ act(() => {
117
+ root.render(<Omnibar onOpenResource={vi.fn()} commandItems={[]} searchData={{ hits }} note={{ text: "Couldn't read Certificate (networking.internal.knative.dev)." }} />)
118
+ })
119
+ typeQuery('lease')
120
+ const text = document.body.textContent ?? ''
121
+ expect(text.indexOf("Couldn't read Certificate")).toBeGreaterThan(-1)
122
+ expect(text.indexOf("Couldn't read Certificate")).toBeLessThan(text.indexOf('lease-0'))
123
+ })
124
+
125
+ it('keeps the empty state and note steady while the same query re-fetches', () => {
126
+ render({ text: 'Still loading — results may change.' }, { isFetching: true })
127
+ typeQuery('lease')
128
+ expect(document.body.textContent).toContain('No matches in what Radar searched.')
129
+ expect(document.body.textContent).toContain('Still loading — results may change.')
130
+ })
131
+
132
+ it('claims no match only when the search covered everything it was asked about', () => {
133
+ render(undefined)
134
+ typeQuery('lease')
135
+ expect(document.body.textContent).toContain('No resources match “lease”.')
136
+ render({ text: "Leases can't be searched." })
137
+ typeQuery('lease')
138
+ expect(document.body.textContent).toContain('No matches in what Radar searched.')
139
+ expect(document.body.textContent).not.toContain('No resources match')
140
+ })
141
+ })