@riosst100/pwa-marketplace 1.7.4 → 1.7.6
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/CustomSubCategory/subCategory.js +12 -10
- package/src/components/FilterTop/CurrentTopFilters/currentTopFilter.js +2 -2
- package/src/components/FilterTop/FilterBlockList/filterBlockList.js +3 -1
- package/src/components/FilterTop/FilterBlockList/filterTopItem.js +9 -4
- package/src/components/FilterTop/FilterBlockList/filterTopItemGroup.js +3 -2
- package/src/components/FilterTop/filterTop.js +45 -3
- package/src/components/FilterTop/filterTop.module.css +1 -1
- package/src/components/FilterTop/filterTopBlock.js +3 -1
- package/src/components/ShopBy/shopBy.js +4 -2
- package/src/components/SubCategory/subCategory.js +1 -1
- package/src/overwrites/venia-ui/lib/components/Breadcrumbs/breadcrumbs.js +9 -1
- package/src/talons/FilterTop/useFilterTop.js +1 -27
- package/src/talons/ShopBy/shopBy.gql.js +17 -3
- package/src/talons/ShopBy/useShopBy.js +99 -21
- package/src/talons/SubCategory/useSubCategory.js +1 -1
package/package.json
CHANGED
|
@@ -20,16 +20,18 @@ const SubCategory = props => {
|
|
|
20
20
|
|
|
21
21
|
const subCategory = [];
|
|
22
22
|
|
|
23
|
-
normalizedData && normalizedData.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
if (normalizedData && normalizedData.length) {
|
|
24
|
+
normalizedData.map(({ text, path }, index) => {
|
|
25
|
+
subCategory.push(
|
|
26
|
+
<Link
|
|
27
|
+
key={index}
|
|
28
|
+
to={path}
|
|
29
|
+
>
|
|
30
|
+
<li className={classes.item}>{text}</li>
|
|
31
|
+
</Link>
|
|
32
|
+
)
|
|
33
|
+
});
|
|
34
|
+
}
|
|
33
35
|
|
|
34
36
|
return subCategory.length ? <ul className={classes.root}>{subCategory}</ul> : '';
|
|
35
37
|
|
|
@@ -31,7 +31,7 @@ const CurrentTopFilter = props => {
|
|
|
31
31
|
}
|
|
32
32
|
);
|
|
33
33
|
|
|
34
|
-
return (
|
|
34
|
+
return group != "shopby" ? (
|
|
35
35
|
<span className={classes.item} data-cy="CurrentTopFilter-root">
|
|
36
36
|
<Trigger
|
|
37
37
|
action={handleClick}
|
|
@@ -41,7 +41,7 @@ const CurrentTopFilter = props => {
|
|
|
41
41
|
All
|
|
42
42
|
</Trigger>
|
|
43
43
|
</span>
|
|
44
|
-
);
|
|
44
|
+
) : '';
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
export default CurrentTopFilter;
|
|
@@ -12,7 +12,8 @@ const FilterBlockList = props => {
|
|
|
12
12
|
items,
|
|
13
13
|
onApply,
|
|
14
14
|
filterNames,
|
|
15
|
-
originalFilterState
|
|
15
|
+
originalFilterState,
|
|
16
|
+
search
|
|
16
17
|
} = props;
|
|
17
18
|
|
|
18
19
|
const itemElements = useMemo(() => {
|
|
@@ -27,6 +28,7 @@ const FilterBlockList = props => {
|
|
|
27
28
|
items={items}
|
|
28
29
|
onApply={onApply}
|
|
29
30
|
labels={labels}
|
|
31
|
+
search={search}
|
|
30
32
|
filterNames={filterNames}
|
|
31
33
|
key={key}
|
|
32
34
|
/>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import defaultClasses from './filterTopItem.module.css';
|
|
3
3
|
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
4
|
+
import { Link } from 'react-router-dom';
|
|
4
5
|
|
|
5
6
|
const FilterTopItem = props => {
|
|
6
|
-
const { filterApi, group, item, onApply, labels, activeFilters } = props;
|
|
7
|
+
const { filterApi, group, item, onApply, labels, activeFilters, search } = props;
|
|
7
8
|
const { removeGroup, toggleItem } = filterApi;
|
|
8
9
|
const { title, value } = item;
|
|
9
10
|
|
|
@@ -26,10 +27,14 @@ const FilterTopItem = props => {
|
|
|
26
27
|
[group, item, onApply, removeGroup, toggleItem]
|
|
27
28
|
);
|
|
28
29
|
|
|
29
|
-
const element =
|
|
30
|
-
<
|
|
30
|
+
const element = group == "shopby" ? (
|
|
31
|
+
<Link className={classes.item} to={search ? search + '&shopby=' + value : '?shopby=' + value}>{title}</Link>
|
|
31
32
|
) : (
|
|
32
|
-
|
|
33
|
+
activeFilters.includes(value) ? (
|
|
34
|
+
<span className={classes.item}><b>{title}</b></span>
|
|
35
|
+
) : (
|
|
36
|
+
<span className={classes.item} onClick={() =>handleOnchange(value)}>{title}</span>
|
|
37
|
+
)
|
|
33
38
|
)
|
|
34
39
|
|
|
35
40
|
labels.set(element, label);
|
|
@@ -7,7 +7,7 @@ import defaultClasses from './filterTopItemGroup.module.css';
|
|
|
7
7
|
import CurrentTopFilter from '@riosst100/pwa-marketplace/src/components/FilterTop/CurrentTopFilters/currentTopFilter';
|
|
8
8
|
|
|
9
9
|
const FilterTopItemGroup = props => {
|
|
10
|
-
const { filterApi, filterState, group, items, onApply, labels, filterNames, originalFilterState } = props;
|
|
10
|
+
const { filterApi, filterState, group, items, onApply, labels, filterNames, originalFilterState, search } = props;
|
|
11
11
|
|
|
12
12
|
const classes = useStyle(defaultClasses, props.classes);
|
|
13
13
|
|
|
@@ -50,6 +50,7 @@ const FilterTopItemGroup = props => {
|
|
|
50
50
|
filterState={filterState}
|
|
51
51
|
group={group}
|
|
52
52
|
activeFilters={activeFilters}
|
|
53
|
+
search={search}
|
|
53
54
|
item={item}
|
|
54
55
|
onApply={onApply}
|
|
55
56
|
labels={labels}
|
|
@@ -83,7 +84,7 @@ const FilterTopItemGroup = props => {
|
|
|
83
84
|
return (
|
|
84
85
|
<div className={classes.root}>
|
|
85
86
|
{radioItems}
|
|
86
|
-
{filterElements && filterElements.length ? filterElements : <span className={classes.item}><b>All</b></span>}
|
|
87
|
+
{filterElements && filterElements.length ? filterElements : group != "shopby" ? (<span className={classes.item}><b>All</b></span>) : ''}
|
|
87
88
|
</div>
|
|
88
89
|
);
|
|
89
90
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useMemo, useCallback, useRef } from 'react';
|
|
1
|
+
import React, { useMemo, useCallback, useRef, useState } from 'react';
|
|
2
2
|
import { FormattedMessage } from 'react-intl';
|
|
3
3
|
import { array, arrayOf, shape, string, number } from 'prop-types';
|
|
4
4
|
import { useFilterTop } from '@riosst100/pwa-marketplace/src/talons/FilterTop';
|
|
5
|
-
|
|
5
|
+
import { useLocation } from 'react-router-dom';
|
|
6
6
|
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
7
7
|
import LinkButton from '@magento/venia-ui/lib/components/LinkButton';
|
|
8
8
|
import FilterTopBlock from './filterTopBlock';
|
|
@@ -10,6 +10,8 @@ import defaultClasses from './filterTop.module.css';
|
|
|
10
10
|
import { Filter } from 'iconsax-react';
|
|
11
11
|
import cn from 'classnames';
|
|
12
12
|
import { useHistory } from 'react-router-dom';
|
|
13
|
+
import { Link } from 'react-router-dom';
|
|
14
|
+
import { getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
const SCROLL_OFFSET = 150;
|
|
@@ -33,6 +35,21 @@ const FilterTop = props => {
|
|
|
33
35
|
customFilters
|
|
34
36
|
} = talonProps;
|
|
35
37
|
|
|
38
|
+
const classes = useStyle(defaultClasses, props.classes);
|
|
39
|
+
|
|
40
|
+
const [activeSportCardsSetsFilter, setActiveSportCardsSetsFilter] = useState('all');
|
|
41
|
+
const [activeBaseSetFilter, setActiveBaseSetFilter] = useState('all');
|
|
42
|
+
|
|
43
|
+
const { search } = useLocation();
|
|
44
|
+
|
|
45
|
+
// const filtersSearch = getFiltersFromSearch(search);
|
|
46
|
+
|
|
47
|
+
// console.log(search)
|
|
48
|
+
|
|
49
|
+
// filters.forEach((values, key) => {
|
|
50
|
+
// newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
|
|
51
|
+
// });
|
|
52
|
+
|
|
36
53
|
const filterRef = useRef();
|
|
37
54
|
|
|
38
55
|
const handleApplyFilter = useCallback(
|
|
@@ -84,6 +101,10 @@ const FilterTop = props => {
|
|
|
84
101
|
// });
|
|
85
102
|
// const allowedFiltersArr = ['card_rarity','card_print_version','card_set', 'card_product_type'];
|
|
86
103
|
|
|
104
|
+
// console.log(customFilters)
|
|
105
|
+
|
|
106
|
+
// console.log(filterItems)
|
|
107
|
+
|
|
87
108
|
const filtersList = useMemo(
|
|
88
109
|
() =>
|
|
89
110
|
Array.from(filterItems, ([group, items], iteration) => {
|
|
@@ -101,6 +122,7 @@ const FilterTop = props => {
|
|
|
101
122
|
originalFilterState={filterState}
|
|
102
123
|
filterFrontendInput={frontendInput}
|
|
103
124
|
group={group}
|
|
125
|
+
search={search}
|
|
104
126
|
items={items}
|
|
105
127
|
name={groupName}
|
|
106
128
|
onApply={group == "category_uid" ? handleCategoryApplyFilter : handleApplyFilter}
|
|
@@ -122,7 +144,27 @@ const FilterTop = props => {
|
|
|
122
144
|
);
|
|
123
145
|
|
|
124
146
|
return (
|
|
125
|
-
<div>
|
|
147
|
+
<div>
|
|
148
|
+
{/* <div className={classes.root}>
|
|
149
|
+
{sportCardsSetsFilter.map(({label, value}, index) =>
|
|
150
|
+
activeSportCardsSetsFilter == value ? <span className={classes.item}><b>{label}</b></span> : <span onClick={() => setActiveSportCardsSetsFilter(value)} className={classes.item}>{label}</span>
|
|
151
|
+
)}
|
|
152
|
+
</div>
|
|
153
|
+
<div className={classes.root}>
|
|
154
|
+
{activeSportCardsSetsFilter == "base_set" && baseSetFilter.map(({label, value}, index) =>
|
|
155
|
+
activeBaseSetFilter == value ? <span className={classes.item}><b>{label}</b></span> : <span onClick={() => setActiveBaseSetFilter(value)} className={classes.item}>{label}</span>
|
|
156
|
+
)}
|
|
157
|
+
</div> */}
|
|
158
|
+
{filtersList}
|
|
159
|
+
{/* {activeSportCardsSetsFilter == "inserts_parallel" && (
|
|
160
|
+
<>
|
|
161
|
+
<div className={classes.root}>
|
|
162
|
+
<Link to={'?shopby=inserts'} className={classes.item}>Inserts</Link>
|
|
163
|
+
<Link to={'?shopby=parallel'} className={classes.item}>Parallel</Link>
|
|
164
|
+
</div>
|
|
165
|
+
</>
|
|
166
|
+
)} */}
|
|
167
|
+
</div>
|
|
126
168
|
);
|
|
127
169
|
};
|
|
128
170
|
|
|
@@ -24,7 +24,8 @@ const FilterTopBlock = props => {
|
|
|
24
24
|
onApply,
|
|
25
25
|
filterNames,
|
|
26
26
|
initialOpen,
|
|
27
|
-
originalFilterState
|
|
27
|
+
originalFilterState,
|
|
28
|
+
search
|
|
28
29
|
} = props;
|
|
29
30
|
|
|
30
31
|
const { formatMessage } = useIntl();
|
|
@@ -42,6 +43,7 @@ const FilterTopBlock = props => {
|
|
|
42
43
|
name={name}
|
|
43
44
|
filterFrontendInput={filterFrontendInput}
|
|
44
45
|
group={group}
|
|
46
|
+
search={search}
|
|
45
47
|
items={items}
|
|
46
48
|
filterNames={filterNames}
|
|
47
49
|
onApply={onApply}
|
|
@@ -107,7 +107,7 @@ const ShopBy = props => {
|
|
|
107
107
|
|
|
108
108
|
const talonProps = useShopBy({ searchQuery, setActive, currentSort, categoryId, shopby });
|
|
109
109
|
|
|
110
|
-
const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category } = talonProps;
|
|
110
|
+
const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category, activeFilters } = talonProps;
|
|
111
111
|
|
|
112
112
|
if (loading && !dataResult)
|
|
113
113
|
return <ShopByShimmer />;
|
|
@@ -190,10 +190,12 @@ const ShopBy = props => {
|
|
|
190
190
|
}
|
|
191
191
|
];
|
|
192
192
|
|
|
193
|
+
console.log(activeFilters)
|
|
194
|
+
|
|
193
195
|
return (
|
|
194
196
|
<Fragment>
|
|
195
197
|
<StoreTitle>{attributeData ? 'By ' + attributeData.label : 'Shop By'}</StoreTitle>
|
|
196
|
-
<Breadcrumbs categoryId={categoryId} customPage={'By ' + attributeData.label} />
|
|
198
|
+
<Breadcrumbs categoryId={categoryId} customPage={'By ' + attributeData.label} currentFilter={activeFilters} />
|
|
197
199
|
<h1 className='mx-auto relative block text-xl font-bold text-center pt-10 pb-4'>
|
|
198
200
|
{attributeData ? 'By ' + attributeData.label : 'Shop By'}
|
|
199
201
|
</h1>
|
|
@@ -20,7 +20,7 @@ const SubCategory = props => {
|
|
|
20
20
|
|
|
21
21
|
const subCategory = [];
|
|
22
22
|
|
|
23
|
-
normalizedData && normalizedData.map(({ text, path }, index) => {
|
|
23
|
+
normalizedData && normalizedData.length && normalizedData.map(({ text, path }, index) => {
|
|
24
24
|
if (index < maxSubCategory) {
|
|
25
25
|
subCategory.push(
|
|
26
26
|
<Link
|
|
@@ -70,23 +70,30 @@ const Breadcrumbs = props => {
|
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// console.log(currentFilter)
|
|
74
|
+
|
|
73
75
|
const filterBreadcrumbsElement = [];
|
|
74
76
|
|
|
75
77
|
currentFilter && currentFilter.length && currentFilter.map((filter, index) => {
|
|
76
78
|
currentProduct ? (
|
|
77
79
|
filterBreadcrumbsElement.push(
|
|
80
|
+
<>
|
|
81
|
+
<span className={classes.divider}>{DELIMITER}</span>
|
|
78
82
|
<Link
|
|
79
83
|
key={index}
|
|
80
84
|
className={classes.link}
|
|
81
|
-
to={
|
|
85
|
+
to={filter.path}
|
|
82
86
|
onClick={handleClick}
|
|
83
87
|
>
|
|
84
88
|
{filter.label}
|
|
85
89
|
</Link>
|
|
90
|
+
</>
|
|
86
91
|
)
|
|
87
92
|
) : (
|
|
88
93
|
customPage ? (
|
|
89
94
|
filterBreadcrumbsElement.push(
|
|
95
|
+
<>
|
|
96
|
+
<span className={classes.divider}>{DELIMITER}</span>
|
|
90
97
|
<Link
|
|
91
98
|
key={index}
|
|
92
99
|
className={classes.link}
|
|
@@ -95,6 +102,7 @@ const Breadcrumbs = props => {
|
|
|
95
102
|
>
|
|
96
103
|
{filter.label}
|
|
97
104
|
</Link>
|
|
105
|
+
</>
|
|
98
106
|
)
|
|
99
107
|
) : filterBreadcrumbsElement.push(
|
|
100
108
|
<span key={index}>
|
|
@@ -173,33 +173,7 @@ export const useFilterTop = props => {
|
|
|
173
173
|
const frontendInput = new Map();
|
|
174
174
|
const itemsByGroup = new Map();
|
|
175
175
|
const customFiltersMap = [];
|
|
176
|
-
|
|
177
|
-
const sortedFilters = sortFiltersArray([...filters]);
|
|
178
|
-
|
|
179
|
-
for (const filter of sortedFilters) {
|
|
180
|
-
const { options, label: name, attribute_code: group } = filter;
|
|
181
|
-
|
|
182
|
-
// If this aggregation is not a possible filter, just back out.
|
|
183
|
-
if (possibleFilters.has(group)) {
|
|
184
|
-
const items = [];
|
|
185
|
-
|
|
186
|
-
// add filter name
|
|
187
|
-
names.set(group, name);
|
|
188
|
-
|
|
189
|
-
// add filter key permutations
|
|
190
|
-
keys.add(`${group}[filter]`);
|
|
191
|
-
|
|
192
|
-
// Add frontend input type
|
|
193
|
-
frontendInput.set(group, null);
|
|
194
|
-
// add items
|
|
195
|
-
for (const { label, value, path } of options) {
|
|
196
|
-
items.push({ title: stripHtml(label), value, path });
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
itemsByGroup.set(group, items);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
176
|
+
|
|
203
177
|
if (customFiltersData) {
|
|
204
178
|
customFiltersData.map(({ attribute_code, options }, index) => {
|
|
205
179
|
|
|
@@ -12,8 +12,8 @@ export const GET_STORE_CONFIG_DATA = gql`
|
|
|
12
12
|
`;
|
|
13
13
|
|
|
14
14
|
export const GET_SHOP_BY_DATA_QUERY = gql`
|
|
15
|
-
query getShopByData($categoryUrlKey: String!, $attributeCode: String) {
|
|
16
|
-
shopByData(categoryUrlKey: $categoryUrlKey, attributeCode: $attributeCode) {
|
|
15
|
+
query getShopByData($categoryUrlKey: String!, $attributeCode: String, $filters: ProductAttributeFilterInput!) {
|
|
16
|
+
shopByData(categoryUrlKey: $categoryUrlKey, attributeCode: $attributeCode, filters: $filters) {
|
|
17
17
|
label
|
|
18
18
|
count
|
|
19
19
|
attribute_code
|
|
@@ -40,8 +40,22 @@ export const GET_CATEGORY_CONTENT = gql`
|
|
|
40
40
|
}
|
|
41
41
|
`;
|
|
42
42
|
|
|
43
|
+
export const GET_FILTER_INPUTS = gql`
|
|
44
|
+
query GetFilterInputsForCategory {
|
|
45
|
+
__type(name: "ProductAttributeFilterInput") {
|
|
46
|
+
inputFields {
|
|
47
|
+
name
|
|
48
|
+
type {
|
|
49
|
+
name
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
|
|
43
56
|
export default {
|
|
44
57
|
getStoreConfigData: GET_STORE_CONFIG_DATA,
|
|
45
58
|
getShopByDataQuery: GET_SHOP_BY_DATA_QUERY,
|
|
46
|
-
getCategoryContentQuery: GET_CATEGORY_CONTENT
|
|
59
|
+
getCategoryContentQuery: GET_CATEGORY_CONTENT,
|
|
60
|
+
getFilterInputsQuery: GET_FILTER_INPUTS,
|
|
47
61
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { useQuery } from '@apollo/client';
|
|
1
|
+
import { useQuery, useLazyQuery } from '@apollo/client';
|
|
2
2
|
import { useEffect, useMemo } from 'react';
|
|
3
3
|
import { useLocation } from 'react-router-dom';
|
|
4
4
|
import { useAppContext } from '@magento/peregrine/lib/context/app';
|
|
5
5
|
|
|
6
6
|
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
7
7
|
import DEFAULT_OPERATIONS from './shopBy.gql';
|
|
8
|
+
import { getFilterInput, getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
|
|
8
9
|
|
|
9
10
|
export const useShopBy = props => {
|
|
10
11
|
|
|
@@ -13,8 +14,8 @@ export const useShopBy = props => {
|
|
|
13
14
|
const { value: sortby } = currentSort
|
|
14
15
|
|
|
15
16
|
const operations = mergeOperations(DEFAULT_OPERATIONS, null);
|
|
16
|
-
const { getStoreConfigData, getShopByDataQuery, getCategoryContentQuery } = operations;
|
|
17
|
-
const { pathname } = useLocation();
|
|
17
|
+
const { getStoreConfigData, getShopByDataQuery, getCategoryContentQuery, getFilterInputsQuery } = operations;
|
|
18
|
+
const { pathname, search } = useLocation();
|
|
18
19
|
// const [
|
|
19
20
|
// ,
|
|
20
21
|
// {
|
|
@@ -22,6 +23,11 @@ export const useShopBy = props => {
|
|
|
22
23
|
// }
|
|
23
24
|
// ] = useAppContext();
|
|
24
25
|
|
|
26
|
+
const [runQuery, queryResponse] = useLazyQuery(getShopByDataQuery, {
|
|
27
|
+
fetchPolicy: 'cache-and-network',
|
|
28
|
+
nextFetchPolicy: 'cache-first'
|
|
29
|
+
});
|
|
30
|
+
|
|
25
31
|
const { data: storeConfigData } = useQuery(getStoreConfigData, {
|
|
26
32
|
fetchPolicy: 'cache-and-network',
|
|
27
33
|
nextFetchPolicy: 'cache-first'
|
|
@@ -33,26 +39,97 @@ export const useShopBy = props => {
|
|
|
33
39
|
|
|
34
40
|
const categoryUrlSuffix = storeConfigData?.storeConfig?.category_url_suffix;
|
|
35
41
|
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
const { data: introspectionData } = useQuery(getFilterInputsQuery);
|
|
43
|
+
|
|
44
|
+
const filterTypeMap = useMemo(() => {
|
|
45
|
+
const typeMap = new Map();
|
|
46
|
+
if (introspectionData) {
|
|
47
|
+
introspectionData.__type.inputFields.forEach(({ name, type }) => {
|
|
48
|
+
typeMap.set(name, type.name);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return typeMap;
|
|
52
|
+
}, [introspectionData]);
|
|
53
|
+
|
|
54
|
+
const activeFilters = [];
|
|
55
|
+
|
|
56
|
+
// if (!filterTypeMap.size) {
|
|
57
|
+
// return;
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
const filters = getFiltersFromSearch(search);
|
|
61
|
+
|
|
62
|
+
console.log(search)
|
|
63
|
+
|
|
64
|
+
// Construct the filter arg object.
|
|
65
|
+
const newFilters = {};
|
|
66
|
+
filters.forEach((values, key) => {
|
|
67
|
+
newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
|
|
68
|
+
// console.log(key)
|
|
69
|
+
// console.log(values)
|
|
70
|
+
|
|
71
|
+
if (key == "sc_baseball_release") {
|
|
72
|
+
for(let item of values) {
|
|
73
|
+
if(item) {
|
|
74
|
+
// console.log(item.split(',')[0])
|
|
75
|
+
const data = search.split('&');
|
|
76
|
+
data.pop();
|
|
77
|
+
activeFilters.push(
|
|
78
|
+
{
|
|
79
|
+
'label': item.split(',')[0],
|
|
80
|
+
'path': data
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
43
85
|
}
|
|
44
86
|
});
|
|
45
87
|
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
// Use the category uid for the current category page regardless of the
|
|
93
|
+
// applied filters. Follow-up in PWA-404.
|
|
94
|
+
// newFilters['category_uid'] = { eq: id };
|
|
95
|
+
|
|
96
|
+
runQuery({
|
|
97
|
+
variables: {
|
|
98
|
+
filters: newFilters,
|
|
99
|
+
categoryUrlKey: categoryUrlKey,
|
|
100
|
+
attributeCode: shopby
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}, [
|
|
104
|
+
runQuery,
|
|
105
|
+
// filterTypeMap,
|
|
106
|
+
// search
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
// console.log(activeFilters)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
// const { error, loading, data } = useQuery(getShopByDataQuery, {
|
|
114
|
+
// fetchPolicy: 'cache-and-network',
|
|
115
|
+
// nextFetchPolicy: 'cache-first',
|
|
116
|
+
// skip: !storeConfigData,
|
|
117
|
+
// variables: {
|
|
118
|
+
// categoryUrlKey: categoryUrlKey,
|
|
119
|
+
// attributeCode: shopby
|
|
120
|
+
// }
|
|
121
|
+
// });
|
|
122
|
+
|
|
46
123
|
const alpha = ['#', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
|
|
47
124
|
|
|
48
|
-
// const isBackgroundLoading = !!
|
|
125
|
+
// const isBackgroundLoading = !!queryResponse && loading;
|
|
49
126
|
|
|
50
127
|
const originalDataResult = useMemo(() => {
|
|
51
|
-
if (!
|
|
128
|
+
if (!queryResponse) {
|
|
52
129
|
return null;
|
|
53
130
|
}
|
|
54
131
|
|
|
55
|
-
const rawData = data
|
|
132
|
+
const rawData = queryResponse?.data?.shopByData;
|
|
56
133
|
if (!rawData) {
|
|
57
134
|
return null;
|
|
58
135
|
}
|
|
@@ -72,14 +149,14 @@ export const useShopBy = props => {
|
|
|
72
149
|
const sortbyData = [];
|
|
73
150
|
|
|
74
151
|
return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : mappingData;
|
|
75
|
-
}, [
|
|
152
|
+
}, [queryResponse, sortby, searchQuery]);
|
|
76
153
|
|
|
77
154
|
const dataResult = useMemo(() => {
|
|
78
|
-
if (!
|
|
155
|
+
if (!queryResponse) {
|
|
79
156
|
return null;
|
|
80
157
|
}
|
|
81
158
|
|
|
82
|
-
const rawData = data
|
|
159
|
+
const rawData = queryResponse?.data?.shopByData;
|
|
83
160
|
if (!rawData) {
|
|
84
161
|
return null;
|
|
85
162
|
}
|
|
@@ -106,14 +183,14 @@ export const useShopBy = props => {
|
|
|
106
183
|
const sortbyData = [];
|
|
107
184
|
|
|
108
185
|
return sortby != "all" ? sortbyData && sortbyData.length ? sortbyData.sort((a, b) => b.release_type.toLowerCase().localeCompare(a.release_type.toLowerCase())) : sortbyData : mappingData;
|
|
109
|
-
}, [
|
|
186
|
+
}, [queryResponse, sortby, searchQuery]);
|
|
110
187
|
|
|
111
188
|
const availableGroups = originalDataResult ? Object.keys(originalDataResult).sort() : [];
|
|
112
189
|
|
|
113
190
|
const filteredAvailableGroups = dataResult ? Object.keys(dataResult).sort() : [];
|
|
114
191
|
|
|
115
192
|
|
|
116
|
-
const attributeData = data ? data.shopByData[0] : null
|
|
193
|
+
const attributeData = queryResponse?.data?.shopByData && queryResponse?.data?.shopByData.length ? queryResponse.data.shopByData[0] : null
|
|
117
194
|
|
|
118
195
|
const { data: categoryData, loading: categoryLoading } = useQuery(
|
|
119
196
|
getCategoryContentQuery,
|
|
@@ -133,8 +210,8 @@ export const useShopBy = props => {
|
|
|
133
210
|
: null;
|
|
134
211
|
|
|
135
212
|
return {
|
|
136
|
-
error,
|
|
137
|
-
loading,
|
|
213
|
+
// error,
|
|
214
|
+
// loading,
|
|
138
215
|
dataResult,
|
|
139
216
|
// collectibleGameSets,
|
|
140
217
|
filteredAvailableGroups,
|
|
@@ -143,7 +220,8 @@ export const useShopBy = props => {
|
|
|
143
220
|
availableGroups,
|
|
144
221
|
attributeData,
|
|
145
222
|
alpha,
|
|
146
|
-
category
|
|
223
|
+
category,
|
|
224
|
+
activeFilters
|
|
147
225
|
// productType
|
|
148
226
|
};
|
|
149
227
|
};
|