@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,61 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { RESIZE_EDGE_PX, isDoublePress, looksMaximised, mnemonicMenuIndex, resizeEdgeAt } from './titleBar'
|
|
4
|
+
|
|
5
|
+
describe('resizeEdgeAt', () => {
|
|
6
|
+
const W = 1000
|
|
7
|
+
const H = 800
|
|
8
|
+
it('names edges and corners within the resize band', () => {
|
|
9
|
+
expect(resizeEdgeAt(0, 0, W, H, false)).toBe('nw-resize')
|
|
10
|
+
expect(resizeEdgeAt(W - 1, 0, W, H, false)).toBe('ne-resize')
|
|
11
|
+
expect(resizeEdgeAt(0, H - 1, W, H, false)).toBe('sw-resize')
|
|
12
|
+
expect(resizeEdgeAt(W - 1, H - 1, W, H, false)).toBe('se-resize')
|
|
13
|
+
expect(resizeEdgeAt(500, 2, W, H, false)).toBe('n-resize')
|
|
14
|
+
expect(resizeEdgeAt(500, H - 2, W, H, false)).toBe('s-resize')
|
|
15
|
+
expect(resizeEdgeAt(2, 400, W, H, false)).toBe('w-resize')
|
|
16
|
+
expect(resizeEdgeAt(W - 2, 400, W, H, false)).toBe('e-resize')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('is null inside the window and whenever the window is maximised', () => {
|
|
20
|
+
expect(resizeEdgeAt(RESIZE_EDGE_PX, 400, W, H, false)).toBeNull()
|
|
21
|
+
expect(resizeEdgeAt(500, 400, W, H, false)).toBeNull()
|
|
22
|
+
expect(resizeEdgeAt(0, 0, W, H, true)).toBeNull()
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
describe('mnemonicMenuIndex', () => {
|
|
27
|
+
const menus = ['File', 'Edit', 'View', 'Help'].map((label) => ({ label, items: [] }))
|
|
28
|
+
const ev = (key: string, mods: Partial<KeyboardEvent> = {}) =>
|
|
29
|
+
({ key, altKey: true, ctrlKey: false, metaKey: false, shiftKey: false, ...mods }) as KeyboardEvent
|
|
30
|
+
|
|
31
|
+
it('maps Alt+first letter to the menu, in either case', () => {
|
|
32
|
+
expect(mnemonicMenuIndex(menus, ev('f'))).toBe(0)
|
|
33
|
+
expect(mnemonicMenuIndex(menus, ev('E'))).toBe(1)
|
|
34
|
+
expect(mnemonicMenuIndex(menus, ev('v'))).toBe(2)
|
|
35
|
+
expect(mnemonicMenuIndex(menus, ev('h'))).toBe(3)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('ignores other letters, plain keys and other modifiers', () => {
|
|
39
|
+
expect(mnemonicMenuIndex(menus, ev('x'))).toBe(-1)
|
|
40
|
+
expect(mnemonicMenuIndex(menus, ev('f', { altKey: false }))).toBe(-1)
|
|
41
|
+
expect(mnemonicMenuIndex(menus, ev('f', { ctrlKey: true }))).toBe(-1)
|
|
42
|
+
expect(mnemonicMenuIndex(menus, ev('f', { shiftKey: true }))).toBe(-1)
|
|
43
|
+
expect(mnemonicMenuIndex(menus, ev('ArrowDown'))).toBe(-1)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('isDoublePress', () => {
|
|
48
|
+
it('needs both a short gap and almost no movement', () => {
|
|
49
|
+
const first = { t: 1000, x: 100, y: 10 }
|
|
50
|
+
expect(isDoublePress(first, { t: 1300, x: 101, y: 11 })).toBe(true)
|
|
51
|
+
expect(isDoublePress(first, { t: 1600, x: 100, y: 10 })).toBe(false)
|
|
52
|
+
expect(isDoublePress(first, { t: 1100, x: 140, y: 10 })).toBe(false)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('looksMaximised', () => {
|
|
57
|
+
it('compares the window with the work area', () => {
|
|
58
|
+
expect(looksMaximised(1920, 1040, 1920, 1040)).toBe(true)
|
|
59
|
+
expect(looksMaximised(1440, 900, 1920, 1040)).toBe(false)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Pure helpers for the Windows desktop title bar (WindowsTitleBar.tsx).
|
|
2
|
+
|
|
3
|
+
export type TitleBarItem = { label?: string; shortcut?: string; separator?: boolean }
|
|
4
|
+
export type TitleBarMenu = { label: string; items: TitleBarItem[] }
|
|
5
|
+
export type TitleBarState = { title: string; menus: TitleBarMenu[] }
|
|
6
|
+
|
|
7
|
+
export const RESIZE_EDGE_PX = 6
|
|
8
|
+
|
|
9
|
+
/** Edge names are the cursor values Wails maps to resize hit-tests ("resize:<edge>"). */
|
|
10
|
+
export function resizeEdgeAt(x: number, y: number, width: number, height: number, maximised: boolean): string | null {
|
|
11
|
+
if (maximised) return null
|
|
12
|
+
const top = y < RESIZE_EDGE_PX
|
|
13
|
+
const bottom = y >= height - RESIZE_EDGE_PX
|
|
14
|
+
const left = x < RESIZE_EDGE_PX
|
|
15
|
+
const right = x >= width - RESIZE_EDGE_PX
|
|
16
|
+
if (top && left) return 'nw-resize'
|
|
17
|
+
if (top && right) return 'ne-resize'
|
|
18
|
+
if (bottom && left) return 'sw-resize'
|
|
19
|
+
if (bottom && right) return 'se-resize'
|
|
20
|
+
if (top) return 'n-resize'
|
|
21
|
+
if (bottom) return 's-resize'
|
|
22
|
+
if (left) return 'w-resize'
|
|
23
|
+
if (right) return 'e-resize'
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Alt+<first letter> opens that menu, as in native Windows menu bars. */
|
|
28
|
+
export function mnemonicMenuIndex(menus: TitleBarMenu[], e: Pick<KeyboardEvent, 'key' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'>): number {
|
|
29
|
+
if (!e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || e.key.length !== 1) return -1
|
|
30
|
+
const k = e.key.toLowerCase()
|
|
31
|
+
return menus.findIndex((m) => m.label.charAt(0).toLowerCase() === k)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type Press = { t: number; x: number; y: number }
|
|
35
|
+
|
|
36
|
+
/** The native move loop swallows the browser's click sequence, so a double
|
|
37
|
+
* click on the drag area is detected by time and distance instead. */
|
|
38
|
+
export function isDoublePress(prev: Press, next: Press, windowMs = 500, slopPx = 4): boolean {
|
|
39
|
+
return next.t - prev.t < windowMs && Math.abs(next.x - prev.x) < slopPx && Math.abs(next.y - prev.y) < slopPx
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A frameless window maximised by Windows fills the monitor's work area. */
|
|
43
|
+
export function looksMaximised(outerWidth: number, outerHeight: number, availWidth: number, availHeight: number): boolean {
|
|
44
|
+
return outerWidth >= availWidth - 1 && outerHeight >= availHeight - 1
|
|
45
|
+
}
|
package/src/index.css
CHANGED
|
@@ -146,6 +146,25 @@ body {
|
|
|
146
146
|
flex-direction: column;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
/* The Windows desktop app draws its own title bar above the app shell
|
|
150
|
+
(desktop/WindowsTitleBar.tsx); the shell gives up that height. */
|
|
151
|
+
html.radar-custom-titlebar body {
|
|
152
|
+
overflow: hidden;
|
|
153
|
+
}
|
|
154
|
+
html.radar-custom-titlebar #radar {
|
|
155
|
+
margin-top: var(--radar-titlebar-h);
|
|
156
|
+
height: calc(100vh - var(--radar-titlebar-h));
|
|
157
|
+
}
|
|
158
|
+
html.radar-custom-titlebar #radar .h-screen {
|
|
159
|
+
height: calc(100vh - var(--radar-titlebar-h));
|
|
160
|
+
}
|
|
161
|
+
/* Full-window overlays (dialogs, fullscreen views) start below the title bar
|
|
162
|
+
so their own top controls stay reachable. */
|
|
163
|
+
html.radar-custom-titlebar .fixed.inset-0:not([data-radar-titlebar]),
|
|
164
|
+
html.radar-custom-titlebar .fixed.top-0:not([data-radar-titlebar]) {
|
|
165
|
+
top: var(--radar-titlebar-h);
|
|
166
|
+
}
|
|
167
|
+
|
|
149
168
|
/* ============================================
|
|
150
169
|
REACT FLOW CUSTOMIZATIONS
|
|
151
170
|
============================================ */
|
|
@@ -15,7 +15,7 @@ export interface KindListProps {
|
|
|
15
15
|
inspected: SelectedResource | null
|
|
16
16
|
onInspect: (resource: SelectedResource) => void
|
|
17
17
|
onClearNamespaces: () => void
|
|
18
|
-
onCreate: (kind: HostKind) => void
|
|
18
|
+
onCreate: (kind: HostKind, initialYaml?: string) => void
|
|
19
19
|
}
|
|
20
20
|
type ExclusiveDetailSlot = 'summary' | 'destination' | 'logs'
|
|
21
21
|
export interface ResourceHost {
|
|
@@ -27,12 +27,16 @@ export interface ResourceHost {
|
|
|
27
27
|
title: string
|
|
28
28
|
mode: (support: RadarFeatureSupport, pending: boolean) => KindListMode
|
|
29
29
|
Component: ComponentType<KindListProps>
|
|
30
|
+
/** Set when the list ignores the namespace filter: the header's picker is disabled with this tooltip while the list shows. */
|
|
31
|
+
namespaceFilterTooltip?: string
|
|
30
32
|
}[]
|
|
31
33
|
renderers?: RendererOverrides
|
|
32
34
|
resources?: readonly { name: string; group: string }[]
|
|
33
35
|
expandedPath?: (resource: HostResource, context?: string, tab?: 'yaml') => string | null
|
|
34
36
|
detailRedirect?: (resource: HostResource, search: URLSearchParams) => string | null
|
|
35
37
|
detailSlots?: (resource: HostResource) => DetailSlots
|
|
38
|
+
/** More for one of the resource's issues, inside that issue's "What's wrong" in the drawer. */
|
|
39
|
+
issueDetail?: (props: { issue: { kind?: string; reason?: string }; resource: any }) => ReactNode
|
|
36
40
|
detailOwnership?: readonly ExclusiveDetailSlot[]
|
|
37
41
|
logs?: (resource: HostResource, data: { apiVersion?: string } | null | undefined) => ReactNode
|
|
38
42
|
drawerNavigation?: {
|
|
@@ -6,7 +6,7 @@ import { ResourceRendererDispatch } from '@skyhook-io/k8s-ui'
|
|
|
6
6
|
import { encodeDrawerTrail } from '../utils/drawer-trail'
|
|
7
7
|
import { kindToPluralWithGroup } from '../utils/navigation'
|
|
8
8
|
import {
|
|
9
|
-
decorateResourceDiagnose, renderResourceKindList, resourceKindListMode, resourceKindListTitle, ResourceDrawerNavigation,
|
|
9
|
+
decorateResourceDiagnose, renderResourceKindList, resourceKindListMode, resourceKindListNamespaceFilterTooltip, resourceKindListTitle, ResourceDrawerNavigation,
|
|
10
10
|
resourceDetailRedirect, resourceDetailSlots, resourceExpandedPath,
|
|
11
11
|
resourceLogs, resourceRendererOverrides, resourceHosts,
|
|
12
12
|
} from './resourceHosts'
|
|
@@ -51,11 +51,11 @@ describe('application resource hosts', () => {
|
|
|
51
51
|
'CustomResourceDefinitionRenderer', 'RayJobRenderer', 'JobRenderer', 'JobSetRenderer', 'RayServiceRenderer', 'RayClusterRenderer',
|
|
52
52
|
'KueueWorkloadRenderer', 'LocalQueueRenderer', 'ClusterQueueRenderer', 'CAPIClusterRenderer', 'PodRenderer', 'KarpenterNodePoolRenderer',
|
|
53
53
|
'NodeRenderer', 'ServiceRenderer', 'WorkloadRenderer', 'CompositeRenderer', 'ServiceAccountRenderer',
|
|
54
|
-
'RoleRenderer', 'RoleBindingRenderer', 'NamespaceRenderer', 'HPARenderer', 'PVCRenderer',
|
|
54
|
+
'RoleRenderer', 'RoleBindingRenderer', 'NamespaceRenderer', 'HPARenderer', 'PVCRenderer', 'HTTPRouteRenderer',
|
|
55
55
|
'RolloutRenderer', 'KyvernoPolicyCoverage', 'KyvernoPolicyQueued', 'CNPGObjectStoreRenderer',
|
|
56
56
|
'VeleroBSLRenderer', 'VeleroBackupRenderer', 'VeleroRestoreRenderer', 'CNPGClusterRenderer',
|
|
57
57
|
'CNPGDatabaseRenderer', 'CNPGPublicationRenderer', 'CNPGSubscriptionRenderer', 'CNPGImageCatalogRenderer',
|
|
58
|
-
'FluxHelmReleaseRenderer', 'OpenTelemetryCollectorRenderer', 'ValidatingAdmissionPolicyRenderer', 'ValidatingAdmissionPolicyBindingRenderer',
|
|
58
|
+
'FluxHelmReleaseRenderer', 'OpenTelemetryCollectorRenderer', 'ValidatingAdmissionPolicyRenderer', 'ValidatingAdmissionPolicyBindingRenderer', 'SecretProviderClassRenderer', 'UpgradePlanRenderer',
|
|
59
59
|
].sort())
|
|
60
60
|
const inherited = [{ id: 'local', label: 'Local', render: () => null }]
|
|
61
61
|
expect(resourceDetailSlots({ kind: 'Pod', group: '', namespace: 'db', name: 'pg-1' }, inherited).extraTabs).toEqual(inherited)
|
|
@@ -135,6 +135,18 @@ describe('application resource hosts', () => {
|
|
|
135
135
|
expect(resourceKindListTitle(cnpgKind)).toBe('CloudNativePG Clusters')
|
|
136
136
|
})
|
|
137
137
|
|
|
138
|
+
it('disables the namespace filter only while a list that ignores it is on screen', () => {
|
|
139
|
+
for (const name of ['backups', 'restores', 'schedules', 'backupstoragelocations']) {
|
|
140
|
+
const kind = { name, group: 'velero.io' }
|
|
141
|
+
expect(resourceKindListNamespaceFilterTooltip(kind, { veleroWorkspace: 'supported' }, false)).toContain('namespace filter doesn’t apply')
|
|
142
|
+
// The generic table that an older Radar shows does honour the filter.
|
|
143
|
+
expect(resourceKindListNamespaceFilterTooltip(kind, { veleroWorkspace: 'unsupported' }, false)).toBeUndefined()
|
|
144
|
+
expect(resourceKindListNamespaceFilterTooltip(kind, { veleroWorkspace: 'unknown' }, false)).toBeUndefined()
|
|
145
|
+
}
|
|
146
|
+
expect(resourceKindListNamespaceFilterTooltip({ name: 'deletebackuprequests', group: 'velero.io' }, { veleroWorkspace: 'supported' }, false)).toBeUndefined()
|
|
147
|
+
expect(resourceKindListNamespaceFilterTooltip(cnpgKind, supported, false)).toBeUndefined()
|
|
148
|
+
})
|
|
149
|
+
|
|
138
150
|
it('decorates Diagnose only for the integration-owned resource context', () => {
|
|
139
151
|
const render = vi.fn(() => <span>diagnose</span>)
|
|
140
152
|
const decorated = decorateResourceDiagnose(render)!
|
|
@@ -6,6 +6,7 @@ import type { RenderDiagnoseAction } from '../context/DiagnoseCustomization'
|
|
|
6
6
|
import { apiVersionToGroup } from '../utils/navigation'
|
|
7
7
|
import type { SelectedResource } from '../types'
|
|
8
8
|
import { cnpgResourceHost } from '../components/cnpg/host'
|
|
9
|
+
import { veleroResourceHost } from '../components/velero/host'
|
|
9
10
|
import { crdResourceHost } from '../components/resources/crd/host'
|
|
10
11
|
import {
|
|
11
12
|
composeDetailSlots, composeResourceHosts, hostsForResource, hostSupport, resourceHostForSlot,
|
|
@@ -32,13 +33,13 @@ import { NamespaceRenderer } from '../components/resources/renderers/NamespaceRe
|
|
|
32
33
|
import { CAPIClusterRenderer } from '../components/resources/renderers/CAPIClusterRenderer'
|
|
33
34
|
import { HPARenderer } from '../components/resources/renderers/HPARenderer'
|
|
34
35
|
import { PVCRenderer } from '../components/resources/renderers/PVCRenderer'
|
|
36
|
+
import { HTTPRouteRenderer } from '../components/resources/renderers/HTTPRouteRenderer'
|
|
35
37
|
import { RolloutRenderer } from '../components/resources/renderers/RolloutRenderer'
|
|
36
38
|
import { KyvernoPolicyCoverage } from '../components/resources/renderers/KyvernoPolicyCoverage'
|
|
37
39
|
import { KyvernoPolicyQueued } from '../components/resources/renderers/KyvernoPolicyQueued'
|
|
38
|
-
import { VeleroBSLRenderer } from '../components/resources/renderers/VeleroBSLRenderer'
|
|
39
|
-
import { VeleroBackupRenderer } from '../components/resources/renderers/VeleroBackupRenderer'
|
|
40
|
-
import { VeleroRestoreRenderer } from '../components/resources/renderers/VeleroRestoreRenderer'
|
|
41
40
|
import { FluxHelmReleaseRenderer } from '../components/resources/renderers/FluxHelmReleaseRenderer'
|
|
41
|
+
import { SecretProviderClassRenderer } from '../components/resources/renderers/SecretProviderClassRenderer'
|
|
42
|
+
import { UpgradePlanRenderer } from '../components/resources/renderers/UpgradePlanRenderer'
|
|
42
43
|
import {
|
|
43
44
|
ValidatingAdmissionPolicyBindingRenderer,
|
|
44
45
|
ValidatingAdmissionPolicyRenderer,
|
|
@@ -46,7 +47,9 @@ import {
|
|
|
46
47
|
|
|
47
48
|
export const resourceHosts: readonly ResourceHost[] = [
|
|
48
49
|
{ id: 'kubernetes', renderers: { PodRenderer, NodeRenderer, ServiceRenderer, WorkloadRenderer, HPARenderer, PVCRenderer } },
|
|
50
|
+
{ id: 'gateway-api', renderers: { HTTPRouteRenderer } },
|
|
49
51
|
{ id: 'rbac', renderers: { ServiceAccountRenderer, RoleRenderer, RoleBindingRenderer, NamespaceRenderer } },
|
|
52
|
+
{ id: 'system-upgrade', renderers: { UpgradePlanRenderer } },
|
|
50
53
|
{ id: 'batch-and-admission', renderers: { JobRenderer, JobSetRenderer, KueueWorkloadRenderer } },
|
|
51
54
|
{
|
|
52
55
|
id: 'kueue-queues',
|
|
@@ -62,8 +65,9 @@ export const resourceHosts: readonly ResourceHost[] = [
|
|
|
62
65
|
{ id: 'crossplane', renderers: { CompositeRenderer } },
|
|
63
66
|
{ id: 'rollouts', renderers: { RolloutRenderer } },
|
|
64
67
|
{ id: 'kyverno', renderers: { KyvernoPolicyCoverage, KyvernoPolicyQueued } },
|
|
65
|
-
|
|
68
|
+
veleroResourceHost,
|
|
66
69
|
{ id: 'flux', renderers: { FluxHelmReleaseRenderer } },
|
|
70
|
+
{ id: 'secrets-store-csi', renderers: { SecretProviderClassRenderer } },
|
|
67
71
|
{ id: 'admission-policy', renderers: { ValidatingAdmissionPolicyRenderer, ValidatingAdmissionPolicyBindingRenderer } },
|
|
68
72
|
cnpgResourceHost,
|
|
69
73
|
crdResourceHost,
|
|
@@ -79,6 +83,14 @@ export function resourceDetailRedirect(resource: HostResource, search: URLSearch
|
|
|
79
83
|
return resourceHostForSlot(resourceHosts, resource, 'destination')?.detailRedirect?.(resource, search) ?? null
|
|
80
84
|
}
|
|
81
85
|
|
|
86
|
+
export function resourceIssueDetail(resource: HostResource, props: { issue: { kind?: string; reason?: string }; resource: any }) {
|
|
87
|
+
for (const host of hostsForResource(resourceHosts, resource)) {
|
|
88
|
+
const detail = host.issueDetail?.(props)
|
|
89
|
+
if (detail) return detail
|
|
90
|
+
}
|
|
91
|
+
return null
|
|
92
|
+
}
|
|
93
|
+
|
|
82
94
|
export function resourceDetailSlots(resource: HostResource, inheritedTabs?: WorkloadExtraTab[]): DetailSlots {
|
|
83
95
|
const slots = hostsForResource(resourceHosts, resource)
|
|
84
96
|
.map(host => ({ id: host.id, slots: host.detailSlots?.(resource) }))
|
|
@@ -103,8 +115,9 @@ export function ResourceDrawerNavigation({ resource }: { resource: SelectedResou
|
|
|
103
115
|
|
|
104
116
|
export function useResourceHostFeatures(): HostFeatures {
|
|
105
117
|
// Hook order is fixed here; selected adapters mount components that own their data hooks.
|
|
106
|
-
const { support } = useRadarFeature('cnpgWorkspace')
|
|
107
|
-
|
|
118
|
+
const { support: cnpgWorkspace } = useRadarFeature('cnpgWorkspace')
|
|
119
|
+
const { support: veleroWorkspace } = useRadarFeature('veleroWorkspace')
|
|
120
|
+
return useMemo(() => ({ cnpgWorkspace, veleroWorkspace }), [cnpgWorkspace, veleroWorkspace])
|
|
108
121
|
}
|
|
109
122
|
|
|
110
123
|
|
|
@@ -123,6 +136,13 @@ export function resourceKindListMode(kind: Pick<HostKind, 'name' | 'group'> | nu
|
|
|
123
136
|
return contribution?.list.mode(hostSupport(contribution.host, features), pending) ?? 'table'
|
|
124
137
|
}
|
|
125
138
|
|
|
139
|
+
/** The disabled picker's tooltip while a kind's own list, which ignores the namespace filter, is on screen. */
|
|
140
|
+
export function resourceKindListNamespaceFilterTooltip(kind: Pick<HostKind, 'name' | 'group'> | null, features: HostFeatures, pending: boolean): string | undefined {
|
|
141
|
+
const contribution = kindListHost(kind)
|
|
142
|
+
if (!contribution?.list.namespaceFilterTooltip) return undefined
|
|
143
|
+
return contribution.list.mode(hostSupport(contribution.host, features), pending) === 'view' ? contribution.list.namespaceFilterTooltip : undefined
|
|
144
|
+
}
|
|
145
|
+
|
|
126
146
|
export function resourceKindListTitle(kind: Pick<HostKind, 'name' | 'group'>): string | null {
|
|
127
147
|
return kindListHost(kind)?.list.title ?? null
|
|
128
148
|
}
|
|
@@ -17,6 +17,14 @@ describe('workspace route ownership', () => {
|
|
|
17
17
|
expect(capacity.pageTitle('/capacity/demand')).toBe('Capacity Demand')
|
|
18
18
|
expect(capacity.pageTitle('/capacity/activity')).toBe('Capacity Activity')
|
|
19
19
|
expect(capacity.pageTitle('/capacity/unknown')).toBe('Capacity')
|
|
20
|
+
const velero = workspaceForPath('/velero')!
|
|
21
|
+
expect(velero.id).toBe('velero')
|
|
22
|
+
expect(velero.navView).toBe('resources')
|
|
23
|
+
expect(velero.namespaceScope).toBe('cluster')
|
|
24
|
+
expect(velero.namespaceFilterTooltip).toBeTruthy()
|
|
25
|
+
expect(velero.pageTitle('/velero')).toBe('Velero overview')
|
|
26
|
+
expect(velero.pageTitle('/velero/unknown')).toBe('Velero overview')
|
|
27
|
+
expect(workspaceForView('velero')).toBe(velero)
|
|
20
28
|
})
|
|
21
29
|
|
|
22
30
|
it('only owns whole route prefixes inside either OSS or an embedded router basename', () => {
|
|
@@ -24,6 +32,8 @@ describe('workspace route ownership', () => {
|
|
|
24
32
|
expect(workspaceForPath('/cnpg/')).toBeDefined()
|
|
25
33
|
expect(workspaceForPath('/cnpg-other')).toBeUndefined()
|
|
26
34
|
expect(workspaceForPath('/capacity-other')).toBeUndefined()
|
|
35
|
+
expect(workspaceForPath('/velero')?.id).toBe('velero')
|
|
36
|
+
expect(workspaceForPath('/velero-other')).toBeUndefined()
|
|
27
37
|
expect(workspaceForPath('/workload/clusters/db/pg')).toBeUndefined()
|
|
28
38
|
// React Router supplies basename-relative locations to the application.
|
|
29
39
|
expect(workspaceForPath('/c/demo/cnpg')).toBeUndefined()
|
|
@@ -34,6 +44,7 @@ describe('workspace route ownership', () => {
|
|
|
34
44
|
expect(workspaceContextSwitchSearch('/cnpg/clusters/db/pg', search).toString()).toBe('ctx=old-cluster')
|
|
35
45
|
expect(workspaceContextSwitchSearch('/cnpg', search).toString()).toBe('')
|
|
36
46
|
expect(workspaceContextSwitchSearch('/capacity/pools/default', search).toString()).toBe('')
|
|
47
|
+
expect(workspaceContextSwitchSearch('/velero', search).toString()).toBe('')
|
|
37
48
|
expect(workspaceContextSwitchSearch('/resources/pods', search).toString()).toBe('')
|
|
38
49
|
expect(search.get('tab')).toBe('storage')
|
|
39
50
|
})
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { capacityWorkspaceRoute } from '../components/capacity/workspaceRoute'
|
|
2
2
|
import { cnpgWorkspaceRoute } from '../components/cnpg/workspaceRoute'
|
|
3
|
+
import { veleroWorkspaceRoute } from '../components/velero/workspaceRoute'
|
|
3
4
|
import type { WorkspaceRoute } from './workspaceRoute'
|
|
4
5
|
|
|
5
|
-
export const workspaceRoutes = [cnpgWorkspaceRoute, capacityWorkspaceRoute] as const
|
|
6
|
+
export const workspaceRoutes = [cnpgWorkspaceRoute, capacityWorkspaceRoute, veleroWorkspaceRoute] as const
|
|
6
7
|
|
|
7
8
|
export const workspaceLabels = {
|
|
8
9
|
cnpg: cnpgWorkspaceRoute.label,
|
|
9
10
|
capacity: capacityWorkspaceRoute.label,
|
|
11
|
+
velero: veleroWorkspaceRoute.label,
|
|
10
12
|
} satisfies Record<WorkspaceRoute['id'], string>
|
|
11
13
|
|
|
12
14
|
export function workspaceForPath(pathname: string) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { ComponentType } from 'react'
|
|
2
2
|
import { CapacityView } from '../components/capacity/CapacityView'
|
|
3
3
|
import { CNPGView } from '../components/cnpg/CNPGView'
|
|
4
|
+
import { VeleroView } from '../components/velero/VeleroView'
|
|
4
5
|
import type { WorkspaceRoute, WorkspaceScreenProps } from './workspaceRoute'
|
|
5
6
|
|
|
6
7
|
const screens: Record<WorkspaceRoute['id'], ComponentType<WorkspaceScreenProps>> = {
|
|
7
8
|
cnpg: CNPGView,
|
|
8
9
|
capacity: ({ onOpenResource }) => <CapacityView onOpenResource={onOpenResource} />,
|
|
10
|
+
velero: VeleroView,
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export function WorkspaceScreen({ workspace, ...props }: WorkspaceScreenProps & { workspace: WorkspaceRoute }) {
|
package/src/main.tsx
CHANGED
|
@@ -4,6 +4,9 @@ import { RadarApp } from './RadarApp'
|
|
|
4
4
|
import { setAutomaticRequestMarking } from './api/config'
|
|
5
5
|
import { openExternal } from './utils/navigation'
|
|
6
6
|
import { installWailsClipboardShim } from './utils/wails-clipboard'
|
|
7
|
+
import { installWindowsTitleBar } from './desktop/WindowsTitleBar'
|
|
8
|
+
import { installDesktopZoomShortcuts } from './utils/desktop-zoom'
|
|
9
|
+
import { installStaleAssetPrompt } from './utils/staleAssetPrompt'
|
|
7
10
|
import './index.css'
|
|
8
11
|
|
|
9
12
|
// Automatic requests can beat the usage status to the server, and a recording
|
|
@@ -26,6 +29,11 @@ window.addEventListener('click', (e: MouseEvent) => {
|
|
|
26
29
|
// Wails desktop clipboard shim — see web/src/utils/wails-clipboard.ts for the
|
|
27
30
|
// full WKWebView background and what each interception exists for.
|
|
28
31
|
installWailsClipboardShim()
|
|
32
|
+
installWindowsTitleBar()
|
|
33
|
+
installDesktopZoomShortcuts()
|
|
34
|
+
// Embedding hosts serve their own assets and own their notices, so the prompt
|
|
35
|
+
// lives here rather than in RadarApp.
|
|
36
|
+
installStaleAssetPrompt()
|
|
29
37
|
|
|
30
38
|
// Mouse back/forward button navigation (button 3 = back, button 4 = forward).
|
|
31
39
|
// Uses 'mouseup' in capture phase to intercept before the browser's native handler.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { installDesktopZoomShortcuts, zoomStep } from './desktop-zoom'
|
|
5
|
+
|
|
6
|
+
const key = (k: string, mods: Partial<KeyboardEventInit> = {}) =>
|
|
7
|
+
({ key: k, ctrlKey: true, altKey: false, metaKey: false, ...mods }) as KeyboardEvent
|
|
8
|
+
|
|
9
|
+
describe('zoomStep', () => {
|
|
10
|
+
it('maps Ctrl+= / Ctrl++ to zoom in and Ctrl+- / Ctrl+_ to zoom out', () => {
|
|
11
|
+
expect(zoomStep(key('='))).toBeCloseTo(0.1)
|
|
12
|
+
expect(zoomStep(key('+'))).toBeCloseTo(0.1)
|
|
13
|
+
expect(zoomStep(key('-'))).toBeCloseTo(-0.1)
|
|
14
|
+
expect(zoomStep(key('_'))).toBeCloseTo(-0.1)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('ignores other keys and modifier combinations', () => {
|
|
18
|
+
expect(zoomStep(key('0'))).toBe(0)
|
|
19
|
+
expect(zoomStep(key('=', { ctrlKey: false }))).toBe(0)
|
|
20
|
+
expect(zoomStep(key('=', { altKey: true }))).toBe(0)
|
|
21
|
+
expect(zoomStep(key('=', { metaKey: true }))).toBe(0)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
describe('installDesktopZoomShortcuts', () => {
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
document.body.style.zoom = ''
|
|
28
|
+
document.body.innerHTML = ''
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const press = (target: EventTarget, k: string) =>
|
|
32
|
+
target.dispatchEvent(new KeyboardEvent('keydown', { key: k, ctrlKey: true, bubbles: true, cancelable: true }))
|
|
33
|
+
|
|
34
|
+
it('zooms the page inside WebView2, clamped to the menu range, but not from a terminal', () => {
|
|
35
|
+
;(window as unknown as { chrome: unknown }).chrome = { webview: {} }
|
|
36
|
+
installDesktopZoomShortcuts()
|
|
37
|
+
|
|
38
|
+
press(document.body, '=')
|
|
39
|
+
expect(document.body.style.zoom).toBe('1.1')
|
|
40
|
+
for (let i = 0; i < 20; i++) press(document.body, '=')
|
|
41
|
+
expect(document.body.style.zoom).toBe('2')
|
|
42
|
+
for (let i = 0; i < 30; i++) press(document.body, '-')
|
|
43
|
+
expect(document.body.style.zoom).toBe('0.5')
|
|
44
|
+
|
|
45
|
+
const term = document.createElement('div')
|
|
46
|
+
term.className = 'xterm'
|
|
47
|
+
const input = document.createElement('textarea')
|
|
48
|
+
term.appendChild(input)
|
|
49
|
+
document.body.appendChild(term)
|
|
50
|
+
press(input, '=')
|
|
51
|
+
expect(document.body.style.zoom).toBe('0.5')
|
|
52
|
+
})
|
|
53
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Ctrl+= / Ctrl+- for the Windows desktop app. The View menu registers these
|
|
2
|
+
// accelerators, but Wails' Windows key table has no entry for "=" or "-", so
|
|
3
|
+
// they are silently dropped, and WebView2's own zoom keys are off. The page
|
|
4
|
+
// applies the same zoom the menu items do. Elsewhere the native accelerators
|
|
5
|
+
// work, so this only runs inside WebView2.
|
|
6
|
+
//
|
|
7
|
+
// Inside a terminal Ctrl+- is readline's undo, so the key is left to xterm
|
|
8
|
+
// there; View → Zoom still works.
|
|
9
|
+
|
|
10
|
+
const STEP = 0.1
|
|
11
|
+
const MIN = 0.5
|
|
12
|
+
const MAX = 2
|
|
13
|
+
|
|
14
|
+
export function zoomStep(e: Pick<KeyboardEvent, 'key' | 'ctrlKey' | 'altKey' | 'metaKey'>): number {
|
|
15
|
+
if (!e.ctrlKey || e.altKey || e.metaKey) return 0
|
|
16
|
+
if (e.key === '=' || e.key === '+') return STEP
|
|
17
|
+
if (e.key === '-' || e.key === '_') return -STEP
|
|
18
|
+
return 0
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function installDesktopZoomShortcuts() {
|
|
22
|
+
if (!(window as unknown as { chrome?: { webview?: unknown } }).chrome?.webview) return
|
|
23
|
+
window.addEventListener('keydown', (e) => {
|
|
24
|
+
const step = zoomStep(e)
|
|
25
|
+
if (!step || (e.target as Element | null)?.closest?.('.xterm')) return
|
|
26
|
+
e.preventDefault()
|
|
27
|
+
const z = parseFloat(document.body.style.zoom || '1')
|
|
28
|
+
document.body.style.zoom = String(Math.min(MAX, Math.max(MIN, Math.round((z + step) * 10) / 10)))
|
|
29
|
+
}, true)
|
|
30
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import type { NamespaceScope } from '../api/client'
|
|
4
|
+
import { applyTabPick, readTabPick, writeTabPick } from './namespacePick'
|
|
5
|
+
|
|
6
|
+
function scope(over: Partial<NamespaceScope> = {}): NamespaceScope {
|
|
7
|
+
return {
|
|
8
|
+
actives: [],
|
|
9
|
+
context: 'ctx-a',
|
|
10
|
+
kubeconfigNamespace: '',
|
|
11
|
+
mode: 'cluster-wide',
|
|
12
|
+
accessibleNamespaces: ['team-a', 'team-b', 'team-c'],
|
|
13
|
+
deniedNamespaces: [],
|
|
14
|
+
authoritative: true,
|
|
15
|
+
canClearNamespace: true,
|
|
16
|
+
cacheScoped: false,
|
|
17
|
+
namespaceRescope: false,
|
|
18
|
+
...over,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
beforeEach(() => sessionStorage.clear())
|
|
23
|
+
|
|
24
|
+
describe('applyTabPick', () => {
|
|
25
|
+
it('seeds a tab with no pick from the server and keeps it after the server pick moves', () => {
|
|
26
|
+
expect(applyTabPick(scope({ actives: ['team-a'], mode: 'namespace' }), '/api').actives).toEqual(['team-a'])
|
|
27
|
+
const later = applyTabPick(scope({ actives: ['team-b'], mode: 'namespace' }), '/api')
|
|
28
|
+
expect(later.actives).toEqual(['team-a'])
|
|
29
|
+
expect(later.mode).toBe('namespace')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('keeps an explicit All over a narrowed server pick', () => {
|
|
33
|
+
writeTabPick('/api', 'ctx-a', [])
|
|
34
|
+
const seen = applyTabPick(scope({ actives: ['team-b'], mode: 'namespace' }), '/api')
|
|
35
|
+
expect(seen.actives).toEqual([])
|
|
36
|
+
expect(seen.mode).toBe('cluster-wide')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('reports restricted when an unpicked tab has only a partial list', () => {
|
|
40
|
+
writeTabPick('/api', 'ctx-a', [])
|
|
41
|
+
expect(applyTabPick(scope({ authoritative: false, actives: ['team-a'] }), '/api').mode).toBe('restricted')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('keeps one pick per Radar address', () => {
|
|
45
|
+
writeTabPick('/api', 'ctx-a', ['team-a'])
|
|
46
|
+
writeTabPick('/clusters/2/api', 'ctx-a', ['team-c'])
|
|
47
|
+
expect(applyTabPick(scope({ actives: ['team-b'] }), '/api').actives).toEqual(['team-a'])
|
|
48
|
+
expect(applyTabPick(scope({ actives: ['team-b'] }), '/clusters/2/api').actives).toEqual(['team-c'])
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('starts again from the server pick after a context switch, also when switching back', () => {
|
|
52
|
+
writeTabPick('/api', 'ctx-a', ['team-a'])
|
|
53
|
+
expect(applyTabPick(scope({ context: 'ctx-b', actives: ['team-b'] }), '/api').actives).toEqual(['team-b'])
|
|
54
|
+
expect(applyTabPick(scope({ actives: ['team-c'] }), '/api').actives).toEqual(['team-c'])
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('drops namespaces a complete list or a completed access check no longer has, and keeps them after a failed lookup', () => {
|
|
58
|
+
writeTabPick('/api', 'ctx-a', ['team-a', 'gone'])
|
|
59
|
+
expect(applyTabPick(scope({ authoritative: false }), '/api').actives).toEqual(['team-a', 'gone'])
|
|
60
|
+
expect(applyTabPick(scope({ accessibleNamespaces: [] }), '/api').actives).toEqual(['team-a', 'gone'])
|
|
61
|
+
expect(applyTabPick(scope({ authoritative: false, accessChecked: true, accessibleNamespaces: ['team-b'] }), '/api').actives).toEqual([])
|
|
62
|
+
writeTabPick('/api', 'ctx-a', ['team-a', 'gone'])
|
|
63
|
+
expect(applyTabPick(scope(), '/api').actives).toEqual(['team-a'])
|
|
64
|
+
expect(readTabPick('/api', 'ctx-a')).toEqual(['team-a'])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('leaves the shared server pick alone under --namespace-scope and on servers without a context', () => {
|
|
68
|
+
writeTabPick('/api', 'ctx-a', ['team-a'])
|
|
69
|
+
expect(applyTabPick(scope({ cacheScoped: true, actives: ['team-b'] }), '/api').actives).toEqual(['team-b'])
|
|
70
|
+
expect(applyTabPick(scope({ context: undefined, actives: ['team-b'] }), '/api').actives).toEqual(['team-b'])
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('writeTabPick', () => {
|
|
75
|
+
it('keeps an accepted pick for the page when sessionStorage is full', () => {
|
|
76
|
+
writeTabPick('/api', 'ctx-a', ['team-a'])
|
|
77
|
+
const setItem = vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
|
78
|
+
throw new DOMException('full', 'QuotaExceededError')
|
|
79
|
+
})
|
|
80
|
+
writeTabPick('/api', 'ctx-a', ['team-b'])
|
|
81
|
+
expect(readTabPick('/api', 'ctx-a')).toEqual(['team-b'])
|
|
82
|
+
setItem.mockRestore()
|
|
83
|
+
writeTabPick('/api', 'ctx-a', ['team-c'])
|
|
84
|
+
expect(sessionStorage.getItem('radar:namespace-pick:/api')).toContain('team-c')
|
|
85
|
+
expect(readTabPick('/api', 'ctx-a')).toEqual(['team-c'])
|
|
86
|
+
})
|
|
87
|
+
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { NamespaceScope } from '../api/client'
|
|
2
|
+
import { createTabStorage } from './tabStorage'
|
|
3
|
+
|
|
4
|
+
// The namespace pick is view state owned by each tab. The server's remembered
|
|
5
|
+
// pick only seeds a tab that has none, so another tab or another person
|
|
6
|
+
// sharing the Kubernetes identity can't change what an open tab shows, on
|
|
7
|
+
// reload included.
|
|
8
|
+
//
|
|
9
|
+
// The tab keeps one pick per Radar address, tagged with the kubeconfig context
|
|
10
|
+
// it was made in. After a context switch the tab starts again from the
|
|
11
|
+
// server's pick for the new context.
|
|
12
|
+
//
|
|
13
|
+
// Under --namespace-scope the pick is the process-wide cache scope and stays
|
|
14
|
+
// server-owned. A server that doesn't report its context predates per-tab
|
|
15
|
+
// picks and keeps the shared behavior, since an older Radar may still apply
|
|
16
|
+
// its stored pick to reads that name no namespace.
|
|
17
|
+
|
|
18
|
+
const storage = createTabStorage()
|
|
19
|
+
// Picks whose sessionStorage write didn't stick (storage full). They win over
|
|
20
|
+
// the stored slot for the life of the page, so an accepted pick isn't undone
|
|
21
|
+
// by the next fetch; a reload then falls back to the stored one.
|
|
22
|
+
const unsaved = new Map<string, string>()
|
|
23
|
+
|
|
24
|
+
function slotKey(apiBase: string): string {
|
|
25
|
+
return `radar:namespace-pick:${apiBase}`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function readTabPick(apiBase: string, context: string): string[] | undefined {
|
|
29
|
+
const key = slotKey(apiBase)
|
|
30
|
+
const raw = unsaved.get(key) ?? storage.get(key)
|
|
31
|
+
if (raw === undefined) return undefined
|
|
32
|
+
try {
|
|
33
|
+
const parsed: unknown = JSON.parse(raw)
|
|
34
|
+
if (typeof parsed !== 'object' || parsed === null || !('context' in parsed) || !('namespaces' in parsed)) return undefined
|
|
35
|
+
const { context: pickedIn, namespaces } = parsed
|
|
36
|
+
if (pickedIn !== context || !Array.isArray(namespaces)) return undefined
|
|
37
|
+
if (namespaces.every((ns): ns is string => typeof ns === 'string')) return namespaces
|
|
38
|
+
} catch { /* unreadable slot: treat as absent */ }
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function writeTabPick(apiBase: string, context: string, namespaces: string[]): void {
|
|
43
|
+
const key = slotKey(apiBase)
|
|
44
|
+
const value = JSON.stringify({ context, namespaces })
|
|
45
|
+
storage.set(key, value)
|
|
46
|
+
if (storage.get(key) === value) unsaved.delete(key)
|
|
47
|
+
else unsaved.set(key, value)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Same cleaning the server applies to a submitted pick. */
|
|
51
|
+
export function cleanPick(namespaces: string[]): string[] {
|
|
52
|
+
return [...new Set(namespaces.filter(ns => ns !== ''))]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function ownsTabPick(scope: Pick<NamespaceScope, 'cacheScoped' | 'context'>): scope is NamespaceScope & { context: string } {
|
|
56
|
+
return !scope.cacheScoped && !!scope.context
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function withActives(scope: NamespaceScope, actives: string[]): NamespaceScope {
|
|
60
|
+
const mode = actives.length > 0 ? 'namespace' : scope.authoritative ? 'cluster-wide' : 'restricted'
|
|
61
|
+
return { ...scope, actives, mode }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Drops picked namespaces missing from the scope's list where the server drops
|
|
66
|
+
* its own pick: when it says so (`accessChecked`), or on a complete non-empty
|
|
67
|
+
* list. After a failed lookup, or with no list at all, the pick stays.
|
|
68
|
+
*/
|
|
69
|
+
export function pruneTabPick(scope: NamespaceScope, pick: string[]): string[] {
|
|
70
|
+
const proves = scope.accessChecked || (scope.authoritative && scope.accessibleNamespaces.length > 0)
|
|
71
|
+
if (!proves) return pick
|
|
72
|
+
const accessible = new Set(scope.accessibleNamespaces)
|
|
73
|
+
return pick.filter(ns => accessible.has(ns))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns the server scope as this tab sees it: its own pick when it has one
|
|
78
|
+
* for this context, else the server's pick, which becomes the tab's.
|
|
79
|
+
*/
|
|
80
|
+
export function applyTabPick(scope: NamespaceScope, apiBase: string): NamespaceScope {
|
|
81
|
+
if (!ownsTabPick(scope)) return scope
|
|
82
|
+
const stored = readTabPick(apiBase, scope.context)
|
|
83
|
+
const pick = pruneTabPick(scope, stored ?? scope.actives)
|
|
84
|
+
if (stored === undefined || pick.length !== stored.length) {
|
|
85
|
+
writeTabPick(apiBase, scope.context, pick)
|
|
86
|
+
}
|
|
87
|
+
return withActives(scope, pick)
|
|
88
|
+
}
|