Skip to content

Commit

Permalink
Suggestion text needs to be a string (#24526) (#24540)
Browse files Browse the repository at this point in the history
* suggestion text needs to be a string

* deduplicate after calling toUser since a string and object version of
the same query could both exist in the persisted log, resulting in
identical strings after toUser runs

* don't put empty strings in the recent search history
  • Loading branch information
Bargs committed Oct 24, 2018
1 parent b616418 commit 42017d5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/ui/public/query_bar/components/query_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ declare module '@elastic/eui' {
export const EuiOutsideClickDetector: SFC<any>;
}

import { debounce } from 'lodash';
import { debounce, uniq } from 'lodash';
import React, { Component, SFC } from 'react';
import { getFromLegacyIndexPattern } from 'ui/index_patterns/static_utils';
import { kfetch } from 'ui/kfetch';
Expand Down Expand Up @@ -242,10 +242,9 @@ export class QueryBar extends Component<Props, State> {
if (!this.persistedLog) {
return [];
}
const recentSearches = this.persistedLog.get();
const recentSearches = uniq(this.persistedLog.get().map(toUser));
const matchingRecentSearches = recentSearches.filter(recentQuery => {
const recentQueryString = typeof recentQuery === 'object' ? toUser(recentQuery) : recentQuery;
return recentQueryString.includes(query);
return recentQuery.includes(query);
});
return matchingRecentSearches.map(recentSearch => {
const text = recentSearch;
Expand Down Expand Up @@ -379,7 +378,7 @@ export class QueryBar extends Component<Props, State> {
preventDefault();
}

if (this.persistedLog) {
if (this.persistedLog && this.state.query.query.trim() !== '') {
this.persistedLog.add(this.state.query.query);
}

Expand Down

0 comments on commit 42017d5

Please sign in to comment.