[v11.2.x] Tempo: Improve performance of drop down in variable query editor (#92012)
Tempo: Improve performance of drop down in variable query editor (#92010)
Improve performance of drop down
(cherry picked from commit ca56f16615)
Co-authored-by: Joey <90795735+joey-grafana@users.noreply.github.com>
This commit is contained in:
co-authored by
Joey
parent
6d288f1d14
commit
c16e4f1e86
@@ -1,8 +1,9 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { DataQuery, SelectableValue } from '@grafana/data';
|
||||
import { InlineField, InlineFieldRow, Select } from '@grafana/ui';
|
||||
import { InlineField, InlineFieldRow, InputActionMeta, Select } from '@grafana/ui';
|
||||
|
||||
import { maxOptions } from './SearchTraceQLEditor/SearchField';
|
||||
import { TempoDatasource } from './datasource';
|
||||
|
||||
export enum TempoVariableQueryType {
|
||||
@@ -33,6 +34,7 @@ export const TempoVariableQueryEditor = ({ onChange, query, datasource }: TempoV
|
||||
const [label, setLabel] = useState(query.label || '');
|
||||
const [type, setType] = useState<number | undefined>(query.type);
|
||||
const [labelOptions, setLabelOptions] = useState<Array<SelectableValue<string>>>([]);
|
||||
const [labelQuery, setLabelQuery] = useState<string>('');
|
||||
|
||||
useEffect(() => {
|
||||
if (type === TempoVariableQueryType.LabelValues) {
|
||||
@@ -42,6 +44,22 @@ export const TempoVariableQueryEditor = ({ onChange, query, datasource }: TempoV
|
||||
}
|
||||
}, [datasource, query, type]);
|
||||
|
||||
const options = useMemo(() => {
|
||||
if (labelQuery.length === 0) {
|
||||
return labelOptions.slice(0, maxOptions);
|
||||
}
|
||||
|
||||
const queryLowerCase = labelQuery.toLowerCase();
|
||||
return labelOptions
|
||||
.filter((tag) => {
|
||||
if (tag.value && tag.value.length > 0) {
|
||||
return tag.value.toLowerCase().includes(queryLowerCase);
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.slice(0, maxOptions);
|
||||
}, [labelQuery, labelOptions]);
|
||||
|
||||
const onQueryTypeChange = (newType: SelectableValue<TempoVariableQueryType>) => {
|
||||
setType(newType.value);
|
||||
if (newType.value !== undefined) {
|
||||
@@ -93,10 +111,17 @@ export const TempoVariableQueryEditor = ({ onChange, query, datasource }: TempoV
|
||||
aria-label="Label"
|
||||
onChange={onLabelChange}
|
||||
onBlur={handleBlur}
|
||||
onInputChange={(value: string, { action }: InputActionMeta) => {
|
||||
if (action === 'input-change') {
|
||||
setLabelQuery(value);
|
||||
}
|
||||
}}
|
||||
onCloseMenu={() => setLabelQuery('')}
|
||||
value={{ label, value: label }}
|
||||
options={labelOptions}
|
||||
options={options}
|
||||
width={32}
|
||||
allowCustomValue
|
||||
virtualized
|
||||
/>
|
||||
</InlineField>
|
||||
</InlineFieldRow>
|
||||
|
||||
Reference in New Issue
Block a user