Browse Source

feat(search): Improve free text autocomplete (#27380)

when doing autocomplete on a query like: free text tag_key the autocomplete logic would try to match that as one tag and there would be no matches but now we take the last token (which would be tag_key in the prev example) delimited by spaces and apply that in our autocomplete logic.
David Wang 3 years ago
parent
commit
61976f3ff4
1 changed files with 4 additions and 4 deletions
  1. 4 4
      static/app/components/smartSearchBar/index.tsx

+ 4 - 4
static/app/components/smartSearchBar/index.tsx

@@ -1017,10 +1017,10 @@ class SmartSearchBar extends React.Component<Props, State> {
     }
 
     if (cursorToken.type === Token.FreeText) {
-      const autocompleteGroups = [
-        await this.generateTagAutocompleteGroup(cursorToken.text),
-      ];
-      this.setState({searchTerm: cursorToken.text});
+      const lastToken = cursorToken.text.trim().split(' ').pop() ?? '';
+      const keyText = lastToken.replace(new RegExp(`^${NEGATION_OPERATOR}`), '');
+      const autocompleteGroups = [await this.generateTagAutocompleteGroup(keyText)];
+      this.setState({searchTerm: keyText});
       this.updateAutoCompleteStateMultiHeader(autocompleteGroups);
       return;
     }