Skip to content

Commit 6e59afb

Browse files
authored
Merge pull request #4399 from mudit06mah/logDeepLink
Frontend: Pod: Added Deeplink compatibility for viewing logs
2 parents f57da2b + dc7e7e4 commit 6e59afb

26 files changed

+60
-44
lines changed

frontend/src/components/pod/Details.tsx

Lines changed: 47 additions & 19 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';
@@ -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
),

frontend/src/components/project/ProjectResourcesTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export function ProjectResourcesTab({
333333
const id = 'logs-' + resource.metadata.uid;
334334
Activity.launch({
335335
id,
336-
title: t('Logs') + ': ' + resource.metadata.name,
336+
title: t('Logs: {{ itemName }}', { itemName: resource.metadata.name }),
337337
cluster: resource.cluster,
338338
icon: (
339339
<Icon icon="mdi:file-document-box-outline" width="100%" height="100%" />

frontend/src/i18n/locales/de/glossary.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
"QoS Class": "QoS-Klasse",
163163
"Priority": "Priorität",
164164
"Show Logs": "Ereignisprotokolle anzeigen",
165-
"Logs": "",
166165
"Terminal / Exec": "Terminal / Befehl ausführen",
167166
"Attach": "Anhängen",
168167
"Restarts": "Neustarts",

frontend/src/i18n/locales/de/translation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@
616616
"Create Project": "",
617617
"Details": "",
618618
"Show Logs": "",
619-
"Logs": "",
619+
"Logs: {{ itemName }}": "",
620620
"Terminal / Exec": "",
621621
"No {{category}} resources found for this project.": "",
622622
"Current//context:replicas": "Aktuell",

frontend/src/i18n/locales/en/glossary.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
"QoS Class": "QoS Class",
163163
"Priority": "Priority",
164164
"Show Logs": "Show Logs",
165-
"Logs": "Logs",
166165
"Terminal / Exec": "Terminal / Exec",
167166
"Attach": "Attach",
168167
"Restarts": "Restarts",

frontend/src/i18n/locales/en/translation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@
616616
"Create Project": "Create Project",
617617
"Details": "Details",
618618
"Show Logs": "Show Logs",
619-
"Logs": "Logs",
619+
"Logs: {{ itemName }}": "Logs: {{ itemName }}",
620620
"Terminal / Exec": "Terminal / Exec",
621621
"No {{category}} resources found for this project.": "No {{category}} resources found for this project.",
622622
"Current//context:replicas": "Current",

frontend/src/i18n/locales/es/glossary.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
"QoS Class": "Clase QoS",
163163
"Priority": "Prioridad",
164164
"Show Logs": "Mostrar Registros",
165-
"Logs": "",
166165
"Terminal / Exec": "Terminal / Exec",
167166
"Attach": "Adjuntar",
168167
"Restarts": "Reinicios",

frontend/src/i18n/locales/es/translation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@
620620
"Create Project": "",
621621
"Details": "",
622622
"Show Logs": "",
623-
"Logs": "",
623+
"Logs: {{ itemName }}": "",
624624
"Terminal / Exec": "",
625625
"No {{category}} resources found for this project.": "",
626626
"Current//context:replicas": "Actuales",

frontend/src/i18n/locales/fr/glossary.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
"QoS Class": "Classe QoS",
163163
"Priority": "Priorité",
164164
"Show Logs": "Afficher les journaux",
165-
"Logs": "",
166165
"Terminal / Exec": "Terminal / Exécution",
167166
"Attach": "Attacher",
168167
"Restarts": "Redémarrages",

frontend/src/i18n/locales/fr/translation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@
620620
"Create Project": "",
621621
"Details": "",
622622
"Show Logs": "",
623-
"Logs": "",
623+
"Logs: {{ itemName }}": "",
624624
"Terminal / Exec": "",
625625
"No {{category}} resources found for this project.": "",
626626
"Current//context:replicas": "Actuels",

0 commit comments

Comments
 (0)