@riosst100/pwa-marketplace 2.9.0 → 2.9.1
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 +1 -1
- package/src/components/SubCategory/subCategory.js +8 -2
- package/src/overwrites/peregrine/lib/talons/RootComponents/Category/categoryContent.gql.js +5 -0
- package/src/overwrites/peregrine/lib/talons/RootComponents/Category/useCategoryContent.js +53 -2
- package/src/overwrites/venia-ui/lib/RootComponents/Category/categoryContent.js +1 -7
package/package.json
CHANGED
|
@@ -22,14 +22,20 @@ const SubCategory = props => {
|
|
|
22
22
|
|
|
23
23
|
normalizedData && normalizedData.length && normalizedData.map(({ text, path }, index) => {
|
|
24
24
|
if (index < maxSubCategory) {
|
|
25
|
-
|
|
25
|
+
const isActive = index == 0 ? true : false;
|
|
26
|
+
|
|
27
|
+
const item = isActive ? (
|
|
28
|
+
<span className={classes.item}><b>{text}</b></span>
|
|
29
|
+
) : (
|
|
26
30
|
<Link
|
|
27
31
|
key={index}
|
|
28
32
|
to={resourceUrl(path)}
|
|
29
33
|
>
|
|
30
34
|
<li className={classes.item}>{text}</li>
|
|
31
35
|
</Link>
|
|
32
|
-
)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
subCategory.push(item)
|
|
33
39
|
}
|
|
34
40
|
});
|
|
35
41
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback, useMemo, useRef, useState, useEffect } from 'react';
|
|
2
2
|
import { useLazyQuery, useQuery } from '@apollo/client';
|
|
3
3
|
|
|
4
4
|
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
5
5
|
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
6
|
-
import { useLocation } from 'react-router-dom';
|
|
6
|
+
import { useLocation, useHistory } from 'react-router-dom';
|
|
7
7
|
import DEFAULT_OPERATIONS from './categoryContent.gql';
|
|
8
8
|
import {
|
|
9
9
|
getFiltersFromSearch,
|
|
@@ -177,6 +177,57 @@ export const useCategoryContent = props => {
|
|
|
177
177
|
|
|
178
178
|
const filters = [];
|
|
179
179
|
|
|
180
|
+
const history = useHistory();
|
|
181
|
+
const location = useLocation();
|
|
182
|
+
|
|
183
|
+
const setQueryParam = ({ history, location, parameter, replace, value }) => {
|
|
184
|
+
const { search } = location;
|
|
185
|
+
const queryParams = new URLSearchParams(search);
|
|
186
|
+
|
|
187
|
+
queryParams.set(parameter, value);
|
|
188
|
+
const destination = { search: queryParams.toString() };
|
|
189
|
+
|
|
190
|
+
if (replace) {
|
|
191
|
+
history.replace(destination);
|
|
192
|
+
} else {
|
|
193
|
+
history.push(destination);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const setDefaultSubcategoryAndTopFilter = useCallback(
|
|
198
|
+
(value, searchParam, replace = false) => {
|
|
199
|
+
// Update the query parameter.
|
|
200
|
+
setQueryParam({
|
|
201
|
+
history,
|
|
202
|
+
location,
|
|
203
|
+
parameter: searchParam,
|
|
204
|
+
replace,
|
|
205
|
+
value: value
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
[history, location]
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
const { search } = location;
|
|
213
|
+
|
|
214
|
+
if (category && category.default_top_filter) {
|
|
215
|
+
const defaultTopFilter = category.default_top_filter;
|
|
216
|
+
|
|
217
|
+
const attrCode = defaultTopFilter.attribute_code;
|
|
218
|
+
const label = defaultTopFilter.label;
|
|
219
|
+
const value = defaultTopFilter.value;
|
|
220
|
+
|
|
221
|
+
if (!search.includes(attrCode)) {
|
|
222
|
+
setDefaultSubcategoryAndTopFilter(
|
|
223
|
+
label + ',' + value,
|
|
224
|
+
attrCode + '[filter]',
|
|
225
|
+
true
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}, [category, location, setDefaultSubcategoryAndTopFilter]);
|
|
230
|
+
|
|
180
231
|
// console.log('rawFilters')
|
|
181
232
|
// console.log(rawFilters)
|
|
182
233
|
|
|
@@ -163,12 +163,6 @@ const CategoryContent = props => {
|
|
|
163
163
|
<FilterModal filters={filters} />
|
|
164
164
|
) : null;
|
|
165
165
|
|
|
166
|
-
// console.log('filters')
|
|
167
|
-
// console.log(filters)
|
|
168
|
-
|
|
169
|
-
// console.log('shouldShowFilterButtons')
|
|
170
|
-
// console.log(shouldShowFilterButtons)
|
|
171
|
-
|
|
172
166
|
const sidebar = shouldShowFilterButtons ? (
|
|
173
167
|
<FilterSidebar hideFilters={category && category.hide_filters ? true : false} children={children} filters={filters} allowedFilters={category ? category.allowed_filters : []} />
|
|
174
168
|
) : shouldShowFilterShimmer ? (
|
|
@@ -289,7 +283,7 @@ const CategoryContent = props => {
|
|
|
289
283
|
|
|
290
284
|
const currentFilter = activeFilters && activeFilters.length ? activeFilters[activeFilters.length - 1].label : '';
|
|
291
285
|
|
|
292
|
-
let title = activeFilters && activeFilters.length ? (
|
|
286
|
+
let title = category && !category.children.length && activeFilters && activeFilters.length ? (
|
|
293
287
|
activeFilters.length > 1 ?
|
|
294
288
|
activeFilters[activeFilters.length - 1].label
|
|
295
289
|
: currentFilter
|