@blaze-cms/react-page-builder 0.124.1-alpha.1 → 0.124.1-alpha.5

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 (36) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/lib/components/Banner/helpers.js +1 -1
  3. package/lib/components/Banner/helpers.js.map +1 -1
  4. package/lib/components/Button.js +4 -0
  5. package/lib/components/Button.js.map +1 -1
  6. package/lib/components/Card/helpers/use-dynamic-size-key.js +1 -5
  7. package/lib/components/Card/helpers/use-dynamic-size-key.js.map +1 -1
  8. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +2 -1
  9. package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  10. package/lib/components/SearchFilter/SearchFilterContainer.js +22 -5
  11. package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  12. package/lib/components/SearchFilter/components/Range.js +2 -3
  13. package/lib/components/SearchFilter/components/Range.js.map +1 -1
  14. package/lib/components/SearchFilter/helpers/build-filters-query.js +24 -6
  15. package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
  16. package/lib-es/components/Banner/helpers.js +1 -1
  17. package/lib-es/components/Banner/helpers.js.map +1 -1
  18. package/lib-es/components/Button.js +4 -1
  19. package/lib-es/components/Button.js.map +1 -1
  20. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +2 -1
  21. package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
  22. package/lib-es/components/SearchFilter/SearchFilterContainer.js +17 -4
  23. package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
  24. package/lib-es/components/SearchFilter/components/Range.js +2 -3
  25. package/lib-es/components/SearchFilter/components/Range.js.map +1 -1
  26. package/lib-es/components/SearchFilter/helpers/build-filters-query.js +25 -6
  27. package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/components/Banner/helpers.js +1 -5
  30. package/src/components/Button.js +8 -1
  31. package/src/components/SearchFilter/SearchFilter/SearchFilter.js +2 -1
  32. package/src/components/SearchFilter/SearchFilterContainer.js +21 -4
  33. package/src/components/SearchFilter/components/Range.js +11 -14
  34. package/src/components/SearchFilter/helpers/build-filters-query.js +7 -6
  35. package/tests/unit/src/components/Banner/helpers.test.js +1 -1
  36. package/tests/unit/src/components/Button.test.js +4 -0
@@ -1,4 +1,4 @@
1
- import React, { useState, Fragment } from 'react';
1
+ import React, { useState, Fragment, useEffect } from 'react';
2
2
  import { useCookies } from 'react-cookie';
3
3
  import { useRouter } from 'next/router';
4
4
  import classnames from 'classnames';
