@skyhook-io/radar-app 1.18.0 → 1.18.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 (69) hide show
  1. package/README.md +6 -0
  2. package/package.json +2 -3
  3. package/src/App.tsx +22 -6
  4. package/src/api/client.gitops-destination.test.tsx +55 -0
  5. package/src/api/client.resource-list.test.ts +76 -0
  6. package/src/api/client.ts +61 -20
  7. package/src/api/quotas.ts +9 -20
  8. package/src/api/radarFeatures.ts +2 -0
  9. package/src/api/resourceLists.test.ts +84 -0
  10. package/src/api/resourceLists.ts +71 -0
  11. package/src/components/cnpg/CNPGView.tsx +1 -0
  12. package/src/components/compare/CompareResourcePicker.test.tsx +58 -0
  13. package/src/components/compare/CompareViewRoute.tsx +5 -1
  14. package/src/components/compare/useCompareCandidates.ts +1 -1
  15. package/src/components/compare/useCompareLauncher.tsx +4 -2
  16. package/src/components/diagnose/StoryExcerpt.tsx +24 -5
  17. package/src/components/diagnose/investigationEvidence/adapters/listCoverage.test.ts +415 -0
  18. package/src/components/diagnose/investigationEvidence/adapters/resource.ts +107 -8
  19. package/src/components/diagnose/investigationEvidence/bodies/inventory.tsx +66 -16
  20. package/src/components/diagnose/investigationEvidence/builder.ts +13 -1
  21. package/src/components/diagnose/investigationEvidence/excerpt.ts +2 -0
  22. package/src/components/diagnose/investigationEvidence/observations.ts +1 -0
  23. package/src/components/diagnose/investigationEvidence/projection.test.ts +24 -1
  24. package/src/components/diagnose/investigationEvidence/types.ts +15 -0
  25. package/src/components/diagnose/toolCallLabel.test.ts +9 -0
  26. package/src/components/diagnose/toolCallLabel.ts +2 -0
  27. package/src/components/execution/BatchExecutionView.image-browse.test.tsx +46 -0
  28. package/src/components/execution/BatchExecutionView.tsx +6 -4
  29. package/src/components/gitops/GitOpsView.identity.test.tsx +113 -0
  30. package/src/components/gitops/GitOpsView.tsx +62 -40
  31. package/src/components/gitops/useDestinationCluster.ts +2 -1
  32. package/src/components/helm/ArtifactHubSourceSearch.test.tsx +124 -0
  33. package/src/components/helm/ArtifactHubSourceSearch.tsx +240 -0
  34. package/src/components/helm/ChartBrowser.tsx +5 -4
  35. package/src/components/helm/TrackChartSourceDialog.render.test.tsx +269 -96
  36. package/src/components/helm/TrackChartSourceDialog.tsx +607 -104
  37. package/src/components/home/mcpToolCatalog.ts +10 -0
  38. package/src/components/resource/PrometheusCharts.overlays.test.ts +45 -0
  39. package/src/components/resource/PrometheusCharts.tsx +2 -2
  40. package/src/components/resources/ResourcesView.tsx +29 -67
  41. package/src/components/resources/renderers/PodRenderer.tsx +4 -1
  42. package/src/components/settings/MyPermissionsDialog.tsx +12 -9
  43. package/src/components/traffic/TrafficSourcePill.test.tsx +110 -0
  44. package/src/components/traffic/TrafficSourcePill.tsx +111 -0
  45. package/src/components/traffic/TrafficView.tsx +9 -55
  46. package/src/components/ui/DiagnosticsOverlay.test.ts +25 -0
  47. package/src/components/ui/DiagnosticsOverlay.tsx +2 -1
  48. package/src/components/ui/Omnibar.note.test.tsx +141 -0
  49. package/src/components/ui/Omnibar.tsx +82 -18
  50. package/src/components/ui/RadarOmnibar.test.tsx +183 -0
  51. package/src/components/ui/RadarOmnibar.tsx +38 -4
  52. package/src/components/ui/UpdateNotification.manual.test.tsx +177 -0
  53. package/src/components/ui/UpdateNotification.test.tsx +2 -1
  54. package/src/components/ui/UpdateNotification.tsx +29 -5
  55. package/src/components/ui/omnibar-match.test.ts +15 -8
  56. package/src/components/ui/omnibar-match.ts +11 -6
  57. package/src/components/ui/searchCoverage.fixtures.ts +16 -0
  58. package/src/components/ui/searchCoverageNote.test.ts +245 -0
  59. package/src/components/ui/searchCoverageNote.ts +222 -0
  60. package/src/components/whats-new/WhatsNew.test.ts +10 -0
  61. package/src/components/whats-new/WhatsNew.tsx +5 -4
  62. package/src/components/whats-new/WhatsNewDialog.test.tsx +20 -0
  63. package/src/components/whats-new/releaseNotes.ts +57 -5
  64. package/src/components/workload/WorkloadView.tsx +8 -2
  65. package/src/hooks/useResourceCounts.ts +2 -0
  66. package/src/index.css +2 -4
  67. package/src/index.ts +7 -0
  68. package/src/utils/artifacthub.test.ts +18 -0
  69. package/src/utils/artifacthub.ts +9 -0
@@ -1,10 +1,29 @@
1
- import { useId, useState, type FormEvent } from 'react'
1
+ import { useEffect, useId, useRef, useState, type FormEvent } from 'react'
2
2
  import { DialogPortal } from '@skyhook-io/k8s-ui/components/ui/DialogPortal'
3
- import { AlertTriangle, Link2, Plus, Trash2, X } from 'lucide-react'
3
+ import { Trash2, X } from 'lucide-react'
4
4
  import { Input } from '@skyhook-io/k8s-ui'
