Prechádzať zdrojové kódy

Explore: make query field suggestions more robust

- drop invalid history items
- make highlighter more robust by defaulting to empty string on text to highlight
David Kaltschmidt 7 rokov pred
rodič
commit
f831836fa7

+ 1 - 1
public/app/features/explore/Typeahead.tsx

@@ -42,7 +42,7 @@ class TypeaheadItem extends React.PureComponent<TypeaheadItemProps> {
   render() {
   render() {
     const { isSelected, item, prefix } = this.props;
     const { isSelected, item, prefix } = this.props;
     const className = isSelected ? 'typeahead-item typeahead-item__selected' : 'typeahead-item';
     const className = isSelected ? 'typeahead-item typeahead-item__selected' : 'typeahead-item';
-    const { label } = item;
+    const label = item.label || '';
     return (
     return (
       <li ref={this.getRef} className={className} onClick={this.onClick}>
       <li ref={this.getRef} className={className} onClick={this.onClick}>
         <Highlighter textToHighlight={label} searchWords={[prefix]} highlightClassName="typeahead-match" />
         <Highlighter textToHighlight={label} searchWords={[prefix]} highlightClassName="typeahead-match" />

+ 3 - 2
public/app/plugins/datasource/logging/language_provider.ts

@@ -97,9 +97,10 @@ export default class LoggingLanguageProvider extends LanguageProvider {
 
 
     if (history && history.length > 0) {
     if (history && history.length > 0) {
       const historyItems = _.chain(history)
       const historyItems = _.chain(history)
-        .uniqBy('query.expr')
-        .take(HISTORY_ITEM_COUNT)
         .map(h => h.query.expr)
         .map(h => h.query.expr)
+        .filter()
+        .uniq()
+        .take(HISTORY_ITEM_COUNT)
         .map(wrapLabel)
         .map(wrapLabel)
         .map(item => addHistoryMetadata(item, history))
         .map(item => addHistoryMetadata(item, history))
         .value();
         .value();

+ 3 - 2
public/app/plugins/datasource/prometheus/language_provider.ts

@@ -125,9 +125,10 @@ export default class PromQlLanguageProvider extends LanguageProvider {
 
 
     if (history && history.length > 0) {
     if (history && history.length > 0) {
       const historyItems = _.chain(history)
       const historyItems = _.chain(history)
-        .uniqBy('query.expr')
-        .take(HISTORY_ITEM_COUNT)
         .map(h => h.query.expr)
         .map(h => h.query.expr)
+        .filter()
+        .uniq()
+        .take(HISTORY_ITEM_COUNT)
         .map(wrapLabel)
         .map(wrapLabel)
         .map(item => addHistoryMetadata(item, history))
         .map(item => addHistoryMetadata(item, history))
         .value();
         .value();