@@ -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,48 @@ 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 ( autoLaunchView !== 'logs' ) {
522+ lastAutoLaunchedPod . current = null ;
523+ return ;
524+ }
525+
526+ if (
527+ podItem &&
528+ autoLaunchView === 'logs' &&
529+ lastAutoLaunchedPod . current !== podItem . metadata . uid
530+ ) {
531+ lastAutoLaunchedPod . current = podItem . metadata . uid ;
532+ launchLogs ( podItem ) ;
533+ }
534+ } , [ podItem , launchLogs , autoLaunchView ] ) ;
535+
494536 function prepareExtraInfo ( item : Pod | null ) {
495537 let extraInfo : {
496538 name : string ;
@@ -589,6 +631,9 @@ export default function PodDetails(props: PodDetailsProps) {
589631 namespace = { namespace }
590632 cluster = { cluster }
591633 withEvents
634+ onResourceUpdate = { item => {
635+ setPodItem ( item ) ;
636+ } }
592637 actions = { item =>
593638 item && [
594639 {
@@ -598,24 +643,7 @@ export default function PodDetails(props: PodDetailsProps) {
598643 < ActionButton
599644 description = { t ( 'Show Logs' ) }
600645 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- } }
646+ onClick = { ( ) => launchLogs ( item ) }
619647 />
620648 </ AuthVisible >
621649 ) ,
0 commit comments