@blaze-cms/react-page-builder 0.131.0 → 0.132.0-admin-updates.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 (229) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/lib/components/Button.js +2 -1
  3. package/lib/components/Button.js.map +1 -1
  4. package/lib/components/Card/CardsRender.js +13 -6
  5. package/lib/components/Card/CardsRender.js.map +1 -1
  6. package/lib/components/Card/helpers/get-updated-items-to-display.js +55 -0
  7. package/lib/components/Card/helpers/get-updated-items-to-display.js.map +1 -0
  8. package/lib/components/Card/helpers/index.js +7 -0
  9. package/lib/components/Card/helpers/index.js.map +1 -1
  10. package/lib/components/CarouselWrapper/SmoothScrollCarousel.js +2 -2
  11. package/lib/components/CarouselWrapper/SmoothScrollCarousel.js.map +1 -1
  12. package/lib/components/Code/Code.js +7 -3
  13. package/lib/components/Code/Code.js.map +1 -1
  14. package/lib/components/DataSummary/helpers/build-loop-props-content.js +6 -3
  15. package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
  16. package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js +3 -2
  17. package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
  18. package/lib/components/DataSummary/helpers/get-link-to-published-content.js +2 -0
  19. package/lib/components/DataSummary/helpers/get-link-to-published-content.js.map +1 -1
  20. package/lib/components/List/ListFactory.js +16 -11
  21. package/lib/components/List/ListFactory.js.map +1 -1
  22. package/lib/components/List/helpers/get-list-query.js +43 -0
  23. package/lib/components/List/helpers/get-list-query.js.map +1 -0
  24. package/lib/components/List/helpers/get-list-specific-search-filter.js +21 -0
  25. package/lib/components/List/helpers/get-list-specific-search-filter.js.map +1 -0
  26. package/lib/components/List/helpers/index.js +14 -0
  27. package/lib/components/List/helpers/index.js.map +1 -1
  28. package/lib/components/List/helpers/strip-query-key.js +14 -0
  29. package/lib/components/List/helpers/strip-query-key.js.map +1 -0
  30. package/lib/components/SearchContent/SearchContent.js +8 -8
  31. package/lib/components/SearchContent/SearchContent.js.map +1 -1
  32. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +17 -13
  33. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  34. package/lib/components/SearchFilter/SearchFilterContainer.js +64 -83
  35. package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  36. package/lib/components/SearchFilter/helpers/build-filters-query.js +3 -1
  37. package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
  38. package/lib/components/SearchFilter/helpers/build-new-url.js +17 -0
  39. package/lib/components/SearchFilter/helpers/build-new-url.js.map +1 -0
  40. package/lib/components/SearchFilter/helpers/build-url-query.js +49 -0
  41. package/lib/components/SearchFilter/helpers/build-url-query.js.map +1 -0
  42. package/lib/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +32 -0
  43. package/lib/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js.map +1 -0
  44. package/lib/components/SearchFilter/helpers/get-filter-values.js +31 -0
  45. package/lib/components/SearchFilter/helpers/get-filter-values.js.map +1 -0
  46. package/lib/components/SearchFilter/helpers/index.js +18 -11
  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/SearchFilter/searchFilterReducer.js +43 -0
  50. package/lib/components/SearchFilter/searchFilterReducer.js.map +1 -0
  51. package/lib/components/SearchFilterSort/SearchFilterSort.js +31 -11
  52. package/lib/components/SearchFilterSort/SearchFilterSort.js.map +1 -1
  53. package/lib/components/SearchFilterSort/helpers/handle-sort-update.js +19 -5
  54. package/lib/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
  55. package/lib/components/SearchFilterSort/helpers/update-sort.js +9 -5
  56. package/lib/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
  57. package/lib/helpers/build-inherited-filters.js +2 -0
  58. package/lib/helpers/build-inherited-filters.js.map +1 -1
  59. package/lib/helpers/build-props-query.js +5 -2
  60. package/lib/helpers/build-props-query.js.map +1 -1
  61. package/lib/helpers/build-query-key.js +16 -0
  62. package/lib/helpers/build-query-key.js.map +1 -0
  63. package/lib/helpers/build-set-filters.js +5 -1
  64. package/lib/helpers/build-set-filters.js.map +1 -1
  65. package/lib/helpers/get-entities-with-banner.js +8 -2
  66. package/lib/helpers/get-entities-with-banner.js.map +1 -1
  67. package/lib/helpers/get-query-filters.js +6 -8
  68. package/lib/helpers/get-query-filters.js.map +1 -1
  69. package/lib/helpers/get-query-props.js +13 -2
  70. package/lib/helpers/get-query-props.js.map +1 -1
  71. package/lib/helpers/get-wrapped-value-with-link.js +2 -3
  72. package/lib/helpers/get-wrapped-value-with-link.js.map +1 -1
  73. package/lib/helpers/index.js +14 -0
  74. package/lib/helpers/index.js.map +1 -1
  75. package/lib/helpers/parse-props-to-display.js +13 -8
  76. package/lib/helpers/parse-props-to-display.js.map +1 -1
  77. package/lib/helpers/process-data-summary-value.js +56 -0
  78. package/lib/helpers/process-data-summary-value.js.map +1 -0
  79. package/lib-es/components/Button.js +2 -1
  80. package/lib-es/components/Button.js.map +1 -1
  81. package/lib-es/components/Card/CardsRender.js +14 -7
  82. package/lib-es/components/Card/CardsRender.js.map +1 -1
  83. package/lib-es/components/Card/helpers/get-updated-items-to-display.js +32 -0
  84. package/lib-es/components/Card/helpers/get-updated-items-to-display.js.map +1 -0
  85. package/lib-es/components/Card/helpers/index.js +1 -0
  86. package/lib-es/components/Card/helpers/index.js.map +1 -1
  87. package/lib-es/components/CarouselWrapper/SmoothScrollCarousel.js +2 -2
  88. package/lib-es/components/CarouselWrapper/SmoothScrollCarousel.js.map +1 -1
  89. package/lib-es/components/Code/Code.js +8 -4
  90. package/lib-es/components/Code/Code.js.map +1 -1
  91. package/lib-es/components/DataSummary/helpers/build-loop-props-content.js +6 -3
  92. package/lib-es/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
  93. package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js +4 -3
  94. package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
  95. package/lib-es/components/DataSummary/helpers/get-link-to-published-content.js +2 -1
  96. package/lib-es/components/DataSummary/helpers/get-link-to-published-content.js.map +1 -1
  97. package/lib-es/components/List/ListFactory.js +16 -12
  98. package/lib-es/components/List/ListFactory.js.map +1 -1
  99. package/lib-es/components/List/helpers/get-list-query.js +24 -0
  100. package/lib-es/components/List/helpers/get-list-query.js.map +1 -0
  101. package/lib-es/components/List/helpers/get-list-specific-search-filter.js +12 -0
  102. package/lib-es/components/List/helpers/get-list-specific-search-filter.js.map +1 -0
  103. package/lib-es/components/List/helpers/index.js +2 -0
  104. package/lib-es/components/List/helpers/index.js.map +1 -1
  105. package/lib-es/components/List/helpers/strip-query-key.js +6 -0
  106. package/lib-es/components/List/helpers/strip-query-key.js.map +1 -0
  107. package/lib-es/components/SearchContent/SearchContent.js +8 -8
  108. package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
  109. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +18 -13
  110. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  111. package/lib-es/components/SearchFilter/SearchFilterContainer.js +48 -70
  112. package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  113. package/lib-es/components/SearchFilter/helpers/build-filters-query.js +2 -0
  114. package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
  115. package/lib-es/components/SearchFilter/helpers/build-new-url.js +8 -0
  116. package/lib-es/components/SearchFilter/helpers/build-new-url.js.map +1 -0
  117. package/lib-es/components/SearchFilter/helpers/build-url-query.js +31 -0
  118. package/lib-es/components/SearchFilter/helpers/build-url-query.js.map +1 -0
  119. package/lib-es/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +18 -0
  120. package/lib-es/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js.map +1 -0
  121. package/lib-es/components/SearchFilter/helpers/get-filter-values.js +19 -0
  122. package/lib-es/components/SearchFilter/helpers/get-filter-values.js.map +1 -0
  123. package/lib-es/components/SearchFilter/helpers/index.js +5 -4
  124. package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
  125. package/lib-es/components/SearchFilter/index.js +2 -2
  126. package/lib-es/components/SearchFilter/index.js.map +1 -1
  127. package/lib-es/components/SearchFilter/searchFilterReducer.js +26 -0
  128. package/lib-es/components/SearchFilter/searchFilterReducer.js.map +1 -0
  129. package/lib-es/components/SearchFilterSort/SearchFilterSort.js +26 -10
  130. package/lib-es/components/SearchFilterSort/SearchFilterSort.js.map +1 -1
  131. package/lib-es/components/SearchFilterSort/helpers/handle-sort-update.js +21 -4
  132. package/lib-es/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
  133. package/lib-es/components/SearchFilterSort/helpers/update-sort.js +8 -4
  134. package/lib-es/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
  135. package/lib-es/helpers/build-inherited-filters.js +2 -0
  136. package/lib-es/helpers/build-inherited-filters.js.map +1 -1
  137. package/lib-es/helpers/build-props-query.js +4 -2
  138. package/lib-es/helpers/build-props-query.js.map +1 -1
  139. package/lib-es/helpers/build-query-key.js +7 -0
  140. package/lib-es/helpers/build-query-key.js.map +1 -0
  141. package/lib-es/helpers/build-set-filters.js +5 -1
  142. package/lib-es/helpers/build-set-filters.js.map +1 -1
  143. package/lib-es/helpers/get-entities-with-banner.js +9 -2
  144. package/lib-es/helpers/get-entities-with-banner.js.map +1 -1
  145. package/lib-es/helpers/get-query-filters.js +6 -8
  146. package/lib-es/helpers/get-query-filters.js.map +1 -1
  147. package/lib-es/helpers/get-query-props.js +10 -2
  148. package/lib-es/helpers/get-query-props.js.map +1 -1
  149. package/lib-es/helpers/get-wrapped-value-with-link.js +2 -2
  150. package/lib-es/helpers/get-wrapped-value-with-link.js.map +1 -1
  151. package/lib-es/helpers/index.js +2 -0
  152. package/lib-es/helpers/index.js.map +1 -1
  153. package/lib-es/helpers/parse-props-to-display.js +12 -9
  154. package/lib-es/helpers/parse-props-to-display.js.map +1 -1
  155. package/lib-es/helpers/process-data-summary-value.js +36 -0
  156. package/lib-es/helpers/process-data-summary-value.js.map +1 -0
  157. package/package.json +10 -10
  158. package/src/components/Button.js +2 -1
  159. package/src/components/Card/CardsRender.js +27 -7
  160. package/src/components/Card/helpers/get-updated-items-to-display.js +32 -0
  161. package/src/components/Card/helpers/index.js +1 -0
  162. package/src/components/CarouselWrapper/SmoothScrollCarousel.js +2 -2
  163. package/src/components/Code/Code.js +7 -3
  164. package/src/components/DataSummary/helpers/build-loop-props-content.js +7 -3
  165. package/src/components/DataSummary/helpers/build-props-to-display-with-content.js +6 -3
  166. package/src/components/DataSummary/helpers/get-link-to-published-content.js +4 -1
  167. package/src/components/List/ListFactory.js +25 -15
  168. package/src/components/List/helpers/get-list-query.js +28 -0
  169. package/src/components/List/helpers/get-list-specific-search-filter.js +10 -0
  170. package/src/components/List/helpers/index.js +2 -0
  171. package/src/components/List/helpers/strip-query-key.js +6 -0
  172. package/src/components/SearchContent/SearchContent.js +8 -8
  173. package/src/components/SearchFilter/SearchFilter/SearchFilter.js +21 -18
  174. package/src/components/SearchFilter/SearchFilterContainer.js +59 -67
  175. package/src/components/SearchFilter/helpers/build-filters-query.js +9 -1
  176. package/src/components/SearchFilter/helpers/build-new-url.js +8 -0
  177. package/src/components/SearchFilter/helpers/build-url-query.js +33 -0
  178. package/src/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +17 -0
  179. package/src/components/SearchFilter/helpers/get-filter-values.js +21 -0
  180. package/src/components/SearchFilter/helpers/index.js +9 -7
  181. package/src/components/SearchFilter/index.js +2 -2
  182. package/src/components/SearchFilter/searchFilterReducer.js +15 -0
  183. package/src/components/SearchFilterSort/SearchFilterSort.js +18 -8
  184. package/src/components/SearchFilterSort/helpers/handle-sort-update.js +14 -5
  185. package/src/components/SearchFilterSort/helpers/update-sort.js +7 -3
  186. package/src/helpers/build-inherited-filters.js +3 -1
  187. package/src/helpers/build-props-query.js +4 -2
  188. package/src/helpers/build-query-key.js +7 -0
  189. package/src/helpers/build-set-filters.js +2 -1
  190. package/src/helpers/get-entities-with-banner.js +3 -2
  191. package/src/helpers/get-query-filters.js +4 -4
  192. package/src/helpers/get-query-props.js +12 -4
  193. package/src/helpers/get-wrapped-value-with-link.js +6 -3
  194. package/src/helpers/index.js +2 -0
  195. package/src/helpers/parse-props-to-display.js +25 -21
  196. package/src/helpers/process-data-summary-value.js +22 -0
  197. package/tests/helpers/mocks.js +3 -5
  198. package/tests/unit/src/components/Card/helpers/get-updated-items-to-display.test.js +72 -0
  199. package/tests/unit/src/components/Code/Code.test.js +5 -0
  200. package/tests/unit/src/components/Code/__snapshots__/Code.test.js.snap +8 -0
  201. package/tests/unit/src/components/DataSummary/helpers/build-loop-props-content.test.js +50 -0
  202. package/tests/unit/src/components/DataSummary/helpers/get-link-to-published-content.test.js +21 -0
  203. package/tests/unit/src/components/SearchFilter/__snapshots__/SearchFilterContainer.test.js.snap +1 -7
  204. package/tests/unit/src/components/SearchFilter/helpers/build-new-query.test.js +10 -10
  205. package/tests/unit/src/components/SearchFilter/helpers/build-query.test.js +24 -7
  206. package/tests/unit/src/components/SearchFilter/helpers/get-initial-filter-values.test.js +10 -10
  207. package/tests/unit/src/components/SearchFilterSort/SearchFilterSort.test.js +4 -1
  208. package/tests/unit/src/components/SearchFilterSort/helpers/handle-sort-update.test.js +26 -19
  209. package/tests/unit/src/components/SearchFilterSort/helpers/update-sort.test.js +10 -1
  210. package/tests/unit/src/helpers/__snapshots__/get-wrapped-value-with-link.test.js.snap +18 -0
  211. package/tests/unit/src/helpers/build-props-query.test.js +25 -0
  212. package/tests/unit/src/helpers/get-wrapped-value-with-link.test.js +2 -2
  213. package/tests/unit/src/helpers/parse-props-to-display.test.js +4 -0
  214. package/tests/unit/src/helpers/prcoess-data-summary-value.test.js +52 -0
  215. package/lib/components/SearchFilter/helpers/build-new-query.js +0 -15
  216. package/lib/components/SearchFilter/helpers/build-new-query.js.map +0 -1
  217. package/lib/components/SearchFilter/helpers/build-query.js +0 -37
  218. package/lib/components/SearchFilter/helpers/build-query.js.map +0 -1
  219. package/lib/components/SearchFilter/helpers/get-initial-filter-values.js +0 -43
  220. package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +0 -1
  221. package/lib-es/components/SearchFilter/helpers/build-new-query.js +0 -6
  222. package/lib-es/components/SearchFilter/helpers/build-new-query.js.map +0 -1
  223. package/lib-es/components/SearchFilter/helpers/build-query.js +0 -23
  224. package/lib-es/components/SearchFilter/helpers/build-query.js.map +0 -1
  225. package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js +0 -26
  226. package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +0 -1
  227. package/src/components/SearchFilter/helpers/build-new-query.js +0 -6
  228. package/src/components/SearchFilter/helpers/build-query.js +0 -26
  229. package/src/components/SearchFilter/helpers/get-initial-filter-values.js +0 -30
