React UI: Simplify query history setting code
The metric names only get loaded once initially, so there is no reason
to mix them up with the handling of ongoing query history.
@@ -50,7 +50,7 @@ class PanelList extends Component<any, PanelListState> {
}
})
.then(json => {
- this.setMetrics(json.data);
+ this.setState({metricNames: json.data});
})
.catch(error => this.setState({ fetchMetricsError: error.message }));
@@ -87,13 +87,12 @@ class PanelList extends Component<any, PanelListState> {
toggleQueryHistory = (e: ChangeEvent<HTMLInputElement>) => {
localStorage.setItem('enable-query-history', `${e.target.checked}`);
- this.setMetrics();
+ this.updatePastQueries();
}
- setMetrics = (metricNames: string[] = this.state.metricNames) => {
+ updatePastQueries = () => {
this.setState({
- pastQueries: this.isHistoryEnabled() ? this.getHistoryItems() : [],
- metricNames
+ pastQueries: this.isHistoryEnabled() ? this.getHistoryItems() : []
});
}
@@ -107,7 +106,7 @@ class PanelList extends Component<any, PanelListState> {
return metric === query ? acc : [...acc, metric]; // Prevent adding query twice.
}, [query]);
localStorage.setItem('history', JSON.stringify(extendedItems.slice(0, 50)));
- this.setMetrics();
+ this.updatePastQueries();
}
getKey(): string {
