Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Remove empty suggestion history #5349

Merged
merged 6 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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
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();
});
});
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.
willie-hung marked this conversation as resolved.
Show resolved Hide resolved
if (!props.suggestion.text.trim()) {
return null;
}

willie-hung marked this conversation as resolved.
Show resolved Hide resolved
return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/interactive-supports-focus
<div
Expand Down
Loading