@skyhook-io/radar-app 1.18.0 → 1.18.2
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 +43 -12
- package/src/api/client.deleteResource.test.tsx +111 -0
- package/src/api/client.gitops-destination.test.tsx +55 -0
- package/src/api/client.resource-list.test.ts +76 -0
- package/src/api/client.resourceAudit.test.tsx +57 -0
- package/src/api/client.resourcePath.test.ts +107 -0
- package/src/api/client.ts +197 -57
- 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/capacity/CapacityDemand.tsx +6 -3
- package/src/components/capacity/CapacityOverview.tsx +14 -7
- package/src/components/capacity/CapacityPoolDetail.tsx +7 -5
- package/src/components/capacity/ClusterSchedulingCard.tsx +3 -3
- package/src/components/capacity/shared.tsx +9 -5
- package/src/components/cnpg/CNPGOverview.tsx +4 -1
- package/src/components/cnpg/CNPGView.tsx +1 -0
- package/src/components/cnpg/actions/useCNPGWriteGuard.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/ApplyDialog.test.tsx +10 -0
- package/src/components/diagnose/ApplyDialog.tsx +8 -1
- package/src/components/diagnose/AssessmentCard.tsx +60 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +5 -0
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +62 -2
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +6 -5
- package/src/components/diagnose/InvestigationView.tsx +47 -13
- package/src/components/diagnose/StoryExcerpt.tsx +24 -5
- package/src/components/diagnose/assessmentCopy.ts +11 -0
- package/src/components/diagnose/investigationEvidence/adapters/changes.ts +36 -1
- package/src/components/diagnose/investigationEvidence/adapters/crossplane.test.tsx +85 -0
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +1 -0
- package/src/components/diagnose/investigationEvidence/adapters/listCoverage.test.ts +415 -0
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +2 -1
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +2 -1
- package/src/components/diagnose/investigationEvidence/adapters/resource.ts +107 -8
- package/src/components/diagnose/investigationEvidence/adapters/testdata/crossplane-paused-get-resource.json +28 -0
- package/src/components/diagnose/investigationEvidence/bodies/index.tsx +2 -0
- package/src/components/diagnose/investigationEvidence/bodies/inventory.tsx +66 -16
- package/src/components/diagnose/investigationEvidence/bodies/workload.tsx +5 -1
- package/src/components/diagnose/investigationEvidence/builder.ts +16 -2
- package/src/components/diagnose/investigationEvidence/cardParts.tsx +7 -2
- package/src/components/diagnose/investigationEvidence/excerpt.ts +2 -0
- package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
- package/src/components/diagnose/investigationEvidence/observations.ts +8 -3
- package/src/components/diagnose/investigationEvidence/projection.test.ts +81 -4
- package/src/components/diagnose/investigationEvidence/types.ts +15 -0
- package/src/components/diagnose/investigationEvidencePresentation.test.ts +36 -2
- package/src/components/diagnose/investigationEvidencePresentation.ts +33 -8
- package/src/components/diagnose/storyParts.test.tsx +53 -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 +9 -8
- package/src/components/helm/HelmReleaseDrawer.tsx +6 -2
- package/src/components/helm/HelmView.tsx +34 -23
- package/src/components/helm/InstallWizard.tsx +6 -2
- package/src/components/helm/TrackChartSourceDialog.render.test.tsx +269 -96
- package/src/components/helm/TrackChartSourceDialog.tsx +607 -104
- package/src/components/helm/ValuesViewer.test.tsx +1 -0
- package/src/components/helm/ValuesViewer.tsx +4 -2
- package/src/components/home/ClusterHealthCard.tsx +28 -21
- package/src/components/home/MCPSetupDialog.test.tsx +27 -2
- package/src/components/home/MCPSetupDialog.tsx +14 -2
- package/src/components/home/mcpToolCatalog.ts +39 -2
- package/src/components/issues/IssuesPane.render.test.tsx +5 -5
- package/src/components/nav/PrimaryNavRail.tsx +34 -2
- package/src/components/product-hunt/ProductHuntNotice.render.test.tsx +120 -0
- package/src/components/product-hunt/ProductHuntNotice.test.ts +121 -0
- package/src/components/product-hunt/ProductHuntNotice.tsx +202 -0
- package/src/components/product-hunt/launchWindow.ts +78 -0
- package/src/components/product-hunt/useProductHuntRailEntry.test.tsx +76 -0
- package/src/components/product-hunt/useProductHuntRailEntry.ts +27 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +45 -0
- package/src/components/resource/PrometheusCharts.tsx +2 -2
- package/src/components/resources/CompositeRenderer.tsx +4 -0
- package/src/components/resources/ResourcesView.tsx +30 -68
- package/src/components/resources/renderers/PodRenderer.tsx +4 -1
- package/src/components/settings/LocalConnectionSettings.tsx +1 -0
- 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 +201 -0
- package/src/components/ui/RadarOmnibar.tsx +39 -4
- package/src/components/ui/SearchSyntaxHelp.test.tsx +39 -0
- package/src/components/ui/SearchSyntaxHelp.tsx +23 -2
- package/src/components/ui/UpdateNotification.manual.test.tsx +177 -0
- package/src/components/ui/UpdateNotification.test.tsx +4 -1
- package/src/components/ui/UpdateNotification.tsx +61 -10
- 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/usage-data/UsageDataPrompt.tsx +19 -1
- 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 +18 -6
- package/src/components/workspace/layout.tsx +2 -1
- package/src/contexts/CapabilitiesContext.tsx +1 -0
- package/src/hooks/useGitOpsWriteGuard.test.tsx +126 -2
- package/src/hooks/useGitOpsWriteGuard.ts +25 -3
- package/src/hooks/useResolvedGitOpsOwner.ts +14 -9
- package/src/hooks/useResourceCounts.ts +2 -0
- package/src/index.css +87 -4
- package/src/index.ts +7 -0
- package/src/utils/artifacthub.test.ts +18 -0
- package/src/utils/artifacthub.ts +9 -0
|
@@ -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)
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import type { SearchCoverageEntry } from './searchCoverageNote'
|
|
7
|
+
import { coverageOf } from './searchCoverage.fixtures'
|
|
8
|
+
|
|
9
|
+
vi.mock('../../api/usage-data', () => ({ recordUsageEvent: vi.fn() }))
|
|
10
|
+
vi.mock('../../hooks/useRecentResources', () => ({ loadRecentResources: () => [], recordRecentResource: vi.fn() }))
|
|
11
|
+
vi.mock('../../api/apiResources', async (importOriginal) => ({ ...(await importOriginal<object>()), useAPIResources: () => ({ data: [] }) }))
|
|
12
|
+
vi.mock('./command-items', async (importOriginal) => ({ ...(await importOriginal<object>()), useCommandItems: () => [] }))
|
|
13
|
+
const caps = vi.hoisted(() => ({ data: undefined as undefined | { authEnabled?: boolean } }))
|
|
14
|
+
vi.mock('../../api/client', async (importOriginal) => ({
|
|
15
|
+
...(await importOriginal<object>()),
|
|
16
|
+
useNamespaceScope: () => ({ data: undefined }),
|
|
17
|
+
useContexts: () => ({ data: [] }),
|
|
18
|
+
useCapabilities: () => caps,
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
import { RadarOmnibar } from './RadarOmnibar'
|
|
22
|
+
|
|
23
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
24
|
+
let root: Root
|
|
25
|
+
let host: HTMLDivElement
|
|
26
|
+
let unsearched: SearchCoverageEntry[]
|
|
27
|
+
let searches = 0
|
|
28
|
+
|
|
29
|
+
const pending: SearchCoverageEntry[] = [{ kind: '*', group: '', reason: 'kind_sync_pending' }]
|
|
30
|
+
const failed: SearchCoverageEntry[] = [{ kind: 'SpStall', group: 'stall.sp-live.test', reason: 'kind_sync_timed_out' }]
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
vi.useFakeTimers()
|
|
34
|
+
Element.prototype.scrollIntoView = vi.fn()
|
|
35
|
+
caps.data = undefined
|
|
36
|
+
searches = 0
|
|
37
|
+
vi.stubGlobal('fetch', vi.fn(async (input: string) => {
|
|
38
|
+
const url = new URL(input, 'http://localhost')
|
|
39
|
+
if (!url.pathname.endsWith('/search')) throw new Error(`Unexpected request: ${input}`)
|
|
40
|
+
searches++
|
|
41
|
+
return new Response(JSON.stringify({ hits: [], total: 0, searched: 0, total_matched: 0, coverage: coverageOf(unsearched) }), { status: 200 })
|
|
42
|
+
}))
|
|
43
|
+
host = document.createElement('div')
|
|
44
|
+
document.body.appendChild(host)
|
|
45
|
+
root = createRoot(host)
|
|
46
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
47
|
+
const noop = vi.fn()
|
|
48
|
+
act(() => {
|
|
49
|
+
root.render(
|
|
50
|
+
<QueryClientProvider client={client}>
|
|
51
|
+
<RadarOmnibar onOpenResource={noop} onNavigateView={noop} onNavigateKind={noop} onSwitchContext={noop} onSetNamespaces={noop} onToggleTheme={noop} />
|
|
52
|
+
</QueryClientProvider>,
|
|
53
|
+
)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
act(() => root.unmount())
|
|
59
|
+
host.remove()
|
|
60
|
+
document.body.innerHTML = ''
|
|
61
|
+
vi.unstubAllGlobals()
|
|
62
|
+
vi.useRealTimers()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
async function typeQuery(text: string) {
|
|
66
|
+
const input = host.querySelector('input')!
|
|
67
|
+
act(() => input.focus())
|
|
68
|
+
act(() => {
|
|
69
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, text)
|
|
70
|
+
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
71
|
+
})
|
|
72
|
+
await act(async () => { await vi.advanceTimersByTimeAsync(200) })
|
|
73
|
+
await act(async () => { await vi.advanceTimersByTimeAsync(100) })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const advance = (ms: number) => act(async () => { await vi.advanceTimersByTimeAsync(ms) })
|
|
77
|
+
const page = () => document.body.textContent ?? ''
|
|
78
|
+
|
|
79
|
+
describe('RadarOmnibar while results load', () => {
|
|
80
|
+
it('requests status context and accepts a full summary from an older Radar', async () => {
|
|
81
|
+
unsearched = []
|
|
82
|
+
vi.mocked(fetch).mockImplementationOnce(async () => new Response(JSON.stringify({
|
|
83
|
+
hits: [{ kind: 'Pod', namespace: 'shop', name: 'legacy-pod', score: 1, summaryContext: {
|
|
84
|
+
health: 'unhealthy', issueCount: 2, managedBy: { kind: 'Deployment', name: 'legacy-owner' },
|
|
85
|
+
} }],
|
|
86
|
+
total: 1, searched: 1, total_matched: 1, coverage: coverageOf([]),
|
|
87
|
+
}), { status: 200 }))
|
|
88
|
+
await typeQuery('legacy-pod')
|
|
89
|
+
|
|
90
|
+
const request = new URL(String(vi.mocked(fetch).mock.calls[0][0]), 'http://localhost')
|
|
91
|
+
expect(request.searchParams.get('context')).toBe('status')
|
|
92
|
+
expect(page()).toContain('legacy-pod')
|
|
93
|
+
expect(page()).toContain('2 issues')
|
|
94
|
+
expect(page()).not.toContain('legacy-owner')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('re-queries a loading search and ends on the failure once Radar gives up on the kind', async () => {
|
|
98
|
+
unsearched = pending
|
|
99
|
+
await typeQuery('sp-live')
|
|
100
|
+
expect(page()).toContain('Still loading — results may change.')
|
|
101
|
+
|
|
102
|
+
await advance(25_000)
|
|
103
|
+
expect(searches).toBeGreaterThanOrEqual(5)
|
|
104
|
+
expect(page()).toContain('Still loading — results may change.')
|
|
105
|
+
|
|
106
|
+
// Radar reports a kind that never synced as failed after about 30 s, so
|
|
107
|
+
// the omnibar must still be asking then.
|
|
108
|
+
await advance(6_000)
|
|
109
|
+
unsearched = failed
|
|
110
|
+
await advance(10_000)
|
|
111
|
+
expect(page()).toContain("Couldn't read SpStall; matches of that kind may be missing.")
|
|
112
|
+
expect(page()).not.toContain('Still loading')
|
|
113
|
+
|
|
114
|
+
const settled = searches
|
|
115
|
+
await advance(30_000)
|
|
116
|
+
expect(searches).toBe(settled)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('still catches a kind that fails 30 s after a watch that started late in warm-up', async () => {
|
|
120
|
+
unsearched = pending
|
|
121
|
+
await typeQuery('sp-live')
|
|
122
|
+
await advance(48_000)
|
|
123
|
+
expect(page()).toContain('Still loading — results may change.')
|
|
124
|
+
unsearched = failed
|
|
125
|
+
await advance(6_000)
|
|
126
|
+
expect(page()).toContain("Couldn't read SpStall; matches of that kind may be missing.")
|
|
127
|
+
const settled = searches
|
|
128
|
+
await advance(30_000)
|
|
129
|
+
expect(searches).toBe(settled)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('stops re-querying after its budget and says so', async () => {
|
|
133
|
+
unsearched = pending
|
|
134
|
+
await typeQuery('sp-live')
|
|
135
|
+
await advance(55_000)
|
|
136
|
+
expect(page()).toContain('Still loading — results may change.')
|
|
137
|
+
await advance(6_000)
|
|
138
|
+
expect(page()).toContain('Still loading — try again shortly.')
|
|
139
|
+
const settled = searches
|
|
140
|
+
await advance(30_000)
|
|
141
|
+
expect(searches).toBe(settled)
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
describe('RadarOmnibar namespace notes', () => {
|
|
146
|
+
// Radar decides whether a missing namespace may be named as absent: only a
|
|
147
|
+
// caller who can see every namespace is told it doesn't exist.
|
|
148
|
+
it('says a namespace does not exist when Radar says so, whatever the auth mode', async () => {
|
|
149
|
+
for (const data of [{}, { authEnabled: true }]) {
|
|
150
|
+
caps.data = data
|
|
151
|
+
unsearched = [{ kind: '*', group: '', reason: 'namespace_not_found', namespaces: ['payments-prd'] }]
|
|
152
|
+
await typeQuery(`ns:payments-prd web${'authEnabled' in data ? 's' : ''}`)
|
|
153
|
+
expect(page()).toContain("Namespace 'payments-prd' doesn't exist on this cluster.")
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('stays scoped to what the caller can see when Radar does not say', async () => {
|
|
158
|
+
for (const data of [{}, { authEnabled: true }]) {
|
|
159
|
+
caps.data = data
|
|
160
|
+
unsearched = [{ kind: '*', group: '', reason: 'user_namespace_not_visible', namespaces: ['payments-prd'] }]
|
|
161
|
+
await typeQuery(`ns:payments-prd web${'authEnabled' in data ? 's' : ''}`)
|
|
162
|
+
expect(page()).toContain("Namespace 'payments-prd' wasn't found in what you can see.")
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
describe('RadarOmnibar read recovery', () => {
|
|
168
|
+
it.each([
|
|
169
|
+
['alone', []],
|
|
170
|
+
['followed by a namespace note', [{ kind: '*', group: '', reason: 'radar_namespace_not_collected', namespaces: ['rel-owner'] }]],
|
|
171
|
+
['preceded by a loading note', pending],
|
|
172
|
+
] as [string, SearchCoverageEntry[]][])('adds the suggested kind %s, preserves modifiers and terms, and re-checks while open', async (_, siblings) => {
|
|
173
|
+
unsearched = [{ kind: 'Certificate', group: 'cert-manager.io', reason: 'read_error' }, ...siblings]
|
|
174
|
+
await typeQuery('ns:prod')
|
|
175
|
+
act(() => host.querySelector('input')!.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true })))
|
|
176
|
+
await typeQuery('label:app=web image:nginx renewal')
|
|
177
|
+
expect(page()).toContain("Couldn't read Certificate; matches of that kind may be missing. Search kind:Certificate to re-check.")
|
|
178
|
+
const button = [...document.body.querySelectorAll('button')].find((b) => b.textContent === 'kind:Certificate')!
|
|
179
|
+
expect(button).toBeDefined()
|
|
180
|
+
const recoveryText = "Couldn't read Certificate; matches of that kind may be missing. Search kind:Certificate to re-check."
|
|
181
|
+
const siblingText = siblings === pending ? 'Still loading — results may change.' : siblings.length ? "Namespace 'rel-owner' wasn't searched: Radar here watches only some namespaces." : ''
|
|
182
|
+
expect(button.parentElement!.textContent?.trim()).toBe(recoveryText)
|
|
183
|
+
expect(button.parentElement!.parentElement!.textContent).toBe(siblings === pending ? `${siblingText} ${recoveryText}` : `${recoveryText}${siblingText ? ` ${siblingText}` : ''}`)
|
|
184
|
+
act(() => button.click())
|
|
185
|
+
await advance(300)
|
|
186
|
+
await advance(100)
|
|
187
|
+
const requests = vi.mocked(fetch).mock.calls.map(([input]) => new URL(String(input), 'http://localhost').searchParams.get('q'))
|
|
188
|
+
expect(requests.at(-1)).toBe('ns:prod kind:Certificate label:app=web image:nginx renewal')
|
|
189
|
+
expect(host.querySelector('input')!.value).toContain('renewal')
|
|
190
|
+
expect(page()).toContain("Couldn't read Certificate; matches of that kind may be missing.")
|
|
191
|
+
expect([...document.body.querySelectorAll('button')].some((b) => b.textContent === 'kind:Certificate')).toBe(false)
|
|
192
|
+
expect(page()).not.toContain('to re-check.')
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
it.each(['kind:Certificate renewal', 'k:certificates renewal'])('keeps an explicit failed search honest: %s', async (query) => {
|
|
196
|
+
unsearched = [{ kind: 'Certificate', group: 'cert-manager.io', reason: 'read_error' }]
|
|
197
|
+
await typeQuery(query)
|
|
198
|
+
expect(page()).toContain("Couldn't read Certificate; matches of that kind may be missing.")
|
|
199
|
+
expect(page()).not.toContain('to re-check.')
|
|
200
|
+
})
|
|
201
|
+
})
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { forwardRef, useMemo, useState } from 'react'
|
|
1
|
+
import { forwardRef, useEffect, useMemo, useState, useRef, useImperativeHandle } from 'react'
|
|
2
2
|
import { Omnibar, type OmnibarHandle } from './Omnibar'
|
|
3
|
-
import { useSearch, useNamespaceScope, useContexts, type SearchHit } from '../../api/client'
|
|
3
|
+
import { useSearch, useNamespaceScope, useContexts, type SearchHit, type SearchResult } from '../../api/client'
|
|
4
4
|
import { useAPIResources } from '../../api/apiResources'
|
|
5
5
|
import { loadRecentResources, recordRecentResource } from '../../hooks/useRecentResources'
|
|
6
6
|
import { useCommandItems, type CommandItemCallbacks } from './command-items'
|
|
7
|
+
import { PENDING_RETRY_BUDGET_MS, PENDING_RETRY_MS, searchCoverageNote } from './searchCoverageNote'
|
|
7
8
|
|
|
8
9
|
interface RadarOmnibarProps extends CommandItemCallbacks {
|
|
9
10
|
onOpenResource: (hit: SearchHit) => void
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
const stillLoading = (data: SearchResult | undefined) => !!data?.coverage?.gaps.some((gap) => gap.code === 'kind_sync_pending')
|
|
14
|
+
|
|
12
15
|
// Radar standalone's omnibar: wires the injectable Omnibar to Radar's own hooks
|
|
13
16
|
// (cluster /api/search, kubeconfig contexts, API discovery, recents). Radar Hub
|
|
14
17
|
// provides a parallel wrapper over fleet search.
|
|
@@ -16,11 +19,31 @@ export const RadarOmnibar = forwardRef<OmnibarHandle, RadarOmnibarProps>(functio
|
|
|
16
19
|
{ onOpenResource, ...callbacks },
|
|
17
20
|
ref,
|
|
18
21
|
) {
|
|
22
|
+
const omnibarRef = useRef<OmnibarHandle>(null)
|
|
23
|
+
useImperativeHandle(ref, () => ({
|
|
24
|
+
focus: () => omnibarRef.current?.focus(),
|
|
25
|
+
addModifier: (modifier) => omnibarRef.current?.addModifier(modifier),
|
|
26
|
+
}), [])
|
|
19
27
|
// The omnibar debounces internally and emits the query to search here.
|
|
20
28
|
const [query, setQuery] = useState('')
|
|
21
29
|
const [open, setOpen] = useState(false)
|
|
30
|
+
// The query whose still-loading re-queries ran out of budget while open.
|
|
31
|
+
const [exhaustedQuery, setExhaustedQuery] = useState<string | null>(null)
|
|
32
|
+
|
|
33
|
+
const { data: searchData, isFetching, isPlaceholderData, isError } = useSearch(query, {
|
|
34
|
+
context: 'status',
|
|
35
|
+
enabled: open,
|
|
36
|
+
globalNs: true,
|
|
37
|
+
refetchInterval: (data) => (open && stillLoading(data) && exhaustedQuery !== query ? PENDING_RETRY_MS : false),
|
|
38
|
+
})
|
|
39
|
+
const pending = !isPlaceholderData && stillLoading(searchData)
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!open || !pending) return
|
|
42
|
+
const timer = setTimeout(() => setExhaustedQuery(query), PENDING_RETRY_BUDGET_MS)
|
|
43
|
+
return () => clearTimeout(timer)
|
|
44
|
+
}, [open, pending, query])
|
|
45
|
+
useEffect(() => { if (!open) setExhaustedQuery(null) }, [open])
|
|
22
46
|
|
|
23
|
-
const { data: searchData, isFetching, isPlaceholderData, isError } = useSearch(query, { enabled: open, globalNs: true })
|
|
24
47
|
const { data: nsScope } = useNamespaceScope()
|
|
25
48
|
const { data: apiResources } = useAPIResources()
|
|
26
49
|
const { data: contexts } = useContexts()
|
|
@@ -32,10 +55,21 @@ export const RadarOmnibar = forwardRef<OmnibarHandle, RadarOmnibarProps>(functio
|
|
|
32
55
|
}), [nsScope, apiResources])
|
|
33
56
|
|
|
34
57
|
const commandItems = useCommandItems(callbacks)
|
|
58
|
+
const { onNavigateKind } = callbacks
|
|
59
|
+
const note = searchCoverageNote(searchData?.coverage, {
|
|
60
|
+
hits: searchData?.hits,
|
|
61
|
+
query,
|
|
62
|
+
recheckKind: (kind) => omnibarRef.current?.addModifier({ key: 'kind', value: kind }),
|
|
63
|
+
pendingExhausted: exhaustedQuery === query,
|
|
64
|
+
openKindList: (kind, group) => {
|
|
65
|
+
const resource = apiResources?.find((r) => r.kind === kind && r.group === group)
|
|
66
|
+
return resource ? () => onNavigateKind(resource.name, resource.group) : undefined
|
|
67
|
+
},
|
|
68
|
+
})
|
|
35
69
|
|
|
36
70
|
return (
|
|
37
71
|
<Omnibar
|
|
38
|
-
ref={
|
|
72
|
+
ref={omnibarRef}
|
|
39
73
|
onOpenResource={onOpenResource}
|
|
40
74
|
commandItems={commandItems}
|
|
41
75
|
onQueryChange={(q, o) => { setQuery(q); setOpen(o) }}
|
|
@@ -43,6 +77,7 @@ export const RadarOmnibar = forwardRef<OmnibarHandle, RadarOmnibarProps>(functio
|
|
|
43
77
|
isFetching={isFetching}
|
|
44
78
|
isError={isError}
|
|
45
79
|
isPlaceholderData={isPlaceholderData}
|
|
80
|
+
note={note}
|
|
46
81
|
modifierOptions={modifierOptions}
|
|
47
82
|
seedNamespaces={nsScope?.actives}
|
|
48
83
|
loadRecents={() => loadRecentResources(contextKey)}
|