Skip to content

Commit

Permalink
feat(xod-client): autoscroll deployment log to the bottom when resizi…
Browse files Browse the repository at this point in the history
…ng done
  • Loading branch information
brusherru committed Dec 28, 2020
1 parent ed58224 commit c710372
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/xod-client/src/debugger/containers/Log.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Log extends React.PureComponent {
this.autoscrollRef = null;

this.onFollowLog = this.onFollowLog.bind(this);
this.onFollowLogClicked = this.onFollowLogClicked.bind(this);
this.scrollToBottom = this.scrollToBottom.bind(this);
}

Expand All @@ -31,8 +32,16 @@ class Log extends React.PureComponent {
}, 0);
}

componentDidUpdate() {
if (this.props.log.length === 0) {
componentDidUpdate(prevProps) {
// To trigger scroll to the bottom and follow log
// after resizing the parents component we're checking for
// change of `doNotSkipLines` property from `true` to `false`
const skipLinesJustTurnedOn =
prevProps.doNotSkipLines && !this.props.doNotSkipLines;
if (
this.props.log.length === 0 ||
(skipLinesJustTurnedOn && !this.props.isSkippingNewSerialLogLines)
) {
this.onFollowLog(false);
}
}
Expand All @@ -42,6 +51,10 @@ class Log extends React.PureComponent {
this.props.stopSkippingNewLogLines(addSkipMessage);
}

onFollowLogClicked(_event) {
this.onFollowLog(true);
}

scrollToBottom() {
if (this.autoscrollRef) {
this.autoscrollRef.scrollDown();
Expand Down Expand Up @@ -74,7 +87,10 @@ class Log extends React.PureComponent {
{R.isEmpty(error) ? null : <div className="error">{error}</div>}
{isSkipOnScrollEnabled && isSkippingNewSerialLogLines ? (
<div className="skipped">
<button className="Button Button--small" onClick={this.onFollowLog}>
<button
className="Button Button--small"
onClick={this.onFollowLogClicked}
>
Follow log ({numberOfSkippedSerialLogLines} new lines skipped)
</button>
</div>
Expand Down

0 comments on commit c710372

Please sign in to comment.