Skip to content

Commit ca56f16

Browse files
authored
Tempo: Improve performance of drop down in variable query editor (grafana#92010)
Improve performance of drop down
1 parent b0031c0 commit ca56f16

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

public/app/plugins/datasource/tempo/VariableQueryEditor.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { useEffect, useState } from 'react';
1+
import { useEffect, useMemo, useState } from 'react';
22

33
import { DataQuery, SelectableValue } from '@grafana/data';
4-
import { InlineField, InlineFieldRow, Select } from '@grafana/ui';
4+
import { InlineField, InlineFieldRow, InputActionMeta, Select } from '@grafana/ui';
55

6+
import { maxOptions } from './SearchTraceQLEditor/SearchField';
67
import { TempoDatasource } from './datasource';
78

89
export enum TempoVariableQueryType {
@@ -33,6 +34,7 @@ export const TempoVariableQueryEditor = ({ onChange, query, datasource }: TempoV
3334
const [label, setLabel] = useState(query.label || '');
3435
const [type, setType] = useState<number | undefined>(query.type);
3536
const [labelOptions, setLabelOptions] = useState<Array<SelectableValue<string>>>([]);
37+
const [labelQuery, setLabelQuery] = useState<string>('');
3638

3739
useEffect(() => {
3840
if (type === TempoVariableQueryType.LabelValues) {
@@ -42,6 +44,22 @@ export const TempoVariableQueryEditor = ({ onChange, query, datasource }: TempoV
4244
}
4345
}, [datasource, query, type]);
4446

47+
const options = useMemo(() => {
48+
if (labelQuery.length === 0) {
49+
return labelOptions.slice(0, maxOptions);
50+
}
51+
52+
const queryLowerCase = labelQuery.toLowerCase();
53+
return labelOptions
54+
.filter((tag) => {
55+
if (tag.value && tag.value.length > 0) {
56+
return tag.value.toLowerCase().includes(queryLowerCase);
57+
}
58+
return false;
59+
})
60+
.slice(0, maxOptions);
61+
}, [labelQuery, labelOptions]);
62+
4563
const onQueryTypeChange = (newType: SelectableValue<TempoVariableQueryType>) => {
4664
setType(newType.value);
4765
if (newType.value !== undefined) {
@@ -93,10 +111,17 @@ export const TempoVariableQueryEditor = ({ onChange, query, datasource }: TempoV
93111
aria-label="Label"
94112
onChange={onLabelChange}
95113
onBlur={handleBlur}
114+
onInputChange={(value: string, { action }: InputActionMeta) => {
115+
if (action === 'input-change') {
116+
setLabelQuery(value);
117+
}
118+
}}
119+
onCloseMenu={() => setLabelQuery('')}
96120
value={{ label, value: label }}
97-
options={labelOptions}
121+
options={options}
98122
width={32}
99123
allowCustomValue
124+
virtualized
100125
/>
101126
</InlineField>
102127
</InlineFieldRow>

0 commit comments

Comments
 (0)