@blaze-cms/react-page-builder 0.124.0-alpha.25 → 0.124.0-alpha.29
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 +32 -0
- package/lib/BannerContext/index.js.map +1 -1
- package/lib/HOC/withInfiniteScroll.js.map +1 -1
- package/lib/HOC/withTitle.js.map +1 -1
- package/lib/PBContext/index.js.map +1 -1
- package/lib/application/query/index.js.map +1 -1
- package/lib/components/BackToTop/BackToTop.js.map +1 -1
- package/lib/components/Banner/AdSlotRender.js.map +1 -1
- package/lib/components/Banner/Banner.js.map +1 -1
- package/lib/components/Banner/BannerRender.js.map +1 -1
- package/lib/components/Banner/helpers.js.map +1 -1
- package/lib/components/Banner/index.js.map +1 -1
- package/lib/components/BlazeLink.js.map +1 -1
- package/lib/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/lib/components/Button.js.map +1 -1
- package/lib/components/Card/Card.js.map +1 -1
- package/lib/components/Card/CardContainer.js.map +1 -1
- package/lib/components/Card/CardFactory.js.map +1 -1
- package/lib/components/Card/CardRender.js.map +1 -1
- package/lib/components/Card/helpers/filter-query-setup.js.map +1 -1
- package/lib/components/Card/helpers/filters-setup.js.map +1 -1
- package/lib/components/Card/helpers/get-dynamic-grid-classes.js.map +1 -1
- package/lib/components/Carousel/Carousel.js.map +1 -1
- package/lib/components/Carousel/CarouselImage/CarouselImage.js.map +1 -1
- package/lib/components/Carousel/CarouselRender/CarouselRender.js.map +1 -1
- package/lib/components/CarouselWrapper.js.map +1 -1
- package/lib/components/ClickWrapper.js.map +1 -1
- package/lib/components/Code/Code.js.map +1 -1
- package/lib/components/Code/ScriptTag.js.map +1 -1
- package/lib/components/Code/helpers/wrap-script-tags.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryFactory.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryRender.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/HeadingLargeSummary/HeadingLargeSummary.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/HeadingLargeSummary/HeadingLargeSummaryContent.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/ItemDetailsSummary/ItemDetailsSummary.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/ItemDetailsSummary/ItemDetailsSummaryContent.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/LargeSummary/LargeSummary.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/LargeSummary/LargeSummaryContent.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/ListSummary/ListSummary.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/ListSummary/ListSummaryContent.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/TextSummary/TextSummary.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/TextSummary/TextSummaryContent.js.map +1 -1
- package/lib/components/DataSummary/DataSummaryTypes/index.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
- package/lib/components/DataSummary/helpers/get-data-summary-query.js.map +1 -1
- package/lib/components/DataSummary/helpers/get-link-based-on-value.js.map +1 -1
- package/lib/components/DataSummary/helpers/get-prop-value.js.map +1 -1
- package/lib/components/DataSummary/helpers/get-value-from-array.js.map +1 -1
- package/lib/components/DataSummary/helpers/strip-summary-props-content.js.map +1 -1
- package/lib/components/EmailConfirm/EmailConfirm.js.map +1 -1
- package/lib/components/Image/GlobalLightbox/GlobalLightbox.js.map +1 -1
- package/lib/components/Image/GlobalLightbox/NavButton.js.map +1 -1
- package/lib/components/Image/GlobalLightbox/index.js.map +1 -1
- package/lib/components/Image/Image.js.map +1 -1
- package/lib/components/Image/ImageDetails.js.map +1 -1
- package/lib/components/Image/ImageFactory.js.map +1 -1
- package/lib/components/Image/ImageRender.js.map +1 -1
- package/lib/components/Image/Lightbox/Lightbox.js.map +1 -1
- package/lib/components/ItemListButton/ItemListButton.js.map +1 -1
- package/lib/components/ItemListCounter/ItemListCounter.js.map +1 -1
- package/lib/components/Layout/Layout.js.map +1 -1
- package/lib/components/Layout/helpers/check-if-row-has-columns.js.map +1 -1
- package/lib/components/LazyImage/LazyImage.js.map +1 -1
- package/lib/components/LazyImage/index.js.map +1 -1
- package/lib/components/List/ListBuilder.js.map +1 -1
- package/lib/components/List/ListFactory.js.map +1 -1
- package/lib/components/List/ListRender.js.map +1 -1
- package/lib/components/List/components/Cards/CardRenderWithInfiniteScroll.js.map +1 -1
- package/lib/components/List/components/Cards/CardsRender.js.map +1 -1
- package/lib/components/List/components/Cards/CardsRenderItem.js.map +1 -1
- package/lib/components/List/components/Cards/CardsRenderWrapper.js.map +1 -1
- package/lib/components/List/components/Full/FullRender.js.map +1 -1
- package/lib/components/List/components/Full/FullRenderItem.js.map +1 -1
- package/lib/components/List/components/Full/FullRenderWithInfiniteScroll.js.map +1 -1
- package/lib/components/List/components/Header/ListHeader.js.map +1 -1
- package/lib/components/List/components/Pagination/Classic.js.map +1 -1
- package/lib/components/List/components/Pagination/ListPagination.js.map +1 -1
- package/lib/components/List/components/Pagination/LoadMore.js.map +1 -1
- package/lib/components/List/helpers/build-az-aggregations.js.map +1 -1
- package/lib/components/List/helpers/build-az-url.js.map +1 -1
- package/lib/components/List/helpers/build-pagination-items.js.map +1 -1
- package/lib/components/List/helpers/build-pagination-url.js.map +1 -1
- package/lib/components/Login/LoggedInMessage.js.map +1 -1
- package/lib/components/Login/Login.js.map +1 -1
- package/lib/components/Login/LoginForm.js.map +1 -1
- package/lib/components/Menu/Menu.js +3 -1
- package/lib/components/Menu/Menu.js.map +1 -1
- package/lib/components/MenuItem/MenuItem.js.map +1 -1
- package/lib/components/Modal/Modal.js.map +1 -1
- package/lib/components/PasswordReset/PasswordReset.js.map +1 -1
- package/lib/components/PasswordReset/helpers/validatePassword.js.map +1 -1
- package/lib/components/PasswordResetRequest/PasswordResetRequest.js.map +1 -1
- package/lib/components/SearchContent/SearchContent.js +15 -7
- package/lib/components/SearchContent/SearchContent.js.map +1 -1
- package/lib/components/SearchContent/SearchContentItems.js +5 -2
- package/lib/components/SearchContent/SearchContentItems.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/CloseMobileForm.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/MobileFormToolbar.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/ResetDesktopForm.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +16 -44
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +86 -21
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/components/Checkbox.js +17 -9
- package/lib/components/SearchFilter/components/Checkbox.js.map +1 -1
- package/lib/components/SearchFilter/components/Range.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.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/calculate-min-max.js.map +1 -1
- package/lib/components/SearchFilter/helpers/check-if-range-updated.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-filter-value-from-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-intersected-prop.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-range-value.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-responsive-filter-classnames.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-select-options.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/SearchFilterSort/SearchFilterSort.js.map +1 -1
- package/lib/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
- package/lib/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
- package/lib/components/SocialFollow/SFItem.js.map +1 -1
- package/lib/components/SocialFollow/SocialFollow.js.map +1 -1
- package/lib/components/SocialFollow/SocialFollowRender.js.map +1 -1
- package/lib/components/SubMenu/SubMenu.js.map +1 -1
- package/lib/components/TextBlock/TextBlockRender.js.map +1 -1
- package/lib/components/TextBlock/index.js.map +1 -1
- package/lib/components/Video/Video.js.map +1 -1
- package/lib/components/Video/VideoModal.js.map +1 -1
- package/lib/components/Video/VideoRender.js.map +1 -1
- package/lib/components/Video/providers/Default.js.map +1 -1
- package/lib/components/Video/providers/JWPlayer/JWPlayerProvider.js.map +1 -1
- package/lib/components/Video/providers/YouTube/YouTubeProvider.js.map +1 -1
- package/lib/components/Video/providers/YouTube/YoutubeEmbeded.js.map +1 -1
- package/lib/components/Video/providers/get-provider.js.map +1 -1
- package/lib/components/Wrapper.js.map +1 -1
- package/lib/components/index.js.map +1 -1
- package/lib/helpers/build-inherited-filters.js.map +1 -1
- package/lib/helpers/build-raw-query-base.js.map +1 -1
- package/lib/helpers/build-raw-query.js.map +1 -1
- package/lib/helpers/build-search-values-checkbox-select.js.map +1 -1
- package/lib/helpers/check-props-to-use.js.map +1 -1
- package/lib/helpers/get-entities-with-banner.js.map +1 -1
- package/lib/helpers/get-entity-data.js.map +1 -1
- package/lib/helpers/get-entity-render-props.js.map +1 -1
- package/lib/helpers/get-filter-props.js.map +1 -1
- package/lib/helpers/get-generic-props.js.map +1 -1
- package/lib/helpers/get-generic-render-variables.js.map +1 -1
- package/lib/helpers/get-image-ids.js.map +1 -1
- package/lib/helpers/get-item-list-ids.js.map +1 -1
- package/lib/helpers/get-parsed-prop-values.js.map +1 -1
- package/lib/helpers/get-prop-values.js.map +1 -1
- package/lib/helpers/get-query-filters.js.map +1 -1
- package/lib/helpers/get-query-props.js.map +1 -1
- package/lib/helpers/get-updated-filter-by.js.map +1 -1
- package/lib/helpers/inject-banner.js.map +1 -1
- package/lib/helpers/inject-banners-to-entities.js.map +1 -1
- package/lib/helpers/inject-multiple-banners/get-banners-for-entities/get-banners-for-entities.js.map +1 -1
- package/lib/helpers/inject-multiple-banners/get-banners-for-nodes/get-banners-for-nodes.js.map +1 -1
- package/lib/helpers/inject-multiple-banners/get-banners-for-nodes/helpers/group-node-entities.js.map +1 -1
- package/lib/helpers/inject-multiple-banners/inject-multiple-banners.js.map +1 -1
- package/lib/helpers/is-filter-entitys-id.js.map +1 -1
- package/lib/helpers/parse-TextBlock.js.map +1 -1
- package/lib/helpers/parse-props-to-display.js.map +1 -1
- package/lib/helpers/render-children.js.map +1 -1
- package/lib/helpers/sort-response-data.js.map +1 -1
- package/lib/hooks/helpers/RenderComponent.js.map +1 -1
- package/lib/hooks/helpers/buildPBComponents.js.map +1 -1
- package/lib/hooks/helpers/getComponent.js.map +1 -1
- package/lib/hooks/helpers/inject-element-banners.js.map +1 -1
- package/lib/hooks/helpers/inject-textblock-banners.js.map +1 -1
- package/lib/hooks/helpers/insert-banners.js.map +1 -1
- package/lib/hooks/helpers/update-targetings.js.map +1 -1
- package/lib/hooks/use-banner-insertion.js.map +1 -1
- package/lib/hooks/use-check-mobile-screen.js.map +1 -1
- package/lib/hooks/use-get-entity-schema.js.map +1 -1
- package/lib/hooks/use-get-entity-schemas-as-obj.js.map +1 -1
- package/lib/hooks/use-get-image-id-from-relation.js.map +1 -1
- package/lib/hooks/use-get-images.js.map +1 -1
- package/lib/hooks/use-get-single-entity-schema.js.map +1 -1
- package/lib/hooks/use-page-builder.js.map +1 -1
- package/lib/utils/get-class-modifiers.js.map +1 -1
- package/lib/utils/get-image-data.js.map +1 -1
- package/lib-es/components/Menu/Menu.js +3 -1
- package/lib-es/components/Menu/Menu.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContent.js +9 -5
- package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContentItems.js +4 -2
- package/lib-es/components/SearchContent/SearchContentItems.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 +13 -38
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +69 -14
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/components/Checkbox.js +17 -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-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.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/package.json +3 -2
- package/src/components/Menu/Menu.js +5 -2
- package/src/components/SearchContent/SearchContent.js +9 -5
- package/src/components/SearchContent/SearchContentItems.js +7 -1
- package/src/components/SearchFilter/SearchFilter/FiltersList.js +30 -37
- package/src/components/SearchFilter/SearchFilter/SearchFilter.js +11 -25
- package/src/components/SearchFilter/SearchFilterContainer.js +56 -15
- package/src/components/SearchFilter/components/Checkbox.js +22 -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-raw-query-stringified.js +2 -1
- package/src/components/SearchFilter/helpers/get-initial-filter-values.js +1 -0
- package/src/components/SearchFilter/helpers/index.js +3 -1
- package/tests/unit/src/components/Menu/__snapshots__/Menu.test.js.snap +12 -11
- package/tests/unit/src/components/SearchFilter/SearchFilter/SearchFilter.test.js +3 -6
- package/tests/unit/src/components/SearchFilter/__snapshots__/SearchFilterContainer.test.js.snap +1 -7
- 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
|
@@ -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,27 @@ 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);
|
|
51
|
+
const [filterValues, dispatch] = useReducer(reducer, null);
|
|
27
52
|
const hasUrl = !!url;
|
|
28
53
|
const {
|
|
29
54
|
url: currentUrl,
|
|
30
55
|
query: { sort, sortby },
|
|
31
56
|
query
|
|
32
|
-
} = parseUrl(
|
|
57
|
+
} = parseUrl(asPath);
|
|
33
58
|
const sortValues = sort && sortby ? stringify({ sort, sortby }) : '';
|
|
34
59
|
const baseQuery = sortValues ? `${currentUrl}?${sortValues}` : currentUrl;
|
|
35
60
|
|
|
36
61
|
const action = getSearchPublishedContent(RAW_RESULTS);
|
|
37
|
-
|
|
38
|
-
let rawQueryStringified = '';
|
|
39
|
-
|
|
40
62
|
const checkboxSelectValues = [];
|
|
41
63
|
const rangeValues = [];
|
|
42
64
|
|
|
@@ -50,21 +72,32 @@ const SearchFilterContainer = ({
|
|
|
50
72
|
|
|
51
73
|
const { docType } = getEntityData(entity);
|
|
52
74
|
|
|
53
|
-
|
|
75
|
+
const filtersQuery = shouldAddFilters
|
|
76
|
+
? buildFiltersQuery(filters || query, filterBy, filterByProperty)
|
|
77
|
+
: [];
|
|
78
|
+
|
|
79
|
+
const rawQueryStringified = buildRawQueryStringified(
|
|
80
|
+
checkboxSelectValues,
|
|
81
|
+
rangeValues,
|
|
82
|
+
docType,
|
|
83
|
+
filtersQuery
|
|
84
|
+
);
|
|
54
85
|
|
|
55
|
-
const { data, error
|
|
86
|
+
const { data, error } = useQuery(action, {
|
|
56
87
|
variables: { rawQueryStringified, limit: 0 }, // we only want aggs so limit=0 for no search results
|
|
57
88
|
skip: !rawQueryStringified
|
|
58
89
|
});
|
|
59
90
|
|
|
60
|
-
if (loading) return null;
|
|
61
91
|
if (error) return error.message;
|
|
62
92
|
if (!filters.length) return null;
|
|
63
93
|
|
|
64
|
-
const { searchPublishedContent: { rawResults: { aggregations: filterData
|
|
94
|
+
const { searchPublishedContent: { rawResults: { aggregations: filterData } = {} } = {} } =
|
|
65
95
|
data || {};
|
|
66
96
|
|
|
67
|
-
|
|
97
|
+
if (!filterValues && filterData) {
|
|
98
|
+
const initialFilterValues = getInitialFilterValues(filterData, filters, query);
|
|
99
|
+
dispatch({ newValues: initialFilterValues, shouldSearch: false, type: 'update' });
|
|
100
|
+
}
|
|
68
101
|
|
|
69
102
|
const handleSearch = newQuery => {
|
|
70
103
|
setDisplaySearchFilter(false);
|
|
@@ -93,17 +126,19 @@ const SearchFilterContainer = ({
|
|
|
93
126
|
window.scrollTo(0, 0);
|
|
94
127
|
}
|
|
95
128
|
};
|
|
129
|
+
if (!filterValues) return '';
|
|
96
130
|
|
|
97
131
|
return (
|
|
98
132
|
<SearchFilter
|
|
99
133
|
key={key}
|
|
134
|
+
setAppliedFilters={dispatch}
|
|
100
135
|
searchFilterRef={searchFilterRef}
|
|
101
136
|
data={filterData}
|
|
102
137
|
filters={filters}
|
|
103
138
|
hasUrl={hasUrl}
|
|
104
139
|
entity={entity}
|
|
105
140
|
handleSearch={handleSearch}
|
|
106
|
-
|
|
141
|
+
filterValues={filterValues}
|
|
107
142
|
name={name}
|
|
108
143
|
isCollapsedOnResponsive={isCollapsedOnResponsive}
|
|
109
144
|
displaySearchFilter={displaySearchFilter}
|
|
@@ -121,7 +156,10 @@ SearchFilterContainer.propTypes = {
|
|
|
121
156
|
name: PropTypes.string.isRequired,
|
|
122
157
|
isCollapsedOnResponsive: PropTypes.bool,
|
|
123
158
|
groupAfterMobile: PropTypes.number,
|
|
124
|
-
groupAfterDesktop: PropTypes.number
|
|
159
|
+
groupAfterDesktop: PropTypes.number,
|
|
160
|
+
filterBy: PropTypes.array,
|
|
161
|
+
filterByProperty: PropTypes.array,
|
|
162
|
+
shouldAddFilters: PropTypes.bool
|
|
125
163
|
};
|
|
126
164
|
|
|
127
165
|
SearchFilterContainer.defaultProps = {
|
|
@@ -130,7 +168,10 @@ SearchFilterContainer.defaultProps = {
|
|
|
130
168
|
entity: '',
|
|
131
169
|
isCollapsedOnResponsive: true,
|
|
132
170
|
groupAfterMobile: 0,
|
|
133
|
-
groupAfterDesktop: 0
|
|
171
|
+
groupAfterDesktop: 0,
|
|
172
|
+
filterBy: [],
|
|
173
|
+
filterByProperty: [],
|
|
174
|
+
shouldAddFilters: false
|
|
134
175
|
};
|
|
135
176
|
|
|
136
177
|
export default withTitle(SearchFilterContainer);
|
|
@@ -7,7 +7,15 @@ 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);
|
|
12
20
|
|
|
13
21
|
const handleCheckboxOptions = () => {
|
|
@@ -35,7 +43,10 @@ const Checkbox = ({ data, prop, updateFilterValues, filterValues, label, shouldS
|
|
|
35
43
|
const multiple = [];
|
|
36
44
|
|
|
37
45
|
const sortedValues = data[prop].buckets
|
|
38
|
-
.map(({ key }) =>
|
|
46
|
+
.map(({ key, doc_count: count }) => {
|
|
47
|
+
const optionLabel = displayFilterCount ? `${key} (${count})` : key;
|
|
48
|
+
return [key, optionLabel, !count];
|
|
49
|
+
})
|
|
39
50
|
.filter(Boolean)
|
|
40
51
|
.sort();
|
|
41
52
|
|
|
@@ -43,11 +54,12 @@ const Checkbox = ({ data, prop, updateFilterValues, filterValues, label, shouldS
|
|
|
43
54
|
(value, i) =>
|
|
44
55
|
i < checkboxLimit[prop] &&
|
|
45
56
|
multiple.push({
|
|
46
|
-
label: upperFirst(value),
|
|
47
|
-
value,
|
|
57
|
+
label: upperFirst(value[1]),
|
|
58
|
+
value: value[0],
|
|
48
59
|
name: prop,
|
|
49
|
-
checked: checkboxQueryParams.includes(value),
|
|
50
|
-
id: value
|
|
60
|
+
checked: checkboxQueryParams.includes(value[0]),
|
|
61
|
+
id: value[0],
|
|
62
|
+
disabled: value[2]
|
|
51
63
|
})
|
|
52
64
|
);
|
|
53
65
|
|
|
@@ -95,12 +107,14 @@ Checkbox.propTypes = {
|
|
|
95
107
|
filterValues: PropTypes.object.isRequired,
|
|
96
108
|
updateFilterValues: PropTypes.func.isRequired,
|
|
97
109
|
shouldSearch: PropTypes.bool,
|
|
98
|
-
label: PropTypes.string
|
|
110
|
+
label: PropTypes.string,
|
|
111
|
+
displayFilterCount: PropTypes.bool
|
|
99
112
|
};
|
|
100
113
|
|
|
101
114
|
Checkbox.defaultProps = {
|
|
102
115
|
shouldSearch: false,
|
|
103
|
-
label: ''
|
|
116
|
+
label: '',
|
|
117
|
+
displayFilterCount: false
|
|
104
118
|
};
|
|
105
119
|
|
|
106
120
|
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);
|
|
@@ -5,7 +5,7 @@ import { MdSearch } from 'react-icons/md';
|
|
|
5
5
|
import { withTitle } from '../../../HOC';
|
|
6
6
|
import { SEARCH_TERM } from '../constants';
|
|
7
7
|
|
|
8
|
-
const TextSearch = ({ label, searchValue, updateFilterValues
|
|
8
|
+
const TextSearch = ({ label, searchValue, updateFilterValues }) => (
|
|
9
9
|
<div className="search">
|
|
10
10
|
<div className="search__wrapper">
|
|
11
11
|
<div className="form-field form-field--input form-field--search">
|
|
@@ -34,10 +34,8 @@ const TextSearch = ({ label, searchValue, updateFilterValues, handleSubmit, filt
|
|
|
34
34
|
);
|
|
35
35
|
|
|
36
36
|
TextSearch.propTypes = {
|
|
37
|
-
filterValues: PropTypes.object.isRequired,
|
|
38
37
|
searchValue: PropTypes.string.isRequired,
|
|
39
38
|
updateFilterValues: PropTypes.func.isRequired,
|
|
40
|
-
handleSubmit: PropTypes.func.isRequired,
|
|
41
39
|
label: PropTypes.string
|
|
42
40
|
};
|
|
43
41
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const builFilterObject = (key, value, filters) => {
|
|
2
|
+
const isArray = Array.isArray(value);
|
|
3
|
+
if (!isArray) {
|
|
4
|
+
const singleFilterObj = { match: { [key]: value } };
|
|
5
|
+
filters.push(singleFilterObj);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
value.forEach(filterValue => {
|
|
10
|
+
filters.push({ match: { [key]: filterValue } });
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
const buildFiltersQuery = (query, filterBy, filterByProperty) => {
|
|
14
|
+
const mustFilters = [];
|
|
15
|
+
Object.keys(query).forEach(queryKey => {
|
|
16
|
+
if (queryKey === 'search_term' || queryKey === 'shouldSearch') return;
|
|
17
|
+
if (!queryKey || !query[queryKey]) return;
|
|
18
|
+
const queryValue = query[queryKey];
|
|
19
|
+
const queryKeyword = `${queryKey}.keyword`;
|
|
20
|
+
builFilterObject(queryKeyword, queryValue, mustFilters);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (filterByProperty && filterByProperty.length) {
|
|
24
|
+
filterByProperty &&
|
|
25
|
+
filterByProperty.forEach(filterByPropOption => {
|
|
26
|
+
const [filterByPropKey] = filterByPropOption.split('/');
|
|
27
|
+
filterBy.forEach(filterByOption => {
|
|
28
|
+
if (filterByOption.indexOf(filterByPropKey) === -1) return;
|
|
29
|
+
const [, filteryByValue] = filterByOption.split('/');
|
|
30
|
+
const filterByKeyword = `${filterByPropKey}.keyword`;
|
|
31
|
+
if (!filteryByValue) return;
|
|
32
|
+
mustFilters.push({ match: { [filterByKeyword]: filteryByValue } });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return mustFilters;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default buildFiltersQuery;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KEYWORD, SIZE } from '../constants';
|
|
2
2
|
|
|
3
|
-
const buildRawQueryStringified = (checkboxSelectValues, rangeValues, entity) => {
|
|
3
|
+
const buildRawQueryStringified = (checkboxSelectValues, rangeValues, entity, mustFilters) => {
|
|
4
4
|
if (!checkboxSelectValues.length && !rangeValues.length) return '';
|
|
5
5
|
|
|
6
6
|
const aggs = {};
|
|
@@ -36,6 +36,7 @@ const buildRawQueryStringified = (checkboxSelectValues, rangeValues, entity) =>
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
],
|
|
39
|
+
must: mustFilters,
|
|
39
40
|
minimum_should_match: 1
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -3,6 +3,7 @@ import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
|
3
3
|
|
|
4
4
|
const getInitialFilterValues = (filterData, filters, query) => {
|
|
5
5
|
const filterValues = {};
|
|
6
|
+
|
|
6
7
|
Object.keys(filterData).forEach(key => {
|
|
7
8
|
const filterProps =
|
|
8
9
|
filters.find(({ propsToDisplay }) => propsToDisplay.find(prop => key === prop)) || {};
|
|
@@ -13,6 +13,7 @@ import isDeviceDesktop from './is-device-desktop';
|
|
|
13
13
|
import getInitialFilterValues from './get-initial-filter-values';
|
|
14
14
|
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
15
15
|
import buildQuery from './build-query';
|
|
16
|
+
import buildFiltersQuery from './build-filters-query';
|
|
16
17
|
|
|
17
18
|
export {
|
|
18
19
|
buildQuery,
|
|
@@ -30,5 +31,6 @@ export {
|
|
|
30
31
|
getSelectOptions,
|
|
31
32
|
isDeviceDesktop,
|
|
32
33
|
getInitialFilterValues,
|
|
33
|
-
getFilterValueFromQuery
|
|
34
|
+
getFilterValueFromQuery,
|
|
35
|
+
buildFiltersQuery
|
|
34
36
|
};
|
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
exports[`Menu component should render without throwing an error and match snapshot 1`] = `
|
|
4
4
|
<DocumentFragment>
|
|
5
5
|
<div
|
|
6
|
-
class="menu--
|
|
6
|
+
class="menu--wrapper"
|
|
7
7
|
>
|
|
8
|
-
<
|
|
9
|
-
class="menu-
|
|
8
|
+
<div
|
|
9
|
+
class="menu--desktop-wrapper"
|
|
10
10
|
>
|
|
11
|
-
<
|
|
12
|
-
class="
|
|
11
|
+
<ul
|
|
12
|
+
class="menu-mod"
|
|
13
13
|
>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
<div
|
|
15
|
+
class="child_1"
|
|
16
|
+
>
|
|
17
|
+
only child
|
|
18
|
+
</div>
|
|
19
|
+
</ul>
|
|
20
|
+
</div>
|
|
20
21
|
</div>
|
|
21
22
|
</DocumentFragment>
|
|
22
23
|
`;
|
|
@@ -11,7 +11,7 @@ const renderComponent = (Component, props) => {
|
|
|
11
11
|
|
|
12
12
|
const mockedProps = {
|
|
13
13
|
data: {},
|
|
14
|
-
|
|
14
|
+
filterValues: {},
|
|
15
15
|
filters: [],
|
|
16
16
|
searchFilterRef: {},
|
|
17
17
|
buttonRef: { current: null },
|
|
@@ -24,14 +24,11 @@ const mockedProps = {
|
|
|
24
24
|
groupAfterMobile: 0,
|
|
25
25
|
groupAfterDesktop: 0,
|
|
26
26
|
isCollapsedOnResponsive: true,
|
|
27
|
-
displaySearchFilter: false
|
|
27
|
+
displaySearchFilter: false,
|
|
28
|
+
setAppliedFilters: jest.fn()
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
describe('SearchFilter component', () => {
|
|
31
|
-
it('should be defined', () => {
|
|
32
|
-
expect(SearchFilter).toBeDefined();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
32
|
describe('when isCollapsedOnResponsive = true, displaySearchFilter = false', () => {
|
|
36
33
|
const specificMockedProps = {
|
|
37
34
|
...mockedProps,
|
package/tests/unit/src/components/SearchFilter/__snapshots__/SearchFilterContainer.test.js.snap
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`SearchFilter container should match snapshot 1`] =
|
|
4
|
-
<DocumentFragment>
|
|
5
|
-
<div>
|
|
6
|
-
Mocked component
|
|
7
|
-
</div>
|
|
8
|
-
</DocumentFragment>
|
|
9
|
-
`;
|
|
3
|
+
exports[`SearchFilter container should match snapshot 1`] = `<DocumentFragment />`;
|
|
10
4
|
|
|
11
5
|
exports[`SearchFilter container should return null if no filters are passed 1`] = `<DocumentFragment />`;
|
package/tests/unit/src/components/SearchFilter/components/__snapshots__/Checkbox.test.js.snap
CHANGED
|
@@ -10,6 +10,7 @@ exports[`Checkbox component should render without throwing an error match snapsh
|
|
|
10
10
|
class="form-checkbox"
|
|
11
11
|
data-cy="checkbox-cy-1"
|
|
12
12
|
data-testid="checkbox-1"
|
|
13
|
+
disabled=""
|
|
13
14
|
id="name1-checkbox"
|
|
14
15
|
name="name"
|
|
15
16
|
readonly=""
|
|
@@ -36,6 +37,7 @@ exports[`Checkbox component should render without throwing an error match snapsh
|
|
|
36
37
|
class="form-checkbox"
|
|
37
38
|
data-cy="checkbox-cy-2"
|
|
38
39
|
data-testid="checkbox-2"
|
|
40
|
+
disabled=""
|
|
39
41
|
id="name2-checkbox"
|
|
40
42
|
name="name"
|
|
41
43
|
readonly=""
|
|
@@ -13,11 +13,13 @@ exports[`Select component should display label as placeholder with no label tag
|
|
|
13
13
|
Placeholder label
|
|
14
14
|
</option>
|
|
15
15
|
<option
|
|
16
|
+
disabled=""
|
|
16
17
|
value="name1"
|
|
17
18
|
>
|
|
18
19
|
name1
|
|
19
20
|
</option>
|
|
20
21
|
<option
|
|
22
|
+
disabled=""
|
|
21
23
|
value="name2"
|
|
22
24
|
>
|
|
23
25
|
name2
|
|
@@ -46,11 +48,13 @@ exports[`Select component should render witout throwing an error and match snaps
|
|
|
46
48
|
Any
|
|
47
49
|
</option>
|
|
48
50
|
<option
|
|
51
|
+
disabled=""
|
|
49
52
|
value="name1"
|
|
50
53
|
>
|
|
51
54
|
name1
|
|
52
55
|
</option>
|
|
53
56
|
<option
|
|
57
|
+
disabled=""
|
|
54
58
|
value="name2"
|
|
55
59
|
>
|
|
56
60
|
name2
|