@skyhook-io/radar-app 1.19.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +5 -5
- package/src/App.tsx +31 -5
- package/src/api/application-evidence.ts +63 -0
- package/src/api/argoSync.test.ts +22 -0
- package/src/api/client.audit-gating.test.tsx +48 -0
- package/src/api/client.kueuePosition.test.ts +32 -0
- package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
- package/src/api/client.resource-identity.test.ts +3 -0
- package/src/api/client.resourceIssues.test.tsx +239 -0
- package/src/api/client.resourcePath.test.ts +3 -0
- package/src/api/client.ts +285 -55
- package/src/api/config.ts +21 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/radarFeatures.render.test.tsx +33 -1
- package/src/api/radarFeatures.test.ts +47 -0
- package/src/api/radarFeatures.ts +40 -1
- package/src/api/rbac.settled.test.tsx +42 -0
- package/src/api/rbac.test.ts +18 -0
- package/src/api/rbac.ts +37 -7
- package/src/api/traffic.ts +9 -4
- package/src/api/usage-data.fixtures.ts +3 -1
- package/src/api/usage-data.test.tsx +134 -0
- package/src/api/usage-data.ts +35 -7
- package/src/api/workloadPodsPolling.test.ts +26 -0
- package/src/components/CloudConnectFlow.test.tsx +86 -0
- package/src/components/CloudConnectFlow.tsx +65 -27
- package/src/components/CloudFunnelButton.test.tsx +140 -5
- package/src/components/CloudFunnelButton.tsx +50 -9
- package/src/components/ConnectionErrorView.test.tsx +34 -0
- package/src/components/ConnectionErrorView.tsx +35 -11
- package/src/components/ContextSwitcher.tsx +5 -2
- package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
- package/src/components/SwitchAwareConnectionError.tsx +85 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
- package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
- package/src/components/capacity/CapacityDemand.tsx +3 -2
- package/src/components/capacity/demandSummary.test.ts +38 -0
- package/src/components/capacity/shared.tsx +12 -1
- package/src/components/cost/ApplicationCostTab.tsx +4 -0
- package/src/components/cost/CostTrendChart.tsx +2 -0
- package/src/components/cost/WorkloadCostTab.tsx +4 -0
- package/src/components/cost/source.test.ts +5 -0
- package/src/components/cost/source.ts +11 -0
- package/src/components/diagnose/AIMarkdown.tsx +3 -0
- package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
- package/src/components/diagnose/AgentSetupNotice.tsx +21 -3
- package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
- package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +1 -1
- package/src/components/diagnose/DiagnoseContext.tsx +68 -2
- package/src/components/diagnose/DiagnoseSurface.tsx +58 -113
- package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
- package/src/components/diagnose/Home.test.tsx +26 -0
- package/src/components/diagnose/Home.tsx +20 -1
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +45 -22
- package/src/components/diagnose/InvestigationView.tsx +94 -26
- package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
- package/src/components/diagnose/LocalDiagnoseAction.tsx +354 -35
- package/src/components/diagnose/NextStepJump.test.tsx +92 -0
- package/src/components/diagnose/NextStepJump.tsx +75 -0
- package/src/components/diagnose/QuestionComposer.tsx +8 -0
- package/src/components/diagnose/exampleInvestigation.events.json +191 -0
- package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
- package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
- package/src/components/diagnose/exampleInvestigation.ts +121 -0
- package/src/components/diagnose/investigationCase.test.tsx +9 -1
- package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +50 -2
- package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
- package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
- package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
- package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/diagnose/investigationState.ts +28 -0
- package/src/components/diagnose/lastInvestigation.test.ts +95 -0
- package/src/components/diagnose/lastInvestigation.ts +58 -0
- package/src/components/diagnose/launch.test.ts +125 -1
- package/src/components/diagnose/launch.ts +57 -10
- package/src/components/diagnose/toolCallLabel.test.ts +10 -4
- package/src/components/execution/BatchExecutionView.tsx +24 -11
- package/src/components/execution/JobSetAdmission.test.tsx +42 -0
- package/src/components/execution/JobSetAdmission.tsx +18 -3
- package/src/components/execution/JobSetMemberComparison.tsx +2 -1
- package/src/components/execution/runState.test.ts +14 -0
- package/src/components/execution/runState.ts +8 -0
- package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
- package/src/components/gitops/GitOpsView.tsx +86 -17
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
- package/src/components/gitops/destination-toast.test.ts +1 -1
- package/src/components/gitops/destination-toast.ts +2 -2
- package/src/components/home/ClusterHealthCard.tsx +1 -1
- package/src/components/home/HomeAgentBlock.test.tsx +31 -3
- package/src/components/home/HomeAgentBlock.tsx +13 -4
- package/src/components/home/HomeDiagramCard.tsx +47 -0
- package/src/components/home/HomeView.tsx +81 -41
- package/src/components/home/MCPSetupDialog.test.tsx +95 -5
- package/src/components/home/MCPSetupDialog.tsx +30 -5
- package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
- package/src/components/home/ProblemsPanel.test.tsx +3 -1
- package/src/components/home/TopologyPreview.test.tsx +73 -0
- package/src/components/home/TopologyPreview.tsx +120 -233
- package/src/components/home/TrafficSummary.test.tsx +63 -0
- package/src/components/home/TrafficSummary.tsx +135 -138
- package/src/components/home/mcpToolCatalog.ts +23 -10
- package/src/components/issues/IssuesPane.test.ts +11 -0
- package/src/components/issues/IssuesPane.tsx +15 -5
- package/src/components/issues/uncheckedSources.test.ts +20 -1
- package/src/components/issues/uncheckedSources.ts +18 -0
- package/src/components/kueue/KueuePendingPosition.tsx +35 -0
- package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
- package/src/components/kueue/useRelatedReads.test.ts +56 -0
- package/src/components/kueue/useRelatedReads.ts +205 -0
- package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
- package/src/components/logs/MultiPodLogsTab.tsx +120 -0
- package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
- package/src/components/logs/PodLogsUnavailable.tsx +21 -0
- package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
- package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
- package/src/components/logs/RayClusterLogsTab.tsx +109 -0
- package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
- package/src/components/logs/rayClusterPods.ts +32 -0
- package/src/components/outageSince.test.ts +21 -0
- package/src/components/outageSince.ts +10 -0
- package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
- package/src/components/resource/PrometheusCharts.tsx +3 -40
- package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
- package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
- package/src/components/resources/crd/host.tsx +14 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
- package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
- package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
- package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
- package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
- package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
- package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
- package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
- package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
- package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
- package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
- package/src/components/traffic/TrafficView.tsx +3 -3
- package/src/components/ui/command-items-crd.test.tsx +23 -0
- package/src/components/ui/command-items.ts +2 -1
- package/src/components/useContextSwitchFlow.test.tsx +61 -0
- package/src/components/useContextSwitchFlow.tsx +21 -4
- package/src/components/whats-new/WhatsNew.test.ts +10 -3
- package/src/components/whats-new/WhatsNew.tsx +5 -1
- package/src/components/whats-new/WhatsNewDialog.test.tsx +17 -3
- package/src/components/whats-new/releaseNotes.ts +77 -4
- package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
- package/src/components/workload/RelatedFindingsSection.tsx +80 -0
- package/src/components/workload/WorkloadView.test.ts +10 -1
- package/src/components/workload/WorkloadView.tsx +85 -98
- package/src/components/workload/issueResourceOpener.test.ts +20 -0
- package/src/components/workload/issueResourceOpener.ts +17 -0
- package/src/context/ConnectionContext.tsx +133 -60
- package/src/context/ConnectionProvider.retry.test.tsx +176 -0
- package/src/context/ContextSwitchContext.tsx +14 -1
- package/src/context/DiagnoseCustomization.tsx +3 -0
- package/src/context/clusterConnected.ts +10 -0
- package/src/contexts/CapabilitiesContext.tsx +6 -4
- package/src/hooks/useElementSize.ts +30 -0
- package/src/integrations/resourceHost.test.tsx +1 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +21 -4
- package/src/integrations/resourceHosts.tsx +12 -0
- package/src/main.tsx +5 -0
- package/src/utils/related-findings.ts +46 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { recordUsageEvent } from '../../api/usage-data'
|
|
3
|
+
import { issueResourceOpener } from './issueResourceOpener'
|
|
4
|
+
|
|
5
|
+
vi.mock('../../api/usage-data', () => ({ recordUsageEvent: vi.fn() }))
|
|
6
|
+
|
|
7
|
+
describe('issueResourceOpener', () => {
|
|
8
|
+
afterEach(() => vi.mocked(recordUsageEvent).mockClear())
|
|
9
|
+
|
|
10
|
+
it('opens the resource and counts it once', () => {
|
|
11
|
+
const navigate = vi.fn()
|
|
12
|
+
issueResourceOpener(navigate)?.({ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'cart' })
|
|
13
|
+
expect(navigate).toHaveBeenCalledWith({ kind: 'deployments', namespace: 'shop', name: 'cart', group: 'apps' })
|
|
14
|
+
expect(vi.mocked(recordUsageEvent).mock.calls).toEqual([[{ type: 'ui', name: 'issue_action:open' }]])
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('leaves links off when the host has nowhere to navigate', () => {
|
|
18
|
+
expect(issueResourceOpener(undefined)).toBeUndefined()
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { kindToPluralWithGroup, type IssueResourceRef } from '@skyhook-io/k8s-ui'
|
|
2
|
+
import { recordUsageEvent } from '../../api/usage-data'
|
|
3
|
+
import type { NavigateToResource } from '../../utils/navigation'
|
|
4
|
+
|
|
5
|
+
// Opens a resource linked from an issue or finding, and counts it for usage data.
|
|
6
|
+
export function issueResourceOpener(navigate: NavigateToResource | undefined) {
|
|
7
|
+
if (!navigate) return undefined
|
|
8
|
+
return (ref: IssueResourceRef) => {
|
|
9
|
+
recordUsageEvent({ type: 'ui', name: 'issue_action:open' })
|
|
10
|
+
navigate({
|
|
11
|
+
kind: kindToPluralWithGroup(ref.kind, ref.group ?? ''),
|
|
12
|
+
namespace: ref.namespace ?? '',
|
|
13
|
+
name: ref.name,
|
|
14
|
+
group: ref.group ?? '',
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createContext, useContext, useState, useCallback, useEffect, useRef, ReactNode } from 'react'
|
|
2
2
|
import { useQuery, useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'
|
|
3
|
-
import { getApiBase } from '../api/config'
|
|
3
|
+
import { automaticRequestHeaders, getApiBase } from '../api/config'
|
|
4
4
|
import { readErrorBody } from '../api/httpErrors'
|
|
5
5
|
import { apiFetch, type SyncStatusSnapshot, type NodeDrainActivity } from '../api/client'
|
|
6
|
+
import { ClusterConnectedContext } from './clusterConnected'
|
|
6
7
|
|
|
7
8
|
export type ConnectionStateType = 'connected' | 'disconnected' | 'connecting'
|
|
8
9
|
|
|
@@ -13,6 +14,9 @@ export interface ConnectionState {
|
|
|
13
14
|
error?: string
|
|
14
15
|
errorType?: string // config, auth, auth-rejected, auth-plugin-stuck, rbac, network, timeout, tls, unknown
|
|
15
16
|
progressMessage?: string
|
|
17
|
+
// When this context stopped working (RFC 3339). Set by the server while
|
|
18
|
+
// disconnected; older servers never send it.
|
|
19
|
+
disconnectedAt?: string
|
|
16
20
|
// Per-kind readiness while the initial informer sync runs ('connecting'
|
|
17
21
|
// with informers started). Drives the progressive app shell — absent once
|
|
18
22
|
// connected or before informers exist.
|
|
@@ -49,6 +53,15 @@ class ConnectionRetryError extends Error {
|
|
|
49
53
|
const ConnectionContext = createContext<ConnectionContextValue | null>(null)
|
|
50
54
|
const AUTO_RETRY_INITIAL_DELAY_MS = 10000
|
|
51
55
|
const AUTO_RETRY_MAX_DELAY_MS = 60000
|
|
56
|
+
// Failed attempts in an outage before an unattended window slows to
|
|
57
|
+
// AUTO_RETRY_UNATTENDED_DELAY_MS (10s + 20s + 40s + 60s + 60s ≈ 3 minutes).
|
|
58
|
+
const AUTO_RETRY_ATTEMPTS_BEFORE_SLOWDOWN = 5
|
|
59
|
+
const AUTO_RETRY_UNATTENDED_DELAY_MS = 5 * 60_000
|
|
60
|
+
const WAKE_RETRY_DEDUPE_MS = 2000
|
|
61
|
+
// Returning to the window retries at once, but no sooner than this after the
|
|
62
|
+
// previous attempt started: someone alt-tabbing while they fix a VPN would
|
|
63
|
+
// otherwise run a full reconnect on every return.
|
|
64
|
+
const WAKE_RETRY_MIN_GAP_MS = AUTO_RETRY_INITIAL_DELAY_MS
|
|
52
65
|
const CONNECTION_STATUS_FALLBACK_POLL_MS = 30000
|
|
53
66
|
|
|
54
67
|
export function refreshQueriesAfterReconnect(queryClient: QueryClient, previousContext: string, nextContext: string) {
|
|
@@ -97,9 +110,10 @@ async function fetchConnectionStatus(sseGenerationAtStart: number): Promise<Poll
|
|
|
97
110
|
return { ...status, sseGenerationAtStart }
|
|
98
111
|
}
|
|
99
112
|
|
|
100
|
-
async function retryConnection(): Promise<ConnectionState> {
|
|
113
|
+
async function retryConnection(automatic = false): Promise<ConnectionState> {
|
|
101
114
|
const response = await apiFetch(`${getApiBase()}/connection/retry`, {
|
|
102
115
|
method: 'POST',
|
|
116
|
+
headers: automatic ? automaticRequestHeaders() : undefined,
|
|
103
117
|
})
|
|
104
118
|
if (!response.ok) {
|
|
105
119
|
const error = await readErrorBody(response) as { error?: string; errorType?: string }
|
|
@@ -125,6 +139,12 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
125
139
|
const hasConnectedRef = useRef(false)
|
|
126
140
|
const autoRetryInFlightRef = useRef(false)
|
|
127
141
|
const autoRetryDelayRef = useRef(AUTO_RETRY_INITIAL_DELAY_MS)
|
|
142
|
+
// Attempts in the current outage; only a successful connect resets it, so a
|
|
143
|
+
// manual retry's brief 'connecting' doesn't restart the count.
|
|
144
|
+
const autoRetryAttemptsRef = useRef(0)
|
|
145
|
+
const autoRetryContextRef = useRef('')
|
|
146
|
+
const lastWakeRetryAtRef = useRef(0)
|
|
147
|
+
const lastAutoRetryAtRef = useRef(0)
|
|
128
148
|
const manualRetryPendingRef = useRef(false)
|
|
129
149
|
// Fed by the status poll only (SSE frames don't carry the field, and must
|
|
130
150
|
// not clear it): while the server's recovery loop owns the episode, browser
|
|
@@ -155,6 +175,9 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
155
175
|
// Cache refresh shared by every path that lands on 'connected'.
|
|
156
176
|
const lastCacheRefreshAtRef = useRef(0)
|
|
157
177
|
const refreshCachesOnConnect = useCallback(() => {
|
|
178
|
+
// RBAC queries don't refetch an errored answer on mount; a fresh
|
|
179
|
+
// connection is when that answer may have changed.
|
|
180
|
+
queryClient.removeQueries({ queryKey: ['rbac'], predicate: query => query.state.status === 'error' })
|
|
158
181
|
const firstConnect = !hasConnectedRef.current
|
|
159
182
|
hasConnectedRef.current = true
|
|
160
183
|
// Poll and SSE can both observe the same reconnect within moments of each
|
|
@@ -258,6 +281,7 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
258
281
|
error: data.error,
|
|
259
282
|
errorType: data.errorType,
|
|
260
283
|
progressMessage: data.progressMessage,
|
|
284
|
+
disconnectedAt: data.disconnectedAt,
|
|
261
285
|
syncStatus: data.syncStatus,
|
|
262
286
|
})
|
|
263
287
|
if (becameConnected) {
|
|
@@ -267,7 +291,7 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
267
291
|
|
|
268
292
|
// Retry mutation
|
|
269
293
|
const retryMutation = useMutation({
|
|
270
|
-
mutationFn: retryConnection,
|
|
294
|
+
mutationFn: () => retryConnection(),
|
|
271
295
|
onMutate: () => {
|
|
272
296
|
manualRetryPendingRef.current = true
|
|
273
297
|
// Until SSE re-delivers state, a failed retry may report its own error
|
|
@@ -322,6 +346,13 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
322
346
|
}, [retryMutation.isPending])
|
|
323
347
|
|
|
324
348
|
useEffect(() => {
|
|
349
|
+
// An outage belongs to one context: switching to another starts its own
|
|
350
|
+
// count and backoff, and so does connecting.
|
|
351
|
+
if (connection.state === 'connected' || autoRetryContextRef.current !== connection.context) {
|
|
352
|
+
autoRetryAttemptsRef.current = 0
|
|
353
|
+
autoRetryDelayRef.current = AUTO_RETRY_INITIAL_DELAY_MS
|
|
354
|
+
autoRetryContextRef.current = connection.context
|
|
355
|
+
}
|
|
325
356
|
if (connection.state !== 'disconnected' || !shouldAutoRetryConnection(connection.errorType)) {
|
|
326
357
|
autoRetryDelayRef.current = AUTO_RETRY_INITIAL_DELAY_MS
|
|
327
358
|
return
|
|
@@ -329,65 +360,102 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
329
360
|
let stopped = false
|
|
330
361
|
let retryTimeout: number | undefined
|
|
331
362
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (serverOwnsRecoveryRef.current) {
|
|
342
|
-
scheduleRetry()
|
|
343
|
-
return
|
|
344
|
-
}
|
|
363
|
+
// Nobody is looking at a hidden or unfocused window (a desktop window
|
|
364
|
+
// behind others still reports visible), so after a few failures it
|
|
365
|
+
// checks only every few minutes. Coming back retries at once.
|
|
366
|
+
const nextDelay = () => {
|
|
367
|
+
const unattended = document.visibilityState === 'hidden' || !document.hasFocus()
|
|
368
|
+
return unattended && autoRetryAttemptsRef.current >= AUTO_RETRY_ATTEMPTS_BEFORE_SLOWDOWN
|
|
369
|
+
? AUTO_RETRY_UNATTENDED_DELAY_MS
|
|
370
|
+
: autoRetryDelayRef.current
|
|
371
|
+
}
|
|
345
372
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
373
|
+
const attempt = () => {
|
|
374
|
+
if (stopped) return
|
|
375
|
+
if (manualRetryPendingRef.current || autoRetryInFlightRef.current) {
|
|
376
|
+
scheduleRetry()
|
|
377
|
+
return
|
|
378
|
+
}
|
|
379
|
+
// Checked at fire time (not arm time): the poll may have learned
|
|
380
|
+
// mid-wait that the server's recovery loop owns this episode.
|
|
381
|
+
if (serverOwnsRecoveryRef.current) {
|
|
382
|
+
scheduleRetry()
|
|
383
|
+
return
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
autoRetryInFlightRef.current = true
|
|
387
|
+
autoRetryAttemptsRef.current += 1
|
|
388
|
+
lastAutoRetryAtRef.current = Date.now()
|
|
389
|
+
setIsAutoRetrying(true)
|
|
390
|
+
let recovered = false
|
|
391
|
+
retryConnection(true)
|
|
392
|
+
.then((result) => {
|
|
393
|
+
if (stopped) return
|
|
394
|
+
recovered = true
|
|
395
|
+
autoRetryDelayRef.current = AUTO_RETRY_INITIAL_DELAY_MS
|
|
396
|
+
sseActiveRef.current = false
|
|
397
|
+
const previousContext = connectionRef.current.context
|
|
398
|
+
setConnection(result)
|
|
399
|
+
if (result.state === 'connected') {
|
|
400
|
+
hasConnectedRef.current = true
|
|
401
|
+
lastCacheRefreshAtRef.current = Date.now()
|
|
402
|
+
}
|
|
403
|
+
refreshQueriesAfterReconnect(queryClient, previousContext, result.context)
|
|
404
|
+
})
|
|
405
|
+
.catch((error: Error) => {
|
|
406
|
+
if (stopped) return
|
|
407
|
+
const retryError = error as ConnectionRetryError
|
|
408
|
+
setConnection(prev => {
|
|
409
|
+
if (sseActiveRef.current && prev.state === 'connected') return prev
|
|
410
|
+
return {
|
|
411
|
+
...prev,
|
|
412
|
+
state: 'disconnected',
|
|
413
|
+
error: error.message || prev.error,
|
|
414
|
+
errorType: retryError.errorType || prev.errorType,
|
|
415
|
+
progressMessage: undefined,
|
|
387
416
|
}
|
|
388
417
|
})
|
|
389
|
-
|
|
418
|
+
autoRetryDelayRef.current = Math.min(autoRetryDelayRef.current * 2, AUTO_RETRY_MAX_DELAY_MS)
|
|
419
|
+
// Keep the visible disconnected state until a retry succeeds.
|
|
420
|
+
})
|
|
421
|
+
.finally(() => {
|
|
422
|
+
autoRetryInFlightRef.current = false
|
|
423
|
+
setIsAutoRetrying(false)
|
|
424
|
+
// Mirror the manual-retry onSettled: re-poll so a status update
|
|
425
|
+
// dropped by the mid-retry guard isn't stranded until next tick.
|
|
426
|
+
queryClient.invalidateQueries({ queryKey: ['connection-status'] })
|
|
427
|
+
if (!stopped && !recovered) {
|
|
428
|
+
scheduleRetry()
|
|
429
|
+
}
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const scheduleRetry = () => {
|
|
434
|
+
retryTimeout = window.setTimeout(attempt, nextDelay())
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Returning to the window or regaining the network retries now, silently.
|
|
438
|
+
// focus and visibilitychange often fire together, so one wake per moment.
|
|
439
|
+
// The network coming back counts even in a background window.
|
|
440
|
+
const wake = (event: Event) => {
|
|
441
|
+
if (stopped) return
|
|
442
|
+
if (event.type !== 'online' && document.visibilityState === 'hidden') return
|
|
443
|
+
const now = Date.now()
|
|
444
|
+
if (now - lastWakeRetryAtRef.current < WAKE_RETRY_DEDUPE_MS) return
|
|
445
|
+
// The network coming back is worth an attempt right away; a focus or
|
|
446
|
+
// visibility change only once the previous attempt is old enough.
|
|
447
|
+
if (event.type !== 'online' && now - lastAutoRetryAtRef.current < WAKE_RETRY_MIN_GAP_MS) return
|
|
448
|
+
lastWakeRetryAtRef.current = now
|
|
449
|
+
if (manualRetryPendingRef.current || autoRetryInFlightRef.current || serverOwnsRecoveryRef.current) return
|
|
450
|
+
if (retryTimeout !== undefined) {
|
|
451
|
+
window.clearTimeout(retryTimeout)
|
|
452
|
+
}
|
|
453
|
+
autoRetryDelayRef.current = AUTO_RETRY_INITIAL_DELAY_MS
|
|
454
|
+
attempt()
|
|
390
455
|
}
|
|
456
|
+
window.addEventListener('focus', wake)
|
|
457
|
+
window.addEventListener('online', wake)
|
|
458
|
+
document.addEventListener('visibilitychange', wake)
|
|
391
459
|
|
|
392
460
|
scheduleRetry()
|
|
393
461
|
|
|
@@ -396,8 +464,11 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
396
464
|
if (retryTimeout !== undefined) {
|
|
397
465
|
window.clearTimeout(retryTimeout)
|
|
398
466
|
}
|
|
467
|
+
window.removeEventListener('focus', wake)
|
|
468
|
+
window.removeEventListener('online', wake)
|
|
469
|
+
document.removeEventListener('visibilitychange', wake)
|
|
399
470
|
}
|
|
400
|
-
}, [connection.errorType, connection.state, queryClient])
|
|
471
|
+
}, [connection.context, connection.errorType, connection.state, queryClient])
|
|
401
472
|
|
|
402
473
|
const retry = useCallback(() => {
|
|
403
474
|
if (retryMutation.isPending || autoRetryInFlightRef.current) return
|
|
@@ -444,7 +515,9 @@ export function ConnectionProvider({ children }: { children: ReactNode }) {
|
|
|
444
515
|
|
|
445
516
|
return (
|
|
446
517
|
<ConnectionContext.Provider value={value}>
|
|
447
|
-
{
|
|
518
|
+
<ClusterConnectedContext.Provider value={connection.state === 'connected'}>
|
|
519
|
+
{children}
|
|
520
|
+
</ClusterConnectedContext.Provider>
|
|
448
521
|
</ConnectionContext.Provider>
|
|
449
522
|
)
|
|
450
523
|
}
|
|
@@ -0,0 +1,176 @@
|
|
|
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 { ConnectionProvider, useConnection } from './ConnectionContext'
|
|
7
|
+
|
|
8
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
9
|
+
|
|
10
|
+
let root: Root
|
|
11
|
+
let container: HTMLDivElement
|
|
12
|
+
let retries: number
|
|
13
|
+
const seen = vi.fn<(value: ReturnType<typeof useConnection>) => void>()
|
|
14
|
+
const latest = () => seen.mock.lastCall?.[0]
|
|
15
|
+
let focused: boolean
|
|
16
|
+
let pollContext: string
|
|
17
|
+
|
|
18
|
+
function Probe() {
|
|
19
|
+
seen(useConnection())
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function jsonResponse(status: number, body: unknown) {
|
|
24
|
+
return new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function advance(ms: number) {
|
|
28
|
+
await act(async () => {
|
|
29
|
+
await vi.advanceTimersByTimeAsync(ms)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
beforeEach(async () => {
|
|
34
|
+
vi.useFakeTimers()
|
|
35
|
+
retries = 0
|
|
36
|
+
seen.mockClear()
|
|
37
|
+
focused = false
|
|
38
|
+
pollContext = 'prod'
|
|
39
|
+
vi.spyOn(document, 'hasFocus').mockImplementation(() => focused)
|
|
40
|
+
vi.stubGlobal('fetch', vi.fn(async (input: string) => {
|
|
41
|
+
const url = new URL(String(input), 'http://localhost')
|
|
42
|
+
if (url.pathname === '/api/connection/retry') {
|
|
43
|
+
retries += 1
|
|
44
|
+
return jsonResponse(503, { error: 'cluster unreachable', errorType: 'network' })
|
|
45
|
+
}
|
|
46
|
+
if (url.pathname === '/api/connection') {
|
|
47
|
+
return jsonResponse(200, {
|
|
48
|
+
state: 'disconnected',
|
|
49
|
+
context: pollContext,
|
|
50
|
+
error: 'cluster unreachable',
|
|
51
|
+
errorType: 'network',
|
|
52
|
+
disconnectedAt: '2026-10-30T14:02:00Z',
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
return jsonResponse(404, { error: 'not found' })
|
|
56
|
+
}))
|
|
57
|
+
|
|
58
|
+
container = document.createElement('div')
|
|
59
|
+
document.body.appendChild(container)
|
|
60
|
+
root = createRoot(container)
|
|
61
|
+
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
62
|
+
await act(async () => {
|
|
63
|
+
root.render(
|
|
64
|
+
<QueryClientProvider client={client}>
|
|
65
|
+
<ConnectionProvider>
|
|
66
|
+
<Probe />
|
|
67
|
+
</ConnectionProvider>
|
|
68
|
+
</QueryClientProvider>,
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
// Let the first status poll land.
|
|
72
|
+
await advance(100)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
afterEach(() => {
|
|
76
|
+
act(() => root.unmount())
|
|
77
|
+
container.remove()
|
|
78
|
+
vi.restoreAllMocks()
|
|
79
|
+
vi.unstubAllGlobals()
|
|
80
|
+
vi.useRealTimers()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// Attempts land at 10s, 30s, 70s, 130s and 190s (10s doubling to a 60s cap).
|
|
84
|
+
const FIVE_ATTEMPTS_MS = 190_000
|
|
85
|
+
|
|
86
|
+
describe('ConnectionProvider auto-retry', () => {
|
|
87
|
+
it('carries the outage start from the server', () => {
|
|
88
|
+
expect(latest()?.connection.state).toBe('disconnected')
|
|
89
|
+
expect(latest()?.connection.disconnectedAt).toBe('2026-10-30T14:02:00Z')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('keeps retrying every minute while someone is looking', async () => {
|
|
93
|
+
focused = true
|
|
94
|
+
await advance(FIVE_ATTEMPTS_MS)
|
|
95
|
+
expect(retries).toBe(5)
|
|
96
|
+
await advance(60_000)
|
|
97
|
+
expect(retries).toBe(6)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('slows to every five minutes when nobody is looking, then retries at once on return', async () => {
|
|
101
|
+
await advance(FIVE_ATTEMPTS_MS)
|
|
102
|
+
expect(retries).toBe(5)
|
|
103
|
+
|
|
104
|
+
await advance(60_000)
|
|
105
|
+
expect(retries).toBe(5)
|
|
106
|
+
await advance(240_000)
|
|
107
|
+
expect(retries).toBe(6)
|
|
108
|
+
await advance(30_000)
|
|
109
|
+
|
|
110
|
+
focused = true
|
|
111
|
+
await act(async () => {
|
|
112
|
+
window.dispatchEvent(new Event('focus'))
|
|
113
|
+
document.dispatchEvent(new Event('visibilitychange'))
|
|
114
|
+
})
|
|
115
|
+
await advance(10)
|
|
116
|
+
// focus and visibilitychange together are one return, so one retry.
|
|
117
|
+
expect(retries).toBe(7)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('alt-tabbing back and forth retries no more than every ten seconds', async () => {
|
|
121
|
+
focused = true
|
|
122
|
+
await advance(15_000)
|
|
123
|
+
expect(retries).toBe(1) // the scheduled attempt at 10s
|
|
124
|
+
// Back to the window every 3s for 30s, as when switching to a terminal
|
|
125
|
+
// to fix the VPN and back.
|
|
126
|
+
for (let i = 0; i < 10; i++) {
|
|
127
|
+
await act(async () => {
|
|
128
|
+
window.dispatchEvent(new Event('blur'))
|
|
129
|
+
window.dispatchEvent(new Event('focus'))
|
|
130
|
+
document.dispatchEvent(new Event('visibilitychange'))
|
|
131
|
+
})
|
|
132
|
+
await advance(3_000)
|
|
133
|
+
}
|
|
134
|
+
// 30s of returns: at most one attempt per ten seconds, scheduled ones included.
|
|
135
|
+
expect(retries).toBeLessThanOrEqual(4)
|
|
136
|
+
expect(retries).toBeGreaterThanOrEqual(3)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('retries at once when the network comes back', async () => {
|
|
140
|
+
focused = true
|
|
141
|
+
await advance(15_000)
|
|
142
|
+
const before = retries
|
|
143
|
+
await act(async () => {
|
|
144
|
+
window.dispatchEvent(new Event('online'))
|
|
145
|
+
})
|
|
146
|
+
await advance(10)
|
|
147
|
+
expect(retries).toBe(before + 1)
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
describe('ConnectionProvider auto-retry across contexts and background windows', () => {
|
|
152
|
+
it('retries at once when the network comes back, even in a hidden window', async () => {
|
|
153
|
+
await advance(FIVE_ATTEMPTS_MS)
|
|
154
|
+
const before = retries
|
|
155
|
+
const visibility = vi.spyOn(document, 'visibilityState', 'get').mockReturnValue('hidden')
|
|
156
|
+
await act(async () => {
|
|
157
|
+
window.dispatchEvent(new Event('online'))
|
|
158
|
+
})
|
|
159
|
+
await advance(10)
|
|
160
|
+
expect(retries).toBe(before + 1)
|
|
161
|
+
visibility.mockRestore()
|
|
162
|
+
})
|
|
163
|
+
it('starts a fresh count and backoff for another context', async () => {
|
|
164
|
+
await advance(FIVE_ATTEMPTS_MS)
|
|
165
|
+
expect(retries).toBe(5)
|
|
166
|
+
// The next status poll reports a different context that is also down.
|
|
167
|
+
pollContext = 'staging'
|
|
168
|
+
await advance(30_000)
|
|
169
|
+
await advance(100)
|
|
170
|
+
expect(latest()?.connection.context).toBe('staging')
|
|
171
|
+
const before = retries
|
|
172
|
+
// A fresh outage retries after the initial 10s, not the unattended 5 minutes.
|
|
173
|
+
await advance(10_500)
|
|
174
|
+
expect(retries).toBe(before + 1)
|
|
175
|
+
})
|
|
176
|
+
})
|
|
@@ -9,8 +9,19 @@ export interface ParsedContextInfo {
|
|
|
9
9
|
clusterName: string
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// A switch Radar refused before leaving the current cluster, because the new
|
|
13
|
+
// one didn't answer. The app shows the connection error screen for it while
|
|
14
|
+
// staying connected to the current cluster underneath.
|
|
15
|
+
export interface FailedSwitch {
|
|
16
|
+
context: string
|
|
17
|
+
error: string
|
|
18
|
+
errorType: string
|
|
19
|
+
}
|
|
20
|
+
|
|
12
21
|
interface ContextSwitchState {
|
|
13
22
|
isSwitching: boolean
|
|
23
|
+
failedSwitch: FailedSwitch | null
|
|
24
|
+
setFailedSwitch: (failed: FailedSwitch | null) => void
|
|
14
25
|
targetContext: ParsedContextInfo | null
|
|
15
26
|
progressMessage: string | null
|
|
16
27
|
startSwitch: (context: ParsedContextInfo) => void
|
|
@@ -29,8 +40,10 @@ export function ContextSwitchProvider({ children }: { children: ReactNode }) {
|
|
|
29
40
|
const [isSwitching, setIsSwitching] = useState(false)
|
|
30
41
|
const [targetContext, setTargetContext] = useState<ParsedContextInfo | null>(null)
|
|
31
42
|
const [progressMessage, setProgressMessage] = useState<string | null>(null)
|
|
43
|
+
const [failedSwitch, setFailedSwitch] = useState<FailedSwitch | null>(null)
|
|
32
44
|
|
|
33
45
|
const startSwitch = useCallback((context: ParsedContextInfo) => {
|
|
46
|
+
setFailedSwitch(null)
|
|
34
47
|
setIsSwitching(true)
|
|
35
48
|
setTargetContext(context)
|
|
36
49
|
setProgressMessage(null)
|
|
@@ -57,7 +70,7 @@ export function ContextSwitchProvider({ children }: { children: ReactNode }) {
|
|
|
57
70
|
}, [])
|
|
58
71
|
|
|
59
72
|
return (
|
|
60
|
-
<ContextSwitchContext.Provider value={{ isSwitching, targetContext, progressMessage, startSwitch, updateProgress, endSwitch, setOpenAfterSwitch, takeOpenAfterSwitch }}>
|
|
73
|
+
<ContextSwitchContext.Provider value={{ isSwitching, failedSwitch, setFailedSwitch, targetContext, progressMessage, startSwitch, updateProgress, endSwitch, setOpenAfterSwitch, takeOpenAfterSwitch }}>
|
|
61
74
|
{children}
|
|
62
75
|
</ContextSwitchContext.Provider>
|
|
63
76
|
)
|
|
@@ -39,6 +39,9 @@ export type RenderDiagnoseAction = (ctx: {
|
|
|
39
39
|
/** Coarse health of the resource (from its status badge), so the entry point can
|
|
40
40
|
* adapt: an urgent "Investigate" on a problem vs. a quiet "ask AI" when fine/unknown. */
|
|
41
41
|
health?: "problem" | "healthy" | "unknown";
|
|
42
|
+
/** The object's metadata.creationTimestamp, when loaded. An investigation
|
|
43
|
+
* that started before it was of an earlier object with the same name. */
|
|
44
|
+
createdAt?: string;
|
|
42
45
|
}) => ReactNode;
|
|
43
46
|
|
|
44
47
|
/**
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
|
|
3
|
+
// Whether the cluster is connected right now, for data hooks that poll it.
|
|
4
|
+
// Kept apart from ConnectionContext so api hooks can read it without a
|
|
5
|
+
// circular import. Defaults to true outside the provider (tests, hosts).
|
|
6
|
+
export const ClusterConnectedContext = createContext(true)
|
|
7
|
+
|
|
8
|
+
export function useClusterConnected(): boolean {
|
|
9
|
+
return useContext(ClusterConnectedContext)
|
|
10
|
+
}
|
|
@@ -159,6 +159,9 @@ export function useNamespacedCapabilities(namespace: string | undefined) {
|
|
|
159
159
|
console.warn('Failed to fetch namespace capabilities, using global:', namespace, error)
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
// A failed refetch keeps the last successful namespace answer; with none,
|
|
163
|
+
// the global value is not an answer for this namespace.
|
|
164
|
+
const namespaceUnknown = Boolean(namespace && !nsCaps && (isPending || error))
|
|
162
165
|
return useMemo(() => ({
|
|
163
166
|
canExec: nsCaps?.exec ?? globalCaps.exec,
|
|
164
167
|
canViewLogs: nsCaps?.logs ?? globalCaps.logs,
|
|
@@ -166,8 +169,7 @@ export function useNamespacedCapabilities(namespace: string | undefined) {
|
|
|
166
169
|
canHelmWrite: nsCaps?.helmWrite ?? globalCaps.helmWrite,
|
|
167
170
|
workloadWrites: nsCaps?.workloadWrites ?? globalCaps.workloadWrites,
|
|
168
171
|
workloadWritesPending: Boolean(namespace && isPending),
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}), [globalCaps.exec, globalCaps.logs, globalCaps.portForward, globalCaps.helmWrite, globalCaps.workloadWrites, error, isPending, namespace, nsCaps])
|
|
172
|
+
helmWriteUnknown: namespaceUnknown,
|
|
173
|
+
logsUnknown: namespaceUnknown,
|
|
174
|
+
}), [globalCaps.exec, globalCaps.logs, globalCaps.portForward, globalCaps.helmWrite, globalCaps.workloadWrites, isPending, namespace, nsCaps, namespaceUnknown])
|
|
173
175
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface ElementSize {
|
|
4
|
+
width: number
|
|
5
|
+
height: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Tracks an element's rendered size. Until the first measurement (and where
|
|
9
|
+
// ResizeObserver is missing, as in jsdom) it reports `initial`.
|
|
10
|
+
export function useElementSize<T extends Element>(initial: ElementSize) {
|
|
11
|
+
const ref = useRef<T>(null)
|
|
12
|
+
const [size, setSize] = useState(initial)
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const el = ref.current
|
|
16
|
+
if (!el || typeof ResizeObserver === 'undefined') return
|
|
17
|
+
const update = () => {
|
|
18
|
+
const { width, height } = el.getBoundingClientRect()
|
|
19
|
+
if (width > 0 && height > 0) {
|
|
20
|
+
setSize(prev => (prev.width === width && prev.height === height ? prev : { width, height }))
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
update()
|
|
24
|
+
const observer = new ResizeObserver(update)
|
|
25
|
+
observer.observe(el)
|
|
26
|
+
return () => observer.disconnect()
|
|
27
|
+
}, [])
|
|
28
|
+
|
|
29
|
+
return [ref, size] as const
|
|
30
|
+
}
|
|
@@ -48,6 +48,7 @@ describe('resource host composition', () => {
|
|
|
48
48
|
|
|
49
49
|
it('catches summary and tab conflicts even if a contribution omitted its declaration', () => {
|
|
50
50
|
expect(() => composeDetailSlots(['one', 'two'].map(id => ({ id, slots: { renderSummary: () => null } })))).toThrow('summary ownership conflict')
|
|
51
|
+
expect(() => composeDetailSlots(['one', 'two'].map(id => ({ id, slots: { renderStatusBadge: () => null } })))).toThrow('status badge ownership conflict')
|
|
51
52
|
const tab = { id: 'runs', label: 'Runs', render: () => null }
|
|
52
53
|
expect(composeDetailSlots([], [tab, tab]).extraTabs).toEqual([tab, tab])
|
|
53
54
|
expect(() => composeDetailSlots([{ id: 'execution', slots: { extraTabs: [tab] } }], [tab])).toThrow('tab ownership conflict: runs')
|
|
@@ -6,7 +6,7 @@ import type { SelectedResource } from '../types'
|
|
|
6
6
|
import { kindToPluralWithGroup } from '../utils/navigation'
|
|
7
7
|
|
|
8
8
|
export type HostResource = Pick<SelectedResource, 'kind' | 'group' | 'namespace' | 'name'>
|
|
9
|
-
export type DetailSlots = Pick<ComponentProps<typeof WorkloadView>, 'renderSummary' | 'renderHeaderActions' | 'extraTabs'>
|
|
9
|
+
export type DetailSlots = Pick<ComponentProps<typeof WorkloadView>, 'renderSummary' | 'renderHeaderActions' | 'extraTabs' | 'renderStatusBadge'>
|
|
10
10
|
export type HostFeatures = Partial<Record<RadarFeature, RadarFeatureSupport>>
|
|
11
11
|
export type KindListMode = 'table' | 'wait' | 'view'
|
|
12
12
|
export interface HostKind { name: string; kind: string; group: string }
|
|
@@ -84,6 +84,9 @@ export function composeDetailSlots(contributions: readonly { id: string; slots:
|
|
|
84
84
|
const summaries = contributions.filter(host => host.slots?.renderSummary)
|
|
85
85
|
if (summaries.length > 1) throw new Error(`Resource host summary ownership conflict: ${summaries.map(host => host.id).join(', ')}`)
|
|
86
86
|
const summary = summaries[0]?.slots?.renderSummary
|
|
87
|
+
const badges = contributions.filter(host => host.slots?.renderStatusBadge)
|
|
88
|
+
if (badges.length > 1) throw new Error(`Resource host status badge ownership conflict: ${badges.map(host => host.id).join(', ')}`)
|
|
89
|
+
const badge = badges[0]?.slots?.renderStatusBadge
|
|
87
90
|
const actions = contributions.filter(host => host.slots?.renderHeaderActions)
|
|
88
91
|
const tabs = [...inheritedTabs, ...contributions.flatMap(host => host.slots?.extraTabs ?? [])]
|
|
89
92
|
const tabIds = new Set(inheritedTabs.map(tab => tab.id))
|
|
@@ -93,6 +96,7 @@ export function composeDetailSlots(contributions: readonly { id: string; slots:
|
|
|
93
96
|
}
|
|
94
97
|
return {
|
|
95
98
|
...(summary ? { renderSummary: summary } : {}),
|
|
99
|
+
...(badge ? { renderStatusBadge: badge } : {}),
|
|
96
100
|
...(actions.length ? { renderHeaderActions: (props: Parameters<NonNullable<DetailSlots['renderHeaderActions']>>[0]) => actions.map(host => createElement(Fragment, { key: host.id }, host.slots!.renderHeaderActions!(props))) } : {}),
|
|
97
101
|
...(tabs.length ? { extraTabs: tabs } : {}),
|
|
98
102
|
}
|