diff --git a/public/app/features/trails/MetricSelectScene.tsx b/public/app/features/trails/MetricSelectScene.tsx index aa036f9ba01..995a012db44 100644 --- a/public/app/features/trails/MetricSelectScene.tsx +++ b/public/app/features/trails/MetricSelectScene.tsx @@ -1,5 +1,6 @@ import { css } from '@emotion/css'; import leven from 'leven'; +import { debounce } from 'lodash'; import React, { useCallback } from 'react'; import { GrafanaTheme2, VariableRefresh } from '@grafana/data'; @@ -288,18 +289,26 @@ export class MetricSelectScene extends SceneObjectBase { } }; - public onSearchChange = (evt: React.SyntheticEvent) => { + public onSearchQueryChange = (evt: React.SyntheticEvent) => { this.setState({ searchQuery: evt.currentTarget.value }); + this.searchQueryChangedDebounced(); + }; + + private searchQueryChangedDebounced = debounce(() => { this.updateMetrics(); // Need to repeat entire pipeline this.buildLayout(); - }; + }, 500); public onPrefixFilterChange = (prefixFilter: string | undefined) => { this.setState({ prefixFilter }); + this.prefixFilterChangedDebounced(); + }; + + private prefixFilterChangedDebounced = debounce(() => { this.applyMetricPrefixFilter(); this.updateMetrics(false); // Only needed to applyMetricPrefixFilter this.buildLayout(); - }; + }, 1000); public onTogglePreviews = () => { this.setState({ showPreviews: !this.state.showPreviews }); @@ -339,7 +348,7 @@ export class MetricSelectScene extends SceneObjectBase { placeholder="Search metrics" prefix={} value={searchQuery} - onChange={model.onSearchChange} + onChange={model.onSearchQueryChange} disabled={disableSearch} />