@blaze-cms/react-page-builder 0.131.0-project-admin-customisations.2 → 0.131.1

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 (256) hide show
  1. package/CHANGELOG.md +5 -21
  2. package/lib/HOC/recreateOnNavigation.js +29 -0
  3. package/lib/HOC/recreateOnNavigation.js.map +1 -0
  4. package/lib/components/Button.js +1 -2
  5. package/lib/components/Button.js.map +1 -1
  6. package/lib/components/Card/CardsContainer.js +5 -5
  7. package/lib/components/Card/CardsContainer.js.map +1 -1
  8. package/lib/components/Card/CardsRender.js +6 -13
  9. package/lib/components/Card/CardsRender.js.map +1 -1
  10. package/lib/components/Card/helpers/index.js +0 -7
  11. package/lib/components/Card/helpers/index.js.map +1 -1
  12. package/lib/components/Code/Code.js +3 -7
  13. package/lib/components/Code/Code.js.map +1 -1
  14. package/lib/components/ContentGroupSection/ContentGroupSection.js +4 -1
  15. package/lib/components/ContentGroupSection/ContentGroupSection.js.map +1 -1
  16. package/lib/components/DataSummary/helpers/build-loop-props-content.js +1 -3
  17. package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
  18. package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js +2 -3
  19. package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
  20. package/lib/components/Layout/Layout.js +3 -2
  21. package/lib/components/Layout/Layout.js.map +1 -1
  22. package/lib/components/Layout/LayoutFactory.js +35 -0
  23. package/lib/components/Layout/LayoutFactory.js.map +1 -0
  24. package/lib/components/Layout/LayoutWithStickyTimer.js +66 -0
  25. package/lib/components/Layout/LayoutWithStickyTimer.js.map +1 -0
  26. package/lib/components/Layout/index.js +2 -2
  27. package/lib/components/Layout/index.js.map +1 -1
  28. package/lib/components/List/ListFactory.js +11 -16
  29. package/lib/components/List/ListFactory.js.map +1 -1
  30. package/lib/components/List/helpers/index.js +0 -14
  31. package/lib/components/List/helpers/index.js.map +1 -1
  32. package/lib/components/SearchContent/SearchContent.js +6 -8
  33. package/lib/components/SearchContent/SearchContent.js.map +1 -1
  34. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +11 -17
  35. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  36. package/lib/components/SearchFilter/SearchFilterContainer.js +85 -63
  37. package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  38. package/lib/components/SearchFilter/helpers/build-filters-query.js +1 -3
  39. package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
  40. package/lib/components/SearchFilter/helpers/build-new-query.js +15 -0
  41. package/lib/components/SearchFilter/helpers/build-new-query.js.map +1 -0
  42. package/lib/components/SearchFilter/helpers/build-query.js +37 -0
  43. package/lib/components/SearchFilter/helpers/build-query.js.map +1 -0
  44. package/lib/components/SearchFilter/helpers/get-initial-filter-values.js +43 -0
  45. package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -0
  46. package/lib/components/SearchFilter/helpers/index.js +11 -18
  47. package/lib/components/SearchFilter/helpers/index.js.map +1 -1
  48. package/lib/components/SearchFilter/index.js.map +1 -1
  49. package/lib/components/SearchFilterSort/SearchFilterSort.js +11 -31
  50. package/lib/components/SearchFilterSort/SearchFilterSort.js.map +1 -1
  51. package/lib/components/SearchFilterSort/helpers/handle-sort-update.js +5 -19
  52. package/lib/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
  53. package/lib/components/SearchFilterSort/helpers/update-sort.js +5 -9
  54. package/lib/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
  55. package/lib/helpers/build-inherited-filters.js +0 -2
  56. package/lib/helpers/build-inherited-filters.js.map +1 -1
  57. package/lib/helpers/build-props-query.js +2 -5
  58. package/lib/helpers/build-props-query.js.map +1 -1
  59. package/lib/helpers/build-set-filters.js +1 -5
  60. package/lib/helpers/build-set-filters.js.map +1 -1
  61. package/lib/helpers/get-query-filters.js +8 -6
  62. package/lib/helpers/get-query-filters.js.map +1 -1
  63. package/lib/helpers/get-query-props.js +2 -13
  64. package/lib/helpers/get-query-props.js.map +1 -1
  65. package/lib/helpers/get-wrapped-value-with-link.js +3 -2
  66. package/lib/helpers/get-wrapped-value-with-link.js.map +1 -1
  67. package/lib/helpers/index.js +0 -14
  68. package/lib/helpers/index.js.map +1 -1
  69. package/lib/helpers/parse-props-to-display.js +8 -13
  70. package/lib/helpers/parse-props-to-display.js.map +1 -1
  71. package/lib/utils/get-class-modifiers.js +1 -1
  72. package/lib/utils/get-class-modifiers.js.map +1 -1
  73. package/lib-es/HOC/recreateOnNavigation.js +20 -0
  74. package/lib-es/HOC/recreateOnNavigation.js.map +1 -0
  75. package/lib-es/components/Button.js +1 -2
  76. package/lib-es/components/Button.js.map +1 -1
  77. package/lib-es/components/Card/CardsContainer.js +5 -5
  78. package/lib-es/components/Card/CardsContainer.js.map +1 -1
  79. package/lib-es/components/Card/CardsRender.js +7 -14
  80. package/lib-es/components/Card/CardsRender.js.map +1 -1
  81. package/lib-es/components/Card/helpers/index.js +0 -1
  82. package/lib-es/components/Card/helpers/index.js.map +1 -1
  83. package/lib-es/components/Code/Code.js +4 -8
  84. package/lib-es/components/Code/Code.js.map +1 -1
  85. package/lib-es/components/ContentGroupSection/ContentGroupSection.js +8 -4
  86. package/lib-es/components/ContentGroupSection/ContentGroupSection.js.map +1 -1
  87. package/lib-es/components/DataSummary/helpers/build-loop-props-content.js +1 -3
  88. package/lib-es/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
  89. package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js +3 -4
  90. package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
  91. package/lib-es/components/Layout/Layout.js +3 -2
  92. package/lib-es/components/Layout/Layout.js.map +1 -1
  93. package/lib-es/components/Layout/LayoutFactory.js +14 -0
  94. package/lib-es/components/Layout/LayoutFactory.js.map +1 -0
  95. package/lib-es/components/Layout/LayoutWithStickyTimer.js +42 -0
  96. package/lib-es/components/Layout/LayoutWithStickyTimer.js.map +1 -0
  97. package/lib-es/components/Layout/index.js +2 -2
  98. package/lib-es/components/Layout/index.js.map +1 -1
  99. package/lib-es/components/List/ListFactory.js +12 -16
  100. package/lib-es/components/List/ListFactory.js.map +1 -1
  101. package/lib-es/components/List/helpers/index.js +0 -2
  102. package/lib-es/components/List/helpers/index.js.map +1 -1
  103. package/lib-es/components/SearchContent/SearchContent.js +6 -8
  104. package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
  105. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +11 -18
  106. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  107. package/lib-es/components/SearchFilter/SearchFilterContainer.js +72 -47
  108. package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  109. package/lib-es/components/SearchFilter/helpers/build-filters-query.js +0 -2
  110. package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
  111. package/lib-es/components/SearchFilter/helpers/build-new-query.js +6 -0
  112. package/lib-es/components/SearchFilter/helpers/build-new-query.js.map +1 -0
  113. package/lib-es/components/SearchFilter/helpers/build-query.js +23 -0
  114. package/lib-es/components/SearchFilter/helpers/build-query.js.map +1 -0
  115. package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js +26 -0
  116. package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -0
  117. package/lib-es/components/SearchFilter/helpers/index.js +4 -5
  118. package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
  119. package/lib-es/components/SearchFilter/index.js +2 -2
  120. package/lib-es/components/SearchFilter/index.js.map +1 -1
  121. package/lib-es/components/SearchFilterSort/SearchFilterSort.js +10 -26
  122. package/lib-es/components/SearchFilterSort/SearchFilterSort.js.map +1 -1
  123. package/lib-es/components/SearchFilterSort/helpers/handle-sort-update.js +4 -21
  124. package/lib-es/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
  125. package/lib-es/components/SearchFilterSort/helpers/update-sort.js +4 -8
  126. package/lib-es/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
  127. package/lib-es/helpers/build-inherited-filters.js +0 -2
  128. package/lib-es/helpers/build-inherited-filters.js.map +1 -1
  129. package/lib-es/helpers/build-props-query.js +2 -4
  130. package/lib-es/helpers/build-props-query.js.map +1 -1
  131. package/lib-es/helpers/build-set-filters.js +1 -5
  132. package/lib-es/helpers/build-set-filters.js.map +1 -1
  133. package/lib-es/helpers/get-query-filters.js +8 -6
  134. package/lib-es/helpers/get-query-filters.js.map +1 -1
  135. package/lib-es/helpers/get-query-props.js +2 -10
  136. package/lib-es/helpers/get-query-props.js.map +1 -1
  137. package/lib-es/helpers/get-wrapped-value-with-link.js +2 -2
  138. package/lib-es/helpers/get-wrapped-value-with-link.js.map +1 -1
  139. package/lib-es/helpers/index.js +0 -2
  140. package/lib-es/helpers/index.js.map +1 -1
  141. package/lib-es/helpers/parse-props-to-display.js +9 -12
  142. package/lib-es/helpers/parse-props-to-display.js.map +1 -1
  143. package/lib-es/utils/get-class-modifiers.js +1 -1
  144. package/lib-es/utils/get-class-modifiers.js.map +1 -1
  145. package/package.json +10 -10
  146. package/src/HOC/recreateOnNavigation.js +21 -0
  147. package/src/components/Button.js +1 -2
  148. package/src/components/Card/CardsContainer.js +3 -3
  149. package/src/components/Card/CardsRender.js +7 -27
  150. package/src/components/Card/helpers/index.js +0 -1
  151. package/src/components/Code/Code.js +3 -7
  152. package/src/components/ContentGroupSection/ContentGroupSection.js +1 -1
  153. package/src/components/DataSummary/helpers/build-loop-props-content.js +1 -4
  154. package/src/components/DataSummary/helpers/build-props-to-display-with-content.js +3 -6
  155. package/src/components/Layout/Layout.js +29 -32
  156. package/src/components/Layout/LayoutFactory.js +17 -0
  157. package/src/components/Layout/LayoutWithStickyTimer.js +40 -0
  158. package/src/components/Layout/index.js +2 -2
  159. package/src/components/List/ListFactory.js +15 -25
  160. package/src/components/List/helpers/index.js +0 -2
  161. package/src/components/SearchContent/SearchContent.js +6 -8
  162. package/src/components/SearchFilter/SearchFilter/SearchFilter.js +12 -21
  163. package/src/components/SearchFilter/SearchFilterContainer.js +69 -57
  164. package/src/components/SearchFilter/helpers/build-filters-query.js +1 -9
  165. package/src/components/SearchFilter/helpers/build-new-query.js +6 -0
  166. package/src/components/SearchFilter/helpers/build-query.js +26 -0
  167. package/src/components/SearchFilter/helpers/get-initial-filter-values.js +30 -0
  168. package/src/components/SearchFilter/helpers/index.js +7 -9
  169. package/src/components/SearchFilter/index.js +2 -2
  170. package/src/components/SearchFilterSort/SearchFilterSort.js +8 -18
  171. package/src/components/SearchFilterSort/helpers/handle-sort-update.js +5 -14
  172. package/src/components/SearchFilterSort/helpers/update-sort.js +3 -7
  173. package/src/helpers/build-inherited-filters.js +1 -3
  174. package/src/helpers/build-props-query.js +2 -4
  175. package/src/helpers/build-set-filters.js +1 -2
  176. package/src/helpers/get-query-filters.js +4 -4
  177. package/src/helpers/get-query-props.js +4 -12
  178. package/src/helpers/get-wrapped-value-with-link.js +3 -6
  179. package/src/helpers/index.js +0 -2
  180. package/src/helpers/parse-props-to-display.js +21 -25
  181. package/src/utils/get-class-modifiers.js +1 -1
  182. package/tests/helpers/mocks.js +5 -3
  183. package/tests/unit/src/HOC/recreateOnNavigation.test.js +28 -0
  184. package/tests/unit/src/components/Code/Code.test.js +0 -5
  185. package/tests/unit/src/components/Code/__snapshots__/Code.test.js.snap +0 -8
  186. package/tests/unit/src/components/DataSummary/helpers/build-loop-props-content.test.js +0 -9
  187. package/tests/unit/src/components/Layout/Layout.test.js +1 -1
  188. package/tests/unit/src/components/Layout/LayoutFactory.test.js +53 -0
  189. package/tests/unit/src/components/SearchFilter/__snapshots__/SearchFilterContainer.test.js.snap +7 -1
  190. package/tests/unit/src/components/SearchFilter/helpers/build-new-query.test.js +10 -10
  191. package/tests/unit/src/components/SearchFilter/helpers/build-query.test.js +7 -24
  192. package/tests/unit/src/components/SearchFilter/helpers/get-initial-filter-values.test.js +10 -10
  193. package/tests/unit/src/components/SearchFilterSort/SearchFilterSort.test.js +1 -4
  194. package/tests/unit/src/components/SearchFilterSort/helpers/handle-sort-update.test.js +19 -26
  195. package/tests/unit/src/components/SearchFilterSort/helpers/update-sort.test.js +1 -10
  196. package/tests/unit/src/helpers/build-props-query.test.js +0 -25
  197. package/tests/unit/src/helpers/get-wrapped-value-with-link.test.js +2 -2
  198. package/tests/unit/src/helpers/parse-props-to-display.test.js +0 -4
  199. package/lib/components/Card/helpers/get-updated-items-to-display.js +0 -55
  200. package/lib/components/Card/helpers/get-updated-items-to-display.js.map +0 -1
  201. package/lib/components/List/helpers/get-list-query.js +0 -43
  202. package/lib/components/List/helpers/get-list-query.js.map +0 -1
  203. package/lib/components/List/helpers/get-list-specific-search-filter.js +0 -21
  204. package/lib/components/List/helpers/get-list-specific-search-filter.js.map +0 -1
  205. package/lib/components/List/helpers/strip-query-key.js +0 -14
  206. package/lib/components/List/helpers/strip-query-key.js.map +0 -1
  207. package/lib/components/SearchFilter/helpers/build-new-url.js +0 -17
  208. package/lib/components/SearchFilter/helpers/build-new-url.js.map +0 -1
  209. package/lib/components/SearchFilter/helpers/build-url-query.js +0 -48
  210. package/lib/components/SearchFilter/helpers/build-url-query.js.map +0 -1
  211. package/lib/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +0 -32
  212. package/lib/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js.map +0 -1
  213. package/lib/components/SearchFilter/helpers/get-filter-values.js +0 -31
  214. package/lib/components/SearchFilter/helpers/get-filter-values.js.map +0 -1
  215. package/lib/components/SearchFilter/searchFilterReducer.js +0 -45
  216. package/lib/components/SearchFilter/searchFilterReducer.js.map +0 -1
  217. package/lib/helpers/build-query-key.js +0 -16
  218. package/lib/helpers/build-query-key.js.map +0 -1
  219. package/lib/helpers/process-data-summary-value.js +0 -56
  220. package/lib/helpers/process-data-summary-value.js.map +0 -1
  221. package/lib-es/components/Card/helpers/get-updated-items-to-display.js +0 -32
  222. package/lib-es/components/Card/helpers/get-updated-items-to-display.js.map +0 -1
  223. package/lib-es/components/List/helpers/get-list-query.js +0 -24
  224. package/lib-es/components/List/helpers/get-list-query.js.map +0 -1
  225. package/lib-es/components/List/helpers/get-list-specific-search-filter.js +0 -12
  226. package/lib-es/components/List/helpers/get-list-specific-search-filter.js.map +0 -1
  227. package/lib-es/components/List/helpers/strip-query-key.js +0 -6
  228. package/lib-es/components/List/helpers/strip-query-key.js.map +0 -1
  229. package/lib-es/components/SearchFilter/helpers/build-new-url.js +0 -8
  230. package/lib-es/components/SearchFilter/helpers/build-new-url.js.map +0 -1
  231. package/lib-es/components/SearchFilter/helpers/build-url-query.js +0 -30
  232. package/lib-es/components/SearchFilter/helpers/build-url-query.js.map +0 -1
  233. package/lib-es/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +0 -18
  234. package/lib-es/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js.map +0 -1
  235. package/lib-es/components/SearchFilter/helpers/get-filter-values.js +0 -19
  236. package/lib-es/components/SearchFilter/helpers/get-filter-values.js.map +0 -1
  237. package/lib-es/components/SearchFilter/searchFilterReducer.js +0 -28
  238. package/lib-es/components/SearchFilter/searchFilterReducer.js.map +0 -1
  239. package/lib-es/helpers/build-query-key.js +0 -7
  240. package/lib-es/helpers/build-query-key.js.map +0 -1
  241. package/lib-es/helpers/process-data-summary-value.js +0 -36
  242. package/lib-es/helpers/process-data-summary-value.js.map +0 -1
  243. package/src/components/Card/helpers/get-updated-items-to-display.js +0 -32
  244. package/src/components/List/helpers/get-list-query.js +0 -28
  245. package/src/components/List/helpers/get-list-specific-search-filter.js +0 -10
  246. package/src/components/List/helpers/strip-query-key.js +0 -6
  247. package/src/components/SearchFilter/helpers/build-new-url.js +0 -8
  248. package/src/components/SearchFilter/helpers/build-url-query.js +0 -31
  249. package/src/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +0 -17
  250. package/src/components/SearchFilter/helpers/get-filter-values.js +0 -21
  251. package/src/components/SearchFilter/searchFilterReducer.js +0 -15
  252. package/src/helpers/build-query-key.js +0 -7
  253. package/src/helpers/process-data-summary-value.js +0 -22
  254. package/tests/unit/src/components/Card/helpers/get-updated-items-to-display.test.js +0 -72
  255. package/tests/unit/src/helpers/__snapshots__/get-wrapped-value-with-link.test.js.snap +0 -18
  256. package/tests/unit/src/helpers/prcoess-data-summary-value.test.js +0 -52
