@skyhook-io/radar-app 1.21.6 → 1.21.8

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 (118) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -7
  3. package/src/App.tsx +31 -4
  4. package/src/RadarApp.tsx +8 -2
  5. package/src/api/client.discoverMetrics.test.tsx +69 -0
  6. package/src/api/client.issueCorrelation.test.tsx +244 -0
  7. package/src/api/client.issueRowChanges.test.tsx +129 -0
  8. package/src/api/client.pendingOwnership.test.tsx +197 -0
  9. package/src/api/client.prometheusStatus.test.ts +4 -0
  10. package/src/api/client.restartError.test.ts +36 -1
  11. package/src/api/client.stopWorkflow.test.tsx +133 -0
  12. package/src/api/client.submitWorkflowTemplate.test.tsx +127 -0
  13. package/src/api/client.ts +582 -114
  14. package/src/api/connectionBinding.test.tsx +3 -1
  15. package/src/api/connectionBinding.ts +14 -2
  16. package/src/api/gitOpsPermissions.render.test.tsx +155 -0
  17. package/src/api/gitOpsPermissions.test.ts +90 -0
  18. package/src/api/gitOpsPermissions.ts +51 -0
  19. package/src/api/httpErrors.test.ts +30 -1
  20. package/src/api/httpErrors.ts +17 -0
  21. package/src/api/openobserveSetup.ts +85 -0
  22. package/src/api/podDebug.test.tsx +137 -0
  23. package/src/api/podDebug.ts +82 -0
  24. package/src/api/prometheusCharts.test.ts +23 -0
  25. package/src/api/prometheusCharts.ts +25 -0
  26. package/src/api/radarFeatures.render.test.tsx +43 -2
  27. package/src/api/radarFeatures.test.ts +18 -1
  28. package/src/api/radarFeatures.ts +17 -4
  29. package/src/api/reviewedActionMutation.ts +9 -2
  30. package/src/api/workloadMetrics.ts +2 -0
  31. package/src/components/NamespaceSwitcher.tsx +6 -2
  32. package/src/components/applications/ApplicationsView.identity.test.ts +35 -7
  33. package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
  34. package/src/components/applications/ApplicationsView.tsx +127 -173
  35. package/src/components/cnpg/CNPGOperatorConditions.test.tsx +3 -0
  36. package/src/components/cnpg/CNPGOperatorConditions.tsx +4 -14
  37. package/src/components/cnpg/host.test.tsx +1 -1
  38. package/src/components/cnpg/host.tsx +0 -2
  39. package/src/components/dock/BottomDock.tsx +7 -3
  40. package/src/components/dock/MissingShellDebug.test.tsx +193 -0
  41. package/src/components/dock/MissingShellDebug.tsx +114 -0
  42. package/src/components/dock/PodDebugSession.test.tsx +60 -0
  43. package/src/components/dock/PodDebugSession.tsx +96 -0
  44. package/src/components/dock/TerminalTab.test.tsx +48 -4
  45. package/src/components/dock/TerminalTab.tsx +47 -25
  46. package/src/components/dock/WorkloadLogsTab.test.tsx +24 -1
  47. package/src/components/dock/WorkloadLogsTab.tsx +16 -0
  48. package/src/components/execution/BatchExecutionView.command.test.tsx +69 -0
  49. package/src/components/execution/BatchExecutionView.tsx +88 -5
  50. package/src/components/execution/BatchExecutionView.workflow-stop.test.tsx +69 -0
  51. package/src/components/execution/WorkflowRunStopAction.tsx +8 -0
  52. package/src/components/gitops/GitOpsPermissionRowActions.test.tsx +100 -0
  53. package/src/components/gitops/GitOpsPermissionRowActions.tsx +27 -0
  54. package/src/components/gitops/GitOpsView.identity.test.tsx +1 -0
  55. package/src/components/gitops/GitOpsView.permissions.test.tsx +102 -0
  56. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +95 -7
  57. package/src/components/gitops/GitOpsView.tsx +93 -32
  58. package/src/components/helm/OwnedResources.tsx +1 -0
  59. package/src/components/home/HomeView.tsx +9 -1
  60. package/src/components/home/ProblemsPanel.investigate.test.tsx +12 -2
  61. package/src/components/home/mcpToolCatalog.ts +1 -0
  62. package/src/components/issues/IssuesPane.render.test.tsx +78 -2
  63. package/src/components/issues/IssuesPane.tsx +49 -6
  64. package/src/components/issues/useIssueExpansion.ts +91 -0
  65. package/src/components/resource/MetricsNotConnected.test.tsx +50 -0
  66. package/src/components/resource/MetricsNotConnected.tsx +114 -0
  67. package/src/components/resource/PVCUsageBar.tsx +2 -1
  68. package/src/components/resource/PrometheusCharts.render.test.tsx +47 -0
  69. package/src/components/resource/PrometheusCharts.tsx +14 -2
  70. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +91 -1
  71. package/src/components/resource/PrometheusChartsGrid.tsx +28 -52
  72. package/src/components/resource/RestartChart.tsx +4 -3
  73. package/src/components/resource/RightsizingPanel.source.test.tsx +34 -0
  74. package/src/components/resource/RightsizingStrip.tsx +5 -3
  75. package/src/components/resource/WorkloadMetricsSection.render.test.tsx +6 -0
  76. package/src/components/resource/WorkloadMetricsSection.tsx +14 -11
  77. package/src/components/resource/nameMatchedScope.ts +9 -3
  78. package/src/components/resources/EmptyNamespaceHint.tsx +42 -0
  79. package/src/components/resources/PodDebugAction.test.tsx +157 -0
  80. package/src/components/resources/PodDebugAction.tsx +207 -0
  81. package/src/components/resources/PodDebugPermission.tsx +21 -0
  82. package/src/components/resources/ResourcesView.empty-hint.test.tsx +132 -0
  83. package/src/components/resources/ResourcesView.tsx +39 -5
  84. package/src/components/resources/namespaceHint.test.ts +34 -0
  85. package/src/components/resources/namespaceHint.ts +19 -0
  86. package/src/components/resources/renderers/AdmissionPolicyRenderers.tsx +135 -0
  87. package/src/components/resources/renderers/NodeRenderer.tsx +2 -1
  88. package/src/components/resources/renderers/PodRenderer.tsx +12 -5
  89. package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +24 -1
  90. package/src/components/settings/FormSaveActions.tsx +6 -2
  91. package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
  92. package/src/components/settings/MetricsBackendSwitch.tsx +165 -0
  93. package/src/components/settings/OpenObserveSetup.test.tsx +384 -0
  94. package/src/components/settings/OpenObserveSetup.tsx +328 -0
  95. package/src/components/settings/SettingsDialog.tsx +21 -7
  96. package/src/components/settings/openobserveStatus.test.ts +34 -0
  97. package/src/components/settings/openobserveStatus.ts +55 -0
  98. package/src/components/timeline/TimelineList.selection.test.tsx +40 -0
  99. package/src/components/timeline/TimelineList.test.ts +18 -0
  100. package/src/components/timeline/TimelineList.tsx +19 -5
  101. package/src/components/timeline/TimelineView.tsx +2 -0
  102. package/src/components/workload/WorkloadView.pendingOwnership.test.tsx +34 -0
  103. package/src/components/workload/WorkloadView.tabUrl.test.tsx +44 -0
  104. package/src/components/workload/WorkloadView.tsx +103 -16
  105. package/src/components/workspace/WorkspaceConditions.tsx +56 -0
  106. package/src/components/workspace/layout.test.tsx +20 -0
  107. package/src/components/workspace/layout.tsx +1 -1
  108. package/src/context/TimelineNavigation.test.ts +59 -0
  109. package/src/context/TimelineNavigation.tsx +86 -0
  110. package/src/contexts/CapabilitiesContext.tsx +5 -1
  111. package/src/hooks/useResourceCounts.ts +2 -1
  112. package/src/hooks/useWorkflowStopAction.ts +31 -0
  113. package/src/index.css +1 -0
  114. package/src/integrations/resourceHosts.test.tsx +2 -2
  115. package/src/integrations/resourceHosts.tsx +4 -2
  116. package/src/k8s-ui-exports.test.ts +10 -0
  117. package/src/utils/page-links.ts +15 -1
  118. package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
