@blaze-cms/react-page-builder 0.133.0-core-styles.3 → 0.133.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.
- package/CHANGELOG.md +57 -10
- package/lib/components/Banner/AdSlotRender.js +3 -12
- package/lib/components/Banner/AdSlotRender.js.map +1 -1
- package/lib/components/Banner/Banner.js +7 -4
- package/lib/components/Banner/Banner.js.map +1 -1
- package/lib/components/Banner/BannerRender.js +1 -5
- package/lib/components/Banner/BannerRender.js.map +1 -1
- package/lib/components/Button.js +3 -1
- package/lib/components/Button.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js +2 -3
- package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib/components/DataSummary/helpers/get-link-to-published-content.js +0 -2
- package/lib/components/DataSummary/helpers/get-link-to-published-content.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +58 -22
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-filters-query.js +18 -16
- package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-url-query.js +3 -2
- package/lib/components/SearchFilter/helpers/build-url-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js +33 -0
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -0
- package/lib/components/SearchFilter/helpers/get-updated-filter-by.js +38 -0
- package/lib/components/SearchFilter/helpers/get-updated-filter-by.js.map +1 -0
- package/lib/components/SearchFilter/helpers/index.js +8 -1
- package/lib/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib/helpers/build-sort-values.js +4 -1
- package/lib/helpers/build-sort-values.js.map +1 -1
- package/lib/helpers/get-generic-render-variables.js +12 -17
- package/lib/helpers/get-generic-render-variables.js.map +1 -1
- package/lib-es/components/Banner/AdSlotRender.js +3 -12
- package/lib-es/components/Banner/AdSlotRender.js.map +1 -1
- package/lib-es/components/Banner/Banner.js +7 -4
- package/lib-es/components/Banner/Banner.js.map +1 -1
- package/lib-es/components/Banner/BannerRender.js +2 -6
- package/lib-es/components/Banner/BannerRender.js.map +1 -1
- package/lib-es/components/Button.js +2 -1
- package/lib-es/components/Button.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js +2 -3
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/get-link-to-published-content.js +1 -2
- package/lib-es/components/DataSummary/helpers/get-link-to-published-content.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +2 -2
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +54 -13
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js +18 -16
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-url-query.js +1 -2
- package/lib-es/components/SearchFilter/helpers/build-url-query.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js +21 -0
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/get-updated-filter-by.js +19 -0
- package/lib-es/components/SearchFilter/helpers/get-updated-filter-by.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/index.js +3 -2
- package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib-es/helpers/build-sort-values.js +1 -1
- package/lib-es/helpers/build-sort-values.js.map +1 -1
- package/lib-es/helpers/get-generic-render-variables.js +1 -2
- package/lib-es/helpers/get-generic-render-variables.js.map +1 -1
- package/package.json +10 -10
- package/src/components/Banner/AdSlotRender.js +5 -9
- package/src/components/Banner/Banner.js +11 -9
- package/src/components/Banner/BannerRender.js +0 -4
- package/src/components/Button.js +6 -1
- package/src/components/DataSummary/helpers/build-loop-props-content.js +2 -3
- package/src/components/DataSummary/helpers/get-link-to-published-content.js +1 -4
- package/src/components/SearchFilter/SearchFilter/SearchFilter.js +5 -2
- package/src/components/SearchFilter/SearchFilterContainer.js +42 -14
- package/src/components/SearchFilter/helpers/build-filters-query.js +23 -20
- package/src/components/SearchFilter/helpers/build-url-query.js +1 -3
- package/src/components/SearchFilter/helpers/get-initial-filter-values.js +24 -0
- package/src/components/SearchFilter/helpers/get-updated-filter-by.js +18 -0
- package/src/components/SearchFilter/helpers/index.js +5 -3
- package/src/helpers/build-sort-values.js +1 -1
- package/src/helpers/get-generic-render-variables.js +1 -2
- package/tests/unit/src/components/Banner/AdSlotRender.test.js +11 -6
- package/tests/unit/src/components/Banner/__snapshots__/AdSlotRender.test.js.snap +25 -45
- package/tests/unit/src/components/Banner/__snapshots__/BannerRender.test.js.snap +3 -8
- package/tests/unit/src/components/DataSummary/helpers/build-loop-props-content.test.js +0 -41
- package/tests/unit/src/components/DataSummary/helpers/get-link-to-published-content.test.js +0 -21
- package/tests/unit/src/components/SearchFilter/helpers/build-query.test.js +6 -0
- package/tests/unit/src/components/SearchFilter/helpers/get-updated-filter-by.test.js +28 -0
- package/tests/unit/src/helpers/build-sort-values.test.js +20 -0
- package/tests/unit/src/helpers/get-generic-render-variables.test.js +25 -0
- package/tests/unit/src/components/PlaceholderIcon/__snapshots__/index.test.js.snap +0 -72
- package/tests/unit/src/components/PlaceholderIcon/index.test.js +0 -20
- /package/tests/unit/src/components/SearchFilter/helpers/{build-new-query.test.js → build-new-url.test.js} +0 -0
|
@@ -34,7 +34,6 @@ const BannerRender = ({
|
|
|
34
34
|
actionKey,
|
|
35
35
|
renderCounter,
|
|
36
36
|
userPropsData,
|
|
37
|
-
modifiers,
|
|
38
37
|
...otherProps
|
|
39
38
|
}) => {
|
|
40
39
|
const { id } = otherProps;
|
|
@@ -91,7 +90,6 @@ const BannerRender = ({
|
|
|
91
90
|
sizeId={sizeId}
|
|
92
91
|
parsedAdunit={parsedAdunit}
|
|
93
92
|
parsedSizes={parsedSizes}
|
|
94
|
-
modifiers={modifiers}
|
|
95
93
|
targetingArguments={targetingArguments}
|
|
96
94
|
/>
|
|
97
95
|
);
|
|
@@ -110,7 +108,6 @@ BannerRender.propTypes = {
|
|
|
110
108
|
targetings: PropTypes.string,
|
|
111
109
|
sizes: PropTypes.string,
|
|
112
110
|
renderCounter: PropTypes.number,
|
|
113
|
-
modifiers: PropTypes.string,
|
|
114
111
|
userPropsData: PropTypes.object
|
|
115
112
|
};
|
|
116
113
|
|
|
@@ -123,7 +120,6 @@ BannerRender.defaultProps = {
|
|
|
123
120
|
targetings: '',
|
|
124
121
|
sizes: '',
|
|
125
122
|
renderCounter: null,
|
|
126
|
-
modifiers: '',
|
|
127
123
|
userPropsData: {}
|
|
128
124
|
};
|
|
129
125
|
|
package/src/components/Button.js
CHANGED
|
@@ -60,7 +60,12 @@ const Button = props => {
|
|
|
60
60
|
const logout = () => {
|
|
61
61
|
handleLogout(client);
|
|
62
62
|
if (hasChildren(children)) return setShowChildren(true);
|
|
63
|
-
|
|
63
|
+
|
|
64
|
+
if (!urlToUse) return router.reload();
|
|
65
|
+
|
|
66
|
+
return urlToUse.startsWith('/')
|
|
67
|
+
? router.push('/Resolver', urlToUse)
|
|
68
|
+
: (window.location.href = urlToUse);
|
|
64
69
|
};
|
|
65
70
|
|
|
66
71
|
const handleClick = () => {
|
|
@@ -45,12 +45,11 @@ const buildLoopPropsContent = (loopProps = [], propsToDisplay = [], limit = 0, d
|
|
|
45
45
|
|
|
46
46
|
return propertiesToDisplay.map(key => {
|
|
47
47
|
const loopValue = loopValues[key];
|
|
48
|
-
const
|
|
49
|
-
const propValue = loopValueItem ? getLoopValue(loopValueItem) : regularValues[key];
|
|
48
|
+
const propValue = loopValue ? getLoopValue(loopValue[i]) : regularValues[key];
|
|
50
49
|
if (!propValue) return null;
|
|
51
50
|
|
|
52
51
|
const processedValue = processDataSummaryValue(propValue, options);
|
|
53
|
-
const linkToPublishedContent = getLinkToPublishedContent(key, data
|
|
52
|
+
const linkToPublishedContent = getLinkToPublishedContent(key, data);
|
|
54
53
|
return [upperFirst(label), processedValue, linkToPublishedContent, modifier];
|
|
55
54
|
});
|
|
56
55
|
})
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
const getLinkToPublishedContent = (key = '', props = {}
|
|
1
|
+
const getLinkToPublishedContent = (key = '', props = {}) => {
|
|
2
2
|
const [baseKey] = key.split('.');
|
|
3
3
|
if (!props[baseKey]) return '';
|
|
4
|
-
|
|
5
|
-
if (currentValue && typeof currentValue.url !== 'undefined') return currentValue.url;
|
|
6
|
-
|
|
7
4
|
const content = Array.isArray(props[baseKey]) ? props[baseKey][0] : props[baseKey];
|
|
8
5
|
return content && content.url ? content.url : '';
|
|
9
6
|
};
|
|
@@ -3,7 +3,8 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import debounce from 'lodash.debounce';
|
|
5
5
|
import FiltersList from './FiltersList';
|
|
6
|
-
import { isDeviceDesktop,
|
|
6
|
+
import { isDeviceDesktop, getResponsiveFilterClassnames, buildUrlQuery } from '../helpers';
|
|
7
|
+
|
|
7
8
|
import CloseMobileForm from './CloseMobileForm';
|
|
8
9
|
import ResetDesktopForm from './ResetDesktopForm';
|
|
9
10
|
import MobileFormToolbar from './MobileFormToolbar';
|
|
@@ -31,7 +32,9 @@ const SearchFilter = ({
|
|
|
31
32
|
const [moreFiltersDesktopCollapsed, setMoreFiltersDesktopCollapsed] = useState(true);
|
|
32
33
|
|
|
33
34
|
const doSubmit = newValues => {
|
|
34
|
-
const newQuery =
|
|
35
|
+
const newQuery = filterValues
|
|
36
|
+
? buildUrlQuery(newValues, filters, listComponentName, query)
|
|
37
|
+
: '';
|
|
35
38
|
handleSearch(newQuery);
|
|
36
39
|
setMoreFiltersDesktopCollapsed(true);
|
|
37
40
|
setMoreFiltersMobileCollapsed(true);
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import React, { useState, useRef, useReducer,
|
|
1
|
+
import React, { useState, useEffect, useRef, useReducer, useContext } from 'react';
|
|
2
|
+
import { MainContext } from '@blaze-cms/nextjs-components';
|
|
2
3
|
import { useRouter } from 'next/router';
|
|
3
4
|
import { useQuery } from '@apollo/client';
|
|
4
5
|
import PropTypes from 'prop-types';
|
|
5
6
|
import { parseUrl } from 'query-string';
|
|
6
7
|
import SearchFilter from './SearchFilter';
|
|
7
8
|
import { withTitle } from '../../HOC';
|
|
8
|
-
import { getSearchPublishedContent } from '../../application/query';
|
|
9
|
+
import { getSearchPublishedContent, generateSingleItemQuery } from '../../application/query';
|
|
9
10
|
import {
|
|
10
11
|
buildNewUrl,
|
|
11
12
|
buildRawQueryStringified,
|
|
12
13
|
getFilterValues,
|
|
13
14
|
buildFiltersQuery,
|
|
14
|
-
getFilterRangesAndCheckboxesValues
|
|
15
|
+
getFilterRangesAndCheckboxesValues,
|
|
16
|
+
getUpdatedFilterBy
|
|
15
17
|
} from './helpers';
|
|
16
|
-
import { getEntityData } from '../../helpers';
|
|
18
|
+
import { getEntityData, getInheritedFilters, getQueryProps } from '../../helpers';
|
|
17
19
|
import { RAW_RESULTS } from './constants';
|
|
18
20
|
import { SCROLL_OFFSET } from '../../constants';
|
|
19
21
|
import searchFilterReducer from './searchFilterReducer';
|
|
22
|
+
import { useGetEntitySchemasAsObj } from '../../hooks';
|
|
20
23
|
|
|
21
24
|
const getFiltersUrlQuery = (query, listName) => {
|
|
22
25
|
if (!listName) return query;
|
|
@@ -46,18 +49,20 @@ const SearchFilterContainer = ({
|
|
|
46
49
|
filterBy,
|
|
47
50
|
filterByProperty,
|
|
48
51
|
shouldAddFilters,
|
|
49
|
-
listComponentName
|
|
52
|
+
listComponentName,
|
|
53
|
+
parent
|
|
50
54
|
}) => {
|
|
55
|
+
const { isPreview } = useContext(MainContext);
|
|
51
56
|
const router = useRouter();
|
|
52
57
|
const { asPath } = router;
|
|
53
58
|
const searchFilterRef = useRef(null);
|
|
54
59
|
const [key, setKey] = useState(`filter-${name}`);
|
|
55
60
|
const [displaySearchFilter, setDisplaySearchFilter] = useState(false);
|
|
56
61
|
const [urlPath, setUrlPath] = useState(asPath); // used as asPath can take too long to update
|
|
62
|
+
const [filterValues, dispatch] = useReducer(searchFilterReducer, null);
|
|
57
63
|
const { url: currentUrl, query } = parseUrl(urlPath);
|
|
58
64
|
const updatedQuery = getFiltersUrlQuery(query, listComponentName);
|
|
59
|
-
|
|
60
|
-
const [filterValues, dispatch] = useReducer(searchFilterReducer, null);
|
|
65
|
+
const { itemId: parentId, itemEntity: parentEntity } = parent;
|
|
61
66
|
|
|
62
67
|
useEffect(
|
|
63
68
|
() => {
|
|
@@ -65,6 +70,27 @@ const SearchFilterContainer = ({
|
|
|
65
70
|
},
|
|
66
71
|
[asPath]
|
|
67
72
|
);
|
|
73
|
+
const { data: mainSchemas = {}, loading: schemasLoading } = useGetEntitySchemasAsObj([
|
|
74
|
+
parentEntity,
|
|
75
|
+
entity
|
|
76
|
+
]);
|
|
77
|
+
const { [parentEntity]: parentSchema = {}, [entity]: filterEntitySchema = {} } = mainSchemas;
|
|
78
|
+
const { actions = {} } = parentSchema || {};
|
|
79
|
+
const getAction = isPreview ? actions.get : actions.getPublished;
|
|
80
|
+
const inheritedFilters = getInheritedFilters(filterBy, filterByProperty);
|
|
81
|
+
const queryProps = getQueryProps(inheritedFilters, parentSchema, filterEntitySchema);
|
|
82
|
+
const { data: { entityData: parentData } = {}, loading: parentQueryLoading } = useQuery(
|
|
83
|
+
generateSingleItemQuery(getAction, queryProps),
|
|
84
|
+
{
|
|
85
|
+
variables: { id: parentId },
|
|
86
|
+
skip: schemasLoading || !inheritedFilters.length
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
const { updatedFilterBy, updatedFilterByProperty } = getUpdatedFilterBy(
|
|
90
|
+
filterBy,
|
|
91
|
+
filterByProperty,
|
|
92
|
+
parentData
|
|
93
|
+
);
|
|
68
94
|
|
|
69
95
|
const action = getSearchPublishedContent(RAW_RESULTS);
|
|
70
96
|
const [checkboxSelectValues, rangeValues] = getFilterRangesAndCheckboxesValues(filters);
|
|
@@ -73,9 +99,9 @@ const SearchFilterContainer = ({
|
|
|
73
99
|
|
|
74
100
|
const filtersQuery = buildFiltersQuery({
|
|
75
101
|
shouldAddFilters,
|
|
76
|
-
query: filterValues
|
|
77
|
-
filterBy,
|
|
78
|
-
filterByProperty,
|
|
102
|
+
query: filterValues,
|
|
103
|
+
filterBy: updatedFilterBy,
|
|
104
|
+
filterByProperty: updatedFilterByProperty,
|
|
79
105
|
rangeValues,
|
|
80
106
|
queryKeys: Object.keys(updatedQuery)
|
|
81
107
|
});
|
|
@@ -89,7 +115,7 @@ const SearchFilterContainer = ({
|
|
|
89
115
|
|
|
90
116
|
const { data, error, loading } = useQuery(action, {
|
|
91
117
|
variables: { rawQueryStringified, limit: 0 }, // we only want aggs so limit=0 for no search results
|
|
92
|
-
skip: !rawQueryStringified
|
|
118
|
+
skip: !rawQueryStringified || parentQueryLoading
|
|
93
119
|
});
|
|
94
120
|
|
|
95
121
|
if (error) return error.message;
|
|
@@ -98,7 +124,7 @@ const SearchFilterContainer = ({
|
|
|
98
124
|
const { searchPublishedContent: { rawResults: { aggregations: filterData } = {} } = {} } =
|
|
99
125
|
data || {};
|
|
100
126
|
|
|
101
|
-
if (!filterValues && !loading && (filterData || !rawQueryStringified)) {
|
|
127
|
+
if (!filterValues && !loading && !parentQueryLoading && (filterData || !rawQueryStringified)) {
|
|
102
128
|
const newValues = getFilterValues(filterData, filters, updatedQuery);
|
|
103
129
|
dispatch({ newValues, shouldSearch: false, type: 'update' });
|
|
104
130
|
return null;
|
|
@@ -171,7 +197,8 @@ SearchFilterContainer.propTypes = {
|
|
|
171
197
|
filterBy: PropTypes.array,
|
|
172
198
|
filterByProperty: PropTypes.array,
|
|
173
199
|
shouldAddFilters: PropTypes.bool,
|
|
174
|
-
listComponentName: PropTypes.string
|
|
200
|
+
listComponentName: PropTypes.string,
|
|
201
|
+
parent: PropTypes.object
|
|
175
202
|
};
|
|
176
203
|
|
|
177
204
|
SearchFilterContainer.defaultProps = {
|
|
@@ -184,7 +211,8 @@ SearchFilterContainer.defaultProps = {
|
|
|
184
211
|
filterBy: [],
|
|
185
212
|
filterByProperty: [],
|
|
186
213
|
shouldAddFilters: false,
|
|
187
|
-
listComponentName: ''
|
|
214
|
+
listComponentName: '',
|
|
215
|
+
parent: {}
|
|
188
216
|
};
|
|
189
217
|
|
|
190
218
|
export default withTitle(SearchFilterContainer);
|
|
@@ -29,38 +29,41 @@ const builFilterObject = ({ queryKey, value, filters, isRange, isInQuery }) => {
|
|
|
29
29
|
filters.push({ match: { [key]: filterValue } });
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
+
|
|
32
33
|
const buildFiltersQuery = ({
|
|
33
34
|
shouldAddFilters,
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
filterBy,
|
|
36
37
|
filterByProperty,
|
|
37
38
|
rangeValues,
|
|
38
|
-
queryKeys
|
|
39
|
+
queryKeys,
|
|
40
|
+
query
|
|
39
41
|
}) => {
|
|
40
42
|
if (!shouldAddFilters) return [];
|
|
41
43
|
const mustFilters = [];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
if (query) {
|
|
45
|
+
Object.keys(query).forEach(queryKey => {
|
|
46
|
+
if (QUERY_KEYS_TO_IGNORE.includes(queryKey)) return;
|
|
47
|
+
if (!queryKey || !query[queryKey]) return;
|
|
48
|
+
const queryValue = query[queryKey];
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const isRange = rangeValues.includes(queryKey);
|
|
51
|
+
const isInQuery = queryKeys.includes(queryKey);
|
|
52
|
+
builFilterObject({ queryKey, value: queryValue, filters: mustFilters, isRange, isInQuery });
|
|
53
|
+
});
|
|
54
|
+
}
|
|
51
55
|
|
|
52
56
|
if (filterByProperty && filterByProperty.length) {
|
|
53
|
-
filterByProperty
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
mustFilters.push({ match: { [filterByKeyword]: filteryByValue } });
|
|
62
|
-
});
|
|
57
|
+
filterByProperty.forEach(filterByPropOption => {
|
|
58
|
+
const [filterByPropKey] = filterByPropOption.split('/');
|
|
59
|
+
filterBy.forEach(filterByOption => {
|
|
60
|
+
if (filterByOption.indexOf(filterByPropKey) === -1) return;
|
|
61
|
+
const [, filteryByValue] = filterByOption.split('/');
|
|
62
|
+
const filterByKeyword = `${filterByPropKey}.keyword`;
|
|
63
|
+
if (!filteryByValue) return;
|
|
64
|
+
mustFilters.push({ match: { [filterByKeyword]: filteryByValue } });
|
|
63
65
|
});
|
|
66
|
+
});
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
return mustFilters;
|
|
@@ -2,9 +2,7 @@ import { SEARCH_TERM, TEXT_SEARCH } from '../constants';
|
|
|
2
2
|
import parseFilterValue from './parse-filter-value';
|
|
3
3
|
import { buildQueryKey } from '../../../helpers';
|
|
4
4
|
|
|
5
|
-
const buildUrlQuery = (filterValues, filters, listComponentName = '', query = {}) => {
|
|
6
|
-
if (!filterValues) return '';
|
|
7
|
-
|
|
5
|
+
const buildUrlQuery = (filterValues = {}, filters = [], listComponentName = '', query = {}) => {
|
|
8
6
|
const newQuery = [];
|
|
9
7
|
const queryKeys = [];
|
|
10
8
|
const searchValue = filterValues[SEARCH_TERM];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SEARCH_TERM, TEXT_SEARCH } from '../constants';
|
|
2
|
+
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
3
|
+
import { buildQueryKey } from '../../../helpers';
|
|
4
|
+
|
|
5
|
+
const getInitialFilterValues = (filterData, filters, query, listComponentName) => {
|
|
6
|
+
const filterValues = {};
|
|
7
|
+
const searchQueryKey = buildQueryKey(SEARCH_TERM, listComponentName);
|
|
8
|
+
filterValues[SEARCH_TERM] = query[searchQueryKey] || '';
|
|
9
|
+
|
|
10
|
+
filters.forEach(filterProps => {
|
|
11
|
+
const {
|
|
12
|
+
propsToDisplay: [key],
|
|
13
|
+
type
|
|
14
|
+
} = filterProps;
|
|
15
|
+
if (type === TEXT_SEARCH) return;
|
|
16
|
+
const data = filterData && filterData[key] ? filterData[key] : {};
|
|
17
|
+
const queryKey = buildQueryKey(key, listComponentName);
|
|
18
|
+
filterValues[key] = getFilterValueFromQuery(queryKey, filterProps, data, query);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return filterValues;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default getInitialFilterValues;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const getUpdatedFilterBy = (filterBy, filterByProperty, parentData) => {
|
|
2
|
+
if (!parentData || (filterBy && filterBy.length))
|
|
3
|
+
return { updatedFilterBy: filterBy, updatedFilterByProperty: filterByProperty };
|
|
4
|
+
|
|
5
|
+
const updatedFilterBy = [];
|
|
6
|
+
filterByProperty.forEach(property => {
|
|
7
|
+
const [key] = property.split('/');
|
|
8
|
+
const filterData = parentData[key];
|
|
9
|
+
|
|
10
|
+
if (!filterData) return;
|
|
11
|
+
if (Array.isArray(filterData)) filterData.forEach(dat => updatedFilterBy.push(`${key}/${dat}`));
|
|
12
|
+
else updatedFilterBy.push(`${key}/${filterData}`);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return { updatedFilterBy, updatedFilterByProperty: filterByProperty };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default getUpdatedFilterBy;
|
|
@@ -12,12 +12,12 @@ import getSelectOptions from './get-select-options';
|
|
|
12
12
|
import isDeviceDesktop from './is-device-desktop';
|
|
13
13
|
import getFilterValues from './get-filter-values';
|
|
14
14
|
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
15
|
-
import buildUrlQuery from './build-url-query';
|
|
16
15
|
import buildFiltersQuery from './build-filters-query';
|
|
17
16
|
import getFilterRangesAndCheckboxesValues from './get-filter-ranges-and-checkboxes-values';
|
|
17
|
+
import getUpdatedFilterBy from './get-updated-filter-by';
|
|
18
|
+
import buildUrlQuery from './build-url-query';
|
|
18
19
|
|
|
19
20
|
export {
|
|
20
|
-
buildUrlQuery,
|
|
21
21
|
buildNewUrl,
|
|
22
22
|
buildRawQueryStringified,
|
|
23
23
|
decodeValue,
|
|
@@ -34,5 +34,7 @@ export {
|
|
|
34
34
|
getFilterValues,
|
|
35
35
|
getFilterValueFromQuery,
|
|
36
36
|
buildFiltersQuery,
|
|
37
|
-
getFilterRangesAndCheckboxesValues
|
|
37
|
+
getFilterRangesAndCheckboxesValues,
|
|
38
|
+
getUpdatedFilterBy,
|
|
39
|
+
buildUrlQuery
|
|
38
40
|
};
|
|
@@ -23,7 +23,7 @@ const buildSortValues = (sortFilters, relations, stringProps, useSortObject) =>
|
|
|
23
23
|
const sortFieldName = getSortbyFieldName(relations, propsToDisplay, stringProps);
|
|
24
24
|
return sortFieldName ? `${sortFieldName}:${sort.toLowerCase()}` : null;
|
|
25
25
|
})
|
|
26
|
-
.filter(
|
|
26
|
+
.filter((item, index, arr) => (!item ? false : arr.indexOf(item) === index))
|
|
27
27
|
.join(',');
|
|
28
28
|
|
|
29
29
|
return { sort: sortValues };
|
|
@@ -3,10 +3,9 @@ import buildSortValues from './build-sort-values';
|
|
|
3
3
|
|
|
4
4
|
const getCorrectSort = (relations, filterProps, stringProps, useSortObject) => {
|
|
5
5
|
const { sort, sortby, sortProperties = [] } = filterProps;
|
|
6
|
-
const [sortProperty = []] = sortProperties || [];
|
|
7
6
|
|
|
8
7
|
return buildSortValues(
|
|
9
|
-
[{ sort, propsToDisplay: sortby }, ...
|
|
8
|
+
[{ sort, propsToDisplay: sortby }, ...sortProperties],
|
|
10
9
|
relations,
|
|
11
10
|
stringProps,
|
|
12
11
|
useSortObject
|
|
@@ -50,17 +50,17 @@ describe('Banner render component', () => {
|
|
|
50
50
|
<AdSlotRender {...defaultProps} shouldShowBanner={false} />
|
|
51
51
|
);
|
|
52
52
|
|
|
53
|
-
expect(container.childNodes[0].nodeName).toEqual('
|
|
54
|
-
expect(
|
|
53
|
+
expect(container.childNodes[0].nodeName).toEqual('STYLE');
|
|
54
|
+
expect(container.childNodes[1]).toHaveClass('ad-slot ad-slot-loading banner-sizeId');
|
|
55
55
|
expect(() => getByTestId(slotTestId)).toThrow();
|
|
56
56
|
expect(asFragment()).toMatchSnapshot();
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
describe('AdSlot loading', () => {
|
|
60
60
|
it('should render AdSlot', () => {
|
|
61
|
-
const { asFragment, getByTestId } = render(<AdSlotRender {...defaultProps} />);
|
|
61
|
+
const { asFragment, container, getByTestId } = render(<AdSlotRender {...defaultProps} />);
|
|
62
62
|
expect(getByTestId('adslot-test')).toBeDefined();
|
|
63
|
-
expect(
|
|
63
|
+
expect(container.childNodes[1]).toHaveClass('ad-slot ad-slot-loading banner-sizeId');
|
|
64
64
|
expect(asFragment()).toMatchSnapshot();
|
|
65
65
|
});
|
|
66
66
|
|
|
@@ -69,11 +69,16 @@ describe('Banner render component', () => {
|
|
|
69
69
|
const adSlot = getByTestId(slotTestId);
|
|
70
70
|
|
|
71
71
|
fireEvent.mouseOver(adSlot);
|
|
72
|
-
await waitFor(() =>
|
|
72
|
+
await waitFor(() =>
|
|
73
|
+
expect(container.childNodes[0]).toHaveClass('ad-slot ad-slot-loaded banner-sizeId')
|
|
74
|
+
);
|
|
75
|
+
expect(container.childNodes[0]).toHaveStyle('min-height: 250px');
|
|
73
76
|
expect(asFragment()).toMatchSnapshot();
|
|
74
77
|
|
|
75
78
|
fireEvent.mouseLeave(adSlot);
|
|
76
|
-
await waitFor(() =>
|
|
79
|
+
await waitFor(() =>
|
|
80
|
+
expect(container.childNodes[0]).toHaveClass('ad-slot ad-slot-empty banner-sizeId')
|
|
81
|
+
);
|
|
77
82
|
expect(asFragment()).toMatchSnapshot();
|
|
78
83
|
});
|
|
79
84
|
});
|
|
@@ -3,18 +3,13 @@
|
|
|
3
3
|
exports[`Banner render component AdSlot loading should change class and remove responsive styles after loaded events 1`] = `
|
|
4
4
|
<DocumentFragment>
|
|
5
5
|
<div
|
|
6
|
-
class="banner
|
|
6
|
+
class="ad-slot ad-slot-loaded banner-sizeId"
|
|
7
|
+
style="min-height: 250px;"
|
|
7
8
|
>
|
|
8
9
|
<div
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
>
|
|
13
|
-
<div
|
|
14
|
-
data-testid="adslot-test"
|
|
15
|
-
role="button"
|
|
16
|
-
/>
|
|
17
|
-
</div>
|
|
10
|
+
data-testid="adslot-test"
|
|
11
|
+
role="button"
|
|
12
|
+
/>
|
|
18
13
|
</div>
|
|
19
14
|
</DocumentFragment>
|
|
20
15
|
`;
|
|
@@ -22,59 +17,44 @@ exports[`Banner render component AdSlot loading should change class and remove r
|
|
|
22
17
|
exports[`Banner render component AdSlot loading should change class and remove responsive styles after loaded events 2`] = `
|
|
23
18
|
<DocumentFragment>
|
|
24
19
|
<div
|
|
25
|
-
class="banner
|
|
20
|
+
class="ad-slot ad-slot-empty banner-sizeId"
|
|
21
|
+
style=""
|
|
26
22
|
>
|
|
27
23
|
<div
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
>
|
|
32
|
-
<div
|
|
33
|
-
data-testid="adslot-test"
|
|
34
|
-
role="button"
|
|
35
|
-
/>
|
|
36
|
-
</div>
|
|
24
|
+
data-testid="adslot-test"
|
|
25
|
+
role="button"
|
|
26
|
+
/>
|
|
37
27
|
</div>
|
|
38
28
|
</DocumentFragment>
|
|
39
29
|
`;
|
|
40
30
|
|
|
41
31
|
exports[`Banner render component AdSlot loading should render AdSlot 1`] = `
|
|
42
32
|
<DocumentFragment>
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
>
|
|
46
|
-
<style>
|
|
47
|
-
@media(min-width:320px){.banner-sizeId{min-height:100px;}
|
|
33
|
+
<style>
|
|
34
|
+
@media(min-width:320px){.banner-sizeId{min-height:100px;}
|
|
48
35
|
@media(min-width:728px){.banner-sizeId{min-height:100px;}
|
|
49
36
|
@media(min-width:970px){.banner-sizeId{min-height:250px;}
|
|
50
|
-
|
|
37
|
+
</style>
|
|
38
|
+
<div
|
|
39
|
+
class="ad-slot ad-slot-loading banner-sizeId"
|
|
40
|
+
>
|
|
51
41
|
<div
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<div
|
|
56
|
-
data-testid="adslot-test"
|
|
57
|
-
role="button"
|
|
58
|
-
/>
|
|
59
|
-
</div>
|
|
42
|
+
data-testid="adslot-test"
|
|
43
|
+
role="button"
|
|
44
|
+
/>
|
|
60
45
|
</div>
|
|
61
46
|
</DocumentFragment>
|
|
62
47
|
`;
|
|
63
48
|
|
|
64
49
|
exports[`Banner render component should not render AdSlot if shouldShowBanner=false but should render styles and wrapper 1`] = `
|
|
65
50
|
<DocumentFragment>
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
>
|
|
69
|
-
<style>
|
|
70
|
-
@media(min-width:320px){.banner-sizeId{min-height:100px;}
|
|
51
|
+
<style>
|
|
52
|
+
@media(min-width:320px){.banner-sizeId{min-height:100px;}
|
|
71
53
|
@media(min-width:728px){.banner-sizeId{min-height:100px;}
|
|
72
54
|
@media(min-width:970px){.banner-sizeId{min-height:250px;}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/>
|
|
78
|
-
</div>
|
|
55
|
+
</style>
|
|
56
|
+
<div
|
|
57
|
+
class="ad-slot ad-slot-loading banner-sizeId"
|
|
58
|
+
/>
|
|
79
59
|
</DocumentFragment>
|
|
80
60
|
`;
|
|
@@ -2,14 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`Banner render component should render 1`] = `
|
|
4
4
|
<DocumentFragment>
|
|
5
|
+
<style />
|
|
5
6
|
<div
|
|
6
|
-
class="banner
|
|
7
|
-
|
|
8
|
-
<style />
|
|
9
|
-
<div
|
|
10
|
-
class="ad-slot ad-slot-loading banner-sizeId"
|
|
11
|
-
data-testid="ad-slot"
|
|
12
|
-
/>
|
|
13
|
-
</div>
|
|
7
|
+
class="ad-slot ad-slot-loading banner-sizeId"
|
|
8
|
+
/>
|
|
14
9
|
</DocumentFragment>
|
|
15
10
|
`;
|
|
@@ -90,45 +90,4 @@ describe('buildLoopPropsContent helper function', () => {
|
|
|
90
90
|
});
|
|
91
91
|
expect.hasAssertions();
|
|
92
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
|
-
});
|
|
134
93
|
});
|
|
@@ -38,25 +38,4 @@ 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
|
-
});
|
|
62
41
|
});
|
|
@@ -11,6 +11,7 @@ const mockedProps = [
|
|
|
11
11
|
];
|
|
12
12
|
|
|
13
13
|
describe('buildUrlQuery helper function', () => {
|
|
14
|
+
const noProps = buildUrlQuery();
|
|
14
15
|
const simpleExample = buildUrlQuery(...mockedProps[0]);
|
|
15
16
|
const withTextSearch = buildUrlQuery(...mockedProps[1]);
|
|
16
17
|
const withSearchAndRange = buildUrlQuery(...mockedProps[2]);
|
|
@@ -20,6 +21,11 @@ describe('buildUrlQuery helper function', () => {
|
|
|
20
21
|
anotherQuery: '123'
|
|
21
22
|
});
|
|
22
23
|
|
|
24
|
+
it('should not break if no params are passed', () => {
|
|
25
|
+
expect(typeof noProps).toBe('string');
|
|
26
|
+
expect(noProps).toEqual('');
|
|
27
|
+
});
|
|
28
|
+
|
|
23
29
|
it('should always return a string', () => {
|
|
24
30
|
expect(typeof simpleExample).toBe('string');
|
|
25
31
|
});
|