@blaze-cms/react-page-builder 0.124.0-alpha.9 → 0.124.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +303 -0
- package/README.md +8 -0
- package/lib/application/query/index.js +8 -2
- package/lib/application/query/index.js.map +1 -1
- package/lib/components/Button.js +18 -5
- package/lib/components/Button.js.map +1 -1
- package/lib/components/Card/CardContainer.js +3 -7
- package/lib/components/Card/CardContainer.js.map +1 -1
- package/lib/components/Card/CardFactory.js +6 -3
- package/lib/components/Card/CardFactory.js.map +1 -1
- package/lib/components/CarouselWrapper.js +2 -2
- package/lib/components/CarouselWrapper.js.map +1 -1
- package/lib/components/Image/ImageRender.js +5 -1
- package/lib/components/Image/ImageRender.js.map +1 -1
- package/lib/components/ItemList/ItemListButton/ItemListButton.js +161 -0
- package/lib/components/ItemList/ItemListButton/ItemListButton.js.map +1 -0
- package/lib/components/ItemList/ItemListButton/index.js +16 -0
- package/lib/components/ItemList/ItemListButton/index.js.map +1 -0
- package/lib/components/ItemList/ItemListCounter/ItemListCounter.js +83 -0
- package/lib/components/ItemList/ItemListCounter/ItemListCounter.js.map +1 -0
- package/lib/components/ItemList/ItemListCounter/index.js +16 -0
- package/lib/components/ItemList/ItemListCounter/index.js.map +1 -0
- package/lib/components/ItemList/ItemListNew/ItemListNew.js +87 -0
- package/lib/components/ItemList/ItemListNew/ItemListNew.js.map +1 -0
- package/lib/components/ItemList/ItemListNew/index.js +16 -0
- package/lib/components/ItemList/ItemListNew/index.js.map +1 -0
- package/lib/components/ItemList/constants.js +19 -0
- package/lib/components/ItemList/constants.js.map +1 -0
- package/lib/components/ItemList/helpers/get-item-list-data.js +17 -0
- package/lib/components/ItemList/helpers/get-item-list-data.js.map +1 -0
- package/lib/components/ItemList/helpers/get-item-list-id.js +23 -0
- package/lib/components/ItemList/helpers/get-item-list-id.js.map +1 -0
- package/lib/components/ItemList/helpers/get-item-list-ids.js +28 -0
- package/lib/components/ItemList/helpers/get-item-list-ids.js.map +1 -0
- package/lib/components/ItemList/helpers/index.js +50 -0
- package/lib/components/ItemList/helpers/index.js.map +1 -0
- package/lib/components/ItemList/helpers/set-item-list-id.js +22 -0
- package/lib/components/ItemList/helpers/set-item-list-id.js.map +1 -0
- package/lib/components/ItemList/helpers/set-param-and-redirect.js +51 -0
- package/lib/components/ItemList/helpers/set-param-and-redirect.js.map +1 -0
- package/lib/components/ItemList/hooks/index.js +18 -0
- package/lib/components/ItemList/hooks/index.js.map +1 -0
- package/lib/components/ItemList/hooks/use-item-list-id.js +45 -0
- package/lib/components/ItemList/hooks/use-item-list-id.js.map +1 -0
- package/lib/components/LazyImage/LazyImage.js +5 -1
- package/lib/components/LazyImage/LazyImage.js.map +1 -1
- package/lib/components/List/ListBuilder.js +12 -6
- package/lib/components/List/ListBuilder.js.map +1 -1
- package/lib/components/List/ListFactory.js +34 -7
- package/lib/components/List/ListFactory.js.map +1 -1
- package/lib/components/List/helpers/has-required-item-list-details.js +29 -0
- package/lib/components/List/helpers/has-required-item-list-details.js.map +1 -0
- package/lib/components/List/helpers/index.js +8 -0
- package/lib/components/List/helpers/index.js.map +1 -1
- package/lib/components/Menu/Menu.js +41 -28
- package/lib/components/Menu/Menu.js.map +1 -1
- package/lib/components/Menu/MenuContext.js +20 -0
- package/lib/components/Menu/MenuContext.js.map +1 -0
- package/lib/components/MenuItem/MenuItem.js +26 -7
- package/lib/components/MenuItem/MenuItem.js.map +1 -1
- package/lib/components/SearchContent/SearchContent.js +183 -0
- package/lib/components/SearchContent/SearchContent.js.map +1 -0
- package/lib/components/SearchContent/SearchContentItems.js +51 -0
- package/lib/components/SearchContent/SearchContentItems.js.map +1 -0
- package/lib/components/SearchContent/SearchContentResults.js +45 -0
- package/lib/components/SearchContent/SearchContentResults.js.map +1 -0
- package/lib/components/SearchContent/SearchContentToggleIcon.js +42 -0
- package/lib/components/SearchContent/SearchContentToggleIcon.js.map +1 -0
- package/lib/components/SearchContent/index.js +2 -301
- package/lib/components/SearchContent/index.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/FiltersList.js +2 -4
- package/lib/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +16 -66
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +87 -23
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/components/Checkbox.js +19 -9
- package/lib/components/SearchFilter/components/Checkbox.js.map +1 -1
- package/lib/components/SearchFilter/components/Select.js +27 -11
- package/lib/components/SearchFilter/components/Select.js.map +1 -1
- package/lib/components/SearchFilter/components/TextSearch.js +1 -5
- package/lib/components/SearchFilter/components/TextSearch.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-filters-query.js +87 -0
- package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -0
- package/lib/components/SearchFilter/helpers/build-query.js +1 -1
- package/lib/components/SearchFilter/helpers/build-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
- package/lib/components/SearchFilter/helpers/build-raw-query-stringified.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js +18 -3
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
- package/lib/components/SearchFilter/helpers/index.js +8 -0
- package/lib/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib/components/SearchFilter/helpers/parse-filter-value.js +3 -7
- package/lib/components/SearchFilter/helpers/parse-filter-value.js.map +1 -1
- package/lib/components/index.js +16 -1
- package/lib/components/index.js.map +1 -1
- package/lib/constants/index.js +3 -1
- package/lib/constants/index.js.map +1 -1
- package/lib/helpers/build-raw-query.js.map +1 -1
- package/lib/hooks/helpers/append-gtm-classname.js +1 -0
- package/lib/hooks/helpers/append-gtm-classname.js.map +1 -1
- package/lib-es/application/query/index.js +45 -1
- package/lib-es/application/query/index.js.map +1 -1
- package/lib-es/components/Button.js +18 -6
- package/lib-es/components/Button.js.map +1 -1
- package/lib-es/components/Card/CardContainer.js +3 -7
- package/lib-es/components/Card/CardContainer.js.map +1 -1
- package/lib-es/components/Card/CardFactory.js +7 -4
- package/lib-es/components/Card/CardFactory.js.map +1 -1
- package/lib-es/components/CarouselWrapper.js +2 -2
- package/lib-es/components/CarouselWrapper.js.map +1 -1
- package/lib-es/components/Image/ImageRender.js +4 -1
- package/lib-es/components/Image/ImageRender.js.map +1 -1
- package/lib-es/components/ItemList/ItemListButton/ItemListButton.js +111 -0
- package/lib-es/components/ItemList/ItemListButton/ItemListButton.js.map +1 -0
- package/lib-es/components/ItemList/ItemListButton/index.js +3 -0
- package/lib-es/components/ItemList/ItemListButton/index.js.map +1 -0
- package/lib-es/components/ItemList/ItemListCounter/ItemListCounter.js +60 -0
- package/lib-es/components/ItemList/ItemListCounter/ItemListCounter.js.map +1 -0
- package/lib-es/components/ItemList/ItemListCounter/index.js +3 -0
- package/lib-es/components/ItemList/ItemListCounter/index.js.map +1 -0
- package/lib-es/components/ItemList/ItemListNew/ItemListNew.js +64 -0
- package/lib-es/components/ItemList/ItemListNew/ItemListNew.js.map +1 -0
- package/lib-es/components/ItemList/ItemListNew/index.js +3 -0
- package/lib-es/components/ItemList/ItemListNew/index.js.map +1 -0
- package/lib-es/components/ItemList/constants.js +6 -0
- package/lib-es/components/ItemList/constants.js.map +1 -0
- package/lib-es/components/ItemList/helpers/get-item-list-data.js +7 -0
- package/lib-es/components/ItemList/helpers/get-item-list-data.js.map +1 -0
- package/lib-es/components/ItemList/helpers/get-item-list-id.js +11 -0
- package/lib-es/components/ItemList/helpers/get-item-list-id.js.map +1 -0
- package/lib-es/components/ItemList/helpers/get-item-list-ids.js +13 -0
- package/lib-es/components/ItemList/helpers/get-item-list-ids.js.map +1 -0
- package/lib-es/components/ItemList/helpers/index.js +6 -0
- package/lib-es/components/ItemList/helpers/index.js.map +1 -0
- package/lib-es/components/ItemList/helpers/set-item-list-id.js +10 -0
- package/lib-es/components/ItemList/helpers/set-item-list-id.js.map +1 -0
- package/lib-es/components/ItemList/helpers/set-param-and-redirect.js +20 -0
- package/lib-es/components/ItemList/helpers/set-param-and-redirect.js.map +1 -0
- package/lib-es/components/ItemList/hooks/index.js +2 -0
- package/lib-es/components/ItemList/hooks/index.js.map +1 -0
- package/lib-es/components/ItemList/hooks/use-item-list-id.js +26 -0
- package/lib-es/components/ItemList/hooks/use-item-list-id.js.map +1 -0
- package/lib-es/components/LazyImage/LazyImage.js +4 -1
- package/lib-es/components/LazyImage/LazyImage.js.map +1 -1
- package/lib-es/components/List/ListBuilder.js +12 -6
- package/lib-es/components/List/ListBuilder.js.map +1 -1
- package/lib-es/components/List/ListFactory.js +33 -9
- package/lib-es/components/List/ListFactory.js.map +1 -1
- package/lib-es/components/List/helpers/has-required-item-list-details.js +20 -0
- package/lib-es/components/List/helpers/has-required-item-list-details.js.map +1 -0
- package/lib-es/components/List/helpers/index.js +1 -0
- package/lib-es/components/List/helpers/index.js.map +1 -1
- package/lib-es/components/Menu/Menu.js +54 -46
- package/lib-es/components/Menu/Menu.js.map +1 -1
- package/lib-es/components/Menu/MenuContext.js +6 -0
- package/lib-es/components/Menu/MenuContext.js.map +1 -0
- package/lib-es/components/MenuItem/MenuItem.js +24 -9
- package/lib-es/components/MenuItem/MenuItem.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContent.js +129 -0
- package/lib-es/components/SearchContent/SearchContent.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContentItems.js +33 -0
- package/lib-es/components/SearchContent/SearchContentItems.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContentResults.js +31 -0
- package/lib-es/components/SearchContent/SearchContentResults.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContentToggleIcon.js +30 -0
- package/lib-es/components/SearchContent/SearchContentToggleIcon.js.map +1 -0
- package/lib-es/components/SearchContent/index.js +1 -205
- package/lib-es/components/SearchContent/index.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js +2 -4
- package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +10 -43
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +70 -15
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Checkbox.js +18 -9
- package/lib-es/components/SearchFilter/components/Checkbox.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Select.js +23 -8
- package/lib-es/components/SearchFilter/components/Select.js.map +1 -1
- package/lib-es/components/SearchFilter/components/TextSearch.js +1 -5
- package/lib-es/components/SearchFilter/components/TextSearch.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js +54 -0
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/build-query.js +1 -1
- package/lib-es/components/SearchFilter/helpers/build-query.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
- package/lib-es/components/SearchFilter/helpers/build-raw-query-stringified.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js +13 -1
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/index.js +2 -1
- package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/parse-filter-value.js +3 -3
- package/lib-es/components/SearchFilter/helpers/parse-filter-value.js.map +1 -1
- package/lib-es/components/index.js +10 -1
- package/lib-es/components/index.js.map +1 -1
- package/lib-es/constants/index.js +2 -1
- package/lib-es/constants/index.js.map +1 -1
- package/lib-es/helpers/build-raw-query.js.map +1 -1
- package/lib-es/hooks/helpers/append-gtm-classname.js +1 -0
- package/lib-es/hooks/helpers/append-gtm-classname.js.map +1 -1
- package/package.json +5 -4
- package/src/application/query/index.js +51 -1
- package/src/components/Button.js +27 -5
- package/src/components/Card/CardContainer.js +2 -6
- package/src/components/Card/CardFactory.js +5 -3
- package/src/components/CarouselWrapper.js +2 -2
- package/src/components/Image/ImageRender.js +3 -0
- package/src/components/ItemList/ItemListButton/ItemListButton.js +94 -0
- package/src/components/ItemList/ItemListButton/index.js +3 -0
- package/src/components/ItemList/ItemListCounter/ItemListCounter.js +52 -0
- package/src/components/ItemList/ItemListCounter/index.js +3 -0
- package/src/components/ItemList/ItemListNew/ItemListNew.js +51 -0
- package/src/components/ItemList/ItemListNew/index.js +3 -0
- package/src/components/ItemList/constants.js +5 -0
- package/src/components/ItemList/helpers/get-item-list-data.js +6 -0
- package/src/components/ItemList/helpers/get-item-list-id.js +11 -0
- package/src/components/ItemList/helpers/get-item-list-ids.js +10 -0
- package/src/components/ItemList/helpers/index.js +5 -0
- package/src/components/ItemList/helpers/set-item-list-id.js +9 -0
- package/src/components/ItemList/helpers/set-param-and-redirect.js +20 -0
- package/src/components/ItemList/hooks/index.js +1 -0
- package/src/components/ItemList/hooks/use-item-list-id.js +27 -0
- package/src/components/LazyImage/LazyImage.js +11 -1
- package/src/components/List/ListBuilder.js +10 -5
- package/src/components/List/ListFactory.js +48 -12
- package/src/components/List/helpers/has-required-item-list-details.js +14 -0
- package/src/components/List/helpers/index.js +1 -0
- package/src/components/Menu/Menu.js +61 -54
- package/src/components/Menu/MenuContext.js +5 -0
- package/src/components/MenuItem/MenuItem.js +39 -14
- package/src/components/SearchContent/SearchContent.js +136 -0
- package/src/components/SearchContent/SearchContentItems.js +28 -0
- package/src/components/SearchContent/SearchContentResults.js +27 -0
- package/src/components/SearchContent/SearchContentToggleIcon.js +27 -0
- package/src/components/SearchContent/index.js +1 -217
- package/src/components/SearchFilter/SearchFilter/FiltersList.js +30 -37
- package/src/components/SearchFilter/SearchFilter/SearchFilter.js +10 -25
- package/src/components/SearchFilter/SearchFilterContainer.js +61 -16
- package/src/components/SearchFilter/components/Checkbox.js +23 -8
- package/src/components/SearchFilter/components/Select.js +18 -11
- package/src/components/SearchFilter/components/TextSearch.js +1 -3
- package/src/components/SearchFilter/helpers/build-filters-query.js +40 -0
- package/src/components/SearchFilter/helpers/build-query.js +3 -1
- package/src/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
- package/src/components/SearchFilter/helpers/get-initial-filter-values.js +12 -1
- package/src/components/SearchFilter/helpers/index.js +3 -1
- package/src/components/SearchFilter/helpers/parse-filter-value.js +3 -3
- package/src/components/index.js +10 -1
- package/src/constants/index.js +2 -0
- package/src/helpers/build-raw-query.js +1 -0
- package/src/hooks/helpers/append-gtm-classname.js +3 -0
- package/tests/unit/src/components/Button.test.js +55 -1
- package/tests/unit/src/components/ItemList/ItemListButton.test.js +175 -0
- package/tests/unit/src/components/ItemList/ItemListCounter.test.js +65 -0
- package/tests/unit/src/components/ItemList/ItemListNew.test.js +164 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListButton.test.js.snap +107 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListCounter.test.js.snap +31 -0
- package/tests/unit/src/components/ItemList/__snapshots__/ItemListNew.test.js.snap +27 -0
- package/tests/unit/src/components/ItemList/helpers/get-item-list-data.test.js +28 -0
- package/tests/unit/src/components/ItemList/helpers/get-item-list-id.test.js +20 -0
- package/tests/unit/src/components/ItemList/helpers/get-item-list-ids.test.js +19 -0
- package/tests/unit/src/components/ItemList/helpers/set-item-list-id.test.js +13 -0
- package/tests/unit/src/components/ItemList/helpers/set-param-and-redirect.test.js +30 -0
- package/tests/unit/src/components/ItemList/hooks/use-item-list-id.test.js +32 -0
- package/tests/unit/src/components/List/helpers/has-required-item-list-details.test.js +30 -0
- package/tests/unit/src/components/Menu/Menu.test.js +9 -3
- package/tests/unit/src/components/Menu/__snapshots__/Menu.test.js.snap +12 -11
- package/tests/unit/src/components/MenuItem/MenuItem.test.js +1 -1
- package/tests/unit/src/components/MenuItem/SubMenu.test.js +5 -1
- package/tests/unit/src/components/MenuItem/__snapshots__/MenuItem.test.js.snap +54 -10
- package/tests/unit/src/components/SearchContent/SearchContent.test.js +29 -0
- package/tests/unit/src/components/SearchContent/__snapshots__/SearchContent.test.js.snap +9 -0
- package/tests/unit/src/components/SearchFilter/SearchFilter/SearchFilter.test.js +3 -6
- package/tests/unit/src/components/SearchFilter/components/__snapshots__/Checkbox.test.js.snap +2 -0
- package/tests/unit/src/components/SearchFilter/components/__snapshots__/Select.test.js.snap +4 -0
- package/tests/unit/src/components/SearchFilter/helpers/build-query.test.js +2 -2
- package/tests/unit/src/components/SearchFilter/helpers/get-initial-filter-values.test.js +25 -11
- package/tests/unit/src/components/SearchFilter/helpers/parse-filter-value.test.js +1 -1
- package/tests/unit/src/components/__snapshots__/index.test.js.snap +12 -0
|
@@ -1,219 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { gql, useApolloClient } from '@apollo/client';
|
|
4
|
-
|
|
5
|
-
import { useRouter } from 'next/router';
|
|
6
|
-
import { getPublishedContent } from '../../application/query';
|
|
7
|
-
import BlazeLink from '../BlazeLink';
|
|
8
|
-
|
|
9
|
-
const logError = error => error;
|
|
10
|
-
|
|
11
|
-
const SearchContent = ({
|
|
12
|
-
entities,
|
|
13
|
-
searchInputAlignment,
|
|
14
|
-
searchInputWrapperMobile,
|
|
15
|
-
searchInputWrapperDesktop,
|
|
16
|
-
collapsible,
|
|
17
|
-
isMobile,
|
|
18
|
-
placeholder
|
|
19
|
-
}) => {
|
|
20
|
-
const [collapsed, setCollapsed] = useState(collapsible);
|
|
21
|
-
const [searchTerm, setSearchTerm] = useState(null);
|
|
22
|
-
const [data, setData] = useState([]);
|
|
23
|
-
|
|
24
|
-
const router = useRouter();
|
|
25
|
-
const client = useApolloClient();
|
|
26
|
-
|
|
27
|
-
const capitalize = s => {
|
|
28
|
-
if (typeof s !== 'string') return '';
|
|
29
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
React.useEffect(() => {
|
|
33
|
-
if (data && data.length !== 0) return;
|
|
34
|
-
|
|
35
|
-
const promises = entities.map(entity => {
|
|
36
|
-
const [a, b] = entity.split('_');
|
|
37
|
-
|
|
38
|
-
const entityName = capitalize(a) + capitalize(b);
|
|
39
|
-
|
|
40
|
-
const rawQueryStringified = JSON.stringify({
|
|
41
|
-
size: 0,
|
|
42
|
-
query: {
|
|
43
|
-
bool: {
|
|
44
|
-
should: [
|
|
45
|
-
{
|
|
46
|
-
match: {
|
|
47
|
-
docType: entity
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
minimum_should_match: 1
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const query = gql`
|
|
57
|
-
${getPublishedContent(entityName)}
|
|
58
|
-
`;
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
return client.query({
|
|
62
|
-
query,
|
|
63
|
-
variables: {
|
|
64
|
-
rawQueryStringified,
|
|
65
|
-
offset: 0,
|
|
66
|
-
limit: 5
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
} catch (e) {
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
(async () => {
|
|
76
|
-
try {
|
|
77
|
-
const fetchResults = await Promise.all(promises);
|
|
78
|
-
const searchResults = fetchResults
|
|
79
|
-
.map(result => {
|
|
80
|
-
const { data: resultData } = result;
|
|
81
|
-
return resultData.searchPublishedContent.results;
|
|
82
|
-
})
|
|
83
|
-
.flat();
|
|
84
|
-
|
|
85
|
-
setData(searchResults);
|
|
86
|
-
} catch (e) {
|
|
87
|
-
logError(e);
|
|
88
|
-
}
|
|
89
|
-
})();
|
|
90
|
-
} catch (e) {
|
|
91
|
-
logError(e);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const handleClick = (e, url) => {
|
|
96
|
-
e.preventDefault();
|
|
97
|
-
router.push(url);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const handleKeyPress = e => {
|
|
101
|
-
if (e.key === 'Enter' && e.target.value !== '') {
|
|
102
|
-
router.push(`/search?search_term=${e.target.value}`);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const renderResults = () =>
|
|
107
|
-
// eslint-disable-next-line no-undef
|
|
108
|
-
data?.map(dataItem => {
|
|
109
|
-
const { name, image, url } = dataItem;
|
|
110
|
-
|
|
111
|
-
if (searchTerm && searchTerm !== '') {
|
|
112
|
-
if (name.includes(searchTerm)) {
|
|
113
|
-
return (
|
|
114
|
-
<BlazeLink href={url} onClick={e => handleClick(e, url)}>
|
|
115
|
-
<div className="mt-2 mb-1">
|
|
116
|
-
<div className="flex justify-start items-center">
|
|
117
|
-
{image.url ? <img src={image.url} alt={name} className="w-20 h-14" /> : null}
|
|
118
|
-
<span className="ml-2">{name}</span>
|
|
119
|
-
</div>
|
|
120
|
-
</div>
|
|
121
|
-
</BlazeLink>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const searchResultsMessage = searchTerm ? `Search results for: ${searchTerm}` : '';
|
|
130
|
-
|
|
131
|
-
return collapsed ? (
|
|
132
|
-
<div className={isMobile ? searchInputWrapperMobile : searchInputWrapperDesktop}>
|
|
133
|
-
<div className="search-content--collapse__wrapper">
|
|
134
|
-
<label className="search-content--collapse__label">
|
|
135
|
-
<span className="search-content--collapse__icon_wrapper">
|
|
136
|
-
<svg className="search-content--collapse__icon" viewBox="0 0 20 20">
|
|
137
|
-
<path
|
|
138
|
-
fillRule="evenodd"
|
|
139
|
-
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
|
|
140
|
-
clipRule="evenodd"
|
|
141
|
-
/>
|
|
142
|
-
</svg>
|
|
143
|
-
</span>
|
|
144
|
-
<input
|
|
145
|
-
onFocus={() => setCollapsed(false)}
|
|
146
|
-
onChange={e => setSearchTerm(e.target.value)}
|
|
147
|
-
type="text"
|
|
148
|
-
name="search"
|
|
149
|
-
value=""
|
|
150
|
-
className="search-content--collapse__input"
|
|
151
|
-
/>
|
|
152
|
-
</label>
|
|
153
|
-
</div>
|
|
154
|
-
</div>
|
|
155
|
-
) : (
|
|
156
|
-
<>
|
|
157
|
-
<div className={`${isMobile ? searchInputWrapperMobile : searchInputWrapperDesktop}`}>
|
|
158
|
-
<div className="search-content--expanded__wrapper">
|
|
159
|
-
<label className="search-content--expanded__label">
|
|
160
|
-
<span className="search-content--expanded__icon_wrapper">
|
|
161
|
-
<svg className="search-content--expanded__icon" viewBox="0 0 20 20">
|
|
162
|
-
<path
|
|
163
|
-
fillRule="evenodd"
|
|
164
|
-
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
|
|
165
|
-
clipRule="evenodd"
|
|
166
|
-
/>
|
|
167
|
-
</svg>
|
|
168
|
-
</span>
|
|
169
|
-
<input
|
|
170
|
-
type="text"
|
|
171
|
-
name="search"
|
|
172
|
-
onChange={e => setSearchTerm(e.target.value)}
|
|
173
|
-
onKeyPress={handleKeyPress}
|
|
174
|
-
className="search-content--expanded__input"
|
|
175
|
-
placeholder={placeholder}
|
|
176
|
-
onBlur={() => {
|
|
177
|
-
if (!collapsible) return;
|
|
178
|
-
if (!searchTerm || searchTerm === '') setCollapsed(true);
|
|
179
|
-
}}
|
|
180
|
-
/>
|
|
181
|
-
</label>
|
|
182
|
-
</div>
|
|
183
|
-
{data &&
|
|
184
|
-
searchResultsMessage !== '' && (
|
|
185
|
-
<div className="search-content--results__wrapper">
|
|
186
|
-
<div className="search-content--results__wrapper--message">
|
|
187
|
-
<div className="text-sm pt-2">{searchResultsMessage}</div>
|
|
188
|
-
|
|
189
|
-
<div className="search-content--results__message">
|
|
190
|
-
<div className="search-content--results__content">{renderResults()}</div>
|
|
191
|
-
</div>
|
|
192
|
-
</div>
|
|
193
|
-
</div>
|
|
194
|
-
)}
|
|
195
|
-
</div>
|
|
196
|
-
</>
|
|
197
|
-
);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
SearchContent.propTypes = {
|
|
201
|
-
searchInputAlignment: PropTypes.string,
|
|
202
|
-
searchInputWrapperMobile: PropTypes.string,
|
|
203
|
-
searchInputWrapperDesktop: PropTypes.string,
|
|
204
|
-
placeholder: PropTypes.string,
|
|
205
|
-
isMobile: PropTypes.bool,
|
|
206
|
-
collapsible: PropTypes.bool,
|
|
207
|
-
entities: PropTypes.array.isRequired
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
SearchContent.defaultProps = {
|
|
211
|
-
searchInputAlignment: '',
|
|
212
|
-
searchInputWrapperMobile: '',
|
|
213
|
-
searchInputWrapperDesktop: '',
|
|
214
|
-
placeholder: '',
|
|
215
|
-
isMobile: false,
|
|
216
|
-
collapsible: false
|
|
217
|
-
};
|
|
1
|
+
import SearchContent from './SearchContent';
|
|
218
2
|
|
|
219
3
|
export default SearchContent;
|
|
@@ -17,13 +17,10 @@ const FiltersList = ({
|
|
|
17
17
|
|
|
18
18
|
return filters.map(({ type, label, propsToDisplay, elementTitle, ...otherProps }, index) => {
|
|
19
19
|
if (!propsToDisplay && !propsToDisplay.length) return null;
|
|
20
|
-
|
|
21
20
|
const dynamicKey = [itemId, index].join('-');
|
|
22
21
|
const isDataAvailable = !!data && Object.keys(data).length;
|
|
23
22
|
const dataAggregations = isDataAvailable ? data : null;
|
|
24
23
|
const areAggregationsAvailable = isDataAvailable && !!dataAggregations;
|
|
25
|
-
const results = areAggregationsAvailable && dataAggregations[propsToDisplay[0]];
|
|
26
|
-
const shouldDisplayFilter = results && results.buckets && results.buckets.length;
|
|
27
24
|
|
|
28
25
|
switch (type) {
|
|
29
26
|
case TEXT_SEARCH:
|
|
@@ -43,43 +40,39 @@ const FiltersList = ({
|
|
|
43
40
|
);
|
|
44
41
|
case CHECKBOX:
|
|
45
42
|
return (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
</div>
|
|
62
|
-
)
|
|
43
|
+
<div
|
|
44
|
+
key={dynamicKey}
|
|
45
|
+
className="filter__section filter__section--search-refine filter__section--checkboxes">
|
|
46
|
+
<Checkbox
|
|
47
|
+
{...otherProps}
|
|
48
|
+
data={data}
|
|
49
|
+
prop={propsToDisplay[0]}
|
|
50
|
+
label={label}
|
|
51
|
+
elementTitle={elementTitle}
|
|
52
|
+
hasUrl={hasUrl}
|
|
53
|
+
filterValues={filterValues}
|
|
54
|
+
updateFilterValues={updateFilterValues}
|
|
55
|
+
shouldSearch={shouldSearch}
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
63
58
|
);
|
|
64
59
|
case SELECT:
|
|
65
60
|
return (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
</div>
|
|
82
|
-
)
|
|
61
|
+
<div
|
|
62
|
+
key={dynamicKey}
|
|
63
|
+
className="filter__section filter__section--search-refine filter__section--selects">
|
|
64
|
+
<SelectFilter
|
|
65
|
+
{...otherProps}
|
|
66
|
+
data={data}
|
|
67
|
+
prop={propsToDisplay[0]}
|
|
68
|
+
label={label}
|
|
69
|
+
elementTitle={elementTitle}
|
|
70
|
+
hasUrl={hasUrl}
|
|
71
|
+
filterValues={filterValues}
|
|
72
|
+
updateFilterValues={updateFilterValues}
|
|
73
|
+
shouldSearch={shouldSearch}
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
83
76
|
);
|
|
84
77
|
case RANGE:
|
|
85
78
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useEffect
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import debounce from 'lodash.debounce';
|
|
@@ -14,21 +14,6 @@ import ResetDesktopForm from './ResetDesktopForm';
|
|
|
14
14
|
import MobileFormToolbar from './MobileFormToolbar';
|
|
15
15
|
import { SEARCH, REFINE, MORE_FILTERS_CLASSES } from '../constants';
|
|
16
16
|
|
|
17
|
-
const reducer = (state, action) => {
|
|
18
|
-
const { newValues, type, shouldSearch = true } = action;
|
|
19
|
-
|
|
20
|
-
switch (type) {
|
|
21
|
-
case 'update':
|
|
22
|
-
return { ...state, ...newValues, shouldSearch };
|
|
23
|
-
case 'resetSearch':
|
|
24
|
-
return { ...state, shouldSearch: false };
|
|
25
|
-
case 'reset':
|
|
26
|
-
return { ...newValues, shouldSearch };
|
|
27
|
-
default:
|
|
28
|
-
throw new Error();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
17
|
const SearchFilter = ({
|
|
33
18
|
searchFilterRef,
|
|
34
19
|
data,
|
|
@@ -40,13 +25,13 @@ const SearchFilter = ({
|
|
|
40
25
|
isCollapsedOnResponsive,
|
|
41
26
|
displaySearchFilter,
|
|
42
27
|
setDisplaySearchFilter,
|
|
43
|
-
initialFilterValues,
|
|
44
28
|
groupAfterDesktop,
|
|
45
|
-
groupAfterMobile
|
|
29
|
+
groupAfterMobile,
|
|
30
|
+
filterValues,
|
|
31
|
+
setAppliedFilters
|
|
46
32
|
}) => {
|
|
47
33
|
const [moreFiltersMobileCollapsed, setMoreFiltersMobileCollapsed] = useState(true);
|
|
48
34
|
const [moreFiltersDesktopCollapsed, setMoreFiltersDesktopCollapsed] = useState(true);
|
|
49
|
-
const [filterValues, dispatch] = useReducer(reducer, initialFilterValues);
|
|
50
35
|
|
|
51
36
|
const doSubmit = (newValues = filterValues) => {
|
|
52
37
|
const newQuery = buildQuery(newValues, filters);
|
|
@@ -63,10 +48,10 @@ const SearchFilter = ({
|
|
|
63
48
|
() => {
|
|
64
49
|
if (filterValues.shouldSearch) {
|
|
65
50
|
handleSubmit(filterValues);
|
|
66
|
-
|
|
51
|
+
setAppliedFilters({ type: 'resetSearch' });
|
|
67
52
|
}
|
|
68
53
|
},
|
|
69
|
-
[filterValues, handleSubmit]
|
|
54
|
+
[filterValues, handleSubmit, setAppliedFilters]
|
|
70
55
|
);
|
|
71
56
|
|
|
72
57
|
const formClass = classnames('filter__form filter__form--initial', {
|
|
@@ -85,12 +70,11 @@ const SearchFilter = ({
|
|
|
85
70
|
|
|
86
71
|
const handleReset = () => {
|
|
87
72
|
const newValues = getInitialFilterValues(data, filters, {});
|
|
88
|
-
|
|
89
|
-
dispatch({ newValues, type: 'reset' });
|
|
73
|
+
setAppliedFilters({ newValues, type: 'reset' });
|
|
90
74
|
};
|
|
91
75
|
|
|
92
76
|
const updateFilterValues = (newValues, shouldSubmit) => {
|
|
93
|
-
|
|
77
|
+
setAppliedFilters({ newValues, shouldSearch: shouldSubmit, type: 'update' });
|
|
94
78
|
};
|
|
95
79
|
|
|
96
80
|
const shouldGroup = !!(groupAfterDesktop || groupAfterMobile);
|
|
@@ -248,7 +232,8 @@ SearchFilter.propTypes = {
|
|
|
248
232
|
isCollapsedOnResponsive: PropTypes.bool.isRequired,
|
|
249
233
|
groupAfterDesktop: PropTypes.number.isRequired,
|
|
250
234
|
groupAfterMobile: PropTypes.number.isRequired,
|
|
251
|
-
|
|
235
|
+
filterValues: PropTypes.object.isRequired,
|
|
236
|
+
setAppliedFilters: PropTypes.func.isRequired
|
|
252
237
|
};
|
|
253
238
|
|
|
254
239
|
export default SearchFilter;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useRef } from 'react';
|
|
1
|
+
import React, { useState, useRef, useReducer } from 'react';
|
|
2
2
|
import { useRouter } from 'next/router';
|
|
3
3
|
import { useQuery } from '@apollo/client';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
@@ -6,11 +6,31 @@ import { parseUrl, stringify } from 'query-string';
|
|
|
6
6
|
import SearchFilter from './SearchFilter';
|
|
7
7
|
import { withTitle } from '../../HOC';
|
|
8
8
|
import { getSearchPublishedContent } from '../../application/query';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
buildNewQuery,
|
|
11
|
+
buildRawQueryStringified,
|
|
12
|
+
getInitialFilterValues,
|
|
13
|
+
buildFiltersQuery
|
|
14
|
+
} from './helpers';
|
|
10
15
|
import { getEntityData } from '../../helpers';
|
|
11
16
|
import { RAW_RESULTS, RANGE, CHECKBOX_SELECT } from './constants';
|
|
12
17
|
import { SCROLL_OFFSET } from '../../constants';
|
|
13
18
|
|
|
19
|
+
const reducer = (state, action) => {
|
|
20
|
+
const { newValues, type, shouldSearch = true } = action;
|
|
21
|
+
|
|
22
|
+
switch (type) {
|
|
23
|
+
case 'update':
|
|
24
|
+
return { ...state, ...newValues, shouldSearch };
|
|
25
|
+
case 'resetSearch':
|
|
26
|
+
return { ...state, shouldSearch: false };
|
|
27
|
+
case 'reset':
|
|
28
|
+
return { ...newValues, shouldSearch };
|
|
29
|
+
default:
|
|
30
|
+
throw new Error();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
14
34
|
const SearchFilterContainer = ({
|
|
15
35
|
entity,
|
|
16
36
|
url,
|
|
@@ -18,25 +38,31 @@ const SearchFilterContainer = ({
|
|
|
18
38
|
name,
|
|
19
39
|
isCollapsedOnResponsive,
|
|
20
40
|
groupAfterMobile,
|
|
21
|
-
groupAfterDesktop
|
|
41
|
+
groupAfterDesktop,
|
|
42
|
+
filterBy,
|
|
43
|
+
filterByProperty,
|
|
44
|
+
shouldAddFilters
|
|
22
45
|
}) => {
|
|
23
46
|
const router = useRouter();
|
|
47
|
+
const { asPath } = router;
|
|
24
48
|
const searchFilterRef = useRef(null);
|
|
25
49
|
const [key, setKey] = useState(`filter-${name}`);
|
|
26
50
|
const [displaySearchFilter, setDisplaySearchFilter] = useState(false);
|
|
27
|
-
const hasUrl = !!url;
|
|
28
51
|
const {
|
|
29
52
|
url: currentUrl,
|
|
30
53
|
query: { sort, sortby },
|
|
31
54
|
query
|
|
32
|
-
} = parseUrl(
|
|
55
|
+
} = parseUrl(asPath);
|
|
56
|
+
const [filterValues, dispatch] = useReducer(
|
|
57
|
+
reducer,
|
|
58
|
+
getInitialFilterValues(null, filters, query)
|
|
59
|
+
);
|
|
60
|
+
const hasUrl = !!url;
|
|
61
|
+
|
|
33
62
|
const sortValues = sort && sortby ? stringify({ sort, sortby }) : '';
|
|
34
63
|
const baseQuery = sortValues ? `${currentUrl}?${sortValues}` : currentUrl;
|
|
35
64
|
|
|
36
65
|
const action = getSearchPublishedContent(RAW_RESULTS);
|
|
37
|
-
|
|
38
|
-
let rawQueryStringified = '';
|
|
39
|
-
|
|
40
66
|
const checkboxSelectValues = [];
|
|
41
67
|
const rangeValues = [];
|
|
42
68
|
|
|
@@ -50,21 +76,32 @@ const SearchFilterContainer = ({
|
|
|
50
76
|
|
|
51
77
|
const { docType } = getEntityData(entity);
|
|
52
78
|
|
|
53
|
-
|
|
79
|
+
const filtersQuery = shouldAddFilters
|
|
80
|
+
? buildFiltersQuery(filterValues || query, filterBy, filterByProperty)
|
|
81
|
+
: [];
|
|
82
|
+
|
|
83
|
+
const rawQueryStringified = buildRawQueryStringified(
|
|
84
|
+
checkboxSelectValues,
|
|
85
|
+
rangeValues,
|
|
86
|
+
docType,
|
|
87
|
+
filtersQuery
|
|
88
|
+
);
|
|
54
89
|
|
|
55
|
-
const { data, error
|
|
90
|
+
const { data, error } = useQuery(action, {
|
|
56
91
|
variables: { rawQueryStringified, limit: 0 }, // we only want aggs so limit=0 for no search results
|
|
57
92
|
skip: !rawQueryStringified
|
|
58
93
|
});
|
|
59
94
|
|
|
60
|
-
if (loading) return null;
|
|
61
95
|
if (error) return error.message;
|
|
62
96
|
if (!filters.length) return null;
|
|
63
97
|
|
|
64
|
-
const { searchPublishedContent: { rawResults: { aggregations: filterData
|
|
98
|
+
const { searchPublishedContent: { rawResults: { aggregations: filterData } = {} } = {} } =
|
|
65
99
|
data || {};
|
|
66
100
|
|
|
67
|
-
|
|
101
|
+
if (filterValues.dataNotSet && filterData) {
|
|
102
|
+
const initialFilterValues = getInitialFilterValues(filterData, filters, query);
|
|
103
|
+
dispatch({ newValues: initialFilterValues, shouldSearch: false, type: 'update' });
|
|
104
|
+
}
|
|
68
105
|
|
|
69
106
|
const handleSearch = newQuery => {
|
|
70
107
|
setDisplaySearchFilter(false);
|
|
@@ -93,17 +130,19 @@ const SearchFilterContainer = ({
|
|
|
93
130
|
window.scrollTo(0, 0);
|
|
94
131
|
}
|
|
95
132
|
};
|
|
133
|
+
if (!filterValues) return '';
|
|
96
134
|
|
|
97
135
|
return (
|
|
98
136
|
<SearchFilter
|
|
99
137
|
key={key}
|
|
138
|
+
setAppliedFilters={dispatch}
|
|
100
139
|
searchFilterRef={searchFilterRef}
|
|
101
140
|
data={filterData}
|
|
102
141
|
filters={filters}
|
|
103
142
|
hasUrl={hasUrl}
|
|
104
143
|
entity={entity}
|
|
105
144
|
handleSearch={handleSearch}
|
|
106
|
-
|
|
145
|
+
filterValues={filterValues}
|
|
107
146
|
name={name}
|
|
108
147
|
isCollapsedOnResponsive={isCollapsedOnResponsive}
|
|
109
148
|
displaySearchFilter={displaySearchFilter}
|
|
@@ -121,7 +160,10 @@ SearchFilterContainer.propTypes = {
|
|
|
121
160
|
name: PropTypes.string.isRequired,
|
|
122
161
|
isCollapsedOnResponsive: PropTypes.bool,
|
|
123
162
|
groupAfterMobile: PropTypes.number,
|
|
124
|
-
groupAfterDesktop: PropTypes.number
|
|
163
|
+
groupAfterDesktop: PropTypes.number,
|
|
164
|
+
filterBy: PropTypes.array,
|
|
165
|
+
filterByProperty: PropTypes.array,
|
|
166
|
+
shouldAddFilters: PropTypes.bool
|
|
125
167
|
};
|
|
126
168
|
|
|
127
169
|
SearchFilterContainer.defaultProps = {
|
|
@@ -130,7 +172,10 @@ SearchFilterContainer.defaultProps = {
|
|
|
130
172
|
entity: '',
|
|
131
173
|
isCollapsedOnResponsive: true,
|
|
132
174
|
groupAfterMobile: 0,
|
|
133
|
-
groupAfterDesktop: 0
|
|
175
|
+
groupAfterDesktop: 0,
|
|
176
|
+
filterBy: [],
|
|
177
|
+
filterByProperty: [],
|
|
178
|
+
shouldAddFilters: false
|
|
134
179
|
};
|
|
135
180
|
|
|
136
181
|
export default withTitle(SearchFilterContainer);
|
|
@@ -7,8 +7,17 @@ import { withTitle } from '../../../HOC';
|
|
|
7
7
|
import { decodeValue } from '../helpers';
|
|
8
8
|
import { LIMIT_MIN, LIMIT_MAX, MORE, LESS } from '../constants';
|
|
9
9
|
|
|
10
|
-
const Checkbox = ({
|
|
10
|
+
const Checkbox = ({
|
|
11
|
+
data,
|
|
12
|
+
prop,
|
|
13
|
+
updateFilterValues,
|
|
14
|
+
filterValues,
|
|
15
|
+
label,
|
|
16
|
+
shouldSearch,
|
|
17
|
+
displayFilterCount
|
|
18
|
+
}) => {
|
|
11
19
|
const [checkboxLimit, setCheckboxLimit] = useState(null);
|
|
20
|
+
if (!data[prop]) return null;
|
|
12
21
|
|
|
13
22
|
const handleCheckboxOptions = () => {
|
|
14
23
|
if (checkboxLimit[prop] === LIMIT_MIN) {
|
|
@@ -35,7 +44,10 @@ const Checkbox = ({ data, prop, updateFilterValues, filterValues, label, shouldS
|
|
|
35
44
|
const multiple = [];
|
|
36
45
|
|
|
37
46
|
const sortedValues = data[prop].buckets
|
|
38
|
-
.map(({ key }) =>
|
|
47
|
+
.map(({ key, doc_count: count }) => {
|
|
48
|
+
const optionLabel = displayFilterCount ? `${key} (${count})` : key;
|
|
49
|
+
return [key, optionLabel, !count];
|
|
50
|
+
})
|
|
39
51
|
.filter(Boolean)
|
|
40
52
|
.sort();
|
|
41
53
|
|
|
@@ -43,11 +55,12 @@ const Checkbox = ({ data, prop, updateFilterValues, filterValues, label, shouldS
|
|
|
43
55
|
(value, i) =>
|
|
44
56
|
i < checkboxLimit[prop] &&
|
|
45
57
|
multiple.push({
|
|
46
|
-
label: upperFirst(value),
|
|
47
|
-
value,
|
|
58
|
+
label: upperFirst(value[1]),
|
|
59
|
+
value: value[0],
|
|
48
60
|
name: prop,
|
|
49
|
-
checked: checkboxQueryParams.includes(value),
|
|
50
|
-
id: value
|
|
61
|
+
checked: checkboxQueryParams.includes(value[0]),
|
|
62
|
+
id: value[0],
|
|
63
|
+
disabled: value[2]
|
|
51
64
|
})
|
|
52
65
|
);
|
|
53
66
|
|
|
@@ -95,12 +108,14 @@ Checkbox.propTypes = {
|
|
|
95
108
|
filterValues: PropTypes.object.isRequired,
|
|
96
109
|
updateFilterValues: PropTypes.func.isRequired,
|
|
97
110
|
shouldSearch: PropTypes.bool,
|
|
98
|
-
label: PropTypes.string
|
|
111
|
+
label: PropTypes.string,
|
|
112
|
+
displayFilterCount: PropTypes.bool
|
|
99
113
|
};
|
|
100
114
|
|
|
101
115
|
Checkbox.defaultProps = {
|
|
102
116
|
shouldSearch: false,
|
|
103
|
-
label: ''
|
|
117
|
+
label: '',
|
|
118
|
+
displayFilterCount: false
|
|
104
119
|
};
|
|
105
120
|
|
|
106
121
|
export default withTitle(Checkbox);
|
|
@@ -11,17 +11,21 @@ const SelectFilter = ({
|
|
|
11
11
|
updateFilterValues,
|
|
12
12
|
filterValues,
|
|
13
13
|
shouldSearch,
|
|
14
|
-
displayLabelAsPlaceholder
|
|
14
|
+
displayLabelAsPlaceholder,
|
|
15
|
+
displayFilterCount
|
|
15
16
|
}) => {
|
|
16
17
|
const filterValue = filterValues[prop] || '';
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
18
|
+
const disabledOptions = [];
|
|
19
|
+
const { buckets = [] } = data[prop] || {};
|
|
20
|
+
const options = buckets
|
|
21
|
+
.map(({ key, doc_count: count }) => {
|
|
22
|
+
if (!count) disabledOptions.push(key);
|
|
23
|
+
const optionLabel = displayFilterCount ? `${key} (${count})` : key;
|
|
24
|
+
return [key, optionLabel];
|
|
25
|
+
})
|
|
20
26
|
.filter(Boolean)
|
|
21
27
|
.sort();
|
|
22
28
|
|
|
23
|
-
const optionsJoined = options;
|
|
24
|
-
|
|
25
29
|
const labelText = label || prop;
|
|
26
30
|
let labelToUse = labelText;
|
|
27
31
|
let defaultTextValue = DEFAULT_OPTION;
|
|
@@ -36,14 +40,14 @@ const SelectFilter = ({
|
|
|
36
40
|
value={filterValue}
|
|
37
41
|
id={prop}
|
|
38
42
|
data-testid={`filter-${prop}`}
|
|
39
|
-
options={
|
|
43
|
+
options={options}
|
|
40
44
|
defaultTextValue={defaultTextValue}
|
|
41
45
|
onChange={({ value }) => {
|
|
42
46
|
let valueToUse = value;
|
|
43
47
|
if (value === defaultTextValue) valueToUse = '';
|
|
44
|
-
|
|
45
48
|
updateFilterValues({ [prop]: valueToUse }, shouldSearch);
|
|
46
49
|
}}
|
|
50
|
+
disabled={disabledOptions}
|
|
47
51
|
/>
|
|
48
52
|
);
|
|
49
53
|
};
|
|
@@ -51,17 +55,20 @@ const SelectFilter = ({
|
|
|
51
55
|
SelectFilter.propTypes = {
|
|
52
56
|
data: PropTypes.object.isRequired,
|
|
53
57
|
prop: PropTypes.string.isRequired,
|
|
54
|
-
filterValues: PropTypes.object
|
|
58
|
+
filterValues: PropTypes.object,
|
|
55
59
|
updateFilterValues: PropTypes.func.isRequired,
|
|
56
60
|
shouldSearch: PropTypes.bool,
|
|
57
61
|
label: PropTypes.string,
|
|
58
|
-
displayLabelAsPlaceholder: PropTypes.bool
|
|
62
|
+
displayLabelAsPlaceholder: PropTypes.bool,
|
|
63
|
+
displayFilterCount: PropTypes.bool
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
SelectFilter.defaultProps = {
|
|
67
|
+
filterValues: {},
|
|
62
68
|
shouldSearch: false,
|
|
63
69
|
label: '',
|
|
64
|
-
displayLabelAsPlaceholder: false
|
|
70
|
+
displayLabelAsPlaceholder: false,
|
|
71
|
+
displayFilterCount: false
|
|
65
72
|
};
|
|
66
73
|
|
|
67
74
|
export default withTitle(SelectFilter);
|