5
- import { useAddHelmRepository, useAddOCISource, useCapabilities, useCloudRole, useClusterInfo, useHelmOCISources, useHelmRepositories, useHelmSourceStatus, useRemoveOCISource, useSetHelmSource, useRadarFeature } from '../../api/client'
5
+ import {
6
+ useAddHelmRepository,
7
+ useAddOCISource,
8
+ useCapabilities,
9
+ useCloudRole,
10
+ useClusterInfo,
11
+ useHelmOCISources,
12
+ useHelmRepositories,
13
+ useHelmSourceStatus,
14
+ useRemoveOCISource,
15
+ useSetHelmSource,
16
+ useRadarFeature,
17
+ } from '../../api/client'
6
18
  import { OperatorManagedNotice } from '../settings/OperatorManagedNotice'
7
- import type { ChartSourceStatus, HelmRepository, UpgradeInfo, SourceUpgradeSelection } from '../../types'
19
+ import { ArtifactHubSourceSearch, publicChartSourceURL } from './ArtifactHubSourceSearch'
20
+ import type {
21
+ ChartSourceCandidate,
22
+ ChartSourceStatus,
23
+ HelmRepository,
24
+ UpgradeInfo,
25
+ SourceUpgradeSelection,
26
+ } from '../../types'
8
27
 