@@ -2,37 +2,33 @@ import React, { useState, useRef, useReducer, useEffect } from 'react';
2
2
  import { useRouter } from 'next/router';
3
3
  import { useQuery } from '@apollo/client';
4
4
  import PropTypes from 'prop-types';
5
- import { parseUrl } from 'query-string';
5
+ 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
9
  import {
10
- buildNewUrl,
10
+ buildNewQuery,
11
11
  buildRawQueryStringified,
12
- getFilterValues,
13
- buildFiltersQuery,
14
- getFilterRangesAndCheckboxesValues
12
+ getInitialFilterValues,
13
+ buildFiltersQuery
15
14
  } from './helpers';
16
15
  import { getEntityData } from '../../helpers';
17
- import { RAW_RESULTS } from './constants';
16
+ import { RAW_RESULTS, RANGE, CHECKBOX_SELECT } from './constants';
18
17
  import { SCROLL_OFFSET } from '../../constants';
19
- import searchFilterReducer from './searchFilterReducer';
20
-
21
- const getFiltersUrlQuery = (query, listName) => {
22
- if (!listName) return query;
23
- const updatedQuery = {};
24
- const listKey = `pb[${listName}]`;
25
- Object.keys(query).forEach(queryKey => {
26
- const isListKey = queryKey.indexOf(`${listName}`) !== -1;
27
- if (!isListKey) return;
28
- const decodedQueryValue = Array.isArray(query[queryKey])
29
- ? query[queryKey].map(value => decodeURIComponent(value))
30
- : decodeURIComponent(query[queryKey]);
31
- const strippedKey = queryKey.substring(listKey.length + 1, queryKey.length - 1);
32
- if (isListKey) updatedQuery[strippedKey] = decodedQueryValue;
33
- });
34
18
 
35
- return updatedQuery;
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: false };
29
+ default:
30
+ throw new Error();
31
+ }
36
32
  };
