Skip to content

Commit 114673f

Browse files
AlanGreenetekton-robot
authored andcommitted
Remove legacy auto-scroll code
Remove the dormant step log auto-scroll code leftover from the recently removed legacy design. Also remove the related scroll button code that has been replaced by the global scroll buttons since v0.65.
1 parent aae92bd commit 114673f

4 files changed

Lines changed: 3 additions & 212 deletions

File tree

packages/components/src/components/Log/Log.jsx

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ limitations under the License.
1212
*/
1313
/* istanbul ignore file */
1414

15-
import { Component, createRef } from 'react';
15+
import { Component } from 'react';
1616
import { PrefixContext, SkeletonText } from '@carbon/react';
1717
import { FixedSizeList as List } from 'react-window';
1818
import { injectIntl, useIntl } from 'react-intl';
1919
import { getStepStatusReason, isRunning } from '@tektoncd/dashboard-utils';
2020
import { Information } from '@carbon/react/icons';
2121

22-
import {
23-
hasElementPositiveVerticalScrollBottom,
24-
isElementEndBelowViewBottom
25-
} from './domUtils';
2622
import DotSpinner from '../DotSpinner';
2723
import LogFormat from '../LogFormat';
2824

@@ -81,34 +77,13 @@ export class LogContainer extends Component {
8177
constructor(props) {
8278
super(props);
8379
this.state = { groupsExpanded: {}, loading: true, logs: [] };
84-
this.logRef = createRef();
85-
this.textRef = createRef();
8680
}
8781

8882
componentDidMount() {
8983
this.loadLog();
90-
if (this.props.enableLogAutoScroll) {
91-
this.wasRunningAfterMounting();
92-
window.addEventListener('scroll', this.handleLogScroll, true);
93-
this.handleLogScroll();
94-
}
95-
}
96-
97-
componentDidUpdate(prevProps, prevState) {
98-
if (
99-
this.props.enableLogAutoScroll &&
100-
prevState.logs?.length !== this.state.logs?.length
101-
) {
102-
if (this.shouldAutoScroll()) {
103-
this.scrollToBottomLog();
104-
return;
105-
}
106-
this.handleLogScroll();
107-
}
10884
}
10985

11086
componentWillUnmount() {
111-
window.removeEventListener('scroll', this.handleLogScroll, true);
11287
clearTimeout(this.timer);
11388
this.cancelled = true;
11489
}
@@ -122,45 +97,6 @@ export class LogContainer extends Component {
12297
}));
12398
};
12499