@@ -0,0 +1,86 @@
1
+ import { createContext, useContext } from 'react'
2
+ import type { IssueTimelineEventTarget, IssueTimelineLinks, TimeRange } from '@skyhook-io/k8s-ui'
3
+
4
+ /**
5
+ * Opens the Timeline on one event. The app shell provides it because opening
6
+ * the Timeline in a namespace moves the app's namespace scope, the URL and the
7
+ * server's pick together. Absent outside the shell, where change rows keep
8
+ * their link to the changed object.
9
+ */
10
+ const TimelineNavigationContext = createContext<Required<Pick<IssueTimelineLinks, 'onTimelineEventClick' | 'canOpenTimelineEvent'>> | undefined>(undefined)
11
+
12
+ export const TimelineNavigationProvider = TimelineNavigationContext.Provider
13
+
14
+ /** The change-row Timeline links the app shell offers, or undefined outside it. */
15
+ export function useTimelineEventLinks(): IssueTimelineLinks | undefined {
16
+ return useContext(TimelineNavigationContext)
17
+ }
18
+
19
+ // How much of the Timeline around the event the link shows. The range is
20
+ // frozen there, so an event older than the Timeline's default last hour is
21
+ // still in view.
22
+ const EVENT_CONTEXT_MS = 30 * 60 * 1000
23
+
24
+ const HOUR_MS = 60 * 60 * 1000
25
+ // The list's own range choices, narrowest first, at or above its 1h default;
26
+ // past them it offers only 'all'.
27
+ const LIST_RANGES: [TimeRange, number][] = [['1h', HOUR_MS], ['6h', 6 * HOUR_MS], ['24h', 24 * HOUR_MS]]
28
+
29
+ /** The /timeline query that opens target's event: the event id and a frozen
30
+ * range around it, which the scrubber and the swimlane use. A list without a
31
+ * scrubber (a cluster too large for one without a namespace filter) keeps its
32
+ * own range instead, so `time` names the narrowest of its ranges that reaches
33
+ * back to the event. Namespace scope is the caller's (see openTimelineEventIn). */
34
+ export function timelineEventSearch(target: IssueTimelineEventTarget, now = Date.now()): URLSearchParams {
35
+ const params = new URLSearchParams({ event: target.eventId })
36
+ const at = Date.parse(target.timestamp)
37
+ if (Number.isFinite(at)) {
38
+ const to = Math.min(now, at + EVENT_CONTEXT_MS)
39
+ const from = Math.min(at, to) - EVENT_CONTEXT_MS
40
+ params.set('from', String(from))
41
+ params.set('to', String(to))
42
+ params.set('time', LIST_RANGES.find(([, ms]) => ms >= now - from)?.[0] ?? 'all')
43
+ }
44
+ return params
45
+ }
46
+
47
+ /** What opening the Timeline in a namespace scope needs from the app shell. */
48
+ export interface TimelineScopeControls {
49
+ /** The namespaces the app is scoped to now; empty is all. */
50
+ currentNamespaces: string[]
51
+ /** The cache itself is scoped to namespaces (--namespace-scope), so the
52
+ * view can't widen to all of them. */
53
+ cacheScoped: boolean
54
+ /** The app's own scope state. */
55
+ setNamespaces: (namespaces: string[]) => void
56
+ /** Records the pick with the server. It can fail (Radar Hub's proxy passes
57
+ * GET only), so nothing waits on it. */
58
+ requestNamespaces: (namespaces: string[]) => void
59
+ navigate: (search: URLSearchParams) => void
60
+ }
61
+
62
+ /** Whether the Timeline can show target's event: a cluster-scoped event shows
63
+ * only with no namespace filter, which a namespace-scoped cache can't drop. */
64
+ export function canOpenTimelineEvent(target: IssueTimelineEventTarget, cacheScoped: boolean): boolean {
65
+ return Boolean(target.namespace) || !cacheScoped
66
+ }
67
+
68
+ /** Opens the Timeline on target's event in the event's namespace, or in all
69
+ * namespaces for a cluster-scoped event. Scope state and URL move together,
70
+ * as the Timeline's own namespace prompt does: the URL-write effect would
71
+ * otherwise restore the previous scope over the destination's `namespaces`
72
+ * while the URL-read effect applies it, and the two would alternate. The
73
+ * server's pick is requested alongside, never awaited. Only a Radar that
74
+ * reports change event ids gets here, and such a Radar never applies a
75
+ * stored pick to a read that names no namespace. */
76
+ export function openTimelineEventIn(target: IssueTimelineEventTarget, controls: TimelineScopeControls, now = Date.now()) {
77
+ const params = timelineEventSearch(target, now)
78
+ const scope = target.namespace ? [target.namespace] : []
79
+ if (target.namespace) params.set('namespaces', target.namespace)
80
+ const unchanged = scope.length === controls.currentNamespaces.length && scope.every((ns, i) => ns === controls.currentNamespaces[i])
81
+ if (!unchanged) {
82
+ controls.setNamespaces(scope)
83
+ controls.requestNamespaces(scope)
84
+ }
85
+ controls.navigate(params)
86
+ }
@@ -41,6 +41,8 @@ const restrictedCapabilities: Capabilities = {
41
41
  daemonSets: false,
42
42
  statefulSets: false,
43
43
  rollouts: false,
44
+ cronJobs: false,
45
+ createJobs: false,
44
46
  },
