@riosst100/pwa-marketplace 1.7.5 → 1.7.7
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/FilterTop/FilterBlockList/filterTopItem.js +1 -1
- package/src/components/FilterTop/FilterBlockList/filterTopItemGroup.js +1 -0
- package/src/components/ShopBy/shopBy.js +14 -4
- package/src/overwrites/venia-ui/lib/components/Breadcrumbs/breadcrumbs.js +9 -1
- package/src/talons/ShopBy/shopBy.gql.js +17 -3
- package/src/talons/ShopBy/useShopBy.js +99 -21
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ const FilterTopItem = props => {
|
|
|
27
27
|
[group, item, onApply, removeGroup, toggleItem]
|
|
28
28
|
);
|
|
29
29
|
|
|
30
|
-
const element = group == "shopby" ? (
|
|
30
|
+
const element = group == "shopby" || group == "shopby_with_all" ? (
|
|
31
31
|
<Link className={classes.item} to={search ? search + '&shopby=' + value : '?shopby=' + value}>{title}</Link>
|
|
32
32
|
) : (
|
|
33
33
|
activeFilters.includes(value) ? (
|
|
@@ -84,6 +84,7 @@ const FilterTopItemGroup = props => {
|
|
|
84
84
|
return (
|
|
85
85
|
<div className={classes.root}>
|
|
86
86
|
{radioItems}
|
|
87
|
+
{filterElements && filterElements.length > 10 ? <span className={classes.item}><b>More Item</b></span> : ''}
|
|
87
88
|
{filterElements && filterElements.length ? filterElements : group != "shopby" ? (<span className={classes.item}><b>All</b></span>) : ''}
|
|
88
89
|
</div>
|
|
89
90
|
);
|
|
@@ -89,6 +89,7 @@ const ShopBy = props => {
|
|
|
89
89
|
|
|
90
90
|
const [searchQuery, setSearchQuery] = useState('');
|
|
91
91
|
|
|
92
|
+
const { search } = useLocation();
|
|
92
93
|
|
|
93
94
|
const sortProps = useCustomSort({ sortFromSearch: false, defaultSort: {
|
|
94
95
|
sortText: 'All (A-Z)',
|
|
@@ -107,7 +108,7 @@ const ShopBy = props => {
|
|
|
107
108
|
|
|
108
109
|
const talonProps = useShopBy({ searchQuery, setActive, currentSort, categoryId, shopby });
|
|
109
110
|
|
|
110
|
-
const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category } = talonProps;
|
|
111
|
+
const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category, activeFilters } = talonProps;
|
|
111
112
|
|
|
112
113
|
if (loading && !dataResult)
|
|
113
114
|
return <ShopByShimmer />;
|
|
@@ -127,6 +128,10 @@ const ShopBy = props => {
|
|
|
127
128
|
return result;
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
const filterSearchArr = search ? search.split('&') : [];
|
|
132
|
+
filterSearchArr.pop();
|
|
133
|
+
const filterSearch = filterSearchArr.join('&')
|
|
134
|
+
|
|
130
135
|
const setRelases = newAvailableGroups.map((group, index) => {
|
|
131
136
|
const optionsResult = [];
|
|
132
137
|
|
|
@@ -134,8 +139,11 @@ const ShopBy = props => {
|
|
|
134
139
|
dataResult[group].map((option, index) => {
|
|
135
140
|
const { label, value } = option;
|
|
136
141
|
|
|
142
|
+
const filter = attributeData.attribute_code + '[filter]=' + label + ',' + value;
|
|
143
|
+
const params = filterSearch ? filterSearch + '&' + filter : '?' + filter;
|
|
144
|
+
|
|
137
145
|
const categoryUrl = resourceUrl(
|
|
138
|
-
`/${category.url_path}${categoryUrlSuffix || ''}
|
|
146
|
+
`/${category.url_path}${categoryUrlSuffix || ''}${params}`
|
|
139
147
|
);
|
|
140
148
|
|
|
141
149
|
optionsResult.push(<li className='list-none'>
|
|
@@ -143,7 +151,7 @@ const ShopBy = props => {
|
|
|
143
151
|
{label}
|
|
144
152
|
</Link>
|
|
145
153
|
</li>)
|
|
146
|
-
})
|
|
154
|
+
});
|
|
147
155
|
|
|
148
156
|
let optionsResultSplitted = [];
|
|
149
157
|
if (active == group) {
|
|
@@ -190,10 +198,12 @@ const ShopBy = props => {
|
|
|
190
198
|
}
|
|
191
199
|
];
|
|
192
200
|
|
|
201
|
+
console.log(activeFilters)
|
|
202
|
+
|
|
193
203
|
return (
|
|
194
204
|
<Fragment>
|
|
195
205
|
<StoreTitle>{attributeData ? 'By ' + attributeData.label : 'Shop By'}</StoreTitle>
|
|
196
|
-
<Breadcrumbs categoryId={categoryId} customPage={'By ' + attributeData.label} />
|
|
206
|
+
<Breadcrumbs categoryId={categoryId} customPage={'By ' + attributeData.label} currentFilter={activeFilters} />
|
|
197
207
|
<h1 className='mx-auto relative block text-xl font-bold text-center pt-10 pb-4'>
|
|
198
208
|
{attributeData ? 'By ' + attributeData.label : 'Shop By'}
|
|
199
209
|
</h1>
|
|
@@ -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}>
|
|
@@ -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
|
};
|