From 780b115a4a0e48af6a0ef45f0808e81e6d1a9065 Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Wed, 24 Oct 2018 13:28:40 -0400 Subject: [PATCH 1/3] suggestion text needs to be a string --- src/ui/public/query_bar/components/query_bar.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ui/public/query_bar/components/query_bar.tsx b/src/ui/public/query_bar/components/query_bar.tsx index bbffb5ab755f8b..718ee8b71622ec 100644 --- a/src/ui/public/query_bar/components/query_bar.tsx +++ b/src/ui/public/query_bar/components/query_bar.tsx @@ -242,10 +242,9 @@ export class QueryBar extends Component { if (!this.persistedLog) { return []; } - const recentSearches = this.persistedLog.get(); + const recentSearches = 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; From f0b58ae25912d69249f9d6584f85fcb4899b64fd Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Wed, 24 Oct 2018 13:52:49 -0400 Subject: [PATCH 2/3] 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 --- src/ui/public/query_bar/components/query_bar.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/public/query_bar/components/query_bar.tsx b/src/ui/public/query_bar/components/query_bar.tsx index 718ee8b71622ec..ad0fe3023ce954 100644 --- a/src/ui/public/query_bar/components/query_bar.tsx +++ b/src/ui/public/query_bar/components/query_bar.tsx @@ -23,7 +23,7 @@ declare module '@elastic/eui' { export const EuiOutsideClickDetector: SFC; } -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'; @@ -242,7 +242,7 @@ export class QueryBar extends Component { if (!this.persistedLog) { return []; } - const recentSearches = this.persistedLog.get().map(toUser); + const recentSearches = uniq(this.persistedLog.get().map(toUser)); const matchingRecentSearches = recentSearches.filter(recentQuery => { return recentQuery.includes(query); }); From ebdd208a019fcc115ee4785ca3e94ccc60ccdeec Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Wed, 24 Oct 2018 16:43:14 -0400 Subject: [PATCH 3/3] don't put empty strings in the recent search history --- src/ui/public/query_bar/components/query_bar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/public/query_bar/components/query_bar.tsx b/src/ui/public/query_bar/components/query_bar.tsx index ad0fe3023ce954..e1ea35bb61cdb5 100644 --- a/src/ui/public/query_bar/components/query_bar.tsx +++ b/src/ui/public/query_bar/components/query_bar.tsx @@ -378,7 +378,7 @@ export class QueryBar extends Component { preventDefault(); } - if (this.persistedLog) { + if (this.persistedLog && this.state.query.query.trim() !== '') { this.persistedLog.add(this.state.query.query); }