@riosst100/pwa-marketplace 2.6.9 → 2.7.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/FilterListContent/filterListPage.js +1 -1
- package/src/components/SellerProducts/productContent.js +1 -1
- package/src/components/SetsData/setsData.js +1 -1
- package/src/components/ShopBy/shopBy.js +30 -12
- package/src/talons/ShopBy/shopBy.gql.js +30 -0
- package/src/talons/ShopBy/useShopBy.js +64 -83
package/package.json
CHANGED
|
@@ -245,7 +245,7 @@ const FilterListPage = props => {
|
|
|
245
245
|
if (label == "Singles") {
|
|
246
246
|
isSingles = true;
|
|
247
247
|
}
|
|
248
|
-
if (key == "bricks_categories" || key == "sc_sports_categories" || key == "card_game" || key == "product_line" && urlKey == "brands" || key == "product_line" && urlKey == "franchise" || key == "franchise" && urlKey == "brands" || key == "franchise" && urlKey == "franchise" || key == "brands" && urlKey == "franchise" || key == "brands" && urlKey == "brands"
|
|
248
|
+
if (key == "bricks_categories" || key == "sc_sports_categories" || key == "card_game" || key == "product_line" && urlKey == "brands" || key == "product_line" && urlKey == "franchise" || key == "franchise" && urlKey == "brands" || key == "franchise" && urlKey == "franchise" || key == "brands" && urlKey == "franchise" || key == "brands" && urlKey == "brands") {
|
|
249
249
|
activeFilters.push(
|
|
250
250
|
{
|
|
251
251
|
'label': label,
|
|
@@ -228,7 +228,7 @@ const ProductContent = props => {
|
|
|
228
228
|
if (label == "Singles") {
|
|
229
229
|
isSingles = true;
|
|
230
230
|
}
|
|
231
|
-
if (key == "bricks_categories" || key == "sc_sports_categories" || key == "card_game" || key == "product_line" && urlKey == "brands" || key == "product_line" && urlKey == "franchise" || key == "franchise" && urlKey == "brands" || key == "franchise" && urlKey == "franchise" || key == "brands" && urlKey == "franchise" || key == "brands" && urlKey == "brands"
|
|
231
|
+
if (key == "bricks_categories" || key == "sc_sports_categories" || key == "card_game" || key == "product_line" && urlKey == "brands" || key == "product_line" && urlKey == "franchise" || key == "franchise" && urlKey == "brands" || key == "franchise" && urlKey == "franchise" || key == "brands" && urlKey == "franchise" || key == "brands" && urlKey == "brands") {
|
|
232
232
|
activeFilters.push(
|
|
233
233
|
{
|
|
234
234
|
'label': label,
|
|
@@ -261,7 +261,7 @@ const SetsData = props => {
|
|
|
261
261
|
if (label == "Singles") {
|
|
262
262
|
isSingles = true;
|
|
263
263
|
}
|
|
264
|
-
if (key == "bricks_categories" || key == "sc_sports_categories" || key == "card_game" || key == "product_line" && urlKey == "brands" || key == "product_line" && urlKey == "franchise" || key == "franchise" && urlKey == "brands" || key == "franchise" && urlKey == "franchise" || key == "brands" && urlKey == "franchise" || key == "brands" && urlKey == "brands"
|
|
264
|
+
if (key == "bricks_categories" || key == "sc_sports_categories" || key == "card_game" || key == "product_line" && urlKey == "brands" || key == "product_line" && urlKey == "franchise" || key == "franchise" && urlKey == "brands" || key == "franchise" && urlKey == "franchise" || key == "brands" && urlKey == "franchise" || key == "brands" && urlKey == "brands") {
|
|
265
265
|
activeFilters.push(
|
|
266
266
|
{
|
|
267
267
|
'label': label,
|
|
@@ -83,7 +83,6 @@ const ShopBy = props => {
|
|
|
83
83
|
// totalPagesFromData,
|
|
84
84
|
// attributesBlock,
|
|
85
85
|
// category,
|
|
86
|
-
// virtualCategoryFilters
|
|
87
86
|
// } = talonProps;
|
|
88
87
|
|
|
89
88
|
const [active, setActive] = useState('all')
|
|
@@ -110,9 +109,7 @@ const ShopBy = props => {
|
|
|
110
109
|
|
|
111
110
|
const talonProps = useShopBy({ activeFilter, searchQuery, active, setActive, currentSort, categoryId, shopby });
|
|
112
111
|
|
|
113
|
-
const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category,
|
|
114
|
-
|
|
115
|
-
console.log('dataResult SHOPBY', dataResult)
|
|
112
|
+
const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category, pageInfo } = talonProps;
|
|
116
113
|
|
|
117
114
|
if (loading) {
|
|
118
115
|
return <ShopByShimmer />;
|
|
@@ -153,7 +150,7 @@ const ShopBy = props => {
|
|
|
153
150
|
|
|
154
151
|
if (active === 'all' || active === group) {
|
|
155
152
|
dataResult[group] && dataResult[group].length && dataResult[group].map((option, index) => {
|
|
156
|
-
const {
|
|
153
|
+
const { count, label, value } = option;
|
|
157
154
|
|
|
158
155
|
const filter = attributeData.attribute_code + '[filter]=' + label + ',' + value;
|
|
159
156
|
const params = filterSearch ? filterSearch + '&' + filter + additionalFilter : '?' + filter + additionalFilter;
|
|
@@ -164,7 +161,7 @@ const ShopBy = props => {
|
|
|
164
161
|
|
|
165
162
|
optionsResult.push(<li key={index} className='list-none'>
|
|
166
163
|
<Link to={categoryUrl} className="hover_bg-darkblue-900 hover_text-white w-full block text-[14px] py-[2px] px-0">
|
|
167
|
-
{label} <span className='text-[12px]'>({
|
|
164
|
+
{label} <span className='text-[12px]'>({count})</span>
|
|
168
165
|
</Link>
|
|
169
166
|
</li>)
|
|
170
167
|
});
|
|
@@ -174,8 +171,6 @@ const ShopBy = props => {
|
|
|
174
171
|
optionsResultSplitted = splitToNChunks(optionsResult, 3);
|
|
175
172
|
}
|
|
176
173
|
|
|
177
|
-
// console.log(dataResult)
|
|
178
|
-
|
|
179
174
|
const all = active == "all" ? (
|
|
180
175
|
newAvailableGroups.length == 1 ? (
|
|
181
176
|
optionsResultSplitted && optionsResultSplitted.length && optionsResultSplitted.map((data, index) => (
|
|
@@ -234,7 +229,7 @@ const ShopBy = props => {
|
|
|
234
229
|
];
|
|
235
230
|
|
|
236
231
|
// const title = attributeData ? (attributeData.attribute_code == "sc_baseball_parallel" ? "Parallel Sets" : (attributeData.attribute_code == "sc_baseball_inserts" ? "Insert Sets" : attributeData.label)) : "Shop By"
|
|
237
|
-
const title = pageInfo ? pageInfo.
|
|
232
|
+
const title = pageInfo ? pageInfo.label : '';
|
|
238
233
|
|
|
239
234
|
let availableFilterOption = [];
|
|
240
235
|
|
|
@@ -283,8 +278,6 @@ const ShopBy = props => {
|
|
|
283
278
|
];
|
|
284
279
|
}
|
|
285
280
|
|
|
286
|
-
// console.log(category)
|
|
287
|
-
|
|
288
281
|
if (shopby == "brands" || shopby == "product_line") {
|
|
289
282
|
if (category && category?.url_path.includes('anime-figures')) {
|
|
290
283
|
availableFilterOption = [
|
|
@@ -340,7 +333,32 @@ const ShopBy = props => {
|
|
|
340
333
|
setSearchQuery('')
|
|
341
334
|
}
|
|
342
335
|
|
|
343
|
-
|
|
336
|
+
const activeFilters = [];
|
|
337
|
+
|
|
338
|
+
const allActiveFilters = getFiltersFromSearch(search);
|
|
339
|
+
|
|
340
|
+
if (allActiveFilters && allActiveFilters.size > 0) {
|
|
341
|
+
allActiveFilters.forEach((value, key) => {
|
|
342
|
+
value.forEach((value) => {
|
|
343
|
+
const filterArr = value.split(',');
|
|
344
|
+
|
|
345
|
+
const label = filterArr[0];
|
|
346
|
+
const optionId = filterArr[1];
|
|
347
|
+
if (label == "Singles") {
|
|
348
|
+
isSingles = true;
|
|
349
|
+
}
|
|
350
|
+
if (key == "bricks_categories" || key == "sc_sports_categories" || key == "card_game" || key == "product_line" && urlKey == "brands" || key == "product_line" && urlKey == "franchise" || key == "franchise" && urlKey == "brands" || key == "franchise" && urlKey == "franchise" || key == "brands" && urlKey == "franchise" || key == "brands" && urlKey == "brands") {
|
|
351
|
+
activeFilters.push(
|
|
352
|
+
{
|
|
353
|
+
'label': label,
|
|
354
|
+
'code': key,
|
|
355
|
+
'option_id': optionId
|
|
356
|
+
}
|
|
357
|
+
)
|
|
358
|
+
}
|
|
359
|
+
})
|
|
360
|
+
});
|
|
361
|
+
}
|
|
344
362
|
|
|
345
363
|
return (
|
|
346
364
|
<Fragment>
|
|
@@ -60,9 +60,39 @@ export const GET_FILTER_INPUTS = gql`
|
|
|
60
60
|
}
|
|
61
61
|
`;
|
|
62
62
|
|
|
63
|
+
export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
|
|
64
|
+
query getProductMainFiltersByCategory(
|
|
65
|
+
$filters: ProductAttributeFilterInput!
|
|
66
|
+
) {
|
|
67
|
+
products(filter: $filters) {
|
|
68
|
+
aggregations {
|
|
69
|
+
label
|
|
70
|
+
count
|
|
71
|
+
attribute_code
|
|
72
|
+
options {
|
|
73
|
+
label
|
|
74
|
+
value
|
|
75
|
+
count
|
|
76
|
+
}
|
|
77
|
+
position
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
export const GET_MASTER_ATTRIBUTES = gql`
|
|
84
|
+
query GetMasterAttributes {
|
|
85
|
+
masterAttributes {
|
|
86
|
+
attribute_code
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
90
|
+
|
|
63
91
|
export default {
|
|
64
92
|
getStoreConfigData: GET_STORE_CONFIG_DATA,
|
|
65
93
|
getShopByDataQuery: GET_SHOP_BY_DATA_QUERY,
|
|
66
94
|
getCategoryContentQuery: GET_CATEGORY_CONTENT,
|
|
67
95
|
getFilterInputsQuery: GET_FILTER_INPUTS,
|
|
96
|
+
getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY,
|
|
97
|
+
getMasterAttributesQuery: GET_MASTER_ATTRIBUTES
|
|
68
98
|
};
|
|
@@ -13,7 +13,7 @@ export const useShopBy = props => {
|
|
|
13
13
|
const { value: sortby } = currentSort
|
|
14
14
|
|
|
15
15
|
const operations = mergeOperations(DEFAULT_OPERATIONS, null);
|
|
16
|
-
const { getStoreConfigData, getShopByDataQuery, getCategoryContentQuery, getFilterInputsQuery } = operations;
|
|
16
|
+
const { getStoreConfigData, getShopByDataQuery, getCategoryContentQuery, getFilterInputsQuery, getProductFiltersByCategoryQuery, getMasterAttributesQuery } = operations;
|
|
17
17
|
const { pathname, search } = useLocation();
|
|
18
18
|
// const [
|
|
19
19
|
// ,
|
|
@@ -22,10 +22,18 @@ export const useShopBy = props => {
|
|
|
22
22
|
// }
|
|
23
23
|
// ] = useAppContext();
|
|
24
24
|
|
|
25
|
-
const [runQuery, {data: queryResponse, loading, error}] = useLazyQuery(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const [runQuery, { data: queryResponse, loading, error }] = useLazyQuery(
|
|
26
|
+
getProductFiltersByCategoryQuery,
|
|
27
|
+
{
|
|
28
|
+
fetchPolicy: 'cache-and-network',
|
|
29
|
+
nextFetchPolicy: 'cache-first'
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// const [runQuery, {data: queryResponse, loading, error}] = useLazyQuery(getShopByDataQuery, {
|
|
34
|
+
// fetchPolicy: 'cache-and-network',
|
|
35
|
+
// nextFetchPolicy: 'cache-first'
|
|
36
|
+
// });
|
|
29
37
|
|
|
30
38
|
const { data: storeConfigData } = useQuery(getStoreConfigData, {
|
|
31
39
|
fetchPolicy: 'cache-and-network',
|
|
@@ -50,35 +58,8 @@ export const useShopBy = props => {
|
|
|
50
58
|
return typeMap;
|
|
51
59
|
}, [introspectionData]);
|
|
52
60
|
|
|
53
|
-
// const activeFilters = [];
|
|
54
|
-
|
|
55
|
-
// if (!filterTypeMap.size) {
|
|
56
|
-
// return;
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
61
|
const filters = getFiltersFromSearch(search);
|
|
60
62
|
|
|
61
|
-
// Construct the filter arg object.
|
|
62
|
-
// const newFilters = {};
|
|
63
|
-
// filters.forEach((values, key) => {
|
|
64
|
-
// newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
|
|
65
|
-
|
|
66
|
-
// if (key == "sc_baseball_release") {
|
|
67
|
-
// for(let item of values) {
|
|
68
|
-
// if(item) {
|
|
69
|
-
// // console.log(item.split(',')[0])
|
|
70
|
-
// const data = search.split('&');
|
|
71
|
-
// data.pop();
|
|
72
|
-
// activeFilters.push(
|
|
73
|
-
// {
|
|
74
|
-
// 'label': item.split(',')[0],
|
|
75
|
-
// 'path': data
|
|
76
|
-
// }
|
|
77
|
-
// )
|
|
78
|
-
// }
|
|
79
|
-
// }
|
|
80
|
-
// }
|
|
81
|
-
// });
|
|
82
63
|
const { newFilters, activeFilters } = useMemo(() => {
|
|
83
64
|
const resultFilters = {};
|
|
84
65
|
const resultActiveFilters = [];
|
|
@@ -105,9 +86,46 @@ export const useShopBy = props => {
|
|
|
105
86
|
return { newFilters: resultFilters, activeFilters: resultActiveFilters };
|
|
106
87
|
}, [filterTypeMap]);
|
|
107
88
|
|
|
108
|
-
|
|
89
|
+
// MASTER ATTRIBUTES
|
|
90
|
+
const {
|
|
91
|
+
called: masterAttributesCalled,
|
|
92
|
+
data: masterAttributesData,
|
|
93
|
+
loading: masterAttributesLoading
|
|
94
|
+
} = useQuery(getMasterAttributesQuery,
|
|
95
|
+
{
|
|
96
|
+
fetchPolicy: 'cache-and-network',
|
|
97
|
+
nextFetchPolicy: 'cache-first'
|
|
98
|
+
});
|
|
109
99
|
|
|
100
|
+
const masterAttributes = useMemo(() => {
|
|
101
|
+
const masterAttributes = [];
|
|
110
102
|
|
|
103
|
+
if (masterAttributesData) {
|
|
104
|
+
masterAttributesData.masterAttributes.forEach(({ attribute_code }) => {
|
|
105
|
+
masterAttributes.push(attribute_code);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return masterAttributes;
|
|
110
|
+
}, [masterAttributesData]);
|
|
111
|
+
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
|
|
114
|
+
if (!filterTypeMap.size) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const filters = getFiltersFromSearch(search);
|
|
119
|
+
|
|
120
|
+
const mainAttributes = ['card_game'];
|
|
121
|
+
|
|
122
|
+
// Construct the filter arg object.
|
|
123
|
+
const newFilters = {};
|
|
124
|
+
filters.forEach((values, key) => {
|
|
125
|
+
if (mainAttributes.includes(key)) {
|
|
126
|
+
newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
111
129
|
|
|
112
130
|
// Use the category uid for the current category page regardless of the
|
|
113
131
|
// applied filters. Follow-up in PWA-404.
|
|
@@ -115,37 +133,13 @@ export const useShopBy = props => {
|
|
|
115
133
|
|
|
116
134
|
runQuery({
|
|
117
135
|
variables: {
|
|
118
|
-
filters: newFilters
|
|
119
|
-
categoryUrlKey: categoryUrlKey,
|
|
120
|
-
attributeCode: shopby,
|
|
121
|
-
activeFilter: activeFilter,
|
|
122
|
-
search: search
|
|
136
|
+
filters: newFilters
|
|
123
137
|
}
|
|
124
138
|
});
|
|
125
139
|
}, [
|
|
126
|
-
runQuery,
|
|
127
|
-
activeFilter,
|
|
128
|
-
shopby,
|
|
129
|
-
// categoryUrlKey,
|
|
130
|
-
// filters
|
|
131
|
-
// filterTypeMap,
|
|
132
|
-
search
|
|
140
|
+
runQuery, filterTypeMap, search
|
|
133
141
|
]);
|
|
134
142
|
|
|
135
|
-
// console.log(activeFilters)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// const { error, loading, data } = useQuery(getShopByDataQuery, {
|
|
140
|
-
// fetchPolicy: 'cache-and-network',
|
|
141
|
-
// nextFetchPolicy: 'cache-first',
|
|
142
|
-
// skip: !storeConfigData,
|
|
143
|
-
// variables: {
|
|
144
|
-
// categoryUrlKey: categoryUrlKey,
|
|
145
|
-
// attributeCode: shopby
|
|
146
|
-
// }
|
|
147
|
-
// });
|
|
148
|
-
|
|
149
143
|
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'];
|
|
150
144
|
|
|
151
145
|
// const isBackgroundLoading = !!queryResponse && loading;
|
|
@@ -155,12 +149,14 @@ export const useShopBy = props => {
|
|
|
155
149
|
return null;
|
|
156
150
|
}
|
|
157
151
|
|
|
158
|
-
const rawData = queryResponse?.
|
|
152
|
+
const rawData = queryResponse?.products?.aggregations;
|
|
159
153
|
if (!rawData) {
|
|
160
154
|
return null;
|
|
161
155
|
}
|
|
156
|
+
|
|
157
|
+
let options = rawData.find(item => item.attribute_code === shopby).options;
|
|
162
158
|
|
|
163
|
-
let options = rawData[0].options;
|
|
159
|
+
// let options = rawData[0].options;
|
|
164
160
|
|
|
165
161
|
const mappingData = options.reduce((acc, item) => {
|
|
166
162
|
let firstLetter = item.label.charAt(0).toUpperCase();
|
|
@@ -181,17 +177,16 @@ export const useShopBy = props => {
|
|
|
181
177
|
}, [queryResponse, sortby]);
|
|
182
178
|
|
|
183
179
|
const filteredOptions = useMemo(() => {
|
|
184
|
-
console.log('queryResponse', queryResponse)
|
|
185
180
|
if (!queryResponse) {
|
|
186
181
|
return null;
|
|
187
182
|
}
|
|
188
183
|
|
|
189
|
-
const rawData = queryResponse?.
|
|
184
|
+
const rawData = queryResponse?.products?.aggregations;
|
|
190
185
|
if (!rawData) {
|
|
191
186
|
return null;
|
|
192
187
|
}
|
|
193
|
-
|
|
194
|
-
let options = rawData
|
|
188
|
+
|
|
189
|
+
let options = rawData.find(item => item.attribute_code === shopby).options;
|
|
195
190
|
|
|
196
191
|
// const filteredSets = [];
|
|
197
192
|
|
|
@@ -208,22 +203,10 @@ export const useShopBy = props => {
|
|
|
208
203
|
return option.label.search(new RegExp(searchQuery, "i")) != -1;
|
|
209
204
|
});
|
|
210
205
|
}
|
|
211
|
-
// } else {
|
|
212
|
-
|
|
213
|
-
// console.log(filteredOptions)
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
// }
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
// const sortbyData = [];
|
|
221
206
|
|
|
222
207
|
return options;
|
|
223
208
|
}, [queryResponse, searchQuery]);
|
|
224
209
|
|
|
225
|
-
console.log('filteredOptions',filteredOptions)
|
|
226
|
-
|
|
227
210
|
const dataResult = useMemo(() => {
|
|
228
211
|
if (filteredOptions) {
|
|
229
212
|
return filteredOptions.reduce((acc, item) => {
|
|
@@ -241,9 +224,7 @@ export const useShopBy = props => {
|
|
|
241
224
|
}
|
|
242
225
|
|
|
243
226
|
return filteredOptions;
|
|
244
|
-
}, [filteredOptions])
|
|
245
|
-
|
|
246
|
-
console.log('dataResult',dataResult)
|
|
227
|
+
}, [filteredOptions]);
|
|
247
228
|
|
|
248
229
|
let availableGroups = originalDataResult ? Object.keys(originalDataResult).sort() : [];
|
|
249
230
|
|
|
@@ -255,7 +236,7 @@ export const useShopBy = props => {
|
|
|
255
236
|
}
|
|
256
237
|
|
|
257
238
|
|
|
258
|
-
const attributeData = queryResponse?.
|
|
239
|
+
const attributeData = queryResponse?.products?.aggregations && queryResponse?.products.aggregations.length ? queryResponse.products.aggregations.find(item => item.attribute_code === shopby) : null;
|
|
259
240
|
|
|
260
241
|
const { data: categoryData, loading: categoryLoading } = useQuery(
|
|
261
242
|
getCategoryContentQuery,
|
|
@@ -274,8 +255,8 @@ export const useShopBy = props => {
|
|
|
274
255
|
return null;
|
|
275
256
|
}
|
|
276
257
|
|
|
277
|
-
return queryResponse
|
|
278
|
-
}, [queryResponse]);
|
|
258
|
+
return queryResponse.products.aggregations.find(item => item.attribute_code === shopby);
|
|
259
|
+
}, [queryResponse, shopby]);
|
|
279
260
|
|
|
280
261
|
const category =
|
|
281
262
|
categoryData && categoryData.categories.items.length
|