Skip to content

Commit

Permalink
[Fix] Remove empty suggestion history (#5349) (#5607)
Browse files Browse the repository at this point in the history
* Add search input filter
* Add CHANGELOG.md
* Add tests for empty suggestions
* Add code comment

---------

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>
(cherry picked from commit 808591a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 953fb81 commit 05e3a5c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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 05e3a5c

Please sign in to comment.