@skyhook-io/radar-app 1.20.3 → 1.21.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 (167) hide show
  1. package/package.json +10 -9
  2. package/src/App.tsx +67 -15
  3. package/src/api/client.audit-gating.test.tsx +105 -5
  4. package/src/api/client.auditBadgesSync.test.tsx +118 -0
  5. package/src/api/client.capabilitiesPoll.test.ts +61 -0
  6. package/src/api/client.ts +129 -5
  7. package/src/api/namespaceScopeRetry.test.ts +14 -0
  8. package/src/api/radarFeatures.ts +11 -0
  9. package/src/api/substrateHealth.ts +134 -0
  10. package/src/api/velero.test.ts +60 -0
  11. package/src/api/velero.ts +377 -0
  12. package/src/api/vulnerabilities.ts +313 -0
  13. package/src/components/NamespaceSwitcher.tsx +3 -1
  14. package/src/components/audit/AuditView.tsx +4 -0
  15. package/src/components/audit/ChecksViewTabs.test.tsx +35 -5
  16. package/src/components/audit/ChecksViewTabs.tsx +12 -1
  17. package/src/components/audit/Java4ShellPanel.test.tsx +31 -0
  18. package/src/components/audit/Java4ShellPanel.tsx +313 -0
  19. package/src/components/audit/UpgradeReadinessView.test.ts +35 -1
  20. package/src/components/audit/UpgradeReadinessView.tsx +60 -2
  21. package/src/components/audit/VulnerabilitiesView.tsx +944 -0
  22. package/src/components/cnpg/CNPGClusterTabs.tsx +3 -1
  23. package/src/components/cnpg/CNPGDrawerTrail.tsx +5 -26
  24. package/src/components/cnpg/CNPGInvestigationAction.test.tsx +27 -6
  25. package/src/components/cnpg/CNPGView.tsx +43 -117
  26. package/src/components/cnpg/CNPGWorkspace.compatibility.test.tsx +30 -0
  27. package/src/components/cnpg/host.tsx +2 -2
  28. package/src/components/cnpg/routes.ts +3 -1
  29. package/src/components/cnpg/shared.tsx +5 -53
  30. package/src/components/cnpg/useCNPGNavigate.ts +1 -21
  31. package/src/components/cnpg/useCNPGSidebarWorkspace.ts +16 -13
  32. package/src/components/community.tsx +42 -0
  33. package/src/components/diagnose/diagnoseEvidenceTypes.ts +2 -0
  34. package/src/components/diagnose/investigationMetrics.test.ts +20 -0
  35. package/src/components/diagnose/investigationMetrics.ts +2 -1
  36. package/src/components/dock/BottomDock.tsx +1 -0
  37. package/src/components/dock/LogsTab.tsx +3 -0
  38. package/src/components/gitops/FluxOperatorCard.test.tsx +37 -0
  39. package/src/components/gitops/FluxOperatorCard.tsx +27 -0
  40. package/src/components/gitops/GitOpsView.rowsSummary.test.tsx +59 -0
  41. package/src/components/gitops/GitOpsView.tsx +8 -5
  42. package/src/components/gitops/gitopsRowEvents.test.ts +48 -0
  43. package/src/components/gitops/gitopsRowEvents.ts +31 -0
  44. package/src/components/helm/HelmDrawerFrame.tsx +1 -1
  45. package/src/components/helm/HelmView.tsx +20 -16
  46. package/src/components/helm/OwnedResources.tsx +4 -3
  47. package/src/components/home/ClusterHealthCard.tsx +3 -1
  48. package/src/components/home/HomeAgentBlock.tsx +3 -0
  49. package/src/components/home/HomeView.tsx +7 -0
  50. package/src/components/home/MCPSetupDialog.test.tsx +19 -12
  51. package/src/components/home/MCPSetupDialog.tsx +4 -2
  52. package/src/components/home/mcpToolCatalog.ts +15 -2
  53. package/src/components/home/useVulnerabilitiesRow.test.ts +26 -0
  54. package/src/components/home/useVulnerabilitiesRow.ts +50 -0
  55. package/src/components/logs/LogsViewer.tsx +3 -1
  56. package/src/components/logs/MultiPodLogsTab.test.tsx +24 -4
  57. package/src/components/logs/MultiPodLogsTab.tsx +9 -5
  58. package/src/components/nav/PrimaryNavRail.test.tsx +17 -0
  59. package/src/components/nav/PrimaryNavRail.tsx +174 -29
  60. package/src/components/resource/PrometheusChartsGrid.tsx +5 -1
  61. package/src/components/resource/SubstrateHealthCharts.test.tsx +143 -0
  62. package/src/components/resource/SubstrateHealthCharts.tsx +254 -0
  63. package/src/components/resource/SubstrateVerdictLine.test.tsx +131 -0
  64. package/src/components/resource/SubstrateVerdictLine.tsx +180 -0
  65. package/src/components/resources/ResourcesView.tsx +12 -6
  66. package/src/components/resources/renderers/UpgradePlanRenderer.test.tsx +20 -0
  67. package/src/components/resources/renderers/UpgradePlanRenderer.tsx +22 -0
  68. package/src/components/resources/renderers/VeleroBackupRenderer.tsx +16 -36
  69. package/src/components/resources/renderers/VeleroRestoreRenderer.tsx +6 -19
  70. package/src/components/resources/renderers/WorkloadRenderer.tsx +8 -0
  71. package/src/components/rightsizing/RightsizingScanView.tsx +3 -2
  72. package/src/components/shared/LargeClusterNamespacePicker.test.tsx +27 -0
  73. package/src/components/shared/LargeClusterNamespacePicker.tsx +8 -2
  74. package/src/components/timeline/TimelineView.tsx +3 -1
  75. package/src/components/traffic/TrafficConnectionsTable.test.tsx +94 -0
  76. package/src/components/traffic/TrafficConnectionsTable.tsx +21 -5
  77. package/src/components/traffic/TrafficData.test.tsx +37 -0
  78. package/src/components/traffic/TrafficData.tsx +27 -0
  79. package/src/components/traffic/TrafficFlowList.tsx +9 -7
  80. package/src/components/traffic/TrafficGraph.layoutEngine.test.tsx +193 -0
  81. package/src/components/traffic/TrafficGraph.test.tsx +269 -0
  82. package/src/components/traffic/TrafficGraph.tsx +135 -64
  83. package/src/components/traffic/TrafficGraphUnavailable.tsx +57 -0
  84. package/src/components/traffic/TrafficView.layoutUnavailable.test.tsx +211 -0
  85. package/src/components/traffic/TrafficView.tsx +46 -129
  86. package/src/components/traffic/trafficFilters.test.ts +172 -1
  87. package/src/components/traffic/trafficFilters.ts +139 -0
  88. package/src/components/ui/DiagnosticsOverlay.tsx +14 -1
  89. package/src/components/ui/UpdateNotification.manual.test.tsx +5 -2
  90. package/src/components/ui/UpdateNotification.test.tsx +31 -2
  91. package/src/components/ui/UpdateNotification.tsx +34 -17
  92. package/src/components/ui/command-items.ts +24 -1
  93. package/src/components/velero/VeleroBackupNow.test.tsx +165 -0
  94. package/src/components/velero/VeleroBackupNow.tsx +143 -0
  95. package/src/components/velero/VeleroDeleteBackup.test.tsx +364 -0
  96. package/src/components/velero/VeleroDeleteBackup.tsx +306 -0
  97. package/src/components/velero/VeleroDetailPage.tsx +158 -0
  98. package/src/components/velero/VeleroKindLists.test.tsx +48 -0
  99. package/src/components/velero/VeleroKindLists.tsx +43 -0
  100. package/src/components/velero/VeleroLocations.expand.test.tsx +27 -0
  101. package/src/components/velero/VeleroLocations.test.tsx +86 -0
  102. package/src/components/velero/VeleroLocations.tsx +240 -0
  103. package/src/components/velero/VeleroOverview.test.tsx +311 -0
  104. package/src/components/velero/VeleroOverview.tsx +485 -0
  105. package/src/components/velero/VeleroPages.test.tsx +516 -0
  106. package/src/components/velero/VeleroPages.tsx +1056 -0
  107. package/src/components/velero/VeleroRunArtifacts.test.tsx +241 -0
  108. package/src/components/velero/VeleroRunArtifacts.tsx +112 -0
  109. package/src/components/velero/VeleroRunLists.tsx +309 -0
  110. package/src/components/velero/VeleroRunMessagesHost.test.tsx +25 -0
  111. package/src/components/velero/VeleroRunMessagesHost.tsx +54 -0
  112. package/src/components/velero/VeleroRunVolumes.test.tsx +247 -0
  113. package/src/components/velero/VeleroRunVolumes.tsx +122 -0
  114. package/src/components/velero/VeleroSchedulePause.test.tsx +211 -0
  115. package/src/components/velero/VeleroSchedulePause.tsx +191 -0
  116. package/src/components/velero/VeleroScheduleStatusBadge.test.tsx +28 -0
  117. package/src/components/velero/VeleroScheduleStatusBadge.tsx +21 -0
  118. package/src/components/velero/VeleroSchedules.tsx +255 -0
  119. package/src/components/velero/VeleroView.tsx +59 -0
  120. package/src/components/velero/VeleroWorkspace.gate.test.tsx +97 -0
  121. package/src/components/velero/attention.test.ts +178 -0
  122. package/src/components/velero/attention.ts +281 -0
  123. package/src/components/velero/backupDelete.test.tsx +91 -0
  124. package/src/components/velero/backupDelete.tsx +182 -0
  125. package/src/components/velero/coverage.test.ts +87 -0
  126. package/src/components/velero/coverage.ts +150 -0
  127. package/src/components/velero/host.tsx +92 -0
  128. package/src/components/velero/routes.ts +78 -0
  129. package/src/components/velero/runs.tsx +121 -0
  130. package/src/components/velero/shared.test.ts +84 -0
  131. package/src/components/velero/shared.tsx +423 -0
  132. package/src/components/velero/useVeleroSidebarWorkspace.test.tsx +28 -0
  133. package/src/components/velero/useVeleroSidebarWorkspace.ts +71 -0
  134. package/src/components/velero/velero.fixtures.ts +61 -0
  135. package/src/components/velero/workspaceRoute.ts +21 -0
  136. package/src/components/vulnerabilities/WorkloadVulnerabilitiesSection.tsx +179 -0
  137. package/src/components/vulnerabilities/parts.test.ts +72 -0
  138. package/src/components/vulnerabilities/parts.tsx +291 -0
  139. package/src/components/whats-new/WhatsNewDialog.test.tsx +6 -4
  140. package/src/components/whats-new/releaseNotes.ts +67 -1
  141. package/src/components/workload/WorkloadView.tsx +64 -27
  142. package/src/components/workspace/DrawerTrailBack.tsx +32 -0
  143. package/src/components/workspace/WorkspaceFrame.tsx +71 -0
  144. package/src/components/workspace/coverage.ts +61 -0
  145. package/src/components/workspace/layout.test.tsx +29 -1
  146. package/src/components/workspace/layout.tsx +15 -5
  147. package/src/components/workspace/sidebar.ts +9 -0
  148. package/src/components/workspace/useWorkspaceDrawer.ts +63 -0
  149. package/src/components/workspace/useWorkspaceNavigate.ts +21 -0
  150. package/src/desktop/AboutDialog.test.ts +12 -0
  151. package/src/desktop/AboutDialog.tsx +151 -0
  152. package/src/desktop/WindowsTitleBar.tsx +359 -0
  153. package/src/desktop/titleBar.test.ts +61 -0
  154. package/src/desktop/titleBar.ts +45 -0
  155. package/src/index.css +19 -0
  156. package/src/integrations/resourceHost.ts +5 -1
  157. package/src/integrations/resourceHosts.test.tsx +14 -2
  158. package/src/integrations/resourceHosts.tsx +22 -6
  159. package/src/integrations/workspaceRoute.ts +1 -1
  160. package/src/integrations/workspaceRoutes.test.ts +11 -0
  161. package/src/integrations/workspaceRoutes.ts +3 -1
  162. package/src/integrations/workspaceScreens.tsx +2 -0
  163. package/src/main.tsx +8 -0
  164. package/src/utils/desktop-zoom.test.ts +53 -0
  165. package/src/utils/desktop-zoom.ts +30 -0
  166. package/src/utils/staleAssetPrompt.test.tsx +76 -0
  167. package/src/utils/staleAssetPrompt.tsx +32 -0
