@skyhook-io/radar-app 1.22.2 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +49 -13
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/api/agentSandbox.ts +259 -0
  6. package/src/api/client.autoPromConnect.test.tsx +43 -0
  7. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  8. package/src/api/client.ts +151 -27
  9. package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
  10. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  11. package/src/api/diagnose.ts +4 -0
  12. package/src/api/kagent.test.ts +82 -0
  13. package/src/api/kagent.ts +230 -0
  14. package/src/api/poll.ts +78 -0
  15. package/src/api/prometheusCharts.ts +5 -0
  16. package/src/api/radarFeatures.test.ts +9 -0
  17. package/src/api/radarFeatures.ts +16 -0
  18. package/src/api/substrateWorkspace.test.ts +72 -0
  19. package/src/api/substrateWorkspace.ts +1394 -0
  20. package/src/api/vulnerabilities.ts +207 -9
  21. package/src/api/workloadSource.test.tsx +315 -0
  22. package/src/api/workloadSource.ts +128 -12
  23. package/src/components/CloudConnectFlow.tsx +46 -7
  24. package/src/components/CloudFunnelButton.test.tsx +193 -7
  25. package/src/components/CloudFunnelButton.tsx +128 -32
  26. package/src/components/SelfManagedStart.tsx +12 -2
  27. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  28. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  29. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  30. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  31. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  32. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  33. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  34. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  35. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  36. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  37. package/src/components/agentsandbox/data.ts +135 -0
  38. package/src/components/agentsandbox/host.test.ts +27 -0
  39. package/src/components/agentsandbox/host.tsx +85 -0
  40. package/src/components/agentsandbox/labels.test.ts +42 -0
  41. package/src/components/agentsandbox/labels.ts +146 -0
  42. package/src/components/agentsandbox/listFilters.ts +85 -0
  43. package/src/components/agentsandbox/lists.ts +52 -0
  44. package/src/components/agentsandbox/routes.ts +23 -0
  45. package/src/components/agentsandbox/shared.tsx +321 -0
  46. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  47. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  48. package/src/components/agentsandbox/workspace.tsx +258 -0
  49. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  50. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  51. package/src/components/applications/ApplicationsView.tsx +156 -3
  52. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  53. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  54. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  55. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  56. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  57. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  58. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  59. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  60. package/src/components/cloudHints/cloudHints.ts +131 -0
  61. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  62. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  63. package/src/components/cloudHints/cloudLinks.ts +31 -0
  64. package/src/components/cloudHints/hintStorage.ts +28 -0
  65. package/src/components/cnpg/CNPGView.tsx +4 -7
  66. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  67. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  68. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  69. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  70. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  71. package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
  72. package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
  73. package/src/components/helm/HelmView.tsx +4 -3
  74. package/src/components/helm/ObservedHelmNotice.tsx +39 -17
  75. package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
  76. package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
  77. package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
  78. package/src/components/home/HomeAgentBlock.tsx +2 -0
  79. package/src/components/home/HomeView.tsx +3 -3
  80. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  81. package/src/components/home/MCPSetupDialog.tsx +6 -2
  82. package/src/components/home/McpCloudLine.test.tsx +162 -0
  83. package/src/components/home/McpCloudLine.tsx +95 -0
  84. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  85. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  86. package/src/components/home/mcpToolCatalog.ts +4 -4
  87. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  88. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  89. package/src/components/issues/IssuesPane.tsx +181 -23
  90. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  91. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  92. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  93. package/src/components/issues/sinceLastVisit.ts +439 -0
  94. package/src/components/issues/uncheckedSources.test.ts +8 -0
  95. package/src/components/issues/uncheckedSources.ts +3 -0
  96. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  97. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  98. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  99. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  100. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  101. package/src/components/kagent/KagentLists.tsx +412 -0
  102. package/src/components/kagent/KagentOverview.tsx +234 -0
  103. package/src/components/kagent/KagentPages.tsx +690 -0
  104. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  105. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  106. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  107. package/src/components/kagent/KagentView.tsx +109 -0
  108. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  109. package/src/components/kagent/host.tsx +144 -0
  110. package/src/components/kagent/routes.ts +31 -0
  111. package/src/components/kagent/shared.tsx +336 -0
  112. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  113. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  114. package/src/components/kagent/workspace.fixtures.ts +108 -0
  115. package/src/components/kagent/workspaceRoute.ts +18 -0
  116. package/src/components/nudges/activeNudges.test.ts +39 -0
  117. package/src/components/nudges/activeNudges.ts +76 -0
  118. package/src/components/poll/OssPoll.tsx +871 -0
  119. package/src/components/poll/mount.test.ts +12 -0
  120. package/src/components/poll/pollCloud.test.ts +23 -0
  121. package/src/components/poll/pollCloud.ts +6 -0
  122. package/src/components/poll/pollDefinition.ts +93 -0
  123. package/src/components/poll/pollFlow.test.ts +140 -0
  124. package/src/components/poll/pollFlow.ts +137 -0
  125. package/src/components/poll/pollSender.test.ts +137 -0
  126. package/src/components/poll/pollSender.ts +76 -0
  127. package/src/components/poll/pollStorage.test.ts +53 -0
  128. package/src/components/poll/pollStorage.ts +77 -0
  129. package/src/components/poll/round.json +350 -0
  130. package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
  131. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  132. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  133. package/src/components/resource/PrometheusCharts.tsx +10 -1
  134. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  135. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  136. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  137. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  138. package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
  139. package/src/components/resources/ImageFilesystemModal.tsx +42 -3
  140. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  141. package/src/components/resources/ResourcesView.tsx +24 -11
  142. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  143. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  144. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  145. package/src/components/settings/SettingsDialog.tsx +84 -16
  146. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  147. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  148. package/src/components/settings/SubstrateSettings.tsx +544 -0
  149. package/src/components/settings/settings-state.test.ts +21 -3
  150. package/src/components/settings/settings-state.ts +13 -3
  151. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  152. package/src/components/share/ShareLinkButton.tsx +391 -0
  153. package/src/components/share/openShareInCloud.test.ts +29 -0
  154. package/src/components/share/openShareInCloud.ts +10 -0
  155. package/src/components/share/shareLink.test.ts +129 -0
  156. package/src/components/share/shareLink.ts +175 -0
  157. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  158. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  159. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  160. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  161. package/src/components/substrate/SubstrateActors.tsx +612 -0
  162. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  163. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  164. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  165. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  166. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  167. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  168. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  169. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  170. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  171. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  172. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  173. package/src/components/substrate/SubstrateView.tsx +173 -0
  174. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  175. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  176. package/src/components/substrate/attention.ts +81 -0
  177. package/src/components/substrate/contextPin.tsx +69 -0
  178. package/src/components/substrate/host.tsx +83 -0
  179. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  180. package/src/components/substrate/readings.test.ts +484 -0
  181. package/src/components/substrate/readings.ts +997 -0
  182. package/src/components/substrate/routes.ts +103 -0
  183. package/src/components/substrate/shared.tsx +426 -0
  184. package/src/components/substrate/substrate.fixtures.ts +325 -0
  185. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  186. package/src/components/substrate/workspaceRoute.ts +23 -0
  187. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  188. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  189. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  190. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  191. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  192. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  193. package/src/components/traffic/TrafficGraph.tsx +17 -14
  194. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  195. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  196. package/src/components/traffic/TrafficView.tsx +26 -56
  197. package/src/components/traffic/trafficFilters.test.ts +61 -1
  198. package/src/components/traffic/trafficFilters.ts +68 -8
  199. package/src/components/ui/UpdateNotification.tsx +2 -0
  200. package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
  201. package/src/components/velero/VeleroOverview.tsx +2 -2
  202. package/src/components/velero/VeleroView.tsx +3 -6
  203. package/src/components/vulnerabilities/columns.tsx +132 -0
  204. package/src/components/vulnerabilities/filters.tsx +317 -0
  205. package/src/components/vulnerabilities/owner.test.ts +54 -0
  206. package/src/components/vulnerabilities/owner.tsx +163 -0
  207. package/src/components/vulnerabilities/parts.test.ts +126 -12
  208. package/src/components/vulnerabilities/parts.tsx +612 -52
  209. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  210. package/src/components/vulnerabilities/traffic.tsx +40 -0
  211. package/src/components/whats-new/WhatsNew.tsx +2 -0
  212. package/src/components/whats-new/releaseNotes.ts +75 -1
  213. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  214. package/src/components/workload/WorkloadView.tsx +52 -13
  215. package/src/components/workspace/layout.tsx +13 -7
  216. package/src/components/workspace/sidebar.test.ts +48 -0
  217. package/src/components/workspace/sidebar.ts +73 -3
  218. package/src/components/workspace/table.ts +2 -1
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/integrations/resourceHost.ts +12 -6
  222. package/src/integrations/resourceHosts.test.tsx +27 -1
  223. package/src/integrations/resourceHosts.tsx +15 -7
  224. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  225. package/src/integrations/sidebarWorkspaces.ts +41 -0
  226. package/src/integrations/workspaceRoute.ts +1 -1
  227. package/src/integrations/workspaceRoutes.ts +7 -1
  228. package/src/integrations/workspaceScreens.tsx +6 -0
