@@ -26,7 +26,7 @@ import { Terminal as XTerminal } from '@xterm/xterm';
2626import _ from 'lodash' ;
2727import React from 'react' ;
2828import { useTranslation } from 'react-i18next' ;
29- import { useParams } from 'react-router-dom' ;
29+ import { useLocation , useParams } from 'react-router-dom' ;
3030import { KubeContainerStatus } from '../../lib/k8s/cluster' ;
3131import Pod from '../../lib/k8s/pod' ;
3232import { DefaultHeaderAction } from '../../redux/actionButtonsSlice' ;
@@ -491,6 +491,43 @@ export default function PodDetails(props: PodDetailsProps) {
491491 const { t } = useTranslation ( 'glossary' ) ;
492492 const dispatchHeadlampEvent = useEventCallback ( ) ;
493493
494+ const lastAutoLaunchedPod = React . useRef < string | null > ( null ) ;
495+ const location = useLocation ( ) ;
496+ const queryParams = new URLSearchParams ( location . search ) ;
497+ const autoLaunchView = queryParams . get ( 'view' ) ;
498+ const [ podItem , setPodItem ] = React . useState < Pod | null > ( null ) ;
499+
500+ const launchLogs = React . useCallback (
501+ ( item : Pod ) => {
502+ Activity . launch ( {
503+ id : 'logs-' + item . metadata . uid ,
504+ title : t ( 'Logs: {{ itemName }}' , { itemName : item . metadata . name } ) ,
505+ cluster : item . cluster ,
506+ icon : < Icon icon = "mdi:file-document-box-outline" width = "100%" height = "100%" /> ,
507+ location : 'full' ,
508+ content : < PodLogViewer noDialog open item = { item } onClose = { ( ) => { } } /> ,
509+ } ) ;
510+ dispatchHeadlampEvent ( {
511+ type : HeadlampEventType . LOGS ,
512+ data : {
513+ status : EventStatus . OPENED ,
514+ } ,
515+ } ) ;
516+ } ,
517+ [ t , dispatchHeadlampEvent ]
518+ ) ;
519+
520+ React . useEffect ( ( ) => {
521+ if (
522+ podItem &&
523+ autoLaunchView === 'logs' &&
524+ lastAutoLaunchedPod . current !== podItem . metadata . uid
525+ ) {
526+ lastAutoLaunchedPod . current = podItem . metadata . uid ;
527+ launchLogs ( podItem ) ;
528+ }
529+ } , [ podItem , launchLogs , autoLaunchView ] ) ;
530+
494531 function prepareExtraInfo ( item : Pod | null ) {
495532 let extraInfo : {
496533 name : string ;
@@ -589,6 +626,9 @@ export default function PodDetails(props: PodDetailsProps) {
589626 namespace = { namespace }
590627 cluster = { cluster }
591628 withEvents
629+ onResourceUpdate = { item => {
630+ setPodItem ( item ) ;
631+ } }
592632 actions = { item =>
593633 item && [
594634 {
@@ -598,24 +638,7 @@ export default function PodDetails(props: PodDetailsProps) {
598638 < ActionButton
599639 description = { t ( 'Show Logs' ) }
600640 icon = "mdi:file-document-box-outline"
601- onClick = { ( ) => {
602- Activity . launch ( {
603- id : 'logs-' + item . metadata . uid ,
604- title : t ( 'Logs' ) + ': ' + item . metadata . name ,
605- cluster : item . cluster ,
606- icon : (
607- < Icon icon = "mdi:file-document-box-outline" width = "100%" height = "100%" />
608- ) ,
609- location : 'full' ,
610- content : < PodLogViewer noDialog open item = { item } onClose = { ( ) => { } } /> ,
611- } ) ;
612- dispatchHeadlampEvent ( {
613- type : HeadlampEventType . LOGS ,
614- data : {
615- status : EventStatus . OPENED ,
616- } ,
617- } ) ;
618- } }
641+ onClick = { ( ) => launchLogs ( item ) }
619642 />
620643 </ AuthVisible >
621644 ) ,
0 commit comments