@@ -8,6 +8,7 @@ import {useCallback, useEffect} from 'react';
88import { debounceTime , takeUntil } from 'rxjs/operators' ;
99import { fromEvent , ReplaySubject , Subject } from 'rxjs' ;
1010import { Context } from '../../../shared/context' ;
11+ import { Tooltip } from 'argo-ui/v2' ;
1112import { ErrorNotification , NotificationType } from 'argo-ui' ;
1213export 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+
2839export 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