@skyhook-io/radar-app 1.21.6 → 1.21.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +7 -7
- package/src/App.tsx +31 -4
- package/src/RadarApp.tsx +8 -2
- package/src/api/client.discoverMetrics.test.tsx +69 -0
- package/src/api/client.issueCorrelation.test.tsx +244 -0
- package/src/api/client.issueRowChanges.test.tsx +129 -0
- package/src/api/client.pendingOwnership.test.tsx +197 -0
- package/src/api/client.prometheusStatus.test.ts +4 -0
- package/src/api/client.restartError.test.ts +36 -1
- package/src/api/client.stopWorkflow.test.tsx +133 -0
- package/src/api/client.submitWorkflowTemplate.test.tsx +127 -0
- package/src/api/client.ts +582 -114
- package/src/api/connectionBinding.test.tsx +3 -1
- package/src/api/connectionBinding.ts +14 -2
- package/src/api/gitOpsPermissions.render.test.tsx +155 -0
- package/src/api/gitOpsPermissions.test.ts +90 -0
- package/src/api/gitOpsPermissions.ts +51 -0
- package/src/api/httpErrors.test.ts +30 -1
- package/src/api/httpErrors.ts +17 -0
- package/src/api/openobserveSetup.ts +85 -0
- package/src/api/podDebug.test.tsx +137 -0
- package/src/api/podDebug.ts +82 -0
- package/src/api/prometheusCharts.test.ts +23 -0
- package/src/api/prometheusCharts.ts +25 -0
- package/src/api/radarFeatures.render.test.tsx +43 -2
- package/src/api/radarFeatures.test.ts +18 -1
- package/src/api/radarFeatures.ts +17 -4
- package/src/api/reviewedActionMutation.ts +9 -2
- package/src/api/workloadMetrics.ts +2 -0
- package/src/components/NamespaceSwitcher.tsx +6 -2
- package/src/components/applications/ApplicationsView.identity.test.ts +35 -7
- package/src/components/applications/ApplicationsView.openResource.test.tsx +137 -11
- package/src/components/applications/ApplicationsView.tsx +127 -173
- package/src/components/cnpg/CNPGOperatorConditions.test.tsx +3 -0
- package/src/components/cnpg/CNPGOperatorConditions.tsx +4 -14
- package/src/components/cnpg/host.test.tsx +1 -1
- package/src/components/cnpg/host.tsx +0 -2
- package/src/components/dock/BottomDock.tsx +7 -3
- package/src/components/dock/MissingShellDebug.test.tsx +193 -0
- package/src/components/dock/MissingShellDebug.tsx +114 -0
- package/src/components/dock/PodDebugSession.test.tsx +60 -0
- package/src/components/dock/PodDebugSession.tsx +96 -0
- package/src/components/dock/TerminalTab.test.tsx +48 -4
- package/src/components/dock/TerminalTab.tsx +47 -25
- package/src/components/dock/WorkloadLogsTab.test.tsx +24 -1
- package/src/components/dock/WorkloadLogsTab.tsx +16 -0
- package/src/components/execution/BatchExecutionView.command.test.tsx +69 -0
- package/src/components/execution/BatchExecutionView.tsx +88 -5
- package/src/components/execution/BatchExecutionView.workflow-stop.test.tsx +69 -0
- package/src/components/execution/WorkflowRunStopAction.tsx +8 -0
- package/src/components/gitops/GitOpsPermissionRowActions.test.tsx +100 -0
- package/src/components/gitops/GitOpsPermissionRowActions.tsx +27 -0
- package/src/components/gitops/GitOpsView.identity.test.tsx +1 -0
- package/src/components/gitops/GitOpsView.permissions.test.tsx +102 -0
- package/src/components/gitops/GitOpsView.syncRequest.test.tsx +95 -7
- package/src/components/gitops/GitOpsView.tsx +93 -32
- package/src/components/helm/OwnedResources.tsx +1 -0
- package/src/components/home/HomeView.tsx +9 -1
- package/src/components/home/ProblemsPanel.investigate.test.tsx +12 -2
- package/src/components/home/mcpToolCatalog.ts +1 -0
- package/src/components/issues/IssuesPane.render.test.tsx +78 -2
- package/src/components/issues/IssuesPane.tsx +49 -6
- package/src/components/issues/useIssueExpansion.ts +91 -0
- package/src/components/resource/MetricsNotConnected.test.tsx +50 -0
- package/src/components/resource/MetricsNotConnected.tsx +114 -0
- package/src/components/resource/PVCUsageBar.tsx +2 -1
- package/src/components/resource/PrometheusCharts.render.test.tsx +47 -0
- package/src/components/resource/PrometheusCharts.tsx +14 -2
- package/src/components/resource/PrometheusChartsGrid.render.test.tsx +91 -1
- package/src/components/resource/PrometheusChartsGrid.tsx +28 -52
- package/src/components/resource/RestartChart.tsx +4 -3
- package/src/components/resource/RightsizingPanel.source.test.tsx +34 -0
- package/src/components/resource/RightsizingStrip.tsx +5 -3
- package/src/components/resource/WorkloadMetricsSection.render.test.tsx +6 -0
- package/src/components/resource/WorkloadMetricsSection.tsx +14 -11
- package/src/components/resource/nameMatchedScope.ts +9 -3
- package/src/components/resources/EmptyNamespaceHint.tsx +42 -0
- package/src/components/resources/PodDebugAction.test.tsx +157 -0
- package/src/components/resources/PodDebugAction.tsx +207 -0
- package/src/components/resources/PodDebugPermission.tsx +21 -0
- package/src/components/resources/ResourcesView.empty-hint.test.tsx +132 -0
- package/src/components/resources/ResourcesView.tsx +39 -5
- package/src/components/resources/namespaceHint.test.ts +34 -0
- package/src/components/resources/namespaceHint.ts +19 -0
- package/src/components/resources/renderers/AdmissionPolicyRenderers.tsx +135 -0
- package/src/components/resources/renderers/NodeRenderer.tsx +2 -1
- package/src/components/resources/renderers/PodRenderer.tsx +12 -5
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.test.tsx +24 -1
- package/src/components/settings/FormSaveActions.tsx +6 -2
- package/src/components/settings/LocalIntegrationStatus.tsx +14 -3
- package/src/components/settings/MetricsBackendSwitch.tsx +165 -0
- package/src/components/settings/OpenObserveSetup.test.tsx +384 -0
- package/src/components/settings/OpenObserveSetup.tsx +328 -0
- package/src/components/settings/SettingsDialog.tsx +21 -7
- package/src/components/settings/openobserveStatus.test.ts +34 -0
- package/src/components/settings/openobserveStatus.ts +55 -0
- package/src/components/timeline/TimelineList.selection.test.tsx +40 -0
- package/src/components/timeline/TimelineList.test.ts +18 -0
- package/src/components/timeline/TimelineList.tsx +19 -5
- package/src/components/timeline/TimelineView.tsx +2 -0
- package/src/components/workload/WorkloadView.pendingOwnership.test.tsx +34 -0
- package/src/components/workload/WorkloadView.tabUrl.test.tsx +44 -0
- package/src/components/workload/WorkloadView.tsx +103 -16
- package/src/components/workspace/WorkspaceConditions.tsx +56 -0
- package/src/components/workspace/layout.test.tsx +20 -0
- package/src/components/workspace/layout.tsx +1 -1
- package/src/context/TimelineNavigation.test.ts +59 -0
- package/src/context/TimelineNavigation.tsx +86 -0
- package/src/contexts/CapabilitiesContext.tsx +5 -1
- package/src/hooks/useResourceCounts.ts +2 -1
- package/src/hooks/useWorkflowStopAction.ts +31 -0
- package/src/index.css +1 -0
- package/src/integrations/resourceHosts.test.tsx +2 -2
- package/src/integrations/resourceHosts.tsx +4 -2
- package/src/k8s-ui-exports.test.ts +10 -0
- package/src/utils/page-links.ts +15 -1
- package/src/components/resources/renderers/ValidatingAdmissionPolicyRenderer.tsx +0 -128
|
@@ -1,50 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { Link } from 'react-router-dom'
|
|
3
|
+
import { relatedResourcePath } from '../../utils/navigation'
|
|
4
|
+
import { getExecContainerNames, TerminalTab as SharedTerminalTab, type DockTab } from '@skyhook-io/k8s-ui'
|
|
5
|
+
import { getApiBase, getWsUrl } from '../../api/config'
|
|
6
|
+
import { useResource } from '../../api/client'
|
|
7
|
+
import type { PodDebugTarget } from '../resources/PodDebugAction'
|
|
8
|
+
import { MissingShellDebug } from './MissingShellDebug'
|
|
9
|
+
import { PodDebugSession } from './PodDebugSession'
|
|
10
|
+
import { useCurrentConnectionId, useOpenedConnection, withConnectionParam } from '../../api/connectionBinding'
|
|
6
11
|
|
|
7
12
|
interface TerminalTabProps {
|
|
8
13
|
namespace: string
|
|
9
14
|
podName: string
|
|
15
|
+
podUID?: string
|
|
10
16
|
containerName: string
|
|
17
|
+
onContainerChange?: (name: string) => void
|
|
11
18
|
containers: string[]
|
|
12
19
|
isActive?: boolean
|
|
13
20
|
shell?: string
|
|
14
21
|
note?: string
|
|
22
|
+
debugSession?: DockTab['debugSession']
|
|
23
|
+
onLeaveTerminal?: () => void
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
export function TerminalTab({ namespace, podName, containerName, containers, isActive, shell, note }: TerminalTabProps) {
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
export function TerminalTab({ namespace, podName, podUID, containerName, containers, onContainerChange, isActive, shell, note, debugSession, onLeaveTerminal }: TerminalTabProps) {
|
|
27
|
+
const openedConnection = useOpenedConnection()
|
|
28
|
+
const [openedBase] = useState(getApiBase)
|
|
29
|
+
const connection = debugSession ? debugSession.connectionId : openedConnection
|
|
30
|
+
const base = debugSession?.apiBase ?? openedBase
|
|
31
|
+
const currentConnection = useCurrentConnectionId()
|
|
32
|
+
const sameConnection = currentConnection === connection && getApiBase() === base
|
|
33
|
+
const checkTargets = !!podUID && !shell && !debugSession && containers.length > 1
|
|
34
|
+
const pod = useResource<PodDebugTarget>('pods', namespace, podName, undefined, { enabled: checkTargets && sameConnection && isActive !== false })
|
|
35
|
+
const currentPod = sameConnection && !pod.error && pod.data?.metadata.uid === podUID ? pod.data : undefined
|
|
36
|
+
const pickerContainers = checkTargets ? getExecContainerNames(currentPod, { runningOnly: true }) : containers
|
|
37
|
+
const podDetailsLink = sameConnection && <Link
|
|
38
|
+
className="mb-2 inline-block text-xs text-accent underline underline-offset-2"
|
|
39
|
+
title="Close this terminal tab and open the current Pod"
|
|
40
|
+
onClick={event => { if (!event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey && event.button === 0) onLeaveTerminal?.() }}
|
|
41
|
+
to={relatedResourcePath({ kind: 'Pod', namespace, name: podName })}
|
|
42
|
+
>Open current Pod details</Link>
|
|
43
|
+
const createSession = async (container: string, failedPodUID?: string) => {
|
|
44
|
+
const uid = debugSession?.podUID ?? podUID ?? failedPodUID
|
|
45
|
+
if (getApiBase() !== base) throw new Error('The cluster connection changed. Reopen the Pod to start a terminal.')
|
|
46
|
+
return {
|
|
47
|
+
wsUrl: withConnectionParam(getWsUrl(`/pods/${namespace}/${podName}/exec?container=${encodeURIComponent(container)}${uid ? `&uid=${encodeURIComponent(uid)}` : ''}${shell ? `&shell=${encodeURIComponent(shell)}` : ''}`), connection),
|
|
33
48
|
}
|
|
34
|
-
return response.json()
|
|
35
49
|
}
|
|
36
50
|
|
|
37
|
-
|
|
51
|
+
const terminal = (
|
|
38
52
|
<SharedTerminalTab
|
|
39
53
|
namespace={namespace}
|
|
40
54
|
podName={podName}
|
|
41
55
|
containerName={containerName}
|
|
42
|
-
containers={
|
|
56
|
+
containers={pickerContainers}
|
|
57
|
+
onContainerChange={onContainerChange}
|
|
43
58
|
isActive={isActive}
|
|
44
59
|
createSession={createSession}
|
|
45
|
-
|
|
60
|
+
podDetailsLink={podDetailsLink}
|
|
61
|
+
renderDebugAction={shell ? undefined : debugSession ? () => <p className="max-w-md text-xs text-theme-text-secondary">
|
|
62
|
+
This debug image has no usable shell. Open Pod details to choose another running container or start a debugger with a different image. {podDetailsLink}
|
|
63
|
+
</p> : (target, uid) =>
|
|
64
|
+
<MissingShellDebug key={JSON.stringify([uid,target])} namespace={namespace} name={podName} target={target} uid={uid} connection={connection} base={base} podDetailsLink={podDetailsLink} />}
|
|
46
65
|
note={note}
|
|
47
66
|
command={shell}
|
|
48
67
|
/>
|
|
49
68
|
)
|
|
69
|
+
return debugSession ? <PodDebugSession namespace={namespace} podName={podName} containerName={containerName} session={debugSession} isActive={isActive} podDetailsLink={podDetailsLink}>
|
|
70
|
+
{terminal}
|
|
71
|
+
</PodDebugSession> : terminal
|
|
50
72
|
}
|
|
@@ -4,8 +4,11 @@ import { createRoot, type Root } from 'react-dom/client'
|
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
5
|
import { WorkloadLogsTab } from './WorkloadLogsTab'
|
|
6
6
|
|
|
7
|
-
const state = vi.hoisted(() => ({ targets: [] as Array<{ kind: string; name: string; role?: string; snapshotOnly?: boolean }> }))
|
|
7
|
+
const state = vi.hoisted(() => ({ replicaSetSupport: true, supportCheckFailed: false, targets: [] as Array<{ kind: string; name: string; role?: string; snapshotOnly?: boolean }> }))
|
|
8
8
|
vi.mock('../../api/client', () => ({
|
|
9
|
+
useRadarFeature: () => state.supportCheckFailed
|
|
10
|
+
? { support: 'unknown', blockedReason: "Couldn't check this cluster's Radar support. Refresh to try again." }
|
|
11
|
+
: state.replicaSetSupport ? { support: 'supported' } : { support: 'unsupported', upgrade: { feature: 'Combined ReplicaSet logs' } },
|
|
9
12
|
useResource: (_kind: string, _namespace: string, name: string) => ({
|
|
10
13
|
data: { metadata: { uid: name }, spec: { replicatedJobs: [{ name: name === 'first' ? 'workers' : 'leader' }] } },
|
|
11
14
|
}),
|
|
@@ -13,6 +16,7 @@ vi.mock('../../api/client', () => ({
|
|
|
13
16
|
data: { collection: 'members', runs: [{ group: 'batch', kind: 'jobs', namespace, name: `${name}-0`, phase: 'Running', active: true }], total: 1 },
|
|
14
17
|
}),
|
|
15
18
|
}))
|
|
19
|
+
vi.mock('../../contexts/CapabilitiesContext', () => ({ useNamespacedCapabilities: () => ({ canViewLogs: true }) }))
|
|
16
20
|
vi.mock('../logs/WorkloadLogsViewer', () => ({
|
|
17
21
|
WorkloadLogsViewer: (props: { kind: string; name: string; role?: string; snapshotOnly?: boolean }) => {
|
|
18
22
|
state.targets.push(props)
|
|
@@ -25,6 +29,8 @@ let root: Root
|
|
|
25
29
|
let element: HTMLDivElement
|
|
26
30
|
beforeEach(() => {
|
|
27
31
|
state.targets = []
|
|
32
|
+
state.replicaSetSupport = true
|
|
33
|
+
state.supportCheckFailed = false
|
|
28
34
|
element = document.createElement('div')
|
|
29
35
|
document.body.appendChild(element)
|
|
30
36
|
root = createRoot(element)
|
|
@@ -64,3 +70,20 @@ describe('dock JobSet logs', () => {
|
|
|
64
70
|
expect(element.querySelector('[data-log-target="jobs/second-0"]')).not.toBeNull()
|
|
65
71
|
})
|
|
66
72
|
})
|
|
73
|
+
|
|
74
|
+
describe('dock ReplicaSet logs', () => {
|
|
75
|
+
it('checks the connected Radar before following a ReplicaSet', async () => {
|
|
76
|
+
await render('web-v2', 'ReplicaSet')
|
|
77
|
+
expect(state.targets.at(-1)).toMatchObject({ kind: 'replicasets', name: 'web-v2' })
|
|
78
|
+
state.targets = []
|
|
79
|
+
state.replicaSetSupport = false
|
|
80
|
+
await render('web-v2', 'replicasets')
|
|
81
|
+
expect(state.targets).toEqual([])
|
|
82
|
+
expect(element.textContent).toContain('newer Radar')
|
|
83
|
+
state.supportCheckFailed = true
|
|
84
|
+
await render('web-v2', 'replicasets')
|
|
85
|
+
expect(state.targets).toEqual([])
|
|
86
|
+
expect(element.textContent).toContain("Couldn't check")
|
|
87
|
+
expect(element.textContent).not.toContain('newer Radar')
|
|
88
|
+
})
|
|
89
|
+
})
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { AlertBanner, PaneLoader, RadarUpgradeNote } from '@skyhook-io/k8s-ui'
|
|
2
|
+
import { useRadarFeature } from '../../api/client'
|
|
3
|
+
import { useNamespacedCapabilities } from '../../contexts/CapabilitiesContext'
|
|
1
4
|
import { WorkloadLogsViewer } from '../logs/WorkloadLogsViewer'
|
|
2
5
|
import { ScheduledWorkloadLogsViewer } from '../logs/ScheduledWorkloadLogsViewer'
|
|
3
6
|
|
|
@@ -8,6 +11,16 @@ interface WorkloadLogsTabProps {
|
|
|
8
11
|
viewNamespaces?: string[]
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
function ReplicaSetDockLogs({ namespace, name }: { namespace: string; name: string }) {
|
|
15
|
+
const { support, upgrade, blockedReason } = useRadarFeature('replicaSetLogs')
|
|
16
|
+
const { canViewLogs, logsUnknown } = useNamespacedCapabilities(namespace)
|
|
17
|
+
if (upgrade) return <RadarUpgradeNote requirement={upgrade} />
|
|
18
|
+
if (blockedReason) return <AlertBanner variant="info" title={blockedReason} />
|
|
19
|
+
if (support !== 'supported') return <PaneLoader label="Checking ReplicaSet log support…" className="h-full" />
|
|
20
|
+
if (!canViewLogs && !logsUnknown) return <AlertBanner variant="warning" title="Pod logs are restricted in this namespace." />
|
|
21
|
+
return <WorkloadLogsViewer kind="replicasets" namespace={namespace} name={name} />
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
export function WorkloadLogsTab({
|
|
12
25
|
namespace,
|
|
13
26
|
workloadKind,
|
|
@@ -15,6 +28,9 @@ export function WorkloadLogsTab({
|
|
|
15
28
|
viewNamespaces,
|
|
16
29
|
}: WorkloadLogsTabProps) {
|
|
17
30
|
const normalizedKind = workloadKind.toLowerCase()
|
|
31
|
+
if (normalizedKind === 'replicasets' || normalizedKind === 'replicaset') {
|
|
32
|
+
return <ReplicaSetDockLogs namespace={namespace} name={workloadName} />
|
|
33
|
+
}
|
|
18
34
|
const isScheduled = normalizedKind === 'cronjob' || normalizedKind === 'cronjobs' ||
|
|
19
35
|
normalizedKind === 'cronworkflow' || normalizedKind === 'cronworkflows' ||
|
|
20
36
|
normalizedKind === 'workflowtemplate' || normalizedKind === 'workflowtemplates' ||
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import { CommandFact } from './BatchExecutionView'
|
|
6
|
+
|
|
7
|
+
vi.mock('../../api/client', () => ({}))
|
|
8
|
+
|
|
9
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
10
|
+
|
|
11
|
+
const script = "sh -c echo '{{inputs.parameters.greeting}}, {{inputs.parameters.target}}'\nset -e\nrun-the-export --all"
|
|
12
|
+
|
|
13
|
+
let root: Root
|
|
14
|
+
let host: HTMLDivElement
|
|
15
|
+
let scrollHeight = 0
|
|
16
|
+
|
|
17
|
+
function render(command = script) {
|
|
18
|
+
host = document.createElement('div')
|
|
19
|
+
document.body.appendChild(host)
|
|
20
|
+
root = createRoot(host)
|
|
21
|
+
act(() => root.render(<CommandFact command={command} />))
|
|
22
|
+
return host.querySelector<HTMLElement>('[data-testid="definition-command"]')!
|
|
23
|
+
}
|
|
24
|
+
const button = (name: string) => [...host.querySelectorAll('button')].find((b) => b.textContent === name || b.getAttribute('aria-label') === name)
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
scrollHeight = 0
|
|
28
|
+
Object.defineProperty(HTMLElement.prototype, 'scrollHeight', { configurable: true, get: () => scrollHeight })
|
|
29
|
+
Object.defineProperty(HTMLElement.prototype, 'clientHeight', { configurable: true, get: () => 64 })
|
|
30
|
+
})
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
act(() => root.unmount())
|
|
33
|
+
host.remove()
|
|
34
|
+
vi.unstubAllGlobals()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('CommandFact', () => {
|
|
38
|
+
it('shows the whole command on its own line, keeping script line breaks, with no toggle when it fits', () => {
|
|
39
|
+
scrollHeight = 64
|
|
40
|
+
const code = render()
|
|
41
|
+
expect(code.textContent).toBe(script)
|
|
42
|
+
expect(code.className).toContain('whitespace-pre-wrap')
|
|
43
|
+
expect(code.className).toContain('[overflow-wrap:anywhere]')
|
|
44
|
+
expect(button('Show all')).toBeUndefined()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('clamps a command taller than the card and expands it in place', () => {
|
|
48
|
+
scrollHeight = 200
|
|
49
|
+
const code = render()
|
|
50
|
+
expect(code.className).toContain('line-clamp-4')
|
|
51
|
+
const toggle = button('Show all')!
|
|
52
|
+
expect(toggle.getAttribute('aria-expanded')).toBe('false')
|
|
53
|
+
act(() => toggle.click())
|
|
54
|
+
expect(code.className).not.toContain('line-clamp-4')
|
|
55
|
+
expect(button('Show less')!.getAttribute('aria-expanded')).toBe('true')
|
|
56
|
+
act(() => button('Show less')!.click())
|
|
57
|
+
expect(code.className).toContain('line-clamp-4')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('copies the whole command, not the clamped text', async () => {
|
|
61
|
+
scrollHeight = 200
|
|
62
|
+
const writeText = vi.fn().mockResolvedValue(undefined)
|
|
63
|
+
vi.stubGlobal('navigator', { clipboard: { writeText } })
|
|
64
|
+
render()
|
|
65
|
+
await act(async () => { button('Copy command')!.click() })
|
|
66
|
+
expect(writeText).toHaveBeenCalledWith(script)
|
|
67
|
+
expect(button('Command copied')).toBeDefined()
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState, type ComponentType, type ReactNode } from 'react'
|
|
2
|
-
import { Activity, GitBranch, Terminal } from 'lucide-react'
|
|
1
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType, type ReactNode } from 'react'
|
|
2
|
+
import { Activity, Check, Copy, GitBranch, Terminal } from 'lucide-react'
|
|
3
3
|
import { clsx } from 'clsx'
|
|
4
4
|
import {
|
|
5
5
|
Collapse,
|
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
podStatusClass,
|
|
15
15
|
podStatusLabel,
|
|
16
16
|
workloadPodDetail,
|
|
17
|
+
WorkflowShutdownBadge,
|
|
17
18
|
} from '@skyhook-io/k8s-ui'
|
|
19
|
+
import { copyText } from '@skyhook-io/k8s-ui/utils/clipboard'
|
|
18
20
|
import { buildWorkflowExecutionModel, flattenWorkflowExecution, type WorkflowExecutionActivity, type WorkflowExecutionModel, type WorkflowExecutionNode, type WorkflowExecutionRow, type WorkflowTemplateReference } from '@skyhook-io/k8s-ui/utils/workflow-execution'
|
|
19
21
|
import { midTruncate } from '@skyhook-io/k8s-ui/utils/format'
|
|
20
22
|
import { isJobSetV1Alpha2 } from '@skyhook-io/k8s-ui/components/resources/resource-utils-jobset-lws'
|
|
@@ -27,6 +29,7 @@ import { getScaledJobStatus } from '../resources/resource-utils-keda'
|
|
|
27
29
|
import { Tooltip } from '../ui/Tooltip'
|
|
28
30
|
import { ImageFilesystemModal } from '../resources/ImageFilesystemModal'
|
|
29
31
|
import { useIsAuthEnabled } from '../../contexts/CapabilitiesContext'
|
|
32
|
+
import { WorkflowRunStopAction } from './WorkflowRunStopAction'
|
|
30
33
|
import { executionDefinitionDiffers, executionDefinitionSummary, type ExecutionDefinitionSummary, type ExecutionUnitSummary } from './execution-definition'
|
|
31
34
|
import { batchRunHasContainerOutcome, batchRunNextStep, isFailedRunPhase, type BatchRunNextStep } from './batch-run-actions'
|
|
32
35
|
import { JobSetAdmission } from './JobSetAdmission'
|
|
@@ -254,6 +257,17 @@ function BatchExecutionContent({ leadContent, kind, apiKind, namespace, name, re
|
|
|
254
257
|
{ enabled: Boolean(fetchTarget), refetchInterval: selectedRun?.active ? 5000 : false },
|
|
255
258
|
)
|
|
256
259
|
const selectedResource = scheduled ? selectedResourceQuery.data : resource
|
|
260
|
+
// A scheduled parent's selected run is a child Workflow with no action bar
|
|
261
|
+
// of its own here; a standalone Workflow already has Stop in its bar.
|
|
262
|
+
// An older Radar's run rows carry no group; the Workflow object's own
|
|
263
|
+
// apiVersion still decides, in WorkflowStopAction.
|
|
264
|
+
const selectedRunStoppable = scheduled && selectedRun?.kind === 'workflows' && (!selectedRun.group || selectedRun.group === 'argoproj.io')
|
|
265
|
+
// Only the selected run's own, currently readable object: never the previous
|
|
266
|
+
// selection's, nor a last copy kept after a failed refetch.
|
|
267
|
+
const selectedWorkflow = selectedRunStoppable && !selectedResourceQuery.error &&
|
|
268
|
+
selectedResource?.metadata?.name === selectedRun.name && selectedResource?.metadata?.namespace === selectedRun.namespace
|
|
269
|
+
? selectedResource
|
|
270
|
+
: undefined
|
|
257
271
|
const workflowExecution = useMemo(
|
|
258
272
|
() => selectedResource && selectedRun?.kind === 'workflows' ? buildWorkflowExecutionModel(selectedResource) : null,
|
|
259
273
|
[selectedResource, selectedRun?.kind],
|
|
@@ -418,7 +432,14 @@ function BatchExecutionContent({ leadContent, kind, apiKind, namespace, name, re
|
|
|
418
432
|
{selectedResourceQuery.isFetching && <span>refreshing</span>}
|
|
419
433
|
</div>
|
|
420
434
|
</div>
|
|
421
|
-
<
|
|
435
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
436
|
+
{/* Stays mounted across selections so a request in flight keeps its dialog. */}
|
|
437
|
+
{selectedRunStoppable && (
|
|
438
|
+
<WorkflowRunStopAction workflow={selectedWorkflow} namespace={selectedRun.namespace} name={selectedRun.name} />
|
|
439
|
+
)}
|
|
440
|
+
{selectedWorkflow && <WorkflowShutdownBadge data={selectedWorkflow} />}
|
|
441
|
+
<span className={clsx('badge', selectedRunHeldByKueue ? 'status-neutral' : phaseBadgeClass(selectedRun.phase))}>{selectedRunHeldByKueue ? `Held by Kueue until admitted${selectedRun.deleting ? ' · deleting' : ''}` : runStateLabel(selectedRun)}</span>
|
|
442
|
+
</div>
|
|
422
443
|
</div>
|
|
423
444
|
{memberCollection && <div className="flex flex-wrap items-center gap-3 border-b border-theme-border px-4 py-2 text-xs">
|
|
424
445
|
{!runs.some(run => workloadRunKey(run) === selectedRunKey) && <span className="text-theme-text-secondary">Selected Job is outside the current filter or shown window.</span>}
|
|
@@ -754,7 +775,7 @@ function ExecutionUnitDetails({ unit, namespace, pullSecrets, compact }: { unit:
|
|
|
754
775
|
{!compact && <div className="mb-1 flex items-center justify-between gap-3"><span className="truncate text-xs font-medium text-theme-text-primary">{unit.name}</span><span className="text-[10px] uppercase tracking-wide text-theme-text-tertiary">{unit.type}</span></div>}
|
|
755
776
|
<div className="space-y-1">
|
|
756
777
|
{unit.image && <DefinitionFact label="Image" value={unit.image} mono onClick={canBrowseImage ? () => setBrowseImage(true) : undefined} tooltip={canBrowseImage ? 'Browse image filesystem from registry' : IMAGE_BROWSE_VIA_POD} hint={!canBrowseImage} />}
|
|
757
|
-
{unit.command && <
|
|
778
|
+
{unit.command && <CommandFact key={unit.command} command={unit.command} />}
|
|
758
779
|
{!compact && unit.requests && <DefinitionFact label="Requests" value={unit.requests} />}
|
|
759
780
|
{!compact && unit.limits && <DefinitionFact label="Limits" value={unit.limits} />}
|
|
760
781
|
</div>
|
|
@@ -775,8 +796,70 @@ function ExecutionUnitDetails({ unit, namespace, pullSecrets, compact }: { unit:
|
|
|
775
796
|
|
|
776
797
|
const IMAGE_BROWSE_VIA_POD = "With sign-in on, browse an image's files from one of its Pods."
|
|
777
798
|
|
|
799
|
+
// A command (command plus args, often a whole `sh -c` script) can be far wider and
|
|
800
|
+
// taller than the card. It gets its own full-width line, keeps the script's line
|
|
801
|
+
// breaks, clamps to a few lines with an explicit toggle when it overflows, and
|
|
802
|
+
// copies whole; a hover tooltip can't hold or copy a script.
|
|
803
|
+
export function CommandFact({ command }: { command: string }) {
|
|
804
|
+
const ref = useRef<HTMLElement>(null)
|
|
805
|
+
const [expanded, setExpanded] = useState(false)
|
|
806
|
+
const [overflows, setOverflows] = useState(false)
|
|
807
|
+
const [copied, setCopied] = useState(false)
|
|
808
|
+
|
|
809
|
+
useLayoutEffect(() => {
|
|
810
|
+
const el = ref.current
|
|
811
|
+
if (!el || expanded) return
|
|
812
|
+
const measure = () => setOverflows(el.scrollHeight > el.clientHeight + 1)
|
|
813
|
+
measure()
|
|
814
|
+
if (typeof ResizeObserver === 'undefined') return
|
|
815
|
+
const observer = new ResizeObserver(measure)
|
|
816
|
+
observer.observe(el)
|
|
817
|
+
return () => observer.disconnect()
|
|
818
|
+
}, [expanded])
|
|
819
|
+
|
|
820
|
+
useEffect(() => {
|
|
821
|
+
if (!copied) return
|
|
822
|
+
const timer = setTimeout(() => setCopied(false), 1500)
|
|
823
|
+
return () => clearTimeout(timer)
|
|
824
|
+
}, [copied])
|
|
825
|
+
|
|
826
|
+
return (
|
|
827
|
+
<div className="text-sm">
|
|
828
|
+
<div className="flex items-center justify-between gap-3">
|
|
829
|
+
<span className="text-theme-text-tertiary">Command</span>
|
|
830
|
+
<button
|
|
831
|
+
type="button"
|
|
832
|
+
onClick={() => { void copyText(command).then((ok) => { if (ok) setCopied(true) }) }}
|
|
833
|
+
aria-label={copied ? 'Command copied' : 'Copy command'}
|
|
834
|
+
className="rounded p-0.5 text-theme-text-tertiary hover:bg-theme-hover hover:text-theme-text-primary"
|
|
835
|
+
>
|
|
836
|
+
{copied ? <Check className="h-3.5 w-3.5" /> : <Copy className="h-3.5 w-3.5" />}
|
|
837
|
+
</button>
|
|
838
|
+
</div>
|
|
839
|
+
{/* Padding sits on the wrapper: inside the clamped box it would expose the top of the next line. */}
|
|
840
|
+
<div className="mt-1 rounded bg-theme-base px-2 py-1.5">
|
|
841
|
+
<code
|
|
842
|
+
ref={ref}
|
|
843
|
+
data-testid="definition-command"
|
|
844
|
+
className={clsx(
|
|
845
|
+
'whitespace-pre-wrap font-mono text-xs text-theme-text-primary [overflow-wrap:anywhere]',
|
|
846
|
+
expanded ? 'block' : 'line-clamp-4',
|
|
847
|
+
)}
|
|
848
|
+
>
|
|
849
|
+
{command}
|
|
850
|
+
</code>
|
|
851
|
+
</div>
|
|
852
|
+
{(overflows || expanded) && (
|
|
853
|
+
<button type="button" aria-expanded={expanded} onClick={() => setExpanded((open) => !open)} className="mt-1 text-xs text-accent-text hover:underline">
|
|
854
|
+
{expanded ? 'Show less' : 'Show all'}
|
|
855
|
+
</button>
|
|
856
|
+
)}
|
|
857
|
+
</div>
|
|
858
|
+
)
|
|
859
|
+
}
|
|
860
|
+
|
|
778
861
|
function DefinitionFact({ label, value, mono = false, onClick, tooltip, hint = false }: { label: string; value: string; mono?: boolean; onClick?: () => void; tooltip?: string; hint?: boolean }) {
|
|
779
|
-
const valueClassName = clsx('
|
|
862
|
+
const valueClassName = clsx('min-w-0 text-theme-text-primary [overflow-wrap:anywhere]', mono && 'font-mono text-xs', onClick && 'text-accent-text hover:underline', hint && 'cursor-help underline decoration-dotted decoration-theme-text-tertiary underline-offset-2')
|
|
780
863
|
return (
|
|
781
864
|
<div className="flex items-start justify-between gap-3 text-sm">
|
|
782
865
|
<span className="shrink-0 text-theme-text-tertiary">{label}</span>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { BatchExecutionFullscreen } from './BatchExecutionView'
|
|
4
|
+
|
|
5
|
+
const run: { group: string; kind: string; namespace: string; name: string; phase: string; active: boolean } = { group: 'argoproj.io', kind: 'workflows', namespace: 'ci', name: 'nightly-abc12', phase: 'Running', active: true }
|
|
6
|
+
const child = { apiVersion: 'argoproj.io/v1alpha1', kind: 'Workflow', metadata: { name: 'nightly-abc12', namespace: 'ci', uid: 'uid-1' }, spec: {}, status: { phase: 'Running' } }
|
|
7
|
+
const selected = vi.hoisted(() => ({ data: undefined as unknown, error: undefined as unknown }))
|
|
8
|
+
|
|
9
|
+
vi.mock('../../api/client', () => ({
|
|
10
|
+
useResource: () => ({ data: selected.data, error: selected.error }),
|
|
11
|
+
useWorkloadPods: () => ({}),
|
|
12
|
+
useJobSetResources: () => ({ data: undefined, isLoading: false }),
|
|
13
|
+
useWorkloadRuns: () => ({ data: { collection: 'runs', runs: [run], total: 1, truncated: false } }),
|
|
14
|
+
}))
|
|
15
|
+
vi.mock('./WorkflowRunStopAction', () => ({
|
|
16
|
+
WorkflowRunStopAction: ({ workflow, namespace, name }: { workflow?: { metadata: { uid: string } }; namespace: string; name: string }) =>
|
|
17
|
+
<span data-stop-action={`${namespace}/${name}/${workflow?.metadata.uid ?? 'none'}`} />,
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
const key = 'workflows/ci/nightly-abc12'
|
|
21
|
+
|
|
22
|
+
describe('Stop in the run view', () => {
|
|
23
|
+
it('offers Stop for the selected child Workflow of a CronWorkflow', () => {
|
|
24
|
+
selected.data = child
|
|
25
|
+
selected.error = undefined
|
|
26
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
27
|
+
expect(html).toContain('data-stop-action="ci/nightly-abc12/uid-1"')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('shows a requested shutdown beside the run state', () => {
|
|
31
|
+
selected.data = { ...child, spec: { shutdown: 'Terminate' } }
|
|
32
|
+
selected.error = undefined
|
|
33
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
34
|
+
expect(html).toContain('Terminating')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('accepts a run row without a group, as an older Radar sends it', () => {
|
|
38
|
+
selected.data = child
|
|
39
|
+
selected.error = undefined
|
|
40
|
+
run.group = undefined as unknown as string
|
|
41
|
+
try {
|
|
42
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
43
|
+
expect(html).toContain('data-stop-action="ci/nightly-abc12/uid-1"')
|
|
44
|
+
} finally {
|
|
45
|
+
run.group = 'argoproj.io'
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('withholds the object after a failed refetch, keeping only the last copy', () => {
|
|
50
|
+
selected.data = child
|
|
51
|
+
selected.error = new Error('workflow not found')
|
|
52
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
53
|
+
expect(html).toContain('data-stop-action="ci/nightly-abc12/none"')
|
|
54
|
+
selected.error = undefined
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('waits for the selected run’s own object, never acting on a previous selection', () => {
|
|
58
|
+
selected.data = { ...child, metadata: { ...child.metadata, name: 'nightly-old' } }
|
|
59
|
+
selected.error = undefined
|
|
60
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="CronWorkflow" apiKind="cronworkflows" namespace="ci" name="nightly" resource={{ spec: {} }} selectedRunKey={key} />)
|
|
61
|
+
// Mounted, so a request in flight keeps its dialog, but given no object to act on.
|
|
62
|
+
expect(html).toContain('data-stop-action="ci/nightly-abc12/none"')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('leaves a standalone Workflow to its action bar', () => {
|
|
66
|
+
const html = renderToStaticMarkup(<BatchExecutionFullscreen kind="Workflow" apiKind="workflows" namespace="ci" name="nightly-abc12" resource={child} selectedRunKey={key} />)
|
|
67
|
+
expect(html).not.toContain('data-stop-action')
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WorkflowStopAction } from '@skyhook-io/k8s-ui'
|
|
2
|
+
import { useWorkflowStopAction } from '../../hooks/useWorkflowStopAction'
|
|
3
|
+
|
|
4
|
+
/** Stop / Terminate for a child Workflow selected in a scheduled parent's run view. */
|
|
5
|
+
export function WorkflowRunStopAction({ workflow, namespace, name }: { workflow: unknown; namespace: string; name: string }) {
|
|
6
|
+
const stop = useWorkflowStopAction('workflows', 'argoproj.io', namespace)
|
|
7
|
+
return <WorkflowStopAction data={workflow} namespace={namespace} name={name} {...stop} />
|
|
8
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act } from 'react'
|
|
3
|
+
import { createRoot } from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { RefreshCw } from 'lucide-react'
|
|
6
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
7
|
+
import type { GitOpsRow } from '@skyhook-io/k8s-ui'
|
|
8
|
+
import { GitOpsPermissionRowActions } from './GitOpsPermissionRowActions'
|
|
9
|
+
|
|
10
|
+
vi.mock('../../context/RadarUpgradeHost', () => ({ useRadarUpgradeHost: () => ({}) }))
|
|
11
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
12
|
+
const row = { kindName: 'applications', group: 'argoproj.io', namespace: 'argocd', name: 'demo' } as GitOpsRow
|
|
13
|
+
const note = "Couldn't check your permissions. You can still try."
|
|
14
|
+
const sync = vi.fn()
|
|
15
|
+
let client: QueryClient
|
|
16
|
+
let host: HTMLDivElement
|
|
17
|
+
let root: ReturnType<typeof createRoot>
|
|
18
|
+
let answer: () => Promise<Response>
|
|
19
|
+
const requests = vi.fn((input: RequestInfo | URL) => String(input).includes('/gitops/capabilities/') ? answer() : new Promise<Response>(() => {}))
|
|
20
|
+
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
vi.useFakeTimers()
|
|
23
|
+
sync.mockClear()
|
|
24
|
+
requests.mockClear()
|
|
25
|
+
answer = () => new Promise<Response>(() => {})
|
|
26
|
+
vi.stubGlobal('fetch', requests)
|
|
27
|
+
client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
28
|
+
client.setQueryData(['capabilities'], { features: { gitopsActionCapabilities: true } })
|
|
29
|
+
host = document.createElement('div')
|
|
30
|
+
document.body.append(host)
|
|
31
|
+
root = createRoot(host)
|
|
32
|
+
await act(async () => root.render(
|
|
33
|
+
<QueryClientProvider client={client}>
|
|
34
|
+
<GitOpsPermissionRowActions row={row} items={[{ key: 'sync', label: 'Sync', icon: RefreshCw, onClick: sync }]} />
|
|
35
|
+
</QueryClientProvider>,
|
|
36
|
+
))
|
|
37
|
+
})
|
|
38
|
+
afterEach(async () => {
|
|
39
|
+
await act(async () => root.unmount())
|
|
40
|
+
client.clear()
|
|
41
|
+
host.remove()
|
|
42
|
+
vi.useRealTimers()
|
|
43
|
+
vi.unstubAllGlobals()
|
|
44
|
+
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
|
|
45
|
+
})
|
|
46
|
+
async function openMenu() {
|
|
47
|
+
await act(async () => host.querySelector<HTMLButtonElement>('[aria-label="Row actions"]')!.click())
|
|
48
|
+
await act(async () => { await vi.advanceTimersByTimeAsync(1) })
|
|
49
|
+
}
|
|
50
|
+
const action = () => host.querySelector<HTMLButtonElement>('[role="menuitem"]')!
|
|
51
|
+
|
|
52
|
+
it('shows the unavailable note only in the open menu after a failed check and permits the action', async () => {
|
|
53
|
+
let reject: (error: Error) => void
|
|
54
|
+
answer = () => new Promise((_, fail) => { reject = fail })
|
|
55
|
+
expect(requests.mock.calls.some(([url]) => String(url).includes('/gitops/capabilities/'))).toBe(false)
|
|
56
|
+
expect(host.textContent).not.toContain(note)
|
|
57
|
+
await openMenu()
|
|
58
|
+
expect(host.textContent).not.toContain(note)
|
|
59
|
+
await act(async () => {
|
|
60
|
+
reject!(new Error('Permission check failed'))
|
|
61
|
+
await vi.advanceTimersByTimeAsync(1)
|
|
62
|
+
})
|
|
63
|
+
const menu = host.querySelector('[role="menu"]')!
|
|
64
|
+
expect(menu.querySelector('p')!.textContent).toBe(note)
|
|
65
|
+
expect(menu.querySelector('p')!.className).toContain('text-theme-text-secondary')
|
|
66
|
+
expect(menu.querySelectorAll('button')).toHaveLength(1)
|
|
67
|
+
expect(action().disabled).toBe(false)
|
|
68
|
+
expect(action().getAttribute('aria-disabled')).not.toBe('true')
|
|
69
|
+
await act(async () => action().click())
|
|
70
|
+
expect(sync).toHaveBeenCalledOnce()
|
|
71
|
+
await act(async () => { await vi.advanceTimersByTimeAsync(1000) })
|
|
72
|
+
expect(host.querySelector('[role="menu"]')).toBeNull()
|
|
73
|
+
expect(host.textContent).not.toContain(note)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('shows the unavailable note and enables an expired denial while checks remain pending', async () => {
|
|
77
|
+
answer = async () => Response.json({ actions: { sync: { allowed: false, denied: [{ verb: 'patch', resource: 'applications', group: 'argoproj.io', namespace: 'argocd', name: 'demo' }] } } })
|
|
78
|
+
await openMenu()
|
|
79
|
+
expect(action().getAttribute('aria-disabled')).toBe('true')
|
|
80
|
+
expect(host.textContent).not.toContain(note)
|
|
81
|
+
answer = () => new Promise<Response>(() => {})
|
|
82
|
+
await act(async () => { await vi.advanceTimersByTimeAsync(119_998) })
|
|
83
|
+
expect(action().getAttribute('aria-disabled')).toBe('true')
|
|
84
|
+
await act(async () => { await vi.advanceTimersByTimeAsync(2) })
|
|
85
|
+
expect(host.querySelector('[role="menu"]')!.textContent).toContain(note)
|
|
86
|
+
expect(action().disabled).toBe(false)
|
|
87
|
+
expect(action().getAttribute('aria-disabled')).not.toBe('true')
|
|
88
|
+
await act(async () => action().click())
|
|
89
|
+
expect(sync).toHaveBeenCalledOnce()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('keeps a denied action disabled while the row menu closes', async () => {
|
|
93
|
+
answer = async () => Response.json({ actions: { sync: { allowed: false, denied: [{ verb: 'patch', resource: 'applications', group: 'argoproj.io', namespace: 'argocd', name: 'demo' }] } } })
|
|
94
|
+
await openMenu()
|
|
95
|
+
expect(action().getAttribute('aria-disabled')).toBe('true')
|
|
96
|
+
|
|
97
|
+
await act(async () => host.querySelector<HTMLButtonElement>('[aria-label="Row actions"]')!.click())
|
|
98
|
+
expect(host.querySelector('[role="menu"]')?.hasAttribute('inert')).toBe(true)
|
|
99
|
+
expect(action().getAttribute('aria-disabled')).toBe('true')
|
|
100
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { RowActionMenu, type RowActionItem } from '@skyhook-io/k8s-ui/components/ui/RowActionMenu'
|
|
3
|
+
import type { GitOpsRow } from '@skyhook-io/k8s-ui'
|
|
4
|
+
import { useGitOpsActionCapabilities } from '../../api/client'
|
|
5
|
+
|
|
6
|
+
export function GitOpsPermissionRowActions({ row, items }: { row: GitOpsRow; items: RowActionItem[] }) {
|
|
7
|
+
return (
|
|
8
|
+
<RowActionMenu items={items} renderOpenItems={(render, open) => (
|
|
9
|
+
<PermissionItems row={row} items={items} render={render} open={open} />
|
|
10
|
+
)} />
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function PermissionItems({ row, items, render, open }: {
|
|
15
|
+
row: GitOpsRow
|
|
16
|
+
items: RowActionItem[]
|
|
17
|
+
render: (items: RowActionItem[], note?: string) => ReactNode
|
|
18
|
+
open: boolean
|
|
19
|
+
}) {
|
|
20
|
+
const { disabledReasons, permissionCheckUnavailable } = useGitOpsActionCapabilities(row.kindName, row.group, row.namespace, row.name, open)
|
|
21
|
+
const actions = items.map(item => {
|
|
22
|
+
const action = item.key === 'hard-refresh' ? 'refresh' : item.key
|
|
23
|
+
const reason = item.disabledReason || disabledReasons[action]
|
|
24
|
+
return { ...item, disabled: item.disabled || !!reason, disabledReason: reason }
|
|
25
|
+
})
|
|
26
|
+
return render(actions, permissionCheckUnavailable ? "Couldn't check your permissions. You can still try." : undefined)
|
|
27
|
+
}
|
|
@@ -19,6 +19,7 @@ vi.mock('../../api/client', async (importOriginal) => {
|
|
|
19
19
|
}
|
|
20
20
|
})
|
|
21
21
|
vi.mock('../ui/Toast', () => ({ useToast: () => ({ showError: vi.fn(), showSuccess: vi.fn(), showToast: vi.fn() }) }))
|
|
22
|
+
vi.mock('../../context/ConnectionContext', () => ({ useConnection: () => ({ connection: { state: 'connected', context: 'test' } }) }))
|
|
22
23
|
vi.mock('../useContextSwitchFlow', () => ({ useContextSwitchFlow: () => ({ confirmDialog: null }) }))
|
|
23
24
|
vi.mock('./useDestinationCluster', () => ({ useDestinationCluster: (...args: unknown[]) => { destinationRequest(...args); return {} } }))
|
|
24
25
|
vi.mock('../../hooks/useKeyboardShortcuts', () => ({ useRegisterShortcut: () => {} }))
|