125-
handleLogScroll = () => {
126-
if (!this.state.loading) {
127-
const isLogBottomUnseen = this.isLogBottomUnseen();
128-
if (isLogBottomUnseen !== this.state.isLogBottomUnseen) {
129-
this.setState({
130-
isLogBottomUnseen
131-
});
132-
}
133-
}
134-
};
135-
136-
shouldAutoScroll = () => {
137-
return (
138-
this.props.enableLogAutoScroll &&
139-
this.state.isLogBottomUnseen === false &&
140-
this.wasRunningAfterMounting() &&
141-
this.isLogBottomUnseen()
142-
);
143-
};
144-
145-
isLogBottomUnseen = () => {
146-
return (
147-
isElementEndBelowViewBottom(this.logRef?.current) ||
148-
hasElementPositiveVerticalScrollBottom(
149-
this.textRef?.current?.firstElementChild
150-
)
151-
);
152-
};
153-
154-
scrollToBottomLog = () => {
155-
const longTextElement = this.textRef?.current?.firstElementChild;
156-
if (longTextElement) {
157-
longTextElement.scrollTop =
158-
longTextElement.scrollHeight - longTextElement.clientHeight;
159-
}
160-
const rootElement = document.documentElement;
161-
rootElement.scrollTop = rootElement.scrollHeight - rootElement.clientHeight;
162-
};
163-
164100
wasRunningAfterMounting = () => {
165101
if (this.alreadyWasRunningAfterMounting) {
166102
return true;
@@ -497,15 +433,13 @@ export class LogContainer extends Component {
497433
const { toolbar } = this.props;
498434
const { loading } = this.state;
499435
return (
500-
<pre className="tkn--log tkn--theme-dark" ref={this.logRef}>
436+
<pre className="tkn--log tkn--theme-dark">
501437
{loading ? (
502438
<SkeletonText paragraph width="60%" />
503439
) : (
504440
<>
505441
{toolbar}
506-
<div className="tkn--log-container" ref={this.textRef}>
507-
{this.getLogList()}
508-
</div>
442+
<div className="tkn--log-container">{this.getLogList()}</div>
509443
{this.logTrailer()}
510444
</>
511445
)}

packages/components/src/components/Log/Log.test.jsx

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -114,98 +114,6 @@ describe('Log', () => {
114114
await waitFor(() => getByText('Line 1'));
115115
});
116116

117-
it('auto-scrolls down, for a running step, when new logs are added and the Log component bottom is below the viewport', async () => {
118-
const medium = Array.from(
119-
{ length: 199 },
120-
(_v, i) => `Line ${i + 2}\n`
121-
).join('');
122-
vi.spyOn(Element.prototype, 'getBoundingClientRect')
123-
.mockReturnValue({ bottom: 2500 })
124-
.mockReturnValueOnce({ bottom: 0 });
125-
const spiedFn = vi.spyOn(Element.prototype, 'scrollTop', 'set'); // the scrollTop value is changed in scrollToBottomLog
126-
127-
const { rerender } = render(
128-
<Log
129-
stepStatus={{ running: true }}
130-
enableLogAutoScroll
131-
pollingInterval={100}
132-
fetchLogs={() => 'Line 1'}
133-
/>
134-
);
135-
rerender(
136-
<Log
137-
stepStatus={{ running: true }}
138-
enableLogAutoScroll
139-
pollingInterval={100}
140-
fetchLogs={() => `Line1\n${medium}`}
141-
/>
142-
);
143-
await waitFor(() => expect(spiedFn).toHaveBeenCalled());
144-
});
145-
146-
it('auto-scrolls down, for a running step, when new logs are added and the Log component is scrollable', async () => {
147-
const long = Array.from(
148-
{ length: 19999 },
149-
(_v, i) => `Line ${i + 1}\n`
150-
).join('');
151-
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockReturnValue({
152-
bottom: 0
153-
});
154-
vi.spyOn(Element.prototype, 'scrollTop', 'get')
155-
.mockReturnValue(-1) // to ensure el.scrollHeight - el.clientHeight > el.scrollTop i.e. 0 - 0 > -1
156-
.mockReturnValueOnce(0);
157-
const spiedFn = vi.spyOn(Element.prototype, 'scrollTop', 'set'); // the scrollTop value is changed in scrollToBottomLog
158-
159-
const { rerender } = render(
160-
<Log
161-
stepStatus={{ running: true }}
162-
enableLogAutoScroll
163-
pollingInterval={100}
164-
fetchLogs={() => long}
165-
/>
166-
);
167-
rerender(
168-
<Log
169-
stepStatus={{ running: true }}
170-
enableLogAutoScroll
171-
pollingInterval={100}
172-
fetchLogs={() => `${long}\nLine 20000`}
173-
/>
174-
);
175-
await waitFor(() => expect(spiedFn).toHaveBeenCalled());
176-
});
177-
178-
it('does not auto-scroll down when the step was never running after the component mounting', async () => {
179-
const long = Array.from(
180-
{ length: 19999 },
181-
(_v, i) => `Line ${i + 1}\n`
182-
).join('');
183-
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockReturnValue({
184-
bottom: 0
185-
});
186-
vi.spyOn(Element.prototype, 'scrollTop', 'get')
187-
.mockReturnValue(-1) // to ensure el.scrollHeight - el.clientHeight > el.scrollTop i.e. 0 - 0 > -1
188-
.mockReturnValueOnce(0);
189-
const spiedFn = vi.spyOn(Element.prototype, 'scrollTop', 'set'); // the scrollTop value is changed in scrollToBottomLog
190-
191-
const { rerender } = render(
192-
<Log
193-
stepStatus={{ terminated: { reason: 'Completed' } }}
194-
enableLogAutoScroll
195-
pollingInterval={100}
196-
fetchLogs={() => long}
197-
/>
198-
);
199-
rerender(
200-
<Log
201-
stepStatus={{ terminated: { reason: 'Completed' } }}
202-
enableLogAutoScroll
203-
pollingInterval={100}
204-
fetchLogs={() => `${long}\nLine 20000`}
205-
/>
206-
);
207-
await waitFor(() => expect(spiedFn).not.toHaveBeenCalled());
208-
});
209117
it('renders the provided content when streaming logs', async () => {
210118
const { getByText } = render(
211119
<Log

packages/components/src/components/Log/domUtils.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

packages/components/src/components/PipelineRun/PipelineRun.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export default /* istanbul ignore next */ function PipelineRun({
4040
description,
4141
displayRunHeader,
4242
duration,
43-
enableLogAutoScroll,
44-
enableLogScrollButtons,
4543
error,
4644
fetchLogs,
4745
forceLogPolling,
@@ -109,8 +107,6 @@ export default /* istanbul ignore next */ function PipelineRun({
109107

110108
return (
111109
<Log
112-
enableLogAutoScroll={enableLogAutoScroll}
113-
enableLogScrollButtons={enableLogScrollButtons}
114110
fetchLogs={() => fetchLogs({ stepName, stepStatus, taskRun })}
115111
forcePolling={forceLogPolling}
116112
isSidecar={isSidecar}

0 commit comments

Comments
 (0)