Skip to content

Commit c8d432e

Browse files
feat: display logs in steps detail (#401)
1 parent a83032e commit c8d432e

File tree

4 files changed

+96
-33
lines changed

4 files changed

+96
-33
lines changed

src/ui/components/lineage/Sidebar.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
fetchArtifactData,
1010
// fetchArtifactVisualizationSize,
1111
fetchStepData,
12-
// fetchStepLogs,
1312
} from '../../layouts/runs/RunDetail/sidebarServices';
1413
import styles from './index.module.scss';
1514
// import { runsActions } from '../../../redux/actions';
@@ -27,16 +26,13 @@ const Sidebar: React.FC<any> = ({ selectedNode }) => {
2726
const [isStepNode, setIsStepNode] = useState(true);
2827
const [artifact, setArtifact] = useState([] as any);
2928
const [step, setStep] = useState([] as any);
30-
const [logs] = useState([] as any);
3129
const sidebar_ref = useRef<HTMLInputElement>(null); //eslint-disable-line
3230
const authToken = useSelector(sessionSelectors.authenticationToken);
3331

3432
async function FetchData(type: boolean) {
3533
if (type) {
3634
const data = await fetchStepData(selectedNode, authToken);
37-
// const _logs = await fetchStepLogs(selectedNode, authToken);
3835
setStep(data);
39-
// setLogs(_logs);
4036
setFetching(false);
4137
} else {
4238
const data = await fetchArtifactData(selectedNode, authToken);
@@ -107,7 +103,7 @@ const Sidebar: React.FC<any> = ({ selectedNode }) => {
107103
</div>
108104
<div className={`${styles.bodyContainer}`}>
109105
{isStepNode ? (
110-
<StepnodeTabHeader node={step} logs={logs} fetching={fetching} />
106+
<StepnodeTabHeader node={step} fetching={fetching} />
111107
) : (
112108
<ArtifactTabHeader node={artifact} fetching={fetching} />
113109
)}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React, { useEffect, useRef, useState } from 'react';
2+
import styles from '../index.module.scss';
3+
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
4+
import { okaidia } from 'react-syntax-highlighter/dist/esm/styles/prism';
5+
import { fetchStepLogs } from '../../../layouts/runs/RunDetail/sidebarServices';
6+
import { useSelector } from 'react-redux';
7+
import { sessionSelectors } from '../../../../redux/selectors';
8+
import { FullWidthSpinner } from '../../spinners';
9+
10+
type DisplayLogsProps = { selectedNode: any };
11+
12+
const DisplayLogs = ({ selectedNode }: DisplayLogsProps) => {
13+
const divRef = useRef<HTMLDivElement>(null);
14+
const authToken = useSelector(sessionSelectors.authenticationToken);
15+
const [logs, setLogs] = useState('');
16+
const [fetching, setFetching] = useState(true);
17+
18+
async function fetchLogs(node: any) {
19+
const logs = await fetchStepLogs(node, authToken);
20+
setLogs(logs);
21+
setFetching(false);
22+
}
23+
24+
useEffect(() => {
25+
if (selectedNode === null) return;
26+
fetchLogs(selectedNode.id).then(() => {
27+
setFetching(false);
28+
});
29+
// eslint-disable-next-line react-hooks/exhaustive-deps
30+
}, []);
31+
32+
useEffect(() => {
33+
if (divRef.current) {
34+
const preElement = divRef.current.querySelector('pre');
35+
if (preElement) {
36+
preElement.scrollTop = preElement.scrollHeight;
37+
}
38+
}
39+
}, [fetching, logs]);
40+
41+
useEffect(() => {
42+
let pollingInterval: NodeJS.Timeout;
43+
if (selectedNode === null) return;
44+
if (!fetching) {
45+
pollingInterval = setInterval(() => {
46+
fetchLogs(selectedNode.id);
47+
}, 2000);
48+
}
49+
return () => clearInterval(pollingInterval);
50+
51+
// eslint-disable-next-line react-hooks/exhaustive-deps
52+
}, [fetching]);
53+
54+
return (
55+
<>
56+
{fetching ? (
57+
<div className={styles.FullWidthSpinnerContainer}>
58+
<FullWidthSpinner color="black" size="md" />
59+
<p style={{ fontFamily: 'Rubik', fontSize: '14px' }}>
60+
Loading Logs, please wait...
61+
</p>
62+
</div>
63+
) : (
64+
<div ref={divRef} className={styles.codeContainer}>
65+
<SyntaxHighlighter
66+
customStyle={{ width: '100%', height: '80%', fontSize: 16 }}
67+
wrapLines={true}
68+
language="text"
69+
style={okaidia}
70+
>
71+
{logs ? logs : 'No Logs Avaialable'}
72+
</SyntaxHighlighter>
73+
</div>
74+
)}
75+
</>
76+
);
77+
};
78+
79+
export default DisplayLogs;

src/ui/components/lineage/sidebarTabsSwitchers/stepTabSwitcher.tsx

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import styles from '../index.module.scss';
66
import stepStyles from './artifact.module.scss';
77
import { FullWidthSpinner } from '../../spinners';
88
import { formatDateToDisplayOnTable } from '../../../../utils';
9+
import DisplayLogs from './DisplayLogs';
910

1011
const stylesActive = {
1112
opacity: 1,
@@ -19,10 +20,6 @@ const stylesInActive = {
1920
};
2021

2122
const tabs = [
22-
// {
23-
// title: 'Logs',
24-
// case: '__LOG',
25-
// },
2623
{
2724
title: 'Attributes',
2825
case: '__ATTRIBUTE',
@@ -31,6 +28,10 @@ const tabs = [
3128
title: 'Code',
3229
case: '__CODE',
3330
},
31+
{
32+
title: 'Logs',
33+
case: '__LOG',
34+
},
3435
];
3536

3637
// const TextInput: React.FC<any> = ({ label, value }) => {
@@ -74,7 +75,7 @@ const tabs = [
7475
// );
7576
// };
7677

77-
const StepnodeTabHeader: React.FC<any> = ({ node, logs, fetching }) => {
78+
const StepnodeTabHeader: React.FC<any> = ({ node, fetching }) => {
7879
const [show, setShow] = useState('__ATTRIBUTE');
7980
const [dynamicWidth, setDynamicWidth] = useState<number | undefined>(79);
8081
const [dynamicLeft, setDynamicLeft] = useState<number | undefined>(21);
@@ -138,7 +139,10 @@ const StepnodeTabHeader: React.FC<any> = ({ node, logs, fetching }) => {
138139
></div>
139140

140141
{fetching ? (
141-
<div className={`${styles.FullWidthSpinnerContainer}`}>
142+
<div
143+
style={{ minHeight: '100%' }}
144+
className={`${styles.FullWidthSpinnerContainer}`}
145+
>
142146
<FullWidthSpinner color="black" size="md" />
143147
<p style={{ fontFamily: 'Rubik', fontSize: '14px' }}>
144148
Loading Step. Please wait
@@ -399,20 +403,7 @@ const StepnodeTabHeader: React.FC<any> = ({ node, logs, fetching }) => {
399403
) : (
400404
''
401405
)}
402-
{/* {show === '__LOG' ? (
403-
<div className={styles.codeContainer}>
404-
<SyntaxHighlighter
405-
customStyle={{ width: '100%', height: '80%', fontSize: 16 }}
406-
wrapLines={true}
407-
language="python"
408-
style={okaidia}
409-
>
410-
{logs ? logs : 'No Logs Avaialable'}
411-
</SyntaxHighlighter>
412-
</div>
413-
) : (
414-
''
415-
)} */}
406+
{show === '__LOG' ? <DisplayLogs selectedNode={node} /> : ''}
416407
</>
417408
)}
418409
</>

src/ui/layouts/runs/RunDetail/sidebarServices.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ export const fetchStepData = async (selectedNode: any, authToken: any) => {
2020
return data;
2121
};
2222

23-
export const fetchStepLogs = async (selectedNode: any, authToken: any) => {
23+
export const fetchStepLogs = async (id: string, authToken: any) => {
2424
const logs = axios
25-
.get(
26-
`${process.env.REACT_APP_BASE_API_URL}/steps/${selectedNode.execution_id}/logs`,
27-
{
28-
headers: {
29-
Authorization: `bearer ${authToken}`,
30-
},
25+
.get(`${process.env.REACT_APP_BASE_API_URL}/steps/${id}/logs`, {
26+
headers: {
27+
Authorization: `bearer ${authToken}`,
3128
},
32-
)
29+
})
3330
.then((response) => {
3431
return response?.data;
3532
})

0 commit comments

Comments
 (0)