@riosst100/pwa-marketplace 2.6.9 → 2.7.0

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@riosst100/pwa-marketplace",
3
3
  "author": "riosst100@gmail.com",
4
- "version": "2.6.9",
4
+ "version": "2.7.0",
5
5
  "main": "src/index.js",
6
6
  "pwa-studio": {
7
7
  "targets": {
@@ -110,9 +110,7 @@ const ShopBy = props => {
110
110
 
111
111
  const talonProps = useShopBy({ activeFilter, searchQuery, active, setActive, currentSort, categoryId, shopby });
112
112
 
113
- const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category, activeFilters, pageInfo } = talonProps;
114
-
115
- console.log('dataResult SHOPBY', dataResult)
113
+ const { error, loading, dataResult, categoryUrlSuffix, categoryUrlKey, productType, filteredAvailableGroups, availableGroups, attributeData, alpha, category, pageInfo } = talonProps;
116
114
 
117
115
  if (loading) {
118
116
  return <ShopByShimmer />;
@@ -153,7 +151,7 @@ const ShopBy = props => {
153
151
 
154
152
  if (active === 'all' || active === group) {
155
153
  dataResult[group] && dataResult[group].length && dataResult[group].map((option, index) => {
156
- const { products_count, label, value } = option;
154
+ const { count, label, value } = option;
157
155
 
158
156
  const filter = attributeData.attribute_code + '[filter]=' + label + ',' + value;
159
157
  const params = filterSearch ? filterSearch + '&' + filter + additionalFilter : '?' + filter + additionalFilter;
@@ -164,7 +162,7 @@ const ShopBy = props => {
164
162
 
165
163
  optionsResult.push(<li key={index} className='list-none'>
166
164
  <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]'>({products_count})</span>
165
+ {label} <span className='text-[12px]'>({count})</span>
168
166
  </Link>
169
167
  </li>)
170
168
  });
@@ -174,8 +172,6 @@ const ShopBy = props => {
174
172
  optionsResultSplitted = splitToNChunks(optionsResult, 3);
175
173
  }
176
174
 
177
- // console.log(dataResult)
178
-
179
175
  const all = active == "all" ? (
180
176
  newAvailableGroups.length == 1 ? (
181
177
  optionsResultSplitted && optionsResultSplitted.length && optionsResultSplitted.map((data, index) => (
@@ -234,7 +230,7 @@ const ShopBy = props => {
234
230
  ];
235
231
 
236
232
  // 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.title : '';
233
+ const title = pageInfo ? pageInfo.label : '';
238
234
 
239
235
  let availableFilterOption = [];
240
236
 
@@ -283,8 +279,6 @@ const ShopBy = props => {
283
279
  ];
284
280
  }
285
281
 
286
- // console.log(category)
287
-
288
282
  if (shopby == "brands" || shopby == "product_line") {
289
283
  if (category && category?.url_path.includes('anime-figures')) {
290
284
  availableFilterOption = [
@@ -340,7 +334,32 @@ const ShopBy = props => {
340
334
  setSearchQuery('')
341
335
  }
342
336
 
343
- // console.log(category)
337
+ const activeFilters = [];
338
+
339
+ const allActiveFilters = getFiltersFromSearch(search);
340
+
341
+ if (allActiveFilters && allActiveFilters.size > 0) {
342
+ allActiveFilters.forEach((value, key) => {
343
+ value.forEach((value) => {
344
+ const filterArr = value.split(',');
345
+
346
+ const label = filterArr[0];
347
+ const optionId = filterArr[1];
348
+ if (label == "Singles") {
349
+ isSingles = true;
350
+ }
351
+ 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" || virtualCategoryFilters && virtualCategoryFilters.includes(key)) {
352
+ activeFilters.push(
353
+ {
354
+ 'label': label,
355
+ 'code': key,
356
+ 'option_id': optionId
357
+ }
358
+ )
359
+ }
360
+ })
361
+ });
362
+ }
344
363
 
345
364
  return (
346
365
  <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(getShopByDataQuery, {
26
- fetchPolicy: 'cache-and-network',
27
- nextFetchPolicy: 'cache-first'
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
- useEffect(() => {
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?.shopByData?.data;
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?.shopByData?.data;
184
+ const rawData = queryResponse?.products?.aggregations;
190
185
  if (!rawData) {
191
186
  return null;
192
187
  }
193
-
194
- let options = rawData[0].options;
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?.shopByData?.data && queryResponse?.shopByData.data.length ? queryResponse.shopByData.data[0] : null
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?.shopByData?.page_info;
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