Skip to content

Commit 352a851

Browse files
fix: No match scenario in search (#1667)
Co-authored-by: Alex Varchuk <[email protected]>
1 parent 8e75f99 commit 352a851

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

e2e/integration/search.e2e.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ describe('Search', () => {
5353
getSearchInput().type('int', { force: true });
5454
cy.get('[data-markjs]').should('exist');
5555
});
56+
57+
it('should show proper message when no search results are found', () => {
58+
getSearchResults().should('not.exist');
59+
getSearchInput().type('xzss', {force: true});
60+
getSearchResults().should('exist').should('contain', 'No results found');
61+
})
5662
});

src/components/SearchBox/SearchBox.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
SearchResultsBox,
1717
SearchWrap,
1818
} from './styled.elements';
19+
import { l } from '../../services/Labels';
1920

2021
export interface SearchBoxProps {
2122
search: SearchStore<string>;
@@ -28,6 +29,7 @@ export interface SearchBoxProps {
2829

2930
export interface SearchBoxState {
3031
results: SearchResult[];
32+
noResults: boolean;
3133
term: string;
3234
activeItemIdx: number;
3335
}
@@ -39,6 +41,7 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
3941
super(props);
4042
this.state = {
4143
results: [],
44+
noResults: false,
4245
term: '',
4346
activeItemIdx: -1,
4447
};
@@ -47,6 +50,7 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
4750
clearResults(term: string) {
4851
this.setState({
4952
results: [],
53+
noResults: false,
5054
term,
5155
});
5256
this.props.marker.unmark();
@@ -55,6 +59,7 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
5559
clear = () => {
5660
this.setState({
5761
results: [],
62+
noResults: false,
5863
term: '',
5964
activeItemIdx: -1,
6065
});
@@ -95,6 +100,7 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
95100
setResults(results: SearchResult[], term: string) {
96101
this.setState({
97102
results,
103+
noResults: results.length === 0
98104
});
99105
this.props.marker.mark(term);
100106
}
@@ -166,6 +172,9 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
166172
</SearchResultsBox>
167173
</PerfectScrollbarWrap>
168174
)}
175+
{this.state.term && this.state.noResults ? (
176+
<SearchResultsBox data-role="search:results">{l('noResultsFound')}</SearchResultsBox>
177+
) : null}
169178
</SearchWrap>
170179
);
171180
}

src/services/Labels.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface LabelsConfig {
1010
arrayOf: string;
1111
webhook: string;
1212
const: string;
13+
noResultsFound: string;
1314
download: string;
1415
downloadSpecification: string;
1516
responses: string;
@@ -32,6 +33,7 @@ const labels: LabelsConfig = {
3233
arrayOf: 'Array of ',
3334
webhook: 'Event',
3435
const: 'Value',
36+
noResultsFound: 'No results found',
3537
download: 'Download',
3638
downloadSpecification: 'Download OpenAPI specification',
3739
responses: 'Responses',

0 commit comments

Comments
 (0)