45
47
  mcpEnabled: false,
46
48
  mcpExecTools: false,
@@ -165,6 +167,8 @@ export function useNamespacedCapabilities(namespace: string | undefined) {
165
167
  // the global value is not an answer for this namespace.
166
168
  const namespaceUnknown = Boolean(namespace && !nsCaps && (isPending || error))
167
169
  return useMemo(() => ({
170
+ canOpenEphemeralTerminal: !error && nsCaps?.podExecUID === true,
171
+ podDebugImage: nsCaps?.podDebug ? nsCaps.podDebugImage : undefined,
168
172
  canExec: nsCaps?.exec ?? globalCaps.exec,
169
173
  canViewLogs: nsCaps?.logs ?? globalCaps.logs,
170
174
  canPortForward: nsCaps?.portForward ?? globalCaps.portForward,
@@ -173,5 +177,5 @@ export function useNamespacedCapabilities(namespace: string | undefined) {
173
177
  workloadWritesPending: Boolean(namespace && isPending),
174
178
  helmWriteUnknown: namespaceUnknown,
175
179
  logsUnknown: namespaceUnknown,
176
- }), [globalCaps.exec, globalCaps.logs, globalCaps.portForward, globalCaps.helmWrite, globalCaps.workloadWrites, isPending, namespace, nsCaps, namespaceUnknown])
180
+ }), [error, globalCaps.exec, globalCaps.logs, globalCaps.portForward, globalCaps.helmWrite, globalCaps.workloadWrites, isPending, namespace, nsCaps, namespaceUnknown])
177
181
  }
