Browse Source

React UI: Simplify query history setting code (#6225)

The metric names only get loaded once initially, so there is no reason
to mix them up with the handling of ongoing query history.

Signed-off-by: Julius Volz <julius.volz@gmail.com>
pull/6226/head
Julius Volz 5 years ago committed by GitHub
parent
commit
9698262b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      web/ui/react-app/src/PanelList.tsx

11
web/ui/react-app/src/PanelList.tsx

@ -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 {

Loading…
Cancel
Save