@@ -5,13 +5,12 @@ import { useAPIResources } from '../../api/apiResources'
5
5
  import { useVeleroWorkspace } from '../../api/velero'
6
6
  import { useNamespaces, useRadarFeature } from '../../api/client'
7
7
  import { useMediaQuery } from '../../hooks/useMediaQuery'
8
- import { useCNPGSidebarWorkspace } from '../cnpg/useCNPGSidebarWorkspace'
8
+ import { useIntegrationSidebars } from '../../integrations/sidebarWorkspaces'
9
9
  import { WorkspaceFrame } from '../workspace/WorkspaceFrame'
10
- import { useMergedSidebarWorkspaces } from '../workspace/sidebar'
11
10
  import { useWorkspaceDrawer } from '../workspace/useWorkspaceDrawer'
12
11
  import { VeleroScreenGate, useVeleroInstallation } from './shared'
13
12
  import { VeleroOverview } from './VeleroOverview'
14
- import { useVeleroSidebarWorkspace, veleroDiscovered } from './useVeleroSidebarWorkspace'
13
+ import { veleroDiscovered } from './useVeleroSidebarWorkspace'
15
14
  import { VELERO_DETAIL_KINDS, VELERO_GROUP, parseVeleroRoute } from './routes'
16
15
  import { VeleroDetailPage } from './VeleroDetailPage'
