@blaze-cms/react-page-builder 0.130.0 → 0.131.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.
- package/CHANGELOG.md +28 -0
- package/lib/components/Card/CardsRender.js +13 -6
- package/lib/components/Card/CardsRender.js.map +1 -1
- package/lib/components/Card/helpers/get-updated-items-to-display.js +55 -0
- package/lib/components/Card/helpers/get-updated-items-to-display.js.map +1 -0
- package/lib/components/Card/helpers/index.js +7 -0
- package/lib/components/Card/helpers/index.js.map +1 -1
- package/lib/components/Code/Code.js +7 -3
- package/lib/components/Code/Code.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js +3 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js +3 -2
- package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
- package/lib/components/List/ListFactory.js +16 -11
- package/lib/components/List/ListFactory.js.map +1 -1
- package/lib/components/List/helpers/get-list-query.js +43 -0
- package/lib/components/List/helpers/get-list-query.js.map +1 -0
- package/lib/components/List/helpers/get-list-specific-search-filter.js +21 -0
- package/lib/components/List/helpers/get-list-specific-search-filter.js.map +1 -0
- package/lib/components/List/helpers/index.js +14 -0
- package/lib/components/List/helpers/index.js.map +1 -1
- package/lib/components/List/helpers/strip-query-key.js +14 -0
- package/lib/components/List/helpers/strip-query-key.js.map +1 -0
- package/lib/components/SearchContent/SearchContent.js +8 -6
- package/lib/components/SearchContent/SearchContent.js.map +1 -1
- package/lib/components/SearchContent/SearchContentItems.js +1 -1
- package/lib/components/SearchContent/SearchContentItems.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +17 -11
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +63 -85
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-filters-query.js +3 -1
- package/lib/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-new-url.js +17 -0
- package/lib/components/SearchFilter/helpers/build-new-url.js.map +1 -0
- package/lib/components/SearchFilter/helpers/build-url-query.js +48 -0
- package/lib/components/SearchFilter/helpers/build-url-query.js.map +1 -0
- package/lib/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +32 -0
- package/lib/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js.map +1 -0
- package/lib/components/SearchFilter/helpers/get-filter-values.js +31 -0
- package/lib/components/SearchFilter/helpers/get-filter-values.js.map +1 -0
- package/lib/components/SearchFilter/helpers/index.js +18 -11
- package/lib/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib/components/SearchFilter/index.js.map +1 -1
- package/lib/components/SearchFilter/searchFilterReducer.js +45 -0
- package/lib/components/SearchFilter/searchFilterReducer.js.map +1 -0
- package/lib/components/SearchFilterSort/SearchFilterSort.js +31 -11
- package/lib/components/SearchFilterSort/SearchFilterSort.js.map +1 -1
- package/lib/components/SearchFilterSort/helpers/handle-sort-update.js +19 -5
- package/lib/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
- package/lib/components/SearchFilterSort/helpers/update-sort.js +9 -5
- package/lib/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
- package/lib/helpers/build-inherited-filters.js +2 -0
- package/lib/helpers/build-inherited-filters.js.map +1 -1
- package/lib/helpers/build-props-query.js +5 -2
- package/lib/helpers/build-props-query.js.map +1 -1
- package/lib/helpers/build-query-key.js +16 -0
- package/lib/helpers/build-query-key.js.map +1 -0
- package/lib/helpers/build-set-filters.js +5 -1
- package/lib/helpers/build-set-filters.js.map +1 -1
- package/lib/helpers/get-query-filters.js +6 -8
- package/lib/helpers/get-query-filters.js.map +1 -1
- package/lib/helpers/get-query-props.js +13 -2
- package/lib/helpers/get-query-props.js.map +1 -1
- package/lib/helpers/get-wrapped-value-with-link.js +2 -3
- package/lib/helpers/get-wrapped-value-with-link.js.map +1 -1
- package/lib/helpers/index.js +14 -0
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/parse-props-to-display.js +13 -8
- package/lib/helpers/parse-props-to-display.js.map +1 -1
- package/lib/helpers/process-data-summary-value.js +56 -0
- package/lib/helpers/process-data-summary-value.js.map +1 -0
- package/lib-es/components/Card/CardsRender.js +14 -7
- package/lib-es/components/Card/CardsRender.js.map +1 -1
- package/lib-es/components/Card/helpers/get-updated-items-to-display.js +32 -0
- package/lib-es/components/Card/helpers/get-updated-items-to-display.js.map +1 -0
- package/lib-es/components/Card/helpers/index.js +1 -0
- package/lib-es/components/Card/helpers/index.js.map +1 -1
- package/lib-es/components/Code/Code.js +8 -4
- package/lib-es/components/Code/Code.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js +3 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js +4 -3
- package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
- package/lib-es/components/List/ListFactory.js +16 -12
- package/lib-es/components/List/ListFactory.js.map +1 -1
- package/lib-es/components/List/helpers/get-list-query.js +24 -0
- package/lib-es/components/List/helpers/get-list-query.js.map +1 -0
- package/lib-es/components/List/helpers/get-list-specific-search-filter.js +12 -0
- package/lib-es/components/List/helpers/get-list-specific-search-filter.js.map +1 -0
- package/lib-es/components/List/helpers/index.js +2 -0
- package/lib-es/components/List/helpers/index.js.map +1 -1
- package/lib-es/components/List/helpers/strip-query-key.js +6 -0
- package/lib-es/components/List/helpers/strip-query-key.js.map +1 -0
- package/lib-es/components/SearchContent/SearchContent.js +8 -6
- package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContentItems.js +1 -1
- package/lib-es/components/SearchContent/SearchContentItems.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +18 -11
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +47 -72
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js +2 -0
- package/lib-es/components/SearchFilter/helpers/build-filters-query.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-new-url.js +8 -0
- package/lib-es/components/SearchFilter/helpers/build-new-url.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/build-url-query.js +30 -0
- package/lib-es/components/SearchFilter/helpers/build-url-query.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +18 -0
- package/lib-es/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/get-filter-values.js +19 -0
- package/lib-es/components/SearchFilter/helpers/get-filter-values.js.map +1 -0
- package/lib-es/components/SearchFilter/helpers/index.js +5 -4
- package/lib-es/components/SearchFilter/helpers/index.js.map +1 -1
- package/lib-es/components/SearchFilter/index.js +2 -2
- package/lib-es/components/SearchFilter/index.js.map +1 -1
- package/lib-es/components/SearchFilter/searchFilterReducer.js +28 -0
- package/lib-es/components/SearchFilter/searchFilterReducer.js.map +1 -0
- package/lib-es/components/SearchFilterSort/SearchFilterSort.js +26 -10
- package/lib-es/components/SearchFilterSort/SearchFilterSort.js.map +1 -1
- package/lib-es/components/SearchFilterSort/helpers/handle-sort-update.js +21 -4
- package/lib-es/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
- package/lib-es/components/SearchFilterSort/helpers/update-sort.js +8 -4
- package/lib-es/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
- package/lib-es/helpers/build-inherited-filters.js +2 -0
- package/lib-es/helpers/build-inherited-filters.js.map +1 -1
- package/lib-es/helpers/build-props-query.js +4 -2
- package/lib-es/helpers/build-props-query.js.map +1 -1
- package/lib-es/helpers/build-query-key.js +7 -0
- package/lib-es/helpers/build-query-key.js.map +1 -0
- package/lib-es/helpers/build-set-filters.js +5 -1
- package/lib-es/helpers/build-set-filters.js.map +1 -1
- package/lib-es/helpers/get-query-filters.js +6 -8
- package/lib-es/helpers/get-query-filters.js.map +1 -1
- package/lib-es/helpers/get-query-props.js +10 -2
- package/lib-es/helpers/get-query-props.js.map +1 -1
- package/lib-es/helpers/get-wrapped-value-with-link.js +2 -2
- package/lib-es/helpers/get-wrapped-value-with-link.js.map +1 -1
- package/lib-es/helpers/index.js +2 -0
- package/lib-es/helpers/index.js.map +1 -1
- package/lib-es/helpers/parse-props-to-display.js +12 -9
- package/lib-es/helpers/parse-props-to-display.js.map +1 -1
- package/lib-es/helpers/process-data-summary-value.js +36 -0
- package/lib-es/helpers/process-data-summary-value.js.map +1 -0
- package/package.json +10 -10
- package/src/components/Card/CardsRender.js +27 -7
- package/src/components/Card/helpers/get-updated-items-to-display.js +32 -0
- package/src/components/Card/helpers/index.js +1 -0
- package/src/components/Code/Code.js +7 -3
- package/src/components/DataSummary/helpers/build-loop-props-content.js +4 -1
- package/src/components/DataSummary/helpers/build-props-to-display-with-content.js +6 -3
- package/src/components/List/ListFactory.js +25 -15
- package/src/components/List/helpers/get-list-query.js +28 -0
- package/src/components/List/helpers/get-list-specific-search-filter.js +10 -0
- package/src/components/List/helpers/index.js +2 -0
- package/src/components/List/helpers/strip-query-key.js +6 -0
- package/src/components/SearchContent/SearchContent.js +8 -6
- package/src/components/SearchFilter/SearchFilter/SearchFilter.js +21 -12
- package/src/components/SearchFilter/SearchFilterContainer.js +57 -69
- package/src/components/SearchFilter/helpers/build-filters-query.js +9 -1
- package/src/components/SearchFilter/helpers/build-new-url.js +8 -0
- package/src/components/SearchFilter/helpers/build-url-query.js +31 -0
- package/src/components/SearchFilter/helpers/get-filter-ranges-and-checkboxes-values.js +17 -0
- package/src/components/SearchFilter/helpers/get-filter-values.js +21 -0
- package/src/components/SearchFilter/helpers/index.js +9 -7
- package/src/components/SearchFilter/index.js +2 -2
- package/src/components/SearchFilter/searchFilterReducer.js +15 -0
- package/src/components/SearchFilterSort/SearchFilterSort.js +18 -8
- package/src/components/SearchFilterSort/helpers/handle-sort-update.js +14 -5
- package/src/components/SearchFilterSort/helpers/update-sort.js +7 -3
- package/src/helpers/build-inherited-filters.js +3 -1
- package/src/helpers/build-props-query.js +4 -2
- package/src/helpers/build-query-key.js +7 -0
- package/src/helpers/build-set-filters.js +2 -1
- package/src/helpers/get-query-filters.js +4 -4
- package/src/helpers/get-query-props.js +12 -4
- package/src/helpers/get-wrapped-value-with-link.js +6 -3
- package/src/helpers/index.js +2 -0
- package/src/helpers/parse-props-to-display.js +25 -21
- package/src/helpers/process-data-summary-value.js +22 -0
- package/tests/helpers/mocks.js +3 -5
- package/tests/unit/src/components/Card/helpers/get-updated-items-to-display.test.js +72 -0
- package/tests/unit/src/components/Code/Code.test.js +5 -0
- package/tests/unit/src/components/Code/__snapshots__/Code.test.js.snap +8 -0
- package/tests/unit/src/components/DataSummary/helpers/build-loop-props-content.test.js +9 -0
- package/tests/unit/src/components/SearchFilter/__snapshots__/SearchFilterContainer.test.js.snap +1 -7
- package/tests/unit/src/components/SearchFilter/helpers/build-new-query.test.js +10 -10
- package/tests/unit/src/components/SearchFilter/helpers/build-query.test.js +24 -7
- package/tests/unit/src/components/SearchFilter/helpers/get-initial-filter-values.test.js +10 -10
- package/tests/unit/src/components/SearchFilterSort/SearchFilterSort.test.js +4 -1
- package/tests/unit/src/components/SearchFilterSort/helpers/handle-sort-update.test.js +26 -19
- package/tests/unit/src/components/SearchFilterSort/helpers/update-sort.test.js +10 -1
- package/tests/unit/src/helpers/__snapshots__/get-wrapped-value-with-link.test.js.snap +18 -0
- package/tests/unit/src/helpers/build-props-query.test.js +25 -0
- package/tests/unit/src/helpers/get-wrapped-value-with-link.test.js +2 -2
- package/tests/unit/src/helpers/parse-props-to-display.test.js +4 -0
- package/tests/unit/src/helpers/prcoess-data-summary-value.test.js +52 -0
- package/lib/components/SearchFilter/helpers/build-new-query.js +0 -15
- package/lib/components/SearchFilter/helpers/build-new-query.js.map +0 -1
- package/lib/components/SearchFilter/helpers/build-query.js +0 -37
- package/lib/components/SearchFilter/helpers/build-query.js.map +0 -1
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js +0 -43
- package/lib/components/SearchFilter/helpers/get-initial-filter-values.js.map +0 -1
- package/lib-es/components/SearchFilter/helpers/build-new-query.js +0 -6
- package/lib-es/components/SearchFilter/helpers/build-new-query.js.map +0 -1
- package/lib-es/components/SearchFilter/helpers/build-query.js +0 -23
- package/lib-es/components/SearchFilter/helpers/build-query.js.map +0 -1
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js +0 -26
- package/lib-es/components/SearchFilter/helpers/get-initial-filter-values.js.map +0 -1
- package/src/components/SearchFilter/helpers/build-new-query.js +0 -6
- package/src/components/SearchFilter/helpers/build-query.js +0 -26
- package/src/components/SearchFilter/helpers/get-initial-filter-values.js +0 -30
|
@@ -5,8 +5,8 @@ import debounce from 'lodash.debounce';
|
|
|
5
5
|
import FiltersList from './FiltersList';
|
|
6
6
|
import {
|
|
7
7
|
isDeviceDesktop,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
buildUrlQuery,
|
|
9
|
+
getFilterValues,
|
|
10
10
|
getResponsiveFilterClassnames
|
|
11
11
|
} from '../helpers';
|
|
12
12
|
import CloseMobileForm from './CloseMobileForm';
|
|
@@ -16,6 +16,7 @@ import { SEARCH, REFINE, MORE_FILTERS_CLASSES } from '../constants';
|
|
|
16
16
|
|
|
17
17
|
const SearchFilter = ({
|
|
18
18
|
searchFilterRef,
|
|
19
|
+
listComponentName,
|
|
19
20
|
data,
|
|
20
21
|
filters,
|
|
21
22
|
hasUrl,
|
|
@@ -28,13 +29,14 @@ const SearchFilter = ({
|
|
|
28
29
|
groupAfterDesktop,
|
|
29
30
|
groupAfterMobile,
|
|
30
31
|
filterValues,
|
|
31
|
-
setAppliedFilters
|
|
32
|
+
setAppliedFilters,
|
|
33
|
+
query
|
|
32
34
|
}) => {
|
|
33
35
|
const [moreFiltersMobileCollapsed, setMoreFiltersMobileCollapsed] = useState(true);
|
|
34
36
|
const [moreFiltersDesktopCollapsed, setMoreFiltersDesktopCollapsed] = useState(true);
|
|
35
37
|
|
|
36
|
-
const doSubmit =
|
|
37
|
-
const newQuery =
|
|
38
|
+
const doSubmit = newValues => {
|
|
39
|
+
const newQuery = buildUrlQuery(newValues, filters, listComponentName, query);
|
|
38
40
|
handleSearch(newQuery);
|
|
39
41
|
setMoreFiltersDesktopCollapsed(true);
|
|
40
42
|
setMoreFiltersMobileCollapsed(true);
|
|
@@ -69,7 +71,7 @@ const SearchFilter = ({
|
|
|
69
71
|
const formId = `filter-${name}-form`;
|
|
70
72
|
|
|
71
73
|
const handleReset = () => {
|
|
72
|
-
const newValues =
|
|
74
|
+
const newValues = getFilterValues(null, filters, {});
|
|
73
75
|
setAppliedFilters({ newValues, type: 'reset' });
|
|
74
76
|
doSubmit(newValues);
|
|
75
77
|
};
|
|
@@ -79,7 +81,7 @@ const SearchFilter = ({
|
|
|
79
81
|
};
|
|
80
82
|
|
|
81
83
|
const shouldGroup = !!(groupAfterDesktop || groupAfterMobile);
|
|
82
|
-
|
|
84
|
+
|
|
83
85
|
return (
|
|
84
86
|
<>
|
|
85
87
|
<form
|
|
@@ -89,7 +91,7 @@ const SearchFilter = ({
|
|
|
89
91
|
id={formId}
|
|
90
92
|
onSubmit={e => {
|
|
91
93
|
e.preventDefault();
|
|
92
|
-
doSubmit();
|
|
94
|
+
doSubmit(filterValues);
|
|
93
95
|
}}>
|
|
94
96
|
{displaySearchFilter && (
|
|
95
97
|
<CloseMobileForm handleClose={() => setDisplaySearchFilter(false)} />
|
|
@@ -101,7 +103,7 @@ const SearchFilter = ({
|
|
|
101
103
|
<div className="filter__wrapper filter__wrapper--search-refine">
|
|
102
104
|
{!shouldGroup && (
|
|
103
105
|
<FiltersList
|
|
104
|
-
shouldSearch={
|
|
106
|
+
shouldSearch={!hasUrl}
|
|
105
107
|
data={data}
|
|
106
108
|
filters={filters}
|
|
107
109
|
hasUrl={hasUrl}
|
|
@@ -114,7 +116,7 @@ const SearchFilter = ({
|
|
|
114
116
|
{shouldGroup && (
|
|
115
117
|
<>
|
|
116
118
|
<FiltersList
|
|
117
|
-
shouldSearch={
|
|
119
|
+
shouldSearch={!hasUrl}
|
|
118
120
|
data={data}
|
|
119
121
|
filters={filters.slice(0, groupAfterMobile)}
|
|
120
122
|
hasUrl={hasUrl}
|
|
@@ -136,7 +138,7 @@ const SearchFilter = ({
|
|
|
136
138
|
<div className={moreFiltersMobileWrapperClass}>
|
|
137
139
|
<div className={MORE_FILTERS_CLASSES.MOBILE_CONTENT}>
|
|
138
140
|
<FiltersList
|
|
139
|
-
shouldSearch={
|
|
141
|
+
shouldSearch={!hasUrl && isDeviceDesktop()}
|
|
140
142
|
data={data}
|
|
141
143
|
filters={filters.slice(
|
|
142
144
|
groupAfterMobile,
|
|
@@ -233,7 +235,14 @@ SearchFilter.propTypes = {
|
|
|
233
235
|
groupAfterDesktop: PropTypes.number.isRequired,
|
|
234
236
|
groupAfterMobile: PropTypes.number.isRequired,
|
|
235
237
|
filterValues: PropTypes.object.isRequired,
|
|
236
|
-
setAppliedFilters: PropTypes.func.isRequired
|
|
238
|
+
setAppliedFilters: PropTypes.func.isRequired,
|
|
239
|
+
listComponentName: PropTypes.string,
|
|
240
|
+
query: PropTypes.object
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
SearchFilter.defaultProps = {
|
|
244
|
+
listComponentName: '',
|
|
245
|
+
query: {}
|
|
237
246
|
};
|
|
238
247
|
|
|
239
248
|
export default SearchFilter;
|
|
@@ -2,33 +2,37 @@ 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
|
|
5
|
+
import { parseUrl } 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
|
-
|
|
10
|
+
buildNewUrl,
|
|
11
11
|
buildRawQueryStringified,
|
|
12
|
-
|
|
13
|
-
buildFiltersQuery
|
|
12
|
+
getFilterValues,
|
|
13
|
+
buildFiltersQuery,
|
|
14
|
+
getFilterRangesAndCheckboxesValues
|
|
14
15
|
} from './helpers';
|
|
15
16
|
import { getEntityData } from '../../helpers';
|
|
16
|
-
import { RAW_RESULTS
|
|
17
|
+
import { RAW_RESULTS } from './constants';
|
|
17
18
|
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
|
+
});
|
|
18
34
|
|
|
19
|
-
|
|
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
|
-
}
|
|
35
|
+
return updatedQuery;
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
const SearchFilterContainer = ({
|
|
@@ -41,7 +45,8 @@ const SearchFilterContainer = ({
|
|
|
41
45
|
groupAfterDesktop,
|
|
42
46
|
filterBy,
|
|
43
47
|
filterByProperty,
|
|
44
|
-
shouldAddFilters
|
|
48
|
+
shouldAddFilters,
|
|
49
|
+
listComponentName
|
|
45
50
|
}) => {
|
|
46
51
|
const router = useRouter();
|
|
47
52
|
const { asPath } = router;
|
|
@@ -49,15 +54,10 @@ const SearchFilterContainer = ({
|
|
|
49
54
|
const [key, setKey] = useState(`filter-${name}`);
|
|
50
55
|
const [displaySearchFilter, setDisplaySearchFilter] = useState(false);
|
|
51
56
|
const [urlPath, setUrlPath] = useState(asPath); // used as asPath can take too long to update
|
|
52
|
-
const {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} = parseUrl(urlPath);
|
|
57
|
-
const [filterValues, dispatch] = useReducer(
|
|
58
|
-
reducer,
|
|
59
|
-
getInitialFilterValues(null, filters, query)
|
|
60
|
-
);
|
|
57
|
+
const { url: currentUrl, query } = parseUrl(urlPath);
|
|
58
|
+
const updatedQuery = getFiltersUrlQuery(query, listComponentName);
|
|
59
|
+
|
|
60
|
+
const [filterValues, dispatch] = useReducer(searchFilterReducer, null);
|
|
61
61
|
|
|
62
62
|
useEffect(
|
|
63
63
|
() => {
|
|
@@ -66,34 +66,19 @@ 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
|
-
|
|
74
69
|
const action = getSearchPublishedContent(RAW_RESULTS);
|
|
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
|
-
});
|
|
70
|
+
const [checkboxSelectValues, rangeValues] = getFilterRangesAndCheckboxesValues(filters);
|
|
85
71
|
|
|
86
72
|
const { docType } = getEntityData(entity);
|
|
87
73
|
|
|
88
|
-
const filtersQuery =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
: [];
|
|
74
|
+
const filtersQuery = buildFiltersQuery({
|
|
75
|
+
shouldAddFilters,
|
|
76
|
+
query: filterValues || {},
|
|
77
|
+
filterBy,
|
|
78
|
+
filterByProperty,
|
|
79
|
+
rangeValues,
|
|
80
|
+
queryKeys: Object.keys(updatedQuery)
|
|
81
|
+
});
|
|
97
82
|
|
|
98
83
|
const rawQueryStringified = buildRawQueryStringified(
|
|
99
84
|
checkboxSelectValues,
|
|
@@ -102,7 +87,7 @@ const SearchFilterContainer = ({
|
|
|
102
87
|
filtersQuery
|
|
103
88
|
);
|
|
104
89
|
|
|
105
|
-
const { data, error } = useQuery(action, {
|
|
90
|
+
const { data, error, loading } = useQuery(action, {
|
|
106
91
|
variables: { rawQueryStringified, limit: 0 }, // we only want aggs so limit=0 for no search results
|
|
107
92
|
skip: !rawQueryStringified
|
|
108
93
|
});
|
|
@@ -113,30 +98,29 @@ const SearchFilterContainer = ({
|
|
|
113
98
|
const { searchPublishedContent: { rawResults: { aggregations: filterData } = {} } = {} } =
|
|
114
99
|
data || {};
|
|
115
100
|
|
|
116
|
-
if (filterValues
|
|
117
|
-
const
|
|
118
|
-
dispatch({ newValues
|
|
101
|
+
if (!filterValues && !loading && filterData) {
|
|
102
|
+
const newValues = getFilterValues(filterData, filters, updatedQuery);
|
|
103
|
+
dispatch({ newValues, shouldSearch: false, type: 'update' });
|
|
119
104
|
}
|
|
120
105
|
|
|
121
106
|
const handleSearch = newQuery => {
|
|
122
107
|
setDisplaySearchFilter(false);
|
|
123
|
-
|
|
108
|
+
const hashBit = asPath.split('#')[1] || '';
|
|
109
|
+
const parsedHashBit = hashBit ? `#${hashBit}` : '';
|
|
110
|
+
scrollToFirstList();
|
|
124
111
|
if (!newQuery) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return router.push('/Resolver', baseQuery, { shallow: !hasUrl, scroll: false }).then(() => {
|
|
112
|
+
const baseQuery = `${currentUrl}${parsedHashBit}`;
|
|
113
|
+
return router.push('/Resolver', baseQuery, { shallow: !url, scroll: false }).then(() => {
|
|
128
114
|
setKey(`filter-${name}:${Date.now()}`); // remove after range component update
|
|
129
115
|
});
|
|
130
116
|
}
|
|
131
|
-
const newUrl =
|
|
132
|
-
|
|
133
|
-
setUrlPath(newUrl);
|
|
134
|
-
return router.push('/Resolver', newUrl, { shallow: !hasUrl, scroll: false });
|
|
117
|
+
const newUrl = buildNewUrl(url, currentUrl, newQuery, hashBit);
|
|
118
|
+
return router.push('/Resolver', newUrl, { shallow: !url, scroll: false });
|
|
135
119
|
};
|
|
136
120
|
|
|
137
121
|
const scrollToFirstList = () => {
|
|
138
122
|
const [list] = document.getElementsByClassName('list-top');
|
|
139
|
-
const shouldScrollToFirstList = !
|
|
123
|
+
const shouldScrollToFirstList = !url && list;
|
|
140
124
|
|
|
141
125
|
if (shouldScrollToFirstList) {
|
|
142
126
|
window.scrollTo({
|
|
@@ -147,16 +131,18 @@ const SearchFilterContainer = ({
|
|
|
147
131
|
window.scrollTo(0, 0);
|
|
148
132
|
}
|
|
149
133
|
};
|
|
150
|
-
if (!filterValues) return
|
|
134
|
+
if (!filterValues || filterValues.dataNotSet) return null;
|
|
151
135
|
|
|
152
136
|
return (
|
|
153
137
|
<SearchFilter
|
|
154
138
|
key={key}
|
|
155
139
|
setAppliedFilters={dispatch}
|
|
140
|
+
query={updatedQuery}
|
|
141
|
+
listComponentName={listComponentName}
|
|
156
142
|
searchFilterRef={searchFilterRef}
|
|
157
143
|
data={filterData}
|
|
158
144
|
filters={filters}
|
|
159
|
-
hasUrl={
|
|
145
|
+
hasUrl={!!url}
|
|
160
146
|
entity={entity}
|
|
161
147
|
handleSearch={handleSearch}
|
|
162
148
|
filterValues={filterValues}
|
|
@@ -180,7 +166,8 @@ SearchFilterContainer.propTypes = {
|
|
|
180
166
|
groupAfterDesktop: PropTypes.number,
|
|
181
167
|
filterBy: PropTypes.array,
|
|
182
168
|
filterByProperty: PropTypes.array,
|
|
183
|
-
shouldAddFilters: PropTypes.bool
|
|
169
|
+
shouldAddFilters: PropTypes.bool,
|
|
170
|
+
listComponentName: PropTypes.string
|
|
184
171
|
};
|
|
185
172
|
|
|
186
173
|
SearchFilterContainer.defaultProps = {
|
|
@@ -192,7 +179,8 @@ SearchFilterContainer.defaultProps = {
|
|
|
192
179
|
groupAfterDesktop: 0,
|
|
193
180
|
filterBy: [],
|
|
194
181
|
filterByProperty: [],
|
|
195
|
-
shouldAddFilters: false
|
|
182
|
+
shouldAddFilters: false,
|
|
183
|
+
listComponentName: ''
|
|
196
184
|
};
|
|
197
185
|
|
|
198
186
|
export default withTitle(SearchFilterContainer);
|
|
@@ -29,7 +29,15 @@ const builFilterObject = ({ queryKey, value, filters, isRange, isInQuery }) => {
|
|
|
29
29
|
filters.push({ match: { [key]: filterValue } });
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
-
const buildFiltersQuery = ({
|
|
32
|
+
const buildFiltersQuery = ({
|
|
33
|
+
shouldAddFilters,
|
|
34
|
+
query,
|
|
35
|
+
filterBy,
|
|
36
|
+
filterByProperty,
|
|
37
|
+
rangeValues,
|
|
38
|
+
queryKeys
|
|
39
|
+
}) => {
|
|
40
|
+
if (!shouldAddFilters) return [];
|
|
33
41
|
const mustFilters = [];
|
|
34
42
|
Object.keys(query).forEach(queryKey => {
|
|
35
43
|
if (QUERY_KEYS_TO_IGNORE.includes(queryKey)) return;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const buildNewUrl = (url, currentUrl, queryParams, hashBit) => {
|
|
2
|
+
const encodedQuery = encodeURI(queryParams);
|
|
3
|
+
const baseUrl = url || currentUrl;
|
|
4
|
+
const newUrl = encodedQuery ? `${baseUrl}?${encodedQuery}` : `${baseUrl}`;
|
|
5
|
+
return hashBit ? `${newUrl}#${hashBit}` : newUrl;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export default buildNewUrl;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SEARCH_TERM, TEXT_SEARCH } from '../constants';
|
|
2
|
+
import parseFilterValue from './parse-filter-value';
|
|
3
|
+
import { buildQueryKey } from '../../../helpers';
|
|
4
|
+
|
|
5
|
+
const buildUrlQuery = (filterValues, filters, listComponentName = '', query = {}) => {
|
|
6
|
+
const newQuery = [];
|
|
7
|
+
const queryKeys = [];
|
|
8
|
+
const searchValue = filterValues[SEARCH_TERM];
|
|
9
|
+
const searchKey = buildQueryKey(SEARCH_TERM, listComponentName);
|
|
10
|
+
queryKeys.push(searchKey);
|
|
11
|
+
if (searchValue) newQuery.push(`${searchKey}=${searchValue}`);
|
|
12
|
+
|
|
13
|
+
filters.forEach(({ propsToDisplay, type }) => {
|
|
14
|
+
if (type === TEXT_SEARCH) return;
|
|
15
|
+
propsToDisplay.forEach(prop => {
|
|
16
|
+
const value = filterValues[prop];
|
|
17
|
+
const filterKey = buildQueryKey(prop, listComponentName);
|
|
18
|
+
queryKeys.push(filterKey);
|
|
19
|
+
const parsedValue = parseFilterValue(filterKey, type, value, newQuery);
|
|
20
|
+
if (parsedValue && !newQuery.includes(parsedValue)) newQuery.push(parsedValue);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
Object.keys(query).forEach(key => {
|
|
25
|
+
if (queryKeys.indexOf(key) === -1) newQuery.push(`${key}=${query[key]}`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return newQuery.join('&');
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default buildUrlQuery;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RANGE, CHECKBOX_SELECT } from '../constants';
|
|
2
|
+
|
|
3
|
+
const getFilterRangesAndCheckboxesValues = filters => {
|
|
4
|
+
const checkboxSelectValues = [];
|
|
5
|
+
const rangeValues = [];
|
|
6
|
+
|
|
7
|
+
filters.forEach(({ type, propsToDisplay }) => {
|
|
8
|
+
if (CHECKBOX_SELECT.includes(type)) {
|
|
9
|
+
checkboxSelectValues.push(propsToDisplay[0]);
|
|
10
|
+
} else if (type === RANGE) {
|
|
11
|
+
rangeValues.push(...propsToDisplay);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return [checkboxSelectValues, rangeValues];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default getFilterRangesAndCheckboxesValues;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SEARCH_TERM, TEXT_SEARCH } from '../constants';
|
|
2
|
+
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
3
|
+
|
|
4
|
+
const getFilterValues = (filterData, filters, query) => {
|
|
5
|
+
const filterValues = {};
|
|
6
|
+
filterValues[SEARCH_TERM] = query[SEARCH_TERM] || '';
|
|
7
|
+
|
|
8
|
+
filters.forEach(filterProps => {
|
|
9
|
+
const {
|
|
10
|
+
propsToDisplay: [key],
|
|
11
|
+
type
|
|
12
|
+
} = filterProps;
|
|
13
|
+
if (type === TEXT_SEARCH) return;
|
|
14
|
+
const data = filterData && filterData[key] ? filterData[key] : {};
|
|
15
|
+
filterValues[key] = getFilterValueFromQuery(key, filterProps, data, query);
|
|
16
|
+
});
|
|
17
|
+
filterValues.dataNotSet = !filterData;
|
|
18
|
+
return filterValues;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default getFilterValues;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import buildNewUrl from './build-new-url';
|
|
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,14 +10,15 @@ 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
|
|
13
|
+
import getFilterValues from './get-filter-values';
|
|
14
14
|
import getFilterValueFromQuery from './get-filter-value-from-query';
|
|
15
|
-
import
|
|
15
|
+
import buildUrlQuery from './build-url-query';
|
|
16
16
|
import buildFiltersQuery from './build-filters-query';
|
|
17
|
+
import getFilterRangesAndCheckboxesValues from './get-filter-ranges-and-checkboxes-values';
|
|
17
18
|
|
|
18
19
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
buildUrlQuery,
|
|
21
|
+
buildNewUrl,
|
|
21
22
|
buildRawQueryStringified,
|
|
22
23
|
decodeValue,
|
|
23
24
|
encodeValue,
|
|
@@ -30,7 +31,8 @@ export {
|
|
|
30
31
|
getRangeValue,
|
|
31
32
|
getSelectOptions,
|
|
32
33
|
isDeviceDesktop,
|
|
33
|
-
|
|
34
|
+
getFilterValues,
|
|
34
35
|
getFilterValueFromQuery,
|
|
35
|
-
buildFiltersQuery
|
|
36
|
+
buildFiltersQuery,
|
|
37
|
+
getFilterRangesAndCheckboxesValues
|
|
36
38
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import SearchFilter from './SearchFilterContainer';
|
|
2
2
|
|
|
3
|
-
export default
|
|
3
|
+
export default SearchFilter;
|
|
@@ -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 { ...newValues, shouldSearch: false };
|
|
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 {
|
|
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
|
|
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
|
|
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 }) =>
|
|
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
|
|
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 !==
|
|
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
|
|
24
|
+
? router.push(`/Resolver`, `${url}?${stringifiedQuery}${parsedHash}`, routerOptions)
|
|
25
|
+
: router.push(`/Resolver`, `${url}${parsedHash}`, routerOptions);
|
|
18
26
|
}
|
|
19
|
-
|
|
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,
|
|
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
|
-
|
|
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))
|
|
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}}`;
|
|
@@ -31,8 +31,9 @@ const buildSetFilters = ({
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const shouldApplyFilterValues = filterBy.length && filterByProperty.length;
|
|
34
|
-
|
|
34
|
+
if (!shouldApplyFilterValues) return { checkboxFilters, listFilterValues: {} };
|
|
35
35
|
|
|
36
|
+
const listFilterValues = getFilterValues(filterBy);
|
|
36
37
|
return { checkboxFilters, listFilterValues };
|
|
37
38
|
};
|
|
38
39
|
|