Skip to content

Commit 8d6eedb

Browse files
stuartrowetimja
andauthored
Improve the height calculation of the ConsoleLogStream component (#371)
Co-authored-by: Tim Jacomb <[email protected]>
1 parent db73d64 commit 8d6eedb

File tree

4 files changed

+58
-37
lines changed

4 files changed

+58
-37
lines changed
Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
11
import React from "react";
2-
2+
import { useEffect, useRef } from "react";
33
import { makeReactChildren, tokenizeANSIString } from "./Ansi";
44

55
export interface ConsoleLineProps {
66
lineNumber: string;
77
content: string;
88
stepId: string;
99
startByte: number;
10+
heightCallback: (height: number) => void;
1011
}
1112

1213
// Console output line
13-
export const ConsoleLine = (props: ConsoleLineProps) => (
14-
<pre
15-
className="console-output-line"
16-
key={`console-line-pre${props.lineNumber}`}
17-
>
18-
<div
19-
className="console-output-line-anchor"
20-
id={`log-${props.lineNumber}`}
21-
key={`${props.lineNumber}-anchor`}
22-
/>
23-
<div className="console-output-line" key={`${props.lineNumber}-body`}>
24-
<a
25-
className="console-line-number"
26-
href={`?start-byte=${props.startByte}&selected-node=${props.stepId}#log-${props.lineNumber}`} //`}
14+
export const ConsoleLine = (props: ConsoleLineProps) => {
15+
const ref = useRef<HTMLDivElement>(null);
16+
useEffect(() => {
17+
const height = ref.current ? ref.current.getBoundingClientRect().height : 0;
18+
props.heightCallback(height);
19+
}, []);
20+
21+
return (
22+
<pre
23+
className="console-output-line"
24+
key={`console-line-pre${props.lineNumber}`}
25+
>
26+
<div
27+
className="console-output-line-anchor"
28+
id={`log-${props.lineNumber}`}
29+
key={`${props.lineNumber}-anchor`}
30+
/>
31+
<div
32+
className="console-output-line"
33+
key={`${props.lineNumber}-body`}
34+
ref={ref}
2735
>
28-
{props.lineNumber}
29-
</a>
30-
<div className="console-text">
31-
{makeReactChildren(
32-
tokenizeANSIString(props.content),
33-
`${props.stepId}-${props.lineNumber}`
34-
)}
36+
<a
37+
className="console-line-number"
38+
href={`?start-byte=${props.startByte}&selected-node=${props.stepId}#log-${props.lineNumber}`} //`}
39+
>
40+
{props.lineNumber}
41+
</a>
42+
<div className="console-text">
43+
{makeReactChildren(
44+
tokenizeANSIString(props.content),
45+
`${props.stepId}-${props.lineNumber}`
46+
)}
47+
</div>
3548
</div>
36-
</div>
37-
</pre>
38-
);
49+
</pre>
50+
);
51+
};

src/main/frontend/pipeline-console-view/pipeline-console/main/ConsoleLogCard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ export class ConsoleLogCard extends React.Component<
276276
logBuffer={this.props.stepBuffer}
277277
handleMoreConsoleClick={this.props.handleMoreConsoleClick}
278278
step={this.props.step}
279+
maxHeightScale={0.85}
279280
open={this.state.open}
280281
setClose={handleClose}
281282
/>
@@ -295,6 +296,7 @@ export class ConsoleLogCard extends React.Component<
295296
logBuffer={this.props.stepBuffer}
296297
handleMoreConsoleClick={this.props.handleMoreConsoleClick}
297298
step={this.props.step}
299+
maxHeightScale={0.65}
298300
/>
299301
</Suspense>
300302
</CardContent>

src/main/frontend/pipeline-console-view/pipeline-console/main/ConsoleLogModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface ConsoleLogModelProps {
77
logBuffer: StepLogBufferInfo;
88
handleMoreConsoleClick: (nodeId: string, startByte: number) => void;
99
step: StepInfo;
10-
10+
maxHeightScale: number;
1111
setClose: () => void;
1212
open: boolean;
1313
}

src/main/frontend/pipeline-console-view/pipeline-console/main/ConsoleLogStream.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { Virtuoso, VirtuosoHandle, LogLevel } from "react-virtuoso";
3-
import { useState, useEffect, useRef } from "react";
3+
import { useCallback, useState, useEffect, useRef } from "react";
44
import { Result, StepInfo, StepLogBufferInfo } from "./PipelineConsoleModel";
55

66
import Button from "@mui/material/Button";
@@ -9,6 +9,7 @@ export interface ConsoleLogStreamProps {
99
logBuffer: StepLogBufferInfo;
1010
handleMoreConsoleClick: (nodeId: string, startByte: number) => void;
1111
step: StepInfo;
12+
maxHeightScale: number;
1213
}
1314

1415
import { ConsoleLine } from "./ConsoleLine";
@@ -20,6 +21,7 @@ export default function ConsoleLogStream(props: ConsoleLogStreamProps) {
2021
const [moveToBottom, setMoveToBottom] = useState(true);
2122
const showButtonInterval = useRef<NodeJS.Timeout | null>(null);
2223
const [showButton, setShowButton] = useState(false);
24+
const [maxConsoleLineHeight, setMaxConsoleLineHeight] = useState(1);
2325

2426
useEffect(() => {
2527
return () => {
@@ -50,6 +52,14 @@ export default function ConsoleLogStream(props: ConsoleLogStreamProps) {
5052
}
5153
}, [moveToBottom]);
5254

55+
const consoleLineHeightCallback = useCallback((height: number) => {
56+
if (height > maxConsoleLineHeight) {
57+
setMaxConsoleLineHeight(height);
58+
} else if (maxConsoleLineHeight == 1) {
59+
setMaxConsoleLineHeight(height);
60+
}
61+
}, []);
62+
5363
const scrollListBottom = () => {
5464
if (virtuosoRef.current) {
5565
if (props.logBuffer.lines) {
@@ -70,22 +80,17 @@ export default function ConsoleLogStream(props: ConsoleLogStreamProps) {
7080
return props.step.state === Result.running || props.logBuffer.startByte < 0;
7181
};
7282

73-
const minHeight = () => {
74-
const numberOfLines = props.logBuffer.lines.length;
75-
76-
if (numberOfLines > 200) {
77-
return 60;
78-
}
79-
80-
return numberOfLines * 3;
83+
const height = () => {
84+
const spinnerLines = shouldRequestMoreLogs() ? 2 : 0;
85+
return (props.logBuffer.lines.length + spinnerLines) * maxConsoleLineHeight;
8186
};
8287

8388
return (
8489
<>
8590
<Virtuoso
8691
style={{
87-
minHeight: `${minHeight()}vh`,
88-
maxHeight: window.innerHeight / 2,
92+
height: `${height()}px`,
93+
maxHeight: window.innerHeight * props.maxHeightScale,
8994
}}
9095
ref={virtuosoRef}
9196
data={props.logBuffer.lines}
@@ -109,6 +114,7 @@ export default function ConsoleLogStream(props: ConsoleLogStreamProps) {
109114
content={content}
110115
stepId={props.step.id}
111116
startByte={props.logBuffer.startByte}
117+
heightCallback={consoleLineHeightCallback}
112118
/>
113119
);
114120
}}

0 commit comments

Comments
 (0)