Skip to content

Commit

Permalink
[Fix] Remove empty suggestion history (#5349)
Browse files Browse the repository at this point in the history
* Add search input filter

Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Add CHANGELOG.md

Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Add tests for empty suggestions

Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Add code comment

Signed-off-by: Willie Hung <willie880201044@gmail.com>

---------

Signed-off-by: Willie Hung <willie880201044@gmail.com>
Signed-off-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
Co-authored-by: Anan Zhuang <ananzh@amazon.com>
  • Loading branch information
3 people authored Dec 13, 2023
1 parent 478176a commit 808591a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
41 changes: 41 additions & 0 deletions src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -135,4 +143,37 @@ describe('SuggestionComponent', () => {
component.simulate('mouseenter');
expect(mockHandler).toHaveBeenCalledTimes(1);
});

it('Should return null for empty suggestion text', () => {
const component = shallow(
<SuggestionComponent
onClick={noop}
onMouseEnter={noop}
selected={false}
suggestion={mockEmptySuggestion}
innerRef={noop}
ariaId={'suggestion-empty'}
shouldDisplayDescription={true}
/>
);

expect(component.isEmptyRender()).toBeTruthy();
});

it('Should return null for suggestion text with only whitespace', () => {
const whitespaceSuggestion = { ...mockEmptySuggestion, text: ' ' };
const component = shallow(
<SuggestionComponent
onClick={noop}
onMouseEnter={noop}
selected={false}
suggestion={whitespaceSuggestion}
innerRef={noop}
ariaId={'suggestion-whitespace'}
shouldDisplayDescription={true}
/>
);

expect(component.isEmptyRender()).toBeTruthy();
});
});
7 changes: 7 additions & 0 deletions src/plugins/data/public/ui/typeahead/suggestion_component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div
Expand Down

0 comments on commit 808591a

Please sign in to comment.