@riosst100/pwa-marketplace 2.3.4 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@riosst100/pwa-marketplace",
3
3
  "author": "riosst100@gmail.com",
4
- "version": "2.3.4",
4
+ "version": "2.3.6",
5
5
  "main": "src/index.js",
6
6
  "pwa-studio": {
7
7
  "targets": {
@@ -5,7 +5,7 @@ import { Link } from 'react-router-dom';
5
5
 
6
6
  const FilterTopItem = props => {
7
7
  const { setFilterBy, filterBy, filterApi, group, item, onApply, labels, activeFilters, search } = props;
8
- const { removeGroup, toggleItem } = filterApi;
8
+ const { removeGroup, toggleItem, clear } = filterApi;
9
9
  const { title, value } = item;
10
10
 
11
11
  const classes = useStyle(defaultClasses, props.classes);
@@ -14,8 +14,11 @@ const FilterTopItem = props => {
14
14
 
15
15
  const handleOnchange = useCallback(
16
16
  e => {
17
+ filterApi.clear();
18
+
17
19
  if (group != "category_uid") {
18
20
  removeGroup({ group });
21
+ // clear();
19
22
  if (e === item.value) {
20
23
  toggleItem({ group, item });
21
24
  }
@@ -67,6 +67,12 @@ const ProductContent = props => {
67
67
  const shouldShowFilterButtons = filters && filters.length;
68
68
  const shouldShowFilterShimmer = filters === null;
69
69
 
70
+ // console.log('shouldShowFilterButtons')
71
+ // console.log(shouldShowFilterButtons)
72
+
73
+ // console.log('filters')
74
+ // console.log(filters)
75
+
70
76
  const sidebar = shouldShowFilterButtons ? (
71
77
  <FilterSidebar hideFilters={false} children={[]} filters={filters} allowedFilters={[]} />
72
78
  ) : shouldShowFilterShimmer ? (
@@ -168,8 +168,8 @@ const ShopBySets = props => {
168
168
  // alpha = availableGroups;
169
169
  }
170
170
 
171
- console.log('==productType')
172
- console.log(productType)
171
+ // console.log('==productType')
172
+ // console.log(productType)
173
173
 
174
174
  let title = "A2ll Sets";
175
175
  if (productType == "expansion_sets") {
@@ -2,9 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_PRODUCT_FILTERS_BY_CATEGORY = gql`
4
4
  query getProductFiltersByCategory(
5
- $categoryIdFilter: FilterEqualTypeInput!
5
+ $filters: ProductAttributeFilterInput!
6
6
  ) {
7
- products(filter: { category_uid: $categoryIdFilter }) {
7
+ products(filter: $filters) {
8
8
  aggregations {
9
9
  label
10
10
  count
@@ -89,10 +89,33 @@ export const GET_STORE_CONFIG_DATA = gql`
89
89
  }
90
90
  `;
91
91
 
92
+ export const GET_FILTER_INPUTS = gql`
93
+ query GetFilterInputsForCategory {
94
+ __type(name: "ProductAttributeFilterInput") {
95
+ inputFields {
96
+ name
97
+ type {
98
+ name
99
+ }
100
+ }
101
+ }
102
+ }
103
+ `;
104
+
105
+ export const GET_MASTER_ATTRIBUTES = gql`
106
+ query GetMasterAttributes {
107
+ masterAttributes {
108
+ attribute_code
109
+ }
110
+ }
111
+ `;
112
+
92
113
 
93
114
  export default {
94
115
  getCategoryContentQuery: GET_CATEGORY_CONTENT,
95
116
  getProductFiltersByCategoryQuery: GET_PRODUCT_FILTERS_BY_CATEGORY,
96
117
  getCategoryAvailableSortMethodsQuery: GET_CATEGORY_AVAILABLE_SORT_METHODS,
97
- getStoreConfigQuery: GET_STORE_CONFIG_DATA
118
+ getStoreConfigQuery: GET_STORE_CONFIG_DATA,
119
+ getFilterInputsQuery: GET_FILTER_INPUTS,
120
+ getMasterAttributesQuery: GET_MASTER_ATTRIBUTES
98
121
  };
@@ -107,9 +107,9 @@ export const useCategory = props => {
107
107
  loading: introspectionLoading
108
108
  } = useQuery(getFilterInputsQuery);
109
109
 
110
- console.log(introspectionCalled)
111
- console.log(introspectionLoading)
112
- console.log(introspectionData)
110
+ // console.log(introspectionCalled)
111
+ // console.log(introspectionLoading)
112
+ // console.log(introspectionData)
113
113
 
114
114
  // Create a type map we can reference later to ensure we pass valid args
115
115
  // to the graphql query.
@@ -3,8 +3,12 @@ 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
-
6
+ import { useLocation } from 'react-router-dom';
7
7
  import DEFAULT_OPERATIONS from './categoryContent.gql';
8
+ import {
9
+ getFiltersFromSearch,
10
+ getFilterInput
11
+ } from '@magento/peregrine/lib/talons/FilterModal/helpers';
8
12
 
9
13
  /**
10
14
  * Returns props necessary to render the categoryContent component.
@@ -27,7 +31,9 @@ export const useCategoryContent = props => {
27
31
  getCategoryContentQuery,
28
32
  getProductFiltersByCategoryQuery,
29
33
  getCategoryAvailableSortMethodsQuery,
30
- getStoreConfigQuery
34
+ getStoreConfigQuery,
35
+ getFilterInputsQuery,
36
+ getMasterAttributesQuery
31
37
  } = operations;
32
38
 
33
39
  const placeholderItems = Array.from({ length: pageSize }).fill(null);
@@ -72,18 +78,75 @@ export const useCategoryContent = props => {
72
78
  );
73
79
 
74
80
  const [, { dispatch }] = useEventingContext();
81
+ const { search } = useLocation();
82
+
83
+ const {
84
+ called: introspectionCalled,
85
+ data: introspectionData,
86
+ loading: introspectionLoading
87
+ } = useQuery(getFilterInputsQuery);
88
+
89
+ const filterTypeMap = useMemo(() => {
90
+ const typeMap = new Map();
91
+ if (introspectionData) {
92
+ introspectionData.__type.inputFields.forEach(({ name, type }) => {
93
+ typeMap.set(name, type.name);
94
+ });
95
+ }
96
+ return typeMap;
97
+ }, [introspectionData]);
98
+
99
+ // MASTER ATTRIBUTES
100
+ const {
101
+ called: masterAttributesCalled,
102
+ data: masterAttributesData,
103
+ loading: masterAttributesLoading
104
+ } = useQuery(getMasterAttributesQuery,
105
+ {
106
+ fetchPolicy: 'cache-and-network',
107
+ nextFetchPolicy: 'cache-first'
108
+ });
109
+
110
+ const masterAttributes = useMemo(() => {
111
+ const masterAttributes = [];
112
+
113
+ if (masterAttributesData) {
114
+ masterAttributesData.masterAttributes.forEach(({ attribute_code }) => {
115
+ masterAttributes.push(attribute_code);
116
+ });
117
+ }
118
+
119
+ return masterAttributes;
120
+ }, [masterAttributesData]);
121
+
75
122
 
76
123
  useEffect(() => {
77
124
  if (categoryId) {
125
+
126
+ // categoryIdFilter: {
127
+ // eq: categoryId
128
+ // }
129
+ if (!filterTypeMap.size) {
130
+ return;
131
+ }
132
+
133
+ const filters = getFiltersFromSearch(search);
134
+
135
+ // Construct the filter arg object.
136
+ const newFilters = {};
137
+ filters.forEach((values, key) => {
138
+ if (masterAttributes.includes(key)) {
139
+ newFilters[key] = getFilterInput(values, filterTypeMap.get(key));
140
+ }
141
+ });
142
+
78
143
  getFilters({
79
144
  variables: {
80
- categoryIdFilter: {
81
- eq: categoryId
82
- }
145
+ filters: newFilters
83
146
  }
84
147
  });
85
148
  }
86
- }, [categoryId, getFilters]);
149
+ }, [categoryId, getFilters, filterTypeMap, search, masterAttributes]);
87
150
 
88
151
  useEffect(() => {
89
152
  if (categoryId) {
@@ -97,6 +160,9 @@ export const useCategoryContent = props => {
97
160
  }
98
161
  }, [categoryId, getSortMethods]);
99
162
 
163
+ // console.log('filterData')
164
+ // console.log(filterData)
165
+
100
166
  const rawFilters = filterData ? filterData.products.aggregations : null;
101
167
  const items = data ? data.products.items : placeholderItems;
102
168
  const category =
@@ -110,8 +176,14 @@ export const useCategoryContent = props => {
110
176
 
111
177
  const filters = [];
112
178
 
179
+ // console.log('rawFilters')
180
+ // console.log(rawFilters)
181
+
113
182
  rawFilters && rawFilters.map((filter, index) => {
114
183
 
184
+ // console.log('filter')
185
+ // console.log(filter)
186
+
115
187
  const filterOptions = [];
116
188
  let label = filter.label;
117
189
  if (filter.attribute_code == "category_uid") {
@@ -57,8 +57,6 @@ const CategoryContent = props => {
57
57
 
58
58
  const history = useHistory();
59
59
 
60
- console.log("categoryId: "+categoryId)
61
-
62
60
  const talonProps = useCategoryContent({
63
61
  categoryId,
64
62
  data,
@@ -165,6 +163,12 @@ const CategoryContent = props => {
165
163
  <FilterModal filters={filters} />
166
164
  ) : null;
167
165
 
166
+ // console.log('filters')
167
+ // console.log(filters)
168
+
169
+ // console.log('shouldShowFilterButtons')
170
+ // console.log(shouldShowFilterButtons)
171
+
168
172
  const sidebar = shouldShowFilterButtons ? (
169
173
  <FilterSidebar hideFilters={category && category.hide_filters ? true : false} children={children} filters={filters} allowedFilters={category ? category.allowed_filters : []} />
170
174
  ) : shouldShowFilterShimmer ? (
@@ -15,10 +15,14 @@ import { useFieldApi } from 'informed';
15
15
  import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
16
16
 
17
17
  const FilterItemRadioGroup = props => {
18
- const { filterApi, filterState, group, items, onApply, labels } = props;
18
+ const { filterApi, filterState, group, items, onApply, labels,isListExpanded = true, itemCountToShow = 5 } = props;
19
19
 
20
20
  const radioItems = useMemo(() => {
21
- return items.map(item => {
21
+ return items.map((item,index) => {
22
+ if (!isListExpanded && index >= itemCountToShow) {
23
+ return null;
24
+ }
25
+
22
26
  const code = `item-${group}-${item.value}`;
23
27
  return (
24
28
  <FilterItemRadio
@@ -32,7 +36,7 @@ const FilterItemRadioGroup = props => {
32
36
  />
33
37
  );
34
38
  });
35
- }, [filterApi, filterState, group, items, labels, onApply]);
39
+ }, [filterApi, filterState, group, items, labels, onApply,isListExpanded,itemCountToShow]);
36
40
 
37
41
  const fieldValue = useMemo(() => {
38
42
  if (filterState) {
@@ -103,6 +103,7 @@ const FilterList = props => {
103
103
  // search value is not referenced, so this array is stable
104
104
  const itemElements = useMemo(() => {
105
105
  // if (filterFrontendInput === 'boolean') {
106
+
106
107
  const key = `item-${group}`;
107
108
  return (
108
109
  <li
@@ -118,6 +119,8 @@ const FilterList = props => {
118
119
  items={items}
119
120
  onApply={onApply}
120
121
  labels={labels}
122
+ isListExpanded={isListExpanded}
123
+ itemCountToShow={itemCountToShow}
121
124
  />
122
125
  </li>
123
126
  );
@@ -33,6 +33,12 @@ const FilterSidebar = props => {
33
33
  handleReset
34
34
  } = talonProps;
35
35
 
36
+ // console.log('RIO')
37
+ // console.log('filters')
38
+ // console.log(filters)
39
+ // console.log('filterCountToOpen'+filterCountToOpen)
40
+ // console.log('hideFilters'+hideFilters)
41
+
36
42
  const filterRef = useRef();
37
43
  const classes = useStyle(defaultClasses, props.classes);
38
44
 
@@ -80,9 +86,9 @@ const FilterSidebar = props => {
80
86
 
81
87
  const allowedFiltersArr = [];
82
88
 
83
- // allowedFilters?.length && allowedFilters.map((val, index) => {
84
- // allowedFiltersArr.push(val.code);
85
- // });
89
+ allowedFilters?.length && allowedFilters.map((val, index) => {
90
+ allowedFiltersArr.push(val.code);
91
+ });
86
92
 
87
93
  const filtersList = useMemo(
88
94
  () =>
@@ -92,24 +98,26 @@ const FilterSidebar = props => {
92
98
  const frontendInput = filterFrontendInput.get(group);
93
99
 
94
100
  const hideFilters = ['trains','trains_locomotives','trains_supplies_type','lof_preorder','auction','special_price','sc_baseball_inserts','sc_baseball_parallel','sale','sc_set_type','sc_brands'];
95
- if (!hideFilters.includes(group) && groupName) {
101
+ if (!allowedFiltersArr?.length || filterState.size && allowedFiltersArr.length || !filterState.size && allowedFiltersArr.length && allowedFiltersArr.includes(group)) {
102
+ if (!hideFilters.includes(group) && groupName) {
96
103
 
97
- // if (!allowedFiltersArr?.length && group != "category_uid" || allowedFiltersArr?.length && allowedFiltersArr.includes(group)) {
98
-
99
-
100
- return (
101
- <FilterBlock
102
- key={group}
103
- filterApi={filterApi}
104
- filterState={blockState}
105
- filterFrontendInput={frontendInput}
106
- group={group}
107
- items={items}
108
- name={groupName}
109
- onApply={group == "category_uid" ? handleCategoryApplyFilter : handleApplyFilter}
110
- initialOpen={true}
111
- />
112
- );
104
+ // if (!allowedFiltersArr?.length && group != "category_uid" || allowedFiltersArr?.length && allowedFiltersArr.includes(group)) {
105
+
106
+
107
+ return (
108
+ <FilterBlock
109
+ key={group}
110
+ filterApi={filterApi}
111
+ filterState={blockState}
112
+ filterFrontendInput={frontendInput}
113
+ group={group}
114
+ items={items}
115
+ name={groupName}
116
+ onApply={group == "category_uid" ? handleCategoryApplyFilter : handleApplyFilter}
117
+ initialOpen={true}
118
+ />
119
+ );
120
+ }
113
121
  }
114
122
  }),
115
123
  [
@@ -91,8 +91,8 @@ export const useCollectibleGameSets = props => {
91
91
  // const availableReleaseYears = collectibleGameSets && collectibleGameSets.length ? collectibleGameSets.map(({ data }) => data.release_year) : [];
92
92
  const availableReleaseYears = [];
93
93
 
94
- console.log('collectibleGameSets')
95
- console.log(collectibleGameSets)
94
+ // console.log('collectibleGameSets')
95
+ // console.log(collectibleGameSets)
96
96
 
97
97
  const filteredCollectibleGameSets = useMemo(() => {
98
98
  if (!collectibleGameSets) {
@@ -89,8 +89,8 @@ export const useProductContent = props => {
89
89
  }
90
90
  }, [sellerId, getSortMethods]);
91
91
 
92
- console.log('data')
93
- console.log(data)
92
+ // console.log('data')
93
+ // console.log(data)
94
94
 
95
95
  const rawFilters = filterData ? filterData.products.aggregations : null;
96
96
  const items = data ? data.items : placeholderItems;
@@ -76,9 +76,9 @@ export const useSellerProducts = props => {
76
76
  data
77
77
  } = queryResponse;
78
78
 
79
- console.log('===data===')
80
- console.log(data)
81
- console.log('======')
79
+ // console.log('===data===')
80
+ // console.log(data)
81
+ // console.log('======')
82
82
 
83
83
  const {
84
84
  called: categoryCalled,
@@ -154,8 +154,8 @@ export const useSellerProducts = props => {
154
154
 
155
155
  // Run the category query immediately and whenever its variable values change.
156
156
  useEffect(() => {
157
- console.log('=categoryData=')
158
- console.log(categoryData)
157
+ // console.log('=categoryData=')
158
+ // console.log(categoryData)
159
159
  if (!categoryData) {
160
160
  return;
161
161
  }
@@ -167,8 +167,8 @@ export const useSetsData = props => {
167
167
  // availableYears = availableYears && availableYears.length ? availableYears.slice().sort((a, b) =>a.group.toLowerCase().localeCompare(b.group.toLowerCase())) : [];
168
168
  // const groupByYears = setsData && setsData.length ? setsData.map(({ group,release_year }) => release_year) : [];
169
169
 
170
- console.log('availableYears')
171
- console.log(availableYears)
170
+ // console.log('availableYears')
171
+ // console.log(availableYears)
172
172
 
173
173
  // const availableLeagues = setsData && setsData.length ? setsData.map(({ sets }) => setsData.map(({ sc_league }) => sc_league)) : [];
174
174
  // console.log(availableLeagues)