@@ -14,7 +14,7 @@ export interface ResourceCountsResponse {
14
14
  // Lightweight per-kind counts for the Resources sidebar badges. Shared by the
15
15
  // Resources view and any surface that renders the same sidebar standalone, so
16
16
  // both read one cache entry.
17
- export function useResourceCounts(namespaces: string[]) {
17
+ export function useResourceCounts(namespaces: string[], options?: { enabled?: boolean }) {
18
18
  const { connection } = useConnection()
19
19
  const namespacesParam = namespaces.join(',')
20
20
  return useQuery({
@@ -34,6 +34,7 @@ export function useResourceCounts(namespaces: string[]) {
34
34
  })
35
35
  }
36
36
  },
37
+ enabled: options?.enabled ?? true,
37
38
  staleTime: 10000,
38
39
  // SSE invalidation isn't running while connecting, and mid-sync counts
39
40
  // are what unlatch guarded kinds as their informers finish — poll fast
@@ -0,0 +1,31 @@
1
+ import { canStopWorkflow, type WorkflowStopActionProps } from '@skyhook-io/k8s-ui'
2
+ import { isWorkflowStopTargetGone, useRadarFeature, useStopWorkflow } from '../api/client'
3
+ import { useNamespacedCapabilities } from '../contexts/CapabilitiesContext'
4
+
5
+ type WorkflowStopHostProps = Pick<WorkflowStopActionProps, 'onStopWorkflow' | 'isStoppingWorkflow' | 'workflowStopUpgrade'>
6
+
7
+ /**
8
+ * Wires Stop / Terminate for an Argo Workflow in `namespace`: offered only when
9
+ * the Radar serves the stop endpoint and the caller may patch Workflows there.
10
+ */
11
+ export function useWorkflowStopAction(kind: string, group: string | undefined, namespace: string | undefined): WorkflowStopHostProps {
12
+ const { workloadWrites, workloadWritesPending } = useNamespacedCapabilities(namespace)
13
+ const { support, upgrade } = useRadarFeature('workflowStop')
14
+ const mutation = useStopWorkflow()
15
+ const allowed = !workloadWritesPending && canStopWorkflow({ name: kind, group }, workloadWrites, support === 'supported')
16
+ return {
17
+ // mutateAsync, not mutate: the stop dialog stays open when this rejects.
18
+ // A run that is gone or replaced has nothing left to retry, so those
19
+ // resolve and close it; the mutation meta has already reported them.
20
+ onStopWorkflow: allowed
21
+ ? (params) => mutation.mutateAsync(params).catch((error: unknown) => {
22
+ if (isWorkflowStopTargetGone(error)) return
23
+ throw error
24
+ })
25
+ : undefined,
26
+ isStoppingWorkflow: mutation.isPending,
27
+ // Only a Radar known to lack the endpoint gets the upgrade note; a failed
28
+ // capabilities probe is not evidence of an old Radar.
29
+ workflowStopUpgrade: kind === 'workflows' && group === 'argoproj.io' && support === 'unsupported' ? upgrade : null,
30
+ }
31
+ }
package/src/index.css CHANGED
@@ -36,6 +36,7 @@
36
36
  }
37
37
  @container metrics (min-width: 1200px) {
38
38
  .metrics-chart-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
39
+ .metrics-chart-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
39
40
  .metrics-chart-wide { grid-column: auto; }
40
41
  }
41
42
  .investigation-assessment {
@@ -55,7 +55,7 @@ describe('application resource hosts', () => {
55
55
  'RolloutRenderer', 'KyvernoPolicyCoverage', 'KyvernoPolicyQueued', 'CNPGObjectStoreRenderer',
56
56
  'VeleroBSLRenderer', 'VeleroBackupRenderer', 'VeleroRestoreRenderer', 'CNPGClusterRenderer',
57
57
  'CNPGDatabaseRenderer', 'CNPGPublicationRenderer', 'CNPGSubscriptionRenderer', 'CNPGImageCatalogRenderer',
58
- 'FluxHelmReleaseRenderer', 'OpenTelemetryCollectorRenderer', 'ValidatingAdmissionPolicyRenderer', 'ValidatingAdmissionPolicyBindingRenderer', 'SecretProviderClassRenderer', 'UpgradePlanRenderer', 'SealedSecretRenderer', 'K3sHelmChartRenderer',
58
+ 'FluxHelmReleaseRenderer', 'OpenTelemetryCollectorRenderer', 'ValidatingAdmissionPolicyRenderer', 'ValidatingAdmissionPolicyBindingRenderer', 'MutatingAdmissionPolicyRenderer', 'MutatingAdmissionPolicyBindingRenderer', 'SecretProviderClassRenderer', 'UpgradePlanRenderer', 'SealedSecretRenderer', 'K3sHelmChartRenderer',
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)
@@ -74,7 +74,7 @@ describe('application resource hosts', () => {
74
74
  const path = resourceDetailRedirect({ ...cluster, kind: 'clusters' }, search)!
75
75
  const url = new URL(path, 'http://radar.test')
76
76
  expect(url.pathname).toBe('/cnpg/clusters/db/pg')
77
- expect(Object.fromEntries(url.searchParams)).toEqual({ ctx: 'kind-demo', tab: 'activity', drawer: 'pods:pg-1', 'ai-run': 'run' })
77
+ expect(Object.fromEntries(url.searchParams)).toEqual({ ctx: 'kind-demo', tab: 'events', drawer: 'pods:pg-1', 'ai-run': 'run' })
78
78
  expect(search.get('tab')).toBe('events')
79
79
  expect(search.get('apiGroup')).toBe('postgresql.cnpg.io')
80
80
  })
@@ -44,9 +44,11 @@ import { SealedSecretRenderer } from '../components/resources/renderers/SealedSe
44
44
  import { K3sHelmChartRenderer } from '../components/resources/renderers/K3sHelmChartRenderer'
45
45
  import { UpgradePlanRenderer } from '../components/resources/renderers/UpgradePlanRenderer'
46
46
  import {
47
+ MutatingAdmissionPolicyBindingRenderer,
48
+ MutatingAdmissionPolicyRenderer,
47
49
  ValidatingAdmissionPolicyBindingRenderer,
48
50
  ValidatingAdmissionPolicyRenderer,
49
- } from '../components/resources/renderers/ValidatingAdmissionPolicyRenderer'
51
+ } from '../components/resources/renderers/AdmissionPolicyRenderers'
50
52
 
51
53
  export const resourceHosts: readonly ResourceHost[] = [
52
54
  { id: 'kubernetes', renderers: { PodRenderer, NodeRenderer, ServiceRenderer, WorkloadRenderer, HPARenderer, PVCRenderer } },
@@ -74,7 +76,7 @@ export const resourceHosts: readonly ResourceHost[] = [
74
76
  { id: 'longhorn', renderers: { LonghornVolumeRenderer } },
75
77
  { id: 'flux', renderers: { FluxHelmReleaseRenderer } },
76
78
  { id: 'secrets-store-csi', renderers: { SecretProviderClassRenderer } },
77
- { id: 'admission-policy', renderers: { ValidatingAdmissionPolicyRenderer, ValidatingAdmissionPolicyBindingRenderer } },
79
+ { id: 'admission-policy', renderers: { ValidatingAdmissionPolicyRenderer, ValidatingAdmissionPolicyBindingRenderer, MutatingAdmissionPolicyRenderer, MutatingAdmissionPolicyBindingRenderer } },
78
80
  cnpgResourceHost,
79
81
  crdResourceHost,
80
82
  ]
@@ -3,6 +3,7 @@ import { describe, expect, test } from 'vitest'
3
3
  import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
4
4
  import { dirname, join, resolve } from 'node:path'
5
5
  import { fileURLToPath } from 'node:url'
6
+ import { compareVersions } from './utils/version'
6
7
 
7
8
  // Radar's own build aliases @skyhook-io/k8s-ui to its source, so a deep
8
9
  // import that the package's `exports` map can't serve still builds here and
@@ -50,6 +51,15 @@ function sourceFiles(dir: string): string[] {
50
51
  })
51
52
  }
52
53
 
54
+ test('radar-app requires a k8s-ui peer that types workflowStop and workloadRestartPreconditions', () => {
55
+ const manifest = JSON.parse(readFileSync(resolve(here, '../package.json'), 'utf8'))
56
+ const lock = JSON.parse(readFileSync(resolve(here, '../../package-lock.json'), 'utf8'))
57
+ const range = manifest.peerDependencies['@skyhook-io/k8s-ui']
58
+ expect(lock.packages.web.peerDependencies['@skyhook-io/k8s-ui']).toBe(range)
59
+ expect(range).toMatch(/^>=/)
60
+ expect(compareVersions(range.slice(2), '1.21.7')).toBeGreaterThanOrEqual(0)
61
+ })
62
+
53
63
  describe('@skyhook-io/k8s-ui deep imports', () => {
54
64
  const imports = new Set<string>()
55
65
  for (const file of sourceFiles(here)) {
@@ -1,3 +1,5 @@
1
+ import { useLocation, useNavigate } from 'react-router-dom'
2
+
1
3
  /**
2
4
  * The label for "← back" on the page a push lands on: the title of the page
3
5
  * being left, which Radar keeps in the document title.
@@ -7,7 +9,7 @@ export function currentPageLabel(): string {
7
9
  }
8
10
 
9
11
  /**
10
- * Radar's Issues page narrowed to one subject (it has no link to a single issue).
12
+ * Radar's Issues page narrowed to all issues for one subject.
11
13
  * The subject travels as `resource=ns/name`, never `namespace=`: App reads a bare
12
14
  * `namespace` as the view filter, and a URL without `namespaces` clears it.
13
15
  */
@@ -20,6 +22,18 @@ export function issuesPathForSubject(subject: { kind: string; group?: string; na
20
22
  return `/issues?${params}`
21
23
  }
22
24
 
25
+ // A manual selection replaces the deep link so Back still returns to its origin.
26
+ export function useClearLinkedIssue() {
27
+ const location = useLocation()
28
+ const navigate = useNavigate()
29
+ return () => {
30
+ const params = new URLSearchParams(location.search)
31
+ if (!params.has('issue')) return
32
+ params.delete('issue')
33
+ navigate({ pathname: location.pathname, search: params.toString(), hash: location.hash }, { replace: true, state: location.state })
34
+ }
35
+ }
36
+
23
37
  export const RIGHTSIZING_SCAN_PATH = '/cost/rightsizing'
24
38
 
25
39
  export function isRightsizingScanPath(pathname: string): boolean {
@@ -1,128 +0,0 @@
1
- import { Link2 } from 'lucide-react'
2
- import {
3
- RelationshipGroup,
4
- ResourceLink,
5
- Section,
6
- type ResourceRef,
7
- } from '@skyhook-io/k8s-ui'
8
- import { LookupFailureNote } from '@skyhook-io/k8s-ui/components/resources/renderers/LookupFailureNote'
9
- import {
10
- ValidatingAdmissionPolicyBindingRenderer as BaseBindingRenderer,
11
- ValidatingAdmissionPolicyRenderer as BasePolicyRenderer,
12
- } from '@skyhook-io/k8s-ui/components/resources/renderers/ValidatingAdmissionPolicyRenderers'
13
- import { useResources, useResourceWithRelationships } from '../../../api/client'
14
-
15
- const ADMISSION_REGISTRATION_GROUP = 'admissionregistration.k8s.io'
16
-
17
- export function ValidatingAdmissionPolicyRenderer({
18
- data,
19
- onNavigate,
20
- }: {
21
- data: any
22
- onNavigate?: (ref: ResourceRef) => void
23
- }) {
24
- const name = data?.metadata?.name
25
- const query = useResources<any>(
26
- 'validatingadmissionpolicybindings',
27
- undefined,
28
- ADMISSION_REGISTRATION_GROUP,
29
- { enabled: Boolean(name), refetchInterval: 30000 },
30
- )
31
- const bindings = (query.data ?? []).filter(binding => binding?.spec?.policyName === name)
32
- const bindingLookupComplete = query.coverage?.status === 'complete' && !query.error
33
- const bindingTitle = bindingLookupComplete
34
- ? `Bindings (${bindings.length})`
35
- : bindings.length > 0 ? `Bindings (${bindings.length}+)` : 'Bindings'
36
- const refs = bindings.map(binding => ({
37
- kind: 'ValidatingAdmissionPolicyBinding',
38
- namespace: '',
39
- name: binding?.metadata?.name ?? '',
40
- group: ADMISSION_REGISTRATION_GROUP,
41
- }))
42
-
43
- return (
44
- <BasePolicyRenderer
45
- data={data}
46
- onNavigate={onNavigate}
47
- bindings={
48
- <Section title={bindingTitle} icon={Link2} defaultExpanded>
49
- {query.isLoading ? (
50
- <div className="text-sm text-theme-text-tertiary">Looking for readable bindings…</div>
51
- ) : query.error && bindings.length === 0 ? (
52
- <LookupFailureNote errors={[query.error]} what="which bindings select this policy" />
53
- ) : bindings.length === 0 && bindingLookupComplete ? (
54
- <div className="text-sm text-theme-text-tertiary">
55
- No readable bindings select this policy; this policy has no effect.
56
- </div>
57
- ) : bindings.length === 0 ? (
58
- <div className="text-sm text-theme-text-tertiary">
59
- Binding availability could not be established; this policy may still have readable bindings.
60
- </div>
61
- ) : (
62
- <div className="space-y-2">
63
- {!bindingLookupComplete && !query.error && (
64
- <div className="text-sm text-theme-text-tertiary">
65
- This list may be incomplete; binding coverage could not be confirmed.
66
- </div>
67
- )}
68
- <LookupFailureNote
69
- errors={[query.error]}
70
- what="which bindings select this policy"
71
- incomplete
72
- />
73
- <RelationshipGroup label="Select this policy" refs={refs} onNavigate={onNavigate} />
74
- </div>
75
- )}
76
- </Section>
77
- }
78
- />
79
- )
80
- }
81
-
82
- export function ValidatingAdmissionPolicyBindingRenderer({
83
- data,
84
- onNavigate,
85
- }: {
86
- data: any
87
- onNavigate?: (ref: ResourceRef) => void
88
- }) {
89
- const policyName = data?.spec?.policyName ?? ''
90
- const query = useResourceWithRelationships<any>(
91
- 'validatingadmissionpolicies',
92
- '',
93
- policyName,
94
- ADMISSION_REGISTRATION_GROUP,
95
- )
96
- const status = typeof query.error === 'object' && query.error !== null && 'status' in query.error
97
- ? (query.error as { status?: unknown }).status
98
- : undefined
99
- const reference = query.isLoading ? (
100
- <ReferenceState name={policyName} note="Checking policy availability…" />
101
- ) : status === 404 ? (
102
- <ReferenceState name={policyName} note="Referenced policy was not found." />
103
- ) : status === 403 ? (
104
- <ReferenceState name={policyName} note="Not permitted to check policy availability." />
105
- ) : query.error ? (
106
- <ReferenceState name={policyName} note="Could not check policy availability." />
107
- ) : query.data ? (
108
- <ResourceLink
109
- name={policyName}
110
- kind="validatingadmissionpolicies"
111
- namespace=""
112
- group={ADMISSION_REGISTRATION_GROUP}
113
- onNavigate={onNavigate}
114
- />
115
- ) : (
116
- <ReferenceState name={policyName} note="Policy availability was not checked." />
117
- )
118
- return <BaseBindingRenderer data={data} onNavigate={onNavigate} policyReference={reference} />
119
- }
120
-
121
- function ReferenceState({ name, note }: { name: string; note: string }) {
122
- return (
123
- <span className="space-y-0.5">
124
- <span className="block">{name || 'Not specified'}</span>
125
- <span className="block text-xs text-theme-text-tertiary">{note}</span>
126
- </span>
127
- )
128
- }