From 9f551400c3d09bfb032f3a770a363d707da63654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vieira?= Date: Thu, 9 Mar 2023 12:45:16 +0000 Subject: [PATCH] OpenTSDB: suggest_tagv receives prefix on input change (#64475) replace Select with AsyncSelect on tagv search --- .../opentsdb/components/FilterSection.tsx | 34 +++++++++---------- .../components/OpenTsdbQueryEditor.tsx | 4 +-- .../opentsdb/components/TagSection.tsx | 34 +++++-------------- 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/public/app/plugins/datasource/opentsdb/components/FilterSection.tsx b/public/app/plugins/datasource/opentsdb/components/FilterSection.tsx index ba255b948ed..c947b0017db 100644 --- a/public/app/plugins/datasource/opentsdb/components/FilterSection.tsx +++ b/public/app/plugins/datasource/opentsdb/components/FilterSection.tsx @@ -1,8 +1,18 @@ +import debounce from 'debounce-promise'; import { size } from 'lodash'; import React, { useCallback, useState } from 'react'; import { SelectableValue, toOption } from '@grafana/data'; -import { InlineLabel, Select, InlineFormLabel, InlineSwitch, Icon, clearButtonStyles, useStyles2 } from '@grafana/ui'; +import { + InlineLabel, + Select, + InlineFormLabel, + InlineSwitch, + Icon, + clearButtonStyles, + useStyles2, + AsyncSelect, +} from '@grafana/ui'; import { OpenTsdbFilter, OpenTsdbQuery } from '../types'; @@ -12,7 +22,7 @@ export interface FilterSectionProps { onRunQuery: () => void; suggestTagKeys: (query: OpenTsdbQuery) => Promise; filterTypes: string[]; - suggestTagValues: () => Promise; + suggestTagValues: (value: string) => Promise; } export function FilterSection({ @@ -28,9 +38,6 @@ export function FilterSection({ const [tagKeys, updTagKeys] = useState>>(); const [keyIsLoading, updKeyIsLoading] = useState(); - const [tagValues, updTagValues] = useState>>(); - const [valueIsLoading, updValueIsLoading] = useState(); - const [addFilterMode, updAddFilterMode] = useState(false); const [curFilterType, updCurFilterType] = useState('iliteral_or'); @@ -108,6 +115,8 @@ export function FilterSection({ return searchWords.reduce((acc, cur) => acc && label.toLowerCase().includes(cur.toLowerCase()), true); }, []); + const tagValueSearch = debounce((query: string) => suggestTagValues(query), 350); + return (
@@ -185,23 +194,14 @@ export function FilterSection({
- { - if (!tagValues) { - updValueIsLoading(true); - const tVs = await suggestTagValues(); - updTagValues(tVs); - updValueIsLoading(false); - } - }} - isLoading={valueIsLoading} - options={tagValues} + loadOptions={tagValueSearch} + defaultOptions={[]} onChange={({ value }) => { if (value) { updCurTagValue(value);