@@ -15,24 +15,31 @@ class QueryAutocompleter {
15
15
constructor ( datasource : QuickwitDataSource ) {
16
16
this . datasource = datasource
17
17
}
18
- getFields ( ) {
19
- return this . datasource . getTagKeys ( )
18
+ async getFields ( ) {
19
+ return await this . datasource . getTagKeys ( )
20
20
}
21
- async getSuggestions ( word : string ) : Promise < Completion [ ] > {
22
- let suggestions : Completion [ ] = [ ] ;
23
21
22
+ async getFieldValues ( fieldName : string ) {
23
+ return this . datasource . getTagValues ( { key :fieldName } )
24
+ }
24
25
26
+ async getSuggestions ( word : string ) : Promise < { from : number , options : Completion [ ] } > {
27
+ let suggestions : { from : number , options : Completion [ ] } = { from : 0 , options : [ ] } ;
28
+
29
+ const wordIsField = word . match ( / ( [ \w \. ] + ) : ( \S * ) / )
30
+ if ( wordIsField ?. length ) {
31
+ const [ _match , fieldName , fieldValue ] = wordIsField ;
32
+ const candidateValues = await this . getFieldValues ( fieldName )
33
+ suggestions . from = fieldName . length + 1
34
+ suggestions . options = ( candidateValues . filter ( v => v . text . startsWith ( fieldValue ) )
35
+ . map ( v => ( { type :'text' , label :v . text , } ) ) )
36
+ } else {
25
37
const candidateFields = await this . getFields ( )
26
- suggestions = ( candidateFields
27
- . filter ( f => f . text . startsWith ( word ) )
28
- . map ( f => ( {
29
- type : 'text' ,
30
- section : "Fields" ,
31
- label :f . text ,
32
- detail :`${ f . value } ` ,
33
- } ) ) ) ;
34
-
35
- return suggestions ;
38
+ suggestions . from = 0
39
+ suggestions . options = ( candidateFields . filter ( f => f . text . startsWith ( word ) )
40
+ . map ( f => ( { type : 'text' , label :f . text , detail :`${ f . value } ` , } ) ) )
41
+ }
42
+ return suggestions
36
43
}
37
44
}
38
45
@@ -61,19 +68,15 @@ export function LogContextQueryEditor(){
61
68
const autocomplete = autocompletion ( {
62
69
override : [ async ( context : CompletionContext ) => {
63
70
let word = context . matchBefore ( / \S * / ) ;
64
-
65
71
if ( ! word ) { return null }
66
72
const suggestions = await autocompleter . getSuggestions ( word ?. text ) ;
67
-
68
73
return {
69
- from : word . from ,
70
- options : suggestions
74
+ from : word . from + suggestions . from ,
75
+ options : suggestions . options
71
76
}
72
77
} ]
73
78
} )
74
79
75
-
76
-
77
80
return ( < CodeMirror
78
81
ref = { editorRef }
79
82
className = { css `height : 100% ` } // XXX : need to set height for both wrapper elements
0 commit comments