Преглед изворни кода

azuremonitor: fix where suggestions

Alexander Zobnin пре 6 година
родитељ
комит
99ff8e68ff

+ 19 - 9
public/app/plugins/datasource/grafana-azure-monitor-datasource/editor/KustoQueryField.tsx

@@ -99,12 +99,12 @@ export default class KustoQueryField extends QueryField {
       if (wrapperClasses.contains('function-context')) {
       if (wrapperClasses.contains('function-context')) {
         typeaheadContext = 'context-function';
         typeaheadContext = 'context-function';
         if (this.fields) {
         if (this.fields) {
-          suggestionGroups = this._getKeywordSuggestions();
+          suggestionGroups = this.getKeywordSuggestions();
         } else {
         } else {
           this._fetchFields();
           this._fetchFields();
           return;
           return;
         }
         }
-      } else if (modelPrefix.match(/(where\s$)/i)) {
+      } else if (modelPrefix.match(/(where\s(\w+\b)?$)/i)) {
         typeaheadContext = 'context-where';
         typeaheadContext = 'context-where';
         const fullQuery = Plain.serialize(this.state.value);
         const fullQuery = Plain.serialize(this.state.value);
         const table = this.getTableFromContext(fullQuery);
         const table = this.getTableFromContext(fullQuery);
@@ -116,7 +116,7 @@ export default class KustoQueryField extends QueryField {
       } else if (modelPrefix.match(/(,\s*$)/)) {
       } else if (modelPrefix.match(/(,\s*$)/)) {
         typeaheadContext = 'context-multiple-fields';
         typeaheadContext = 'context-multiple-fields';
         if (this.fields) {
         if (this.fields) {
-          suggestionGroups = this._getKeywordSuggestions();
+          suggestionGroups = this.getKeywordSuggestions();
         } else {
         } else {
           this._fetchFields();
           this._fetchFields();
           return;
           return;
@@ -124,7 +124,7 @@ export default class KustoQueryField extends QueryField {
       } else if (modelPrefix.match(/(from\s$)/i)) {
       } else if (modelPrefix.match(/(from\s$)/i)) {
         typeaheadContext = 'context-from';
         typeaheadContext = 'context-from';
         if (this.events) {
         if (this.events) {
-          suggestionGroups = this._getKeywordSuggestions();
+          suggestionGroups = this.getKeywordSuggestions();
         } else {
         } else {
           this._fetchEvents();
           this._fetchEvents();
           return;
           return;
@@ -132,7 +132,7 @@ export default class KustoQueryField extends QueryField {
       } else if (modelPrefix.match(/(^select\s\w*$)/i)) {
       } else if (modelPrefix.match(/(^select\s\w*$)/i)) {
         typeaheadContext = 'context-select';
         typeaheadContext = 'context-select';
         if (this.fields) {
         if (this.fields) {
-          suggestionGroups = this._getKeywordSuggestions();
+          suggestionGroups = this.getKeywordSuggestions();
         } else {
         } else {
           this._fetchFields();
           this._fetchFields();
           return;
           return;
@@ -140,16 +140,19 @@ export default class KustoQueryField extends QueryField {
       } else if (modelPrefix.match(/from\s\S+\s\w*$/i)) {
       } else if (modelPrefix.match(/from\s\S+\s\w*$/i)) {
         prefix = '';
         prefix = '';
         typeaheadContext = 'context-since';
         typeaheadContext = 'context-since';
-        suggestionGroups = this._getKeywordSuggestions();
+        suggestionGroups = this.getKeywordSuggestions();
       // } else if (modelPrefix.match(/\d+\s\w*$/)) {
       // } else if (modelPrefix.match(/\d+\s\w*$/)) {
       //   typeaheadContext = 'context-number';
       //   typeaheadContext = 'context-number';
       //   suggestionGroups = this._getAfterNumberSuggestions();
       //   suggestionGroups = this._getAfterNumberSuggestions();
       } else if (modelPrefix.match(/ago\b/i) || modelPrefix.match(/facet\b/i) || modelPrefix.match(/\$__timefilter\b/i)) {
       } else if (modelPrefix.match(/ago\b/i) || modelPrefix.match(/facet\b/i) || modelPrefix.match(/\$__timefilter\b/i)) {
         typeaheadContext = 'context-timeseries';
         typeaheadContext = 'context-timeseries';
-        suggestionGroups = this._getKeywordSuggestions();
+        suggestionGroups = this.getKeywordSuggestions();
       } else if (prefix && !wrapperClasses.contains('argument')) {
       } else if (prefix && !wrapperClasses.contains('argument')) {
+        if (modelPrefix.match(/\s$/i)) {
+          prefix = '';
+        }
         typeaheadContext = 'context-builtin';
         typeaheadContext = 'context-builtin';
-        suggestionGroups = this._getKeywordSuggestions();
+        suggestionGroups = this.getKeywordSuggestions();
       } else if (Plain.serialize(this.state.value) === '') {
       } else if (Plain.serialize(this.state.value) === '') {
         typeaheadContext = 'context-new';
         typeaheadContext = 'context-new';
         if (this.schema) {
         if (this.schema) {
@@ -159,6 +162,12 @@ export default class KustoQueryField extends QueryField {
           setTimeout(this.onTypeahead, 0);
           setTimeout(this.onTypeahead, 0);
           return;
           return;
         }
         }
+      } else {
+        typeaheadContext = 'context-builtin';
+        if (modelPrefix.match(/\s$/i)) {
+          prefix = '';
+        }
+        suggestionGroups = this.getKeywordSuggestions();
       }
       }
 
 
       let results = 0;
       let results = 0;
@@ -178,6 +187,7 @@ export default class KustoQueryField extends QueryField {
         .filter(group => group.items.length > 0);
         .filter(group => group.items.length > 0);
 
 
       // console.log('onTypeahead', selection.anchorNode, wrapperClasses, text, offset, prefix, typeaheadContext);
       // console.log('onTypeahead', selection.anchorNode, wrapperClasses, text, offset, prefix, typeaheadContext);
+      // console.log('onTypeahead', modelPrefix, prefix, typeaheadContext);
 
 
       this.setState({
       this.setState({
         typeaheadPrefix: prefix,
         typeaheadPrefix: prefix,
@@ -283,7 +293,7 @@ export default class KustoQueryField extends QueryField {
   //   ];
   //   ];
   // }
   // }
 
 
-  private _getKeywordSuggestions(): SuggestionGroup[] {
+  private getKeywordSuggestions(): SuggestionGroup[] {
     return [
     return [
       {
       {
         prefixMatch: true,
         prefixMatch: true,