11import defaults from 'lodash/defaults' ;
22
33import React , { useState , useEffect } from 'react' ;
4- import { AsyncSelect , Label , Field } from '@grafana/ui' ;
4+ import { Label , Select } from '@grafana/ui' ;
55import { QueryEditorProps , SelectableValue } from '@grafana/data' ;
66import { DataSource } from './datasource' ;
77import { defaultQuery , MyDataSourceOptions , FlamegraphQuery } from './types' ;
@@ -11,6 +11,7 @@ type Props = QueryEditorProps<DataSource, FlamegraphQuery, MyDataSourceOptions>;
1111
1212export const QueryEditor = ( props : Props ) => {
1313 const query = defaults ( props . query , defaultQuery ) ;
14+ console . log ( props ) ;
1415 const [ appName , setAppName ] = useState < SelectableValue < string > > ( { label : query . name , value : query . name } ) ;
1516 const [ names , setNames ] = useState < SelectableValue < string > [ ] > ( [ ] ) ;
1617 const loadAppNames = ( query : string ) => {
@@ -28,8 +29,10 @@ export const QueryEditor = (props: Props) => {
2829
2930 useEffect ( ( ) => {
3031 const { onChange, query, onRunQuery } = props ;
31- onChange ( { ...query , name : appName . value } ) ;
32- onRunQuery ( ) ;
32+ if ( appName . value ) {
33+ onChange ( { ...query , name : appName . value } ) ;
34+ onRunQuery ( ) ;
35+ }
3336 } , [ appName ] ) ;
3437
3538 return (
@@ -42,15 +45,14 @@ export const QueryEditor = (props: Props) => {
4245 /> */ }
4346 < div style = { { display : 'flex' , flexDirection : 'row' , marginTop : '10px' } } >
4447 < Label style = { { marginTop : '8px' , marginRight : '10px' } } > Application</ Label >
45- < Field >
46- < AsyncSelect
47- placeholder = 'Application name'
48- value = { appName }
49- onChange = { setAppName }
50- defaultOptions = { names }
51- loadOptions = { ( query : string ) => Promise . resolve ( names . filter ( name => name . value ?. includes ( query ) ) ) }
52- />
53- </ Field >
48+ < Select
49+ onChange = { ( v ) => v ? setAppName ( v ) : setAppName ( { label :'' , value : '' } ) }
50+ value = { appName }
51+ options = { names }
52+ backspaceRemovesValue
53+ isClearable
54+ allowCustomValue
55+ />
5456 </ div >
5557 </ div >
5658 ) ;
0 commit comments