@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.
Files changed (237) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/lib/BannerContext/index.js.map +1 -1
  3. package/lib/HOC/withInfiniteScroll.js.map +1 -1
  4. package/lib/HOC/withTitle.js.map +1 -1
  5. package/lib/PBContext/index.js.map +1 -1
  6. package/lib/application/query/index.js.map +1 -1
  7. package/lib/components/BackToTop/BackToTop.js.map +1 -1
  8. package/lib/components/Banner/AdSlotRender.js.map +1 -1
  9. package/lib/components/Banner/Banner.js.map +1 -1
  10. package/lib/components/Banner/BannerRender.js.map +1 -1
  11. package/lib/components/Banner/helpers.js.map +1 -1
  12. package/lib/components/Banner/index.js.map +1 -1
  13. package/lib/components/BlazeLink.js.map +1 -1
  14. package/lib/components/Breadcrumb/Breadcrumb.js.map +1 -1
  15. package/lib/components/Button.js.map +1 -1
  16. package/lib/components/Card/Card.js.map +1 -1
  17. package/lib/components/Card/CardContainer.js.map +1 -1
  18. package/lib/components/Card/CardFactory.js.map +1 -1
  19. package/lib/components/Card/CardRender.js.map +1 -1
  20. package/lib/components/Card/helpers/filter-query-setup.js.map +1 -1
  21. package/lib/components/Card/helpers/filters-setup.js.map +1 -1
  22. package/lib/components/Card/helpers/get-dynamic-grid-classes.js.map +1 -1
  23. package/lib/components/Carousel/Carousel.js.map +1 -1
  24. package/lib/components/Carousel/CarouselImage/CarouselImage.js.map +1 -1
  25. package/lib/components/Carousel/CarouselRender/CarouselRender.js.map +1 -1
  26. package/lib/components/CarouselWrapper.js.map +1 -1
  27. package/lib/components/ClickWrapper.js.map +1 -1
  28. package/lib/components/Code/Code.js.map +1 -1
  29. package/lib/components/Code/ScriptTag.js.map +1 -1
  30. package/lib/components/Code/helpers/wrap-script-tags.js.map +1 -1
  31. package/lib/components/DataSummary/DataSummaryFactory.js.map +1 -1
  32. package/lib/components/DataSummary/DataSummaryRender.js.map +1 -1
  33. package/lib/components/DataSummary/DataSummaryTypes/HeadingLargeSummary/HeadingLargeSummary.js.map +1 -1
  34. package/lib/components/DataSummary/DataSummaryTypes/HeadingLargeSummary/HeadingLargeSummaryContent.js.map +1 -1
  35. package/lib/components/DataSummary/DataSummaryTypes/ItemDetailsSummary/ItemDetailsSummary.js.map +1 -1
  36. package/lib/components/DataSummary/DataSummaryTypes/ItemDetailsSummary/ItemDetailsSummaryContent.js.map +1 -1
  37. package/lib/components/DataSummary/DataSummaryTypes/LargeSummary/LargeSummary.js.map +1 -1
  38. package/lib/components/DataSummary/DataSummaryTypes/LargeSummary/LargeSummaryContent.js.map +1 -1
  39. package/lib/components/DataSummary/DataSummaryTypes/ListSummary/ListSummary.js.map +1 -1
  40. package/lib/components/DataSummary/DataSummaryTypes/ListSummary/ListSummaryContent.js.map +1 -1
  41. package/lib/components/DataSummary/DataSummaryTypes/TextSummary/TextSummary.js.map +1 -1
  42. package/lib/components/DataSummary/DataSummaryTypes/TextSummary/TextSummaryContent.js.map +1 -1
  43. package/lib/components/DataSummary/DataSummaryTypes/index.js.map +1 -1
  44. package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
  45. package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
  46. package/lib/components/DataSummary/helpers/get-data-summary-query.js.map +1 -1
  47. package/lib/components/DataSummary/helpers/get-link-based-on-value.js.map +1 -1
  48. package/lib/components/DataSummary/helpers/get-prop-value.js.map +1 -1
  49. package/lib/components/DataSummary/helpers/get-value-from-array.js.map +1 -1
  50. package/lib/components/DataSummary/helpers/strip-summary-props-content.js.map +1 -1
  51. package/lib/components/EmailConfirm/EmailConfirm.js.map +1 -1
  52. package/lib/components/Image/GlobalLightbox/GlobalLightbox.js.map +1 -1
  53. package/lib/components/Image/GlobalLightbox/NavButton.js.map +1 -1
  54. package/lib/components/Image/GlobalLightbox/index.js.map +1 -1
  55. package/lib/components/Image/Image.js.map +1 -1
  56. package/lib/components/Image/ImageDetails.js.map +1 -1
  57. package/lib/components/Image/ImageFactory.js.map +1 -1
  58. package/lib/components/Image/ImageRender.js.map +1 -1
  59. package/lib/components/Image/Lightbox/Lightbox.js.map +1 -1
  60. package/lib/components/ItemListButton/ItemListButton.js.map +1 -1
  61. package/lib/components/ItemListCounter/ItemListCounter.js.map +1 -1
  62. package/lib/components/Layout/Layout.js.map +1 -1
  63. package/lib/components/Layout/helpers/check-if-row-has-columns.js.map +1 -1
  64. package/lib/components/LazyImage/LazyImage.js.map +1 -1
  65. package/lib/components/LazyImage/index.js.map +1 -1
  66. package/lib/components/List/ListBuilder.js.map +1 -1
  67. package/lib/components/List/ListFactory.js.map +1 -1
  68. package/lib/components/List/ListRender.js.map +1 -1
  69. package/lib/components/List/components/Cards/CardRenderWithInfiniteScroll.js.map +1 -1
  70. package/lib/components/List/components/Cards/CardsRender.js.map +1 -1
  71. package/lib/components/List/components/Cards/CardsRenderItem.js.map +1 -1
  72. package/lib/components/List/components/Cards/CardsRenderWrapper.js.map +1 -1
  73. package/lib/components/List/components/Full/FullRender.js.map +1 -1
  74. package/lib/components/List/components/Full/FullRenderItem.js.map +1 -1
  75. package/lib/components/List/components/Full/FullRenderWithInfiniteScroll.js.map +1 -1
  76. package/lib/components/List/components/Header/ListHeader.js.map +1 -1
  77. package/lib/components/List/components/Pagination/Classic.js.map +1 -1
  78. package/lib/components/List/components/Pagination/ListPagination.js.map +1 -1
  79. package/lib/components/List/components/Pagination/LoadMore.js.map +1 -1
  80. package/lib/components/List/helpers/build-az-aggregations.js.map +1 -1
  81. package/lib/components/List/helpers/build-az-url.js.map +1 -1
  82. package/lib/components/List/helpers/build-pagination-items.js.map +1 -1
  83. package/lib/components/List/helpers/build-pagination-url.js.map +1 -1
  84. package/lib/components/Login/LoggedInMessage.js.map +1 -1
  85. package/lib/components/Login/Login.js.map +1 -1
  86. package/lib/components/Login/LoginForm.js.map +1 -1
  87. package/lib/components/Menu/Menu.js +3 -1
  88. package/lib/components/Menu/Menu.js.map +1 -1
  89. package/lib/components/MenuItem/MenuItem.js.map +1 -1
  90. package/lib/components/Modal/Modal.js.map +1 -1
  91. package/lib/components/PasswordReset/PasswordReset.js.map +1 -1
  92. package/lib/components/PasswordReset/helpers/validatePassword.js.map +1 -1
  93. package/lib/components/PasswordResetRequest/PasswordResetRequest.js.map +1 -1
  94. package/lib/components/SearchContent/SearchContent.js +15 -7
  95. package/lib/components/SearchContent/SearchContent.js.map +1 -1
  96. package/lib/components/SearchContent/SearchContentItems.js +5 -2
  97. package/lib/components/SearchContent/SearchContentItems.js.map +1 -1
  98. package/lib/components/SearchFilter/SearchFilter/CloseMobileForm.js.map +1 -1
  99. package/lib/components/SearchFilter/SearchFilter/FiltersList.js +2 -4
  100. package/lib/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
  101. package/lib/components/SearchFilter/SearchFilter/MobileFormToolbar.js.map +1 -1
  102. package/lib/components/SearchFilter/SearchFilter/ResetDesktopForm.js.map +1 -1
  103. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +16 -44
  104. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  105. package/lib/components/SearchFilter/SearchFilterContainer.js +86 -21
  106. package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  107. package/lib/components/SearchFilter/components/Checkbox.js +17 -9
  108. package/lib/components/SearchFilter/components/Checkbox.js.map +1 -1
  109. package/lib/components/SearchFilter/components/Range.js.map +1 -1
  110. package/lib/components/SearchFilter/components/Select.js +27 -11
  111. package/lib/components/SearchFilter/components/Select.js.map +1 -1
  112. package/lib/components/SearchFilter/components/TextSearch.js +1 -5
  113. package/lib/components/SearchFilter/components/TextSearch.js.map +1 -1
  114. package/lib/components/SearchFilter/helpers/build-filters-query.js +87 -0
  115. package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -0
  116. package/lib/components/SearchFilter/helpers/build-query.js.map +1 -1
  117. package/lib/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
  118. package/lib/components/SearchFilter/helpers/build-raw-query-stringified.js.map +1 -1
  119. package/lib/components/SearchFilter/helpers/calculate-min-max.js.map +1 -1
  120. package/lib/components/SearchFilter/helpers/check-if-range-updated.js.map +1 -1
  121. package/lib/components/SearchFilter/helpers/get-filter-value-from-query.js.map +1 -1
  122. package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
  123. package/lib/components/SearchFilter/helpers/get-intersected-prop.js.map +1 -1
  124. package/lib/components/SearchFilter/helpers/get-range-value.js.map +1 -1
  125. package/lib/components/SearchFilter/helpers/get-responsive-filter-classnames.js.map +1 -1
  126. package/lib/components/SearchFilter/helpers/get-select-options.js.map +1 -1
  127. package/lib/components/SearchFilter/helpers/index.js +8 -0
  128. package/lib/components/SearchFilter/helpers/index.js.map +1 -1
  129. package/lib/components/SearchFilterSort/SearchFilterSort.js.map +1 -1
  130. package/lib/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
  131. package/lib/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
  132. package/lib/components/SocialFollow/SFItem.js.map +1 -1
  133. package/lib/components/SocialFollow/SocialFollow.js.map +1 -1
  134. package/lib/components/SocialFollow/SocialFollowRender.js.map +1 -1
  135. package/lib/components/SubMenu/SubMenu.js.map +1 -1
  136. package/lib/components/TextBlock/TextBlockRender.js.map +1 -1
  137. package/lib/components/TextBlock/index.js.map +1 -1
  138. package/lib/components/Video/Video.js.map +1 -1
  139. package/lib/components/Video/VideoModal.js.map +1 -1
  140. package/lib/components/Video/VideoRender.js.map +1 -1
  141. package/lib/components/Video/providers/Default.js.map +1 -1
  142. package/lib/components/Video/providers/JWPlayer/JWPlayerProvider.js.map +1 -1
  143. package/lib/components/Video/providers/YouTube/YouTubeProvider.js.map +1 -1
  144. package/lib/components/Video/providers/YouTube/YoutubeEmbeded.js.map +1 -1
  145. package/lib/components/Video/providers/get-provider.js.map +1 -1
  146. package/lib/components/Wrapper.js.map +1 -1
  147. package/lib/components/index.js.map +1 -1
  148. package/lib/helpers/build-inherited-filters.js.map +1 -1
  149. package/lib/helpers/build-raw-query-base.js.map +1 -1
  150. package/lib/helpers/build-raw-query.js.map +1 -1
  151. package/lib/helpers/build-search-values-checkbox-select.js.map +1 -1
  152. package/lib/helpers/check-props-to-use.js.map +1 -1
  153. package/lib/helpers/get-entities-with-banner.js.map +1 -1
  154. package/lib/helpers/get-entity-data.js.map +1 -1
  155. package/lib/helpers/get-entity-render-props.js.map +1 -1
  156. package/lib/helpers/get-filter-props.js.map +1 -1
  157. package/lib/helpers/get-generic-props.js.map +1 -1
  158. package/lib/helpers/get-generic-render-variables.js.map +1 -1
  159. package/lib/helpers/get-image-ids.js.map +1 -1
  160. package/lib/helpers/get-item-list-ids.js.map +1 -1
  161. package/lib/helpers/get-parsed-prop-values.js.map +1 -1
  162. package/lib/helpers/get-prop-values.js.map +1 -1
  163. package/lib/helpers/get-query-filters.js.map +1 -1
  164. package/lib/helpers/get-query-props.js.map +1 -1
  165. package/lib/helpers/get-updated-filter-by.js.map +1 -1
  166. package/lib/helpers/inject-banner.js.map +1 -1
  167. package/lib/helpers/inject-banners-to-entities.js.map +1 -1
  168. package/lib/helpers/inject-multiple-banners/get-banners-for-entities/get-banners-for-entities.js.map +1 -1
  169. package/lib/helpers/inject-multiple-banners/get-banners-for-nodes/get-banners-for-nodes.js.map +1 -1
  170. package/lib/helpers/inject-multiple-banners/get-banners-for-nodes/helpers/group-node-entities.js.map +1 -1
  171. package/lib/helpers/inject-multiple-banners/inject-multiple-banners.js.map +1 -1
  172. package/lib/helpers/is-filter-entitys-id.js.map +1 -1
  173. package/lib/helpers/parse-TextBlock.js.map +1 -1
  174. package/lib/helpers/parse-props-to-display.js.map +1 -1
  175. package/lib/helpers/render-children.js.map +1 -1
  176. package/lib/helpers/sort-response-data.js.map +1 -1
  177. package/lib/hooks/helpers/RenderComponent.js.map +1 -1
  178. package/lib/hooks/helpers/buildPBComponents.js.map +1 -1
  179. package/lib/hooks/helpers/getComponent.js.map +1 -1
  180. package/lib/hooks/helpers/inject-element-banners.js.map +1 -1
  181. package/lib/hooks/helpers/inject-textblock-banners.js.map +1 -1
  182. package/lib/hooks/helpers/insert-banners.js.map +1 -1
  183. package/lib/hooks/helpers/update-targetings.js.map +1 -1
  184. package/lib/hooks/use-banner-insertion.js.map +1 -1
  185. package/lib/hooks/use-check-mobile-screen.js.map +1 -1
  186. package/lib/hooks/use-get-entity-schema.js.map +1 -1
  187. package/lib/hooks/use-get-entity-schemas-as-obj.js.map +1 -1
  188. package/lib/hooks/use-get-image-id-from-relation.js.map +1 -1
  189. package/lib/hooks/use-get-images.js.map +1 -1
  190. package/lib/hooks/use-get-single-entity-schema.js.map +1 -1
  191. package/lib/hooks/use-page-builder.js.map +1 -1
  192. package/lib/utils/get-class-modifiers.js.map +1 -1
  193. package/lib/utils/get-image-data.js.map +1 -1
  194. package/lib-es/components/Menu/Menu.js +3 -1
  195. package/lib-es/components/Menu/Menu.js.map +1 -1
  196. package/lib-es/components/SearchContent/SearchContent.js +9 -5
  197. package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
  198. package/lib-es/components/SearchContent/SearchContentItems.js +4 -2
  199. package/lib-es/components/SearchContent/SearchContentItems.js.map +1 -1
  200. package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js +2 -4
  201. package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
  202. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +13 -38
  203. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  204. package/lib-es/components/SearchFilter/SearchFilterContainer.js +69 -14
  205. package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  206. package/lib-es/components/SearchFilter/components/Checkbox.js +17 -9
  207. package/lib-es/components/SearchFilter/components/Checkbox.js.map +1 -1
  208. package/lib-es/components/SearchFilter/components/Select.js +23 -8
  209. package/lib-es/components/SearchFilter/components/Select.js.map +1 -1
  210. package/lib-es/components/SearchFilter/components/TextSearch.js +1 -5
  211. package/lib-es/components/SearchFilter/components/TextSearch.js.map +1 -1
  212. package/lib-es/components/SearchFilter/helpers/build-filters-query.js +54 -0
  213. package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -0
  214. package/lib-es/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
  215. package/lib-es/components/SearchFilter/helpers/build-raw-query-stringified.js.map +1 -1
  216. package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
  217. package/lib-es/components/SearchFilter/helpers/index.js +2 -1
  218. package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
  219. package/package.json +3 -2
  220. package/src/components/Menu/Menu.js +5 -2
  221. package/src/components/SearchContent/SearchContent.js +9 -5
  222. package/src/components/SearchContent/SearchContentItems.js +7 -1
  223. package/src/components/SearchFilter/SearchFilter/FiltersList.js +30 -37
  224. package/src/components/SearchFilter/SearchFilter/SearchFilter.js +11 -25
  225. package/src/components/SearchFilter/SearchFilterContainer.js +56 -15
  226. package/src/components/SearchFilter/components/Checkbox.js +22 -8
  227. package/src/components/SearchFilter/components/Select.js +18 -11
  228. package/src/components/SearchFilter/components/TextSearch.js +1 -3
  229. package/src/components/SearchFilter/helpers/build-filters-query.js +40 -0
  230. package/src/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
  231. package/src/components/SearchFilter/helpers/get-initial-filter-values.js +1 -0
  232. package/src/components/SearchFilter/helpers/index.js +3 -1
  233. package/tests/unit/src/components/Menu/__snapshots__/Menu.test.js.snap +12 -11
  234. package/tests/unit/src/components/SearchFilter/SearchFilter/SearchFilter.test.js +3 -6
  235. package/tests/unit/src/components/SearchFilter/__snapshots__/SearchFilterContainer.test.js.snap +1 -7
  236. package/tests/unit/src/components/SearchFilter/components/__snapshots__/Checkbox.test.js.snap +2 -0
  237. 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 { buildNewQuery, buildRawQueryStringified, getInitialFilterValues } from './helpers';
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(router.asPath);
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
- rawQueryStringified = buildRawQueryStringified(checkboxSelectValues, rangeValues, docType);
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, loading } = useQuery(action, {
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
- const initialFilterValues = getInitialFilterValues(filterData, filters, query);
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
- initialFilterValues={initialFilterValues}
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 = ({ data, prop, updateFilterValues, filterValues, label, shouldSearch }) => {
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 }) => 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 options = data[prop].buckets
19
- .map(bucket => bucket.key)
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={optionsJoined}
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.isRequired,
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, handleSubmit, filterValues }) => (
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--desktop-wrapper"
6
+ class="menu--wrapper"
7
7
  >
8
- <ul
9
- class="menu-mod"
8
+ <div
9
+ class="menu--desktop-wrapper"
10
10
  >
11
- <div
12
- class="child_1"
11
+ <ul
12
+ class="menu-mod"
13
13
  >
14
- only child
15
- </div>
16
- <li>
17
- Search Component
18
- </li>
19
- </ul>
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
- initialFilterValues: {},
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,
@@ -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 />`;
@@ -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