@@ -0,0 +1,15 @@
1
+ const searchFilterReducer = (state, action) => {
2
+ const { newValues, type, shouldSearch = true } = action;
3
+ switch (type) {
4
+ case 'update':
5
+ return { ...state, ...newValues, shouldSearch };
6
+ case 'resetSearch':
7
+ return { ...state, shouldSearch: false };
8
+ case 'reset':
9
+ return null;
10
+ default:
11
+ throw new Error();
12
+ }
13
+ };
14
+
15
+ export default searchFilterReducer;
@@ -1,15 +1,23 @@
1
1
  import React from 'react';
2
2
  import Select from '@blaze-react/select';
3
- import { withRouter } from 'next/router';
3
+ import { useRouter } 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 SearchFilterSort = ({ router, filters, elementLabel, selectLabel, id }) => {
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();
11
18
  const { asPath } = router;
12
- const { url, query, query: { sort, sortby } = {} } = parseUrl(asPath);
19
+ const [sortKey, sortByKey] = getSortFromQuery(listComponentName);
20
+ const { url, query, query: { [sortKey]: sort, [sortByKey]: sortby } = {} } = parseUrl(asPath);
13
21
  const selectedValue = `${sortby}:${sort}` || '';
14
22
  const defaultTextValue = selectLabel || DEFAULT_SORT;
15
23
  const options = filters.map(({ label: optionLabel, propsToDisplay, sort: sortValue }) => [
@@ -17,7 +25,8 @@ const SearchFilterSort = ({ router, filters, elementLabel, selectLabel, id }) =>
17
25
  optionLabel
18
26
  ]);
19
27
 
20
- const setSortValue = ({ value }) => handleSortUpdate(router, value, query, url, selectLabel);
28
+ const setSortValue = ({ value }) =>
29
+ handleSortUpdate({ router, value, query, url, selectLabel, listComponentName });
21
30
 
22
31
  return (
23
32
  <div className="sort-by">
@@ -34,18 +43,19 @@ const SearchFilterSort = ({ router, filters, elementLabel, selectLabel, id }) =>
34
43
  };
35
44
 
36
45
  SearchFilterSort.propTypes = {
37
- router: PropTypes.object.isRequired,
38
46
  filters: PropTypes.array,
39
47
  elementLabel: PropTypes.string,
40
48
  selectLabel: PropTypes.string,
41
- id: PropTypes.string
49
+ id: PropTypes.string,
50
+ listComponentName: PropTypes.string
42
51
  };
43
52
 
44
53
  SearchFilterSort.defaultProps = {
45
54
  filters: [],
46
55
  elementLabel: '',
47
56
  selectLabel: '',
48
- id: ''
57
+ id: '',
58
+ listComponentName: ''
49
59
  };
50
60
 
51
- export default withRouter(withTitle(SearchFilterSort));
61
+ export default withTitle(SearchFilterSort);
@@ -2,21 +2,30 @@ 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) => {
5
+ const handleSortUpdate = ({ router, value, query, url, selectLabel, listComponentName }) => {
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}`;
8
16
  Object.keys(query).forEach(key => {
9
17
  if (key.indexOf(PAGINATION_QUERY) !== -1) return;
10
- if (key !== SORTBY && key !== SORT) queryWithoutSort[key] = query[key];
18
+ if (key !== sortByKey && key !== sortKey) queryWithoutSort[key] = query[key];
11
19
  });
12
20
  if (value === DEFAULT_SORT || value === selectLabel) {
13
21
  const stringifiedQuery = stringify(queryWithoutSort);
14
22
 
15
23
  return stringifiedQuery
16
- ? router.push(`/Resolver`, `${url}?${stringifiedQuery}`, routerOptions)
17
- : router.push(`/Resolver`, url, routerOptions);
24
+ ? router.push(`/Resolver`, `${url}?${stringifiedQuery}${parsedHash}`, routerOptions)
25
+ : router.push(`/Resolver`, `${url}${parsedHash}`, routerOptions);
18
26
  }
19
- const updatedSortUrl = updateSort(value, queryWithoutSort, url);
27
+
28
+ const updatedSortUrl = updateSort(value, queryWithoutSort, url, parsedHash, listComponentName);
20
29
  return router.push('/Resolver', updatedSortUrl, routerOptions);
21
30
  };
22
31
 
@@ -1,10 +1,14 @@
1
1
  import { stringify } from 'query-string';
2
+ import { buildQueryKey } from '../../../helpers';
3
+ import { SORT, SORTBY } from '../constants';
2
4
 
3
- const updateSort = (value, query, url) => {
5
+ const updateSort = (value, query, url, hashBit = '', listComponentName = '') => {
6
+ const sortKey = buildQueryKey(SORT, listComponentName);
7
+ const sortByKey = buildQueryKey(SORTBY, listComponentName);
4
8
  const [newSortBy, newSort] = value.split(':');
5
- const updatedQuery = { ...query, sortby: newSortBy, sort: newSort };
9
+ const updatedQuery = { ...query, [sortByKey]: newSortBy, [sortKey]: newSort };
6
10
  const parsedQuery = stringify(updatedQuery);
7
- return `${url}?${parsedQuery}`;
11
+ return `${url}?${parsedQuery}${hashBit}`;
8
12
  };
9
13
 
10
14
  export default updateSort;
@@ -1,6 +1,7 @@
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';
4
5
 
5
6
  const getRelationData = (entityData, relationName, currentRelationNames) => {
6
7
  if (!entityData) return null;
@@ -49,8 +50,9 @@ const buildInheritedFilters = (
49
50
  shouldIgnoreFilter
50
51
  } = getFilterProps(filter, currentSchema, filterEntitySchema);
51
52
 
52
- const relationData = getRelationData(entityData, relationName, relationForeignKeys);
53
+ if (filterName === ID) return;
53
54
 
55
+ const relationData = getRelationData(entityData, relationName, relationForeignKeys);
54
56
  if (
55
57
  (currentEntityId === entityName && isFilterEntitysId(filterName, currentEntityId)) ||
56
58
  shouldIgnoreFilter
@@ -44,19 +44,21 @@ const buildPropsQuery = (entitySchema, extraProps = [], cardOptions = null, link
44
44
  const buildComplexProps = (
45
45
  shouldAddCategoryProps,
46
46
  props,
47
- { relations = [], dynamicProperties = {} },
47
+ { relations = [], dynamicProperties = {}, properties = {} },
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];
53
54
  const matchingRelation = relations.find(({ localField }) => localField === base);
54
55
  const matchingDynamicProp = Object.keys(dynamicProperties).find(
55
56
  dynamicKey => dynamicKey === base
56
57
  );
57
58
 
58
59
  if (matchingRelation && !nestedProps.includes('id')) nestedProps.push('id');
59
- if (hasLink && (!!matchingRelation || !!matchingDynamicProp)) nestedProps.push('url');
60
+ if (hasLink && (!!matchingProperty || !!matchingRelation || !!matchingDynamicProp))
61
+ nestedProps.push('url');
60
62
  const jointNestedProps = nestedProps.join(',');
61
63
  if (base === 'category' && shouldAddCategoryProps)
62
64
  return `${base}{${jointNestedProps}, ${categoryProps}}`;
@@ -0,0 +1,7 @@
1
+ const buildQueryKey = (key, listName) => {
2
+ const listNameKey = listName ? `pb[${listName}]` : '';
3
+ const wrappedSearchKey = listNameKey ? `[${key}]` : key;
4
+ return `${listNameKey}${wrappedSearchKey}`;
5
+ };
6
+
7
+ export default buildQueryKey;
@@ -31,8 +31,9 @@ const buildSetFilters = ({
31
31
  }
32
32
 
33
33
  const shouldApplyFilterValues = filterBy.length && filterByProperty.length;
34
- const listFilterValues = shouldApplyFilterValues ? getFilterValues(filterBy) : {};
34
+ if (!shouldApplyFilterValues) return { checkboxFilters, listFilterValues: {} };
35
35
 
36
+ const listFilterValues = getFilterValues(filterBy);
36
37
  return { checkboxFilters, listFilterValues };
37
38
  };
38
39
 
@@ -4,8 +4,9 @@ export default function getEntitiesWithBanner(entities, options, hasNewBannerSet
4
4
  const { hasBanner } = options;
5
5
  if (hasNewBannerSettings) {
6
6
  return entities.map(currentEntity => {
7
- const { parent, transform, limit } = options;
8
- return { ...currentEntity, parent, limit, transform };
7
+ const { parent, transform, limit, banner } = options;
8
+ const { adunit, baseAdunit } = banner || {};
9
+ return { ...currentEntity, parent, limit, transform, adunit, baseAdunit };
9
10
  });
10
11
  }
11
12
  if (!hasBanner) return entities;
@@ -2,10 +2,9 @@ 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) => {
6
- if (!searchFilter.settings || !searchFilter.settings.filters) {
5
+ const getQueryFilters = (searchFilter, query, listName) => {
6
+ if (!searchFilter.settings || !searchFilter.settings.filters)
7
7
  return { valuesAnd: [], valuesOr: [] };
8
- }
9
8
 
10
9
  const rangeFilters = getSearchFilterType(searchFilter, RANGE);
11
10
  const checkboxFilters = getSearchFilterType(searchFilter, CHECKBOX);
@@ -15,7 +14,8 @@ const getQueryFilters = (searchFilter, query) => {
15
14
  query,
16
15
  rangeFilters,
17
16
  checkboxFilters,
18
- selectFilters
17
+ selectFilters,
18
+ listName
19
19
  );
20
20
  return { valuesAnd, valuesOr };
21
21
  };
@@ -2,10 +2,11 @@ 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 } = currentSchema;
8
+ const { identifier: currentEntityId, properties } = currentSchema;
9
+ const { identifier: filterEntityId } = filterEntitySchema;
9
10
 
10
11
  return inheritedFilters.reduce((acc, filter) => {
11
12
  const {
@@ -17,12 +18,19 @@ const getQueryProps = (inheritedFilters, currentSchema, filterEntitySchema) => {
17
18
  relationForeignKeys,
18
19
  shouldIgnoreFilter
19
20
  } = 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
-
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
+ }
26
34
  const queryProp = relationEntityName ? `${relationName} { ${relationProp} }` : filterName;
27
35
  const queryPropFinalValue =
28
36
  isEntityItself && isFilterEntitysId(filterName, currentEntityId) ? ID : queryProp;
@@ -6,13 +6,16 @@ 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
+
9
10
  const isLastItem = index === value.length - 1;
10
- const keyFieldValue = isLastItem ? keyValue : keyValue.concat(',');
11
+ const keyFieldValue = isLastItem ? keyValue : <>{keyValue}, </>;
11
12
 
12
13
  return url ? (
13
- <BlazeLink key={[keyPrefix, index].join('-')} href={url}>{`${keyFieldValue} `}</BlazeLink>
14
+ <BlazeLink key={[keyPrefix, index].join('-')} href={url}>
15
+ {<>{keyFieldValue} </>}
16
+ </BlazeLink>
14
17
  ) : (
15
- `${keyFieldValue} `
18
+ <>{keyFieldValue} </>
16
19
  );
17
20
  });
18
21
 
@@ -51,3 +51,5 @@ 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';
@@ -4,35 +4,39 @@ import isObject from './is-object';
4
4
  import getParsedPropValues from './get-parsed-prop-values';
5
5
  import getSanitizedPropValues from './get-sanitized-prop-values';
6
6
  import { BOLD_TAG, BLANK_SPACE_UNICODE_STRING } from '../constants';
7
+ import processDataSummaryValue from './process-data-summary-value';
7
8
 
8
9
  // TODO this helper should be removed if database is wiped clean and all elements change to new props struc
9
10
  const parsePropsToDisplay = (props = {}, propsToDisplay = []) => {
10
11
  if (!isObject(propsToDisplay[0])) return at(props, propsToDisplay).filter(Boolean);
11
12
 
12
- return propsToDisplay.map(
13
- ({ bold, propertiesToDisplay, prefix, suffix, shouldStrip, enableLink }, currentIndex) => {
14
- const Wrapper = bold ? BOLD_TAG : Fragment;
13
+ return propsToDisplay.map((options, currentIndex) => {
14
+ const { bold, propertiesToDisplay, prefix, suffix, shouldStrip, enableLink } = options;
15
+ const Wrapper = bold ? BOLD_TAG : Fragment;
15
16
 
16
- const parsedPropValues = getParsedPropValues({
17
- propertiesToDisplay,
18
- props,
19
- enableLink,
20
- shouldStrip
21
- });
17
+ const parsedPropValues = getParsedPropValues({
18
+ propertiesToDisplay,
19
+ props,
20
+ enableLink,
21
+ shouldStrip
22
+ });
22
23
 
23
- const sanitizedPropValues = getSanitizedPropValues(parsedPropValues);
24
- if (!sanitizedPropValues || !sanitizedPropValues.length) return null;
25
- const stringEndBlank =
26
- currentIndex + 1 === propsToDisplay.length ? '' : BLANK_SPACE_UNICODE_STRING;
24
+ const sanitizedPropValues = getSanitizedPropValues(parsedPropValues);
25
+ if (!sanitizedPropValues || !sanitizedPropValues.length) return null;
26
+ const stringEndBlank =
27
+ currentIndex + 1 === propsToDisplay.length ? '' : BLANK_SPACE_UNICODE_STRING;
27
28
 
28
- return (
29
- <Wrapper>
30
- {prefix} {sanitizedPropValues} {suffix}
31
- {stringEndBlank}
32
- </Wrapper>
33
- );
34
- }
35
- );
29
+ const processedValue = Array.isArray(sanitizedPropValues)
30
+ ? sanitizedPropValues.map(value => processDataSummaryValue(value, options))
31
+ : processDataSummaryValue(sanitizedPropValues, options);
32
+
33
+ return (
34
+ <Wrapper>
35
+ {prefix} {processedValue} {suffix}
36
+ {stringEndBlank}
37
+ </Wrapper>
38
+ );
39
+ });
36
40
  };
37
41
 
38
42
  export default parsePropsToDisplay;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import components from '../components';
3
+
4
+ const { code: Code } = components;
5
+
6
+ const renderCode = value => <Code code={value} disableWrapper />;
7
+
8
+ const processDataSummaryValue = (objPropValue, { isHtml }) => {
9
+ let pValue = objPropValue;
10
+ if (isHtml) {
11
+ pValue = Array.isArray(objPropValue)
12
+ ? objPropValue.map(({ keyField, [keyField]: value, ...otherProps }) => ({
13
+ [keyField]: renderCode(value),
14
+ keyField,
15
+ ...otherProps
16
+ }))
17
+ : renderCode(objPropValue);
18
+ }
19
+ return pValue;
20
+ };
21
+
22
+ export default processDataSummaryValue;
@@ -1139,11 +1139,9 @@ const MOCKED_PROPS_FILTERS_LIST = {
1139
1139
  };
1140
1140
 
1141
1141
  const MOCKED_PROPS_SEARCH_FILTER = {
1142
- router: {
1143
- asPath: 'somePath',
1144
- query: {},
1145
- push: () => {}
1146
- },
1142
+ listComponentName: '',
1143
+ filterData: {},
1144
+ asPath: 'somePath',
1147
1145
  parent: {
1148
1146
  itemEntity: 'published_page'
1149
1147
  },
@@ -0,0 +1,72 @@
1
+ import '@testing-library/jest-dom/extend-expect';
2
+ import getUpdatedItemsToDisplay from '../../../../../../src/components/Card/helpers/get-updated-items-to-display';
3
+
4
+ const mockedProps = {
5
+ itemsToDisplay: [
6
+ {
7
+ displayItems: ['54321']
8
+ }
9
+ ],
10
+ parentEntityData: {
11
+ authorIds: ['12345']
12
+ },
13
+ parentSchema: {
14
+ properties: {
15
+ authorIds: {
16
+ relation: {
17
+ entityIdentifier: 'author'
18
+ }
19
+ }
20
+ }
21
+ },
22
+ inheritedFilters: ['id/author']
23
+ };
24
+
25
+ describe('getUpdatedItemsToDisplay helper function', () => {
26
+ it('should return empty array if no props passed', () => {
27
+ const emptyArray = getUpdatedItemsToDisplay({});
28
+ expect(emptyArray).toEqual([]);
29
+ });
30
+
31
+ it('should return old itemsToDisplay itemsToDisplay if no idProp match, no parentSchema or no parentEntityData', () => {
32
+ const onlyItemsToDisplayPassed = getUpdatedItemsToDisplay({
33
+ itemsToDisplay: mockedProps.itemsToDisplay
34
+ });
35
+ const noIdPropMatch = getUpdatedItemsToDisplay({
36
+ ...mockedProps,
37
+ inheritedFilters: ['notid/author']
38
+ });
39
+ const noParentSchema = getUpdatedItemsToDisplay({
40
+ ...mockedProps,
41
+ parentSchema: null
42
+ });
43
+ const noParentEntityData = getUpdatedItemsToDisplay({
44
+ ...mockedProps,
45
+ parentEntityData: null
46
+ });
47
+ expect(onlyItemsToDisplayPassed).toEqual(mockedProps.itemsToDisplay);
48
+ expect(noIdPropMatch).toEqual(mockedProps.itemsToDisplay);
49
+ expect(noParentSchema).toEqual(mockedProps.itemsToDisplay);
50
+ expect(noParentEntityData).toEqual(mockedProps.itemsToDisplay);
51
+ });
52
+
53
+ it('should return old itemsToDisplay if parentSchema has no propMatch with idProp entity', () => {
54
+ const sameItemsToDisplay = getUpdatedItemsToDisplay({
55
+ ...mockedProps,
56
+ inheritedFilters: ['id/noentitymatch']
57
+ });
58
+ expect(sameItemsToDisplay).toEqual(mockedProps.itemsToDisplay);
59
+ });
60
+
61
+ it('should return updated itemsToDisplay otherwise', () => {
62
+ const sameItemsToDisplay = getUpdatedItemsToDisplay({
63
+ ...mockedProps
64
+ });
65
+ expect(sameItemsToDisplay).toEqual([
66
+ ...mockedProps.itemsToDisplay,
67
+ {
68
+ displayItems: ['12345']
69
+ }
70
+ ]);
71
+ });
72
+ });
@@ -23,6 +23,11 @@ describe('Code component', () => {
23
23
  expect(asFragment()).toMatchSnapshot();
24
24
  });
25
25
 
26
+ it('should not render wrapper', () => {
27
+ const { asFragment } = render(Code, { ...props, disableWrapper: true });
28
+ expect(asFragment()).toMatchSnapshot();
29
+ });
30
+
26
31
  it('should return null if there is not embed code', () => {
27
32
  const { container } = render(Code, {});
28
33
  expect(container.innerHTML).toBe('');
@@ -27,3 +27,11 @@ exports[`Code component should not render script tags 1`] = `
27
27
  </div>
28
28
  </DocumentFragment>
29
29
  `;
30
+
31
+ exports[`Code component should not render wrapper 1`] = `
32
+ <DocumentFragment>
33
+ <p>
34
+ Lorem ipsum
35
+ </p>
36
+ </DocumentFragment>
37
+ `;
@@ -1,6 +1,11 @@
1
1
  import '@testing-library/jest-dom/extend-expect';
2
2
  import buildLoopPropsContent from '../../../../../../src/components/DataSummary/helpers/build-loop-props-content';
3
3
  import { mockedLoopProps, mockedPropsToDisplay, mockedData, mockedResults } from './mocks';
4
+ import processDataSummaryValue from '../../../../../../src/helpers/process-data-summary-value';
5
+
6
+ jest.mock('../../../../../../src/helpers/process-data-summary-value', () =>
7
+ jest.fn(value => value)
8
+ );
4
9
 
5
10
  describe('buildLoopPropsContent helper function', () => {
6
11
  const noParamsPassed = buildLoopPropsContent();
@@ -41,6 +46,10 @@ describe('buildLoopPropsContent helper function', () => {
41
46
  expect(noDataPassed).toEqual([]);
42
47
  });
43
48
 
49
+ it('should call processDataSummaryValue', () => {
50
+ expect(processDataSummaryValue).toHaveBeenCalledWith('pre data name', mockedPropsToDisplay[0]);
51
+ });
52
+
44
53
  it('should return regular dataSummary content if no loopable values are found', () => {
45
54
  expect(withNoLoopValues).toEqual(mockedResults[0]);
46
55
  expect(withNoLoopableValues).toEqual(mockedResults[1]);
@@ -81,4 +90,45 @@ describe('buildLoopPropsContent helper function', () => {
81
90
  });
82
91
  expect.hasAssertions();
83
92
  });
93
+
94
+ it('should nested items with urls', () => {
95
+ const data = {
96
+ nestedLoopProp: [
97
+ {
98
+ nestedValue: 'abc',
99
+ url: 'http://blazecms.app/abc'
100
+ },
101
+ {
102
+ nestedValue: '123',
103
+ url: 'http://blazecms.app/123'
104
+ },
105
+ {
106
+ nestedValue: 'no url',
107
+ url: null
108
+ }
109
+ ]
110
+ };
111
+ const withUrl = buildLoopPropsContent(
112
+ mockedLoopProps,
113
+ [
114
+ {
115
+ bold: false,
116
+ enableLink: true,
117
+ label: '',
118
+ modifier: '',
119
+ prefix: '',
120
+ propertiesToDisplay: ['nestedLoopProp.nestedValue'],
121
+ shouldStrip: true
122
+ }
123
+ ],
124
+ 0,
125
+ data
126
+ );
127
+
128
+ withUrl.forEach(([, value, url], index) => {
129
+ expect(value).toEqual(data.nestedLoopProp[index].nestedValue);
130
+ expect(url).toEqual(data.nestedLoopProp[index].url || '');
131
+ });
132
+ expect.hasAssertions();
133
+ });
84
134
  });
@@ -38,4 +38,25 @@ describe('get link to published content', () => {
38
38
  const result = getLinkToPublishedContent(publishedKey, props);
39
39
  expect(result).toEqual('');
40
40
  });
41
+
42
+ it('should return url from the currentValue', () => {
43
+ const currentValue = { url: 'currentValueUrl' };
44
+ const props = { content: [content] };
45
+ const result = getLinkToPublishedContent(publishedKey, props, currentValue);
46
+ expect(result).toEqual(currentValue.url);
47
+ });
48
+
49
+ it('should return url from the currentValue even if falsey', () => {
50
+ const currentValue = { url: null };
51
+ const props = { content: [content] };
52
+ const result = getLinkToPublishedContent(publishedKey, props, currentValue);
53
+ expect(result).toEqual(currentValue.url);
54
+ });
55
+
56
+ it('should not return url from the currentValue if not set', () => {
57
+ const currentValue = {};
58
+ const props = { content: [content] };
59
+ const result = getLinkToPublishedContent(publishedKey, props, currentValue);
60
+ expect(result).toEqual(content.url);
61
+ });
41
62
  });
@@ -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 />`;
@@ -1,20 +1,20 @@
1
- import buildNewQuery from '../../../../../../src/components/SearchFilter/helpers/build-new-query';
2
-
1
+ import buildNewUrl from '../../../../../../src/components/SearchFilter/helpers/build-new-url';
2
+ // url, currentUrl, queryParams, hashBit
3
3
  const mockedProps = [
4
4
  ['', 'current-as-path', 'some=query&params=value'],
5
5
  ['urlFromProps', '', 'other=query&with=value'],
6
- ['urlFromProps', 'not=used', 'another=query&withthis=value', 'sort=asc&sortby=name']
6
+ ['urlFromProps', 'not=used', 'another=query&withthis=value'],
7
+ ['urlFromProps', 'not=used', 'another=query&withthis=value', 'this-is-content']
7
8
  ];
8
9
 
9
- describe('buildNewQuery helper function', () => {
10
- const simpleExample = buildNewQuery(...mockedProps[0]);
11
- const withPropsUrl = buildNewQuery(...mockedProps[1]);
12
- const withSort = buildNewQuery(...mockedProps[2]);
10
+ describe('buildNewUrl helper function', () => {
11
+ const simpleExample = buildNewUrl(...mockedProps[0]);
12
+ const withPropsUrl = buildNewUrl(...mockedProps[1]);
13
+ const withHash = buildNewUrl(...mockedProps[3]);
13
14
 
14
15
  it('should always return a string', () => {
15
16
  expect(typeof simpleExample).toBe('string');
16
17
  expect(typeof withPropsUrl).toBe('string');
17
- expect(typeof withSort).toBe('string');
18
18
  });
19
19
 
20
20
  it('should return new url using asPath and queryParams passed', () => {
@@ -25,7 +25,7 @@ describe('buildNewQuery helper function', () => {
25
25
  expect(withPropsUrl).toEqual('urlFromProps?other=query&with=value');
26
26
  });
27
27
 
28
- it('should return new url with sort if passed', () => {
29
- expect(withSort).toEqual('urlFromProps?another=query&withthis=value&sort=asc&sortby=name');
28
+ it('should return new url with hash if passed', () => {
29
+ expect(withHash).toEqual('urlFromProps?another=query&withthis=value#this-is-content');
30
30
  });
31
31
  });