@skyhook-io/radar-app 1.21.2 → 1.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +11 -0
  2. package/package.json +2 -2
  3. package/src/App.tsx +50 -28
  4. package/src/api/actions.test.ts +11 -0
  5. package/src/api/actions.ts +5 -0
  6. package/src/api/apiResources.navigation.test.tsx +58 -0
  7. package/src/api/apiResources.ts +22 -16
  8. package/src/api/client.diagnostics.test.ts +52 -0
  9. package/src/api/client.triggerCronJob.test.tsx +49 -0
  10. package/src/api/client.ts +140 -120
  11. package/src/api/connectionBinding.test.tsx +82 -0
  12. package/src/api/connectionBinding.ts +52 -0
  13. package/src/api/contextSwitch.test.ts +11 -0
  14. package/src/api/contextSwitch.ts +58 -0
  15. package/src/api/radarFeatures.ts +5 -0
  16. package/src/components/ConnectionErrorView.tsx +13 -0
  17. package/src/components/ContextSwitchActions.tsx +43 -0
  18. package/src/components/ContextSwitcher.tsx +13 -6
  19. package/src/components/SwitchAwareConnectionError.tsx +2 -2
  20. package/src/components/cost/ApplicationCostTab.test.ts +16 -0
  21. package/src/components/cost/ApplicationCostTab.tsx +41 -9
  22. package/src/components/cost/CostTrendChart.tsx +25 -2
  23. package/src/components/cost/CostTrendWithheld.render.test.tsx +105 -0
  24. package/src/components/cost/CostView.tsx +10 -2
  25. package/src/components/cost/CostViewTabs.test.tsx +18 -0
  26. package/src/components/cost/CostViewTabs.tsx +14 -22
  27. package/src/components/cost/WorkloadCostTab.test.ts +15 -0
  28. package/src/components/cost/WorkloadCostTab.tsx +42 -8
  29. package/src/components/cost/source.test.ts +16 -1
  30. package/src/components/cost/source.ts +34 -0
  31. package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +35 -0
  32. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +16 -1
  33. package/src/components/dock/NodeTerminalTab.test.tsx +4 -2
  34. package/src/components/dock/NodeTerminalTab.tsx +8 -8
  35. package/src/components/dock/TerminalTab.test.tsx +12 -1
  36. package/src/components/dock/TerminalTab.tsx +6 -3
  37. package/src/components/home/CostCard.test.tsx +49 -0
  38. package/src/components/home/CostCard.tsx +98 -63
  39. package/src/components/home/mcpToolCatalog.ts +1 -0
  40. package/src/components/resource/DatadogRightsizingPanel.test.tsx +118 -0
  41. package/src/components/resource/DatadogRightsizingPanel.tsx +68 -0
  42. package/src/components/resource/DatadogWorkloadCharts.tsx +149 -0
  43. package/src/components/resource/HPACharts.render.test.tsx +42 -0
  44. package/src/components/resource/HPACharts.tsx +34 -1
  45. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +126 -3
  46. package/src/components/resource/PrometheusChartsGrid.tsx +58 -25
  47. package/src/components/resource/RestartChart.render.test.tsx +72 -0
  48. package/src/components/resource/RestartChart.tsx +31 -3
  49. package/src/components/resource/RightsizingPanel.access.test.tsx +24 -0
  50. package/src/components/resource/RightsizingStrip.render.test.tsx +44 -0
  51. package/src/components/resource/RightsizingStrip.test.ts +1 -188
  52. package/src/components/resource/RightsizingStrip.tsx +27 -300
  53. package/src/components/resource/WorkloadMetricsSection.render.test.tsx +22 -0
  54. package/src/components/resource/WorkloadMetricsSection.tsx +14 -4
  55. package/src/components/resource/nameMatchedScope.ts +39 -0
  56. package/src/components/resources/pod-file-upload.ts +3 -0
  57. package/src/components/resources/renderers/CAPIClusterRenderer.tsx +5 -2
  58. package/src/components/resources/renderers/LonghornVolumeRenderer.test.tsx +104 -0
  59. package/src/components/resources/renderers/LonghornVolumeRenderer.tsx +31 -0
  60. package/src/components/rightsizing/RightsizingScanLink.tsx +22 -0
  61. package/src/components/rightsizing/RightsizingScanView.tsx +65 -528
  62. package/src/components/rightsizing/model.test.ts +20 -9
  63. package/src/components/rightsizing/model.ts +17 -176
  64. package/src/components/rightsizing/notices.test.tsx +30 -29
  65. package/src/components/ui/DiagnosticsOverlay.test.ts +3 -2
  66. package/src/components/ui/DiagnosticsOverlay.tsx +23 -13
  67. package/src/components/ui/command-items.ts +3 -4
  68. package/src/components/useContextSwitchFlow.test.tsx +9 -0
  69. package/src/components/useContextSwitchFlow.tsx +43 -5
  70. package/src/components/workload/WorkloadRightsizingSource.test.tsx +83 -0
  71. package/src/components/workload/WorkloadView.test.ts +22 -1
  72. package/src/components/workload/WorkloadView.tsx +57 -16
  73. package/src/context/ConnectionContext.test.ts +1 -0
  74. package/src/context/ConnectionContext.tsx +58 -15
  75. package/src/context/ConnectionProvider.connectionId.test.tsx +92 -0
  76. package/src/context/ConnectionProvider.retry.test.tsx +174 -1
  77. package/src/context/ContextSwitchContext.tsx +15 -1
  78. package/src/context/NavCustomization.tsx +6 -3
  79. package/src/hooks/useEventSource.test.tsx +85 -0
  80. package/src/hooks/useEventSource.ts +43 -16
  81. package/src/hooks/useResetViewsOnContextChange.test.tsx +34 -0
  82. package/src/hooks/useResetViewsOnContextChange.ts +27 -0
  83. package/src/index.ts +3 -0
  84. package/src/integrations/resourceHosts.test.tsx +1 -1
  85. package/src/integrations/resourceHosts.tsx +2 -0
  86. package/src/utils/navigation.ts +1 -15
  87. package/src/utils/page-links.ts +6 -0
  88. package/src/components/rightsizing/presentation.test.ts +0 -150
  89. package/src/components/rightsizing/presentation.ts +0 -109
