@skyhook-io/radar-app 1.20.1 → 1.21.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/package.json +10 -9
- package/src/App.tsx +65 -16
- package/src/api/client.audit-gating.test.tsx +105 -5
- package/src/api/client.auditBadgesSync.test.tsx +118 -0
- package/src/api/client.capabilitiesPoll.test.ts +61 -0
- package/src/api/client.namespaceSwitch.hook.test.tsx +170 -1
- package/src/api/client.pauseDeployment.test.tsx +77 -0
- package/src/api/client.restartError.test.ts +14 -0
- package/src/api/client.revisionRefresh.test.tsx +44 -0
- package/src/api/client.rollbackError.test.ts +14 -0
- package/src/api/client.ts +347 -16
- package/src/api/namespaceScopeRetry.test.ts +14 -0
- package/src/api/networkAttachments.test.tsx +120 -0
- package/src/api/networkAttachments.ts +30 -0
- package/src/api/radarFeatures.test.ts +5 -0
- package/src/api/radarFeatures.ts +10 -0
- package/src/api/secretsStore.test.ts +33 -0
- package/src/api/secretsStore.ts +37 -0
- package/src/api/substrateHealth.ts +134 -0
- package/src/api/velero.test.ts +60 -0
- package/src/api/velero.ts +201 -0
- package/src/api/vulnerabilities.ts +255 -0
- package/src/components/ConnectionErrorView.test.tsx +11 -0
- package/src/components/ConnectionErrorView.tsx +19 -0
- package/src/components/ContextSwitcher.tsx +9 -2
- package/src/components/NamespaceSwitcher.tsx +3 -1
- package/src/components/applications/ApplicationsView.openResource.test.tsx +118 -0
- package/src/components/applications/ApplicationsView.tsx +8 -11
- package/src/components/audit/AuditView.tsx +4 -0
- package/src/components/audit/ChecksViewTabs.test.tsx +33 -5
- package/src/components/audit/ChecksViewTabs.tsx +11 -1
- package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
- package/src/components/audit/UpgradeReadinessView.tsx +60 -2
- package/src/components/audit/VulnerabilitiesView.tsx +907 -0
- package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
- package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
- package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
- package/src/components/cnpg/CNPGView.tsx +43 -117
- package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
- package/src/components/cnpg/host.tsx +2 -2
- package/src/components/cnpg/routes.ts +3 -1
- package/src/components/cnpg/shared.tsx +5 -53
- package/src/components/cnpg/useCNPGNavigate.ts +1 -21
- package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
- package/src/components/community.tsx +42 -0
- package/src/components/cost/CostView.tsx +27 -9
- package/src/components/diagnose/InvestigationView.tsx +12 -3
- package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.test.tsx +52 -0
- package/src/components/diagnose/investigationEvidence/adapters/helm.ts +10 -0
- package/src/components/diagnose/investigationEvidence/bodies/platform.tsx +82 -51
- package/src/components/diagnose/investigationEvidence/types.ts +5 -0
- package/src/components/diagnose/investigationMetrics.test.ts +20 -0
- package/src/components/diagnose/investigationMetrics.ts +2 -1
- package/src/components/dock/BottomDock.tsx +1 -0
- package/src/components/dock/LogsTab.tsx +3 -0
- package/src/components/dock/TerminalPreferences.query.test.tsx +57 -0
- package/src/components/dock/TerminalPreferences.test.tsx +68 -0
- package/src/components/dock/TerminalPreferences.tsx +73 -0
- package/src/components/gitops/GitOpsView.tsx +2 -10
- package/src/components/helm/HelmDrawerFrame.tsx +1 -1
- package/src/components/helm/HelmReleaseDrawer.tsx +24 -12
- package/src/components/helm/HelmView.tsx +25 -19
- package/src/components/helm/NotCheckedBadge.test.tsx +62 -0
- package/src/components/helm/NotCheckedBadge.tsx +39 -0
- package/src/components/helm/OwnedResources.test.tsx +86 -0
- package/src/components/helm/OwnedResources.tsx +69 -11
- package/src/components/home/ClusterHealthCard.heading.test.tsx +72 -0
- package/src/components/home/ClusterHealthCard.test.ts +44 -1
- package/src/components/home/ClusterHealthCard.tsx +25 -11
- package/src/components/home/HelmSummary.tsx +15 -15
- package/src/components/home/HomeAgentBlock.tsx +3 -0
- package/src/components/home/HomeView.tsx +7 -0
- package/src/components/home/MCPSetupDialog.test.tsx +19 -12
- package/src/components/home/MCPSetupDialog.tsx +4 -2
- package/src/components/home/mcpToolCatalog.ts +17 -4
- package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
- package/src/components/home/useVulnerabilitiesRow.ts +50 -0
- package/src/components/logs/LogsViewer.tsx +3 -1
- package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
- package/src/components/logs/MultiPodLogsTab.tsx +9 -5
- package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
- package/src/components/nav/PrimaryNavRail.tsx +174 -29
- package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
- package/src/components/resource/RightsizingStrip.test.ts +57 -0
- package/src/components/resource/RightsizingStrip.tsx +53 -4
- package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
- package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
- package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
- package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
- package/src/components/resources/ImageFilesystemModal.test.tsx +74 -6
- package/src/components/resources/ImageFilesystemModal.tsx +98 -6
- package/src/components/resources/PodFileUploadPanel.tsx +150 -0
- package/src/components/resources/PodFilesystemModal.tsx +246 -3
- package/src/components/resources/ResourcesView.tsx +12 -6
- package/src/components/resources/pod-file-upload.test.tsx +223 -0
- package/src/components/resources/pod-file-upload.ts +266 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.test.tsx +50 -0
- package/src/components/resources/renderers/HTTPRouteRenderer.tsx +27 -0
- package/src/components/resources/renderers/PodRenderer.tsx +26 -1
- package/src/components/resources/renderers/SecretProviderClassRenderer.tsx +25 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
- package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
- package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
- package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
- package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
- package/src/components/rightsizing/RightsizingScanView.tsx +19 -3
- package/src/components/rightsizing/model.test.ts +11 -0
- package/src/components/rightsizing/model.ts +3 -1
- package/src/components/rightsizing/presentation.test.ts +46 -0
- package/src/components/rightsizing/presentation.ts +17 -2
- package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
- package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
- package/src/components/timeline/TimelineView.tsx +3 -1
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
- package/src/components/traffic/TrafficData.test.tsx +37 -0
- package/src/components/traffic/TrafficData.tsx +27 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -7
- package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
- package/src/components/traffic/TrafficGraph.test.tsx +269 -0
- package/src/components/traffic/TrafficGraph.tsx +135 -64
- package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
- package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
- package/src/components/traffic/TrafficView.tsx +72 -155
- package/src/components/traffic/trafficFilters.test.ts +189 -1
- package/src/components/traffic/trafficFilters.ts +169 -1
- package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
- package/src/components/ui/Omnibar.tsx +4 -1
- package/src/components/ui/RadarOmnibar.test.tsx +55 -2
- package/src/components/ui/RadarOmnibar.tsx +7 -1
- package/src/components/ui/SearchSyntaxHelp.test.tsx +9 -2
- package/src/components/ui/SearchSyntaxHelp.tsx +3 -2
- package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
- package/src/components/ui/UpdateNotification.test.tsx +54 -3
- package/src/components/ui/UpdateNotification.tsx +60 -19
- package/src/components/ui/command-items.ts +24 -1
- package/src/components/ui/omnibar-match.test.ts +7 -0
- package/src/components/ui/omnibar-match.ts +1 -0
- package/src/components/ui/searchCoverageNote.test.ts +17 -0
- package/src/components/ui/searchCoverageNote.ts +31 -7
- package/src/components/useContextSwitchFlow.tsx +9 -1
- package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
- package/src/components/velero/VeleroBackupNow.tsx +143 -0
- package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
- package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
- package/src/components/velero/VeleroDetailPage.tsx +148 -0
- package/src/components/velero/VeleroKindLists.test.tsx +48 -0
- package/src/components/velero/VeleroKindLists.tsx +43 -0
- package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
- package/src/components/velero/VeleroLocations.test.tsx +86 -0
- package/src/components/velero/VeleroLocations.tsx +240 -0
- package/src/components/velero/VeleroOverview.test.tsx +311 -0
- package/src/components/velero/VeleroOverview.tsx +485 -0
- package/src/components/velero/VeleroPages.test.tsx +516 -0
- package/src/components/velero/VeleroPages.tsx +1056 -0
- package/src/components/velero/VeleroRunLists.tsx +309 -0
- package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
- package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
- package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
- package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
- package/src/components/velero/VeleroSchedules.tsx +255 -0
- package/src/components/velero/VeleroView.tsx +59 -0
- package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
- package/src/components/velero/attention.test.ts +178 -0
- package/src/components/velero/attention.ts +281 -0
- package/src/components/velero/backupDelete.test.tsx +91 -0
- package/src/components/velero/backupDelete.tsx +182 -0
- package/src/components/velero/coverage.test.ts +87 -0
- package/src/components/velero/coverage.ts +150 -0
- package/src/components/velero/host.tsx +86 -0
- package/src/components/velero/routes.ts +78 -0
- package/src/components/velero/runs.tsx +121 -0
- package/src/components/velero/shared.test.ts +84 -0
- package/src/components/velero/shared.tsx +423 -0
- package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
- package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
- package/src/components/velero/velero.fixtures.ts +61 -0
- package/src/components/velero/workspaceRoute.ts +21 -0
- package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +167 -0
- package/src/components/vulnerabilities/parts.test.ts +72 -0
- package/src/components/vulnerabilities/parts.tsx +291 -0
- package/src/components/workload/NodeCertificateEvidence.test.tsx +51 -0
- package/src/components/workload/NodeCertificateEvidence.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +114 -37
- package/src/components/workspace/DrawerTrailBack.tsx +32 -0
- package/src/components/workspace/WorkspaceFrame.tsx +71 -0
- package/src/components/workspace/coverage.ts +61 -0
- package/src/components/workspace/layout.test.tsx +29 -1
- package/src/components/workspace/layout.tsx +15 -5
- package/src/components/workspace/sidebar.ts +9 -0
- package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
- package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
- package/src/context/ConnectionContext.test.ts +1 -0
- package/src/context/ConnectionContext.tsx +2 -2
- package/src/desktop/AboutDialog.test.ts +12 -0
- package/src/desktop/AboutDialog.tsx +151 -0
- package/src/desktop/WindowsTitleBar.tsx +359 -0
- package/src/desktop/titleBar.test.ts +61 -0
- package/src/desktop/titleBar.ts +45 -0
- package/src/index.css +19 -0
- package/src/integrations/resourceHost.ts +5 -1
- package/src/integrations/resourceHosts.test.tsx +15 -3
- package/src/integrations/resourceHosts.tsx +26 -6
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.test.ts +11 -0
- package/src/integrations/workspaceRoutes.ts +3 -1
- package/src/integrations/workspaceScreens.tsx +2 -0
- package/src/main.tsx +8 -0
- package/src/utils/desktop-zoom.test.ts +53 -0
- package/src/utils/desktop-zoom.ts +30 -0
- package/src/utils/namespacePick.test.ts +87 -0
- package/src/utils/namespacePick.ts +88 -0
- package/src/utils/staleAssetPrompt.test.tsx +76 -0
- package/src/utils/staleAssetPrompt.tsx +32 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { CloudUpload, Gauge, Info } from 'lucide-react'
|
|
2
|
+
import { Badge, Property, PropertyList, Section, Tooltip } from '@skyhook-io/k8s-ui'
|
|
3
|
+
import { formatMetricValue } from '@skyhook-io/k8s-ui/components/charts'
|
|
4
|
+
import { isForbiddenError, usePrometheusStatus } from '../../api/client'
|
|
5
|
+
import { useSubstrateHealth, type SubstrateFact, type SubstrateTarget, type SubstrateVerdict } from '../../api/substrateHealth'
|
|
6
|
+
|
|
7
|
+
const OVERDUE_BANDS: Record<string, string> = {
|
|
8
|
+
under_1m: 'under 1m',
|
|
9
|
+
'1m_to_5m': '1–5m',
|
|
10
|
+
'5m_to_15m': '5–15m',
|
|
11
|
+
over_15m: 'over 15m',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A section at the top of the Overview tab that judges a WorkerPool's
|
|
16
|
+
* capacity, or a Node's snapshot uploads, from the same response as the
|
|
17
|
+
* Metrics tab's charts. A Node is a generic page whose readers may never have
|
|
18
|
+
* heard of Agent Substrate, so the title names it and a sentence says what the
|
|
19
|
+
* state means. Shown only when there is a verdict to read; the charts explain
|
|
20
|
+
* every other state. onOpenMetrics switches to a Metrics tab; without one (the
|
|
21
|
+
* drawer, which shows the charts below), the link scrolls to them.
|
|
22
|
+
*/
|
|
23
|
+
export function SubstrateVerdictLine({ target, onOpenMetrics }: { target: SubstrateTarget; onOpenMetrics?: () => void }) {
|
|
24
|
+
const { data: status } = usePrometheusStatus()
|
|
25
|
+
const connected = status?.connected === true
|
|
26
|
+
const { data, error } = useSubstrateHealth(target, connected && Boolean(target.name))
|
|
27
|
+
// A failed refresh leaves the last answer cached; it must not keep asserting it.
|
|
28
|
+
const verdict: SubstrateVerdict | undefined = !connected || isForbiddenError(error)
|
|
29
|
+
? undefined
|
|
30
|
+
: error
|
|
31
|
+
? { state: 'unknown', reason: `Radar could not read Prometheus: ${error.message}`, facts: [] }
|
|
32
|
+
: data?.status === 'available' ? data.verdict : undefined
|
|
33
|
+
if (!verdict) return null
|
|
34
|
+
const pool = target.kind === 'workerpool'
|
|
35
|
+
const title = pool ? 'Agent Substrate capacity' : 'Agent Substrate snapshots'
|
|
36
|
+
// A pool's only qualifier is a shortfall that could not be judged. On
|
|
37
|
+
// Substrate's default install that is every pool, so it is said in the
|
|
38
|
+
// section, not only in a tooltip.
|
|
39
|
+
const qualifier = verdict.state !== 'unknown' ? verdict.reason : undefined
|
|
40
|
+
// Series Radar could not tie to this cluster.
|
|
41
|
+
const unverified = error ? undefined : data?.charts.find(c => c.state === 'ok' && c.isolation.mode === 'unverified')?.isolation.note
|
|
42
|
+
return (
|
|
43
|
+
<section aria-label={title}>
|
|
44
|
+
<Section title={title} icon={pool ? Gauge : CloudUpload}>
|
|
45
|
+
<div className="space-y-3 text-sm">
|
|
46
|
+
<div className="flex items-start gap-2">
|
|
47
|
+
<span className="shrink-0 pt-px"><VerdictState verdict={verdict} /></span>
|
|
48
|
+
<div className="min-w-0 space-y-1">
|
|
49
|
+
<p className="text-theme-text-secondary">
|
|
50
|
+
{meaning(verdict, pool)}
|
|
51
|
+
{unverified && (
|
|
52
|
+
<Tooltip content={sentence(unverified)}>
|
|
53
|
+
<Info aria-label="Qualified" className="ml-1 inline h-3.5 w-3.5 align-[-2px] text-theme-text-tertiary" />
|
|
54
|
+
</Tooltip>
|
|
55
|
+
)}
|
|
56
|
+
</p>
|
|
57
|
+
{qualifier && <p className="text-xs text-theme-text-tertiary">{sentence(qualifier)}</p>}
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
{verdict.facts.length > 0 && (
|
|
61
|
+
<PropertyList>
|
|
62
|
+
{verdict.facts.map(f => <Fact key={f.id} fact={f} />)}
|
|
63
|
+
</PropertyList>
|
|
64
|
+
)}
|
|
65
|
+
<button type="button" onClick={e => (onOpenMetrics ? onOpenMetrics() : scrollToCharts(e.currentTarget))} className="text-xs text-theme-text-tertiary underline-offset-2 hover:text-theme-text-primary hover:underline">
|
|
66
|
+
View metrics
|
|
67
|
+
</button>
|
|
68
|
+
</div>
|
|
69
|
+
</Section>
|
|
70
|
+
</section>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const sentence = (s: string) => (s.endsWith('.') ? s : `${s}.`)
|
|
75
|
+
|
|
76
|
+
// What the state means, in the reader's terms. Claims only what the count
|
|
77
|
+
// proves: a free slot is not proof the next actor fits, and zero overdue
|
|
78
|
+
// uploads is not proof every snapshot is saved.
|
|
79
|
+
function meaning(verdict: SubstrateVerdict, pool: boolean): string {
|
|
80
|
+
switch (verdict.state) {
|
|
81
|
+
case 'workerShortfall':
|
|
82
|
+
return 'Fewer workers can take actors than the pool wants, and it has stayed that way for five minutes. New and resuming actors may wait or fail to start.'
|
|
83
|
+
case 'noFreeActorSlots':
|
|
84
|
+
return 'No worker in this pool has a free actor slot. Actor starts and resumes may wait or fail until there is capacity.'
|
|
85
|
+
case 'noSchedulableWorkers':
|
|
86
|
+
return 'No worker can take an actor right now.'
|
|
87
|
+
case 'freeActorSlots':
|
|
88
|
+
return 'Some worker has a free actor slot, though an actor that needs more CPU or memory than that worker has left can still fail to start.'
|
|
89
|
+
case 'uploadsOverdue':
|
|
90
|
+
return 'Some actor snapshots on this node are overdue for upload to object storage. Until Substrate confirms them stored, losing this node could lose that snapshot state.'
|
|
91
|
+
case 'noUploadsOverdue':
|
|
92
|
+
return 'No snapshot upload is overdue on this node. Snapshots with no storage destination are not counted.'
|
|
93
|
+
}
|
|
94
|
+
return verdict.reason
|
|
95
|
+
? sentence(verdict.reason)
|
|
96
|
+
: `Radar could not read this ${pool ? "pool's capacity" : "node's snapshot uploads"} from Prometheus.`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function VerdictState({ verdict }: { verdict: SubstrateVerdict }) {
|
|
100
|
+
switch (verdict.state) {
|
|
101
|
+
case 'workerShortfall':
|
|
102
|
+
return <Badge severity="warning" size="sm">Short of workers</Badge>
|
|
103
|
+
case 'uploadsOverdue':
|
|
104
|
+
return <Badge severity="warning" size="sm">Uploads overdue</Badge>
|
|
105
|
+
case 'noFreeActorSlots':
|
|
106
|
+
return <Badge severity="neutral" size="sm">Full</Badge>
|
|
107
|
+
case 'noSchedulableWorkers':
|
|
108
|
+
return <Badge severity="neutral" size="sm">No schedulable workers</Badge>
|
|
109
|
+
case 'freeActorSlots':
|
|
110
|
+
return <Badge severity="neutral" size="sm">Free slots</Badge>
|
|
111
|
+
case 'noUploadsOverdue':
|
|
112
|
+
return <Badge severity="neutral" size="sm">No overdue uploads</Badge>
|
|
113
|
+
}
|
|
114
|
+
return <Badge severity="neutral" size="sm">Unknown</Badge>
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Facts read over the hour the charts cover; the others are now.
|
|
118
|
+
const HOURLY_FACTS = new Set(['resumeP95', 'resumeFailures', 'crashes'])
|
|
119
|
+
|
|
120
|
+
// Resumes carry a pool only once a worker is assigned.
|
|
121
|
+
const POOL_PLACED = 'Resumes of actors placed on this pool. A resume that failed before it got a worker names no pool and is not counted.'
|
|
122
|
+
|
|
123
|
+
// A range summary covers only the time Prometheus collected: a rate stays
|
|
124
|
+
// representative, but a count misses whatever happened during a gap.
|
|
125
|
+
const HOURLY = 'Computed from the data Prometheus holds for the last hour. If collection had a gap, the crash count covers less than the hour.'
|
|
126
|
+
|
|
127
|
+
function Fact({ fact }: { fact: SubstrateFact }) {
|
|
128
|
+
const placed = fact.id === 'resumeP95' || fact.id === 'resumeFailures'
|
|
129
|
+
const hourly = HOURLY_FACTS.has(fact.id)
|
|
130
|
+
const title = [placed && POOL_PLACED, hourly && HOURLY].filter(Boolean).join(' ') || undefined
|
|
131
|
+
return (
|
|
132
|
+
<Property
|
|
133
|
+
label={title ? <Tooltip content={title}><span>{fact.label}{hourly ? ' (1h)' : ''}</span></Tooltip> : <span>{fact.label}</span>}
|
|
134
|
+
value={<span className="tabular-nums"><FactValue fact={fact} /></span>}
|
|
135
|
+
/>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function FactValue({ fact }: { fact: SubstrateFact }) {
|
|
140
|
+
if (fact.state === 'unavailable') {
|
|
141
|
+
return (
|
|
142
|
+
<Tooltip content={fact.reason || 'Radar could not read this from Prometheus'}>
|
|
143
|
+
<span className="text-theme-text-tertiary">Unavailable</span>
|
|
144
|
+
</Tooltip>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
if (fact.state === 'empty') {
|
|
148
|
+
return fact.reason ? <Tooltip content={fact.reason}><span>None</span></Tooltip> : <span>None</span>
|
|
149
|
+
}
|
|
150
|
+
const value = fact.value!
|
|
151
|
+
switch (fact.id) {
|
|
152
|
+
case 'workersWithFreeActorSlots':
|
|
153
|
+
return <span>{count(value)}{fact.of !== undefined ? ` of ${count(fact.of)}` : ''}</span>
|
|
154
|
+
case 'schedulableWorkers':
|
|
155
|
+
return <span>{count(value)}{fact.of !== undefined ? ` of ${count(fact.of)} desired` : ''}</span>
|
|
156
|
+
case 'crashes':
|
|
157
|
+
return <span>{count(value)}</span>
|
|
158
|
+
case 'overdueUploads': {
|
|
159
|
+
const parts = fact.parts?.map(p => `${OVERDUE_BANDS[p.label] ?? p.label}: ${count(p.value)}`)
|
|
160
|
+
return <span>{count(value)}{parts?.length ? ` (${parts.join(', ')})` : ''}</span>
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return <span>{formatMetricValue(value, fact.unit)}</span>
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const CHARTS = 'section[aria-label="Agent Substrate metrics"]'
|
|
167
|
+
|
|
168
|
+
// The nearest charts below this line, not another mounted view's.
|
|
169
|
+
function scrollToCharts(from: HTMLElement) {
|
|
170
|
+
let el: HTMLElement | null = from.parentElement
|
|
171
|
+
while (el && !el.querySelector(CHARTS)) el = el.parentElement
|
|
172
|
+
el?.querySelector(CHARTS)?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Replica averages and extrapolated increases can be fractional; they are
|
|
176
|
+
// shown as approximate, never rounded to a whole count.
|
|
177
|
+
function count(value: number): string {
|
|
178
|
+
if (Number.isInteger(value)) return String(value)
|
|
179
|
+
return `≈${Math.abs(value) < 10 ? value.toFixed(1) : Math.round(value)}`
|
|
180
|
+
}
|
|
@@ -5,17 +5,24 @@ import { afterEach, expect, it, vi } from 'vitest'
|
|
|
5
5
|
import { ImageFilesystemModal } from './ImageFilesystemModal'
|
|
6
6
|
import { ApiError } from '../../api/client'
|
|
7
7
|
|
|
8
|
-
const state = vi.hoisted(() => ({
|
|
8
|
+
const state = vi.hoisted(() => ({
|
|
9
|
+
authEnabled: false,
|
|
10
|
+
showMetadata: false,
|
|
11
|
+
metadataImage: 'gcr.io/project/app:v1',
|
|
12
|
+
errorStatus: 401,
|
|
13
|
+
errorData: { registryType: 'google' } as Record<string, unknown>,
|
|
14
|
+
refetch: (() => {}) as () => void,
|
|
15
|
+
}))
|
|
9
16
|
vi.mock('../../contexts/CapabilitiesContext', () => ({ useIsAuthEnabled: () => state.authEnabled }))
|
|
10
17
|
vi.mock('../../api/client', () => ({
|
|
11
18
|
ApiError: class extends Error {
|
|
12
|
-
status =
|
|
13
|
-
data =
|
|
19
|
+
status = state.errorStatus
|
|
20
|
+
data = state.errorData
|
|
14
21
|
},
|
|
15
22
|
useImageMetadata: () => state.showMetadata ? ({
|
|
16
|
-
data: { image:
|
|
17
|
-
refetch:
|
|
18
|
-
}) : ({ error: new ApiError('Authentication required', 401), refetch:
|
|
23
|
+
data: { image: state.metadataImage, digest: 'sha256:abc', platform: 'linux/amd64', totalSize: 1024, layerCount: 1, authMethod: 'google', cached: false },
|
|
24
|
+
refetch: state.refetch,
|
|
25
|
+
}) : ({ error: new ApiError('Authentication required', 401), refetch: state.refetch }),
|
|
19
26
|
}))
|
|
20
27
|
|
|
21
28
|
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
@@ -24,8 +31,22 @@ let root: ReturnType<typeof createRoot>
|
|
|
24
31
|
afterEach(async () => {
|
|
25
32
|
await act(async () => root.unmount())
|
|
26
33
|
state.showMetadata = false
|
|
34
|
+
state.metadataImage = 'gcr.io/project/app:v1'
|
|
35
|
+
state.errorStatus = 401
|
|
36
|
+
state.errorData = { registryType: 'google' }
|
|
37
|
+
state.refetch = () => {}
|
|
38
|
+
vi.unstubAllGlobals()
|
|
39
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
27
40
|
})
|
|
28
41
|
|
|
42
|
+
async function renderModal(props: { onSwitchToPodFiles?: () => void } = {}) {
|
|
43
|
+
root = createRoot(document.createElement('div'))
|
|
44
|
+
await act(async () => {
|
|
45
|
+
root.render(<ImageFilesystemModal open onClose={() => {}} image="gcr.io/project/app:v1" namespace="team" podName="app" pullSecrets={[]} {...props} />)
|
|
46
|
+
})
|
|
47
|
+
return document.body.textContent || ''
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
it.each([true, false])('shows private-image guidance for authEnabled=%s', async (authEnabled) => {
|
|
30
51
|
state.authEnabled = authEnabled
|
|
31
52
|
root = createRoot(document.createElement('div'))
|
|
@@ -66,3 +87,50 @@ it.each([true, false])('shows download confirmation for authEnabled=%s', async (
|
|
|
66
87
|
expect(text).toContain('gcloud')
|
|
67
88
|
}
|
|
68
89
|
})
|
|
90
|
+
|
|
91
|
+
it.each(['node_only', 'registry_unreachable'])('explains a %s image instead of a generic or sign-in error', async (reason) => {
|
|
92
|
+
state.errorStatus = reason === 'node_only' ? 404 : 502
|
|
93
|
+
state.errorData = { error: 'x', reason, registry: 'registry.example' }
|
|
94
|
+
const refetch = vi.fn()
|
|
95
|
+
state.refetch = refetch
|
|
96
|
+
const text = await renderModal({ onSwitchToPodFiles: () => {} })
|
|
97
|
+
expect(text).toContain('registry.example')
|
|
98
|
+
expect(text).toContain('Browse live files from running pod below')
|
|
99
|
+
expect(text).not.toContain('Failed to inspect image')
|
|
100
|
+
expect(text).not.toContain('Authentication Required')
|
|
101
|
+
const retry = [...document.body.querySelectorAll('button')].find((b) => b.textContent?.includes('Retry'))
|
|
102
|
+
if (reason === 'node_only') {
|
|
103
|
+
expect(retry).toBeUndefined()
|
|
104
|
+
} else {
|
|
105
|
+
await act(async () => retry?.click())
|
|
106
|
+
expect(refetch).toHaveBeenCalledTimes(1)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('keeps the generic error box for an error without a known reason', async () => {
|
|
111
|
+
state.errorStatus = 500
|
|
112
|
+
state.errorData = { error: 'Failed to inspect image' }
|
|
113
|
+
const text = await renderModal()
|
|
114
|
+
expect(text).toContain('Failed to inspect image')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('shows the pulled digest and downloads that exact image, not the tag', async () => {
|
|
118
|
+
const digest = 'sha256:' + 'a'.repeat(64)
|
|
119
|
+
state.showMetadata = true
|
|
120
|
+
state.metadataImage = 'gcr.io/project/app@' + digest
|
|
121
|
+
const fetchMock = vi.fn(async () => new Response(JSON.stringify({ image: state.metadataImage, root: { name: '/', path: '/', type: 'dir' }, totalFiles: 0, totalSize: 0 })))
|
|
122
|
+
vi.stubGlobal('fetch', fetchMock)
|
|
123
|
+
const text = await renderModal()
|
|
124
|
+
expect(text).toContain(digest)
|
|
125
|
+
const download = [...document.body.querySelectorAll('button')].find((b) => b.textContent === 'Download & View')
|
|
126
|
+
await act(async () => download?.click())
|
|
127
|
+
expect(fetchMock).toHaveBeenCalledTimes(1)
|
|
128
|
+
const url = new URL(String((fetchMock.mock.calls[0] as unknown[])[0]), 'http://radar.test')
|
|
129
|
+
expect(url.searchParams.get('image')).toBe(state.metadataImage)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('shows no pulled digest when the server inspects the tag as given', async () => {
|
|
133
|
+
state.showMetadata = true
|
|
134
|
+
const text = await renderModal()
|
|
135
|
+
expect(text).not.toContain('sha256:')
|
|
136
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useRef, useEffect, useMemo, useCallback } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
|
-
import { X, Folder, File, Link2, ChevronRight, ChevronDown, AlertTriangle, Loader2, Search, Download, HardDrive, Shield, ShieldCheck, Terminal, Copy, Check, RefreshCw } from 'lucide-react'
|
|
3
|
+
import { X, Folder, File, Link2, ChevronRight, ChevronDown, AlertTriangle, Loader2, Search, Download, HardDrive, Shield, ShieldCheck, Terminal, Copy, Check, RefreshCw, WifiOff } from 'lucide-react'
|
|
4
4
|
import radarLoadingIcon from '@skyhook-io/k8s-ui/assets/radar/radar-icon-loading.svg'
|
|
5
5
|
import { assetUrl } from '@skyhook-io/k8s-ui'
|
|
6
6
|
import { clsx } from 'clsx'
|
|
@@ -78,6 +78,13 @@ export function ImageFilesystemModal({
|
|
|
78
78
|
// Detect auth errors from metadata fetch
|
|
79
79
|
const isAuthError = metadataError instanceof ApiError && metadataError.status === 401
|
|
80
80
|
const registryType = isAuthError ? (metadataError.data?.registryType as string) : undefined
|
|
81
|
+
const unavailable = metadataError instanceof ApiError ? registryUnavailable(metadataError.data) : undefined
|
|
82
|
+
|
|
83
|
+
// The server may pin a tag to the digest the Pod pulled. Later requests
|
|
84
|
+
// name that exact reference, so the listing and file downloads can't drift
|
|
85
|
+
// to whatever the tag points at by then.
|
|
86
|
+
const inspectImage = metadata?.image || image
|
|
87
|
+
const pulledDigest = inspectImage !== image ? inspectImage.split('@')[1] : undefined
|
|
81
88
|
|
|
82
89
|
// Use cached filesystem from metadata if available
|
|
83
90
|
const displayFilesystem: ImageFilesystem | undefined = metadata?.cached
|
|
@@ -89,14 +96,14 @@ export function ImageFilesystemModal({
|
|
|
89
96
|
setIsLoadingFilesystem(true)
|
|
90
97
|
setFilesystemError(null)
|
|
91
98
|
try {
|
|
92
|
-
const result = await fetchImageFilesystem(
|
|
99
|
+
const result = await fetchImageFilesystem(inspectImage, namespace, podName, pullSecrets)
|
|
93
100
|
setFilesystem(result)
|
|
94
101
|
} catch (err) {
|
|
95
102
|
setFilesystemError(err instanceof Error ? err : new Error('Failed to fetch filesystem'))
|
|
96
103
|
} finally {
|
|
97
104
|
setIsLoadingFilesystem(false)
|
|
98
105
|
}
|
|
99
|
-
}, [
|
|
106
|
+
}, [inspectImage, namespace, podName, pullSecrets])
|
|
100
107
|
|
|
101
108
|
// Reset state when modal closes or image changes
|
|
102
109
|
useEffect(() => {
|
|
@@ -153,6 +160,13 @@ export function ImageFilesystemModal({
|
|
|
153
160
|
{image}
|
|
154
161
|
</p>
|
|
155
162
|
</Tooltip>
|
|
163
|
+
{pulledDigest && (
|
|
164
|
+
<Tooltip content={inspectImage} wrapperClassName="!block w-full">
|
|
165
|
+
<p className="text-xs text-theme-text-tertiary mt-1 truncate">
|
|
166
|
+
Pulled digest: <span className="font-mono">{pulledDigest}</span>
|
|
167
|
+
</p>
|
|
168
|
+
</Tooltip>
|
|
169
|
+
)}
|
|
156
170
|
{(displayFilesystem?.platform || metadata?.platform) && (
|
|
157
171
|
<p className="text-xs text-theme-text-tertiary mt-1">
|
|
158
172
|
Platform: {displayFilesystem?.platform || metadata?.platform}
|
|
@@ -208,8 +222,16 @@ export function ImageFilesystemModal({
|
|
|
208
222
|
/>
|
|
209
223
|
)}
|
|
210
224
|
|
|
211
|
-
{
|
|
212
|
-
|
|
225
|
+
{unavailable && (
|
|
226
|
+
<RegistryUnavailable
|
|
227
|
+
{...unavailable}
|
|
228
|
+
liveFilesLinkShown={Boolean(onSwitchToPodFiles)}
|
|
229
|
+
onRetry={() => refetchMetadata()}
|
|
230
|
+
/>
|
|
231
|
+
)}
|
|
232
|
+
|
|
233
|
+
{/* Other errors keep the existing red error box */}
|
|
234
|
+
{error && !isAuthError && !unavailable && (
|
|
213
235
|
<div className="p-4 bg-red-500/10 border border-red-500/30 rounded-lg">
|
|
214
236
|
<div className="flex items-start gap-3">
|
|
215
237
|
<AlertTriangle className="w-5 h-5 text-red-400 shrink-0 mt-0.5" />
|
|
@@ -237,7 +259,7 @@ export function ImageFilesystemModal({
|
|
|
237
259
|
<FileTreeView
|
|
238
260
|
root={displayFilesystem.root}
|
|
239
261
|
searchQuery={searchQuery}
|
|
240
|
-
image={image}
|
|
262
|
+
image={displayFilesystem.image || inspectImage}
|
|
241
263
|
namespace={namespace}
|
|
242
264
|
podName={podName}
|
|
243
265
|
pullSecrets={pullSecrets}
|
|
@@ -513,6 +535,76 @@ function AuthenticationHelp({ image, registryType, onRetry }: AuthenticationHelp
|
|
|
513
535
|
)
|
|
514
536
|
}
|
|
515
537
|
|
|
538
|
+
// ============================================================================
|
|
539
|
+
// Registry Unavailable Component (image Radar can't download)
|
|
540
|
+
// ============================================================================
|
|
541
|
+
|
|
542
|
+
interface RegistryUnavailableInfo {
|
|
543
|
+
reason: 'node_only' | 'registry_unreachable'
|
|
544
|
+
registry: string
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function registryUnavailable(data: Record<string, unknown> | undefined): RegistryUnavailableInfo | undefined {
|
|
548
|
+
const reason = data?.reason
|
|
549
|
+
const registry = typeof data?.registry === 'string' ? data.registry : ''
|
|
550
|
+
if (reason === 'node_only' || reason === 'registry_unreachable') return { reason, registry }
|
|
551
|
+
return undefined
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
interface RegistryUnavailableProps extends RegistryUnavailableInfo {
|
|
555
|
+
liveFilesLinkShown: boolean
|
|
556
|
+
onRetry: () => void
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function RegistryUnavailable({ reason, registry, liveFilesLinkShown, onRetry }: RegistryUnavailableProps) {
|
|
560
|
+
const liveFiles = liveFilesLinkShown && (
|
|
561
|
+
<p className="text-xs text-theme-text-tertiary text-center max-w-md mb-2">
|
|
562
|
+
To see the files now, use Browse live files from running pod below.
|
|
563
|
+
</p>
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
if (reason === 'node_only') {
|
|
567
|
+
return (
|
|
568
|
+
<div className="flex flex-col items-center justify-center py-8">
|
|
569
|
+
<HardDrive className="w-16 h-16 text-amber-400 mb-4" />
|
|
570
|
+
<h4 className="text-lg font-medium text-theme-text-primary mb-2">
|
|
571
|
+
This image was added to the node, not pulled
|
|
572
|
+
</h4>
|
|
573
|
+
<p className="text-sm text-theme-text-secondary text-center max-w-md mb-2">
|
|
574
|
+
The node didn't pull this image from a registry. It was added to the node directly, for example with <span className="font-mono">kind load</span> or <span className="font-mono">ctr images import</span>. Radar can only open images it downloads from a registry, and it couldn't get this one from <span className="inline-code">{registry}</span>.
|
|
575
|
+
</p>
|
|
576
|
+
<p className="text-xs text-theme-text-tertiary text-center max-w-md mb-2">
|
|
577
|
+
To browse it here, push the image to a registry Radar can reach and run the Pod from there.
|
|
578
|
+
</p>
|
|
579
|
+
{liveFiles}
|
|
580
|
+
</div>
|
|
581
|
+
)
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
return (
|
|
585
|
+
<div className="flex flex-col items-center justify-center py-8">
|
|
586
|
+
<WifiOff className="w-16 h-16 text-amber-400 mb-4" />
|
|
587
|
+
<h4 className="text-lg font-medium text-theme-text-primary mb-2">
|
|
588
|
+
Radar can't reach this image's registry
|
|
589
|
+
</h4>
|
|
590
|
+
<p className="text-sm text-theme-text-secondary text-center max-w-md mb-2">
|
|
591
|
+
The connection failed while fetching this image from <span className="inline-code">{registry}</span>. If your nodes pull images through a mirror or an internal copy of this registry, Radar doesn't use it, so it can't open this image.
|
|
592
|
+
</p>
|
|
593
|
+
<p className="text-xs text-theme-text-tertiary text-center max-w-md mb-2">
|
|
594
|
+
If <span className="inline-code">{registry}</span> should be reachable from where Radar runs, check the connection and retry.
|
|
595
|
+
</p>
|
|
596
|
+
{liveFiles}
|
|
597
|
+
<button
|
|
598
|
+
onClick={onRetry}
|
|
599
|
+
className="flex items-center gap-2 px-4 py-2 mt-4 text-sm btn-brand rounded-lg"
|
|
600
|
+
>
|
|
601
|
+
<RefreshCw className="w-4 h-4" />
|
|
602
|
+
Retry
|
|
603
|
+
</button>
|
|
604
|
+
</div>
|
|
605
|
+
)
|
|
606
|
+
}
|
|
607
|
+
|
|
516
608
|
function formatAuthMethod(method: string): string {
|
|
517
609
|
switch (method) {
|
|
518
610
|
case 'google': return 'Google Cloud'
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Link } from 'react-router-dom'
|
|
2
|
+
import { Upload, Loader2 } from 'lucide-react'
|
|
3
|
+
import { AlertBanner } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { formatBytes } from '../../utils/format'
|
|
5
|
+
import { resourcePath } from '../../utils/navigation'
|
|
6
|
+
import { Tooltip } from '../ui/Tooltip'
|
|
7
|
+
import { POD_FILE_PERSISTENCE_NOTE, type MountHint } from './pod-file-upload'
|
|
8
|
+
|
|
9
|
+
export type UploadState =
|
|
10
|
+
| { phase: 'idle' }
|
|
11
|
+
| { phase: 'confirm'; name: string; dir: string; size: number }
|
|
12
|
+
| { phase: 'uploading'; name: string; dir: string; sent: number; total: number }
|
|
13
|
+
| { phase: 'saving'; name: string; dir: string }
|
|
14
|
+
| { phase: 'saved'; path: string; replaced: boolean }
|
|
15
|
+
| { phase: 'error'; name: string; message: string }
|
|
16
|
+
|
|
17
|
+
export function isUploadBusy(state: UploadState): boolean {
|
|
18
|
+
return state.phase === 'uploading' || state.phase === 'saving' || state.phase === 'confirm'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface UploadButtonProps {
|
|
22
|
+
blocked: MountHint | null
|
|
23
|
+
busy: boolean
|
|
24
|
+
/** The listing for the selected container is still loading. */
|
|
25
|
+
loading?: boolean
|
|
26
|
+
onClick: () => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function PodFileUploadButton({ blocked, busy, loading = false, onClick }: UploadButtonProps) {
|
|
30
|
+
const disabled = busy || loading || blocked !== null
|
|
31
|
+
const tip = blocked ? blocked.reason
|
|
32
|
+
: busy ? 'An upload is in progress'
|
|
33
|
+
: loading ? 'Loading the listing…'
|
|
34
|
+
: 'Upload a file into this directory (or drop one on the list)'
|
|
35
|
+
return (
|
|
36
|
+
<Tooltip content={tip}>
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
onClick={onClick}
|
|
40
|
+
disabled={disabled}
|
|
41
|
+
aria-disabled={disabled}
|
|
42
|
+
className="btn-brand inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium mr-2 disabled:opacity-50 disabled:pointer-events-none"
|
|
43
|
+
>
|
|
44
|
+
<Upload className="w-4 h-4" />
|
|
45
|
+
Upload
|
|
46
|
+
</button>
|
|
47
|
+
</Tooltip>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface UploadNoticesProps {
|
|
52
|
+
namespace: string
|
|
53
|
+
blocked: MountHint | null
|
|
54
|
+
onNavigateAway: () => void
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The persistence note, plus why uploads are off here when the pod spec says so. */
|
|
58
|
+
export function PodFileUploadNotices({ namespace, blocked, onNavigateAway }: UploadNoticesProps) {
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<AlertBanner variant="info" title="Uploads change the live container" message={POD_FILE_PERSISTENCE_NOTE} className="mb-3" />
|
|
62
|
+
{blocked && (
|
|
63
|
+
<AlertBanner
|
|
64
|
+
variant="warning"
|
|
65
|
+
title="Uploads are off in this directory"
|
|
66
|
+
message={blocked.reason}
|
|
67
|
+
className="mb-3"
|
|
68
|
+
action={blocked.source ? (
|
|
69
|
+
<Link
|
|
70
|
+
to={resourcePath({ kind: blocked.source.kind, namespace, name: blocked.source.name })}
|
|
71
|
+
onClick={onNavigateAway}
|
|
72
|
+
className="text-xs text-accent hover:underline"
|
|
73
|
+
>
|
|
74
|
+
Open {blocked.source.kind} {blocked.source.name}
|
|
75
|
+
</Link>
|
|
76
|
+
) : undefined}
|
|
77
|
+
/>
|
|
78
|
+
)}
|
|
79
|
+
</>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface UploadStatusProps {
|
|
84
|
+
state: UploadState
|
|
85
|
+
onConfirmReplace: () => void
|
|
86
|
+
onCancel: () => void
|
|
87
|
+
onDismiss: () => void
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function PodFileUploadStatus({ state, onConfirmReplace, onCancel, onDismiss }: UploadStatusProps) {
|
|
91
|
+
switch (state.phase) {
|
|
92
|
+
case 'idle':
|
|
93
|
+
return null
|
|
94
|
+
case 'confirm':
|
|
95
|
+
return (
|
|
96
|
+
<AlertBanner
|
|
97
|
+
variant="warning"
|
|
98
|
+
title={`Replace ${state.name}?`}
|
|
99
|
+
message={`${state.dir === '/' ? '' : state.dir}/${state.name} already exists. Uploading ${formatBytes(state.size)} replaces it in the running container; its owner and permissions are kept, but not ACLs or extended attributes.`}
|
|
100
|
+
className="mb-3"
|
|
101
|
+
>
|
|
102
|
+
<div className="flex gap-2 mt-2">
|
|
103
|
+
<button type="button" onClick={onConfirmReplace} className="btn-brand px-3 py-1 text-xs font-medium">Replace</button>
|
|
104
|
+
<button type="button" onClick={onCancel} className="px-3 py-1 text-xs rounded border border-theme-border text-theme-text-secondary hover:bg-theme-hover">Cancel</button>
|
|
105
|
+
</div>
|
|
106
|
+
</AlertBanner>
|
|
107
|
+
)
|
|
108
|
+
case 'uploading': {
|
|
109
|
+
const pct = state.total > 0 ? Math.min(100, Math.round((state.sent / state.total) * 100)) : 0
|
|
110
|
+
return (
|
|
111
|
+
<div className="mb-3 p-3 border border-theme-border rounded-lg bg-theme-surface" role="status">
|
|
112
|
+
<div className="flex items-center justify-between gap-3 text-sm">
|
|
113
|
+
<span className="min-w-0 truncate text-theme-text-primary">Uploading {state.name}</span>
|
|
114
|
+
<span className="shrink-0 text-xs text-theme-text-tertiary">{formatBytes(state.sent)} of {formatBytes(state.total)}</span>
|
|
115
|
+
<button type="button" onClick={onCancel} className="shrink-0 px-2 py-0.5 text-xs rounded border border-theme-border text-theme-text-secondary hover:bg-theme-hover">Cancel</button>
|
|
116
|
+
</div>
|
|
117
|
+
<div className="mt-2 h-1.5 rounded bg-theme-elevated overflow-hidden" role="progressbar" aria-valuemin={0} aria-valuemax={100} aria-valuenow={pct}>
|
|
118
|
+
<div className="h-full bg-accent" style={{ width: `${pct}%` }} />
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
case 'saving':
|
|
124
|
+
return (
|
|
125
|
+
<div className="mb-3 p-3 border border-theme-border rounded-lg bg-theme-surface flex items-center gap-2 text-sm text-theme-text-primary" role="status">
|
|
126
|
+
<Loader2 className="w-4 h-4 animate-spin shrink-0" />
|
|
127
|
+
<span className="truncate">Saving {state.name} in the container…</span>
|
|
128
|
+
</div>
|
|
129
|
+
)
|
|
130
|
+
case 'saved':
|
|
131
|
+
return (
|
|
132
|
+
<AlertBanner
|
|
133
|
+
variant="success"
|
|
134
|
+
title={state.replaced ? `Replaced ${state.path}` : `Saved ${state.path}`}
|
|
135
|
+
className="mb-3"
|
|
136
|
+
action={<button type="button" onClick={onDismiss} className="text-xs text-theme-text-secondary hover:underline">Dismiss</button>}
|
|
137
|
+
/>
|
|
138
|
+
)
|
|
139
|
+
case 'error':
|
|
140
|
+
return (
|
|
141
|
+
<AlertBanner
|
|
142
|
+
variant="error"
|
|
143
|
+
title={`Could not upload ${state.name}`}
|
|
144
|
+
message={state.message}
|
|
145
|
+
className="mb-3"
|
|
146
|
+
action={<button type="button" onClick={onDismiss} className="text-xs text-theme-text-secondary hover:underline">Dismiss</button>}
|
|
147
|
+
/>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
}
|