9
28
  interface TrackChartSourceDialogProps {
10
29
  operationError?: string | null
@@ -59,8 +78,14 @@ export function repositoryDisplayURL(url: string) {
59
78
  // server stores names in this form, so collisions are checked on it.
60
79
  const MAX_REPOSITORY_NAME_LENGTH = 40
61
80
  export function normalizedRepositoryName(name: string) {
62
- const base = name.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, '-').replace(/^[-._]+|[-._]+$/g, '')
63
- return base.length > MAX_REPOSITORY_NAME_LENGTH ? base.slice(0, MAX_REPOSITORY_NAME_LENGTH).replace(/[-._]+$/, '') : base
81
+ const base = name
82
+ .trim()
83
+ .toLowerCase()
84
+ .replace(/[^a-z0-9._-]+/g, '-')
85
+ .replace(/^[-._]+|[-._]+$/g, '')
86
+ return base.length > MAX_REPOSITORY_NAME_LENGTH
87
+ ? base.slice(0, MAX_REPOSITORY_NAME_LENGTH).replace(/[-._]+$/, '')
88
+ : base
64
89
  }
65
90
 
66
91
  // Name for re-adding the recorded repository on this machine. Reuses the
@@ -71,7 +96,7 @@ export function normalizedRepositoryName(name: string) {
71
96
  export function recordedRepositoryName(alias: string, repositories: HelmRepository[]) {
72
97
  const base = normalizedRepositoryName(alias)
73
98
  if (!base) return ''
74
- const taken = new Set(repositories.map(repository => normalizedRepositoryName(repository.name)))
99
+ const taken = new Set(repositories.map((repository) => normalizedRepositoryName(repository.name)))
75
100
  if (!taken.has(base)) return base
76
101
  for (let n = 2; ; n++) {
77
102
  const suffix = `-${n}`
@@ -82,126 +107,604 @@ export function recordedRepositoryName(alias: string, repositories: HelmReposito
82
107
 
83
108
  export function getSourceIssueCopy(sourceIssue: UpgradeInfo['sourceIssue'], sourceError?: string) {
84
109
  switch (sourceIssue) {
85
- case 'release_changing': return { title: 'Helm operation in progress', body: 'Wait for the current operation to finish, then refresh the source state.' }
86
- case 'source_confirmation_required': return { title: 'Confirm the recorded source', body: 'Verify the original source, or select a source for the next upgrade.' }
87
- case 'source_change_required': return { title: 'Source choice required', body: 'The previous chart change failed. Select a source and preview again before retrying.' }
88
- case 'repo_index_error': return { title: 'A Helm repo index failed', body: 'Fix or refresh the repository before associating it.' }
110
+ case 'release_changing':
111
+ return {
112
+ title: 'Helm operation in progress',
113
+ body: 'Wait for the current operation to finish, then refresh the source state.',
114
+ }
115
+ case 'source_confirmation_required':
116
+ return {
117
+ title: 'Confirm the recorded source',
118
+ body: 'Verify the original source, or select a source for the next upgrade.',
119
+ }
120
+ case 'source_change_required':
121
+ return {
122
+ title: 'Source choice required',
123
+ body: 'The previous chart change failed. Select a source and preview again before retrying.',
124
+ }
125
+ case 'repo_index_error':
126
+ return { title: 'A Helm repo index failed', body: 'Fix or refresh the repository before associating it.' }
89
127
  case 'ambiguous_repository':
90
- case 'ambiguous_source': return { title: 'Chart source unresolved', body: 'Select the original source, or choose a source for the next upgrade.' }
91
- case 'source_unavailable': return { title: 'Recorded source unavailable', body: 'The release provenance is preserved, but that source cannot currently be verified here.' }
92
- case 'untracked': return { title: 'Source not recorded', body: 'Choose a source for the next upgrade, or record the original source.' }
93
- default: return sourceError ? { title: 'Source unresolved', body: sourceError } : undefined
128
+ case 'ambiguous_source':
129
+ return {
130
+ title: 'Chart source unresolved',
131
+ body: 'Select the original source, or choose a source for the next upgrade.',
132
+ }
133
+ case 'source_unavailable':
134
+ return {
135
+ title: 'Recorded source unavailable',
136
+ body: 'The release provenance is preserved, but that source cannot currently be verified here.',
137
+ }
138
+ case 'untracked':
139
+ return {
140
+ title: 'Source not recorded',
141
+ body: 'Choose a source for the next upgrade, or record the original source.',
142
+ }
143
+ default:
144
+ return sourceError ? { title: 'Source unresolved', body: sourceError } : undefined
94
145
  }
95
146
  }
96
147
 
97
- export function TrackChartSourceDialog({ operationError, onSelectUpgradeSource, open, onClose, chartName, namespace, releaseName, sourceIssue, sourceError }: TrackChartSourceDialogProps) {
148
+ export function TrackChartSourceDialog(props: TrackChartSourceDialogProps) {
149
+ return <ChartSourcePicker key={`${props.namespace}/${props.releaseName}`} {...props} />
150
+ }
151
+
152
+ function sourceKey(source: ChartSourceCandidate) {
153
+ return `${source.type}:${publicChartSourceURL(source.url ?? source.reference) ?? source.reference}`
154
+ }
155
+
156
+ function ChartSourcePicker({
157
+ operationError,
158
+ onSelectUpgradeSource,
159
+ open,
160
+ onClose,
161
+ chartName,
162
+ namespace,
163
+ releaseName,
164
+ sourceIssue,
165
+ sourceError,
166
+ }: TrackChartSourceDialogProps) {
98
167
  const sourceFeature = useRadarFeature('helmSourceIdentity')
168
+ const [view, setView] = useState<'added' | 'public' | 'manual'>('added')
169
+ const [manualType, setManualType] = useState<'repository' | 'oci'>('repository')
170
+ const [selectedKey, setSelectedKey] = useState('')
171
+ const [filter, setFilter] = useState('')
99
172
  const [ociPrefix, setOCIPrefix] = useState('')
100
173
  const [repositoryName, setRepositoryName] = useState('')
101
174
  const [repositoryURL, setRepositoryURL] = useState('')
102
- const { data: status, error: statusError, refetch: refetchStatus, isFetching: statusFetching } = useHelmSourceStatus(namespace, releaseName, open)
175
+ const active = useRef(open)
176
+ const generation = useRef(0)
177
+ useEffect(() => {
178
+ active.current = open
179
+ return () => {
180
+ active.current = false
181
+ generation.current += 1
182
+ }
183
+ }, [open])
184
+ const currentSession = () => {
185
+ const startedIn = generation.current
186
+ return () => active.current && generation.current === startedIn
187
+ }
188
+ const {
189
+ data: status,
190
+ error: statusError,
191
+ refetch: refetchStatus,
192
+ isFetching: statusFetching,
193
+ } = useHelmSourceStatus(namespace, releaseName, open)
103
194
  const { data: ociSources } = useHelmOCISources()
104
195
  const { data: clusterInfo } = useClusterInfo()
105
196
  const { data: capabilities } = useCapabilities()
197
+ const { data: repositories, isLoading: repositoriesLoading } = useHelmRepositories()
106
198
  const addOCI = useAddOCISource()
107
199
  const removeOCI = useRemoveOCISource()
108
200
  const addRepository = useAddHelmRepository()
109
201
  const setSource = useSetHelmSource(namespace, releaseName)
110
- const issueCopy = getSourceIssueCopy(sourceIssue, sourceError)
111
- const recorded = status?.recorded
112
- const configManaged = capabilities?.configManagement === 'operator'
113
- // Chart sources are shared configuration that every user's upgrades resolve
114
- // against, so in Radar Cloud only owners change them (the server enforces it).
115
202
  const ownerOnly = !useCloudRole().canAtLeast('owner')
203
+ const configManaged = capabilities?.configManagement === 'operator'
116
204
  const canEditSources = capabilities != null && !configManaged && !ownerOnly
205
+ const pending = addRepository.isPending || addOCI.isPending
206
+ const sourceBusy = Boolean(statusFetching || !status || status.changing || setSource.isPending || pending)
207
+ const configBusy = !canEditSources || repositoriesLoading || pending
117
208
  const titleId = useId()
118
- // The release says which repository it came from, but this machine has no
119
- // repository with that URL: offer to add exactly that one.
120
- const missingRecordedRepository = status && !status.configured && recorded?.type === 'repository' && recorded.url ? recorded : undefined
121
- const { data: repositories, isLoading: repositoriesLoading } = useHelmRepositories()
122
- const recordedName = missingRecordedRepository ? recordedRepositoryName(missingRecordedRepository.reference, repositories ?? []) : undefined
209
+ const formId = useId()
210
+ const panelId = useId()
211
+ const locations: ('added' | 'public')[] =
212
+ chartName && sourceFeature.support === 'supported' ? ['added', 'public'] : ['added']
213
+ const issueCopy = getSourceIssueCopy(sourceIssue, sourceError)
214
+ const recorded = status?.recorded
215
+ const missingRecorded =
216
+ status && !status.configured && recorded?.type === 'repository' && recorded.url ? recorded : undefined
217
+ const recordedName = missingRecorded ? recordedRepositoryName(missingRecorded.reference, repositories ?? []) : ''
218
+ const sources = [...(status?.suggestions ?? []).map((item) => item.source), ...(status?.candidates ?? [])]
219
+ if (recorded) sources.unshift(recorded)
220
+ const seen = new Set<string>()
221
+ const choices = sources.filter((source) => {
222
+ const key = sourceKey(source)
223
+ if (seen.has(key)) return false
224
+ seen.add(key)
225
+ return true
226
+ })
227
+ const selected = choices.find((source) => sourceKey(source) === selectedKey)
228
+ const visible = choices.filter((source) =>
229
+ `${source.reference} ${source.url ?? ''}`.toLowerCase().includes(filter.trim().toLowerCase()),
230
+ )
231
+ const selectedMissing = selected && missingRecorded && sourceKey(selected) === sourceKey(missingRecorded)
232
+ const canVerify =
233
+ selected &&
234
+ !status?.confirmed &&
235
+ !status?.sourceChangeRequired &&
236
+ (selected.type === 'oci' || status?.candidates?.some((source) => sourceKey(source) === selectedKey))
123
237
 
124
- const addRecordedRepository = () => {
125
- if (!missingRecordedRepository || recordedName === undefined) return
126
- const associate = status?.confirmed !== false
127
- addRepository.mutate({ name: recordedName, url: missingRecordedRepository.url, ...(associate ? { namespace, releaseName } : {}) }, { onSuccess: associate ? onClose : () => { void refetchStatus() } })
238
+ const showAdded = (source?: ChartSourceCandidate) => {
239
+ if (!active.current) return
240
+ setView('added')
241
+ setFilter('')
242
+ setSelectedKey(source ? sourceKey(source) : '')
243
+ void refetchStatus()
128
244
  }
129
-
130
- const addRepositoryAndAssociate = (event: FormEvent) => {
131
- event.preventDefault()
132
- const name = repositoryName.trim()
133
- const url = repositoryURL.trim()
134
- if (!name || !isValidHelmRepositoryURL(url)) return
135
- addRepository.mutate({ name, url }, { onSuccess: () => { setRepositoryName(''); setRepositoryURL(''); void refetchStatus() } })
245
+ const addRecorded = () => {
246
+ if (!missingRecorded) return
247
+ const isCurrent = currentSession()
248
+ const associate = status?.confirmed !== false
249
+ addRepository.mutate(
250
+ { name: recordedName, url: missingRecorded.url, ...(associate ? { namespace, releaseName } : {}) },
251
+ {
252
+ onSuccess: () => {
253
+ if (!isCurrent()) return
254
+ if (associate) onClose()
255
+ else showAdded(missingRecorded)
256
+ },
257
+ },
258
+ )
136
259
  }
137
-
138
- const addOCIPrefix = async (event: FormEvent) => {
260
+ const submitManual = (event: FormEvent) => {
139
261
  event.preventDefault()
140
- if (!ociPrefix.trim().startsWith('oci://')) return
141
- await addOCI.mutateAsync(ociPrefix.trim())
142
- setOCIPrefix('')
143
- await refetchStatus()
262
+ const isCurrent = currentSession()
263
+ if (manualType === 'oci') {
264
+ if (!ociPrefix.trim().startsWith('oci://')) return
265
+ const prefix = ociPrefix.trim().replace(/\/+$/, '')
266
+ addOCI.mutate(prefix, {
267
+ onSuccess: () => {
268
+ if (!isCurrent()) return
269
+ setOCIPrefix('')
270
+ showAdded(chartName ? { type: 'oci', reference: `${prefix}/${chartName}` } : undefined)
271
+ },
272
+ })
273
+ } else {
274
+ const url = repositoryURL.trim()
275
+ const name = repositoryName.trim()
276
+ if (!name || !isValidHelmRepositoryURL(url)) return
277
+ addRepository.mutate(
278
+ { name, url },
279
+ {
280
+ onSuccess: (result) => {
281
+ if (!isCurrent()) return
282
+ setRepositoryName('')
283
+ setRepositoryURL('')
284
+ showAdded({ type: 'repository', reference: result.name, url })
285
+ },
286
+ },
287
+ )
288
+ }
144
289
  }
290
+ const manualAction = (
291
+ <button
292
+ type="button"
293
+ onClick={() => setView(view === 'manual' ? 'added' : 'manual')}
294
+ className="text-sm text-accent hover:underline"
295
+ >
296
+ {view === 'manual' ? 'Back to sources' : 'Add manually'}
297
+ </button>
298
+ )
145
299
 
146
- return <DialogPortal ariaLabelledBy={titleId} open={open} onClose={onClose} className="max-w-2xl w-full">
147
- <div className="flex items-start gap-3 p-4 border-b border-theme-border">
148
- <div className="flex items-center justify-center w-10 h-10 rounded-full bg-theme-hover"><Link2 className="w-5 h-5" /></div>
149
- <div className="flex-1 min-w-0"><h3 id={titleId} className="text-lg font-semibold">Track chart source</h3><p className="text-sm text-theme-text-secondary mt-1">Tell Radar which repository or OCI source this release was installed from. Upgrades then come only from that source.</p></div>
150
- <button onClick={onClose} aria-label="Close" className="p-1 rounded hover:bg-theme-elevated"><X className="w-5 h-5" /></button>
151
- </div>
152
- <div className="p-4 space-y-4">
153
- {configManaged && <OperatorManagedNotice helmValue="helm.ociSources" />}
154
- {!configManaged && ownerOnly && <p className="text-sm text-theme-text-secondary">Only organization owners can add or remove chart sources.</p>}
155
- {operationError && <p role="alert" className="text-sm text-theme-text-secondary">{operationError}</p>}
156
- {status?.changing && <button type="button" onClick={() => void refetchStatus()} className="btn-brand px-3 py-2">Refresh source state</button>}
157
- {issueCopy && <div className="flex gap-2 rounded-lg border border-theme-border bg-theme-elevated px-3 py-2 text-sm"><AlertTriangle className="w-4 h-4 mt-0.5 shrink-0" /><div><p className="font-medium">{issueCopy.title}</p><p className="text-theme-text-secondary">{issueCopy.body}</p></div></div>}
158
- <div className="rounded-lg border border-theme-border px-3 py-2">
159
- <p className="text-xs uppercase tracking-wide text-theme-text-tertiary">Release source state</p>
160
- <p className="text-sm font-medium mt-1 break-all">{sourceStatusLine(status, statusError)}</p>
161
- {!status && statusError && <button type="button" onClick={() => refetchStatus()} className="mt-2 px-3 py-1.5 text-sm text-theme-text-primary border border-theme-border rounded-lg hover:bg-theme-elevated transition-colors">Retry</button>}
162
- {recorded && <p className="font-mono text-xs text-theme-text-secondary mt-1 break-all">{recorded.url ?? recorded.reference}</p>}
300
+ return (
301
+ <DialogPortal
302
+ ariaLabelledBy={titleId}
303
+ open={open}
304
+ onClose={onClose}
305
+ className="max-w-xl w-full max-h-[85vh] h-[36rem] flex flex-col overflow-hidden"
306
+ >
307
+ <header className="shrink-0 px-4 pt-4 pb-3">
308
+ <div className="flex items-center justify-between gap-3">
309
+ <h3 id={titleId} className="text-base font-semibold">
310
+ {view === 'manual' ? 'Add chart source' : 'Choose chart source'}
311
+ </h3>
312
+ <button
313
+ type="button"
314
+ onClick={onClose}
315
+ aria-label="Close"
316
+ className="p-1 rounded text-theme-text-secondary hover:bg-theme-hover"
317
+ >
318
+ <X className="w-5 h-5" />
319
+ </button>
320
+ </div>
321
+ <p className="mt-2 text-xs text-theme-text-tertiary">
322
+ {chartName && (
323
+ <>
324
+ <span className="font-medium">{chartName}</span> ·{' '}
325
+ </>
326
+ )}
327
+ {sourceStatusLine(status, statusError)}
328
+ </p>
329
+ {!status && statusError && (
330
+ <button
331
+ type="button"
332
+ onClick={() => void refetchStatus()}
333
+ className="text-sm text-accent hover:underline mt-1"
334
+ >
335
+ Retry
336
+ </button>
337
+ )}
338
+ {status?.changing && (
339
+ <button
340
+ type="button"
341
+ onClick={() => void refetchStatus()}
342
+ className="text-sm text-accent hover:underline mt-1"
343
+ >
344
+ Refresh source state
345
+ </button>
346
+ )}
347
+ {issueCopy &&
348
+ sourceIssue !== 'untracked' &&
349
+ sourceIssue !== 'source_unavailable' &&
350
+ sourceIssue !== 'source_confirmation_required' && (
351
+ <p className="text-xs text-theme-text-secondary mt-2">{issueCopy.body}</p>
352
+ )}
353
+ {operationError && (
354
+ <p role="alert" className="text-sm text-warning-text mt-2">
355
+ {operationError}
356
+ </p>
357
+ )}
358
+ </header>
359
+ {configManaged && (
360
+ <div className="shrink-0 px-4 pb-2">
361
+ <OperatorManagedNotice helmValue="helm.ociSources" />
362
+ </div>
363
+ )}
364
+ {!configManaged && ownerOnly && (
365
+ <p className="shrink-0 px-4 pb-2 text-xs text-theme-text-secondary">
366
+ Only organization owners can add or remove chart sources.
367
+ </p>
368
+ )}
369
+ {view !== 'manual' && (
370
+ <div
371
+ role="tablist"
372
+ aria-label="Chart source location"
373
+ className="shrink-0 flex gap-5 px-4 border-b border-theme-border"
374
+ >
375
+ {locations.map((tab, index) => (
376
+ <button
377
+ key={tab}
378
+ id={`${panelId}-${tab}`}
379
+ type="button"
380
+ role="tab"
381
+ aria-controls={panelId}
382
+ aria-selected={view === tab}
383
+ tabIndex={view === tab ? 0 : -1}
384
+ onKeyDown={(event) => {
385
+ const next =
386
+ event.key === 'Home'
387
+ ? 0
388
+ : event.key === 'End'
389
+ ? locations.length - 1
390
+ : event.key === 'ArrowRight'
391
+ ? (index + 1) % locations.length
392
+ : event.key === 'ArrowLeft'
393
+ ? (index + locations.length - 1) % locations.length
394
+ : undefined
395
+ if (next === undefined) return
396
+ event.preventDefault()
397
+ setView(locations[next])
398
+ setFilter('')
399
+ document.getElementById(`${panelId}-${locations[next]}`)?.focus()
400
+ }}
401
+ onClick={() => {
402
+ setView(tab === 'public' ? 'public' : 'added')
403
+ setFilter('')
404
+ }}
405
+ className={`py-2 text-sm border-b-2 ${view === tab ? 'border-accent text-theme-text-primary' : 'border-transparent text-theme-text-secondary'}`}
406
+ >
407
+ {tab === 'added' ? 'My Repos' : 'ArtifactHub'}
408
+ </button>
409
+ ))}
410
+ </div>
411
+ )}
412
+ <div
413
+ id={panelId}
414
+ role={view === 'manual' ? undefined : 'tabpanel'}
415
+ aria-labelledby={view === 'manual' ? undefined : `${panelId}-${view}`}
416
+ className="flex flex-col flex-1 min-h-0"
417
+ >
418
+ {view === 'public' && open && chartName ? (
419
+ <ArtifactHubSourceSearch
420
+ chartName={chartName}
421
+ disabled={configBusy || sourceBusy}
422
+ manualAction={manualAction}
423
+ isConfigured={(source) =>
424
+ source.type === 'oci'
425
+ ? (ociSources ?? []).some((prefix) => publicChartSourceURL(prefix) === source.prefix)
426
+ : (repositories ?? []).some((repository) => publicChartSourceURL(repository.url) === source.url)
427
+ }
428
+ onConfigured={(source) =>
429
+ showAdded(
430
+ source.type === 'oci'
431
+ ? { type: 'oci', reference: source.url }
432
+ : { type: 'repository', reference: '', url: source.url },
433
+ )
434
+ }
435
+ onAdd={(chart, source) => {
436
+ const isCurrent = currentSession()
437
+ if (source.type === 'oci')
438
+ addOCI.mutate(source.prefix, {
439
+ onSuccess: () => {
440
+ if (isCurrent()) showAdded({ type: 'oci', reference: source.url })
441
+ },
442
+ })
443
+ else
444
+ addRepository.mutate(
445
+ { name: recordedRepositoryName(chart.repository.name, repositories ?? []), url: source.url },
446
+ {
447
+ onSuccess: (result) => {
448
+ if (isCurrent()) showAdded({ type: 'repository', reference: result.name, url: source.url })
449
+ },
450
+ },
451
+ )
452
+ }}
453
+ />
454
+ ) : view === 'manual' ? (
455
+ <>
456
+ <div className="flex-1 min-h-0 overflow-y-auto p-4 space-y-4" aria-label="Manual source setup">
457
+ <div className="flex gap-3" role="group" aria-label="Source type">
458
+ <button
459
+ type="button"
460
+ onClick={() => setManualType('repository')}
461
+ aria-pressed={manualType === 'repository'}
462
+ className={`px-3 py-1.5 text-sm rounded-md ${manualType === 'repository' ? 'bg-theme-active' : 'text-theme-text-secondary'}`}
463
+ >
464
+ Helm repository
465
+ </button>
466
+ <button
467
+ type="button"
468
+ onClick={() => setManualType('oci')}
469
+ aria-pressed={manualType === 'oci'}
470
+ className={`px-3 py-1.5 text-sm rounded-md ${manualType === 'oci' ? 'bg-theme-active' : 'text-theme-text-secondary'}`}
471
+ >
472
+ OCI registry
473
+ </button>
474
+ </div>
475
+ <form id={formId} onSubmit={submitManual} className="space-y-3">
476
+ {manualType === 'repository' ? (
477
+ <>
478
+ <label className="block text-sm text-theme-text-secondary">
479
+ Repository name
480
+ <Input
481
+ value={repositoryName}
482
+ onChange={(event) => setRepositoryName(event.target.value)}
483
+ placeholder="Repository name"
484
+ disabled={configBusy}
485
+ className="mt-1 w-full"
486
+ />
487
+ </label>
488
+ <label className="block text-sm text-theme-text-secondary">
489
+ Repository address
490
+ <Input
491
+ value={repositoryURL}
492
+ onChange={(event) => setRepositoryURL(event.target.value)}
493
+ placeholder="https://charts.example.com"
494
+ disabled={configBusy}
495
+ className="mt-1 w-full"
496
+ />
497
+ </label>
498
+ </>
499
+ ) : (
500
+ <label className="block text-sm text-theme-text-secondary">
501
+ OCI prefix
502
+ <Input
503
+ value={ociPrefix}
504
+ onChange={(event) => setOCIPrefix(event.target.value)}
505
+ placeholder="oci://registry.example.com/charts"
506
+ disabled={configBusy}
507
+ className="mt-1 w-full"
508
+ />
509
+ </label>
510
+ )}
511
+ <p className="text-xs text-theme-text-tertiary">
512
+ After adding a source, choose it for an upgrade or check and record it for this release.
513
+ </p>
514
+ </form>
515
+ {manualType === 'oci' && ociSources && ociSources.length > 0 && (
516
+ <div className="space-y-2">
517
+ <p className="text-xs text-theme-text-tertiary">Registered OCI prefixes</p>
518
+ <ul className="divide-y divide-theme-border">
519
+ {ociSources.map((source) => (
520
+ <li key={source} className="flex items-center justify-between gap-2 py-2">
521
+ <span className="font-mono text-xs break-all">{source}</span>
522
+ {canEditSources && (
523
+ <button
524
+ type="button"
525
+ onClick={() => removeOCI.mutate(source)}
526
+ disabled={removeOCI.isPending}
527
+ aria-label={`Remove ${source}`}
528
+ className="p-1 shrink-0 text-theme-text-secondary hover:text-theme-text-primary disabled:opacity-50"
529
+ >
530
+ <Trash2 className="w-4 h-4" />
531
+ </button>
532
+ )}
533
+ </li>
534
+ ))}
535
+ </ul>
536
+ </div>
537
+ )}
538
+ {manualType === 'oci' && clusterInfo?.inCluster && (
539
+ <p className="text-xs text-warning-text">
540
+ Private OCI sources need credentials available to the in-cluster Radar process.
541
+ </p>
542
+ )}
543
+ </div>
544
+ <footer className="shrink-0 flex items-center justify-between gap-3 px-4 py-3 border-t border-theme-border">
545
+ {manualAction}
546
+ <button
547
+ type="submit"
548
+ form={formId}
549
+ disabled={
550
+ configBusy ||
551
+ (manualType === 'repository'
552
+ ? !repositoryName.trim() || !isValidHelmRepositoryURL(repositoryURL)
553
+ : !ociPrefix.trim().startsWith('oci://'))
554
+ }
555
+ className="btn-brand px-3 py-2 text-sm"
556
+ >
557
+ {manualType === 'repository' ? 'Add repository' : 'Register OCI source'}
558
+ </button>
559
+ </footer>
560
+ </>
561
+ ) : (
562
+ <>
563
+ {choices.length > 6 && (
564
+ <div className="shrink-0 px-4 py-3 border-b border-theme-border">
565
+ <Input
566
+ aria-label="Filter configured sources"
567
+ placeholder="Filter by name or address"
568
+ value={filter}
569
+ onChange={(event) => {
570
+ setFilter(event.target.value)
571
+ setSelectedKey('')
572
+ }}
573
+ className="w-full"
574
+ />
575
+ </div>
576
+ )}
577
+ <div className="flex-1 min-h-0 overflow-y-auto" aria-label="Configured chart sources">
578
+ {visible.length === 0 ? (
579
+ <div className="min-h-40 h-full flex flex-col items-center justify-center gap-3 p-4 text-center">
580
+ <p className="text-sm text-theme-text-secondary">
581
+ {filter ? 'No matching sources.' : 'No configured sources found.'}
582
+ </p>
583
+ {!filter && chartName && sourceFeature.support === 'supported' && (
584
+ <button type="button" onClick={() => setView('public')} className="btn-brand px-3 py-2 text-sm">
585
+ Find a public source
586
+ </button>
587
+ )}
588
+ </div>
589
+ ) : (
590
+ visible.map((source) => {
591
+ const suggestion = status?.suggestions?.find((item) => sourceKey(item.source) === sourceKey(source))
592
+ const isRecorded = recorded && sourceKey(recorded) === sourceKey(source)
593
+ return (
594
+ <button
595
+ key={sourceKey(source)}
596
+ type="button"
597
+ onClick={() => setSelectedKey(sourceKey(source))}
598
+ aria-pressed={selectedKey === sourceKey(source)}
599
+ aria-label={`Choose configured source: ${source.url ?? source.reference}`}
600
+ className={`w-full text-left px-4 py-3 border-b border-theme-border hover:bg-theme-hover ${selectedKey === sourceKey(source) ? 'bg-theme-active' : ''}`}
601
+ >
602
+ <span className="block text-sm font-medium">
603
+ {source.type === 'repository' ? source.reference : 'OCI chart'}
604
+ <span className="ml-2 font-normal text-xs text-theme-text-tertiary">
605
+ {isRecorded
606
+ ? status?.confirmed
607
+ ? 'Current source'
608
+ : 'Last recorded source'
609
+ : source.type === 'oci'
610
+ ? 'Registered source'
611
+ : 'Configured repository'}
612
+ </span>
613
+ </span>
614
+ <span className="block font-mono text-xs text-theme-text-secondary break-all mt-1">
615
+ {source.url ?? source.reference}
616
+ </span>
617
+ {((isRecorded && !status?.configured) || suggestion?.state === 'index_unavailable') && (
618
+ <span className="block text-xs text-warning-text mt-1">
619
+ {isRecorded && !status?.configured
620
+ ? 'Not configured here'
621
+ : 'Refresh its index in Helm Catalog'}
622
+ </span>
623
+ )}
624
+ </button>
625
+ )
626
+ })
627
+ )}
628
+ </div>
629
+ <footer className="shrink-0 border-t border-theme-border px-4 py-3 space-y-2">
630
+ {selectedMissing && (
631
+ <p className="text-xs text-theme-text-tertiary">
632
+ {recordedName ? (
633
+ <>
634
+ Saved in Helm as <span className="font-mono">{recordedName}</span>.
635
+ {recordedName !== missingRecorded.reference && (
636
+ <>
637
+ {' '}
638
+ The name <span className="font-mono">{missingRecorded.reference}</span> is already taken or
639
+ needs normalization.
640
+ </>
641
+ )}
642
+ </>
643
+ ) : (
644
+ 'Radar picks a repository name from the address.'
645
+ )}
646
+ </p>
647
+ )}
648
+ {selected && !selectedMissing && (
649
+ <p className="text-xs text-theme-text-tertiary">
650
+ {canVerify
651
+ ? 'Radar compares the chart information Helm saved. Matching copies can come from more than one publisher.'
652
+ : 'Review the chart version, settings and resource changes before applying.'}
653
+ </p>
654
+ )}
655
+ <div className="flex flex-wrap items-center justify-between gap-3">
656
+ {manualAction}
657
+ <div className="flex flex-wrap items-center gap-3">
658
+ {canVerify && !selectedMissing && (
659
+ <button
660
+ type="button"
661
+ onClick={() => {
662
+ const isCurrent = currentSession()
663
+ if (selected)
664
+ setSource.mutate(selected, {
665
+ onSuccess: () => {
666
+ if (isCurrent()) onClose()
667
+ },
668
+ })
669
+ }}
670
+ disabled={sourceBusy}
671
+ className="text-sm text-accent hover:underline disabled:opacity-50"
672
+ >
673
+ Check and record source
674
+ </button>
675
+ )}
676
+ {selectedMissing ? (
677
+ <button
678
+ type="button"
679
+ onClick={addRecorded}
680
+ disabled={configBusy || sourceBusy}
681
+ className="btn-brand px-3 py-2 text-sm"
682
+ >
683
+ {status?.confirmed !== false ? 'Add repository and use it' : 'Add repository'}
684
+ </button>
685
+ ) : sourceFeature.support === 'supported' && onSelectUpgradeSource && status?.revision ? (
686
+ <button
687
+ type="button"
688
+ disabled={!selected || sourceBusy}
689
+ onClick={() => {
690
+ if (selected && status.revision)
691
+ onSelectUpgradeSource({
692
+ source: selected,
693
+ expectedRevision: status.revision,
694
+ expectedSource: status.recorded ?? null,
695
+ })
696
+ }}
697
+ className="btn-brand px-3 py-2 text-sm"
698
+ >
699
+ Select for upgrade
700
+ </button>
701
+ ) : null}
702
+ </div>
703
+ </div>
704
+ </footer>
705
+ </>
706
+ )}
163
707
  </div>
164
- {missingRecordedRepository && recordedName !== undefined && <div className="space-y-1">
165
- <button type="button" onClick={addRecordedRepository} disabled={!canEditSources || repositoriesLoading || addRepository.isPending} className="btn-brand inline-flex items-center gap-1 px-3 py-2 max-w-full"><Plus className="w-4 h-4 shrink-0" /><span className="truncate">Add {repositoryDisplayURL(missingRecordedRepository.url)}{status?.confirmed !== false ? ' and use it' : ' repository'}</span></button>
166
- <p className="text-xs text-theme-text-tertiary">{!recordedName
167
- ? 'Radar picks a name for it in Helm.'
168
- : recordedName === missingRecordedRepository.reference
169
- ? <>Saved in Helm as <span className="font-mono">{recordedName}</span>, the name it was recorded under.</>
170
- : recordedName === normalizedRepositoryName(missingRecordedRepository.reference)
171
- ? <>Saved in Helm as <span className="font-mono">{recordedName}</span>.</>
172
- : <>Saved in Helm as <span className="font-mono">{recordedName}</span>. The name <span className="font-mono">{missingRecordedRepository.reference}</span> already points to a different repository here.</>}</p>
173
- </div>}
174
- {sourceFeature.support === 'supported' && onSelectUpgradeSource && status?.revision && <div className="space-y-2">
175
- <p className="text-sm font-medium">Sources to use for the next upgrade</p>
176
- <p className="text-xs text-theme-text-secondary">Matching chart names can contain different settings and resources. Review the selected chart before applying.</p>
177
- {(status.suggestions ?? []).map(suggestion => <div key={`${suggestion.source.type}:${suggestion.source.url ?? suggestion.source.reference}`} className="w-full rounded-lg border border-theme-border px-3 py-2">
178
- <span className="text-xs text-theme-text-secondary">{suggestion.current ? status.confirmed && !status.sourceChangeRequired && !status.changing ? 'Current source' : 'Last recorded source' : 'Other source'}{suggestion.state === 'unchecked' ? ' - check versions' : suggestion.state === 'index_unavailable' ? ' - refresh its index first' : ''}</span>
179
- <span className="block font-mono text-sm break-all">{suggestion.source.url ?? suggestion.source.reference}</span>
180
- <button type="button" aria-label={`Select for upgrade: ${suggestion.source.url ?? suggestion.source.reference}`} disabled={status.changing || statusFetching} onClick={() => {
181
- if (!status.revision) return
182
- onSelectUpgradeSource({ source: suggestion.source, expectedRevision: status.revision, expectedSource: status.recorded ?? null })
183
- }} className="mt-1 text-sm text-accent hover:underline disabled:opacity-50">Select for upgrade</button>
184
- {suggestion.source.type === 'oci' && !status.confirmed && !status.sourceChangeRequired && <button type="button" disabled={status.changing || statusFetching || setSource.isPending} onClick={() => setSource.mutate(suggestion.source, { onSuccess: onClose })} className="ml-3 text-sm text-accent hover:underline disabled:opacity-50">Verify and record original source</button>}
185
- </div>)}
186
- {(status.suggestions ?? []).length === 0 && <p className="text-sm text-theme-text-secondary">No configured sources found. Add a repository or OCI source.</p>}
187
- </div>}
188
- {!status?.confirmed && !status?.sourceChangeRequired && status?.candidates && status.candidates.length > 0 && <div>
189
- <p className="text-xs uppercase tracking-wide text-theme-text-tertiary mb-2">Configured sources that publish {chartName || 'this chart'} at the installed version</p>
190
- <div className="space-y-2">{status.candidates.filter(candidate => !status.confirmed || !recorded || (candidate.type === recorded.type && (candidate.url ?? candidate.reference) === (recorded.url ?? recorded.reference))).map(candidate => <button key={`${candidate.type}:${candidate.url ?? candidate.reference}`} onClick={() => setSource.mutate(candidate, { onSuccess: onClose })} disabled={setSource.isPending || statusFetching || status.changing} className="w-full text-left rounded-lg border border-theme-border px-3 py-2 hover:border-accent disabled:opacity-50"><span className="text-xs uppercase text-theme-text-tertiary">{candidate.type}</span><span className="block font-mono text-sm break-all">{candidate.url ?? candidate.reference}</span><span className="text-xs text-accent">Record as original source</span></button>)}</div>
191
- {status.candidates.length > 1 && <p className="text-xs text-amber-600 mt-2">Multiple sources list this chart name and version. Select the original source; Radar compares the stored chart before recording it.</p>}
192
- </div>}
193
- <form onSubmit={addRepositoryAndAssociate} className="space-y-2">
194
- <p className="text-xs uppercase tracking-wide text-theme-text-tertiary">Add chart repository</p>
195
- <div className="grid grid-cols-1 md:grid-cols-[minmax(0,0.8fr)_minmax(0,1.8fr)_auto] gap-2"><Input value={repositoryName} onChange={event => setRepositoryName(event.target.value)} placeholder="Repository name" disabled={!canEditSources} /><Input value={repositoryURL} onChange={event => setRepositoryURL(event.target.value)} placeholder="https://charts.example.com" disabled={!canEditSources} /><button type="submit" disabled={!canEditSources || !repositoryName.trim() || !isValidHelmRepositoryURL(repositoryURL) || addRepository.isPending} className="btn-brand inline-flex items-center justify-center gap-1 px-3 py-2"><Plus className="w-4 h-4" /> Add</button></div>
196
- <p className="text-xs text-theme-text-tertiary">After adding it, select the repository for an upgrade, or associate it with the installed version.</p>
197
- </form>
198
- <form onSubmit={addOCIPrefix} className="space-y-2">
199
- <p className="text-xs uppercase tracking-wide text-theme-text-tertiary">Register OCI prefix</p>
200
- <div className="flex gap-2"><Input value={ociPrefix} onChange={event => setOCIPrefix(event.target.value)} placeholder="oci://registry.example.com/charts" disabled={!canEditSources} /><button type="submit" disabled={!canEditSources || !ociPrefix.trim().startsWith('oci://') || addOCI.isPending} className="btn-brand px-3 py-2">Add</button></div>
201
- <p className="text-xs text-theme-text-tertiary">After registration, select it in the list above. Credentials are reused from Helm and are never recorded in release provenance.</p>
202
- </form>
203
- {ociSources && ociSources.length > 0 && <ul className="space-y-1">{ociSources.map(source => <li key={source} className="flex items-center justify-between gap-2 rounded-lg bg-theme-elevated px-3 py-2"><span className="font-mono text-sm truncate">{source}</span>{canEditSources && <button onClick={() => removeOCI.mutate(source)} disabled={removeOCI.isPending} aria-label={`Remove ${source}`} className="p-1 hover:text-red-400 disabled:opacity-50"><Trash2 className="w-4 h-4" /></button>}</li>)}</ul>}
204
- {clusterInfo?.inCluster && <p className="text-xs text-amber-600 flex items-start gap-2"><AlertTriangle className="w-4 h-4 shrink-0" />Private OCI sources require credentials available to the in-cluster Radar process.</p>}
205
- </div>
206
- </DialogPortal>
708
+ </DialogPortal>
709
+ )
207
710
  }