Merge pull request #4215 from influxdata/enhancements/refactor-tablegraph

Ensure that scrolling does not go out of bounds for table graph
pull/4219/head
Brandon Farmer 2018-08-14 11:25:56 -07:00 committed by GitHub
commit 60f0ac7582
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 4 deletions

View File

@ -29,6 +29,7 @@ export interface PropsMultiGrid {
}
interface State {
scrollToRow: number
scrollLeft: number
scrollTop: number
scrollbarSize: number
@ -53,15 +54,22 @@ class MultiGrid extends React.PureComponent<PropsMultiGrid, State> {
}
public static getDerivedStateFromProps(nextProps: PropsMultiGrid) {
const {scrollToRow} = nextProps
const {scrollToRow, rowCount, height} = nextProps
const scrollTop = scrollToRow * ROW_HEIGHT
const maxScrollTop = (rowCount + 1) * ROW_HEIGHT - (height + ROW_HEIGHT)
const maxRow = rowCount - Math.floor(height / ROW_HEIGHT) / 2
if (scrollTop < 0) {
if (scrollTop <= 0) {
return null
}
if (scrollTop > maxScrollTop || scrollToRow > maxRow) {
return null
}
return {
scrollTop,
scrollToRow,
scrollTop: scrollTop - height / 2,
}
}
@ -81,6 +89,7 @@ class MultiGrid extends React.PureComponent<PropsMultiGrid, State> {
super(props, context)
this.state = {
scrollToRow: props.scrollToRow,
scrollLeft: 0,
scrollTop: 0,
scrollbarSize: 0,
@ -267,6 +276,7 @@ class MultiGrid extends React.PureComponent<PropsMultiGrid, State> {
private renderBottomLeftGrid(props) {
const {fixedColumnCount, fixedRowCount, rowCount, columnWidth} = props
const {scrollToRow} = this.state
if (!fixedColumnCount) {
return null
@ -289,6 +299,7 @@ class MultiGrid extends React.PureComponent<PropsMultiGrid, State> {
>
<Grid
{...props}
scrollToRow={scrollToRow}
cellRenderer={this.cellRendererBottomLeftGrid}
className={this.props.classNameBottomLeftGrid}
columnCount={fixedColumnCount}
@ -317,11 +328,12 @@ class MultiGrid extends React.PureComponent<PropsMultiGrid, State> {
fixedColumnCount,
fixedRowCount,
rowCount,
scrollToRow,
scrollLeft,
scrollTop,
} = props
const {scrollToRow} = this.state
const calculatedRowCount = Math.max(0, rowCount - fixedRowCount)
const leftWidth = this.getLeftGridWidth(props)