@riosst100/pwa-marketplace 1.4.7 → 1.4.8
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/package.json
CHANGED
|
@@ -30,7 +30,7 @@ const CustomFilters = props => {
|
|
|
30
30
|
// create elements and params at the same time for efficiency
|
|
31
31
|
const filterElements = useMemo(() => {
|
|
32
32
|
const elements = [];
|
|
33
|
-
customFiltersData.map((filter, index) => {
|
|
33
|
+
customFiltersData && customFiltersData.map((filter, index) => {
|
|
34
34
|
const { label, attribute_code, options } = filter || {};
|
|
35
35
|
|
|
36
36
|
if (options.length) {
|
|
@@ -43,17 +43,19 @@ const CustomFilters = props => {
|
|
|
43
43
|
// );
|
|
44
44
|
// const keyAttr = `${attribute_code}[filter]`;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (params) {
|
|
47
|
+
Object.keys(params).forEach(function(key, index) {
|
|
48
|
+
if (index > 1) {
|
|
49
|
+
delete params[key];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
51
53
|
|
|
52
54
|
if (value != "all") {
|
|
53
55
|
params[`${attribute_code}[filter]`] = `${label},${value}`;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
const finalParams = Object.keys(params).map(key => `${key}=${params[key]}`).join('&');
|
|
58
|
+
const finalParams = params ? Object.keys(params).map(key => `${key}=${params[key]}`).join('&') : '';
|
|
57
59
|
|
|
58
60
|
// console.log(params)
|
|
59
61
|
|
|
@@ -1,139 +1,13 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { FormattedMessage } from 'react-intl';
|
|
3
|
-
import { array, arrayOf, shape, string, number } from 'prop-types';
|
|
4
|
-
import { useFilterSidebar } from '@magento/peregrine/lib/talons/FilterSidebar';
|
|
5
|
-
|
|
6
|
-
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
7
|
-
import LinkButton from '@magento/venia-ui/lib/components/LinkButton';
|
|
1
|
+
import React from 'react';
|
|
8
2
|
import CustomFilters from './CustomFilters';
|
|
9
|
-
import FilterBlock from '@magento/venia-ui/lib/components/FilterModal/filterBlock';
|
|
10
|
-
import defaultClasses from './filterTop.module.css';
|
|
11
|
-
|
|
12
|
-
import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
|
|
13
|
-
|
|
14
|
-
import { Link } from 'react-router-dom';
|
|
15
|
-
import CurrentFilters from '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/FilterModal/CurrentFilters';
|
|
16
|
-
|
|
17
|
-
const SCROLL_OFFSET = 150;
|
|
18
3
|
|
|
19
|
-
/**
|
|
20
|
-
* A view that displays applicable and applied filters.
|
|
21
|
-
*
|
|
22
|
-
* @param {Object} props.filters - filters to display
|
|
23
|
-
*/
|
|
24
4
|
const FilterTop = props => {
|
|
25
|
-
const {
|
|
26
|
-
const talonProps = useFilterSidebar({ filters });
|
|
27
|
-
const {
|
|
28
|
-
filterApi,
|
|
29
|
-
filterItems,
|
|
30
|
-
filterNames,
|
|
31
|
-
filterFrontendInput,
|
|
32
|
-
filterState,
|
|
33
|
-
handleApply,
|
|
34
|
-
handleReset
|
|
35
|
-
} = talonProps;
|
|
36
|
-
|
|
37
|
-
const filterRef = useRef();
|
|
38
|
-
const classes = useStyle(defaultClasses, props.classes);
|
|
39
|
-
|
|
40
|
-
const handleApplyFilter = useCallback(
|
|
41
|
-
(...args) => {
|
|
42
|
-
const filterElement = filterRef.current;
|
|
43
|
-
if (
|
|
44
|
-
filterElement &&
|
|
45
|
-
typeof filterElement.getBoundingClientRect === 'function'
|
|
46
|
-
) {
|
|
47
|
-
const filterTop = filterElement.getBoundingClientRect().top;
|
|
48
|
-
const windowScrollY =
|
|
49
|
-
window.scrollY + filterTop - SCROLL_OFFSET;
|
|
50
|
-
window.scrollTo(0, windowScrollY);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
handleApply(...args);
|
|
54
|
-
},
|
|
55
|
-
[handleApply, filterRef]
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const filtersList = useMemo(
|
|
59
|
-
() =>
|
|
60
|
-
Array.from(filterItems, ([group, items], iteration) => {
|
|
61
|
-
const blockState = filterState.get(group);
|
|
62
|
-
const groupName = filterNames.get(group);
|
|
63
|
-
const frontendInput = filterFrontendInput.get(group);
|
|
64
|
-
return (
|
|
65
|
-
<FilterBlock
|
|
66
|
-
key={group}
|
|
67
|
-
filterApi={filterApi}
|
|
68
|
-
filterState={blockState}
|
|
69
|
-
filterFrontendInput={frontendInput}
|
|
70
|
-
group={group}
|
|
71
|
-
items={items}
|
|
72
|
-
name={groupName}
|
|
73
|
-
onApply={handleApplyFilter}
|
|
74
|
-
initialOpen={iteration < filterCountToOpen}
|
|
75
|
-
/>
|
|
76
|
-
);
|
|
77
|
-
}),
|
|
78
|
-
[
|
|
79
|
-
filterApi,
|
|
80
|
-
filterItems,
|
|
81
|
-
filterNames,
|
|
82
|
-
filterFrontendInput,
|
|
83
|
-
filterState,
|
|
84
|
-
filterCountToOpen,
|
|
85
|
-
handleApplyFilter
|
|
86
|
-
]
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const clearAll = filterState.size ? (
|
|
90
|
-
<div className={classes.action}>
|
|
91
|
-
<LinkButton
|
|
92
|
-
type="button"
|
|
93
|
-
onClick={handleReset}
|
|
94
|
-
data-cy="FilterSidebar-clearButton"
|
|
95
|
-
>
|
|
96
|
-
<FormattedMessage
|
|
97
|
-
id={'filterModal.all'}
|
|
98
|
-
defaultMessage={'All'}
|
|
99
|
-
/>
|
|
100
|
-
</LinkButton>
|
|
101
|
-
</div>
|
|
102
|
-
) : null;
|
|
103
|
-
|
|
5
|
+
const { category } = props;
|
|
104
6
|
return (
|
|
105
7
|
<CustomFilters
|
|
106
|
-
filterApi={filterApi}
|
|
107
|
-
filterNames={filterNames}
|
|
108
|
-
filterState={filterState}
|
|
109
|
-
clearAll={clearAll}
|
|
110
8
|
category={category}
|
|
111
|
-
onRemove={handleApplyFilter}
|
|
112
9
|
/>
|
|
113
10
|
);
|
|
114
11
|
};
|
|
115
12
|
|
|
116
|
-
FilterTop.defaultProps = {
|
|
117
|
-
filterCountToOpen: 3
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
FilterTop.propTypes = {
|
|
121
|
-
classes: shape({
|
|
122
|
-
action: string,
|
|
123
|
-
blocks: string,
|
|
124
|
-
body: string,
|
|
125
|
-
header: string,
|
|
126
|
-
headerTitle: string,
|
|
127
|
-
root: string,
|
|
128
|
-
root_open: string
|
|
129
|
-
}),
|
|
130
|
-
filters: arrayOf(
|
|
131
|
-
shape({
|
|
132
|
-
attribute_code: string,
|
|
133
|
-
items: array
|
|
134
|
-
})
|
|
135
|
-
),
|
|
136
|
-
filterCountToOpen: number
|
|
137
|
-
};
|
|
138
|
-
|
|
139
13
|
export default FilterTop;
|