Merge pull request #4379 from influxdata/fix/table-update

Properly update tablegraph when in editor
pull/4381/head
Iris Scholten 2018-09-06 15:28:28 -07:00 committed by GitHub
commit 456eb08c3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -76,11 +76,12 @@ class RefreshingGraph extends PureComponent<Props> {
private timeSeries: React.RefObject<TimeSeries> = React.createRef()
public componentDidUpdate() {
public componentDidUpdate(prevProps) {
if (!this.timeSeries.current) {
return
}
if (this.props.editorLocation) {
if (this.props.editorLocation && this.haveVisOptionsChanged(prevProps)) {
this.timeSeries.current.forceUpdate()
}
}
@ -145,6 +146,21 @@ class RefreshingGraph extends PureComponent<Props> {
)
}
private haveVisOptionsChanged(prevProps: Props): boolean {
const visProps: string[] = [
'axes',
'colors',
'tableOptions',
'fieldOptions',
'decimalPlaces',
'timeFormat',
]
const prevVisValues = _.pick(prevProps, visProps)
const curVisValues = _.pick(this.props, visProps)
return !_.isEqual(prevVisValues, curVisValues)
}
private singleStat = (data): JSX.Element => {
const {colors, cellHeight, decimalPlaces, manualRefresh} = this.props

View File

@ -248,7 +248,8 @@ class TableGraph extends Component<Props, State> {
const {sort} = this.state
let result = {}
if (this.hasDataChanged(nextProps.data)) {
const hasDataChanged = this.hasDataChanged(nextProps.data)
if (hasDataChanged) {
result = await timeSeriesToTableGraph(nextProps.data)
}
const data = _.get(result, 'data', this.state.data)
@ -265,7 +266,7 @@ class TableGraph extends Component<Props, State> {
const sortedLabels = _.get(result, 'sortedLabels', this.state.sortedLabels)
const computedFieldOptions = computeFieldOptions(fieldOptions, sortedLabels)
if (this.hasDataChanged(nextProps.data)) {
if (hasDataChanged) {
this.handleUpdateFieldOptions(computedFieldOptions)
}
@ -279,7 +280,7 @@ class TableGraph extends Component<Props, State> {
}
if (
this.hasDataChanged(nextProps.data) ||
hasDataChanged ||
_.includes(updatedProps, 'tableOptions') ||
_.includes(updatedProps, 'fieldOptions') ||
_.includes(updatedProps, 'timeFormat')
@ -338,7 +339,7 @@ class TableGraph extends Component<Props, State> {
const newUUID = _.get(data, '0.response.uuid', null)
const oldUUID = _.get(this.props.data, '0.response.uuid', null)
return newUUID !== oldUUID
return newUUID !== oldUUID || !!this.props.editorLocation
}
private get fixFirstColumn(): boolean {