@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.
Files changed (279) hide show
  1. package/CHANGELOG.md +303 -0
  2. package/README.md +8 -0
  3. package/lib/application/query/index.js +8 -2
  4. package/lib/application/query/index.js.map +1 -1
  5. package/lib/components/Button.js +18 -5
  6. package/lib/components/Button.js.map +1 -1
  7. package/lib/components/Card/CardContainer.js +3 -7
  8. package/lib/components/Card/CardContainer.js.map +1 -1
  9. package/lib/components/Card/CardFactory.js +6 -3
  10. package/lib/components/Card/CardFactory.js.map +1 -1
  11. package/lib/components/CarouselWrapper.js +2 -2
  12. package/lib/components/CarouselWrapper.js.map +1 -1
  13. package/lib/components/Image/ImageRender.js +5 -1
  14. package/lib/components/Image/ImageRender.js.map +1 -1
  15. package/lib/components/ItemList/ItemListButton/ItemListButton.js +161 -0
  16. package/lib/components/ItemList/ItemListButton/ItemListButton.js.map +1 -0
  17. package/lib/components/ItemList/ItemListButton/index.js +16 -0
  18. package/lib/components/ItemList/ItemListButton/index.js.map +1 -0
  19. package/lib/components/ItemList/ItemListCounter/ItemListCounter.js +83 -0
  20. package/lib/components/ItemList/ItemListCounter/ItemListCounter.js.map +1 -0
  21. package/lib/components/ItemList/ItemListCounter/index.js +16 -0
  22. package/lib/components/ItemList/ItemListCounter/index.js.map +1 -0
  23. package/lib/components/ItemList/ItemListNew/ItemListNew.js +87 -0
  24. package/lib/components/ItemList/ItemListNew/ItemListNew.js.map +1 -0
  25. package/lib/components/ItemList/ItemListNew/index.js +16 -0
  26. package/lib/components/ItemList/ItemListNew/index.js.map +1 -0
  27. package/lib/components/ItemList/constants.js +19 -0
  28. package/lib/components/ItemList/constants.js.map +1 -0
  29. package/lib/components/ItemList/helpers/get-item-list-data.js +17 -0
  30. package/lib/components/ItemList/helpers/get-item-list-data.js.map +1 -0
  31. package/lib/components/ItemList/helpers/get-item-list-id.js +23 -0
  32. package/lib/components/ItemList/helpers/get-item-list-id.js.map +1 -0
  33. package/lib/components/ItemList/helpers/get-item-list-ids.js +28 -0
  34. package/lib/components/ItemList/helpers/get-item-list-ids.js.map +1 -0
  35. package/lib/components/ItemList/helpers/index.js +50 -0
  36. package/lib/components/ItemList/helpers/index.js.map +1 -0
  37. package/lib/components/ItemList/helpers/set-item-list-id.js +22 -0
  38. package/lib/components/ItemList/helpers/set-item-list-id.js.map +1 -0
  39. package/lib/components/ItemList/helpers/set-param-and-redirect.js +51 -0
  40. package/lib/components/ItemList/helpers/set-param-and-redirect.js.map +1 -0
  41. package/lib/components/ItemList/hooks/index.js +18 -0
  42. package/lib/components/ItemList/hooks/index.js.map +1 -0
  43. package/lib/components/ItemList/hooks/use-item-list-id.js +45 -0
  44. package/lib/components/ItemList/hooks/use-item-list-id.js.map +1 -0
  45. package/lib/components/LazyImage/LazyImage.js +5 -1
  46. package/lib/components/LazyImage/LazyImage.js.map +1 -1
  47. package/lib/components/List/ListBuilder.js +12 -6
  48. package/lib/components/List/ListBuilder.js.map +1 -1
  49. package/lib/components/List/ListFactory.js +34 -7
  50. package/lib/components/List/ListFactory.js.map +1 -1
  51. package/lib/components/List/helpers/has-required-item-list-details.js +29 -0
  52. package/lib/components/List/helpers/has-required-item-list-details.js.map +1 -0
  53. package/lib/components/List/helpers/index.js +8 -0
  54. package/lib/components/List/helpers/index.js.map +1 -1
  55. package/lib/components/Menu/Menu.js +41 -28
  56. package/lib/components/Menu/Menu.js.map +1 -1
  57. package/lib/components/Menu/MenuContext.js +20 -0
  58. package/lib/components/Menu/MenuContext.js.map +1 -0
  59. package/lib/components/MenuItem/MenuItem.js +26 -7
  60. package/lib/components/MenuItem/MenuItem.js.map +1 -1
  61. package/lib/components/SearchContent/SearchContent.js +183 -0
  62. package/lib/components/SearchContent/SearchContent.js.map +1 -0
  63. package/lib/components/SearchContent/SearchContentItems.js +51 -0
  64. package/lib/components/SearchContent/SearchContentItems.js.map +1 -0
  65. package/lib/components/SearchContent/SearchContentResults.js +45 -0
  66. package/lib/components/SearchContent/SearchContentResults.js.map +1 -0
  67. package/lib/components/SearchContent/SearchContentToggleIcon.js +42 -0
  68. package/lib/components/SearchContent/SearchContentToggleIcon.js.map +1 -0
  69. package/lib/components/SearchContent/index.js +2 -301
  70. package/lib/components/SearchContent/index.js.map +1 -1
  71. package/lib/components/SearchFilter/SearchFilter/FiltersList.js +2 -4
  72. package/lib/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
  73. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +16 -66
  74. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  75. package/lib/components/SearchFilter/SearchFilterContainer.js +87 -23
  76. package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  77. package/lib/components/SearchFilter/components/Checkbox.js +19 -9
  78. package/lib/components/SearchFilter/components/Checkbox.js.map +1 -1
  79. package/lib/components/SearchFilter/components/Select.js +27 -11
  80. package/lib/components/SearchFilter/components/Select.js.map +1 -1
  81. package/lib/components/SearchFilter/components/TextSearch.js +1 -5
  82. package/lib/components/SearchFilter/components/TextSearch.js.map +1 -1
  83. package/lib/components/SearchFilter/helpers/build-filters-query.js +87 -0
  84. package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -0
  85. package/lib/components/SearchFilter/helpers/build-query.js +1 -1
  86. package/lib/components/SearchFilter/helpers/build-query.js.map +1 -1
  87. package/lib/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
  88. package/lib/components/SearchFilter/helpers/build-raw-query-stringified.js.map +1 -1
  89. package/lib/components/SearchFilter/helpers/get-initial-filter-values.js +18 -3
  90. package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
  91. package/lib/components/SearchFilter/helpers/index.js +8 -0
  92. package/lib/components/SearchFilter/helpers/index.js.map +1 -1
  93. package/lib/components/SearchFilter/helpers/parse-filter-value.js +3 -7
  94. package/lib/components/SearchFilter/helpers/parse-filter-value.js.map +1 -1
  95. package/lib/components/index.js +16 -1
  96. package/lib/components/index.js.map +1 -1
  97. package/lib/constants/index.js +3 -1
  98. package/lib/constants/index.js.map +1 -1
  99. package/lib/helpers/build-raw-query.js.map +1 -1
  100. package/lib/hooks/helpers/append-gtm-classname.js +1 -0
  101. package/lib/hooks/helpers/append-gtm-classname.js.map +1 -1
  102. package/lib-es/application/query/index.js +45 -1
  103. package/lib-es/application/query/index.js.map +1 -1
  104. package/lib-es/components/Button.js +18 -6
  105. package/lib-es/components/Button.js.map +1 -1
  106. package/lib-es/components/Card/CardContainer.js +3 -7
  107. package/lib-es/components/Card/CardContainer.js.map +1 -1
  108. package/lib-es/components/Card/CardFactory.js +7 -4
  109. package/lib-es/components/Card/CardFactory.js.map +1 -1
  110. package/lib-es/components/CarouselWrapper.js +2 -2
  111. package/lib-es/components/CarouselWrapper.js.map +1 -1
  112. package/lib-es/components/Image/ImageRender.js +4 -1
  113. package/lib-es/components/Image/ImageRender.js.map +1 -1
  114. package/lib-es/components/ItemList/ItemListButton/ItemListButton.js +111 -0
  115. package/lib-es/components/ItemList/ItemListButton/ItemListButton.js.map +1 -0
  116. package/lib-es/components/ItemList/ItemListButton/index.js +3 -0
  117. package/lib-es/components/ItemList/ItemListButton/index.js.map +1 -0
  118. package/lib-es/components/ItemList/ItemListCounter/ItemListCounter.js +60 -0
  119. package/lib-es/components/ItemList/ItemListCounter/ItemListCounter.js.map +1 -0
  120. package/lib-es/components/ItemList/ItemListCounter/index.js +3 -0
  121. package/lib-es/components/ItemList/ItemListCounter/index.js.map +1 -0
  122. package/lib-es/components/ItemList/ItemListNew/ItemListNew.js +64 -0
  123. package/lib-es/components/ItemList/ItemListNew/ItemListNew.js.map +1 -0
  124. package/lib-es/components/ItemList/ItemListNew/index.js +3 -0
  125. package/lib-es/components/ItemList/ItemListNew/index.js.map +1 -0
  126. package/lib-es/components/ItemList/constants.js +6 -0
  127. package/lib-es/components/ItemList/constants.js.map +1 -0
  128. package/lib-es/components/ItemList/helpers/get-item-list-data.js +7 -0
  129. package/lib-es/components/ItemList/helpers/get-item-list-data.js.map +1 -0
  130. package/lib-es/components/ItemList/helpers/get-item-list-id.js +11 -0
  131. package/lib-es/components/ItemList/helpers/get-item-list-id.js.map +1 -0
  132. package/lib-es/components/ItemList/helpers/get-item-list-ids.js +13 -0
  133. package/lib-es/components/ItemList/helpers/get-item-list-ids.js.map +1 -0
  134. package/lib-es/components/ItemList/helpers/index.js +6 -0
  135. package/lib-es/components/ItemList/helpers/index.js.map +1 -0
  136. package/lib-es/components/ItemList/helpers/set-item-list-id.js +10 -0
  137. package/lib-es/components/ItemList/helpers/set-item-list-id.js.map +1 -0
  138. package/lib-es/components/ItemList/helpers/set-param-and-redirect.js +20 -0
  139. package/lib-es/components/ItemList/helpers/set-param-and-redirect.js.map +1 -0
  140. package/lib-es/components/ItemList/hooks/index.js +2 -0
  141. package/lib-es/components/ItemList/hooks/index.js.map +1 -0
  142. package/lib-es/components/ItemList/hooks/use-item-list-id.js +26 -0
  143. package/lib-es/components/ItemList/hooks/use-item-list-id.js.map +1 -0
  144. package/lib-es/components/LazyImage/LazyImage.js +4 -1
  145. package/lib-es/components/LazyImage/LazyImage.js.map +1 -1
  146. package/lib-es/components/List/ListBuilder.js +12 -6
  147. package/lib-es/components/List/ListBuilder.js.map +1 -1
  148. package/lib-es/components/List/ListFactory.js +33 -9
  149. package/lib-es/components/List/ListFactory.js.map +1 -1
  150. package/lib-es/components/List/helpers/has-required-item-list-details.js +20 -0
  151. package/lib-es/components/List/helpers/has-required-item-list-details.js.map +1 -0
  152. package/lib-es/components/List/helpers/index.js +1 -0
  153. package/lib-es/components/List/helpers/index.js.map +1 -1
  154. package/lib-es/components/Menu/Menu.js +54 -46
  155. package/lib-es/components/Menu/Menu.js.map +1 -1
  156. package/lib-es/components/Menu/MenuContext.js +6 -0
  157. package/lib-es/components/Menu/MenuContext.js.map +1 -0
  158. package/lib-es/components/MenuItem/MenuItem.js +24 -9
  159. package/lib-es/components/MenuItem/MenuItem.js.map +1 -1
  160. package/lib-es/components/SearchContent/SearchContent.js +129 -0
  161. package/lib-es/components/SearchContent/SearchContent.js.map +1 -0
  162. package/lib-es/components/SearchContent/SearchContentItems.js +33 -0
  163. package/lib-es/components/SearchContent/SearchContentItems.js.map +1 -0
  164. package/lib-es/components/SearchContent/SearchContentResults.js +31 -0
  165. package/lib-es/components/SearchContent/SearchContentResults.js.map +1 -0
  166. package/lib-es/components/SearchContent/SearchContentToggleIcon.js +30 -0
  167. package/lib-es/components/SearchContent/SearchContentToggleIcon.js.map +1 -0
  168. package/lib-es/components/SearchContent/index.js +1 -205
  169. package/lib-es/components/SearchContent/index.js.map +1 -1
  170. package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js +2 -4
  171. package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
  172. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +10 -43
  173. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  174. package/lib-es/components/SearchFilter/SearchFilterContainer.js +70 -15
  175. package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  176. package/lib-es/components/SearchFilter/components/Checkbox.js +18 -9
  177. package/lib-es/components/SearchFilter/components/Checkbox.js.map +1 -1
  178. package/lib-es/components/SearchFilter/components/Select.js +23 -8
  179. package/lib-es/components/SearchFilter/components/Select.js.map +1 -1
  180. package/lib-es/components/SearchFilter/components/TextSearch.js +1 -5
  181. package/lib-es/components/SearchFilter/components/TextSearch.js.map +1 -1
  182. package/lib-es/components/SearchFilter/helpers/build-filters-query.js +54 -0
  183. package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -0
  184. package/lib-es/components/SearchFilter/helpers/build-query.js +1 -1
  185. package/lib-es/components/SearchFilter/helpers/build-query.js.map +1 -1
  186. package/lib-es/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
  187. package/lib-es/components/SearchFilter/helpers/build-raw-query-stringified.js.map +1 -1
  188. package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js +13 -1
  189. package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -1
  190. package/lib-es/components/SearchFilter/helpers/index.js +2 -1
  191. package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
  192. package/lib-es/components/SearchFilter/helpers/parse-filter-value.js +3 -3
  193. package/lib-es/components/SearchFilter/helpers/parse-filter-value.js.map +1 -1
  194. package/lib-es/components/index.js +10 -1
  195. package/lib-es/components/index.js.map +1 -1
  196. package/lib-es/constants/index.js +2 -1
  197. package/lib-es/constants/index.js.map +1 -1
  198. package/lib-es/helpers/build-raw-query.js.map +1 -1
  199. package/lib-es/hooks/helpers/append-gtm-classname.js +1 -0
  200. package/lib-es/hooks/helpers/append-gtm-classname.js.map +1 -1
  201. package/package.json +5 -4
  202. package/src/application/query/index.js +51 -1
  203. package/src/components/Button.js +27 -5
  204. package/src/components/Card/CardContainer.js +2 -6
  205. package/src/components/Card/CardFactory.js +5 -3
  206. package/src/components/CarouselWrapper.js +2 -2
  207. package/src/components/Image/ImageRender.js +3 -0
  208. package/src/components/ItemList/ItemListButton/ItemListButton.js +94 -0
  209. package/src/components/ItemList/ItemListButton/index.js +3 -0
  210. package/src/components/ItemList/ItemListCounter/ItemListCounter.js +52 -0
  211. package/src/components/ItemList/ItemListCounter/index.js +3 -0
  212. package/src/components/ItemList/ItemListNew/ItemListNew.js +51 -0
  213. package/src/components/ItemList/ItemListNew/index.js +3 -0
  214. package/src/components/ItemList/constants.js +5 -0
  215. package/src/components/ItemList/helpers/get-item-list-data.js +6 -0
  216. package/src/components/ItemList/helpers/get-item-list-id.js +11 -0
  217. package/src/components/ItemList/helpers/get-item-list-ids.js +10 -0
  218. package/src/components/ItemList/helpers/index.js +5 -0
  219. package/src/components/ItemList/helpers/set-item-list-id.js +9 -0
  220. package/src/components/ItemList/helpers/set-param-and-redirect.js +20 -0
  221. package/src/components/ItemList/hooks/index.js +1 -0
  222. package/src/components/ItemList/hooks/use-item-list-id.js +27 -0
  223. package/src/components/LazyImage/LazyImage.js +11 -1
  224. package/src/components/List/ListBuilder.js +10 -5
  225. package/src/components/List/ListFactory.js +48 -12
  226. package/src/components/List/helpers/has-required-item-list-details.js +14 -0
  227. package/src/components/List/helpers/index.js +1 -0
  228. package/src/components/Menu/Menu.js +61 -54
  229. package/src/components/Menu/MenuContext.js +5 -0
  230. package/src/components/MenuItem/MenuItem.js +39 -14
  231. package/src/components/SearchContent/SearchContent.js +136 -0
  232. package/src/components/SearchContent/SearchContentItems.js +28 -0
  233. package/src/components/SearchContent/SearchContentResults.js +27 -0
  234. package/src/components/SearchContent/SearchContentToggleIcon.js +27 -0
  235. package/src/components/SearchContent/index.js +1 -217
  236. package/src/components/SearchFilter/SearchFilter/FiltersList.js +30 -37
  237. package/src/components/SearchFilter/SearchFilter/SearchFilter.js +10 -25
  238. package/src/components/SearchFilter/SearchFilterContainer.js +61 -16
  239. package/src/components/SearchFilter/components/Checkbox.js +23 -8
  240. package/src/components/SearchFilter/components/Select.js +18 -11
  241. package/src/components/SearchFilter/components/TextSearch.js +1 -3
  242. package/src/components/SearchFilter/helpers/build-filters-query.js +40 -0
  243. package/src/components/SearchFilter/helpers/build-query.js +3 -1
  244. package/src/components/SearchFilter/helpers/build-raw-query-stringified.js +2 -1
  245. package/src/components/SearchFilter/helpers/get-initial-filter-values.js +12 -1
  246. package/src/components/SearchFilter/helpers/index.js +3 -1
  247. package/src/components/SearchFilter/helpers/parse-filter-value.js +3 -3
  248. package/src/components/index.js +10 -1
  249. package/src/constants/index.js +2 -0
  250. package/src/helpers/build-raw-query.js +1 -0
  251. package/src/hooks/helpers/append-gtm-classname.js +3 -0
  252. package/tests/unit/src/components/Button.test.js +55 -1
  253. package/tests/unit/src/components/ItemList/ItemListButton.test.js +175 -0
  254. package/tests/unit/src/components/ItemList/ItemListCounter.test.js +65 -0
  255. package/tests/unit/src/components/ItemList/ItemListNew.test.js +164 -0
  256. package/tests/unit/src/components/ItemList/__snapshots__/ItemListButton.test.js.snap +107 -0
  257. package/tests/unit/src/components/ItemList/__snapshots__/ItemListCounter.test.js.snap +31 -0
  258. package/tests/unit/src/components/ItemList/__snapshots__/ItemListNew.test.js.snap +27 -0
  259. package/tests/unit/src/components/ItemList/helpers/get-item-list-data.test.js +28 -0
  260. package/tests/unit/src/components/ItemList/helpers/get-item-list-id.test.js +20 -0
  261. package/tests/unit/src/components/ItemList/helpers/get-item-list-ids.test.js +19 -0
  262. package/tests/unit/src/components/ItemList/helpers/set-item-list-id.test.js +13 -0
  263. package/tests/unit/src/components/ItemList/helpers/set-param-and-redirect.test.js +30 -0
  264. package/tests/unit/src/components/ItemList/hooks/use-item-list-id.test.js +32 -0
  265. package/tests/unit/src/components/List/helpers/has-required-item-list-details.test.js +30 -0
  266. package/tests/unit/src/components/Menu/Menu.test.js +9 -3
  267. package/tests/unit/src/components/Menu/__snapshots__/Menu.test.js.snap +12 -11
  268. package/tests/unit/src/components/MenuItem/MenuItem.test.js +1 -1
  269. package/tests/unit/src/components/MenuItem/SubMenu.test.js +5 -1
  270. package/tests/unit/src/components/MenuItem/__snapshots__/MenuItem.test.js.snap +54 -10
  271. package/tests/unit/src/components/SearchContent/SearchContent.test.js +29 -0
  272. package/tests/unit/src/components/SearchContent/__snapshots__/SearchContent.test.js.snap +9 -0
  273. package/tests/unit/src/components/SearchFilter/SearchFilter/SearchFilter.test.js +3 -6
  274. package/tests/unit/src/components/SearchFilter/components/__snapshots__/Checkbox.test.js.snap +2 -0
  275. package/tests/unit/src/components/SearchFilter/components/__snapshots__/Select.test.js.snap +4 -0
  276. package/tests/unit/src/components/SearchFilter/helpers/build-query.test.js +2 -2
  277. package/tests/unit/src/components/SearchFilter/helpers/get-initial-filter-values.test.js +25 -11
  278. package/tests/unit/src/components/SearchFilter/helpers/parse-filter-value.test.js +1 -1
  279. package/tests/unit/src/components/__snapshots__/index.test.js.snap +12 -0
