Skip to content

Commit 30742f6

Browse files
authored
feat(ui): disable select not running pod and bring back arrow to selected pod (#21576)
Signed-off-by: linghaoSu <[email protected]>
1 parent 274e918 commit 30742f6

File tree

2 files changed

+79
-17
lines changed

2 files changed

+79
-17
lines changed

ui/src/app/applications/components/pod-terminal-viewer/pod-terminal-viewer.scss

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@
66
}
77
}
88

9-
.negative-space-arrow {
10-
margin-left: -10px;
9+
.pod-terminal-viewer__tab {
10+
cursor: pointer;
11+
border-radius: 3px;
12+
display: flex;
13+
padding: 0.25rem 1rem !important;
14+
align-items: center;
15+
16+
&:hover {
17+
background-color: rgba(0, 0, 0, 0.1);
18+
}
19+
20+
&--disabled {
21+
opacity: 0.6;
22+
cursor: not-allowed !important;
23+
24+
&:hover {
25+
background-color: transparent;
26+
}
27+
}
28+
29+
30+
.pod-terminal-viewer__icon {
31+
top: 0.4rem;
32+
}
33+
34+
.negative-space-arrow {
35+
margin-left: 0.3rem;
36+
}
37+
}
38+
39+
.theme-light {
40+
.pod-terminal-viewer__container {
41+
.tooltip {
42+
background-color: #fff;
43+
border-color: #fff;
44+
color: #191826;
45+
}
46+
}
1147
}

ui/src/app/applications/components/pod-terminal-viewer/pod-terminal-viewer.tsx

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {useCallback, useEffect} from 'react';
88
import {debounceTime, takeUntil} from 'rxjs/operators';
99
import {fromEvent, ReplaySubject, Subject} from 'rxjs';
1010
import {Context} from '../../../shared/context';
11+
import {Tooltip} from 'argo-ui/v2';
1112
import {ErrorNotification, NotificationType} from 'argo-ui';
1213
export interface PodTerminalViewerProps {
1314
applicationName: string;
@@ -25,6 +26,16 @@ export interface ShellFrame {
2526
cols?: number;
2627
}
2728

29+
const TooltipWrapper = (props: {content: React.ReactNode | string; disabled?: boolean; inverted?: boolean} & React.PropsWithRef<any>) => {
30+
return !props.disabled ? (
31+
<Tooltip content={props.content} inverted={props.inverted}>
32+
{props.children}
33+
</Tooltip>
34+
) : (
35+
props.children
36+
);
37+
};
38+
2839
export const PodTerminalViewer: React.FC<PodTerminalViewerProps> = ({
2940
selectedNode,
3041
applicationName,
@@ -231,26 +242,41 @@ export const PodTerminalViewer: React.FC<PodTerminalViewerProps> = ({
231242
}
232243
];
233244

245+
const isContainerRunning = (container: any): boolean => {
246+
const containerStatus =
247+
podState.status?.containerStatuses?.find((status: {name: string}) => status.name === container.name) ||
248+
podState.status?.initContainerStatuses?.find((status: {name: string}) => status.name === container.name);
249+
return containerStatus?.state?.running != null;
250+
};
251+
234252
return (
235-
<div className='row'>
253+
<div className='row pod-terminal-viewer__container'>
236254
<div className='columns small-3 medium-2'>
237255
{containerGroups.map(group => (
238256
<div key={group.title} style={{marginBottom: '1em'}}>
239257
{group.containers.length > 0 && <p>{group.title}</p>}
240-
{group.containers.map((container: any, i: number) => (
241-
<div
242-
className='application-details__container'
243-
key={container.name}
244-
onClick={() => {
245-
if (container.name !== containerName) {
246-
disconnect();
247-
onClickContainer(group, i, 'exec');
248-
}
249-
}}>
250-
{container.name === containerName && <i className='fa fa-angle-right negative-space-arrow' />}
251-
<span title={container.name}>{container.name}</span>
252-
</div>
253-
))}
258+
{group.containers.map((container: any, i: number) => {
259+
const running = isContainerRunning(container);
260+
return (
261+
<TooltipWrapper key={container.name} content={!running ? 'Container is not running' : ''} disabled={running}>
262+
<div
263+
className={`application-details__container pod-terminal-viewer__tab ${!running ? 'pod-terminal-viewer__tab--disabled' : ''}`}
264+
onClick={() => {
265+
if (!running) {
266+
return;
267+
}
268+
if (container.name !== containerName) {
269+
disconnect();
270+
onClickContainer(group, i, 'exec');
271+
}
272+
}}
273+
title={!running ? 'Container is not running' : container.name}>
274+
{container.name === containerName && <i className='pod-terminal-viewer__icon fa fa-angle-right negative-space-arrow' />}
275+
<span>{container.name}</span>
276+
</div>
277+
</TooltipWrapper>
278+
);
279+
})}
254280
</div>
255281
))}
256282
</div>

0 commit comments

Comments
 (0)