diff --git a/ui/src/shared/components/AutoRefresh.tsx b/ui/src/shared/components/AutoRefresh.tsx index fc2d924e9..26c065d2f 100644 --- a/ui/src/shared/components/AutoRefresh.tsx +++ b/ui/src/shared/components/AutoRefresh.tsx @@ -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 } }