17
16
 
@@ -34,11 +33,9 @@ export function VeleroView({ namespaces, selectedResource, onOpenResource, onClo
34
33
  const discovered = veleroDiscovered(apiResources) || discoveryFailed
35
34
  const query = useVeleroWorkspace({ enabled: discovered })
36
35
  // An object's page highlights its kind's row; the Overview row only the Overview.
37
- const veleroSidebar = useVeleroSidebarWorkspace({ apiResources, active: !detail })
36
+ const sidebarWorkspace = useIntegrationSidebars({ apiResources, namespaces, velero: { active: !detail } })
38
37
  const plural = detail?.plural
39
38
  const selectedKind = useMemo(() => (plural ? { name: plural, kind: VELERO_DETAIL_KINDS[plural].kind, group: VELERO_GROUP } : null), [plural])
40
- const cnpgSidebar = useCNPGSidebarWorkspace({ apiResources, namespaces })
41
- const sidebarWorkspace = useMergedSidebarWorkspaces(cnpgSidebar, veleroSidebar)
42
39
  const { drawerTarget, inspect } = useWorkspaceDrawer({ selectedResource, onOpenResource, onCloseResource })
43
40
 
44
41
  const [installation, setInstallation] = useVeleroInstallation(query.data?.installations)
@@ -0,0 +1,132 @@
1
+ import { useState } from 'react'
2
+ import { clsx } from 'clsx'
3
+ import { CalendarX } from 'lucide-react'
4
+ import { WithTooltip } from '../ui/Tooltip'
5
+ import type { VulnerabilitiesResponse, VulnerabilityView } from '../../api/vulnerabilities'
6
+
7
+ /** A table column that is off until someone turns it on, from the page's
8
+ * menu ("Show <label>"). */
9
+ export interface OptionalColumn {
10
+ key: string
11
+ label: string
12
+ /** Says what the column holds: the column head's tooltip. */
13
+ tip: string
14
+ /** Track width in the table's grid. */
15
+ track: string
16
+ /** Whether any row of the answer has a value for it. A column with none
17
+ * (an older Radar, an older Trivy, a report that leaves the field out)
18
+ * isn't offered or drawn, so it never shows as a column of dashes. */
19
+ hasData: (data: VulnerabilitiesResponse) => boolean
20
+ }
21
+
22
+ // Each view's optional columns, in the order they appear. Every value is also
23
+ // in that view's CSV, whatever is shown. An entry with no track isn't a grid
24
+ // column of the view's table (Package URL sits in an expanded image).
25
+ export const OPTIONAL_COLUMNS: Partial<Record<VulnerabilityView, OptionalColumn[]>> = {
26
+ image: [
27
+ { key: 'image.os', label: 'OS', tip: "The image's OS release, as Trivy reports it.", track: 'minmax(140px,0.8fr)', hasData: (d) => !!d.images?.some((i) => i.os) },
28
+ { key: 'image.scanner', label: 'Scanner', tip: "The scanner and version that wrote the image's newest report.", track: '112px', hasData: (d) => !!d.images?.some((i) => i.scanner) },
29
+ { key: 'image.packageUrl', label: 'Package URL', tip: "The package URL (purl) Trivy reports for each finding, in an expanded image's findings.", track: '', hasData: (d) => !!d.images?.some((i) => i.findings.some((f) => f.packageUrl)) },
30
+ ],
31
+ cve: [
32
+ { key: 'cve.epss', label: 'EPSS', tip: 'EPSS by FIRST: the chance of exploitation activity in the next 30 days, and its percentile among scored CVEs.', track: '64px', hasData: (d) => d.intel?.epss.state === 'ready' && !!d.cves?.some((c) => c.epss) },
33
+ { key: 'cve.published', label: 'Published', tip: "When the CVE was published, from Trivy's database. Not when it was found in this cluster.", track: '92px', hasData: (d) => !!d.cves?.some((c) => c.publishedAt) },
34
+ { key: 'cve.age', label: 'Age', tip: 'Days since the CVE was published, not since it was found in this cluster.', track: '76px', hasData: (d) => !!d.cves?.some((c) => c.publishedAt) },
35
+ ],
36
+ workload: [
37
+ { key: 'workload.owner', label: 'Owner', tip: 'The Helm release, or the Argo CD or Flux app and its repository, that deploys the workload, and its team from the team label on the workload or its namespace. Blank when Radar found none of these, and Not checked when your access kept Radar from looking everywhere. It names the app, not the file that sets the image tag.', track: 'minmax(160px,1fr)', hasData: (d) => !!d.ownership },
38
+ ],
39
+ }
40
+
41
+ const STORAGE_KEY = 'radar-vulnerability-columns'
42
+
43
+ function readShown(): Set<string> {
44
+ try {
45
+ const parsed: unknown = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? '[]')
46
+ return new Set(Array.isArray(parsed) ? parsed.filter((k): k is string => typeof k === 'string') : [])
47
+ } catch {
48
+ return new Set()
49
+ }
50
+ }
51
+
52
+ /** The optional columns this browser shows, across views; none by default. */
53
+ export function useOptionalColumns() {
54
+ const [shown, setShown] = useState(readShown)
55
+ const toggle = (key: string) => {
56
+ const next = new Set(shown)
57
+ if (next.has(key)) next.delete(key)
58
+ else next.add(key)
59
+ setShown(next)
60
+ try {
61
+ localStorage.setItem(STORAGE_KEY, JSON.stringify([...next]))
62
+ } catch {
63
+ // Private windows and blocked storage: the choice lasts this visit.
64
+ }
65
+ }
66
+ return { shown, toggle }
67
+ }
68
+
69
+ /** The view's optional columns this answer has data for. */
70
+ export function availableColumns(view: VulnerabilityView, data: VulnerabilitiesResponse): OptionalColumn[] {
71
+ return (OPTIONAL_COLUMNS[view] ?? []).filter((c) => c.hasData(data))
72
+ }
73
+
74
+ /** The view's optional columns, each with whether it is drawn: on in this
75
+ * browser, and with data in this answer. */
76
+ export function columnsFor(view: VulnerabilityView, shown: ReadonlySet<string>, data: VulnerabilitiesResponse): Record<string, boolean> {
77
+ return Object.fromEntries((OPTIONAL_COLUMNS[view] ?? []).map((c) => [c.key.split('.')[1], shown.has(c.key) && c.hasData(data)]))
78
+ }
79
+
80
+ /** A column head with its tooltip, underlined to show there is one. */
81
+ export function OptionalHead({ column, align }: { column?: OptionalColumn; align?: 'right' }) {
82
+ if (!column) return null
83
+ return (
84
+ <WithTooltip tip={column.tip}>
85
+ <span className={clsx('underline decoration-dotted underline-offset-2', align === 'right' && 'text-right')}>{column.label}</span>
86
+ </WithTooltip>
87
+ )
88
+ }
89
+
90
+ export function optionalColumn(view: VulnerabilityView, name: string): OptionalColumn | undefined {
91
+ return OPTIONAL_COLUMNS[view]?.find((c) => c.key === `${view}.${name}`)
92
+ }
93
+
94
+ /** Whole days since a timestamp, never negative. */
95
+ export function daysSince(iso: string, now = Date.now()): number | undefined {
96
+ const t = Date.parse(iso)
97
+ return Number.isFinite(t) ? Math.max(0, Math.floor((now - t) / 86_400_000)) : undefined
98
+ }
99
+
100
+ /** A timestamp's calendar date, as YYYY-MM-DD in UTC. */
101
+ export function isoDate(iso: string): string {
102
+ const t = Date.parse(iso)
103
+ return Number.isFinite(t) ? new Date(t).toISOString().slice(0, 10) : iso
104
+ }
105
+
106
+ /**
107
+ * An image's OS as quiet text, "debian 10.9 · end of life", the end-of-life
108
+ * part only when Trivy says so. lead puts a separator before it, for the
109
+ * image name's line.
110
+ */
111
+ export function OsLabel({ os, endOfLife, lead = false, className }: { os?: string; endOfLife?: boolean; lead?: boolean; className?: string }) {
112
+ if (!os && !endOfLife) return null
113
+ return (
114
+ <span className={clsx('flex min-w-0 items-baseline gap-1.5 whitespace-nowrap text-xs text-theme-text-tertiary', className)}>
115
+ {os && <span className="min-w-0 truncate font-mono">{lead && <span aria-hidden>· </span>}{os}</span>}
116
+ {endOfLife && <EndOfLifeNote lead={lead || !!os} />}
117
+ </span>
118
+ )
119
+ }
120
+
121
+ /** Trivy's end-of-life word for an OS: gray, with a mark, never a status colour. */
122
+ export function EndOfLifeNote({ lead = false }: { lead?: boolean }) {
123
+ return (
124
+ <WithTooltip tip="Trivy reports this OS release as end of life.">
125
+ <span className="inline-flex shrink-0 items-baseline gap-1 font-sans text-xs text-theme-text-tertiary">
126
+ {lead && <span aria-hidden>·</span>}
127
+ <CalendarX className="h-3 w-3 self-center" aria-hidden />
128
+ end of life
129
+ </span>
130
+ </WithTooltip>
131
+ )
132
+ }
@@ -0,0 +1,317 @@
1
+ import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react'
2
+ import type { ReactNode } from 'react'
3
+ import { createPortal } from 'react-dom'
4
+ import { clsx } from 'clsx'
5
+ import { ChevronDown, X } from 'lucide-react'
6
+ import { MultiSelectPicker } from '@skyhook-io/k8s-ui/components/ui/MultiSelectPicker'
7
+ import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
8
+ import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '@skyhook-io/k8s-ui/utils/animation'
9
+ import type { VulnerabilityRiskFactor, VulnerabilitySeverity } from '../../api/vulnerabilities'
10
+ import { RISK_FACTORS, RISK_ORDER, SEVERITIES } from './parts'
11
+
12
+ /** Severities as the filter offers them, unrated last. */
13
+ export const SEVERITY_FILTERS: { key: VulnerabilitySeverity; label: string }[] = [...SEVERITIES.map(({ key, label }) => ({ key, label })), { key: 'unknown', label: 'Unrated' }]
14
+
15
+ /** "Severity" with none selected, the severity's name for one, "Severity: 2" for more. */
16
+ export function severityFilterLabel(selected: VulnerabilitySeverity[]): string {
17
+ const chosen = SEVERITY_FILTERS.filter((s) => selected.includes(s.key))
18
+ if (chosen.length === 0) return 'Severity'
19
+ if (chosen.length === 1) return chosen[0].label
20
+ return `Severity: ${chosen.length}`
21
+ }
22
+
23
+ /** "More filters", or "More filters · 2" when two of its filters are on. */
24
+ export function moreFiltersLabel(on: number): string {
25
+ return on > 0 ? `More filters · ${on}` : 'More filters'
26
+ }
27
+
28
+ const ENABLED = 'input:not([disabled]), button:not([disabled])'
29
+ const FOCUSABLE = 'button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])'
30
+
31
+ // A checkbox first: a disabled Clear all can't take focus.
32
+ const firstControl = (panel: HTMLElement | null) => panel?.querySelector<HTMLElement>('input:not([disabled])') ?? panel?.querySelector<HTMLElement>(ENABLED) ?? null
33
+
34
+ /**
35
+ * A chip that opens a panel of filters below it, in the popover the
36
+ * timeline's Kinds filter uses. The panel takes focus when it opens and
37
+ * gives it back to the chip on Escape, Done, or tabbing past either end,
38
+ * since it is drawn at the end of the page rather than after the chip.
39
+ * A change made in the panel can take away the control that had focus:
40
+ * Clear all disables itself, and a filter offered only while on drops out
41
+ * once off. Focus then goes to the panel's first checkbox, or, when the
42
+ * chip itself goes, to the control before it, rather than to the page.
43
+ */
44
+ function FilterDropdown({ label, active, panelLabel, width = 272, children }: {
45
+ label: string
46
+ active: boolean
47
+ panelLabel: string
48
+ width?: number
49
+ children: (close: () => void) => ReactNode
50
+ }) {
51
+ const [open, setOpen] = useState(false)
52
+ const { shouldRender, isOpen } = useAnimatedUnmount(open, overlayExitMs('menu'))
53
+ const rootRef = useRef<HTMLDivElement | null>(null)
54
+ const buttonRef = useRef<HTMLButtonElement | null>(null)
55
+ const panelRef = useRef<HTMLDivElement | null>(null)
56
+ const [anchor, setAnchor] = useState<{ left: number; top: number } | null>(null)
57
+ const panelId = useId()
58
+ const triggerId = `${panelId}-trigger`
59
+
60
+ // By id, not the ref: the panel's Done button gets this during render.
61
+ const close = () => {
62
+ setOpen(false)
63
+ document.getElementById(triggerId)?.focus()
64
+ }
65
+
66
+ useLayoutEffect(() => {
67
+ if (!open) return
68
+ const place = () => {
69
+ const r = rootRef.current?.getBoundingClientRect()
70
+ if (r) setAnchor({ left: Math.max(8, Math.min(r.left, window.innerWidth - width - 8)), top: r.bottom + 4 })
71
+ }
72
+ place()
73
+ window.addEventListener('scroll', place, true)
74
+ window.addEventListener('resize', place)
75
+ return () => {
76
+ window.removeEventListener('scroll', place, true)
77
+ window.removeEventListener('resize', place)
78
+ }
79
+ }, [open, width])
80
+
81
+ const placed = anchor !== null
82
+ // On a reopen after the exit finished, the panel mounts a render after
83
+ // open turns true, so this waits for shouldRender too.
84
+ useEffect(() => {
85
+ if (!open || !placed || !shouldRender) return
86
+ firstControl(panelRef.current)?.focus()
87
+ }, [open, placed, shouldRender])
88
+
89
+ const focusInPanel = useRef(false)
90
+ useLayoutEffect(() => {
91
+ if (!open) focusInPanel.current = false
92
+ const panel = panelRef.current
93
+ if (!open || !panel || !focusInPanel.current) return
94
+ const active = document.activeElement
95
+ const lost = !active || active === document.body || (panel.contains(active) && active.matches(':disabled'))
96
+ if (lost) (firstControl(panel) ?? buttonRef.current)?.focus()
97
+ })
98
+
99
+ useLayoutEffect(() => {
100
+ const root = rootRef.current
101
+ return () => {
102
+ if (!root || !(focusInPanel.current || root.contains(document.activeElement))) return
103
+ const row = Array.from(root.parentElement?.querySelectorAll<HTMLElement>(FOCUSABLE) ?? []).filter((el) => !root.contains(el))
104
+ const before = row.filter((el) => root.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING)
105
+ ;(before.at(-1) ?? row[0])?.focus()
106
+ }
107
+ }, [])
108
+
109
+ useEffect(() => {
110
+ if (!open) return
111
+ const onDown = (e: PointerEvent) => {
112
+ const t = e.target as Node
113
+ if (rootRef.current?.contains(t) || panelRef.current?.contains(t)) return
114
+ setOpen(false)
115
+ }
116
+ const onKey = (e: KeyboardEvent) => {
117
+ if (e.key === 'Escape') {
118
+ e.stopPropagation()
119
+ setOpen(false)
120
+ buttonRef.current?.focus()
121
+ }
122
+ }
123
+ window.addEventListener('pointerdown', onDown)
124
+ window.addEventListener('keydown', onKey)
125
+ return () => {
126
+ window.removeEventListener('pointerdown', onDown)
127
+ window.removeEventListener('keydown', onKey)
128
+ }
129
+ }, [open])
130
+
131
+ const onPanelKey = (e: React.KeyboardEvent) => {
132
+ if (e.key !== 'Tab') return
133
+ const focusable = Array.from(panelRef.current?.querySelectorAll<HTMLElement>(ENABLED) ?? [])
134
+ const edge = e.shiftKey ? focusable[0] : focusable[focusable.length - 1]
135
+ if (document.activeElement === edge) {
136
+ e.preventDefault()
137
+ close()
138
+ }
139
+ }
140
+
141
+ return (
142
+ <div ref={rootRef} className="relative shrink-0">
143
+ <button
144
+ ref={buttonRef}
145
+ id={triggerId}
146
+ type="button"
147
+ aria-haspopup="dialog"
148
+ aria-expanded={open}
149
+ aria-controls={shouldRender ? panelId : undefined}
150
+ onClick={() => setOpen((o) => !o)}
151
+ // The look of the chips beside it (FilterPill), with a chevron.
152
+ className={clsx(
153
+ 'inline-flex items-center gap-1.5 whitespace-nowrap rounded-md border px-2.5 py-1 text-xs font-medium transition-colors',
154
+ 'focus-visible:ring-2 focus-visible:ring-theme-text-primary/20 focus-visible:outline-none',
155
+ active || open
156
+ ? 'bg-theme-text-primary/10 border-theme-text-primary/25 text-theme-text-primary'
157
+ : 'border-theme-border-light text-theme-text-secondary hover:border-theme-border hover:text-theme-text-primary hover:bg-theme-hover/50',
158
+ )}
159
+ >
160
+ <span>{label}</span>
161
+ <ChevronDown className="h-3.5 w-3.5 text-theme-text-tertiary" aria-hidden />
162
+ </button>
163
+
164
+ {shouldRender && anchor && createPortal(
165
+ <div
166
+ ref={panelRef}
167
+ id={panelId}
168
+ role="dialog"
169
+ aria-label={panelLabel}
170
+ inert={!open}
171
+ onKeyDown={onPanelKey}
172
+ onFocus={() => { focusInPanel.current = true }}
173
+ // Null when focus goes to nothing, as when its control is removed.
174
+ onBlur={(e) => { if (e.relatedTarget && !e.currentTarget.contains(e.relatedTarget)) focusInPanel.current = false }}
175
+ style={{ position: 'fixed', left: anchor.left, top: anchor.top, width, ...overlayTransitionStyle(isOpen, 'menu') }}
176
+ className={clsx(
177
+ 'z-50 origin-top-left rounded-md border border-theme-border bg-theme-surface shadow-theme-lg',
178
+ TRANSITION_MENU,
179
+ isOpen ? 'opacity-100 translate-y-0 scale-100' : 'opacity-0 -translate-y-1 scale-[0.97]',
180
+ !open && 'pointer-events-none',
181
+ )}
182
+ >
183
+ {children(close)}
184
+ </div>,
185
+ document.body,
186
+ )}
187
+ </div>
188
+ )
189
+ }
190
+
191
+ const countMeta = (n: number | undefined) => <span className="shrink-0 text-xs tabular-nums text-theme-text-tertiary">({n ?? 0})</span>
192
+
193
+ /**
194
+ * The severity filter: one chip that opens a checklist of the five
195
+ * severities, each with its finding count in scope. A row is kept when it
196
+ * has a finding at any selected severity.
197
+ */
198
+ export function SeverityFilter({ counts, selected, onChange }: {
199
+ counts: Record<VulnerabilitySeverity, number>
200
+ selected: VulnerabilitySeverity[]
201
+ onChange: (next: VulnerabilitySeverity[]) => void
202
+ }) {
203
+ const [search, setSearch] = useState('')
204
+ const byLabel = useMemo(() => new Map(SEVERITY_FILTERS.map((s) => [s.label, s.key])), [])
205
+ const selectedLabels = useMemo(() => new Set(SEVERITY_FILTERS.filter((s) => selected.includes(s.key)).map((s) => s.label)), [selected])
206
+ const commit = (labels: Iterable<string>) => {
207
+ const chosen = new Set([...labels].map((l) => byLabel.get(l)))
208
+ onChange(SEVERITY_FILTERS.filter((s) => chosen.has(s.key)).map((s) => s.key))
209
+ }
210
+ return (
211
+ <FilterDropdown label={severityFilterLabel(selected)} active={selected.length > 0} panelLabel="Severity" width={232}>
212
+ {(close) => (
213
+ <MultiSelectPicker
214
+ items={SEVERITY_FILTERS.map((s) => s.label)}
215
+ selected={selectedLabels}
216
+ onSelectionChange={commit}
217
+ onClearAll={() => onChange([])}
218
+ onDone={close}
219
+ search={search}
220
+ onSearchChange={setSearch}
221
+ searchPlaceholder="Filter severities"
222
+ summaryEmptyLabel="Any severity"
223
+ noItemsLabel="No severities."
224
+ clearAllDisabled={selected.length === 0}
225
+ clearAllAriaLabel="Clear severities"
226
+ searchThreshold={SEVERITY_FILTERS.length}
227
+ renderItemMeta={(label) => {
228
+ const key = byLabel.get(label)
229
+ return key ? countMeta(counts[key]) : null
230
+ }}
231
+ />
232
+ )}
233
+ </FilterDropdown>
234
+ )
235
+ }
236
+
237
+ function CheckRow({ label, count, description, checked, onChange }: { label: string; count?: number; description?: string; checked: boolean; onChange: () => void }) {
238
+ return (
239
+ <li className="hover:bg-theme-hover">
240
+ <label className="flex cursor-pointer items-start gap-2 px-3 py-1.5 text-sm text-theme-text-primary">
241
+ <input type="checkbox" checked={checked} onChange={onChange} className="mt-1 shrink-0 accent-current" />
242
+ <span className="flex min-w-0 flex-col">
243
+ <span className="flex items-baseline gap-2">
244
+ <span className="truncate">{label}</span>
245
+ {count !== undefined && countMeta(count)}
246
+ </span>
247
+ {description && <span className="text-xs text-theme-text-tertiary">{description}</span>}
248
+ </span>
249
+ </label>
250
+ </li>
251
+ )
252
+ }
253
+
254
+ /**
255
+ * The filters most views need less often, behind one chip: Fix available,
256
+ * OS end of life, and the risk factors checklist. Each is passed only when
257
+ * the view and the answer can apply it; with none to offer there is no chip.
258
+ * The chip counts the filters it holds that are on, the risk factors as one;
259
+ * the serious three alone don't count, since the Serious risk chip shows them.
260
+ */
261
+ export function MoreFilters({ fixable, endOfLife, risk, onClearAll }: {
262
+ fixable?: { on: boolean; onToggle: () => void }
263
+ endOfLife?: { on: boolean; count: number; onToggle: () => void }
264
+ risk?: { counts: Record<VulnerabilityRiskFactor, number>; selected: VulnerabilityRiskFactor[]; seriousOnly: boolean; onChange: (next: VulnerabilityRiskFactor[]) => void }
265
+ /** Turns every filter here off in one change. */
266
+ onClearAll: () => void
267
+ }) {
268
+ if (!fixable && !endOfLife && !risk) return null
269
+ const on = (fixable?.on ? 1 : 0) + (endOfLife?.on ? 1 : 0) + (risk && risk.selected.length > 0 && !risk.seriousOnly ? 1 : 0)
270
+ const anyChecked = !!fixable?.on || !!endOfLife?.on || (risk?.selected.length ?? 0) > 0
271
+ const toggleRisk = (f: VulnerabilityRiskFactor) => {
272
+ if (!risk) return
273
+ const next = new Set(risk.selected)
274
+ if (next.has(f)) next.delete(f)
275
+ else next.add(f)
276
+ risk.onChange(RISK_ORDER.filter((x) => next.has(x)))
277
+ }
278
+ return (
279
+ <FilterDropdown label={moreFiltersLabel(on)} active={on > 0} panelLabel="More filters" width={296}>
280
+ {(close) => (
281
+ <>
282
+ {(fixable || endOfLife) && (
283
+ <ul className="py-1">
284
+ {fixable && <CheckRow label="Fix available" description="Only findings the scanner lists a fixed release for." checked={fixable.on} onChange={fixable.onToggle} />}
285
+ {endOfLife && <CheckRow label="OS end of life" count={endOfLife.count} description="Only images whose OS release Trivy reports as end of life. Images not scanned yet stay listed: their OS is unknown." checked={endOfLife.on} onChange={endOfLife.onToggle} />}
286
+ </ul>
287
+ )}
288
+ {risk && (
289
+ <div className={clsx((fixable || endOfLife) && 'border-t border-theme-border')}>
290
+ <p className="px-3 pb-0.5 pt-2 text-[11px] font-semibold uppercase tracking-wider text-theme-text-tertiary">Risk factors</p>
291
+ <ul className="max-h-80 overflow-y-auto pb-1">
292
+ {RISK_ORDER.map((f) => (
293
+ <CheckRow key={f} label={RISK_FACTORS[f].label} count={risk.counts[f]} checked={risk.selected.includes(f)} onChange={() => toggleRisk(f)} />
294
+ ))}
295
+ </ul>
296
+ </div>
297
+ )}
298
+ <div className="flex items-center justify-between border-t border-theme-border px-2 py-1.5 text-xs text-theme-text-secondary">
299
+ <button
300
+ type="button"
301
+ onClick={anyChecked ? onClearAll : undefined}
302
+ disabled={!anyChecked}
303
+ aria-label="Clear more filters"
304
+ className="flex items-center gap-1 rounded px-1.5 py-0.5 hover:bg-theme-hover disabled:opacity-50 disabled:hover:bg-transparent"
305
+ >
306
+ <X className="h-3 w-3" aria-hidden />
307
+ Clear all
308
+ </button>
309
+ <button type="button" onClick={close} className="rounded bg-theme-elevated px-2 py-0.5 text-[11px] text-theme-text-primary hover:bg-theme-hover">
310
+ Done
311
+ </button>
312
+ </div>
313
+ </>
314
+ )}
315
+ </FilterDropdown>
316
+ )
317
+ }
@@ -0,0 +1,54 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { ownerLookup, type VulnerabilityWorkloadOwner } from '../../api/vulnerabilities'
3
+ import { managerLabel, ownerTip, shortRepo, uncheckedReadsText } from './owner'
4
+
5
+ const helm: VulnerabilityWorkloadOwner = {
6
+ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web',
7
+ manager: { tool: 'helm', kind: 'HelmRelease', namespace: 'shop', name: 'web', chart: 'web-1.2.0' },
8
+ team: 'payments', teamFrom: 'workload',
9
+ }
10
+
11
+ describe('owner', () => {
12
+ it('finds a workload by its identity, whatever its container', () => {
13
+ const find = ownerLookup([helm])
14
+ expect(find({ kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'web' })).toBe(helm)
15
+ expect(find({ kind: 'Deployment', group: 'apps', namespace: 'other', name: 'web' })).toBeUndefined()
16
+ })
17
+
18
+ it('shortens repository addresses for a cell', () => {
19
+ expect(shortRepo('https://github.com/acme/deploy.git')).toBe('github.com/acme/deploy')
20
+ expect(shortRepo('git@github.com:acme/deploy.git')).toBe('github.com/acme/deploy')
21
+ expect(shortRepo('ssh://git@github.com/acme/fleet')).toBe('git@github.com/acme/fleet')
22
+ })
23
+
24
+ it('says what Radar knows and nothing when it knows nothing', () => {
25
+ expect(ownerTip(helm)).toBe('Deployed by Helm release shop/web, chart web-1.2.0. Team payments.')
26
+ expect(ownerTip({ ...helm, manager: { tool: 'argocd', kind: 'Application', group: 'argoproj.io', namespace: 'argocd', name: 'shop', sources: [{ repo: 'https://github.com/acme/deploy.git', path: 'apps' }] }, team: undefined }))
27
+ .toBe('Deployed by Argo CD Application argocd/shop, from github.com/acme/deploy (apps).')
28
+ expect(ownerTip({ ...helm, team: undefined, manager: { tool: 'argocd', kind: 'Application', group: 'argoproj.io', namespace: 'argocd', name: 'shop', shared: true, sources: [{ repo: 'https://charts.example.com' }, { repo: 'https://github.com/acme/deploy.git', path: 'apps' }] } }))
29
+ .toBe('Deployed by Argo CD Application argocd/shop, from charts.example.com, github.com/acme/deploy (apps). More than one Argo CD or Flux object manages it.')
30
+ expect(ownerTip({ ...helm, manager: undefined, team: undefined, managerUnknown: true })).toBe("Radar couldn't tell what deploys it.")
31
+ expect(ownerTip(undefined)).toBeUndefined()
32
+ expect(managerLabel({ tool: 'fluxcd', kind: 'Kustomization', namespace: 'f', name: 'x' })).toBe('Flux Kustomization')
33
+ })
34
+
35
+ it('says when the viewer\'s access kept Radar from checking, not that nothing was found', () => {
36
+ const unchecked = { ...helm, manager: undefined, team: undefined, managerUnknown: true, managerUnchecked: true }
37
+ expect(ownerTip(unchecked)).toBe("Radar couldn't check what deploys it with your access.")
38
+ expect(uncheckedReadsText([
39
+ { kind: 'Application', group: 'argoproj.io', partial: true },
40
+ { kind: 'Kustomization', group: 'kustomize.toolkit.fluxcd.io', partial: true },
41
+ { kind: 'HelmRelease', group: 'helm.toolkit.fluxcd.io', partial: true },
42
+ { kind: 'Namespace' },
43
+ ])).toBe("With your access, Radar couldn't read Argo CD Applications, Flux Kustomizations or Flux HelmReleases outside your namespaces. It also couldn't read namespaces, where a team label may be.")
44
+ expect(uncheckedReadsText([{ kind: 'Application', group: 'argoproj.io' }])).toBe("With your access, Radar couldn't read Argo CD Applications.")
45
+ expect(uncheckedReadsText([])).toBeUndefined()
46
+ expect(uncheckedReadsText(undefined)).toBeUndefined()
47
+ })
48
+
49
+ it('never uses an em dash in its copy', () => {
50
+ expect(ownerTip(helm)).not.toContain('—')
51
+ expect(ownerTip({ ...helm, manager: undefined, managerUnknown: true, managerUnchecked: true })).not.toContain('—')
52
+ expect(uncheckedReadsText([{ kind: 'Application', group: 'argoproj.io', partial: true }, { kind: 'Namespace' }])).not.toContain('—')
53
+ })
54
+ })