Skip to content

Commit

Permalink
perf: TableGraphTable: tweak rendering internal state
Browse files Browse the repository at this point in the history
fields that are often re-updated but rarely change value were moved out of react state
and into internal component state. changing these values won't force re-renders.
  • Loading branch information
hoorayimhelping committed Apr 1, 2020
1 parent 0070350 commit e21e44c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
1. [17384](https://github.com/influxdata/influxdb/pull/17384): Reuse slices built by iterator to reduce allocations
1. [17404](https://github.com/influxdata/influxdb/pull/17404): Updated duplicate check error message to be more explicit and actionable
1. [17515](https://github.com/influxdata/influxdb/pull/17515): Editing a table cell shows the proper values and respects changes
1. [17521](https://github.com/influxdata/influxdb/pull/17521): Table view scrolling should be slightly smoother

### UI Improvements

Expand Down
36 changes: 19 additions & 17 deletions ui/src/shared/components/tables/TableGraphTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ type Props = OwnProps & InjectedHoverProps

interface State {
timeColumnWidth: number
hoveredColumnIndex: number
hoveredRowIndex: number
totalColumnWidths: number
shouldResize: boolean
}
Expand All @@ -69,13 +67,21 @@ class TableGraphTable extends PureComponent<Props, State> {
timeColumnWidth: 0,
shouldResize: false,
totalColumnWidths: 0,
hoveredRowIndex: NULL_ARRAY_INDEX,
hoveredColumnIndex: NULL_ARRAY_INDEX,
}

protected hoveredColumnIndex: number
protected hoveredRowIndex: number

private gridContainer: HTMLDivElement
private multiGrid?: MultiGrid

constructor(props) {
super(props)

this.hoveredRowIndex = NULL_ARRAY_INDEX
this.hoveredColumnIndex = NULL_ARRAY_INDEX
}

public componentDidUpdate() {
if (this.state.shouldResize) {
if (this.multiGrid) {
Expand Down Expand Up @@ -217,9 +223,8 @@ class TableGraphTable extends PureComponent<Props, State> {
const {
transformedDataBundle: {sortedTimeVals},
} = this.props
const {hoveredColumnIndex} = this.state
const {hoverTime} = this.props
const hoveringThisTable = hoveredColumnIndex !== NULL_ARRAY_INDEX
const hoveringThisTable = this.hoveredColumnIndex !== NULL_ARRAY_INDEX

if (!hoverTime || hoveringThisTable || !this.isTimeVisible) {
return {scrollToColumn: 0, scrollToRow: -1}
Expand Down Expand Up @@ -266,10 +271,9 @@ class TableGraphTable extends PureComponent<Props, State> {

onSetHoverTime(new Date(hoverTime).valueOf())
}
this.setState({
hoveredColumnIndex: +dataset.columnIndex,
hoveredRowIndex: +dataset.rowIndex,
})

this.hoveredColumnIndex = +dataset.columnIndex
this.hoveredRowIndex = +dataset.rowIndex
}

private handleMouseLeave = (): void => {
Expand All @@ -278,10 +282,9 @@ class TableGraphTable extends PureComponent<Props, State> {
if (onSetHoverTime) {
onSetHoverTime(0)
}
this.setState({
hoveredColumnIndex: NULL_ARRAY_INDEX,
hoveredRowIndex: NULL_ARRAY_INDEX,
})

this.hoveredColumnIndex = NULL_ARRAY_INDEX
this.hoveredRowIndex = NULL_ARRAY_INDEX
}

private calculateColumnWidth = (columnSizerWidth: number) => (column: {
Expand Down Expand Up @@ -361,9 +364,8 @@ class TableGraphTable extends PureComponent<Props, State> {
onSort,
properties,
} = this.props
const {hoveredRowIndex, hoveredColumnIndex} = this.state
const {scrollToRow} = this.scrollToColRow
const hoverIndex = scrollToRow >= 0 ? scrollToRow : hoveredRowIndex
const hoverIndex = scrollToRow >= 0 ? scrollToRow : this.hoveredRowIndex

return (
<TableCell
Expand All @@ -376,7 +378,7 @@ class TableGraphTable extends PureComponent<Props, State> {
hoveredRowIndex={hoverIndex}
properties={properties}
resolvedFieldOptions={resolvedFieldOptions}
hoveredColumnIndex={hoveredColumnIndex}
hoveredColumnIndex={this.hoveredColumnIndex}
isFirstColumnFixed={this.fixFirstColumn}
isVerticalTimeAxis={this.isVerticalTimeAxis}
onClickFieldName={onSort}
Expand Down

0 comments on commit e21e44c

Please sign in to comment.