@skyhook-io/radar-app 1.22.1 → 1.23.0
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 +131 -38
- package/src/RadarApp.basename.test.tsx +177 -0
- package/src/RadarApp.settings.test.tsx +33 -0
- package/src/RadarApp.tsx +5 -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 +128 -25
- 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/prometheusCharts.ts +5 -0
- package/src/api/radarFeatures.test.ts +9 -0
- package/src/api/radarFeatures.ts +13 -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 +1172 -0
- package/src/api/workloadSource.ts +408 -0
- package/src/components/APIUnreachableBanner.test.tsx +19 -0
- package/src/components/APIUnreachableBanner.tsx +20 -0
- package/src/components/CloudConnectFlow.tsx +46 -7
- package/src/components/CloudFunnelButton.test.tsx +193 -7
- package/src/components/CloudFunnelButton.tsx +127 -32
- package/src/components/ConnectionErrorView.test.tsx +63 -2
- package/src/components/ConnectionErrorView.tsx +88 -68
- 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/ActivityTurn.tsx +6 -4
- package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
- package/src/components/diagnose/AssessmentCard.tsx +1 -2
- package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -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/diagnose/Home.test.tsx +6 -0
- package/src/components/diagnose/Home.tsx +10 -3
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
- package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
- package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
- package/src/components/diagnose/InvestigationView.tsx +120 -23
- package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
- package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
- package/src/components/diagnose/investigationState.ts +9 -0
- package/src/components/diagnose/parts.test.tsx +11 -3
- package/src/components/diagnose/toolCallLabel.ts +3 -0
- package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
- package/src/components/home/ActivitySummary.tsx +3 -8
- package/src/components/home/ClusterHealthCard.tsx +91 -17
- package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
- package/src/components/home/HomeAgentBlock.tsx +2 -0
- package/src/components/home/HomeView.tsx +9 -29
- 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/TopologyPreview.test.tsx +31 -30
- package/src/components/home/TopologyPreview.tsx +19 -28
- package/src/components/home/mcpToolCatalog.test.ts +10 -0
- package/src/components/home/mcpToolCatalog.ts +7 -7
- 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/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/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/ResourceDetailDrawer.tsx +1 -0
- package/src/components/resources/ResourcesView.tsx +2 -6
- package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
- package/src/components/resources/renderers/PodRenderer.tsx +8 -2
- package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
- package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
- 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/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/workload/WorkloadView.substrateVersion.test.tsx +88 -0
- package/src/components/workload/WorkloadView.tsx +119 -14
- package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
- 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/context/ConnectionContext.tsx +24 -5
- package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
- package/src/context/ConnectionProvider.handover.test.tsx +94 -0
- package/src/context/DiagnoseCustomization.tsx +20 -2
- package/src/contexts/RegistryAccessMode.test.tsx +51 -0
- package/src/contexts/RegistryAccessMode.tsx +25 -0
- package/src/hooks/useEventSource.test.tsx +275 -4
- package/src/hooks/useEventSource.ts +278 -51
- package/src/index.ts +1 -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
- package/src/utils/navigation.test.ts +1 -6
- package/src/utils/navigation.ts +9 -44
- package/src/utils/network-policy-navigation.test.ts +21 -36
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore, type KeyboardEvent as ReactKeyboardEvent } from 'react'
|
|
2
|
+
import { createPortal } from 'react-dom'
|
|
3
|
+
import { useHref } from 'react-router-dom'
|
|
4
|
+
import { clsx } from 'clsx'
|
|
5
|
+
import { Check, ExternalLink, Link as LinkIcon, X } from 'lucide-react'
|
|
6
|
+
import { copyText } from '@skyhook-io/k8s-ui/utils/clipboard'
|
|
7
|
+
import { useCapabilities, useClusterInfo, useCloudInstallDiscover } from '../../api/client'
|
|
8
|
+
import { recordUsageEvent } from '../../api/usage-data'
|
|
9
|
+
import { useConnection } from '../../context/ConnectionContext'
|
|
10
|
+
import { useAnimatedUnmount } from '../../hooks/useAnimatedUnmount'
|
|
11
|
+
import { Tooltip } from '../ui/Tooltip'
|
|
12
|
+
import { TRANSITION_MENU, overlayExitMs, overlayTransitionStyle } from '../../utils/animation'
|
|
13
|
+
import { useCloudHintsEnabled } from '../cloudHints/cloudHints'
|
|
14
|
+
import { openShareInCloud } from './openShareInCloud'
|
|
15
|
+
import { isDesktopApp } from '../../utils/desktop-download'
|
|
16
|
+
import { openExternal } from '../../utils/navigation'
|
|
17
|
+
import {
|
|
18
|
+
CLOUD_SHARE_SHOWS,
|
|
19
|
+
cloudShareShows,
|
|
20
|
+
cloudViewUrl,
|
|
21
|
+
hideCloudShare,
|
|
22
|
+
isCloudShareHidden,
|
|
23
|
+
isLoopbackHostname,
|
|
24
|
+
noteCloudShareShown,
|
|
25
|
+
subscribeCloudShareHidden,
|
|
26
|
+
type ShareSubject,
|
|
27
|
+
} from './shareLink'
|
|
28
|
+
|
|
29
|
+
const COPIED_MS = 1500
|
|
30
|
+
const MENU_WIDTH = 288
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Whether the share menu offers Radar Cloud. Only where a copied link can't
|
|
34
|
+
* reach a teammate: Radar runs on this computer and the browser opened it on a
|
|
35
|
+
* loopback name. A shared install's link already works for the team, so it gets
|
|
36
|
+
* no Radar Cloud option. The server still decides whether there is anything to
|
|
37
|
+
* point at (the cloudConnect capability), embedded hosts never show it, and a
|
|
38
|
+
* person who hid it never sees it again.
|
|
39
|
+
*/
|
|
40
|
+
export function useShareCloudOption(): { available: boolean; hide: () => void } {
|
|
41
|
+
const hintsEnabled = useCloudHintsEnabled()
|
|
42
|
+
const capabilities = useCapabilities()
|
|
43
|
+
const hidden = useSyncExternalStore(subscribeCloudShareHidden, isCloudShareHidden, () => false)
|
|
44
|
+
const available =
|
|
45
|
+
hintsEnabled &&
|
|
46
|
+
!hidden &&
|
|
47
|
+
capabilities.data?.deployment?.mode === 'local' &&
|
|
48
|
+
typeof window !== 'undefined' &&
|
|
49
|
+
isLoopbackHostname(window.location.hostname)
|
|
50
|
+
return { available, hide: hideCloudShare }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ShareLinkButtonProps {
|
|
54
|
+
/** Router-relative path and query this link opens. */
|
|
55
|
+
path: string
|
|
56
|
+
/** What the link points at, for the Radar Cloud dialog. */
|
|
57
|
+
subject: ShareSubject | null
|
|
58
|
+
/** Icon size: 'md' matches the drawer's header icons, 'sm' an issue row. */
|
|
59
|
+
size?: 'sm' | 'md'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Copies a link to what's on screen in one click. Where that link only works on
|
|
64
|
+
* this computer, the first few copies also open a small popup that confirms the
|
|
65
|
+
* copy, says the link is local, and offers Radar Cloud for a link the team can
|
|
66
|
+
* open. Nothing here shows until the person clicks it.
|
|
67
|
+
*/
|
|
68
|
+
export function ShareLinkButton({ path, subject, size = 'md' }: ShareLinkButtonProps) {
|
|
69
|
+
const href = useHref(path)
|
|
70
|
+
const url = typeof window === 'undefined' ? href : new URL(href, window.location.origin).toString()
|
|
71
|
+
const cloud = useShareCloudOption()
|
|
72
|
+
// The menu keeps clicks from the issue row, which also keeps them from the
|
|
73
|
+
// desktop app's window handler that sends links to the system browser, so
|
|
74
|
+
// the Cloud link does that itself. Asked when the button renders, long
|
|
75
|
+
// before anyone can click inside the menu.
|
|
76
|
+
const [desktop, setDesktop] = useState<boolean | undefined>(undefined)
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!cloud.available) return
|
|
79
|
+
let live = true
|
|
80
|
+
void isDesktopApp().then((d) => live && setDesktop(d))
|
|
81
|
+
return () => {
|
|
82
|
+
live = false
|
|
83
|
+
}
|
|
84
|
+
}, [cloud.available])
|
|
85
|
+
const [open, setOpen] = useState(false)
|
|
86
|
+
// Whether this popup carries the Radar Cloud option, decided at the click so
|
|
87
|
+
// the count it uses up can't remove it from under the person.
|
|
88
|
+
const [withCloud, setWithCloud] = useState(false)
|
|
89
|
+
const [copyFailed, setCopyFailed] = useState(false)
|
|
90
|
+
const [copied, setCopied] = useState(false)
|
|
91
|
+
const [anchor, setAnchor] = useState<{ top: number; right: number } | null>(null)
|
|
92
|
+
const placed = anchor !== null
|
|
93
|
+
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
94
|
+
const menuRef = useRef<HTMLDivElement>(null)
|
|
95
|
+
// One copy at a time, and nothing after this control is gone: a late answer
|
|
96
|
+
// from the clipboard must not reopen a popup or use up a Radar Cloud offer.
|
|
97
|
+
const copying = useRef(false)
|
|
98
|
+
const mounted = useRef(true)
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
mounted.current = true
|
|
101
|
+
return () => {
|
|
102
|
+
mounted.current = false
|
|
103
|
+
}
|
|
104
|
+
}, [])
|
|
105
|
+
const menuId = useId()
|
|
106
|
+
const { shouldRender, isOpen } = useAnimatedUnmount(open, overlayExitMs('menu'))
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!copied) return
|
|
110
|
+
const t = setTimeout(() => setCopied(false), COPIED_MS)
|
|
111
|
+
return () => clearTimeout(t)
|
|
112
|
+
}, [copied])
|
|
113
|
+
|
|
114
|
+
const close = useCallback((restoreFocus: boolean) => {
|
|
115
|
+
setOpen(false)
|
|
116
|
+
setCopyFailed(false)
|
|
117
|
+
if (restoreFocus) triggerRef.current?.focus({ preventScroll: true })
|
|
118
|
+
}, [])
|
|
119
|
+
|
|
120
|
+
useLayoutEffect(() => {
|
|
121
|
+
if (!open) return
|
|
122
|
+
const place = () => {
|
|
123
|
+
const rect = triggerRef.current?.getBoundingClientRect()
|
|
124
|
+
if (!rect) return
|
|
125
|
+
// Below the icon, or above it when the popup would run off the bottom.
|
|
126
|
+
const height = menuRef.current?.offsetHeight ?? 0
|
|
127
|
+
const below = rect.bottom + 4
|
|
128
|
+
const top = height && below + height > window.innerHeight - 8 ? Math.max(8, rect.top - 4 - height) : below
|
|
129
|
+
setAnchor({ top, right: Math.max(8, window.innerWidth - rect.right) })
|
|
130
|
+
}
|
|
131
|
+
place()
|
|
132
|
+
window.addEventListener('resize', place)
|
|
133
|
+
window.addEventListener('scroll', place, true)
|
|
134
|
+
return () => {
|
|
135
|
+
window.removeEventListener('resize', place)
|
|
136
|
+
window.removeEventListener('scroll', place, true)
|
|
137
|
+
}
|
|
138
|
+
// Placed again once the popup is in the page and its height is known.
|
|
139
|
+
}, [open, shouldRender, placed, withCloud, copyFailed])
|
|
140
|
+
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (!open) return
|
|
143
|
+
const onDown = (e: MouseEvent) => {
|
|
144
|
+
const target = e.target as Node
|
|
145
|
+
if (menuRef.current?.contains(target) || triggerRef.current?.contains(target)) return
|
|
146
|
+
close(false)
|
|
147
|
+
}
|
|
148
|
+
// Capture phase, consumed: the Escape that closes this menu must not also
|
|
149
|
+
// close the drawer underneath.
|
|
150
|
+
const onKey = (e: KeyboardEvent) => {
|
|
151
|
+
if (e.key !== 'Escape') return
|
|
152
|
+
e.preventDefault()
|
|
153
|
+
e.stopPropagation()
|
|
154
|
+
close(true)
|
|
155
|
+
}
|
|
156
|
+
document.addEventListener('mousedown', onDown)
|
|
157
|
+
document.addEventListener('keydown', onKey, true)
|
|
158
|
+
return () => {
|
|
159
|
+
document.removeEventListener('mousedown', onDown)
|
|
160
|
+
document.removeEventListener('keydown', onKey, true)
|
|
161
|
+
}
|
|
162
|
+
}, [open, close])
|
|
163
|
+
|
|
164
|
+
// The menu is inert until its entrance starts, and an inert element refuses
|
|
165
|
+
// focus, so the first item is focused once it is live.
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (!open || !isOpen) return
|
|
168
|
+
// The first action, or the popup itself while the Radar Cloud item is still
|
|
169
|
+
// checking, so keyboard focus is inside it either way.
|
|
170
|
+
const first = menuRef.current?.querySelector<HTMLElement>('a[role="menuitem"], button[role="menuitem"], input')
|
|
171
|
+
;(first ?? menuRef.current)?.focus({ preventScroll: true })
|
|
172
|
+
}, [open, isOpen])
|
|
173
|
+
|
|
174
|
+
const copy = async () => {
|
|
175
|
+
if (copying.current) return
|
|
176
|
+
copying.current = true
|
|
177
|
+
let ok: boolean
|
|
178
|
+
try {
|
|
179
|
+
ok = await copyText(url)
|
|
180
|
+
} finally {
|
|
181
|
+
copying.current = false
|
|
182
|
+
}
|
|
183
|
+
if (!mounted.current) return
|
|
184
|
+
const offerCloud = cloud.available && cloudShareShows() < CLOUD_SHARE_SHOWS
|
|
185
|
+
if (ok) {
|
|
186
|
+
recordUsageEvent({ type: 'ui', name: 'share:copy-link' })
|
|
187
|
+
setCopied(true)
|
|
188
|
+
}
|
|
189
|
+
if (ok && !offerCloud) return
|
|
190
|
+
if (offerCloud) noteCloudShareShown()
|
|
191
|
+
setWithCloud(offerCloud)
|
|
192
|
+
// A refused clipboard shows the link to copy by hand.
|
|
193
|
+
setCopyFailed(!ok)
|
|
194
|
+
setOpen(true)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const onTrigger = () => {
|
|
198
|
+
if (open) {
|
|
199
|
+
close(false)
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
void copy()
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const onMenuKeyDown = (e: ReactKeyboardEvent<HTMLDivElement>) => {
|
|
206
|
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return
|
|
207
|
+
const items = Array.from(menuRef.current?.querySelectorAll<HTMLElement>('[role="menuitem"]') ?? [])
|
|
208
|
+
if (!items.length) return
|
|
209
|
+
e.preventDefault()
|
|
210
|
+
const at = items.indexOf(document.activeElement as HTMLElement)
|
|
211
|
+
const next = e.key === 'ArrowDown' ? (at + 1) % items.length : (at - 1 + items.length) % items.length
|
|
212
|
+
items[next]?.focus()
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const label = 'Copy link'
|
|
216
|
+
const iconClass = size === 'sm' ? 'h-3.5 w-3.5' : 'h-4 w-4'
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<>
|
|
220
|
+
<Tooltip content={copied ? 'Link copied' : label} delay={150} position="bottom">
|
|
221
|
+
<button
|
|
222
|
+
ref={triggerRef}
|
|
223
|
+
type="button"
|
|
224
|
+
aria-label={label}
|
|
225
|
+
aria-controls={open ? menuId : undefined}
|
|
226
|
+
onClick={(e) => {
|
|
227
|
+
// Inside an issue row the header toggles on click.
|
|
228
|
+
e.stopPropagation()
|
|
229
|
+
onTrigger()
|
|
230
|
+
}}
|
|
231
|
+
className={clsx(
|
|
232
|
+
'rounded text-theme-text-secondary hover:bg-theme-elevated hover:text-theme-text-primary',
|
|
233
|
+
size === 'sm' ? 'p-1' : 'p-1.5',
|
|
234
|
+
)}
|
|
235
|
+
>
|
|
236
|
+
{copied ? <Check className={clsx(iconClass, 'text-green-400')} /> : <LinkIcon className={iconClass} />}
|
|
237
|
+
</button>
|
|
238
|
+
</Tooltip>
|
|
239
|
+
<span className="sr-only" aria-live="polite">{copied ? 'Link copied' : ''}</span>
|
|
240
|
+
{shouldRender && anchor && createPortal(
|
|
241
|
+
<div
|
|
242
|
+
ref={menuRef}
|
|
243
|
+
id={menuId}
|
|
244
|
+
role="dialog"
|
|
245
|
+
tabIndex={-1}
|
|
246
|
+
aria-label={copyFailed ? "Couldn't copy the link" : 'Link copied'}
|
|
247
|
+
inert={!isOpen || undefined}
|
|
248
|
+
// React events bubble through the portal to the issue row header.
|
|
249
|
+
onClick={(e) => e.stopPropagation()}
|
|
250
|
+
onKeyDown={onMenuKeyDown}
|
|
251
|
+
style={{ position: 'fixed', top: anchor.top, right: anchor.right, width: MENU_WIDTH, ...overlayTransitionStyle(isOpen, 'menu') }}
|
|
252
|
+
className={clsx(
|
|
253
|
+
'z-[130] origin-top-right rounded-lg border border-theme-border bg-theme-surface p-1 shadow-theme-lg',
|
|
254
|
+
TRANSITION_MENU,
|
|
255
|
+
isOpen ? 'scale-100 opacity-100' : 'pointer-events-none scale-95 opacity-0',
|
|
256
|
+
)}
|
|
257
|
+
>
|
|
258
|
+
{copyFailed ? (
|
|
259
|
+
<div className="px-2.5 py-2">
|
|
260
|
+
<p className="text-xs text-theme-text-secondary">Radar couldn't copy the link. Copy it here:</p>
|
|
261
|
+
<input
|
|
262
|
+
readOnly
|
|
263
|
+
value={url}
|
|
264
|
+
aria-label="Link"
|
|
265
|
+
onFocus={(e) => e.currentTarget.select()}
|
|
266
|
+
className="mt-1.5 w-full rounded-md border border-theme-border bg-theme-elevated px-2 py-1 font-mono text-xs text-theme-text-primary"
|
|
267
|
+
/>
|
|
268
|
+
</div>
|
|
269
|
+
) : (
|
|
270
|
+
<div className="flex items-start gap-2 px-2.5 py-2">
|
|
271
|
+
<Check className="mt-0.5 h-4 w-4 shrink-0 text-green-500" aria-hidden />
|
|
272
|
+
<div>
|
|
273
|
+
<span className="block text-sm font-medium text-theme-text-primary">Local link copied</span>
|
|
274
|
+
<span className="block text-xs text-theme-text-tertiary">Works on this computer only ({window.location.host})</span>
|
|
275
|
+
</div>
|
|
276
|
+
</div>
|
|
277
|
+
)}
|
|
278
|
+
{withCloud && cloud.available && (
|
|
279
|
+
<CloudShareItem
|
|
280
|
+
path={path}
|
|
281
|
+
desktop={desktop}
|
|
282
|
+
onOpenCloud={() => {
|
|
283
|
+
recordUsageEvent({ type: 'ui', name: 'share:cloud' })
|
|
284
|
+
close(false)
|
|
285
|
+
}}
|
|
286
|
+
onConnect={(context) => openShareInCloud(subject, context)}
|
|
287
|
+
onHide={() => {
|
|
288
|
+
cloud.hide()
|
|
289
|
+
close(true)
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
)}
|
|
293
|
+
</div>,
|
|
294
|
+
document.body,
|
|
295
|
+
)}
|
|
296
|
+
</>
|
|
297
|
+
)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The Radar Cloud item. Mounted only inside the open menu, so the lookup below
|
|
302
|
+
* runs when someone opens it: the same one the Radar Cloud dialog makes, which
|
|
303
|
+
* lets a cluster that is already connected open this view there directly.
|
|
304
|
+
*/
|
|
305
|
+
function CloudShareItem({ path, desktop, onOpenCloud, onConnect, onHide }: { path: string; desktop: boolean | undefined; onOpenCloud: () => void; onConnect: (context?: string) => void; onHide: () => void }) {
|
|
306
|
+
const capabilities = useCapabilities()
|
|
307
|
+
const clusterInfo = useClusterInfo()
|
|
308
|
+
const clusterConnected = useConnection().connection.state === 'connected'
|
|
309
|
+
const lookup = capabilities.data?.cloudConnect?.lane === 'driver' && clusterConnected
|
|
310
|
+
const discovered = useCloudInstallDiscover(lookup, clusterInfo.data?.context)
|
|
311
|
+
const connected = discovered.isError ? undefined : discovered.data?.connected[0]
|
|
312
|
+
const cloudHref = connected?.clusterUrl ? cloudViewUrl(connected.clusterUrl, path) : null
|
|
313
|
+
// A failed lookup, or a partial one that found nothing, can't tell whether
|
|
314
|
+
// the cluster is connected, so the item doesn't ask to connect it.
|
|
315
|
+
const unknown = discovered.isError || (!connected && !!discovered.data?.partialScan)
|
|
316
|
+
|
|
317
|
+
return (
|
|
318
|
+
<div className="relative">
|
|
319
|
+
{(lookup && (discovered.isPending || discovered.isFetching)) || desktop === undefined ? (
|
|
320
|
+
// Held still until the lookup answers, so the item a click lands on
|
|
321
|
+
// is the one that was read.
|
|
322
|
+
<div role="menuitem" aria-disabled="true" className={clsx(ITEM_CLASS, 'pr-9 cursor-default hover:bg-transparent')}>
|
|
323
|
+
<span className="block text-sm font-medium text-theme-text-tertiary">Radar Cloud</span>
|
|
324
|
+
<span className="block text-xs text-theme-text-tertiary">Checking whether this cluster is connected…</span>
|
|
325
|
+
</div>
|
|
326
|
+
) : cloudHref ? (
|
|
327
|
+
<a
|
|
328
|
+
role="menuitem"
|
|
329
|
+
href={cloudHref}
|
|
330
|
+
target="_blank"
|
|
331
|
+
rel="noopener noreferrer"
|
|
332
|
+
onClick={(e) => {
|
|
333
|
+
if (desktop) {
|
|
334
|
+
e.preventDefault()
|
|
335
|
+
openExternal(cloudHref)
|
|
336
|
+
}
|
|
337
|
+
onOpenCloud()
|
|
338
|
+
}}
|
|
339
|
+
className={clsx(ITEM_CLASS, 'pr-9')}
|
|
340
|
+
>
|
|
341
|
+
<span className="flex items-center gap-1.5 text-sm font-medium text-theme-text-primary">
|
|
342
|
+
Open in Radar Cloud <ExternalLink className="h-3 w-3 text-theme-text-tertiary" aria-hidden />
|
|
343
|
+
</span>
|
|
344
|
+
<span className="block text-xs text-theme-text-tertiary">This view, where your team can open it</span>
|
|
345
|
+
</a>
|
|
346
|
+
) : (
|
|
347
|
+
<button
|
|
348
|
+
type="button"
|
|
349
|
+
role="menuitem"
|
|
350
|
+
onClick={() => {
|
|
351
|
+
onOpenCloud()
|
|
352
|
+
onConnect(clusterInfo.data?.context)
|
|
353
|
+
}}
|
|
354
|
+
className={clsx(ITEM_CLASS, 'pr-9')}
|
|
355
|
+
>
|
|
356
|
+
{unknown ? (
|
|
357
|
+
<>
|
|
358
|
+
<span className="block text-sm font-medium text-theme-text-primary">Share with Radar Cloud</span>
|
|
359
|
+
<span className="block text-xs text-theme-text-tertiary">See how this cluster can share views with your team</span>
|
|
360
|
+
</>
|
|
361
|
+
) : connected ? (
|
|
362
|
+
// Connected, but Radar has no page link for it (another Radar
|
|
363
|
+
// Cloud, or an id it can't read): the dialog says where to go.
|
|
364
|
+
<>
|
|
365
|
+
<span className="block text-sm font-medium text-theme-text-primary">Share from Radar Cloud</span>
|
|
366
|
+
<span className="block text-xs text-theme-text-tertiary">This cluster is already connected to Radar Cloud</span>
|
|
367
|
+
</>
|
|
368
|
+
) : (
|
|
369
|
+
<>
|
|
370
|
+
<span className="block text-sm font-medium text-theme-text-primary">Get a team link</span>
|
|
371
|
+
<span className="block text-xs text-theme-text-tertiary">Connect this cluster to Radar Cloud to share any view</span>
|
|
372
|
+
</>
|
|
373
|
+
)}
|
|
374
|
+
</button>
|
|
375
|
+
)}
|
|
376
|
+
<Tooltip content="Don't show this again" delay={150} position="left" wrapperClassName="absolute right-1.5 top-2">
|
|
377
|
+
<button
|
|
378
|
+
type="button"
|
|
379
|
+
aria-label="Don't show Radar Cloud here again"
|
|
380
|
+
onClick={onHide}
|
|
381
|
+
className="rounded p-1 text-theme-text-tertiary hover:bg-theme-hover hover:text-theme-text-secondary"
|
|
382
|
+
>
|
|
383
|
+
<X className="h-3.5 w-3.5" />
|
|
384
|
+
</button>
|
|
385
|
+
</Tooltip>
|
|
386
|
+
</div>
|
|
387
|
+
)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const ITEM_CLASS =
|
|
391
|
+
'block w-full rounded-md px-2.5 py-2 text-left transition-colors hover:bg-theme-hover focus-visible:bg-theme-hover focus-visible:outline-none'
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
3
|
+
import { OPEN_CLOUD_FUNNEL_EVENT, readOpenRequest } from '../cloudHints/cloudHints'
|
|
4
|
+
import { openShareInCloud } from './openShareInCloud'
|
|
5
|
+
|
|
6
|
+
describe('openShareInCloud', () => {
|
|
7
|
+
const seen: Event[] = []
|
|
8
|
+
const listener = (e: Event) => seen.push(e)
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
window.removeEventListener(OPEN_CLOUD_FUNNEL_EVENT, listener)
|
|
11
|
+
seen.length = 0
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('opens the Radar Cloud dialog tagged share, with the resource being shared', () => {
|
|
15
|
+
window.addEventListener(OPEN_CLOUD_FUNNEL_EVENT, listener)
|
|
16
|
+
openShareInCloud({ kind: 'services', namespace: 'ledger', name: 'cache-lb' }, 'kind-test')
|
|
17
|
+
expect(seen).toHaveLength(1)
|
|
18
|
+
expect(readOpenRequest(seen[0]!)).toMatchObject({
|
|
19
|
+
entry: 'share',
|
|
20
|
+
subject: { intent: 'share', kind: 'services', namespace: 'ledger', name: 'cache-lb', context: 'kind-test' },
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('opens the general pitch when the context is unknown', () => {
|
|
25
|
+
window.addEventListener(OPEN_CLOUD_FUNNEL_EVENT, listener)
|
|
26
|
+
openShareInCloud({ kind: 'Service', namespace: 'ledger', name: 'cache-lb' })
|
|
27
|
+
expect(readOpenRequest(seen[0]!)).toMatchObject({ entry: 'share', subject: null })
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { openCloudFunnel } from '../cloudHints/cloudHints'
|
|
2
|
+
import type { ShareSubject } from './shareLink'
|
|
3
|
+
|
|
4
|
+
// Opens the one Radar Cloud dialog from the share menu, tagged so its links say
|
|
5
|
+
// they came from here and framed around sharing this resource.
|
|
6
|
+
// Without the cluster's context the dialog can't tell which cluster the
|
|
7
|
+
// resource is on, so it opens on the general pitch instead.
|
|
8
|
+
export function openShareInCloud(subject: ShareSubject | null, context?: string): void {
|
|
9
|
+
openCloudFunnel('share', subject && context ? { intent: 'share', ...subject, context } : undefined)
|
|
10
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
cloudViewUrl,
|
|
4
|
+
drawerSharePath,
|
|
5
|
+
hideCloudShare,
|
|
6
|
+
isCloudShareHidden,
|
|
7
|
+
isLoopbackHostname,
|
|
8
|
+
issueSharePath,
|
|
9
|
+
resetCloudShareHiddenForTests,
|
|
10
|
+
} from './shareLink'
|
|
11
|
+
|
|
12
|
+
describe('drawerSharePath', () => {
|
|
13
|
+
const pod = { kind: 'pods', namespace: 'shop', name: 'checkout-0' }
|
|
14
|
+
|
|
15
|
+
it('keeps the address when it already names the resource, with its namespace and filters', () => {
|
|
16
|
+
const location = { pathname: '/resources/pods', search: '?namespaces=shop&q=checkout&resource=shop%2Fcheckout-0&full=1&tab=yaml' }
|
|
17
|
+
expect(drawerSharePath(pod, location)).toBe('/resources/pods?namespaces=shop&q=checkout&resource=shop%2Fcheckout-0&full=1&tab=yaml')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('opens the resource itself when the drawer sits over another page', () => {
|
|
21
|
+
const location = { pathname: '/topology', search: '?namespaces=shop&mode=traffic' }
|
|
22
|
+
expect(drawerSharePath(pod, location)).toBe('/resources/pods?resource=shop%2Fcheckout-0')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('does not reuse the address of another resource with the same name in another group', () => {
|
|
26
|
+
const service = { kind: 'services', group: 'serving.knative.dev', namespace: 'shop', name: 'web' }
|
|
27
|
+
const location = { pathname: '/resources/services', search: '?resource=shop%2Fweb' }
|
|
28
|
+
expect(drawerSharePath(service, location)).toBe('/resources/services?resource=shop%2Fweb&apiGroup=serving.knative.dev')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('links a cluster-scoped resource by name alone', () => {
|
|
32
|
+
expect(drawerSharePath({ kind: 'nodes', name: 'node-a' }, { pathname: '/home', search: '' })).toBe('/resources/nodes?resource=node-a')
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('issueSharePath', () => {
|
|
37
|
+
it('addresses a workload issue within the resource while keeping the namespace view', () => {
|
|
38
|
+
const path = issueSharePath('abc123', { pathname: '/issues', search: '?namespaces=shop' }, {
|
|
39
|
+
kind: 'Deployment', group: 'apps', namespace: 'shop', name: 'checkout',
|
|
40
|
+
})
|
|
41
|
+
expect(path).toBe('/issues?namespaces=shop&kind=Deployment&apiGroup=apps&resource=shop%2Fcheckout&issue=abc123')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('keeps the Issues page filters and adds the issue', () => {
|
|
45
|
+
expect(issueSharePath('abc123', { pathname: '/issues', search: '?namespaces=shop&severity=critical' })).toBe(
|
|
46
|
+
'/issues?namespaces=shop&severity=critical&issue=abc123',
|
|
47
|
+
)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('replaces a different linked issue', () => {
|
|
51
|
+
expect(issueSharePath('new', { pathname: '/issues', search: '?issue=old' })).toBe('/issues?issue=new')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('carries only the namespace view from another page', () => {
|
|
55
|
+
expect(issueSharePath('abc123', { pathname: '/resources/pods', search: '?namespaces=shop&resource=shop%2Fa' })).toBe(
|
|
56
|
+
'/issues?namespaces=shop&issue=abc123',
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
describe('isLoopbackHostname', () => {
|
|
62
|
+
it.each(['localhost', 'LOCALHOST', 'radar.localhost', '127.0.0.1', '127.1.2.3', '::1', '[::1]'])('%s is loopback', (host) => {
|
|
63
|
+
expect(isLoopbackHostname(host)).toBe(true)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it.each(['radar.example.com', '10.0.0.5', '192.168.1.20', '0.0.0.0', 'localhost.example.com', '128.0.0.1', 'radar'])(
|
|
67
|
+
'%s is reachable by others',
|
|
68
|
+
(host) => {
|
|
69
|
+
expect(isLoopbackHostname(host)).toBe(false)
|
|
70
|
+
},
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('cloudViewUrl', () => {
|
|
75
|
+
it('drops the local context pin', () => {
|
|
76
|
+
expect(cloudViewUrl('https://app.radarhq.io/c/abc', '/cnpg/clusters/db/pg?ctx=kind-dev&tab=backups')).toBe(
|
|
77
|
+
'https://app.radarhq.io/c/abc/cnpg/clusters/db/pg?tab=backups',
|
|
78
|
+
)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('opens the same path and query under the cluster page', () => {
|
|
82
|
+
expect(cloudViewUrl('https://app.radarhq.io/c/abc', '/resources/pods?resource=shop%2Fa&namespaces=shop')).toBe(
|
|
83
|
+
'https://app.radarhq.io/c/abc/resources/pods?resource=shop%2Fa&namespaces=shop',
|
|
84
|
+
)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('keeps tags the cluster URL already carries', () => {
|
|
88
|
+
expect(cloudViewUrl('https://app.radarhq.io/c/abc?utm_source=radar-oss', '/issues?issue=x')).toBe(
|
|
89
|
+
'https://app.radarhq.io/c/abc/issues?utm_source=radar-oss&issue=x',
|
|
90
|
+
)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('opens the cluster page for the root path', () => {
|
|
94
|
+
expect(cloudViewUrl('https://app.radarhq.io/c/abc/', '/')).toBe('https://app.radarhq.io/c/abc')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('refuses anything that is not a cluster page', () => {
|
|
98
|
+
expect(cloudViewUrl('https://app.radarhq.io/clusters', '/issues')).toBeNull()
|
|
99
|
+
expect(cloudViewUrl('not a url', '/issues')).toBeNull()
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
describe('hiding the Radar Cloud option', () => {
|
|
104
|
+
afterEach(() => resetCloudShareHiddenForTests())
|
|
105
|
+
|
|
106
|
+
it('is remembered in storage', () => {
|
|
107
|
+
const store = new Map<string, string>()
|
|
108
|
+
const storage = { getItem: (k: string) => store.get(k) ?? null, setItem: (k: string, v: string) => void store.set(k, v) }
|
|
109
|
+
expect(isCloudShareHidden(storage)).toBe(false)
|
|
110
|
+
hideCloudShare(storage)
|
|
111
|
+
resetCloudShareHiddenForTests()
|
|
112
|
+
expect(isCloudShareHidden(storage)).toBe(true)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('holds for the page when storage is blocked', () => {
|
|
116
|
+
const blocked = {
|
|
117
|
+
getItem: () => {
|
|
118
|
+
throw new Error('SecurityError')
|
|
119
|
+
},
|
|
120
|
+
setItem: () => {
|
|
121
|
+
throw new Error('SecurityError')
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
expect(isCloudShareHidden(blocked)).toBe(false)
|
|
125
|
+
expect(() => hideCloudShare(blocked)).not.toThrow()
|
|
126
|
+
expect(isCloudShareHidden(blocked)).toBe(true)
|
|
127
|
+
expect(isCloudShareHidden(undefined)).toBe(true)
|
|
128
|
+
})
|
|
129
|
+
})
|