@skyhook-io/radar-app 1.22.2 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/App.tsx +49 -13
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/api/agentSandbox.ts +259 -0
- package/src/api/client.autoPromConnect.test.tsx +43 -0
- package/src/api/client.metricsRelayCheck.test.tsx +134 -0
- package/src/api/client.ts +151 -27
- package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
- package/src/api/cloudInstallDiscover.test.tsx +76 -0
- package/src/api/diagnose.ts +4 -0
- package/src/api/kagent.test.ts +82 -0
- package/src/api/kagent.ts +230 -0
- package/src/api/poll.ts +78 -0
- package/src/api/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +16 -0
- package/src/api/substrateWorkspace.test.ts +72 -0
- package/src/api/substrateWorkspace.ts +1394 -0
- package/src/api/vulnerabilities.ts +207 -9
- package/src/api/workloadSource.test.tsx +315 -0
- package/src/api/workloadSource.ts +128 -12
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +128 -32
- package/src/components/SelfManagedStart.tsx +12 -2
- package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
- package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
- package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
- package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
- package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
- package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
- package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
- package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
- package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
- package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
- package/src/components/agentsandbox/data.ts +135 -0
- package/src/components/agentsandbox/host.test.ts +27 -0
- package/src/components/agentsandbox/host.tsx +85 -0
- package/src/components/agentsandbox/labels.test.ts +42 -0
- package/src/components/agentsandbox/labels.ts +146 -0
- package/src/components/agentsandbox/listFilters.ts +85 -0
- package/src/components/agentsandbox/lists.ts +52 -0
- package/src/components/agentsandbox/routes.ts +23 -0
- package/src/components/agentsandbox/shared.tsx +321 -0
- package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
- package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
- package/src/components/agentsandbox/workspace.tsx +258 -0
- package/src/components/agentsandbox/workspaceRoute.ts +18 -0
- package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
- package/src/components/applications/ApplicationsView.tsx +156 -3
- package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
- package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
- package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
- package/src/components/audit/VulnerabilitiesView.tsx +639 -199
- package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
- package/src/components/cloudHints/CloudHintLink.tsx +29 -0
- package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
- package/src/components/cloudHints/cloudHints.test.ts +126 -0
- package/src/components/cloudHints/cloudHints.ts +131 -0
- package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
- package/src/components/cloudHints/cloudLinks.test.ts +52 -0
- package/src/components/cloudHints/cloudLinks.ts +31 -0
- package/src/components/cloudHints/hintStorage.ts +28 -0
- package/src/components/cnpg/CNPGView.tsx +4 -7
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/DiagnoseContext.tsx +7 -0
- package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
- package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
- package/src/components/helm/HelmView.tsx +4 -3
- package/src/components/helm/ObservedHelmNotice.tsx +39 -17
- package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
- package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
- package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +3 -3
- package/src/components/home/MCPSetupDialog.test.tsx +9 -0
- package/src/components/home/MCPSetupDialog.tsx +6 -2
- package/src/components/home/McpCloudLine.test.tsx +162 -0
- package/src/components/home/McpCloudLine.tsx +95 -0
- package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +4 -4
- package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
- package/src/components/issues/IssuesPane.render.test.tsx +36 -1
- package/src/components/issues/IssuesPane.tsx +181 -23
- package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
- package/src/components/issues/SinceLastVisitRow.tsx +71 -0
- package/src/components/issues/sinceLastVisit.test.ts +266 -0
- package/src/components/issues/sinceLastVisit.ts +439 -0
- package/src/components/issues/uncheckedSources.test.ts +8 -0
- package/src/components/issues/uncheckedSources.ts +3 -0
- package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
- package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
- package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
- package/src/components/kagent/KagentAgentSessions.tsx +124 -0
- package/src/components/kagent/KagentDetailPage.tsx +106 -0
- package/src/components/kagent/KagentLists.tsx +412 -0
- package/src/components/kagent/KagentOverview.tsx +234 -0
- package/src/components/kagent/KagentPages.tsx +690 -0
- package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
- package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
- package/src/components/kagent/KagentSidebar.test.tsx +112 -0
- package/src/components/kagent/KagentView.tsx +109 -0
- package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
- package/src/components/kagent/host.tsx +144 -0
- package/src/components/kagent/routes.ts +31 -0
- package/src/components/kagent/shared.tsx +336 -0
- package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
- package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
- package/src/components/kagent/workspace.fixtures.ts +108 -0
- package/src/components/kagent/workspaceRoute.ts +18 -0
- package/src/components/nudges/activeNudges.test.ts +39 -0
- package/src/components/nudges/activeNudges.ts +76 -0
- package/src/components/poll/OssPoll.tsx +871 -0
- package/src/components/poll/mount.test.ts +12 -0
- package/src/components/poll/pollCloud.test.ts +23 -0
- package/src/components/poll/pollCloud.ts +6 -0
- package/src/components/poll/pollDefinition.ts +93 -0
- package/src/components/poll/pollFlow.test.ts +140 -0
- package/src/components/poll/pollFlow.ts +137 -0
- package/src/components/poll/pollSender.test.ts +137 -0
- package/src/components/poll/pollSender.ts +76 -0
- package/src/components/poll/pollStorage.test.ts +53 -0
- package/src/components/poll/pollStorage.ts +77 -0
- package/src/components/poll/round.json +350 -0
- package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
- package/src/components/resource/MetricsNotConnected.tsx +10 -7
- package/src/components/resource/PrometheusCharts.tsx +10 -1
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
- package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
- package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
- package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
- package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
- package/src/components/resources/ImageFilesystemModal.tsx +42 -3
- package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +24 -11
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
- package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
- package/src/components/settings/SettingsDialog.tsx +84 -16
- package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
- package/src/components/settings/SubstrateSettings.test.tsx +131 -0
- package/src/components/settings/SubstrateSettings.tsx +544 -0
- package/src/components/settings/settings-state.test.ts +21 -3
- package/src/components/settings/settings-state.ts +13 -3
- package/src/components/share/ShareLinkButton.test.tsx +360 -0
- package/src/components/share/ShareLinkButton.tsx +391 -0
- package/src/components/share/openShareInCloud.test.ts +29 -0
- package/src/components/share/openShareInCloud.ts +10 -0
- package/src/components/share/shareLink.test.ts +129 -0
- package/src/components/share/shareLink.ts +175 -0
- package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
- package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
- package/src/components/substrate/SubstrateActorPage.tsx +384 -0
- package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
- package/src/components/substrate/SubstrateActors.tsx +612 -0
- package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
- package/src/components/substrate/SubstrateConnect.tsx +88 -0
- package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
- package/src/components/substrate/SubstrateOverview.tsx +575 -0
- package/src/components/substrate/SubstratePages.test.tsx +478 -0
- package/src/components/substrate/SubstratePool.test.tsx +462 -0
- package/src/components/substrate/SubstratePoolPage.tsx +95 -0
- package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
- package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
- package/src/components/substrate/SubstrateStateBar.tsx +63 -0
- package/src/components/substrate/SubstrateTemplates.tsx +376 -0
- package/src/components/substrate/SubstrateView.tsx +173 -0
- package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
- package/src/components/substrate/SubstrateWorkers.tsx +389 -0
- package/src/components/substrate/attention.ts +81 -0
- package/src/components/substrate/contextPin.tsx +69 -0
- package/src/components/substrate/host.tsx +83 -0
- package/src/components/substrate/kubectlTarget.test.tsx +77 -0
- package/src/components/substrate/readings.test.ts +484 -0
- package/src/components/substrate/readings.ts +997 -0
- package/src/components/substrate/routes.ts +103 -0
- package/src/components/substrate/shared.tsx +426 -0
- package/src/components/substrate/substrate.fixtures.ts +325 -0
- package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
- package/src/components/substrate/workspaceRoute.ts +23 -0
- package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
- package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
- package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
- package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
- package/src/components/traffic/TrafficFlowList.tsx +9 -5
- package/src/components/traffic/TrafficGraph.test.tsx +26 -0
- package/src/components/traffic/TrafficGraph.tsx +17 -14
- package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
- package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
- package/src/components/traffic/TrafficView.tsx +26 -56
- package/src/components/traffic/trafficFilters.test.ts +61 -1
- package/src/components/traffic/trafficFilters.ts +68 -8
- package/src/components/ui/UpdateNotification.tsx +2 -0
- package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
- package/src/components/velero/VeleroOverview.tsx +2 -2
- package/src/components/velero/VeleroView.tsx +3 -6
- package/src/components/vulnerabilities/columns.tsx +132 -0
- package/src/components/vulnerabilities/filters.tsx +317 -0
- package/src/components/vulnerabilities/owner.test.ts +54 -0
- package/src/components/vulnerabilities/owner.tsx +163 -0
- package/src/components/vulnerabilities/parts.test.ts +126 -12
- package/src/components/vulnerabilities/parts.tsx +612 -52
- package/src/components/vulnerabilities/traffic.test.tsx +65 -0
- package/src/components/vulnerabilities/traffic.tsx +40 -0
- package/src/components/whats-new/WhatsNew.tsx +2 -0
- package/src/components/whats-new/releaseNotes.ts +75 -1
- package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +52 -13
- package/src/components/workspace/layout.tsx +13 -7
- package/src/components/workspace/sidebar.test.ts +48 -0
- package/src/components/workspace/sidebar.ts +73 -3
- package/src/components/workspace/table.ts +2 -1
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/integrations/resourceHost.ts +12 -6
- package/src/integrations/resourceHosts.test.tsx +27 -1
- package/src/integrations/resourceHosts.tsx +15 -7
- package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
- package/src/integrations/sidebarWorkspaces.ts +41 -0
- package/src/integrations/workspaceRoute.ts +1 -1
- package/src/integrations/workspaceRoutes.ts +7 -1
- package/src/integrations/workspaceScreens.tsx +6 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react'
|
|
2
|
-
import { useQuery, type QueryClient, type UseQueryResult } from '@tanstack/react-query'
|
|
2
|
+
import { useQueries, useQuery, useQueryClient, type QueryClient, type UseQueryResult } from '@tanstack/react-query'
|
|
3
3
|
import {
|
|
4
4
|
getRadarUpgradeRequirement,
|
|
5
5
|
type RadarUpgradeRequirement,
|
|
@@ -183,12 +183,27 @@ export function createWorkloadSourceInvalidator(
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
+
function shouldDropCachedSourceOnError(error: unknown): boolean {
|
|
187
|
+
const status = (error as { status?: number } | null)?.status
|
|
188
|
+
return status === 401 || status === 403 || status === 404
|
|
189
|
+
}
|
|
190
|
+
|
|
186
191
|
export type WorkloadSourceQueryResult = UseQueryResult<WorkloadSourceResponse, Error> & {
|
|
187
192
|
support: RadarFeatureSupport
|
|
188
193
|
upgrade: RadarUpgradeRequirement | null
|
|
189
194
|
cachedData?: WorkloadSourceResponse
|
|
190
195
|
}
|
|
191
196
|
|
|
197
|
+
// Evicts cached data on the existing query entry without deleting the entry
|
|
198
|
+
// (removeQueries on a mounted query triggers a fresh refetch) and without
|
|
199
|
+
// calling setQueryData(undefined) (which is a no-op in TanStack Query v5).
|
|
200
|
+
function evictCachedWorkloadSource(queryClient: QueryClient, queryKey: readonly unknown[]) {
|
|
201
|
+
queryClient.getQueryCache().find({ queryKey, exact: true })?.setState({
|
|
202
|
+
data: undefined,
|
|
203
|
+
dataUpdatedAt: 0,
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
192
207
|
export function useWorkloadSource(
|
|
193
208
|
kind: string,
|
|
194
209
|
namespace: string,
|
|
@@ -212,16 +227,26 @@ export function useWorkloadSource(
|
|
|
212
227
|
? last.data
|
|
213
228
|
: undefined
|
|
214
229
|
|
|
230
|
+
const queryClient = useQueryClient()
|
|
215
231
|
const { guard, gatedKey, support, upgrade } = useRadarFeature('workloadSource')
|
|
216
232
|
const query = useQuery<WorkloadSourceResponse, Error>({
|
|
217
233
|
queryKey: ['workload-source', apiBase, normalizedKind, namespace, name, normalizedUid, ...gatedKey],
|
|
218
|
-
queryFn: ({ signal }) =>
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
234
|
+
queryFn: async ({ signal, queryKey }) => {
|
|
235
|
+
try {
|
|
236
|
+
return await guard(() =>
|
|
237
|
+
fetchJSON<WorkloadSourceResponse>(
|
|
238
|
+
`/workloads/${encodeURIComponent(normalizedKind)}/${encodeURIComponent(namespace)}/${encodeURIComponent(name)}/source`,
|
|
239
|
+
signal,
|
|
240
|
+
),
|
|
241
|
+
)
|
|
242
|
+
} catch (err) {
|
|
243
|
+
if (shouldDropCachedSourceOnError(err)) {
|
|
244
|
+
lastSuccessRef.current = null
|
|
245
|
+
evictCachedWorkloadSource(queryClient, queryKey)
|
|
246
|
+
}
|
|
247
|
+
throw err
|
|
248
|
+
}
|
|
249
|
+
},
|
|
225
250
|
placeholderData: () => sameWorkloadCached,
|
|
226
251
|
staleTime: 60_000,
|
|
227
252
|
// Fallback for large clusters where namespace-scoped SSE streams filter out
|
|
@@ -235,13 +260,17 @@ export function useWorkloadSource(
|
|
|
235
260
|
enabled: enabled && Boolean(normalizedKind && namespace && name),
|
|
236
261
|
})
|
|
237
262
|
|
|
263
|
+
const dropCached = shouldDropCachedSourceOnError(query.error)
|
|
264
|
+
|
|
238
265
|
useEffect(() => {
|
|
239
|
-
if (
|
|
266
|
+
if (dropCached) {
|
|
267
|
+
lastSuccessRef.current = null
|
|
268
|
+
} else if (query.data && !query.isPlaceholderData) {
|
|
240
269
|
lastSuccessRef.current = { base: workloadBase, uid: normalizedUid, data: query.data }
|
|
241
270
|
} else if (lastSuccessRef.current && !sameWorkloadCached) {
|
|
242
271
|
lastSuccessRef.current = null
|
|
243
272
|
}
|
|
244
|
-
}, [query.data, query.isPlaceholderData, workloadBase, normalizedUid, sameWorkloadCached])
|
|
273
|
+
}, [dropCached, query.data, query.isPlaceholderData, workloadBase, normalizedUid, sameWorkloadCached])
|
|
245
274
|
|
|
246
275
|
const { error, refetch } = query
|
|
247
276
|
useEffect(() => {
|
|
@@ -254,7 +283,7 @@ export function useWorkloadSource(
|
|
|
254
283
|
...query,
|
|
255
284
|
support,
|
|
256
285
|
upgrade,
|
|
257
|
-
cachedData: query.data ?? sameWorkloadCached,
|
|
286
|
+
cachedData: dropCached ? undefined : (query.data ?? sameWorkloadCached),
|
|
258
287
|
}
|
|
259
288
|
}
|
|
260
289
|
|
|
@@ -265,7 +294,7 @@ export function toWorkloadSourceState(query: WorkloadSourceQueryResult): Workloa
|
|
|
265
294
|
upgrade: getRadarUpgradeRequirement(query.error) ?? query.upgrade ?? undefined,
|
|
266
295
|
}
|
|
267
296
|
}
|
|
268
|
-
const data = query.data ?? query.cachedData
|
|
297
|
+
const data = shouldDropCachedSourceOnError(query.error) ? undefined : (query.data ?? query.cachedData)
|
|
269
298
|
if (data) {
|
|
270
299
|
if (query.error) {
|
|
271
300
|
return {
|
|
@@ -290,3 +319,90 @@ export function toWorkloadSourceState(query: WorkloadSourceQueryResult): Workloa
|
|
|
290
319
|
}
|
|
291
320
|
return { status: 'loading' }
|
|
292
321
|
}
|
|
322
|
+
|
|
323
|
+
export interface WorkloadSourceTargetRef {
|
|
324
|
+
kind: string
|
|
325
|
+
group?: string
|
|
326
|
+
namespace: string
|
|
327
|
+
name: string
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export type WorkloadSourcesRead =
|
|
331
|
+
| { status: 'loading' }
|
|
332
|
+
| { status: 'unreadable'; denied: boolean; message?: string }
|
|
333
|
+
| { status: 'ready'; source: WorkloadSourceResponse; stale?: boolean }
|
|
334
|
+
|
|
335
|
+
// The most workloads one page reads source for at once. Past this limit across
|
|
336
|
+
// environments, cross-environment comparison is skipped while the viewed
|
|
337
|
+
// environment's own workloads are still read when they fit within the limit.
|
|
338
|
+
export const WORKLOAD_SOURCES_MAX = 24
|
|
339
|
+
|
|
340
|
+
/** Source reads for several workloads, sharing the per-workload cache and
|
|
341
|
+
* invalidation of useWorkloadSource. Returns null when the feature is
|
|
342
|
+
* unsupported, disabled, or there are more than WORKLOAD_SOURCES_MAX targets. */
|
|
343
|
+
export function useWorkloadSources(targets: WorkloadSourceTargetRef[], enabled = true): Map<string, WorkloadSourcesRead> | null {
|
|
344
|
+
const apiBase = getApiBase()
|
|
345
|
+
const queryClient = useQueryClient()
|
|
346
|
+
const { guard, gatedKey, support } = useRadarFeature('workloadSource')
|
|
347
|
+
const usable = enabled && support === 'supported' && targets.length > 0 && targets.length <= WORKLOAD_SOURCES_MAX
|
|
348
|
+
const resolved = targets.map((t) => ({ ...t, plural: kindToPluralWithGroup(t.kind, t.group ?? '').toLowerCase() }))
|
|
349
|
+
const results = useQueries({
|
|
350
|
+
queries: resolved.map((t) => ({
|
|
351
|
+
// Not 'workload-source': the per-Pod SSE invalidation that keeps one
|
|
352
|
+
// workload's Source section current would refetch every workload of every
|
|
353
|
+
// environment on each Pod change. These follow the poll instead.
|
|
354
|
+
queryKey: ['app-workload-source', apiBase, t.plural, t.namespace, t.name, ...gatedKey],
|
|
355
|
+
queryFn: async ({ signal, queryKey }: { signal: AbortSignal; queryKey: readonly unknown[] }) => {
|
|
356
|
+
try {
|
|
357
|
+
return await guard(() =>
|
|
358
|
+
fetchJSON<WorkloadSourceResponse>(
|
|
359
|
+
`/workloads/${encodeURIComponent(t.plural)}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.name)}/source`,
|
|
360
|
+
signal,
|
|
361
|
+
),
|
|
362
|
+
)
|
|
363
|
+
} catch (err) {
|
|
364
|
+
if (shouldDropCachedSourceOnError(err)) {
|
|
365
|
+
evictCachedWorkloadSource(queryClient, queryKey)
|
|
366
|
+
}
|
|
367
|
+
throw err
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
staleTime: 60_000,
|
|
371
|
+
refetchInterval: (q: { state: { error: Error | null } }) =>
|
|
372
|
+
isRadarFeatureUnsupported(q.state.error, 'workloadSource') ? false : WORKLOAD_SOURCE_REFETCH_INTERVAL_MS,
|
|
373
|
+
refetchIntervalInBackground: false,
|
|
374
|
+
retry: shouldRetryRadarQuery,
|
|
375
|
+
enabled: usable && supportsWorkloadSource(t.plural, t.group),
|
|
376
|
+
})),
|
|
377
|
+
})
|
|
378
|
+
const resultsRef = useRef(results)
|
|
379
|
+
resultsRef.current = results
|
|
380
|
+
const hasUnsupportedError = results.some((r) => r.error instanceof RadarFeatureUnsupportedError)
|
|
381
|
+
useEffect(() => {
|
|
382
|
+
if (support !== 'supported' || !hasUnsupportedError) return
|
|
383
|
+
for (const r of resultsRef.current) {
|
|
384
|
+
if (r.error instanceof RadarFeatureUnsupportedError) {
|
|
385
|
+
void r.refetch()
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}, [support, hasUnsupportedError])
|
|
389
|
+
if (!usable) return null
|
|
390
|
+
if (results.some((r) => isRadarFeatureUnsupported(r.error, 'workloadSource'))) return null
|
|
391
|
+
const out = new Map<string, WorkloadSourcesRead>()
|
|
392
|
+
resolved.forEach((t, i) => {
|
|
393
|
+
const r = results[i]
|
|
394
|
+
const key = workloadSourceTargetKey(t)
|
|
395
|
+
const status = (r.error as { status?: number } | null)?.status
|
|
396
|
+
const denied = status === 403
|
|
397
|
+
const dropCached = shouldDropCachedSourceOnError(r.error)
|
|
398
|
+
// Auth loss, refusal, or missing workload outranks the cached answer.
|
|
399
|
+
if (r.data && !dropCached) out.set(key, { status: 'ready', source: r.data, ...(r.error ? { stale: true } : {}) })
|
|
400
|
+
else if (r.error) out.set(key, { status: 'unreadable', denied, message: r.error.message })
|
|
401
|
+
else out.set(key, { status: 'loading' })
|
|
402
|
+
})
|
|
403
|
+
return out
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export function workloadSourceTargetKey(t: WorkloadSourceTargetRef): string {
|
|
407
|
+
return `${(t.group ?? '').toLowerCase()}/${t.kind.toLowerCase()}/${t.namespace}/${t.name}`
|
|
408
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
cancelCloudInstall,
|
|
12
12
|
type CloudInstallBlocked,
|
|
13
13
|
type CloudInstallRecoveryGuidance,
|
|
14
|
+
type CloudInstallConnected,
|
|
14
15
|
type CloudInstallStage,
|
|
15
16
|
type CloudInstallStatus,
|
|
16
17
|
dismissCloudInstall,
|
|
@@ -22,16 +23,24 @@ import { showApiError } from './ui/Toast'
|
|
|
22
23
|
// flow itself is server-owned (it survives modal close and page reloads);
|
|
23
24
|
// this component only renders the observed status and issues transitions.
|
|
24
25
|
export function CloudConnectFlow({
|
|
25
|
-
status,
|
|
26
|
+
status: observed,
|
|
26
27
|
blocked,
|
|
27
28
|
exit,
|
|
28
29
|
where,
|
|
29
30
|
onStatus,
|
|
30
31
|
onExit,
|
|
32
|
+
tagUrl = (url) => url,
|
|
33
|
+
connectedAction,
|
|
31
34
|
}: {
|
|
32
35
|
status: CloudInstallStatus
|
|
33
36
|
blocked: CloudInstallBlocked | null
|
|
34
37
|
exit: BlockedExit
|
|
38
|
+
// Marks the Hub approval link with which hint opened the dialog, so the
|
|
39
|
+
// page the person opens can say where they came from.
|
|
40
|
+
tagUrl?: (url: string) => string
|
|
41
|
+
// What the person came to do once the cluster is in Radar Cloud (open the
|
|
42
|
+
// resource they were sharing), offered as the connected card's main action.
|
|
43
|
+
connectedAction?: (connected: CloudInstallConnected) => { label: string; href: string } | null
|
|
35
44
|
// Which cluster this is, for the note a blocked person hands to an admin.
|
|
36
45
|
where?: AdminNoteContext
|
|
37
46
|
// Push a mutation's status response into the shared query state.
|
|
@@ -43,11 +52,19 @@ export function CloudConnectFlow({
|
|
|
43
52
|
return <BlockedView blocked={blocked} exit={exit} where={where} onExit={onExit} />
|
|
44
53
|
}
|
|
45
54
|
|
|
55
|
+
const status: CloudInstallStatus = {
|
|
56
|
+
...observed,
|
|
57
|
+
...(observed.connectUrl && { connectUrl: tagUrl(observed.connectUrl) }),
|
|
58
|
+
...(observed.connected?.clusterUrl && {
|
|
59
|
+
connected: { ...observed.connected, clusterUrl: tagUrl(observed.connected.clusterUrl) },
|
|
60
|
+
}),
|
|
61
|
+
}
|
|
62
|
+
|
|
46
63
|
switch (status.state) {
|
|
47
64
|
case 'preparing':
|
|
48
65
|
return <PreparingCard step={status.prepareStep} context={where?.context} />
|
|
49
66
|
case 'ready':
|
|
50
|
-
return <PlanCard status={status} onStatus={onStatus} onExit={onExit} />
|
|
67
|
+
return <PlanCard status={status} onStatus={onStatus} onExit={onExit} tagUrl={tagUrl} />
|
|
51
68
|
case 'starting':
|
|
52
69
|
case 'awaiting_approval':
|
|
53
70
|
return <ApprovalCard status={status} onStatus={onStatus} />
|
|
@@ -57,7 +74,14 @@ export function CloudConnectFlow({
|
|
|
57
74
|
case 'waiting_tunnel':
|
|
58
75
|
return <ProgressCard status={status} onStatus={onStatus} />
|
|
59
76
|
case 'connected':
|
|
60
|
-
return
|
|
77
|
+
return (
|
|
78
|
+
<ConnectedCard
|
|
79
|
+
status={status}
|
|
80
|
+
onStatus={onStatus}
|
|
81
|
+
onExit={onExit}
|
|
82
|
+
action={status.connected && connectedAction ? connectedAction(status.connected) : null}
|
|
83
|
+
/>
|
|
84
|
+
)
|
|
61
85
|
case 'failed':
|
|
62
86
|
return <FailedCard status={status} where={where} onStatus={onStatus} onExit={onExit} />
|
|
63
87
|
default:
|
|
@@ -427,10 +451,12 @@ function PlanCard({
|
|
|
427
451
|
status,
|
|
428
452
|
onStatus,
|
|
429
453
|
onExit,
|
|
454
|
+
tagUrl,
|
|
430
455
|
}: {
|
|
431
456
|
status: CloudInstallStatus
|
|
432
457
|
onStatus: (st: CloudInstallStatus) => void
|
|
433
458
|
onExit: () => void
|
|
459
|
+
tagUrl: (url: string) => string
|
|
434
460
|
}) {
|
|
435
461
|
const plan = status.plan
|
|
436
462
|
const [clusterName, setClusterName] = useState(plan?.defaultClusterName ?? '')
|
|
@@ -458,10 +484,11 @@ function PlanCard({
|
|
|
458
484
|
// flight, and opening its connectUrl anyway would present an approvable
|
|
459
485
|
// request for a flow the user already stopped.
|
|
460
486
|
if (st.connectUrl && st.state === 'awaiting_approval') {
|
|
487
|
+
const connectUrl = tagUrl(st.connectUrl)
|
|
461
488
|
if (approvalTab.current && !approvalTab.current.closed) {
|
|
462
|
-
approvalTab.current.location.href =
|
|
489
|
+
approvalTab.current.location.href = connectUrl
|
|
463
490
|
} else {
|
|
464
|
-
window.open(
|
|
491
|
+
window.open(connectUrl, '_blank', 'noopener')
|
|
465
492
|
}
|
|
466
493
|
} else {
|
|
467
494
|
approvalTab.current?.close()
|
|
@@ -797,10 +824,12 @@ function ConnectedCard({
|
|
|
797
824
|
status,
|
|
798
825
|
onStatus,
|
|
799
826
|
onExit,
|
|
827
|
+
action,
|
|
800
828
|
}: {
|
|
801
829
|
status: CloudInstallStatus
|
|
802
830
|
onStatus: (st: CloudInstallStatus) => void
|
|
803
831
|
onExit: () => void
|
|
832
|
+
action?: { label: string; href: string } | null
|
|
804
833
|
}) {
|
|
805
834
|
const dismiss = useDismiss(status, onStatus, onExit)
|
|
806
835
|
const connected = status.connected
|
|
@@ -821,13 +850,23 @@ function ConnectedCard({
|
|
|
821
850
|
</p>
|
|
822
851
|
<div className="flex items-center gap-4 mb-4">
|
|
823
852
|
<a
|
|
824
|
-
href={connected.clusterUrl}
|
|
853
|
+
href={action?.href ?? connected.clusterUrl}
|
|
825
854
|
target="_blank"
|
|
826
855
|
rel="noopener noreferrer"
|
|
827
856
|
className="px-5 py-2 rounded-[10px] bg-emerald-500 hover:bg-emerald-400 text-emerald-950 text-[13px] font-bold transition-all inline-flex items-center gap-1.5"
|
|
828
857
|
>
|
|
829
|
-
Open in Radar Cloud <ArrowUpRight className="w-3.5 h-3.5" />
|
|
858
|
+
{action?.label ?? 'Open in Radar Cloud'} <ArrowUpRight className="w-3.5 h-3.5" />
|
|
830
859
|
</a>
|
|
860
|
+
{action && (
|
|
861
|
+
<a
|
|
862
|
+
href={connected.clusterUrl}
|
|
863
|
+
target="_blank"
|
|
864
|
+
rel="noopener noreferrer"
|
|
865
|
+
className="text-[12.5px] text-theme-text-secondary hover:text-theme-text-primary hover:underline underline-offset-2"
|
|
866
|
+
>
|
|
867
|
+
Open the cluster
|
|
868
|
+
</a>
|
|
869
|
+
)}
|
|
831
870
|
<button onClick={dismiss} className="text-[12.5px] text-theme-text-tertiary hover:text-theme-text-primary transition-colors">
|
|
832
871
|
Done
|
|
833
872
|
</button>
|
|
@@ -4,7 +4,8 @@ import { createRoot, type Root } from 'react-dom/client'
|
|
|
4
4
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
6
6
|
import type { ConnectionStateType } from '../context/ConnectionContext'
|
|
7
|
-
import { CloudFunnelButton } from './CloudFunnelButton'
|
|
7
|
+
import { CloudFunnelButton, openCloudFunnel } from './CloudFunnelButton'
|
|
8
|
+
import { OPEN_CLOUD_FUNNEL_EVENT } from './cloudHints/cloudHints'
|
|
8
9
|
|
|
9
10
|
const connection = vi.hoisted(() => ({ state: 'connecting' as ConnectionStateType }))
|
|
10
11
|
vi.mock('../context/ConnectionContext', () => ({ useConnection: () => ({ connection }) }))
|
|
@@ -12,12 +13,22 @@ vi.mock('./ui/Tooltip', () => ({ Tooltip: ({ children }: { children: ReactNode }
|
|
|
12
13
|
const toast = vi.hoisted(() => ({ showApiError: vi.fn() }))
|
|
13
14
|
vi.mock('./ui/Toast', () => toast)
|
|
14
15
|
vi.mock('./CloudConnectFlow', () => ({
|
|
15
|
-
CloudConnectFlow: ({ status, blocked, onExit }: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
16
|
+
CloudConnectFlow: ({ status, blocked, onExit, connectedAction }: {
|
|
17
|
+
status: { state: string; prepareStep?: string; connected?: { clusterUrl: string } }
|
|
18
|
+
blocked: unknown
|
|
19
|
+
onExit: () => void
|
|
20
|
+
connectedAction?: (connected: { clusterUrl: string }) => { label: string; href: string } | null
|
|
21
|
+
}) => {
|
|
22
|
+
// The connected card's main link, as the real one picks it.
|
|
23
|
+
const action = status.connected && connectedAction?.(status.connected)
|
|
24
|
+
return (
|
|
25
|
+
<div>
|
|
26
|
+
Install flow [{blocked ? 'blocked' : status.state} {status.prepareStep ?? '-'}]
|
|
27
|
+
{status.connected && <a href={action?.href ?? status.connected.clusterUrl}>{action?.label ?? 'Open in Radar Cloud'}</a>}
|
|
28
|
+
<button onClick={onExit}>Leave flow</button>
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
},
|
|
21
32
|
}))
|
|
22
33
|
|
|
23
34
|
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
@@ -107,6 +118,11 @@ async function startConnect() {
|
|
|
107
118
|
await act(async () => { button('Connect this cluster…')!.click() })
|
|
108
119
|
}
|
|
109
120
|
|
|
121
|
+
function closeButton() {
|
|
122
|
+
return document.querySelector<HTMLButtonElement>('[aria-label="Close"]')!
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
110
126
|
function button(text: string) {
|
|
111
127
|
return Array.from(document.querySelectorAll('button')).find(element => element.textContent === text)
|
|
112
128
|
}
|
|
@@ -326,3 +342,173 @@ describe('Cloud connect preparation progress', () => {
|
|
|
326
342
|
expect(toast.showApiError).not.toHaveBeenCalled()
|
|
327
343
|
})
|
|
328
344
|
})
|
|
345
|
+
|
|
346
|
+
describe('Cloud dialog opened from an in-context hint', () => {
|
|
347
|
+
async function renderReady() {
|
|
348
|
+
await render()
|
|
349
|
+
await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function signupLink() {
|
|
353
|
+
return document.querySelector<HTMLAnchorElement>('a[href*="wizard-signup-button"]')
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
it('tags the links the person opens with the hint, and only for that open', async () => {
|
|
357
|
+
lane = 'wizard'
|
|
358
|
+
await renderReady()
|
|
359
|
+
await act(async () => openCloudFunnel('ai-setup'))
|
|
360
|
+
await until(() => expect(signupLink()).not.toBeNull())
|
|
361
|
+
expect(new URL(signupLink()!.href).searchParams.get('utm_term')).toBe('ai-setup')
|
|
362
|
+
|
|
363
|
+
await act(async () => { closeButton().click() })
|
|
364
|
+
await act(async () => { (document.querySelector('[aria-label="Radar Cloud"]') as HTMLButtonElement).click() })
|
|
365
|
+
await until(() => expect(signupLink()).not.toBeNull())
|
|
366
|
+
expect(new URL(signupLink()!.href).searchParams.has('utm_term')).toBe(false)
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
it('names the hint on the copy fetch, and nothing when the globe button opens it', async () => {
|
|
370
|
+
lane = 'wizard'
|
|
371
|
+
await renderReady()
|
|
372
|
+
await act(async () => openCloudFunnel('settings-ai'))
|
|
373
|
+
await until(() => expect(requests.some(r => r.startsWith('/api/connect/info') && r.includes('entry=settings-ai'))).toBe(true))
|
|
374
|
+
await act(async () => { closeButton().click() })
|
|
375
|
+
requests.length = 0
|
|
376
|
+
await act(async () => { (document.querySelector('[aria-label="Radar Cloud"]') as HTMLButtonElement).click() })
|
|
377
|
+
await until(() => expect(requests.some(r => r.startsWith('/api/connect/info'))).toBe(true))
|
|
378
|
+
expect(requests.filter(r => r.startsWith('/api/connect/info')).every(r => !r.includes('entry='))).toBe(true)
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
it('ignores a forged hint name from another script', async () => {
|
|
382
|
+
lane = 'wizard'
|
|
383
|
+
await renderReady()
|
|
384
|
+
await act(async () => {
|
|
385
|
+
window.dispatchEvent(new CustomEvent(OPEN_CLOUD_FUNNEL_EVENT, { detail: { entry: 'evil"&x=1' } }))
|
|
386
|
+
})
|
|
387
|
+
await until(() => expect(signupLink()).not.toBeNull())
|
|
388
|
+
expect(new URL(signupLink()!.href).searchParams.has('utm_term')).toBe(false)
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
it('opens Self-Managed when asked even while a hosted install awaits approval, and Back returns to it', async () => {
|
|
392
|
+
connection.state = 'connected'
|
|
393
|
+
flowState = 'awaiting_approval'
|
|
394
|
+
await render()
|
|
395
|
+
await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
|
|
396
|
+
await act(async () => openCloudFunnel('oss-poll', undefined, 'self-managed'))
|
|
397
|
+
await until(() => expect(document.querySelector('a[href*="self-managed-signup"]')).not.toBeNull())
|
|
398
|
+
expect(document.body.textContent).not.toContain('Install flow')
|
|
399
|
+
await act(async () => { button('Back to Radar Cloud')!.click() })
|
|
400
|
+
await until(() => expect(document.body.textContent).toContain('Install flow [awaiting_approval -]'))
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
it('opens the poll on Self-Managed, and its links name the poll as the campaign', async () => {
|
|
404
|
+
lane = 'wizard'
|
|
405
|
+
await renderReady()
|
|
406
|
+
await act(async () => openCloudFunnel('oss-poll', undefined, 'self-managed'))
|
|
407
|
+
const selfManagedLink = () => document.querySelector<HTMLAnchorElement>('a[href*="self-managed-signup"]')
|
|
408
|
+
await until(() => expect(selfManagedLink()).not.toBeNull())
|
|
409
|
+
const url = new URL(selfManagedLink()!.href)
|
|
410
|
+
expect(url.searchParams.get('utm_campaign')).toBe('oss-poll')
|
|
411
|
+
expect(url.searchParams.get('utm_content')).toBe('self-managed-signup')
|
|
412
|
+
expect(url.searchParams.get('utm_term')).toBe('oss-poll')
|
|
413
|
+
expect(url.searchParams.get('intent')).toBe('self-hosting')
|
|
414
|
+
expect(signupLink()).toBeNull()
|
|
415
|
+
|
|
416
|
+
// The poll's hosted line opens the pitch, still under the poll's campaign.
|
|
417
|
+
await act(async () => { document.querySelector<HTMLButtonElement>('[aria-label="Close"]')!.click() })
|
|
418
|
+
await act(async () => openCloudFunnel('oss-poll'))
|
|
419
|
+
await until(() => expect(signupLink()).not.toBeNull())
|
|
420
|
+
expect(new URL(signupLink()!.href).searchParams.get('utm_campaign')).toBe('oss-poll')
|
|
421
|
+
|
|
422
|
+
// Any other entry, and the globe button, keep the dialog's own campaign.
|
|
423
|
+
await act(async () => { closeButton().click() })
|
|
424
|
+
await act(async () => openCloudFunnel('settings-ai'))
|
|
425
|
+
await until(() => expect(signupLink()).not.toBeNull())
|
|
426
|
+
expect(new URL(signupLink()!.href).searchParams.get('utm_campaign')).toBe('cloud-modal')
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
it('shows the resource being shared instead of the general pitch', async () => {
|
|
430
|
+
lane = 'wizard'
|
|
431
|
+
await renderReady()
|
|
432
|
+
await act(async () =>
|
|
433
|
+
openCloudFunnel('share', { intent: 'share', kind: 'Pod', name: 'api-1', namespace: 'shop', context: 'test-cluster' }),
|
|
434
|
+
)
|
|
435
|
+
await until(() => expect(document.body.textContent).toContain('Share api-1 with your team'))
|
|
436
|
+
const text = document.body.textContent ?? ''
|
|
437
|
+
expect(text).toContain('Pod api-1')
|
|
438
|
+
expect(text).toContain('namespace shop')
|
|
439
|
+
expect(text).toContain('Connecting the cluster lets Radar Cloud store its event history, changes and investigation results.')
|
|
440
|
+
expect(text).not.toContain('Meet Radar Cloud')
|
|
441
|
+
expect(new URL(signupLink()!.href).searchParams.get('utm_term')).toBe('share')
|
|
442
|
+
// A feature dialog stays about the feature: no assurance ticks, so no
|
|
443
|
+
// free-tier line, and nothing tucked behind a disclosure.
|
|
444
|
+
expect(text).not.toContain('clusters free')
|
|
445
|
+
expect(text).not.toContain('SOC 2')
|
|
446
|
+
})
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
describe('Cloud dialog actions for a cluster already in Radar Cloud', () => {
|
|
450
|
+
it('shares the resource: the team link, under a share headline', async () => {
|
|
451
|
+
connection.state = 'connected'
|
|
452
|
+
discovery.connected = [{ namespace: 'radar', deployment: 'radar', clusterUrl: 'https://cloud.example/c/cl_123' }]
|
|
453
|
+
await render()
|
|
454
|
+
await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
|
|
455
|
+
await act(async () =>
|
|
456
|
+
openCloudFunnel('share', { intent: 'share', kind: 'Deployment', group: 'apps', name: 'checkout-api', namespace: 'shop', context: 'test-cluster' }),
|
|
457
|
+
)
|
|
458
|
+
await until(() => expect(document.body.textContent).toContain('This cluster is already connected to Radar Cloud.'))
|
|
459
|
+
const link = Array.from(document.querySelectorAll('a')).find((a) => a.textContent === 'Open checkout-api in Radar Cloud')
|
|
460
|
+
expect(new URL(link!.href).pathname).toBe('/c/cl_123/resources/deployments')
|
|
461
|
+
expect(new URL(link!.href).searchParams.get('utm_term')).toBe('share')
|
|
462
|
+
expect(document.body.textContent).toContain('Share checkout-api with your team')
|
|
463
|
+
expect(document.body.textContent).not.toContain('Connecting the cluster lets Radar Cloud store')
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
it('links the cluster, not the resource, when Radar has moved to another context', async () => {
|
|
467
|
+
connection.state = 'connected'
|
|
468
|
+
discovery.connected = [{ namespace: 'radar', deployment: 'radar', clusterUrl: 'https://cloud.example/c/cl_123' }]
|
|
469
|
+
await render()
|
|
470
|
+
await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
|
|
471
|
+
await act(async () =>
|
|
472
|
+
openCloudFunnel('share', { intent: 'share', kind: 'Deployment', group: 'apps', name: 'checkout-api', namespace: 'shop', context: 'another-cluster' }),
|
|
473
|
+
)
|
|
474
|
+
await until(() => expect(document.body.textContent).toContain('This cluster is already connected to Radar Cloud.'))
|
|
475
|
+
const links = Array.from(document.querySelectorAll('a'))
|
|
476
|
+
expect(links.find((a) => a.textContent === 'Open checkout-api in Radar Cloud')).toBeUndefined()
|
|
477
|
+
// The share body names the other cluster's resource, so it gives way to the pitch.
|
|
478
|
+
expect(document.body.textContent).not.toContain('Share checkout-api with your team')
|
|
479
|
+
expect(new URL(links.find((a) => a.textContent === 'Open in Radar Cloud')!.href).pathname).toBe('/c/cl_123')
|
|
480
|
+
})
|
|
481
|
+
// An install flow keeps the cluster it started on across a context switch,
|
|
482
|
+
// so its Cloud cluster is the subject's only when the flow ran on the
|
|
483
|
+
// subject's context, whatever context Radar is on now.
|
|
484
|
+
const connectedFlow = (contextName: string) => ({
|
|
485
|
+
state: 'connected',
|
|
486
|
+
flowId: 'f1',
|
|
487
|
+
plan: { mode: 'fresh', contextName, namespace: 'radar', release: 'radar', defaultClusterName: 'a', targetChartVersion: '1.0.0' },
|
|
488
|
+
connected: { clusterId: 'cl_a', clusterUrl: 'https://cloud.example/c/cl_a', trackCommand: 'kubectl get pods -n radar' },
|
|
489
|
+
})
|
|
490
|
+
const share = { intent: 'share' as const, kind: 'Deployment', group: 'apps', name: 'checkout-api', namespace: 'shop', context: 'test-cluster' }
|
|
491
|
+
const cloudLinks = () => Array.from(document.querySelectorAll('a')).filter((a) => a.href.startsWith('https://cloud.example/c/'))
|
|
492
|
+
|
|
493
|
+
it('links the resource from an install that ran on its cluster', async () => {
|
|
494
|
+
connection.state = 'connected'
|
|
495
|
+
statusBody = connectedFlow('test-cluster')
|
|
496
|
+
await render()
|
|
497
|
+
await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
|
|
498
|
+
await act(async () => openCloudFunnel('share', share))
|
|
499
|
+
await until(() => expect(cloudLinks().length).toBeGreaterThan(0))
|
|
500
|
+
const link = Array.from(document.querySelectorAll('a')).find((a) => a.textContent?.includes('Open checkout-api in Radar Cloud'))
|
|
501
|
+
expect(new URL(link!.href).pathname).toBe('/c/cl_a/resources/deployments')
|
|
502
|
+
})
|
|
503
|
+
|
|
504
|
+
it('links only the cluster when the install ran on another cluster', async () => {
|
|
505
|
+
connection.state = 'connected'
|
|
506
|
+
statusBody = connectedFlow('cluster-a')
|
|
507
|
+
await render()
|
|
508
|
+
await until(() => expect(document.querySelector('[aria-label="Radar Cloud"]')).not.toBeNull())
|
|
509
|
+
await act(async () => openCloudFunnel('share', share))
|
|
510
|
+
await until(() => expect(cloudLinks().length).toBeGreaterThan(0))
|
|
511
|
+
expect(cloudLinks().some((a) => new URL(a.href).pathname.includes('/resources/'))).toBe(false)
|
|
512
|
+
expect(document.body.textContent).not.toContain('Open checkout-api in Radar Cloud')
|
|
513
|
+
})
|
|
514
|
+
})
|