@@ -9,7 +9,7 @@ import {
9
9
  formatMetricValue,
10
10
  type ReferenceLine,
11
11
  } from "@skyhook-io/k8s-ui/components/charts";
12
- import { type PrometheusTimeRange } from "../../api/client";
12
+ import { usePrometheusResourceMetrics, type PrometheusTimeRange } from "../../api/client";
13
13
  import {
14
14
  useWorkloadMetrics,
15
15
  type WorkloadMetricPanel,
@@ -19,6 +19,7 @@ import {
19
19
  import { latestWorkloadValue, workloadPodValues } from "./workloadMetricValues";
20
20
  import { WorkloadMetricsHelpDialog } from './WorkloadMetricsHelpDialog';
21
21
  import { Disclosure } from '@skyhook-io/k8s-ui/components/ui/Disclosure';
22
+ import { leastCertainScope, NAME_MATCHED_CLUSTER_NOTE, NAME_MATCHED_SUMMARY } from './nameMatchedScope';
22
23
 
23
24
  interface Props {
24
25
  kind: string;
@@ -30,6 +31,7 @@ interface Props {
30
31
  restartLane?: ReactNode;
31
32
  nameMatchedCharts?: Partial<Record<'cpu' | 'memory', ReactNode>>;
32
33
  controls?: ReactNode;
34
+ workloadTotals?: ReactNode;
33
35
  }
34
36
 
35
37
  export function WorkloadMetricsSection(props: Props) {
@@ -51,6 +53,11 @@ export function WorkloadMetricsSection(props: Props) {
51
53
  const panel = data?.panels[key];
52
54
  return (data || error) && props.nameMatchedCharts?.[key] && (!panel || ['detecting', 'error', 'unavailable'].includes(panel.state));
53
55
  });
56
+ // Read from the cache the name-matched charts fill; never fetches itself.
57
+ const cpuNameMatched = usePrometheusResourceMetrics(props.kind, props.namespace, props.name, 'cpu', props.range, false).data;
58
+ const memoryNameMatched = usePrometheusResourceMetrics(props.kind, props.namespace, props.name, 'memory', props.range, false).data;
59
+ const nameMatchedScope = leastCertainScope(nameMatchedFallbacks.map((key) => (key === 'cpu' ? cpuNameMatched : memoryNameMatched)?.clusterScope));
60
+ const nameMatchedNote = NAME_MATCHED_CLUSTER_NOTE[nameMatchedScope];
54
61
  const resourceNotice = sameResourceScope ? sharedPanelNotice([data?.panels.cpu, data?.panels.memory, data?.panels.throttling]) : undefined;
55
62
  const hasHistoricalTotals = (['cpu', 'memory'] as const).some((key) => data?.history[key]?.mode === 'workload-history');
56
63
  const hasResourceDetails = hasHistoricalTotals || data?.history.throttling?.mode === 'workload-history' || resourceNotice?.state === 'stale';
@@ -67,9 +74,10 @@ export function WorkloadMetricsSection(props: Props) {
67
74
  {data?.state === 'partial' && data.reason && <p role="status" className={`text-xs ${SEVERITY_TEXT.warning}`}>{data.reason}</p>}
68
75
  {isPlaceholderData && <p role="status" className="text-xs text-theme-text-secondary">Loading selected request source… Resources show previous samples.</p>}
69
76
  <WorkloadRequests data={data} isLoading={isLoading || isPlaceholderData} error={error} setSource={setSource} />
77
+ {props.workloadTotals}
70
78
  <section aria-label="Workload resource pressure">
71
79
  {(data?.panels.cpu || data?.panels.memory || data?.panels.throttling) && <div className="mb-2 flex flex-wrap items-baseline gap-x-3 gap-y-1">
72
- <h3 className="text-sm font-semibold text-theme-text-primary">Resources</h3>
80
+ <h3 className="text-sm font-semibold text-theme-text-primary">{props.workloadTotals ? 'Prometheus resources' : 'Resources'}</h3>
73
81
  {sameResourceScope && <HistoryNotice scope={data?.history.cpu} omitReason={data?.panels.cpu?.reason} />}
74
82
  </div>}
75
83
  {props.restartLane}
@@ -97,8 +105,10 @@ export function WorkloadMetricsSection(props: Props) {
97
105
  </Disclosure>}
98
106
  </section>
99
107
  {nameMatchedFallbacks.length > 0 && <details aria-label="Name-matched resource metrics">
100
- <summary className="mb-2 cursor-pointer text-xs text-theme-text-secondary">Basic {nameMatchedFallbacks.map((key) => key === 'cpu' ? 'CPU' : 'memory').join(' / ')} · identity unverified</summary>
101
- <p className={`mb-2 max-w-2xl text-sm ${SEVERITY_TEXT.warning}`}>These charts match current Pod names, not Pod UIDs or historical workload ownership; matching names in a shared backend may include another cluster.</p>
108
+ <summary className="mb-2 cursor-pointer text-xs text-theme-text-secondary">Basic {nameMatchedFallbacks.map((key) => key === 'cpu' ? 'CPU' : 'memory').join(' / ')} · {NAME_MATCHED_SUMMARY[nameMatchedScope]}</summary>
109
+ {nameMatchedNote
110
+ ? <p className={`mb-2 max-w-2xl text-sm ${nameMatchedScope === 'withheld' ? SEVERITY_TEXT.warning : 'text-theme-text-secondary'}`}>These charts match current Pod names, not Pod UIDs or historical workload ownership. {nameMatchedNote}</p>
111
+ : <p className={`mb-2 max-w-2xl text-sm ${SEVERITY_TEXT.warning}`}>These charts match current Pod names, not Pod UIDs or historical workload ownership; matching names in a shared backend may include another cluster.</p>}
102
112
  <div className="metrics-chart-grid">{nameMatchedFallbacks.map((key) => <div key={key}>{props.nameMatchedCharts?.[key]}</div>)}</div>
103
113
  </details>}
104
114
  {data && (data.comparison.cpu || data.comparison.memory || data.comparison.throttling) && <PodComparison
@@ -0,0 +1,39 @@
1
+ import { isClusterScopeWithheld, type ClusterScope } from "@skyhook-io/k8s-ui/types/cluster-scope";
2
+
3
+ /**
4
+ * How the Pod-name-matched charts in one section were kept to this cluster.
5
+ * `caveat` keeps the "may include another cluster" wording: an unlabeled
6
+ * store, older Radar (no clusterScope), or a chart that hasn't answered yet.
7
+ */
8
+ export type NameMatchedScope = "scoped" | "asserted" | "withheld" | "caveat";
9
+
10
+ // Least certain first. A chart drawn without a cluster check outranks a
11
+ // withheld one: it shows numbers that may mix clusters, the withheld one none.
12
+ const RANK: NameMatchedScope[] = ["caveat", "withheld", "asserted", "scoped"];
13
+
14
+ function classify(scope: ClusterScope | null | undefined): NameMatchedScope {
15
+ if (scope?.state === "scoped_configured" || scope?.state === "scoped_verified") return "scoped";
16
+ if (scope?.state === "single_cluster_asserted") return "asserted";
17
+ return isClusterScopeWithheld(scope) ? "withheld" : "caveat";
18
+ }
19
+
20
+ /** The least certain scope among a section's charts. */
21
+ export function leastCertainScope(scopes: (ClusterScope | null | undefined)[]): NameMatchedScope {
22
+ if (scopes.length === 0) return "caveat";
23
+ return scopes.map(classify).reduce((a, b) => (RANK.indexOf(a) <= RANK.indexOf(b) ? a : b));
24
+ }
25
+
26
+ export const NAME_MATCHED_SUMMARY: Record<NameMatchedScope, string> = {
27
+ scoped: "matched by cluster label",
28
+ asserted: "operator declared single-cluster",
29
+ withheld: "identity unverified",
30
+ caveat: "identity unverified",
31
+ };
32
+
33
+ /** The sentence that replaces "may include another cluster", or undefined to keep it. */
34
+ export const NAME_MATCHED_CLUSTER_NOTE: Record<NameMatchedScope, string | undefined> = {
35
+ scoped: "They're kept to this cluster by its cluster labels.",
36
+ asserted: "An operator declared this metrics store single-cluster, so they don't include another cluster.",
37
+ withheld: "Charts that couldn't be kept to this cluster say why in place of their data.",
38
+ caveat: undefined,
39
+ };
@@ -1,6 +1,7 @@
1
1
  import type { FileNode } from '../../types'
2
2
  import { apiUrl, getAuthHeaders, getCredentialsMode } from '../../api/config'
3
3
  import { formatBytes } from '../../utils/format'
4
+ import { CONNECTION_HEADER, connectionHeaderValue } from '../../api/connectionBinding'
4
5
 
5
6
  export const POD_FILE_PERSISTENCE_NOTE =
6
7
  "Changes apply to the running container immediately. Files in the container's own filesystem are lost when it's recreated; files on volumes may persist. For lasting changes, update the source (image, ConfigMap, manifest)."
@@ -235,6 +236,8 @@ export function uploadPodFile(req: UploadRequest): Promise<UploadResult> {
235
236
  xhr.open('POST', url)
236
237
  xhr.withCredentials = getCredentialsMode() === 'include'
237
238
  for (const [k, v] of Object.entries(getAuthHeaders())) xhr.setRequestHeader(k, v)
239
+ const connection = connectionHeaderValue()
240
+ if (connection) xhr.setRequestHeader(CONNECTION_HEADER, connection)
238
241
  xhr.setRequestHeader('Content-Type', 'application/octet-stream')
239
242
  xhr.upload.onprogress = (e) => {
240
243
  if (e.lengthComputable) req.onProgress?.(e.loaded, e.total)
@@ -1,8 +1,11 @@
1
1
  import { CAPIClusterRenderer as BaseCAPIClusterRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/CAPIClusterRenderer'
2
2
  import type { ResourceRef } from '@skyhook-io/k8s-ui'
3
- import { useCapabilities } from '../../../api/client'
3
+ import { apiFetch, useCapabilities } from '../../../api/client'
4
+ import { apiUrl } from '../../../api/config'
5
+
6
+ const request = (path: string, init?: RequestInit) => apiFetch(apiUrl(path), init)
4
7
 
5
8
  export function CAPIClusterRenderer({ data, onNavigate }: { data: any; onNavigate?: (ref: ResourceRef) => void }) {
6
9
  const { data: capabilities } = useCapabilities()
7
- return <BaseCAPIClusterRenderer data={data} onNavigate={onNavigate} canConnect={capabilities != null && capabilities.configManagement !== 'operator'} />
10
+ return <BaseCAPIClusterRenderer data={data} onNavigate={onNavigate} request={request} canConnect={capabilities != null && capabilities.configManagement !== 'operator'} />
8
11
  }
@@ -0,0 +1,104 @@
1
+ import { beforeAll, describe, expect, it, vi } from 'vitest'
2
+ import { renderToStaticMarkup } from 'react-dom/server'
3
+
4
+ const volume = { apiVersion: 'longhorn.io/v1beta2', kind: 'Volume', metadata: { name: 'pvc-1', namespace: 'longhorn-system' }, spec: { numberOfReplicas: 3 }, status: { state: 'attached', robustness: 'healthy', kubernetesStatus: { namespace: 'shop', pvcName: 'data-db-0', lastPVCRefAt: '' } } }
5
+
6
+ async function render(engines: { data?: any[]; error?: unknown; isLoading?: boolean; coverage?: { status: string } }, namespaces?: { name: string }[], authEnabled?: boolean) {
7
+ vi.resetModules()
8
+ vi.doMock('../../../api/client', () => ({
9
+ useResources: () => ({ data: engines.data, coverage: engines.coverage, error: engines.error ?? null, isError: !!engines.error, isLoading: !!engines.isLoading }),
10
+ useNamespaces: () => ({ data: namespaces }),
11
+ useAuthMe: () => ({ data: authEnabled === undefined ? undefined : { authEnabled } }),
12
+ }))
13
+ const { LonghornVolumeRenderer } = await import('./LonghornVolumeRenderer')
14
+ const html = renderToStaticMarkup(<LonghornVolumeRenderer data={volume} />)
15
+ vi.doUnmock('../../../api/client')
16
+ return html
17
+ }
18
+
19
+ describe('LonghornVolumeRenderer (host)', () => {
20
+ // The first dynamic import transforms the renderer's whole k8s-ui graph; pay
21
+ // that once here so each test's own timeout still catches a real hang.
22
+ beforeAll(async () => {
23
+ await render({})
24
+ }, 30_000)
25
+
26
+ it('counts healthy replicas from the volume\'s own Engine', async () => {
27
+ const html = await render({ data: [
28
+ { spec: { volumeName: 'other' }, status: { replicaModeMap: { x: 'RW' } } },
29
+ { spec: { volumeName: 'pvc-1' }, status: { replicaModeMap: { a: 'RW', b: 'RW', c: 'RW' } } },
30
+ ] })
31
+ expect(html).toContain('3 of 3')
32
+ })
33
+
34
+ it('says when it could not read the Engine instead of looking checked', async () => {
35
+ const html = await render({ error: new Error('boom') })
36
+ expect(html).toContain('? of 3')
37
+ expect(html).toContain('Could not check')
38
+ expect(html).not.toContain('Engine not running')
39
+ })
40
+
41
+ it('reads the active Engine while a volume migrates, and unknown when none is active', async () => {
42
+ const migrating = await render({ data: [
43
+ { spec: { volumeName: 'pvc-1', active: false }, status: { replicaModeMap: { a: 'RW' } } },
44
+ { spec: { volumeName: 'pvc-1', active: true }, status: { replicaModeMap: { a: 'RW', b: 'RW', c: 'RW' } } },
45
+ ] })
46
+ expect(migrating).toContain('3 of 3')
47
+ const ambiguous = await render({ data: [
48
+ { spec: { volumeName: 'pvc-1', active: false }, status: { replicaModeMap: { a: 'RW' } } },
49
+ { spec: { volumeName: 'pvc-1', active: false }, status: { replicaModeMap: { a: 'RW', b: 'RW' } } },
50
+ ] })
51
+ expect(ambiguous).toContain('? of 3')
52
+ })
53
+
54
+ it('does not call the Engine stopped while the lookup is still loading', async () => {
55
+ const html = await render({ isLoading: true })
56
+ expect(html).toContain('? of 3')
57
+ expect(html).not.toContain('Engine not running')
58
+ })
59
+
60
+ it('says the Engine is not running once the lookup finds none for this volume', async () => {
61
+ const html = await render({ data: [{ spec: { volumeName: 'other' }, status: { replicaModeMap: { x: 'RW' } } }], coverage: { status: 'complete' } })
62
+ expect(html).toContain('? of 3 (Engine not running)')
63
+ })
64
+
65
+ it('shows Longhorn\'s recorded PVC only when the caller\'s namespace list includes it', async () => {
66
+ expect(await render({ data: [] }, [{ name: 'shop' }])).toContain('shop/data-db-0')
67
+ expect(await render({ data: [] }, [{ name: 'other' }])).not.toContain('data-db-0')
68
+ expect(await render({ data: [] })).not.toContain('data-db-0')
69
+ })
70
+
71
+ it('keeps the history of a deleted namespace when auth is off, and decides from the list while the auth status loads', async () => {
72
+ expect(await render({ data: [] }, [{ name: 'other' }], false)).toContain('shop/data-db-0')
73
+ expect(await render({ data: [] }, undefined, false)).toContain('shop/data-db-0')
74
+ expect(await render({ data: [] }, [{ name: 'other' }], undefined)).not.toContain('data-db-0')
75
+ expect(await render({ data: [] }, [{ name: 'shop' }], undefined)).toContain('shop/data-db-0')
76
+ expect(await render({ data: [] }, [{ name: 'other' }], true)).not.toContain('data-db-0')
77
+ expect(await render({ data: [] }, undefined, true)).not.toContain('data-db-0')
78
+ })
79
+
80
+ it('does not call the Engine stopped when the read was partial or its coverage unknown', async () => {
81
+ for (const coverage of [{ status: 'partial' }, { status: 'unknown' }, undefined]) {
82
+ const html = await render({ data: [], coverage })
83
+ expect(html).toContain('? of 3')
84
+ expect(html).not.toContain('Engine not running')
85
+ }
86
+ })
87
+
88
+ it('reads unknown when more than one Engine is marked active', async () => {
89
+ const html = await render({ data: [
90
+ { spec: { volumeName: 'pvc-1', active: true }, status: { replicaModeMap: { a: 'RW' } } },
91
+ { spec: { volumeName: 'pvc-1', active: true }, status: { replicaModeMap: { a: 'RW', b: 'RW' } } },
92
+ ], coverage: { status: 'complete' } })
93
+ expect(html).toContain('? of 3')
94
+ expect(html).not.toContain('1 of 3')
95
+ expect(html).not.toContain('2 of 3')
96
+ })
97
+
98
+ it('drops the last count when a refresh fails', async () => {
99
+ const html = await render({ data: [{ spec: { volumeName: 'pvc-1', active: true }, status: { replicaModeMap: { a: 'RW', b: 'RW', c: 'RW' } } }], error: new Error('boom') })
100
+ expect(html).toContain('? of 3')
101
+ expect(html).not.toContain('3 of 3')
102
+ expect(html).toContain('Could not check')
103
+ })
104
+ })
@@ -0,0 +1,31 @@
1
+ import { LonghornVolumeRenderer as BaseLonghornVolumeRenderer } from '@skyhook-io/k8s-ui/components/resources/renderers/LonghornVolumeRenderer'
2
+ import { LookupFailureNote } from '@skyhook-io/k8s-ui/components/resources/renderers/LookupFailureNote'
3
+ import { LONGHORN_GROUP } from '@skyhook-io/k8s-ui/components/resources/resource-utils-longhorn'
4
+ import { useAuthMe, useNamespaces, useResources } from '../../../api/client'
5
+
6
+ /** Host wrapper: reads the Volume's Engine, the only source of healthy replicas and rebuild progress. */
7
+ export function LonghornVolumeRenderer({ data }: { data: any }) {
8
+ const engines = useResources<any>('engines', data?.metadata?.namespace ?? '', LONGHORN_GROUP)
9
+ const name = data?.metadata?.name
10
+ // A migrating volume has two Engines; Longhorn's current one is spec.active.
11
+ // After a failed refresh the query keeps the last list; don't show a count from it.
12
+ const candidates = engines.error ? [] : engines.data?.filter((e) => e?.spec?.volumeName === name) ?? []
13
+ const active = candidates.filter((e) => e?.spec?.active === true)
14
+ const engine = candidates.length === 1 ? candidates[0] : active.length === 1 ? active[0] : undefined
15
+ const engineUnknown = !!engines.error || (candidates.length > 1 && !engine)
16
+ // Only a complete read proves the volume has no Engine.
17
+ const engineLookedUp = !engines.isLoading && !engines.error && engines.coverage?.status === 'complete'
18
+ // With auth off every namespace is readable, including a deleted one whose
19
+ // history matters most. Otherwise the caller's own namespace list decides;
20
+ // while it or the auth status load, Longhorn's recorded names stay hidden.
21
+ // Capabilities omit authEnabled when it is false, so only /auth/me says "off".
22
+ const authOff = useAuthMe().data?.authEnabled === false
23
+ const readable = useNamespaces().data
24
+ const canReadNamespace = (ns: string) => authOff || !!readable?.some((n) => n.name === ns)
25
+ return (
26
+ <>
27
+ <BaseLonghornVolumeRenderer data={data} engine={engine} engineUnknown={engineUnknown} engineLookedUp={engineLookedUp} canReadNamespace={canReadNamespace} />
28
+ <LookupFailureNote errors={[engines.error]} what="this volume's engine (healthy replicas, rebuilds)" />
29
+ </>
30
+ )
31
+ }
@@ -0,0 +1,22 @@
1
+ import { RIGHTSIZING_SCAN_PATH } from '../../utils/page-links'
2
+ import type { ComponentPropsWithoutRef } from 'react'
3
+ import { Link, useLocation } from 'react-router-dom'
4
+ import { useNavCustomization } from '../../context/NavCustomization'
5
+
6
+ export function RightsizingScanLink(props: Omit<ComponentPropsWithoutRef<'a'>, 'href' | 'onClick' | 'target'>) {
7
+ const { search } = useLocation()
8
+ const { fleetTakeoverHref, onHostNavigate } = useNavCustomization()
9
+ const href = fleetTakeoverHref?.('rightsizing', search)
10
+ if (!href) return <Link {...props} to={{ pathname: RIGHTSIZING_SCAN_PATH, search }} />
11
+ return (
12
+ <a
13
+ {...props}
14
+ href={href}
15
+ onClick={(event) => {
16
+ if (!onHostNavigate || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return
17
+ event.preventDefault()
18
+ onHostNavigate(href)
19
+ }}
20
+ />
21
+ )
22
+ }