@@ -12,11 +12,17 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
12
12
const myRef : MutableRefObject < string > = useRef ( '' ) ;
13
13
const queryValue : string = myRef . current ;
14
14
15
- const [ streams , setStreams ] : any = useState ( [ ] ) ;
15
+ const [ streams , setStreams ] : any = useState ( { } ) ;
16
+ const [ streamOptions , setStreamOptions ] : any = useState ( [ ] ) ;
16
17
17
18
useEffect ( ( ) => {
18
19
getStreams ( datasource . url ) . then ( ( response : any ) => {
19
- setStreams ( [
20
+ const streams : { [ key : string ] : any } = { } ;
21
+ response . list . forEach ( ( stream : any ) => {
22
+ streams [ stream . name ] = stream ;
23
+ } ) ;
24
+ setStreams ( { ...streams } ) ;
25
+ setStreamOptions ( [
20
26
...response . list . map ( ( stream : any ) => ( {
21
27
label : stream . name ,
22
28
value : stream . name ,
@@ -40,14 +46,12 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
40
46
41
47
const streamUpdated = ( stream : { label : string ; value : string } ) => {
42
48
console . log ( datasource . instanceSettings ) ;
43
- getStreamSchema ( { url : datasource . url , stream : stream . value } ) . then ( ( response : any ) => {
44
- onChange ( {
45
- ...query ,
46
- stream : stream . value ,
47
- streamFields : response . schema ,
48
- } ) ;
49
- onRunQuery ( ) ;
49
+ onChange ( {
50
+ ...query ,
51
+ stream : stream . value ,
52
+ streamFields : streams [ stream . value ] . schema ,
50
53
} ) ;
54
+ onRunQuery ( ) ;
51
55
} ;
52
56
return (
53
57
< div >
@@ -65,7 +69,7 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
65
69
width : 200px !important ;
66
70
margin : 8px 0px ;
67
71
` }
68
- options = { streams }
72
+ options = { streamOptions }
69
73
value = { query . stream }
70
74
onChange = { streamUpdated }
71
75
> </ Select >
0 commit comments