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