Skip to content

Commit d99ede8

Browse files
committed
logsQueryParams
1 parent 85e434d commit d99ede8

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

frontend/src/components/pod/Details.tsx

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Terminal as XTerminal } from '@xterm/xterm';
2626
import _ from 'lodash';
2727
import React from 'react';
2828
import { useTranslation } from 'react-i18next';
29-
import { useParams } from 'react-router-dom';
29+
import { useLocation,useParams } from 'react-router-dom';
3030
import { KubeContainerStatus } from '../../lib/k8s/cluster';
3131
import Pod from '../../lib/k8s/pod';
3232
import { DefaultHeaderAction } from '../../redux/actionButtonsSlice';
@@ -490,6 +490,28 @@ export default function PodDetails(props: PodDetailsProps) {
490490
const { name = params.name, namespace = params.namespace, cluster } = props;
491491
const { t } = useTranslation('glossary');
492492
const dispatchHeadlampEvent = useEventCallback();
493+
//Check url params for logs:
494+
const location = useLocation();
495+
const query = new URLSearchParams(location.search);
496+
const autoLaunchView = query.get('view');
497+
//Only open log window once
498+
const hasAutoLaunched = React.useRef(false);
499+
const launchLogs = (item: Pod) => {
500+
Activity.launch({
501+
id: 'logs-' + item.metadata.uid,
502+
title: t('Logs') + ': ' + item.metadata.name,
503+
cluster: item.cluster,
504+
icon: <Icon icon="mdi:file-document-box-outline" width="100%" height="100%" />,
505+
location: 'full',
506+
content: <PodLogViewer noDialog open item={item} onClose={() => {}} />,
507+
});
508+
dispatchHeadlampEvent({
509+
type: HeadlampEventType.LOGS,
510+
data: {
511+
status: EventStatus.OPENED,
512+
},
513+
});
514+
};
493515

494516
function prepareExtraInfo(item: Pod | null) {
495517
let extraInfo: {
@@ -589,33 +611,23 @@ export default function PodDetails(props: PodDetailsProps) {
589611
namespace={namespace}
590612
cluster={cluster}
591613
withEvents
592-
actions={item =>
593-
item && [
614+
actions={item => {
615+
if (item && autoLaunchView === 'logs' && !hasAutoLaunched.current) {
616+
hasAutoLaunched.current = true;
617+
//Set Timeout is used to prevent rendering issues
618+
setTimeout(() => launchLogs(item), 0);
619+
}
620+
if (!item) return null;
621+
622+
return [
594623
{
595624
id: DefaultHeaderAction.POD_LOGS,
596625
action: (
597626
<AuthVisible item={item} authVerb="get" subresource="log">
598627
<ActionButton
599628
description={t('Show Logs')}
600629
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-
}}
630+
onClick={() => launchLogs(item)}
619631
/>
620632
</AuthVisible>
621633
),
@@ -678,8 +690,8 @@ export default function PodDetails(props: PodDetailsProps) {
678690
</AuthVisible>
679691
),
680692
},
681-
]
682-
}
693+
];
694+
}}
683695
extraInfo={item => prepareExtraInfo(item)}
684696
extraSections={item =>
685697
item && [

0 commit comments

Comments
 (0)