@skyhook-io/radar-app 1.18.0 → 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.
- package/README.md +6 -0
- package/package.json +2 -3
- package/src/App.tsx +22 -6
- package/src/api/client.gitops-destination.test.tsx +55 -0
- package/src/api/client.resource-list.test.ts +76 -0
- package/src/api/client.ts +61 -20
- package/src/api/quotas.ts +9 -20
- package/src/api/radarFeatures.ts +2 -0
- package/src/api/resourceLists.test.ts +84 -0
- package/src/api/resourceLists.ts +71 -0
- package/src/components/cnpg/CNPGView.tsx +1 -0
- package/src/components/compare/CompareResourcePicker.test.tsx +58 -0
- package/src/components/compare/CompareViewRoute.tsx +5 -1
- package/src/components/compare/useCompareCandidates.ts +1 -1
- package/src/components/compare/useCompareLauncher.tsx +4 -2
- package/src/components/diagnose/StoryExcerpt.tsx +24 -5
- package/src/components/diagnose/investigationEvidence/adapters/listCoverage.test.ts +415 -0
- package/src/components/diagnose/investigationEvidence/adapters/resource.ts +107 -8
- package/src/components/diagnose/investigationEvidence/bodies/inventory.tsx +66 -16
- package/src/components/diagnose/investigationEvidence/builder.ts +13 -1
- package/src/components/diagnose/investigationEvidence/excerpt.ts +2 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +1 -0
- package/src/components/diagnose/investigationEvidence/projection.test.ts +24 -1
- package/src/components/diagnose/investigationEvidence/types.ts +15 -0
- package/src/components/diagnose/toolCallLabel.test.ts +9 -0
- package/src/components/diagnose/toolCallLabel.ts +2 -0
- package/src/components/execution/BatchExecutionView.image-browse.test.tsx +46 -0
- package/src/components/execution/BatchExecutionView.tsx +6 -4
- package/src/components/gitops/GitOpsView.identity.test.tsx +113 -0
- package/src/components/gitops/GitOpsView.tsx +62 -40
- package/src/components/gitops/useDestinationCluster.ts +2 -1
- package/src/components/helm/ArtifactHubSourceSearch.test.tsx +124 -0
- package/src/components/helm/ArtifactHubSourceSearch.tsx +240 -0
- package/src/components/helm/ChartBrowser.tsx +5 -4
- package/src/components/helm/TrackChartSourceDialog.render.test.tsx +269 -96
- package/src/components/helm/TrackChartSourceDialog.tsx +607 -104
- package/src/components/home/mcpToolCatalog.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +45 -0
- package/src/components/resource/PrometheusCharts.tsx +2 -2
- package/src/components/resources/ResourcesView.tsx +29 -67
- package/src/components/resources/renderers/PodRenderer.tsx +4 -1
- package/src/components/settings/MyPermissionsDialog.tsx +12 -9
- package/src/components/traffic/TrafficSourcePill.test.tsx +110 -0
- package/src/components/traffic/TrafficSourcePill.tsx +111 -0
- package/src/components/traffic/TrafficView.tsx +9 -55
- package/src/components/ui/DiagnosticsOverlay.test.ts +25 -0
- package/src/components/ui/DiagnosticsOverlay.tsx +2 -1
- package/src/components/ui/Omnibar.note.test.tsx +141 -0
- package/src/components/ui/Omnibar.tsx +82 -18
- package/src/components/ui/RadarOmnibar.test.tsx +183 -0
- package/src/components/ui/RadarOmnibar.tsx +38 -4
- package/src/components/ui/UpdateNotification.manual.test.tsx +177 -0
- package/src/components/ui/UpdateNotification.test.tsx +2 -1
- package/src/components/ui/UpdateNotification.tsx +29 -5
- package/src/components/ui/omnibar-match.test.ts +15 -8
- package/src/components/ui/omnibar-match.ts +11 -6
- package/src/components/ui/searchCoverage.fixtures.ts +16 -0
- package/src/components/ui/searchCoverageNote.test.ts +245 -0
- package/src/components/ui/searchCoverageNote.ts +222 -0
- package/src/components/whats-new/WhatsNew.test.ts +10 -0
- package/src/components/whats-new/WhatsNew.tsx +5 -4
- package/src/components/whats-new/WhatsNewDialog.test.tsx +20 -0
- package/src/components/whats-new/releaseNotes.ts +57 -5
- package/src/components/workload/WorkloadView.tsx +8 -2
- package/src/hooks/useResourceCounts.ts +2 -0
- package/src/index.css +2 -4
- package/src/index.ts +7 -0
- package/src/utils/artifacthub.test.ts +18 -0
- package/src/utils/artifacthub.ts +9 -0
|
@@ -7,10 +7,10 @@ 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 {
|
|
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'
|
|
@@ -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,
|
|
@@ -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
|
-
<
|
|
1513
|
-
{
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
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
|
|
|
@@ -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
|
+
})
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useState, useMemo, useRef, useEffect, useCallback, forwardRef, useImperativeHandle, type ReactNode } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
|
-
import { Search, CornerDownLeft, Loader2, AlertTriangle } from 'lucide-react'
|
|
3
|
+
import { Search, CornerDownLeft, Loader2, AlertTriangle, Info } from 'lucide-react'
|
|
4
4
|
import { clsx } from 'clsx'
|
|
5
5
|
import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
|
|
6
6
|
import { TRANSITION_BACKDROP, TRANSITION_MENU, TW_EASE_UI, overlayExitMs, overlayTransitionStyle } from '../../utils/animation'
|
|
7
7
|
import { SearchPillInput, type SearchModifier } from '@skyhook-io/k8s-ui'
|
|
8
8
|
import { getResourceIcon } from '../../utils/resource-icons'
|
|
9
9
|
import type { SearchHit, SearchMatchedField } from '../../api/client'
|
|
10
|
-
import { contentMatchLabel,
|
|
10
|
+
import { contentMatchLabel, partialSearchNotices } from './omnibar-match'
|
|
11
11
|
import { recordUsageEvent } from '../../api/usage-data'
|
|
12
12
|
import { bestScore, type CommandItem } from './command-items'
|
|
13
13
|
import { SearchSyntaxHelp } from './SearchSyntaxHelp'
|
|
@@ -35,6 +35,19 @@ export interface OmnibarSearchResult {
|
|
|
35
35
|
access_incomplete?: boolean
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// A host-provided line about the current search (what was or wasn't searched),
|
|
39
|
+
// shown muted above the results or the empty state. The host interprets its
|
|
40
|
+
// own search response; the omnibar only renders the text and optional action.
|
|
41
|
+
export interface OmnibarNotePart {
|
|
42
|
+
text: string
|
|
43
|
+
action?: { label: string; suffix?: string; onSelect: () => void; keepOpen?: boolean }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface OmnibarNote extends OmnibarNotePart {
|
|
47
|
+
/** When supplied, renders these parts in order instead of the top-level text/action. */
|
|
48
|
+
parts?: OmnibarNotePart[]
|
|
49
|
+
}
|
|
50
|
+
|
|
38
51
|
// Health → dot color (summaryContext.health is the same vocabulary as the rest
|
|
39
52
|
// of Radar). Kept local + tiny to avoid pulling the full status-tone system.
|
|
40
53
|
function healthDot(health?: string): string | null {
|
|
@@ -88,6 +101,7 @@ function useDebounced<T>(value: T, ms: number): T {
|
|
|
88
101
|
}
|
|
89
102
|
|
|
90
103
|
export interface OmnibarHandle {
|
|
104
|
+
addModifier: (modifier: SearchModifier) => void
|
|
91
105
|
focus: () => void
|
|
92
106
|
}
|
|
93
107
|
|
|
@@ -106,6 +120,10 @@ export interface OmnibarProps {
|
|
|
106
120
|
isError?: boolean
|
|
107
121
|
/** True while React Query serves a previous query's data — gates Enter/clicks. */
|
|
108
122
|
isPlaceholderData?: boolean
|
|
123
|
+
/** Optional note about the current search's coverage, from the host. A
|
|
124
|
+
* note says part of the scope wasn't searched, so an empty result is then
|
|
125
|
+
* qualified rather than reported as no match. */
|
|
126
|
+
note?: OmnibarNote
|
|
109
127
|
/** Bounded modifier value sets to autocomplete (e.g. { ns: [...], kind: [...] }). */
|
|
110
128
|
modifierOptions?: Record<string, string[]>
|
|
111
129
|
/** Namespaces to seed as removable `ns:` pills when the launcher opens empty
|
|
@@ -160,6 +178,7 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
160
178
|
isFetching = false,
|
|
161
179
|
isError = false,
|
|
162
180
|
isPlaceholderData = false,
|
|
181
|
+
note,
|
|
163
182
|
modifierOptions,
|
|
164
183
|
seedNamespaces,
|
|
165
184
|
loadRecents,
|
|
@@ -186,7 +205,13 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
186
205
|
// whole top bar.
|
|
187
206
|
const [anchor, setAnchor] = useState<{ centerX: number; top: number; width: number } | null>(null)
|
|
188
207
|
|
|
189
|
-
useImperativeHandle(ref, () => ({
|
|
208
|
+
useImperativeHandle(ref, () => ({
|
|
209
|
+
focus: () => { inputRef.current?.focus(); inputRef.current?.select() },
|
|
210
|
+
addModifier: (modifier) => {
|
|
211
|
+
setPills((prev) => prev.some((p) => p.key === modifier.key && p.value === modifier.value) ? prev : [...prev, modifier])
|
|
212
|
+
inputRef.current?.focus()
|
|
213
|
+
},
|
|
214
|
+
}), [])
|
|
190
215
|
|
|
191
216
|
// Usage data: one count per opening, one per opening that searched. Never
|
|
192
217
|
// the query itself.
|
|
@@ -348,6 +373,13 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
348
373
|
return Math.max(1, Math.floor(list.clientHeight / rowH) - 1)
|
|
349
374
|
}
|
|
350
375
|
|
|
376
|
+
const close = useCallback(() => {
|
|
377
|
+
setOpen(false)
|
|
378
|
+
setText('')
|
|
379
|
+
setPills([])
|
|
380
|
+
inputRef.current?.blur()
|
|
381
|
+
}, [])
|
|
382
|
+
|
|
351
383
|
const execute = useCallback((row: Row) => {
|
|
352
384
|
if (row.kind === 'command') {
|
|
353
385
|
row.command.action()
|
|
@@ -358,15 +390,16 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
358
390
|
recordRecent?.({ kind: h.kind, group: h.group, namespace: h.namespace, name: h.name, cluster: h.cluster, clusterName: h.clusterName })
|
|
359
391
|
onOpenResource(h)
|
|
360
392
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
setPills([])
|
|
364
|
-
inputRef.current?.blur()
|
|
365
|
-
}, [onOpenResource, recordRecent, onViewAllResults])
|
|
393
|
+
close()
|
|
394
|
+
}, [onOpenResource, recordRecent, onViewAllResults, close])
|
|
366
395
|
|
|
367
396
|
// The resources shown don't (yet) belong to the current query: the debounce
|
|
368
397
|
// hasn't fired, the data is React Query placeholder, or results haven't landed.
|
|
369
398
|
const resourcesStale = searchActive && (debounced !== queryString || isPlaceholderData || (resourceRows.length === 0 && isFetching))
|
|
399
|
+
// A note describes the response it came from: hide it while the shown data
|
|
400
|
+
// belongs to another query, but not during a background refetch of this one.
|
|
401
|
+
const currentData = searchData !== undefined && debounced === queryString && !isPlaceholderData
|
|
402
|
+
const shownNote = searchActive && !isError && currentData ? note : undefined
|
|
370
403
|
|
|
371
404
|
const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
|
|
372
405
|
if (e.key === 'Escape') { e.preventDefault(); setOpen(false); inputRef.current?.blur(); return }
|
|
@@ -387,11 +420,11 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
387
420
|
// are in; fall back to the raw query while they're still loading.
|
|
388
421
|
if (submitToSearch && searchActive) {
|
|
389
422
|
if (viewAllRow) execute(viewAllRow)
|
|
390
|
-
else { onViewAllResults?.(queryString);
|
|
423
|
+
else { onViewAllResults?.(queryString); close() }
|
|
391
424
|
}
|
|
392
425
|
}
|
|
393
426
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
394
|
-
}, [rows, selectedIndex, execute, resourcesStale, submitToSearch, searchActive, viewAllRow, onViewAllResults, queryString])
|
|
427
|
+
}, [rows, selectedIndex, execute, close, resourcesStale, submitToSearch, searchActive, viewAllRow, onViewAllResults, queryString])
|
|
395
428
|
|
|
396
429
|
useEffect(() => {
|
|
397
430
|
listRef.current?.querySelector('[data-selected="true"]')?.scrollIntoView({ block: 'nearest' })
|
|
@@ -429,7 +462,7 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
429
462
|
const mac = typeof navigator !== 'undefined' && navigator.platform.includes('Mac')
|
|
430
463
|
const total = searchData?.total ?? 0
|
|
431
464
|
const totalMatched = searchData?.total_matched ?? 0
|
|
432
|
-
const
|
|
465
|
+
const partialNotices = partialSearchNotices(searchData)
|
|
433
466
|
const hasNsPill = pills.some((p) => p.key === 'ns')
|
|
434
467
|
const dropdownOpen = open && !suggesting && (rows.length > 0 || searchActive)
|
|
435
468
|
// Presence: the scrim and the results panel are menu-kind overlays (140ms
|
|
@@ -479,16 +512,22 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
479
512
|
{isFetching && <Loader2 className="w-3 h-3 animate-spin" />}
|
|
480
513
|
{!isFetching && !isError && totalMatched > total && <span className="normal-case font-normal">showing {total} of {totalMatched}</span>}
|
|
481
514
|
</div>
|
|
515
|
+
{/* Above the rows: with a full page of hits a note below them
|
|
516
|
+
would sit under the fold. */}
|
|
517
|
+
{shownNote && <OmnibarNoteRow note={shownNote} onAction={(action) => {
|
|
518
|
+
action.onSelect()
|
|
519
|
+
if (!action.keepOpen) close()
|
|
520
|
+
}} />}
|
|
482
521
|
{isError ? (
|
|
483
522
|
<div className="flex items-center gap-2 px-3 py-2 text-xs text-amber-600 dark:text-amber-400">
|
|
484
523
|
<AlertTriangle className="w-3.5 h-3.5 shrink-0" /> Search is unavailable right now.
|
|
485
524
|
</div>
|
|
486
|
-
) : resourceRows.length === 0 && !isFetching ? (
|
|
525
|
+
) : resourceRows.length === 0 && (!isFetching || currentData) ? (
|
|
487
526
|
<div className="px-3 py-2 text-xs text-theme-text-tertiary">
|
|
488
|
-
No resources match{freeText ? <> “{freeText}”</> : ''}
|
|
527
|
+
{shownNote ? 'No matches in what Radar searched.' : <>No resources match{freeText ? <> “{freeText}”</> : ''}.</>}
|
|
489
528
|
{hasNsPill && (
|
|
490
529
|
<button onMouseDown={(e) => { e.preventDefault(); clearNsPills() }} className="ml-1.5 text-[var(--color-brand)] hover:underline">
|
|
491
|
-
|
|
530
|
+
Remove namespace filter
|
|
492
531
|
</button>
|
|
493
532
|
)}
|
|
494
533
|
</div>
|
|
@@ -497,11 +536,11 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
497
536
|
<ResourceRow key={row.id} hit={row.hit} stale={resourcesStale} selected={row.id === selectedId} onSelect={() => selectRow(row.id)} onActivate={() => { if (!resourcesStale) execute(row) }} />
|
|
498
537
|
))
|
|
499
538
|
)}
|
|
500
|
-
{!isFetching && !isError &&
|
|
501
|
-
<div className="flex items-start gap-2 px-3 py-1.5 text-
|
|
502
|
-
<AlertTriangle className="w-3 h-3 mt-0.5 shrink-0" /> {
|
|
539
|
+
{!isFetching && !isError && partialNotices.map((notice) => (
|
|
540
|
+
<div key={notice} className="flex items-start gap-2 px-3 py-1.5 text-xs text-warning-text">
|
|
541
|
+
<AlertTriangle className="w-3 h-3 mt-0.5 shrink-0" /> {notice}
|
|
503
542
|
</div>
|
|
504
|
-
)}
|
|
543
|
+
))}
|
|
505
544
|
</>
|
|
506
545
|
)}
|
|
507
546
|
|
|
@@ -621,6 +660,31 @@ export const Omnibar = forwardRef<OmnibarHandle, OmnibarProps>(function Omnibar(
|
|
|
621
660
|
)
|
|
622
661
|
})
|
|
623
662
|
|
|
663
|
+
function OmnibarNoteRow({ note, onAction }: { note: OmnibarNote; onAction: (action: NonNullable<OmnibarNote['action']>) => void }) {
|
|
664
|
+
return (
|
|
665
|
+
<div className="flex items-start gap-1.5 px-3 py-1.5 text-xs text-theme-text-tertiary">
|
|
666
|
+
<Info className="w-3.5 h-3.5 shrink-0 mt-px" />
|
|
667
|
+
<span>
|
|
668
|
+
{(note.parts ?? [note]).map(({ text, action }, index) => (
|
|
669
|
+
<span key={index}>
|
|
670
|
+
{index > 0 && ' '}
|
|
671
|
+
{text}
|
|
672
|
+
{action && (
|
|
673
|
+
<>
|
|
674
|
+
{' '}
|
|
675
|
+
<button type="button" onMouseDown={(e) => e.preventDefault()} onClick={() => onAction(action)} className="text-[var(--color-brand)] hover:underline">
|
|
676
|
+
{action.label}
|
|
677
|
+
</button>
|
|
678
|
+
{action.suffix}
|
|
679
|
+
</>
|
|
680
|
+
)}
|
|
681
|
+
</span>
|
|
682
|
+
))}
|
|
683
|
+
</span>
|
|
684
|
+
</div>
|
|
685
|
+
)
|
|
686
|
+
}
|
|
687
|
+
|
|
624
688
|
function ResourceRow({ hit, selected, stale, onSelect, onActivate }: { hit: SearchHit; selected: boolean; stale?: boolean; onSelect: () => void; onActivate: () => void }) {
|
|
625
689
|
const Icon = getResourceIcon(hit.kind)
|
|
626
690
|
const dot = healthDot(hit.summaryContext?.health)
|