Refactor AutoRefresh polling condition

Refactoring to check for template values that do not have their
localSelected status resolved allows us to avoid initially polling with
default selections after mounting. This condition also allows
AutoRefresh to ignore updates as template values resolve with their
localSelected status. This introduces a delay in cell graphs display before
template value local selections resolve.
pull/3810/head
Delmer Reed 2018-07-03 11:40:00 -04:00
parent a8155cbf2e
commit 6f2ee822c9
1 changed files with 14 additions and 14 deletions

View File

@ -4,7 +4,7 @@ import _ from 'lodash'
import {fetchTimeSeries} from 'src/shared/apis/query'
import {DEFAULT_TIME_SERIES} from 'src/shared/constants/series'
import {TimeSeriesServerResponse, TimeSeriesResponse} from 'src/types/series'
import {Template, Source} from 'src/types'
import {Template, Source, TemplateValue} from 'src/types'
interface Axes {
bounds: {
@ -69,11 +69,13 @@ const AutoRefresh = (
}
public async componentDidMount() {
this.startNewPolling()
if (!this.isAwaitingSelectedValues) {
this.startNewPolling()
}
}
public async componentDidUpdate(prevProps: Props) {
if (!this.isPropsDifferent(prevProps)) {
if (this.isAwaitingSelectedValues || !this.isPropsDifferent(prevProps)) {
return
}
this.startNewPolling()
@ -195,7 +197,7 @@ const AutoRefresh = (
return (
this.props.inView !== nextProps.inView ||
!!this.queryDifference(this.props.queries, nextProps.queries).length ||
this.isActiveTemplatesDifferent(nextProps) ||
!_.isEqual(this.props.templates, nextProps.templates) ||
this.props.autoRefresh !== nextProps.autoRefresh ||
isSourceDifferent
)
@ -233,18 +235,16 @@ const AutoRefresh = (
)
}
private isActiveTemplatesDifferent(prevProps: Props) {
const prevTemplates = this.getActiveTemplates(prevProps.templates)
const templates = this.getActiveTemplates(this.props.templates)
private get isAwaitingSelectedValues(): boolean {
const {templates} = this.props
return !_.isEqual(prevTemplates, templates)
}
const isAwaitingLocalSelection = (v: TemplateValue): boolean =>
v.localSelected === undefined
private getActiveTemplates(tempVars: Template[]): Template[] {
return _.map(tempVars, tempVar => ({
...tempVar,
values: tempVar.values.filter(v => v.selected || v.localSelected),
}))
const allValues = _.flatMap(templates, t => t.values)
const valuesAwaitingSelection = allValues.filter(isAwaitingLocalSelection)
return valuesAwaitingSelection.length !== 0
}
}