@@ -1,5 +1,5 @@
1
- import type { ComponentType } from "react";
2
- import type { ReactNode } from "react";
1
+ import type { ComponentType, ReactNode, RefObject } from "react";
2
+ import { useLayoutEffect, useRef, useState } from "react";
3
3
  import {
4
4
  Home,
5
5
  Network,
@@ -23,6 +23,11 @@ import { clsx } from "clsx";
23
23
  import type { MainView } from "../../types";
24
24
  import { Tooltip } from "../ui/Tooltip";
25
25
  import { assetUrl } from "@skyhook-io/k8s-ui";
26
+ import {
27
+ COMMUNITY_HINT,
28
+ SLACK_COLORS_ON_ROW_HOVER,
29
+ SlackIcon,
30
+ } from "../community";
26
31
 
27
32
  const radarLogoUrl = assetUrl("/images/radar/radar-icon.svg");
28
33
 
@@ -103,6 +108,7 @@ interface PrimaryNavRailProps {
103
108
  whatsNew?: { unread: boolean; onOpen: () => void };
104
109
  // Present during the Product Hunt launch: the launch card opens from it.
105
110
  productHunt?: { onOpen: () => void; id: string; badge: string };
111
+ communityUrl?: string;
106
112
  }
107
113
 
108
114
  export function PrimaryNavRail({
@@ -115,9 +121,21 @@ export function PrimaryNavRail({
115
121
  accountSlot,
116
122
  whatsNew,
117
123
  productHunt,
124
+ communityUrl,
118
125
  }: PrimaryNavRailProps) {
126
+ const asideRef = useRef<HTMLElement>(null);
127
+ const communityRef = useRef<HTMLDivElement>(null);
128
+ const navRef = useRef<HTMLElement>(null);
129
+ const communityFits = useSlimRailRoomFor(
130
+ asideRef,
131
+ communityRef,
132
+ navRef,
133
+ !pinned && !!communityUrl,
134
+ [showPinToggle],
135
+ );
119
136
  return (
120
137
  <aside
138
+ ref={asideRef}
121
139
  aria-label="Primary navigation"
122
140
  className={clsx(
123
141
  // Dedicated sidebar token = the DEEPEST layer of the elevation scale, so
@@ -142,6 +160,7 @@ export function PrimaryNavRail({
142
160
  in slim mode. The slim short-window case is doubly-rare (slim is
143
161
  width-triggered) and yields to keeping fly-outs intact. */}
144
162
  <nav
163
+ ref={navRef}
145
164
  className={clsx(
146
165
  "flex flex-col gap-0.5 pt-3 px-2",
147
166
  pinned && "flex-1 min-h-0 overflow-y-auto",
@@ -158,7 +177,7 @@ export function PrimaryNavRail({
158
177
  ))}
159
178
  </nav>
160
179
 
161
- {!pinned && <div className="flex-1" />}
180
+ {!pinned && <div data-rail-spacer className="flex-1" />}
162
181
 
163
182
  {/* "Me & my tools" — account + settings, the conventional rail-bottom
164
183
  cluster (VS Code / Discord / ArgoCD / Radar Cloud's own UserOrgMenu).
@@ -185,6 +204,21 @@ export function PrimaryNavRail({
185
204
  unread={whatsNew.unread}
186
205
  />
187
206
  )}
207
+ {/* Yields first on a short slim rail (useSlimRailRoomFor); ⌘K and
208
+ Diagnostics still link the community. */}
209
+ {communityUrl && (
210
+ <div ref={communityRef} hidden={!pinned && !communityFits}>
211
+ <RailActionRow
212
+ icon={SlackIcon}
213
+ label="Community"
214
+ ariaLabel="Radar community on Slack"
215
+ hint={COMMUNITY_HINT}
216
+ iconHoverClassName={SLACK_COLORS_ON_ROW_HOVER}
217
+ pinned={pinned}
218
+ href={communityUrl}
219
+ />
220
+ </div>
221
+ )}
188
222
  {onOpenSettings && (
189
223
  <RailActionRow
190
224
  icon={Settings}
@@ -235,6 +269,54 @@ export function PrimaryNavRail({
235
269
  );
236
270
  }
237
271
 
272
+ // The slim rail can't scroll (see the nav comment), so an optional row renders
273
+ // only while everything else still fits with it; otherwise it would push
274
+ // Settings and the pin toggle off-screen. It measures the rail as rendered,
275
+ // because the rows vary (the account row only with auth, launch-window rows)
276
+ // and so does the room (the Windows desktop title bar sits inside the page).
277
+ // The row's own height is left out of the measurement so hiding it can't flip
278
+ // the answer back. Every length is read from rendered boxes, so the comparison
279
+ // holds under the desktop app's body zoom and any root font size; the row's
280
+ // size comes from two consecutive main-nav rows, which share its h-9 and
281
+ // gap-0.5.
282
+ function useSlimRailRoomFor(
283
+ asideRef: RefObject<HTMLElement | null>,
284
+ rowRef: RefObject<HTMLElement | null>,
285
+ sampleRowsRef: RefObject<HTMLElement | null>,
286
+ active: boolean,
287
+ deps: unknown[],
288
+ ): boolean {
289
+ const [fits, setFits] = useState(true);
290
+ useLayoutEffect(() => {
291
+ const aside = asideRef.current;
292
+ if (!active || !aside || typeof ResizeObserver === "undefined") {
293
+ setFits(true);
294
+ return;
295
+ }
296
+ const measure = () => {
297
+ const [first, second] = Array.from(sampleRowsRef.current?.children ?? []);
298
+ if (!first || !second) return;
299
+ const rowPx =
300
+ second.getBoundingClientRect().top - first.getBoundingClientRect().top;
301
+ let used = 0;
302
+ for (const child of Array.from(aside.children)) {
303
+ if (child instanceof HTMLElement && "railSpacer" in child.dataset)
304
+ continue;
305
+ used += child.getBoundingClientRect().height;
306
+ }
307
+ if (rowRef.current && !rowRef.current.hidden) used -= rowPx;
308
+ setFits(used + rowPx <= aside.getBoundingClientRect().height);
309
+ };
310
+ measure();
311
+ const observer = new ResizeObserver(measure);
312
+ observer.observe(aside);
313
+ for (const child of Array.from(aside.children)) observer.observe(child);
314
+ return () => observer.disconnect();
315
+ // eslint-disable-next-line react-hooks/exhaustive-deps
316
+ }, [active, ...deps]);
317
+ return fits;
318
+ }
319
+
238
320
  function BrandRow({
239
321
  pinned,
240
322
  onNavigate,
@@ -358,54 +440,112 @@ function NavRailItem({
358
440
  }
359
441
 
360
442
  // A rail-bottom action row — same icon-column + fly-out treatment as NavRailItem
361
- // but it's an action (onClick), not navigation, so no active-state/accent bar.
443
+ // but it's an action (onClick) or an external link (href), not navigation, so
444
+ // no active-state/accent bar.
362
445
  // Exported so the account control (UserMenu rail variant) can match the look.
363
446
  export function RailActionRow({
364
447
  icon: Icon,
365
448
  label,
449
+ ariaLabel,
366
450
  pinned,
367
451
  onClick,
452
+ href,
368
453
  unread = false,
369
454
  iconClassName,
455
+ iconHoverClassName,
456
+ hint,
370
457
  id,
371
458
  badge,
372
459
  }: {
373
460
  icon: ComponentType<{ className?: string }>;
374
461
  label: string;
462
+ ariaLabel?: string;
375
463
  pinned: boolean;
376
- onClick: () => void;
377
464
  unread?: boolean;
378
465
  iconClassName?: string;
466
+ // Added to the default icon classes rather than replacing them.
467
+ iconHoverClassName?: string;
468
+ // A line under the label: in the fly-out when slim, a tooltip when pinned.
469
+ hint?: string;
379
470
  id?: string;
380
471
  // A small tilted tag on the corner, for an item that's only here for now.
381
472
  badge?: string;
382
- }) {
383
- return (
384
- <div className={clsx("group/item relative", !pinned && "w-10")}>
385
- <button
386
- type="button"
387
- id={id}
388
- onClick={onClick}
473
+ } & (
474
+ { onClick: () => void; href?: never } | { href: string; onClick?: never }
475
+ )) {
476
+ const rowClassName = clsx(
477
+ "relative flex h-9 w-full items-center rounded-md text-sm font-medium text-theme-text-secondary hover:bg-theme-hover hover:text-theme-text-primary transition-colors",
478
+ !pinned && "max-w-10 overflow-hidden",
479
+ );
480
+ const content = (
481
+ <>
482
+ <span className="relative flex w-10 shrink-0 items-center justify-center">
483
+ <Icon
484
+ className={clsx(
485
+ "w-[18px] h-[18px]",
486
+ iconClassName ??
487
+ clsx(
488
+ "group-hover/item:text-theme-text-secondary",
489
+ unread ? "text-accent" : "text-theme-text-tertiary",
490
+ ),
491
+ iconHoverClassName,
492
+ )}
493
+ />
494
+ {unread && (
495
+ <span
496
+ aria-hidden
497
+ className="absolute top-1.5 right-2 h-2 w-2 rounded-full bg-accent ring-2 ring-theme-sidebar"
498
+ />
499
+ )}
500
+ </span>
501
+ <span
389
502
  className={clsx(
390
- "relative flex h-9 w-full items-center rounded-md text-sm font-medium text-theme-text-secondary hover:bg-theme-hover hover:text-theme-text-primary transition-colors",
391
- !pinned && "max-w-10 overflow-hidden",
503
+ "pr-3 truncate",
504
+ !pinned && "opacity-0",
505
+ unread && "text-theme-text-primary",
392
506
  )}
393
507
  >
394
- <span className="relative flex w-10 shrink-0 items-center justify-center">
395
- <Icon className={clsx(
396
- "w-[18px] h-[18px]",
397
- iconClassName ?? clsx("group-hover/item:text-theme-text-secondary", unread ? "text-accent" : "text-theme-text-tertiary"),
398
- )} />
399
- {unread && (
400
- <span aria-hidden className="absolute top-1.5 right-2 h-2 w-2 rounded-full bg-accent ring-2 ring-theme-sidebar" />
401
- )}
402
- </span>
403
- <span className={clsx("pr-3 truncate", !pinned && "opacity-0", unread && "text-theme-text-primary")}>
404
- {label}
405
- {badge && <span className="sr-only"> ({badge})</span>}
406
- {unread && <span className="sr-only"> (unread)</span>}
407
- </span>
408
- </button>
508
+ {label}
509
+ {badge && <span className="sr-only"> ({badge})</span>}
510
+ {unread && <span className="sr-only"> (unread)</span>}
511
+ </span>
512
+ </>
513
+ );
514
+ const row = href ? (
515
+ <a
516
+ id={id}
517
+ href={href}
518
+ target="_blank"
519
+ rel="noopener noreferrer"
520
+ aria-label={ariaLabel}
521
+ className={rowClassName}
522
+ >
523
+ {content}
524
+ </a>
525
+ ) : (
526
+ <button
527
+ type="button"
528
+ id={id}
529
+ onClick={onClick}
530
+ aria-label={ariaLabel}
531
+ className={rowClassName}
532
+ >
533
+ {content}
534
+ </button>
535
+ );
536
+ return (
537
+ <div className={clsx("group/item relative", !pinned && "w-10")}>
538
+ {pinned && hint ? (
539
+ <Tooltip
540
+ content={hint}
541
+ position="right"
542
+ wrapperClassName="!block w-full"
543
+ >
544
+ {row}
545
+ </Tooltip>
546
+ ) : (
547
+ row
548
+ )}
409
549
  {badge && (
410
550
  <span
411
551
  aria-hidden
@@ -420,6 +560,11 @@ export function RailActionRow({
420
560
  className="pointer-events-none absolute left-full top-1/2 z-50 ml-1 hidden -translate-y-1/2 whitespace-nowrap rounded-md border border-theme-border bg-theme-hover px-2.5 py-1 text-[13px] font-medium text-theme-text-primary opacity-0 shadow-lg shadow-black/30 transition-opacity duration-75 group-hover/item:block group-hover/item:opacity-100"
421
561
  >
422
562
  {label}
563
+ {hint && (
564
+ <span className="block w-56 whitespace-normal text-xs font-normal text-theme-text-secondary">
565
+ {hint}
566
+ </span>
567
+ )}
423
568
  </span>
424
569
  )}
425
570
  </div>
@@ -1,3 +1,4 @@
1
+ import { clsx } from "clsx";
1
2
  import { useMemo } from "react";
2
3
  import { useSearchParams } from "react-router-dom";
3
4
  import { Loader2, Wifi, WifiOff } from "lucide-react";
@@ -46,6 +47,8 @@ export interface PrometheusChartsGridProps {
46
47
  name: string;
47
48
  /** Optional full K8s resource for request/limit overlay derivation. */
48
49
  resource?: any;
50
+ /** Fill and scroll its container (default). False lets the parent scroll it with content below. */
51
+ fill?: boolean;
49
52
  }
50
53
 
51
54
  const SUPPORTED_KINDS = new Set([
@@ -64,6 +67,7 @@ export function PrometheusChartsGrid({
64
67
  namespace,
65
68
  name,
66
69
  resource,
70
+ fill = true,
67
71
  }: PrometheusChartsGridProps) {
68
72
  useAutoPromConnect();
69
73
  const { data: status, isLoading: statusLoading } = usePrometheusStatus();
@@ -192,7 +196,7 @@ export function PrometheusChartsGrid({
192
196
  </select>;
193
197
 
194
198
  return (
195
- <div className="flex flex-col min-w-0 w-full h-full overflow-auto">
199
+ <div className={clsx("flex flex-col min-w-0 w-full", fill && "h-full overflow-auto")}>
196
200
  {!isWorkload && <div className="flex shrink-0 items-center justify-between gap-3 px-4 pt-3">{rangeControl}</div>}
197
201
 
198
202
  {isWorkload && (
@@ -0,0 +1,143 @@
1
+ import { renderToStaticMarkup } from 'react-dom/server'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+ import type { SubstrateHealth } from '../../api/substrateHealth'
4
+
5
+ let health: { data?: SubstrateHealth; error?: unknown; upgrade?: unknown; blockedReason?: string; support?: string } = {}
6
+ let promStatus: { connected: boolean; discovering?: boolean; error?: string } = { connected: true }
7
+
8
+ vi.mock('../../api/client', async (orig) => ({
9
+ ...(await orig<typeof import('../../api/client')>()),
10
+ useAutoPromConnect: () => {},
11
+ usePrometheusStatus: () => ({ data: promStatus }),
12
+ usePrometheusConnect: () => ({ mutate: () => {}, isPending: false }),
13
+ }))
14
+ vi.mock('../../api/substrateHealth', async (orig) => ({
15
+ ...(await orig<typeof import('../../api/substrateHealth')>()),
16
+ useSubstrateHealth: () => health,
17
+ }))
18
+
19
+ const { SubstrateHealthCharts } = await import('./SubstrateHealthCharts')
20
+ const { ApiError } = await import('../../api/client')
21
+
22
+ const pool = { kind: 'workerpool' as const, namespace: 'agents', name: 'pool' }
23
+ const node = { kind: 'node' as const, name: 'worker-1' }
24
+ const base = { range: '1h', start: 1000, end: 4600, stepSeconds: 60, charts: [] }
25
+ const render = (target: typeof pool | typeof node) => renderToStaticMarkup(<SubstrateHealthCharts target={target} />)
26
+
27
+ function chart(overrides: Partial<SubstrateHealth['charts'][number]>): SubstrateHealth['charts'][number] {
28
+ return {
29
+ id: 'workers', title: 'Workers by state', unit: 'workers', population: 'Every worker Pod.', source: 'ate_workerpool_workers',
30
+ state: 'ok', isolation: { mode: 'unverified', note: 'Radar couldn\'t confirm these series belong to this exact cluster' },
31
+ series: [
32
+ { labels: { series: 'idle (gvisor)' }, dataPoints: [{ timestamp: 4600, value: 1.5 }] },
33
+ { labels: { series: 'partial (gvisor)' }, dataPoints: [{ timestamp: 4600, value: 1.5 }] },
34
+ ],
35
+ ...overrides,
36
+ }
37
+ }
38
+
39
+ describe('SubstrateHealthCharts', () => {
40
+ it('offers to connect Prometheus only where it is the whole tab', () => {
41
+ promStatus = { connected: false }
42
+ health = {}
43
+ expect(render(pool)).toBe('')
44
+ expect(renderToStaticMarkup(<SubstrateHealthCharts target={pool} standalone />)).toContain('Discover Prometheus')
45
+ promStatus = { connected: true }
46
+ })
47
+
48
+ it('says why there are no charts when Radar support could not be checked', () => {
49
+ health = { blockedReason: "Couldn't check this cluster's Radar support. Refresh to try again." }
50
+ expect(render(pool)).toContain('Refresh to try again')
51
+ expect(render(node)).toBe('')
52
+ })
53
+
54
+ it('shows a metrics error even when a capabilities refresh failed after support was known', () => {
55
+ health = { support: 'supported', blockedReason: "Couldn't check this cluster's Radar support. Refresh to try again.", error: new Error('Prometheus timed out') }
56
+ expect(render(pool)).toContain('Prometheus timed out')
57
+ expect(render(pool)).not.toContain('Refresh to try again')
58
+ })
59
+
60
+ it('says what it looked for when a pool has no Substrate series', () => {
61
+ health = { data: { ...base, status: 'notFound' } }
62
+ expect(render(pool)).toContain('Prometheus has no Agent Substrate metrics for this pool')
63
+ })
64
+
65
+ it('says a pool reports no worker Pods, without the metric-naming hint', () => {
66
+ health = { data: { ...base, status: 'notFound' } }
67
+ const none = renderToStaticMarkup(<SubstrateHealthCharts target={pool} workerPods={0} />)
68
+ expect(none).toContain('The controller reports 0 worker Pods for this pool')
69
+ expect(none).not.toContain('underscore names')
70
+ expect(renderToStaticMarkup(<SubstrateHealthCharts target={pool} workerPods={2} />)).toContain('underscore names')
71
+ })
72
+
73
+ it('stays out of the way on a node that runs no Substrate', () => {
74
+ health = { data: { ...base, status: 'notFound' } }
75
+ expect(render(node)).toBe('')
76
+ health = { data: { ...base, status: 'notOnNode' } }
77
+ expect(render(node)).toBe('')
78
+ })
79
+
80
+ it('explains a node whose series cannot be attributed', () => {
81
+ health = { data: { ...base, status: 'notAttributable', reason: 'atelet\'s series carry no node label' } }
82
+ expect(render(node)).toContain('carry no node label')
83
+ })
84
+
85
+ it('shows a denial instead of an empty chart', () => {
86
+ health = { error: new ApiError('forbidden', 403) }
87
+ expect(render(pool)).toContain('You don&#x27;t have access to these metrics')
88
+ })
89
+
90
+ it('keeps unrounded values readable and explains charts it cannot draw', () => {
91
+ health = { data: { ...base, status: 'available', charts: [
92
+ chart({}),
93
+ chart({ id: 'resumeTime', title: 'Resume time', state: 'duplicateSources', reason: 'reported through more than one scrape job (a, b)', series: [] }),
94
+ ] } }
95
+ const html = render(pool)
96
+ // Each line's latest value sits in its legend entry, unrounded.
97
+ expect(html).toMatch(/idle \(gvisor\)<\/span><span class="tabular-nums[^"]*">1\.5</)
98
+ expect(html).toMatch(/partial \(gvisor\)<\/span><span class="tabular-nums[^"]*">1\.5</)
99
+ expect(html).toContain('Not shown: reported through more than one scrape job (a, b).')
100
+ expect(html).toContain('Aggregates: Substrate keeps actor names out')
101
+ expect(html).toContain('confirm these series belong to this exact cluster')
102
+ })
103
+
104
+ it('collapses among drawer sections, but is a plain heading on a Metrics tab', () => {
105
+ health = { data: { ...base, status: 'available', charts: [chart({})] } }
106
+ expect(render(pool)).toContain('aria-expanded')
107
+ const tab = renderToStaticMarkup(<SubstrateHealthCharts target={pool} collapsible={false} />)
108
+ expect(tab).not.toContain('aria-expanded')
109
+ expect(tab).toContain('Agent Substrate · last 1h')
110
+ })
111
+
112
+ it('states a reason shared by several charts once', () => {
113
+ const refused = { state: 'duplicateSources' as const, reason: 'reported through more than one scrape job (a, b)', series: [] }
114
+ health = { data: { ...base, status: 'available', charts: [
115
+ chart({ id: 'resumeTime', title: 'Resume time', ...refused }),
116
+ chart({ id: 'crashes', title: 'Actor crashes', ...refused }),
117
+ ] } }
118
+ const html = render(pool)
119
+ expect(html).toContain('Resume time · Actor crashes')
120
+ expect(html.split('more than one scrape job').length - 1).toBe(1)
121
+ })
122
+ it('does not call an hour-old sample "now"', () => {
123
+ health = { data: { ...base, status: 'available', charts: [chart({ series: [
124
+ { labels: { series: 'idle (gvisor)' }, dataPoints: [{ timestamp: 1000, value: 2 }, { timestamp: 4600, value: null }] },
125
+ { labels: { series: 'partial (gvisor)' }, dataPoints: [{ timestamp: 1000, value: 1 }] },
126
+ ] })] } }
127
+ expect(render(pool)).not.toMatch(/<\/span><span class="tabular-nums/)
128
+ })
129
+
130
+ it('says when samples begin only when they begin well after the range', () => {
131
+ const late = new Date(4000 * 1000).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
132
+ // Gaps and non-finite values before the first sample don't count; a zero does.
133
+ health = { data: { ...base, status: 'available', charts: [chart({ series: [
134
+ { labels: { series: 'idle (gvisor)' }, dataPoints: [{ timestamp: 1000, value: null }, { timestamp: 4000, value: 0 }] },
135
+ { labels: { series: 'partial (gvisor)' }, dataPoints: [{ timestamp: 4300, value: 1 }] },
136
+ ] })] } }
137
+ expect(render(pool)).toContain(`No samples before ${late}.`)
138
+ health = { data: { ...base, status: 'available', charts: [chart({ series: [
139
+ { labels: { series: 'idle (gvisor)' }, dataPoints: [{ timestamp: 1060, value: 2 }, { timestamp: 4600, value: 2 }] },
140
+ ] })] } }
141
+ expect(render(pool)).not.toContain('No samples before')
142
+ })
143
+ })