@@ -39,6 +39,13 @@ const Button = props => {
39
39
  const { blaze_auth: blazeCookie } = cookies;
40
40
  const [showChildren, setShowChildren] = useState(false);
41
41
 
42
+ useEffect(
43
+ () => {
44
+ setShowChildren(false);
45
+ },
46
+ [router.asPath]
47
+ );
48
+
42
49
  const checkIfButtonShouldRender = () => {
43
50
  if (isLogoutButton) return !!blazeCookie;
44
51
  if (!text && !icon) return false;
@@ -69,8 +69,9 @@ const SearchFilter = ({
69
69
  const formId = `filter-${name}-form`;
70
70
 
71
71
  const handleReset = () => {
72
- const newValues = getInitialFilterValues(data, filters, {});
72
+ const newValues = getInitialFilterValues(null, filters, {});
73
73
  setAppliedFilters({ newValues, type: 'reset' });
74
+ doSubmit(newValues);
74
75
  };
75
76
 
76
77
  const updateFilterValues = (newValues, shouldSubmit) => {
@@ -1,4 +1,4 @@
1
- import React, { useState, useRef, useReducer } from 'react';
1
+ 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';
@@ -25,7 +25,7 @@ const reducer = (state, action) => {
25
25
  case 'resetSearch':
26
26
  return { ...state, shouldSearch: false };
27
27
  case 'reset':
28
- return { ...newValues, shouldSearch };
28
+ return { ...newValues, shouldSearch: false };
29
29
  default:
30
30
  throw new Error();
31
31
  }
@@ -48,15 +48,24 @@ const SearchFilterContainer = ({
48
48
  const searchFilterRef = useRef(null);
49
49
  const [key, setKey] = useState(`filter-${name}`);
50
50
  const [displaySearchFilter, setDisplaySearchFilter] = useState(false);
51
+ const [urlPath, setUrlPath] = useState(asPath); // used as asPath can take too long to update
51
52
  const {
52
53
  url: currentUrl,
53
54
  query: { sort, sortby },
54
55
  query
55
- } = parseUrl(asPath);
56
+ } = parseUrl(urlPath);
56
57
  const [filterValues, dispatch] = useReducer(
57
58
  reducer,
58
59
  getInitialFilterValues(null, filters, query)
59
60
  );
61
+
62
+ useEffect(
63
+ () => {
64
+ if (asPath) setUrlPath(asPath);
65
+ },
66
+ [asPath]
67
+ );
68
+
60
69
  const hasUrl = !!url;
61
70
 
62
71
  const sortValues = sort && sortby ? stringify({ sort, sortby }) : '';
@@ -77,7 +86,13 @@ const SearchFilterContainer = ({
77
86
  const { docType } = getEntityData(entity);
78
87
 
79
88
  const filtersQuery = shouldAddFilters
80
- ? buildFiltersQuery(filterValues || query, filterBy, filterByProperty, rangeValues)
89
+ ? buildFiltersQuery({
90
+ query: filterValues,
91
+ filterBy,
92
+ filterByProperty,
93
+ rangeValues,
94
+ queryKeys: Object.keys(query)
95
+ })
81
96
  : [];
82
97
 
83
98
  const rawQueryStringified = buildRawQueryStringified(
@@ -108,12 +123,14 @@ const SearchFilterContainer = ({
108
123
 
109
124
  if (!newQuery) {
110
125
  scrollToFirstList();
126
+ setUrlPath(baseQuery);
111
127
  return router.push('/Resolver', baseQuery, { shallow: !hasUrl, scroll: false }).then(() => {
112
128
  setKey(`filter-${name}:${Date.now()}`); // remove after range component update
113
129
  });
114
130
  }
115
131
  const newUrl = buildNewQuery(url, currentUrl, newQuery, sortValues);
116
132
  scrollToFirstList();
133
+ setUrlPath(newUrl);
117
134
  return router.push('/Resolver', newUrl, { shallow: !hasUrl, scroll: false });
118
135
  };
119
136
 
@@ -21,7 +21,7 @@ const Range = ({
21
21
  shouldSearch
22
22
  }) => {
23
23
  const router = useRouter();
24
- const debounceAmount = shouldSearch ? 1200 : 100;
24
+ const debounceAmount = shouldSearch ? 1200 : 400;
25
25
  const { query } = parseUrl(decodeValue(router.asPath));
26
26
  const hasMultipleOptions = propsToDisplay.length > 1;
27
27
  const initialRangeOption = getIntersectedProp(query, propsToDisplay) || propsToDisplay[0];
@@ -40,7 +40,6 @@ const Range = ({
40
40
  const options = getSelectOptions(getEntitySchema, propsToDisplay);
41
41
  // get range from aggregations so it updates
42
42
  const { min, max } = calculateMinMax(dataAggregations[rangeOption], rangeInterval);
43
- const shouldShowRange = rangeOption && min !== max;
44
43
  const minValue = rangeValue.minValue < min ? min : rangeValue.minValue;
45
44
  const maxValue = rangeValue.maxValue > max ? max : rangeValue.maxValue;
46
45
  const valueToUse = { ...rangeValue, min, max, minValue, maxValue };
@@ -72,18 +71,16 @@ const Range = ({
72
71
  />
73
72
  </>
74
73
  )}
75
- {shouldShowRange && (
76
- <RangeFilter
77
- key={`${rangeOption}-${minValue}-${maxValue}`}
78
- name={rangeOption}
79
- label={hasMultipleOptions ? '' : label}
80
- value={valueToUse}
81
- id={rangeOption}
82
- onChange={({ value }) => {
83
- handleChange(rangeOption, value);
84
- }}
85
- />
86
- )}
74
+ <RangeFilter
75
+ key={`${rangeOption}-${minValue}-${maxValue}`}
76
+ name={rangeOption}
77
+ label={hasMultipleOptions ? '' : label}
78
+ value={valueToUse}
79
+ id={rangeOption}
80
+ onChange={({ value }) => {
81
+ handleChange(rangeOption, value);
82
+ }}
83
+ />
87
84
  </>
88
85
  );
89
86
  };
@@ -1,14 +1,14 @@
1
1
  const QUERY_KEYS_TO_IGNORE = ['dataNotSet', 'shouldSearch', 'search_term'];
2
2
 
3
- const builFilterObject = (queryKey, value, filters, isRange) => {
3
+ const builFilterObject = ({ queryKey, value, filters, isRange, isInQuery }) => {
4
4
  if (isRange) {
5
5
  // don't add to query if value matches range values
6
- if (value.min !== value.minValue && value.max !== value.maxValue) {
6
+ if (isInQuery || (value.min !== value.minValue && value.max !== value.maxValue)) {
7
7
  filters.push({
8
8
  range: {
9
9
  [queryKey]: {
10
- gte: Number(value.min),
11
- lte: Number(value.max)
10
+ gte: Number(value.minValue),
11
+ lte: Number(value.maxValue)
12
12
  }
13
13
  }
14
14
  });
@@ -29,7 +29,7 @@ const builFilterObject = (queryKey, value, filters, isRange) => {
29
29
  filters.push({ match: { [key]: filterValue } });
30
30
  });
31
31
  };
32
- const buildFiltersQuery = (query, filterBy, filterByProperty, rangeValues) => {
32
+ const buildFiltersQuery = ({ query, filterBy, filterByProperty, rangeValues, queryKeys }) => {
33
33
  const mustFilters = [];
34
34
  Object.keys(query).forEach(queryKey => {
35
35
  if (QUERY_KEYS_TO_IGNORE.includes(queryKey)) return;
@@ -37,7 +37,8 @@ const buildFiltersQuery = (query, filterBy, filterByProperty, rangeValues) => {
37
37
  const queryValue = query[queryKey];
38
38
 
39
39
  const isRange = rangeValues.includes(queryKey);
40
- builFilterObject(queryKey, queryValue, mustFilters, isRange);
40
+ const isInQuery = queryKeys.includes(queryKey);
41
+ builFilterObject({ queryKey, value: queryValue, filters: mustFilters, isRange, isInQuery });
41
42
  });
42
43
 
43
44
  if (filterByProperty && filterByProperty.length) {
@@ -166,7 +166,7 @@ describe('buildContextualTargeting helper', () => {
166
166
  { getPages: [{ tags: [{ name: 'tag1' }, { name: 'tag2' }] }] },
167
167
  [{ label: 'tagKey', propertiesToDisplay: ['tags.name'] }]
168
168
  );
169
- expect(contextualTargeting).toEqual({ tagKey: 'tag1, tag2' });
169
+ expect(contextualTargeting).toEqual({ tagKey: ['tag1', 'tag2'] });
170
170
  });
171
171
  });
172
172
 
@@ -8,6 +8,10 @@ jest.mock('@apollo/client', () => ({
8
8
  useApolloClient: jest.fn(() => ({ resetStore: () => null }))
9
9
  }));
10
10
 
11
+ jest.mock('next/router', () => ({
12
+ useRouter: jest.fn(() => ({ asPath: '' }))
13
+ }));
14
+
11
15
  const componentProps = {
12
16
  type: 'icon',
13
17
  text: 'test',