Skip to content

Commit e4b5840

Browse files
committed
IBX-9837: Add more options to SearchNoResults React component: noResultsHints, extraClasses and searchText is no longer required
1 parent 55f013d commit e4b5840

File tree

2 files changed

+54
-30
lines changed

2 files changed

+54
-30
lines changed

src/bundle/Resources/translations/ibexa_universal_discovery_widget.en.xliff

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@
276276
<target state="new">Try more general keywords.</target>
277277
<note>key: search.no_results.hint.more_general</note>
278278
</trans-unit>
279+
<trans-unit id="9a697642846df0197cb9e2c0987d6e53d9bb3bc4" resname="search.no_results_without_query">
280+
<source>No results found</source>
281+
<target state="new">No results found</target>
282+
<note>key: search.no_results_without_query</note>
283+
</trans-unit>
279284
<trans-unit id="2b096dbbbcadb6a316903dce656706b528229e21" resname="search.placeholder">
280285
<source>Search...</source>
281286
<target state="new">Search...</target>

src/bundle/ui-dev/src/modules/universal-discovery/components/search/search.no.results.js

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,51 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import Icon from '../../../common/icon/icon';
5+
56
import { getTranslator } from '@ibexa-admin-ui/src/bundle/Resources/public/js/scripts/helpers/context.helper';
67

7-
const SearchNoResults = ({ searchText }) => {
8+
import { createCssClassNames } from '@ibexa-admin-ui/src/bundle/ui-dev/src/modules/common/helpers/css.class.names';
9+
10+
const SearchNoResults = ({ searchText, noResultsHints: noResultsHintsCustom, extraClasses }) => {
811
const Translator = getTranslator();
9-
const noResultsLabel = Translator.trans(
10-
/*@Desc("No results found for %query%")*/ 'search.no_results',
11-
{ query: searchText },
12-
'ibexa_universal_discovery_widget',
13-
);
14-
const noResultsHints = [
15-
Translator.trans(
16-
/*@Desc("Check the spelling of keywords.")*/ 'search.no_results.hint.check_spelling',
17-
{},
18-
'ibexa_universal_discovery_widget',
19-
),
20-
Translator.trans(
21-
/*@Desc("Try more general keywords.")*/ 'search.no_results.hint.more_general',
22-
{},
23-
'ibexa_universal_discovery_widget',
24-
),
25-
Translator.trans(
26-
/*@Desc("Try different keywords.")*/ 'search.no_results.hint.different_kewords',
27-
{},
28-
'ibexa_universal_discovery_widget',
29-
),
30-
Translator.trans(
31-
/*@Desc("Try fewer keywords. Reducing keywords results in more matches.")*/ 'search.no_results.hint.fewer_keywords',
32-
{},
33-
'ibexa_universal_discovery_widget',
34-
),
35-
];
12+
const className = createCssClassNames({
13+
'c-search-no-results': true,
14+
[extraClasses]: true,
15+
});
16+
const noResultsLabel = searchText
17+
? Translator.trans(
18+
/*@Desc("No results found for %query%")*/ 'search.no_results',
19+
{ query: searchText },
20+
'ibexa_universal_discovery_widget',
21+
)
22+
: Translator.trans(/*@Desc("No results found")*/ 'search.no_results_without_query', {}, 'ibexa_universal_discovery_widget');
23+
const noResultsHints = noResultsHintsCustom
24+
? noResultsHintsCustom
25+
: [
26+
Translator.trans(
27+
/*@Desc("Check the spelling of keywords.")*/ 'search.no_results.hint.check_spelling',
28+
{},
29+
'ibexa_universal_discovery_widget',
30+
),
31+
Translator.trans(
32+
/*@Desc("Try more general keywords.")*/ 'search.no_results.hint.more_general',
33+
{},
34+
'ibexa_universal_discovery_widget',
35+
),
36+
Translator.trans(
37+
/*@Desc("Try different keywords.")*/ 'search.no_results.hint.different_kewords',
38+
{},
39+
'ibexa_universal_discovery_widget',
40+
),
41+
Translator.trans(
42+
/*@Desc("Try fewer keywords. Reducing keywords results in more matches.")*/ 'search.no_results.hint.fewer_keywords',
43+
{},
44+
'ibexa_universal_discovery_widget',
45+
),
46+
];
3647

3748
return (
38-
<div className="c-search-no-results">
49+
<div className={className}>
3950
<img src="/bundles/ibexaadminui/img/no-results.svg" />
4051
<h2 className="c-search-no-results__no-results-title">{noResultsLabel}</h2>
4152
<div className="c-search-no-results__no-results-subtitle">
@@ -56,7 +67,15 @@ const SearchNoResults = ({ searchText }) => {
5667
};
5768

5869
SearchNoResults.propTypes = {
59-
searchText: PropTypes.string.isRequired,
70+
extraClasses: PropTypes.string,
71+
searchText: PropTypes.string,
72+
noResultsHints: PropTypes.arrayOf(PropTypes.string),
73+
};
74+
75+
SearchNoResults.defaultProps = {
76+
extraClasses: '',
77+
searchText: null,
78+
noResultsHints: null,
6079
};
6180

6281
export default SearchNoResults;

0 commit comments

Comments
 (0)