diff --git a/public/app/features/explore/PromQueryField.tsx b/public/app/features/explore/PromQueryField.tsx index 479529d8e68..20c36ee87f3 100644 --- a/public/app/features/explore/PromQueryField.tsx +++ b/public/app/features/explore/PromQueryField.tsx @@ -156,6 +156,7 @@ interface PromQueryFieldState { labelValues: { [index: string]: { [index: string]: string[] } }; // metric -> labelKey -> [labelValue,...] logLabelOptions: any[]; metrics: string[]; + metricsOptions: any[]; metricsByPrefix: CascaderOption[]; } @@ -167,7 +168,7 @@ interface PromTypeaheadInput { value?: Value; } -class PromQueryField extends React.Component { +class PromQueryField extends React.PureComponent { plugins: any[]; constructor(props: PromQueryFieldProps, context) { @@ -189,6 +190,7 @@ class PromQueryField extends React.Component { - if (!this.state.metrics) { + const { histogramMetrics, metrics, metricsByPrefix } = this.state; + if (!metrics) { return; } + + // Update global prism config setPrismTokens(PRISM_SYNTAX, METRIC_MARK, this.state.metrics); + + // Build metrics tree + const histogramOptions = histogramMetrics.map(hm => ({ label: hm, value: hm })); + const metricsOptions = [ + { label: 'Histograms', value: HISTOGRAM_GROUP, children: histogramOptions }, + ...metricsByPrefix, + ]; + + this.setState({ metricsOptions }); }; onTypeahead = (typeahead: TypeaheadInput): TypeaheadOutput => { @@ -453,7 +467,7 @@ class PromQueryField extends React.Component ({ label: hm, value: hm })); - const metricsOptions = [ - { label: 'Histograms', value: HISTOGRAM_GROUP, children: histogramOptions }, - ...metricsByPrefix, - ]; + const { logLabelOptions, metricsOptions } = this.state; return (
diff --git a/public/app/features/explore/QueryField.tsx b/public/app/features/explore/QueryField.tsx index 93969d214e4..e927b3ca84a 100644 --- a/public/app/features/explore/QueryField.tsx +++ b/public/app/features/explore/QueryField.tsx @@ -132,7 +132,7 @@ export interface TypeaheadOutput { suggestions: SuggestionGroup[]; } -class QueryField extends React.Component { +class QueryField extends React.PureComponent { menuEl: HTMLElement | null; plugins: any[]; resetTimer: any;