37
33
 
38
34
  const SearchFilterContainer = ({
@@ -45,8 +41,7 @@ const SearchFilterContainer = ({
45
41
  groupAfterDesktop,
46
42
  filterBy,
47
43
  filterByProperty,
48
- shouldAddFilters,
49
- listComponentName
44
+ shouldAddFilters
50
45
  }) => {
51
46
  const router = useRouter();
52
47
  const { asPath } = router;
@@ -54,10 +49,15 @@ const SearchFilterContainer = ({
54
49
  const [key, setKey] = useState(`filter-${name}`);
55
50
  const [displaySearchFilter, setDisplaySearchFilter] = useState(false);
56
51
  const [urlPath, setUrlPath] = useState(asPath); // used as asPath can take too long to update
57
- const { url: currentUrl, query } = parseUrl(urlPath);
58
- const updatedQuery = getFiltersUrlQuery(query, listComponentName);
59
-
60
- const [filterValues, dispatch] = useReducer(searchFilterReducer, null);
52
+ const {
53
+ url: currentUrl,
54
+ query: { sort, sortby },
55
+ query
56
+ } = parseUrl(urlPath);
57
+ const [filterValues, dispatch] = useReducer(
58
+ reducer,
59
+ getInitialFilterValues(null, filters, query)
60
+ );
61
61
 
62
62
  useEffect(
63
63
  () => {
@@ -66,19 +66,34 @@ const SearchFilterContainer = ({
66
66
  [asPath]
67
67
  );
68
68
 
69
+ const hasUrl = !!url;
70
+
71
+ const sortValues = sort && sortby ? stringify({ sort, sortby }) : '';
72
+ const baseQuery = sortValues ? `${currentUrl}?${sortValues}` : currentUrl;
73
+
69
74
  const action = getSearchPublishedContent(RAW_RESULTS);
70
- const [checkboxSelectValues, rangeValues] = getFilterRangesAndCheckboxesValues(filters);
75
+ const checkboxSelectValues = [];
76
+ const rangeValues = [];
77
+
78
+ filters.forEach(({ type, propsToDisplay }) => {
79
+ if (CHECKBOX_SELECT.includes(type)) {
80
+ checkboxSelectValues.push(propsToDisplay[0]);
81
+ } else if (type === RANGE) {
82
+ rangeValues.push(...propsToDisplay);
83
+ }
84
+ });
71
85
 
72
86
  const { docType } = getEntityData(entity);
73
87
 
74
- const filtersQuery = buildFiltersQuery({
75
- shouldAddFilters,
76
- query: filterValues || {},
77
- filterBy,
78
- filterByProperty,
79
- rangeValues,
80
- queryKeys: Object.keys(updatedQuery)
81
- });
88
+ const filtersQuery = shouldAddFilters
89
+ ? buildFiltersQuery({
90
+ query: filterValues,
91
+ filterBy,
92
+ filterByProperty,
93
+ rangeValues,
94
+ queryKeys: Object.keys(query)
95
+ })
96
+ : [];
82
97
 
83
98
  const rawQueryStringified = buildRawQueryStringified(
84
99
  checkboxSelectValues,
@@ -87,7 +102,7 @@ const SearchFilterContainer = ({
87
102
  filtersQuery
88
103
  );
89
104
 
90
- const { data, error, loading } = useQuery(action, {
105
+ const { data, error } = useQuery(action, {
91
106
  variables: { rawQueryStringified, limit: 0 }, // we only want aggs so limit=0 for no search results
92
107
  skip: !rawQueryStringified
93
108
  });
@@ -98,29 +113,30 @@ const SearchFilterContainer = ({
98
113
  const { searchPublishedContent: { rawResults: { aggregations: filterData } = {} } = {} } =
99
114
  data || {};
100
115
 
101
- if (!filterValues && !loading && filterData) {
102
- const newValues = getFilterValues(filterData, filters, updatedQuery);
103
- dispatch({ newValues, shouldSearch: false, type: 'update' });
116
+ if (filterValues.dataNotSet && filterData) {
117
+ const initialFilterValues = getInitialFilterValues(filterData, filters, query);
118
+ dispatch({ newValues: initialFilterValues, shouldSearch: false, type: 'update' });
104
119
  }
105
120
 
106
121
  const handleSearch = newQuery => {
107
122
  setDisplaySearchFilter(false);
108
- const hashBit = asPath.split('#')[1] || '';
109
- const parsedHashBit = hashBit ? `#${hashBit}` : '';
110
- scrollToFirstList();
123
+
111
124
  if (!newQuery) {
112
- const baseQuery = `${currentUrl}${parsedHashBit}`;
113
- return router.push('/Resolver', baseQuery, { shallow: !url, scroll: false }).then(() => {
125
+ scrollToFirstList();
126
+ setUrlPath(baseQuery);
127
+ return router.push('/Resolver', baseQuery, { shallow: !hasUrl, scroll: false }).then(() => {
114
128
  setKey(`filter-${name}:${Date.now()}`); // remove after range component update
115
129
  });
116
130
  }
117
- const newUrl = buildNewUrl(url, currentUrl, newQuery, hashBit);
118
- return router.push('/Resolver', newUrl, { shallow: !url, scroll: false });
131
+ const newUrl = buildNewQuery(url, currentUrl, newQuery, sortValues);
132
+ scrollToFirstList();
133
+ setUrlPath(newUrl);
134
+ return router.push('/Resolver', newUrl, { shallow: !hasUrl, scroll: false });
119
135
  };
120
136
 
121
137
  const scrollToFirstList = () => {
122
138
  const [list] = document.getElementsByClassName('list-top');
123
- const shouldScrollToFirstList = !url && list;
139
+ const shouldScrollToFirstList = !hasUrl && list;
124
140
 
125
141
  if (shouldScrollToFirstList) {
126
142
  window.scrollTo({
@@ -131,18 +147,16 @@ const SearchFilterContainer = ({
131
147
  window.scrollTo(0, 0);
132
148
  }
133
149
  };
134
- if (!filterValues || filterValues.dataNotSet) return null;
150
+ if (!filterValues) return '';
135
151
 
136
152
  return (
137
153
  <SearchFilter
138
154
  key={key}
139
155
  setAppliedFilters={dispatch}
140
- query={updatedQuery}
141
- listComponentName={listComponentName}
142
156
  searchFilterRef={searchFilterRef}
143
157
  data={filterData}
144
158
  filters={filters}
145
- hasUrl={!!url}
159
+ hasUrl={hasUrl}
146
160
  entity={entity}
147
161
  handleSearch={handleSearch}
148
162
  filterValues={filterValues}
@@ -166,8 +180,7 @@ SearchFilterContainer.propTypes = {
166
180
  groupAfterDesktop: PropTypes.number,
167
181
  filterBy: PropTypes.array,
168
182
  filterByProperty: PropTypes.array,
169
- shouldAddFilters: PropTypes.bool,
170
- listComponentName: PropTypes.string
183
+ shouldAddFilters: PropTypes.bool
171
184
  };
172
185
 
173
186
  SearchFilterContainer.defaultProps = {
@@ -179,8 +192,7 @@ SearchFilterContainer.defaultProps = {
179
192
  groupAfterDesktop: 0,
180
193
  filterBy: [],
181
194
  filterByProperty: [],
182
- shouldAddFilters: false,
183
- listComponentName: ''
195
+ shouldAddFilters: false
184
196
  };
185
197
 
186
198
  export default withTitle(SearchFilterContainer);
@@ -29,15 +29,7 @@ const builFilterObject = ({ queryKey, value, filters, isRange, isInQuery }) => {
29
29
  filters.push({ match: { [key]: filterValue } });
30
30
  });
31
31
  };
32
- const buildFiltersQuery = ({
33
- shouldAddFilters,
34
- query,
35
- filterBy,
36
- filterByProperty,
37
- rangeValues,
38
- queryKeys
39
- }) => {
40
- if (!shouldAddFilters) return [];
32
+ const buildFiltersQuery = ({ query, filterBy, filterByProperty, rangeValues, queryKeys }) => {
41
33
  const mustFilters = [];
42
34
  Object.keys(query).forEach(queryKey => {
43
35
  if (QUERY_KEYS_TO_IGNORE.includes(queryKey)) return;
@@ -0,0 +1,6 @@
1
+ const buildNewQuery = (url, currentUrl, queryParams, sortValues) => {
2
+ const newUrl = url ? `${url}?${queryParams}` : `${currentUrl}?${queryParams}`;
3
+ return sortValues ? `${newUrl}&${sortValues}` : newUrl;
4
+ };
5
+
6
+ export default buildNewQuery;
@@ -0,0 +1,26 @@
1
+ import { SEARCH_TERM, TEXT_SEARCH } from '../constants';
2
+ import parseFilterValue from './parse-filter-value';
3
+
4
+ const buildQuery = (filterValues, filters) => {
5
+ const newQuery = [];
6
+ const searchValue = filterValues[SEARCH_TERM]
7
+ ? encodeURIComponent(filterValues[SEARCH_TERM])
8
+ : '';
9
+ if (searchValue) newQuery.push(`${SEARCH_TERM}=${searchValue}`);
10
+
11
+ filters.forEach(({ propsToDisplay, type }) => {
12
+ if (type === TEXT_SEARCH) return;
13
+
14
+ propsToDisplay.forEach(prop => {
15
+ const value = filterValues[prop];
16
+ const parsedValue = parseFilterValue(prop, type, value);
17
+ if (parsedValue && !newQuery.includes(parsedValue)) {
18
+ newQuery.push(parsedValue);
19
+ }
20
+ });
21
+ });
22
+
23
+ return newQuery.join('&');
24
+ };
25
+
26
+ export default buildQuery;
@@ -0,0 +1,30 @@
1
+ import { SEARCH_TERM } from '../constants';
2
+ import getFilterValueFromQuery from './get-filter-value-from-query';
3
+
4
+ const getInitialFilterValues = (filterData, filters, query) => {
5
+ const filterValues = {};
6
+ filterValues[SEARCH_TERM] = query[SEARCH_TERM] || '';
7
+
8
+ if (!filterData) {
9
+ filters.forEach(filterProps => {
10
+ const {
11
+ propsToDisplay: [key]
12
+ } = filterProps;
13
+ filterValues[key] = query[key] ? getFilterValueFromQuery(key, filterProps, {}, query) : null;
14
+ });
15
+ filterValues.dataNotSet = true;
16
+ return filterValues;
17
+ }
18
+
19
+ Object.keys(filterData).forEach(key => {
20
+ const filterProps =
21
+ filters.find(({ propsToDisplay }) => propsToDisplay.find(prop => key === prop)) || {};
22
+ filterValues[key] = getFilterValueFromQuery(key, filterProps, filterData[key], query);
23
+ });
24
+
25
+ filterValues.dataNotSet = false;
26
+
27
+ return filterValues;
28
+ };
29
+
30
+ export default getInitialFilterValues;
@@ -1,4 +1,4 @@
1
- import buildNewUrl from './build-new-url';
1
+ import buildNewQuery from './build-new-query';
2
2
  import buildRawQueryStringified from './build-raw-query-stringified';
3
3
  import { decodeValue, encodeValue } from './decode-encode';
4
4
  import checkIfRangeUpdated from './check-if-range-updated';
@@ -10,15 +10,14 @@ import getIntersectedProp from './get-intersected-prop';
10
10
  import getRangeValue from './get-range-value';
11
11
  import getSelectOptions from './get-select-options';
12
12
  import isDeviceDesktop from './is-device-desktop';
13
- import getFilterValues from './get-filter-values';
13
+ import getInitialFilterValues from './get-initial-filter-values';
14
14
  import getFilterValueFromQuery from './get-filter-value-from-query';
15
- import buildUrlQuery from './build-url-query';
15
+ import buildQuery from './build-query';
16
16
  import buildFiltersQuery from './build-filters-query';
17
- import getFilterRangesAndCheckboxesValues from './get-filter-ranges-and-checkboxes-values';
18
17
 
19
18
  export {
20
- buildUrlQuery,
21
- buildNewUrl,
19
+ buildQuery,
20
+ buildNewQuery,
22
21
  buildRawQueryStringified,
23
22
  decodeValue,
24
23
  encodeValue,
@@ -31,8 +30,7 @@ export {
31
30
  getRangeValue,
32
31
  getSelectOptions,
33
32
  isDeviceDesktop,
34
- getFilterValues,
33
+ getInitialFilterValues,
35
34
  getFilterValueFromQuery,
36
- buildFiltersQuery,
37
- getFilterRangesAndCheckboxesValues
35
+ buildFiltersQuery
38
36
  };
@@ -1,3 +1,3 @@
1
- import SearchFilter from './SearchFilterContainer';
1
+ import SearchFilterContainer from './SearchFilterContainer';
2
2
 
3
- export default SearchFilter;
3
+ export default SearchFilterContainer;
@@ -1,23 +1,15 @@
1
1
  import React from 'react';
2
2
  import Select from '@blaze-react/select';
3
- import { useRouter } from 'next/router';
3
+ import { withRouter } from 'next/router';
4
4
  import { parseUrl } from 'query-string';
5
5
  import PropTypes from 'prop-types';
6
6
  import { DEFAULT_SORT } from './constants';
7
7
  import { handleSortUpdate } from './helpers';
8
8
  import { withTitle } from '../../HOC';
9
9
 
10
- const getSortFromQuery = listComponentName => {
11
- const listNameKey = listComponentName ? `pb[${listComponentName}]` : '';
12
- const sortKey = `${listNameKey}${listNameKey ? '[sort]' : 'sort'}`;
13
- const sortByKey = `${listNameKey}${listNameKey ? '[sortby]' : 'sortby'}`;
14
- return [sortKey, sortByKey];
15
- };
16
- const SearchFilterSort = ({ filters, elementLabel, selectLabel, id, listComponentName }) => {
17
- const router = useRouter();
10
+ const SearchFilterSort = ({ router, filters, elementLabel, selectLabel, id }) => {
18
11
  const { asPath } = router;
19
- const [sortKey, sortByKey] = getSortFromQuery(listComponentName);
20
- const { url, query, query: { [sortKey]: sort, [sortByKey]: sortby } = {} } = parseUrl(asPath);
12
+ const { url, query, query: { sort, sortby } = {} } = parseUrl(asPath);
21
13
  const selectedValue = `${sortby}:${sort}` || '';
22
14
  const defaultTextValue = selectLabel || DEFAULT_SORT;
23
15
  const options = filters.map(({ label: optionLabel, propsToDisplay, sort: sortValue }) => [
@@ -25,8 +17,7 @@ const SearchFilterSort = ({ filters, elementLabel, selectLabel, id, listComponen
25
17
  optionLabel
26
18
  ]);
27
19
 
28
- const setSortValue = ({ value }) =>
29
- handleSortUpdate({ router, value, query, url, selectLabel, listComponentName });
20
+ const setSortValue = ({ value }) => handleSortUpdate(router, value, query, url, selectLabel);
30
21
 
31
22
  return (
32
23
  <div className="sort-by">
@@ -43,19 +34,18 @@ const SearchFilterSort = ({ filters, elementLabel, selectLabel, id, listComponen
43
34
  };
44
35
 
45
36
  SearchFilterSort.propTypes = {
37
+ router: PropTypes.object.isRequired,
46
38
  filters: PropTypes.array,
47
39
  elementLabel: PropTypes.string,
48
40
  selectLabel: PropTypes.string,
49
- id: PropTypes.string,
50
- listComponentName: PropTypes.string
41
+ id: PropTypes.string
51
42
  };
52
43
 
53
44
  SearchFilterSort.defaultProps = {
54
45
  filters: [],
55
46
  elementLabel: '',
56
47
  selectLabel: '',
57
- id: '',
58
- listComponentName: ''
48
+ id: ''
59
49
  };
60
50
 
61
- export default withTitle(SearchFilterSort);
51
+ export default withRouter(withTitle(SearchFilterSort));
@@ -2,30 +2,21 @@ import { stringify } from 'query-string';
2
2
  import { DEFAULT_SORT, SORT, SORTBY, PAGINATION_QUERY } from '../constants';
3
3
  import updateSort from './update-sort';
4
4
 
5
- const handleSortUpdate = ({ router, value, query, url, selectLabel, listComponentName }) => {
5
+ const handleSortUpdate = (router, value, query, url, selectLabel) => {
6
6
  const queryWithoutSort = {};
7
7
  const routerOptions = { shallow: true, scroll: false };
8
- const { asPath } = router;
9
- const hashBit = asPath.split('#')[1];
10
- const parsedHash = hashBit ? `#${hashBit}` : '';
11
- const listNameKey = listComponentName ? `pb[${listComponentName}]` : '';
12
- const sortString = listNameKey ? `[${SORT}]` : SORT;
13
- const sortByString = listNameKey ? `[${SORTBY}]` : SORTBY;
14
- const sortKey = `${listNameKey}${sortString}`;
15
- const sortByKey = `${listNameKey}${sortByString}`;
16
8
  Object.keys(query).forEach(key => {
17
9
  if (key.indexOf(PAGINATION_QUERY) !== -1) return;
18
- if (key !== sortByKey && key !== sortKey) queryWithoutSort[key] = query[key];
10
+ if (key !== SORTBY && key !== SORT) queryWithoutSort[key] = query[key];
19
11
  });
20
12
  if (value === DEFAULT_SORT || value === selectLabel) {
21
13
  const stringifiedQuery = stringify(queryWithoutSort);
22
14
 
23
15
  return stringifiedQuery
24
- ? router.push(`/Resolver`, `${url}?${stringifiedQuery}${parsedHash}`, routerOptions)
25
- : router.push(`/Resolver`, `${url}${parsedHash}`, routerOptions);
16
+ ? router.push(`/Resolver`, `${url}?${stringifiedQuery}`, routerOptions)
17
+ : router.push(`/Resolver`, url, routerOptions);
26
18
  }
27
-
28
- const updatedSortUrl = updateSort(value, queryWithoutSort, url, parsedHash, listComponentName);
19
+ const updatedSortUrl = updateSort(value, queryWithoutSort, url);
29
20
  return router.push('/Resolver', updatedSortUrl, routerOptions);
30
21
  };
31
22
 
@@ -1,14 +1,10 @@
1
1
  import { stringify } from 'query-string';
2
- import { buildQueryKey } from '../../../helpers';
3
- import { SORT, SORTBY } from '../constants';
4
2
 
5
- const updateSort = (value, query, url, hashBit = '', listComponentName = '') => {
6
- const sortKey = buildQueryKey(SORT, listComponentName);
7
- const sortByKey = buildQueryKey(SORTBY, listComponentName);
3
+ const updateSort = (value, query, url) => {
8
4
  const [newSortBy, newSort] = value.split(':');
9
- const updatedQuery = { ...query, [sortByKey]: newSortBy, [sortKey]: newSort };
5
+ const updatedQuery = { ...query, sortby: newSortBy, sort: newSort };
10
6
  const parsedQuery = stringify(updatedQuery);
11
- return `${url}?${parsedQuery}${hashBit}`;
7
+ return `${url}?${parsedQuery}`;
12
8
  };
13
9
 
14
10
  export default updateSort;
@@ -1,7 +1,6 @@
1
1
  import flatten from 'lodash.flatten';
2
2
  import isFilterEntitysId from './is-filter-entitys-id';
3
3
  import getFilterProps from './get-filter-props';
4
- import { ID } from '../constants';
5
4
 
6
5
  const getRelationData = (entityData, relationName, currentRelationNames) => {
7
6
  if (!entityData) return null;
@@ -50,9 +49,8 @@ const buildInheritedFilters = (
50
49
  shouldIgnoreFilter
51
50
  } = getFilterProps(filter, currentSchema, filterEntitySchema);
52
51
 
53
- if (filterName === ID) return;
54
-
55
52
  const relationData = getRelationData(entityData, relationName, relationForeignKeys);
53
+
56
54
  if (
57
55
  (currentEntityId === entityName && isFilterEntitysId(filterName, currentEntityId)) ||
58
56
  shouldIgnoreFilter
@@ -44,21 +44,19 @@ const buildPropsQuery = (entitySchema, extraProps = [], cardOptions = null, link
44
44
  const buildComplexProps = (
45
45
  shouldAddCategoryProps,
46
46
  props,
47
- { relations = [], dynamicProperties = {}, properties = {} },
47
+ { relations = [], dynamicProperties = {} },
48
48
  linkProps
49
49
  ) =>
50
50
  Object.keys(props).map(base => {
51
51
  const nestedProps = props[base];
52
52
  const hasLink = !!linkProps.find(linkProp => linkProp.includes(base));
53
- const matchingProperty = !!properties[base];
54
53
  const matchingRelation = relations.find(({ localField }) => localField === base);
55
54
  const matchingDynamicProp = Object.keys(dynamicProperties).find(
56
55
  dynamicKey => dynamicKey === base
57
56
  );
58
57
 
59
58
  if (matchingRelation && !nestedProps.includes('id')) nestedProps.push('id');
60
- if (hasLink && (!!matchingProperty || !!matchingRelation || !!matchingDynamicProp))
61
- nestedProps.push('url');
59
+ if (hasLink && (!!matchingRelation || !!matchingDynamicProp)) nestedProps.push('url');
62
60
  const jointNestedProps = nestedProps.join(',');
63
61
  if (base === 'category' && shouldAddCategoryProps)
64
62
  return `${base}{${jointNestedProps}, ${categoryProps}}`;
@@ -31,9 +31,8 @@ const buildSetFilters = ({
31
31
  }
32
32
 
33
33
  const shouldApplyFilterValues = filterBy.length && filterByProperty.length;
34
- if (!shouldApplyFilterValues) return { checkboxFilters, listFilterValues: {} };
34
+ const listFilterValues = shouldApplyFilterValues ? getFilterValues(filterBy) : {};
35
35
 
36
- const listFilterValues = getFilterValues(filterBy);
37
36
  return { checkboxFilters, listFilterValues };
38
37
  };
39
38
 
@@ -2,9 +2,10 @@ import getSearchFilterType from './get-search-filter-type';
2
2
  import buildSearchValuesCheckboxSelect from './build-search-values-checkbox-select';
3
3
  import { RANGE, CHECKBOX, SELECT } from '../constants';
4
4
 
5
- const getQueryFilters = (searchFilter, query, listName) => {
6
- if (!searchFilter.settings || !searchFilter.settings.filters)
5
+ const getQueryFilters = (searchFilter, query) => {
6
+ if (!searchFilter.settings || !searchFilter.settings.filters) {
7
7
  return { valuesAnd: [], valuesOr: [] };
8
+ }
8
9
 
9
10
  const rangeFilters = getSearchFilterType(searchFilter, RANGE);
10
11
  const checkboxFilters = getSearchFilterType(searchFilter, CHECKBOX);
@@ -14,8 +15,7 @@ const getQueryFilters = (searchFilter, query, listName) => {
14
15
  query,
15
16
  rangeFilters,
16
17
  checkboxFilters,
17
- selectFilters,
18
- listName
18
+ selectFilters
19
19
  );
20
20
  return { valuesAnd, valuesOr };
21
21
  };
@@ -2,11 +2,10 @@ import isFilterEntitysId from './is-filter-entitys-id';
2
2
  import getFilterProps from './get-filter-props';
3
3
  import { ID } from '../constants';
4
4
 
5
- const getQueryProps = (inheritedFilters, currentSchema, filterEntitySchema = {}) => {
5
+ const getQueryProps = (inheritedFilters, currentSchema, filterEntitySchema) => {
6
6
  if (!currentSchema || !inheritedFilters.length) return ID;
7
7
 
8
- const { identifier: currentEntityId, properties } = currentSchema;
9
- const { identifier: filterEntityId } = filterEntitySchema;
8
+ const { identifier: currentEntityId } = currentSchema;
10
9
 
11
10
  return inheritedFilters.reduce((acc, filter) => {
12
11
  const {
@@ -18,19 +17,12 @@ const getQueryProps = (inheritedFilters, currentSchema, filterEntitySchema = {})
18
17
  relationForeignKeys,
19
18
  shouldIgnoreFilter
20
19
  } = getFilterProps(filter, currentSchema, filterEntitySchema);
20
+
21
21
  if (shouldIgnoreFilter) return acc;
22
22
  if (relationForeignKeys && relationForeignKeys.length) {
23
23
  return `${acc} ${relationForeignKeys.join(' ')}`;
24
24
  }
25
- if (filterName === ID) {
26
- const queryValue = Object.keys(properties).find(
27
- propKey =>
28
- properties[propKey] &&
29
- properties[propKey].relation &&
30
- properties[propKey].relation.entityIdentifier === filterEntityId
31
- );
32
- if (queryValue) return `${acc} ${queryValue} `;
33
- }
25
+
34
26
  const queryProp = relationEntityName ? `${relationName} { ${relationProp} }` : filterName;
35
27
  const queryPropFinalValue =
36
28
  isEntityItself && isFilterEntitysId(filterName, currentEntityId) ? ID : queryProp;
@@ -6,16 +6,13 @@ const getWrappedValueWithLink = (value, link, keyPrefix = '') => {
6
6
  const arrayResults = value.map((arrValue, index) => {
7
7
  const { keyField, url } = arrValue;
8
8
  const keyValue = arrValue[keyField];
9
-
10
9
  const isLastItem = index === value.length - 1;
11
- const keyFieldValue = isLastItem ? keyValue : <>{keyValue}, </>;
10
+ const keyFieldValue = isLastItem ? keyValue : keyValue.concat(',');
12
11
 
13
12
  return url ? (
14
- <BlazeLink key={[keyPrefix, index].join('-')} href={url}>
15
- {<>{keyFieldValue} </>}
16
- </BlazeLink>
13
+ <BlazeLink key={[keyPrefix, index].join('-')} href={url}>{`${keyFieldValue} `}</BlazeLink>
17
14
  ) : (
18
- <>{keyFieldValue} </>
15
+ `${keyFieldValue} `
19
16
  );
20
17
  });
21
18
 
@@ -51,5 +51,3 @@ export { default as getParsedPropValues } from './get-parsed-prop-values';
51
51
  export { default as getSanitizedPropValues } from './get-sanitized-prop-values';
52
52
  export { default as appendImages } from './append-images';
53
53
  export { default as parseTextBlock } from './parse-TextBlock';
54
- export { default as processDataSummaryValue } from './process-data-summary-value';
55
- export { default as buildQueryKey } from './build-query-key';