@@ -1,219 +1,3 @@
1
- import React, { useState } from 'react';
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
- !!shouldDisplayFilter && (
47
- <div
48
- key={dynamicKey}
49
- className="filter__section filter__section--search-refine filter__section--checkboxes">
50
- <Checkbox
51
- {...otherProps}
52
- data={data}
53
- prop={propsToDisplay[0]}
54
- label={label}
55
- elementTitle={elementTitle}
56
- hasUrl={hasUrl}
57
- filterValues={filterValues}
58
- updateFilterValues={updateFilterValues}
59
- shouldSearch={shouldSearch}
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
- !!shouldDisplayFilter && (
67
- <div
68
- key={dynamicKey}
69
- className="filter__section filter__section--search-refine filter__section--selects">
70
- <SelectFilter
71
- {...otherProps}
72
- data={data}
73
- prop={propsToDisplay[0]}
74
- label={label}
75
- elementTitle={elementTitle}
76
- hasUrl={hasUrl}
77
- filterValues={filterValues}
78
- updateFilterValues={updateFilterValues}
79
- shouldSearch={shouldSearch}
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, useReducer } from 'react';
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
- dispatch({ type: 'resetSearch' });
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
- dispatch({ newValues, shouldSearch: shouldSubmit, type: 'update' });
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
- initialFilterValues: PropTypes.object.isRequired
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 { 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,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(router.asPath);
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
- rawQueryStringified = buildRawQueryStringified(checkboxSelectValues, rangeValues, docType);
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, loading } = useQuery(action, {
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
- const initialFilterValues = getInitialFilterValues(filterData, filters, query);
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
- initialFilterValues={initialFilterValues}
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 = ({ 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);
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 }) => 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 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);