1- import { useEffect , useState } from 'react' ;
1+ import { useEffect , useMemo , useState } from 'react' ;
22
33import { 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' ;
67import { TempoDatasource } from './datasource' ;
78
89export 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