Keep autoscrolling even when a table is cleared

Summary:
The logs plugin had an inconsistency where you'd be tailing the logs, and then hit "Clear Logs", which would empty the screen, but as the page fills up again, it would stay in the current position and not scroll with the new ones coming in.

This makes it consistent by making the behaviour:
```
If not props.stickyBottom
    never autoscroll, e.g. for static tables of data
else
    if scrolled to the bottom
        autoscroll
    if all the rows fit into the screen at once
        autoscroll
```

Reviewed By: passy

Differential Revision: D15856813

fbshipit-source-id: 1357b0e39b576dbe69d260545b21fdab808d2bd2
This commit is contained in:
John Knox
2019-06-18 09:30:03 -07:00
committed by Facebook Github Bot
parent 447d88e935
commit 6bdaa6aff1

View File

@@ -258,6 +258,18 @@ class ManagedTable extends React.Component<
) {
this.scrollToHighlightedRows();
}
if (
this.props.stickyBottom &&
!this.state.shouldScrollToBottom &&
this.scrollRef &&
this.scrollRef.current &&
this.scrollRef.current.parentElement &&
this.scrollRef.current.parentElement instanceof HTMLElement &&
this.scrollRef.current.offsetHeight <=
this.scrollRef.current.parentElement.offsetHeight
) {
this.setState({shouldScrollToBottom: true});
}
this.firstUpdate = false;
}
@@ -569,12 +581,11 @@ class ManagedTable extends React.Component<
const parent = current ? current.parentElement : null;
if (
this.props.stickyBottom &&
scrollDirection === 'forward' &&
!this.state.shouldScrollToBottom &&
current &&
parent instanceof HTMLElement &&
current.offsetHeight - (scrollOffset + parent.offsetHeight) <
parent.offsetHeight
scrollDirection === 'forward' &&
!this.state.shouldScrollToBottom &&
current.offsetHeight - parent.offsetHeight === scrollOffset
) {
this.setState({shouldScrollToBottom: true});
} else if (