diff --git a/ui/src/ifql/components/TimeMachineTable.tsx b/ui/src/ifql/components/TimeMachineTable.tsx index f1ae32280..cde6f0d19 100644 --- a/ui/src/ifql/components/TimeMachineTable.tsx +++ b/ui/src/ifql/components/TimeMachineTable.tsx @@ -1,4 +1,4 @@ -import React, {PureComponent} from 'react' +import React, {PureComponent, CSSProperties} from 'react' import _ from 'lodash' import {Grid, GridCellProps, AutoSizer, ColumnSizer} from 'react-virtualized' @@ -6,13 +6,55 @@ import {ErrorHandling} from 'src/shared/decorators/errors' import {ScriptResult} from 'src/types' import {vis} from 'src/ifql/constants' +const NUM_FIXED_ROWS = 1 + +interface State { + scrollLeft: number +} + @ErrorHandling -export default class TimeMachineTable extends PureComponent { +export default class TimeMachineTable extends PureComponent< + ScriptResult, + State +> { + constructor(props) { + super(props) + this.state = { + scrollLeft: 0, + } + } + public render() { const {data} = this.props + const {scrollLeft} = this.state return (
+ + {({width}) => ( + + {({adjustedWidth, getColumnWidth}) => ( + + )} + + )} + {({height, width}) => ( { {({adjustedWidth, getColumnWidth}) => ( )} @@ -39,10 +83,45 @@ export default class TimeMachineTable extends PureComponent { ) } + private get headerStyle(): CSSProperties { + // cannot use overflow: hidden overflow-x / overflow-y gets overridden by react-virtualized + return {overflowX: 'hidden', overflowY: 'hidden'} + } + + private get tableStyle(): CSSProperties { + return {marginTop: `${this.headerOffset}px`} + } + private get columnCount(): number { return _.get(this.props.data, '0', []).length } + private get headerOffset(): number { + return NUM_FIXED_ROWS * vis.TABLE_ROW_HEIGHT + } + + private handleScroll = ({scrollLeft}): void => { + this.setState({scrollLeft}) + } + + private headerCellRenderer = ({ + columnIndex, + key, + style, + }: GridCellProps): React.ReactNode => { + const {data} = this.props + + return ( +
+ {data[0][columnIndex]} +
+ ) + } + private cellRenderer = ({ columnIndex, key, @@ -50,15 +129,10 @@ export default class TimeMachineTable extends PureComponent { style, }: GridCellProps): React.ReactNode => { const {data} = this.props - const headerRowClass = !rowIndex ? 'table-graph-cell__fixed-row' : '' return ( -
- {data[rowIndex][columnIndex]} +
+ {data[rowIndex + NUM_FIXED_ROWS][columnIndex]}
) } diff --git a/ui/src/ifql/components/TimeMachineVis.tsx b/ui/src/ifql/components/TimeMachineVis.tsx index 594afeb69..5f58e9a29 100644 --- a/ui/src/ifql/components/TimeMachineVis.tsx +++ b/ui/src/ifql/components/TimeMachineVis.tsx @@ -24,7 +24,7 @@ class TimeMachineVis extends PureComponent { this.state = {selectedResultID: this.initialResultID} } - public componentDidUpdate(__, prevState) { + public componentDidUpdate() { if (!this.selectedResult) { this.setState({selectedResultID: this.initialResultID}) }