diff --git a/CHANGELOG.md b/CHANGELOG.md index 64ca3b02bf54..aed16fbe88f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fix missing border for header navigation control on right ([#5450](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5450)) - [BUG] Fix filtering issue in data source selector ([5484](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5484)) - [BUG][Data] Support for custom filters with heterogeneous data fields ([5577](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5577)) +- [BUG][Data] Fix empty suggestion history when querying in search bar [#5349](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5349) ### 🚞 Infrastructure diff --git a/src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx b/src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx index 9769e4a19346..f75007444f48 100644 --- a/src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx +++ b/src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx @@ -45,6 +45,14 @@ const mockSuggestion: QuerySuggestion = { type: QuerySuggestionTypes.Value, }; +const mockEmptySuggestion: QuerySuggestion = { + description: '', + end: 0, + start: 0, + text: '', + type: QuerySuggestionTypes.Value, +}; + describe('SuggestionComponent', () => { it('Should display the suggestion and use the provided ariaId', () => { const component = shallow( @@ -135,4 +143,37 @@ describe('SuggestionComponent', () => { component.simulate('mouseenter'); expect(mockHandler).toHaveBeenCalledTimes(1); }); + + it('Should return null for empty suggestion text', () => { + const component = shallow( + + ); + + expect(component.isEmptyRender()).toBeTruthy(); + }); + + it('Should return null for suggestion text with only whitespace', () => { + const whitespaceSuggestion = { ...mockEmptySuggestion, text: ' ' }; + const component = shallow( + + ); + + expect(component.isEmptyRender()).toBeTruthy(); + }); }); diff --git a/src/plugins/data/public/ui/typeahead/suggestion_component.tsx b/src/plugins/data/public/ui/typeahead/suggestion_component.tsx index 7d97f5b58283..67243df6415a 100644 --- a/src/plugins/data/public/ui/typeahead/suggestion_component.tsx +++ b/src/plugins/data/public/ui/typeahead/suggestion_component.tsx @@ -61,6 +61,13 @@ interface Props { } export function SuggestionComponent(props: Props) { + // Removing empty suggestions from the history is for maintaining a clean user experience. + // Empty suggestions, which typically result from inadvertent keystrokes or incomplete queries, + // do not provide value to the user. + if (!props.suggestion.text.trim()) { + return null; + } + return ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/interactive-supports-focus