11import { css } from '@emotion/css' ;
2- import { type SelectableValue , toOption } from '@grafana/data' ;
3- import { getTemplateSrv } from '@grafana/runtime' ;
2+ import type { SelectableValue } from '@grafana/data' ;
43import { fuzzyMatch , InlineField , InlineFieldRow , Input , Select } from '@grafana/ui' ;
5- // import { notifyApp } from 'grafana/app/core/actions';
6- // import { createErrorNotification } from 'grafana/app/core/copy/appNotification';
7- // import { dispatch } from 'grafana/app/store/store';
84import React , { useCallback , useEffect , useState } from 'react' ;
95
106import type TraceDatasource from '../datasource' ;
117import type { TraceQuery } from '../types' ;
128import { transformToLogfmt } from '../util' ;
139import { t } from 'common/utils/utils' ;
10+ import { getTemplateSrv } from '@grafana/runtime' ;
1411
1512const durationPlaceholder = 'e.g. 1.2s, 100ms, 500us' ;
1613
@@ -40,16 +37,15 @@ export function SearchForm({ datasource, query, onChange }: Props) {
4037 setIsLoading ( prevValue => ( { ...prevValue , [ loaderOfType ] : true } ) ) ;
4138
4239 try {
43- const values = await datasource . loadOptions ( query . app_name ! , field ) ;
40+ if ( ! query . app_name ) return [ ] ;
41+ const values = await datasource . loadOptions ( query . app_name , field ) ;
4442 if ( ! values ?. length ) {
4543 return [ { label : `No ${ loaderOfType } found` , value : `No ${ loaderOfType } found` } ] ;
4644 }
47-
4845 const options : SelectableValue [ ] = values . sort ( ) . map ( option => ( {
4946 label : option . text ,
5047 value : option . value ,
5148 } ) ) ;
52-
5349 const filteredOptions = options . filter ( item => ( item . value ? fuzzyMatch ( item . value , keyword ) . found : false ) ) ;
5450 return filteredOptions ;
5551 } catch ( error ) {
@@ -65,28 +61,26 @@ export function SearchForm({ datasource, query, onChange }: Props) {
6561 ) ;
6662
6763 useEffect ( ( ) => {
68- const getOperations = async ( ) => {
64+ const getSpans = async ( ) => {
6965 const spansOptions = await loadOptions ( 'spans' , 'span_name' ) ;
70- // if (query.spans && getTemplateSrv().containsTemplate(query.spans)) {
71- // spans.push(toOption(query.spans));
72- // }
7366 setOperationOptions ( [ ...spansOptions ] ) ;
7467 } ;
75- if ( query . app_name ) {
76- getOperations ( ) ;
77- }
68+ query . app_name && getSpans ( ) ;
7869 } , [ datasource , query . app_name , loadOptions ] ) ;
7970 useEffect ( ( ) => {
8071 const getServices = async ( ) => {
8172 const serviceOptions = await loadOptions ( 'services' , 'resource.service.name' ) ;
82- // if (query.service && getTemplateSrv().containsTemplate(query.service)) {
83- // spans.push(toOption(query.service));
84- // }
73+ if ( query . service ?. length && getTemplateSrv ( ) . containsTemplate ( ) ) {
74+ for ( const service of query . service ) {
75+ serviceOptions . push ( {
76+ label : service ,
77+ value : service ,
78+ } ) ;
79+ }
80+ }
8581 setServiceOptions ( [ ...serviceOptions ] ) ;
8682 } ;
87- if ( query . app_name ) {
88- getServices ( ) ;
89- }
83+ query . app_name && getServices ( ) ;
9084 } , [ datasource , query . app_name , loadOptions ] ) ;
9185 return (
9286 < div className = { css ( { maxWidth : '500px' } ) } >
@@ -210,14 +204,15 @@ export function SearchForm({ datasource, query, onChange }: Props) {
210204 < InlineField
211205 label = 'Limit'
212206 labelWidth = { 14 }
213- tooltip = 'Maximum number of returned results'
207+ tooltip = 'Maximum number of returned results, default is 10 '
214208 grow
215209 >
216210 < Input
217211 id = 'limit'
218212 name = 'limit'
219213 type = 'number'
220214 value = { query . limit || '' }
215+ placeholder = 'e.g. 10'
221216 onChange = { v =>
222217 onChange ( {
223218 ...query ,
0 commit comments