@riosst100/pwa-marketplace 2.3.8 → 2.4.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 +1 -1
- package/src/componentOverrideMapping.js +2 -0
- package/src/components/ProductContent/productContent.js +0 -1
- package/src/overwrites/peregrine/lib/talons/FilterModal/filterModal.gql.js +31 -0
- package/src/overwrites/peregrine/lib/talons/FilterModal/useFilterList.js +2 -4
- package/src/overwrites/peregrine/lib/talons/FilterSidebar/useFilterSidebar.js +41 -4
- package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/filterItemRadio.js +2 -1
- package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/filterItemRadioGroup.js +51 -13
- package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/filterList.js +57 -1
- package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/filterList.module.css +9 -0
- package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/subFilterItemRadio.module.css +0 -0
- package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/subFilterItemRadioGroup.js +91 -0
- package/src/overwrites/venia-ui/lib/components/FilterModal/filterBlock.js +12 -2
- package/src/overwrites/venia-ui/lib/components/FilterModal/filterModal.js +1 -0
- package/src/overwrites/venia-ui/lib/components/FilterSidebar/filterSidebar.js +27 -1
- package/src/overwrites/venia-ui/lib/components/RadioGroup/radioGroup.js +77 -0
- package/src/overwrites/venia-ui/lib/components/RadioGroup/radioGroup.module.css +30 -0
package/package.json
CHANGED
|
@@ -14,6 +14,7 @@ module.exports = componentOverrideMapping = {
|
|
|
14
14
|
[`@magento/peregrine/lib/talons/SignIn/useSignIn.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/SignIn/useSignIn.js',
|
|
15
15
|
[`@magento/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js',
|
|
16
16
|
[`@magento/peregrine/lib/talons/MegaMenu/megaMenu.gql.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/MegaMenu/megaMenu.gql.js',
|
|
17
|
+
[`@magento/peregrine/lib/talons/FilterModal/filterModal.gql.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/FilterModal/filterModal.gql.js',
|
|
17
18
|
[`@magento/peregrine/lib/talons/RootComponents/Product/productDetailFragment.gql.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/RootComponents/Product/productDetailFragment.gql.js',
|
|
18
19
|
[`@magento/peregrine/lib/talons/RootComponents/Product/useProduct.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/RootComponents/Product/useProduct.js',
|
|
19
20
|
[`@magento/peregrine/lib/talons/ProductFullDetail/useProductFullDetail.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/ProductFullDetail/useProductFullDetail.js',
|
|
@@ -43,6 +44,7 @@ module.exports = componentOverrideMapping = {
|
|
|
43
44
|
[`@magento/venia-ui/lib/components/QuantityStepper/index.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/QuantityStepper/index.js',
|
|
44
45
|
// [`@magento/venia-ui/lib/components/RichContent/index.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/RichContent/index.js',
|
|
45
46
|
[`@magento/venia-ui/lib/components/RadioGroup/radio.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/RadioGroup/radio.js',
|
|
47
|
+
[`@magento/venia-ui/lib/components/RadioGroup/radioGroup.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/RadioGroup/radioGroup.js',
|
|
46
48
|
[`@magento/venia-ui/lib/components/Button/index.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/Button/index.js',
|
|
47
49
|
[`@magento/venia-ui/lib/components/RichText/index.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/RichText/index.js',
|
|
48
50
|
[`@magento/venia-ui/lib/components/Main/index.js`]: '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/Main/index.js',
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const GET_FILTER_INPUTS = gql`
|
|
4
|
+
query GetFilterInputsForModal {
|
|
5
|
+
__type(name: "ProductAttributeFilterInput") {
|
|
6
|
+
inputFields {
|
|
7
|
+
name
|
|
8
|
+
type {
|
|
9
|
+
name
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
export const GET_SUB_FILTERS = gql`
|
|
17
|
+
query GetSubFilters {
|
|
18
|
+
subFilters {
|
|
19
|
+
attribute_code
|
|
20
|
+
options {
|
|
21
|
+
option_label
|
|
22
|
+
sub_option_labels
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
getFilterInputsQuery: GET_FILTER_INPUTS,
|
|
30
|
+
getSubFiltersQuery: GET_SUB_FILTERS
|
|
31
|
+
};
|
|
@@ -10,9 +10,7 @@ export const useFilterList = props => {
|
|
|
10
10
|
() =>
|
|
11
11
|
items.some((item, index) => {
|
|
12
12
|
return (
|
|
13
|
-
filterState &&
|
|
14
|
-
filterState.has(item) &&
|
|
15
|
-
index >= itemCountToShow
|
|
13
|
+
filterState && filterState.has(item) && index >= itemCountToShow
|
|
16
14
|
);
|
|
17
15
|
}),
|
|
18
16
|
[filterState, itemCountToShow, items]
|
|
@@ -46,7 +44,7 @@ export const useFilterList = props => {
|
|
|
46
44
|
if (!overlay) {
|
|
47
45
|
setActiveFilter(false)
|
|
48
46
|
}
|
|
49
|
-
}, [overlay])
|
|
47
|
+
}, [overlay]);
|
|
50
48
|
|
|
51
49
|
// const handleShowMore = useCallback(() => {
|
|
52
50
|
// handleShowAllOptions();
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
sortFiltersArray,
|
|
13
13
|
stripHtml
|
|
14
14
|
} from '@magento/peregrine/lib/talons/FilterModal/helpers';
|
|
15
|
-
|
|
15
|
+
import { getFiltersFromSearch } from '@magento/peregrine/lib/talons/FilterModal/helpers';
|
|
16
16
|
import DEFAULT_OPERATIONS from '@magento/peregrine/lib/talons/FilterModal/filterModal.gql';
|
|
17
17
|
|
|
18
18
|
const DRAWER_NAME = 'filter';
|
|
@@ -21,7 +21,7 @@ export const useFilterSidebar = props => {
|
|
|
21
21
|
const { filters } = props;
|
|
22
22
|
|
|
23
23
|
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
24
|
-
const { getFilterInputsQuery } = operations;
|
|
24
|
+
const { getFilterInputsQuery, getSubFiltersQuery } = operations;
|
|
25
25
|
|
|
26
26
|
const [isApplying, setIsApplying] = useState(false);
|
|
27
27
|
const [{ drawer }, { toggleDrawer, closeDrawer }] = useAppContext();
|
|
@@ -32,8 +32,20 @@ export const useFilterSidebar = props => {
|
|
|
32
32
|
const history = useHistory();
|
|
33
33
|
const { pathname, search } = useLocation();
|
|
34
34
|
|
|
35
|
+
const allActiveFilters = getFiltersFromSearch(search);
|
|
36
|
+
|
|
35
37
|
const { data: introspectionData } = useQuery(getFilterInputsQuery);
|
|
36
38
|
|
|
39
|
+
const {
|
|
40
|
+
called: subFilterItemsCalled,
|
|
41
|
+
data: subFilterItems,
|
|
42
|
+
loading: subFilterItemsLoading
|
|
43
|
+
} = useQuery(getSubFiltersQuery,
|
|
44
|
+
{
|
|
45
|
+
fetchPolicy: 'cache-and-network',
|
|
46
|
+
nextFetchPolicy: 'cache-first'
|
|
47
|
+
});
|
|
48
|
+
|
|
37
49
|
const attributeCodes = useMemo(
|
|
38
50
|
() => filters.map(({ attribute_code }) => attribute_code),
|
|
39
51
|
[filters]
|
|
@@ -236,10 +248,34 @@ export const useFilterSidebar = props => {
|
|
|
236
248
|
closeDrawer();
|
|
237
249
|
}, [closeDrawer]);
|
|
238
250
|
|
|
239
|
-
const handleApply = useCallback(() => {
|
|
251
|
+
const handleApply = useCallback((...args) => {
|
|
252
|
+
const group = args[0];
|
|
253
|
+
const item = args[1];
|
|
254
|
+
|
|
255
|
+
// REMOVE ACTIVE FILTER
|
|
256
|
+
if (group.includes('card_release')) {
|
|
257
|
+
const subFilter = group.replace("card_release", "card_set");
|
|
258
|
+
filterApi.removeGroup({ group: subFilter });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (group.includes('card_set')) {
|
|
262
|
+
const subFilter = group.replace("card_set", "card_release");
|
|
263
|
+
filterApi.removeGroup({ group: subFilter });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (group.includes('card_game')) {
|
|
267
|
+
if (allActiveFilters && allActiveFilters.size > 0) {
|
|
268
|
+
allActiveFilters.forEach((value, key) => {
|
|
269
|
+
if (key !== 'card_game') {
|
|
270
|
+
filterApi.removeGroup({ group: key });
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
240
276
|
setIsApplying(true);
|
|
241
277
|
handleClose();
|
|
242
|
-
}, [handleClose]);
|
|
278
|
+
}, [handleClose, filterApi, allActiveFilters]);
|
|
243
279
|
|
|
244
280
|
const handleReset = useCallback(() => {
|
|
245
281
|
filterApi.clear();
|
|
@@ -298,6 +334,7 @@ export const useFilterSidebar = props => {
|
|
|
298
334
|
filterApi,
|
|
299
335
|
filterItems,
|
|
300
336
|
filterKeys,
|
|
337
|
+
subFilterItems,
|
|
301
338
|
filterNames,
|
|
302
339
|
filterFrontendInput,
|
|
303
340
|
filterState,
|
|
@@ -6,7 +6,7 @@ import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
|
6
6
|
import { useIntl } from 'react-intl';
|
|
7
7
|
|
|
8
8
|
const FilterItemRadio = props => {
|
|
9
|
-
const { filterApi, group, item, onApply, labels } = props;
|
|
9
|
+
const { filterApi, group, item, isSubFilter, onApply, labels } = props;
|
|
10
10
|
const { removeGroup, toggleItem } = filterApi;
|
|
11
11
|
const { title, value } = item;
|
|
12
12
|
const classes = useStyle(defaultClasses);
|
|
@@ -44,6 +44,7 @@ const FilterItemRadio = props => {
|
|
|
44
44
|
classes={classes}
|
|
45
45
|
id={`item-${group}-${value}`}
|
|
46
46
|
label={title}
|
|
47
|
+
isSubFilter={isSubFilter}
|
|
47
48
|
value={value}
|
|
48
49
|
onChange={handleOnchange}
|
|
49
50
|
data-cy="FilterDefault-radio"
|
package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/filterItemRadioGroup.js
CHANGED
|
@@ -13,10 +13,10 @@ import RadioGroup from '@magento/venia-ui/lib/components/RadioGroup';
|
|
|
13
13
|
import FilterItemRadio from './filterItemRadio';
|
|
14
14
|
import { useFieldApi } from 'informed';
|
|
15
15
|
import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
|
|
16
|
+
import FilterBlock from '@riosst100/pwa-marketplace/src/overwrites/venia-ui/lib/components/FilterModal/filterBlock';
|
|
16
17
|
|
|
17
18
|
const FilterItemRadioGroup = props => {
|
|
18
|
-
const { filterApi, filterState, group, items, onApply, labels,isListExpanded = true, itemCountToShow = 5 } = props;
|
|
19
|
-
|
|
19
|
+
const { filterApi, subFilterItems, allowedSubFilters, subFilter, filterState, group, isSubFilter, items, onApply, labels,isListExpanded = true, itemCountToShow = 5 } = props;
|
|
20
20
|
const radioItems = useMemo(() => {
|
|
21
21
|
return items.map((item,index) => {
|
|
22
22
|
if (!isListExpanded && index >= itemCountToShow) {
|
|
@@ -24,19 +24,57 @@ const FilterItemRadioGroup = props => {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const code = `item-${group}-${item.value}`;
|
|
27
|
+
|
|
28
|
+
if (allowedSubFilters.length && !allowedSubFilters.includes(item.title)) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let newAllowedSubFilters = [];
|
|
33
|
+
|
|
34
|
+
if (subFilter && subFilterItems) {
|
|
35
|
+
const result = subFilterItems.find(item => item.attribute_code === "card_release");
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// Ambil options jika ditemukan
|
|
40
|
+
const options = result ? result.options : [];
|
|
41
|
+
const option = options ? options.find(option => option.option_label === item.title) : [];
|
|
42
|
+
if (option) {
|
|
43
|
+
newAllowedSubFilters = option.sub_option_labels;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
27
48
|
return (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
<>
|
|
50
|
+
<FilterItemRadio
|
|
51
|
+
key={code}
|
|
52
|
+
filterApi={filterApi}
|
|
53
|
+
filterState={filterState}
|
|
54
|
+
group={group}
|
|
55
|
+
item={item}
|
|
56
|
+
onApply={onApply}
|
|
57
|
+
labels={labels}
|
|
58
|
+
/>
|
|
59
|
+
{subFilter && <FilterBlock
|
|
60
|
+
key={subFilter.key}
|
|
61
|
+
filterApi={subFilter.filterApi}
|
|
62
|
+
filterState={subFilter.filterState}
|
|
63
|
+
filterFrontendInput={subFilter.filterFrontendInput}
|
|
64
|
+
group={subFilter.group}
|
|
65
|
+
allowedSubFilters={newAllowedSubFilters}
|
|
66
|
+
subFilterItems={subFilterItems}
|
|
67
|
+
isSubFilter={true}
|
|
68
|
+
items={subFilter.items}
|
|
69
|
+
name={''}
|
|
70
|
+
onApply={subFilter.onApply}
|
|
71
|
+
initialOpen={true}
|
|
72
|
+
/>}
|
|
73
|
+
{/* {subFilterBlock} */}
|
|
74
|
+
</>
|
|
37
75
|
);
|
|
38
76
|
});
|
|
39
|
-
}, [filterApi, filterState, group, items, labels, onApply,isListExpanded,itemCountToShow]);
|
|
77
|
+
}, [filterApi, allowedSubFilters, subFilter, filterState, group, items, labels, onApply,isListExpanded,itemCountToShow]);
|
|
40
78
|
|
|
41
79
|
const fieldValue = useMemo(() => {
|
|
42
80
|
if (filterState) {
|
|
@@ -61,7 +99,7 @@ const FilterItemRadioGroup = props => {
|
|
|
61
99
|
}, [field, fieldApi, fieldState.value, fieldValue]);
|
|
62
100
|
|
|
63
101
|
return (
|
|
64
|
-
<RadioGroup field={field} data-cy="FilterDefault-radioGroup">
|
|
102
|
+
<RadioGroup isSubFilter={isSubFilter} field={field} data-cy="FilterDefault-radioGroup">
|
|
65
103
|
{radioItems}
|
|
66
104
|
</RadioGroup>
|
|
67
105
|
);
|
|
@@ -8,6 +8,7 @@ import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
|
8
8
|
import FilterItem from './filterItem';
|
|
9
9
|
import defaultClasses from './filterList.module.css';
|
|
10
10
|
import FilterItemRadioGroup from './filterItemRadioGroup';
|
|
11
|
+
import SubFilterItemRadioGroup from './subFilterItemRadioGroup';
|
|
11
12
|
|
|
12
13
|
const labels = new WeakMap();
|
|
13
14
|
const labels2 = new WeakMap();
|
|
@@ -19,6 +20,11 @@ const FilterList = props => {
|
|
|
19
20
|
filterApi,
|
|
20
21
|
filterState,
|
|
21
22
|
filterFrontendInput,
|
|
23
|
+
isSubFilter,
|
|
24
|
+
filterItems,
|
|
25
|
+
subFilterItems,
|
|
26
|
+
allowedSubFilters,
|
|
27
|
+
subFilter,
|
|
22
28
|
name,
|
|
23
29
|
group,
|
|
24
30
|
itemCountToShow,
|
|
@@ -99,12 +105,58 @@ const FilterList = props => {
|
|
|
99
105
|
onApply
|
|
100
106
|
]);
|
|
101
107
|
|
|
108
|
+
// const subFilter = useMemo(
|
|
109
|
+
// () =>
|
|
110
|
+
// Array.from(filterItems, ([group, items], iteration) => {
|
|
111
|
+
// // const blockState = filterState.get(group);
|
|
112
|
+
// // const groupName = filterNames.get(group);
|
|
113
|
+
// // const frontendInput = filterFrontendInput.get(group);
|
|
114
|
+
|
|
115
|
+
// if (group.includes('card_set')) {
|
|
116
|
+
// return (
|
|
117
|
+
// // <FilterBlock
|
|
118
|
+
// // key={group}
|
|
119
|
+
// // filterApi={filterApi}
|
|
120
|
+
// // filterState={blockState}
|
|
121
|
+
// // filterFrontendInput={frontendInput}
|
|
122
|
+
// // group={group}
|
|
123
|
+
// // filterItems={filterItems}
|
|
124
|
+
// // items={items}
|
|
125
|
+
// // name={groupName}
|
|
126
|
+
// // onApply={group == "category_uid" ? handleCategoryApplyFilter : handleApplyFilter}
|
|
127
|
+
// // initialOpen={true}
|
|
128
|
+
// // />
|
|
129
|
+
// <SubFilterItemRadioGroup
|
|
130
|
+
// filterApi={filterApi}
|
|
131
|
+
// filterState={filterState}
|
|
132
|
+
// group={group}
|
|
133
|
+
// name={'Set Name'}
|
|
134
|
+
// items={items}
|
|
135
|
+
// onApply={onApply}
|
|
136
|
+
// labels={labels}
|
|
137
|
+
// isListExpanded={isListExpanded}
|
|
138
|
+
// itemCountToShow={itemCountToShow}
|
|
139
|
+
// />
|
|
140
|
+
// );
|
|
141
|
+
// }
|
|
142
|
+
// }),
|
|
143
|
+
// [
|
|
144
|
+
// filterApi,
|
|
145
|
+
// filterItems
|
|
146
|
+
// ]
|
|
147
|
+
// );
|
|
148
|
+
|
|
102
149
|
// memoize item creation
|
|
103
150
|
// search value is not referenced, so this array is stable
|
|
104
151
|
const itemElements = useMemo(() => {
|
|
105
152
|
// if (filterFrontendInput === 'boolean') {
|
|
106
153
|
|
|
107
154
|
const key = `item-${group}`;
|
|
155
|
+
|
|
156
|
+
const cardSetGroup = group.replace('card_release', 'card_set');
|
|
157
|
+
|
|
158
|
+
// const mewSubFilterBlock = subFilterBlock;
|
|
159
|
+
|
|
108
160
|
return (
|
|
109
161
|
<li
|
|
110
162
|
key={key}
|
|
@@ -116,6 +168,10 @@ const FilterList = props => {
|
|
|
116
168
|
filterState={filterState}
|
|
117
169
|
group={group}
|
|
118
170
|
name={name}
|
|
171
|
+
subFilterItems={subFilterItems}
|
|
172
|
+
subFilter={subFilter}
|
|
173
|
+
allowedSubFilters={allowedSubFilters}
|
|
174
|
+
isSubFilter={isSubFilter}
|
|
119
175
|
items={items}
|
|
120
176
|
onApply={onApply}
|
|
121
177
|
labels={labels}
|
|
@@ -235,7 +291,7 @@ const FilterList = props => {
|
|
|
235
291
|
|
|
236
292
|
return (
|
|
237
293
|
<Fragment>
|
|
238
|
-
<ul className={classes.items}>
|
|
294
|
+
<ul className={isSubFilter ? classes.sub_items : classes.items}>
|
|
239
295
|
{itemElements}
|
|
240
296
|
{showMoreItem}
|
|
241
297
|
</ul>
|
|
@@ -8,6 +8,15 @@
|
|
|
8
8
|
composes: border-gray-100 from global;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
.sub_items {
|
|
12
|
+
composes: gap-[15px] from global;
|
|
13
|
+
composes: grid from global;
|
|
14
|
+
/* composes: -ml-1.5 from global; */
|
|
15
|
+
composes: py-2.5 from global;
|
|
16
|
+
grid-template-columns: 100%;
|
|
17
|
+
composes: border-gray-100 from global;
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
.showMoreLessItem {
|
|
12
21
|
composes: pl-1 from global;
|
|
13
22
|
}
|
package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/subFilterItemRadio.module.css
ADDED
|
File without changes
|
package/src/overwrites/venia-ui/lib/components/FilterModal/FilterList/subFilterItemRadioGroup.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React, { useMemo, useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
arrayOf,
|
|
4
|
+
func,
|
|
5
|
+
number,
|
|
6
|
+
oneOfType,
|
|
7
|
+
shape,
|
|
8
|
+
string,
|
|
9
|
+
instanceOf
|
|
10
|
+
} from 'prop-types';
|
|
11
|
+
import setValidator from '@magento/peregrine/lib/validators/set';
|
|
12
|
+
import RadioGroup from '@magento/venia-ui/lib/components/RadioGroup';
|
|
13
|
+
import FilterItemRadio from './filterItemRadio';
|
|
14
|
+
import { useFieldApi } from 'informed';
|
|
15
|
+
import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
|
|
16
|
+
|
|
17
|
+
const SubFilterItemRadioGroup = props => {
|
|
18
|
+
const { filterApi, filterState, group, items, onApply, labels,isListExpanded = true, itemCountToShow = 5 } = props;
|
|
19
|
+
|
|
20
|
+
const radioItems = useMemo(() => {
|
|
21
|
+
return items.map((item,index) => {
|
|
22
|
+
if (!isListExpanded && index >= itemCountToShow) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const code = `item-${group}-${item.value}`;
|
|
27
|
+
return (
|
|
28
|
+
<FilterItemRadio
|
|
29
|
+
key={code}
|
|
30
|
+
filterApi={filterApi}
|
|
31
|
+
filterState={filterState}
|
|
32
|
+
group={group}
|
|
33
|
+
item={item}
|
|
34
|
+
onApply={onApply}
|
|
35
|
+
labels={labels}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
}, [filterApi, filterState, group, items, labels, onApply,isListExpanded,itemCountToShow]);
|
|
40
|
+
|
|
41
|
+
const fieldValue = useMemo(() => {
|
|
42
|
+
if (filterState) {
|
|
43
|
+
for (const item of items) {
|
|
44
|
+
if (filterState.has(item)) {
|
|
45
|
+
return item.value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
}, [filterState, items]);
|
|
52
|
+
const field = `item-${group}`;
|
|
53
|
+
const fieldApi = useFieldApi(field);
|
|
54
|
+
const fieldState = useFieldState(field);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (field && fieldValue === null) {
|
|
57
|
+
fieldApi.reset();
|
|
58
|
+
} else if (field && fieldValue !== fieldState.value) {
|
|
59
|
+
fieldApi.setValue(fieldValue);
|
|
60
|
+
}
|
|
61
|
+
}, [field, fieldApi, fieldState.value, fieldValue]);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<RadioGroup isSubFilter={true} field={field} data-cy="FilterDefault-radioGroup">
|
|
65
|
+
{radioItems}
|
|
66
|
+
</RadioGroup>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
SubFilterItemRadioGroup.defaultProps = {
|
|
71
|
+
onApply: null
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
SubFilterItemRadioGroup.propTypes = {
|
|
75
|
+
filterApi: shape({
|
|
76
|
+
toggleItem: func.isRequired
|
|
77
|
+
}).isRequired,
|
|
78
|
+
filterState: setValidator,
|
|
79
|
+
group: string.isRequired,
|
|
80
|
+
items: arrayOf(
|
|
81
|
+
shape({
|
|
82
|
+
title: string.isRequired,
|
|
83
|
+
value: oneOfType([number, string]).isRequired,
|
|
84
|
+
path: string
|
|
85
|
+
})
|
|
86
|
+
).isRequired,
|
|
87
|
+
onApply: func,
|
|
88
|
+
labels: instanceOf(Map).isRequired
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default SubFilterItemRadioGroup;
|
|
@@ -19,6 +19,11 @@ const FilterBlock = props => {
|
|
|
19
19
|
filterApi,
|
|
20
20
|
filterState,
|
|
21
21
|
filterFrontendInput,
|
|
22
|
+
filterItems,
|
|
23
|
+
subFilter,
|
|
24
|
+
subFilterItems,
|
|
25
|
+
allowedSubFilters,
|
|
26
|
+
isSubFilter,
|
|
22
27
|
group,
|
|
23
28
|
items,
|
|
24
29
|
name,
|
|
@@ -72,6 +77,11 @@ const FilterBlock = props => {
|
|
|
72
77
|
filterApi={filterApi}
|
|
73
78
|
filterState={filterState}
|
|
74
79
|
name={name}
|
|
80
|
+
isSubFilter={isSubFilter}
|
|
81
|
+
subFilter={subFilter}
|
|
82
|
+
allowedSubFilters={allowedSubFilters}
|
|
83
|
+
filterItems={filterItems}
|
|
84
|
+
subFilterItems={subFilterItems}
|
|
75
85
|
filterFrontendInput={filterFrontendInput}
|
|
76
86
|
group={group}
|
|
77
87
|
items={items}
|
|
@@ -86,7 +96,7 @@ const FilterBlock = props => {
|
|
|
86
96
|
aria-label={itemAriaLabel}
|
|
87
97
|
data-cy="FilterBlock-root"
|
|
88
98
|
>
|
|
89
|
-
<button
|
|
99
|
+
{name && <button
|
|
90
100
|
className={classes.trigger}
|
|
91
101
|
onClick={handleClick}
|
|
92
102
|
data-cy="FilterBlock-triggerButton"
|
|
@@ -103,7 +113,7 @@ const FilterBlock = props => {
|
|
|
103
113
|
variant="Outline"
|
|
104
114
|
/>
|
|
105
115
|
</span>
|
|
106
|
-
</button>
|
|
116
|
+
</button>}
|
|
107
117
|
{list}
|
|
108
118
|
</li>
|
|
109
119
|
);
|
|
@@ -28,6 +28,7 @@ const FilterSidebar = props => {
|
|
|
28
28
|
filterItems,
|
|
29
29
|
filterNames,
|
|
30
30
|
filterFrontendInput,
|
|
31
|
+
subFilterItems,
|
|
31
32
|
filterState,
|
|
32
33
|
handleApply,
|
|
33
34
|
handleReset
|
|
@@ -102,15 +103,39 @@ const FilterSidebar = props => {
|
|
|
102
103
|
if (!hideFilters.includes(group) && groupName) {
|
|
103
104
|
|
|
104
105
|
// if (!allowedFiltersArr?.length && group != "category_uid" || allowedFiltersArr?.length && allowedFiltersArr.includes(group)) {
|
|
105
|
-
|
|
106
|
+
let subFilter = null;
|
|
107
|
+
if (group.includes('card_release')) {
|
|
108
|
+
const subGroup = group.replace('card_release', 'card_set');
|
|
109
|
+
const subBlockState = filterState.get(subGroup);
|
|
110
|
+
const subFrontendInput = filterFrontendInput.get(subGroup);
|
|
111
|
+
const subFilterItems = filterItems.get(subGroup);
|
|
112
|
+
|
|
113
|
+
subFilter = {
|
|
114
|
+
key: subGroup,
|
|
115
|
+
filterApi: filterApi,
|
|
116
|
+
filterState: subBlockState,
|
|
117
|
+
filterFrontendInput: subFrontendInput,
|
|
118
|
+
group: subGroup,
|
|
119
|
+
isSubFilter: true,
|
|
120
|
+
items: subFilterItems,
|
|
121
|
+
name: '',
|
|
122
|
+
onApply: handleApplyFilter,
|
|
123
|
+
initialOpen: true
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
}
|
|
106
127
|
|
|
107
128
|
return (
|
|
108
129
|
<FilterBlock
|
|
109
130
|
key={group}
|
|
110
131
|
filterApi={filterApi}
|
|
111
132
|
filterState={blockState}
|
|
133
|
+
allowedSubFilters={[]}
|
|
112
134
|
filterFrontendInput={frontendInput}
|
|
113
135
|
group={group}
|
|
136
|
+
subFilterItems={subFilterItems?.subFilters}
|
|
137
|
+
filterItems={filterItems}
|
|
138
|
+
subFilter={subFilter}
|
|
114
139
|
items={items}
|
|
115
140
|
name={groupName}
|
|
116
141
|
onApply={group == "category_uid" ? handleCategoryApplyFilter : handleApplyFilter}
|
|
@@ -126,6 +151,7 @@ const FilterSidebar = props => {
|
|
|
126
151
|
filterNames,
|
|
127
152
|
filterFrontendInput,
|
|
128
153
|
filterState,
|
|
154
|
+
subFilterItems,
|
|
129
155
|
filterCountToOpen,
|
|
130
156
|
handleApplyFilter
|
|
131
157
|
]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { Fragment } from 'react';
|
|
2
|
+
import { arrayOf, number, node, oneOfType, shape, string } from 'prop-types';
|
|
3
|
+
import { RadioGroup as InformedRadioGroup } from 'informed';
|
|
4
|
+
import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
|
|
5
|
+
|
|
6
|
+
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
7
|
+
import { Message } from '@magento/venia-ui/lib/components/Field';
|
|
8
|
+
import Radio from './radio';
|
|
9
|
+
import defaultClasses from './radioGroup.module.css';
|
|
10
|
+
|
|
11
|
+
const RadioGroup = props => {
|
|
12
|
+
const {
|
|
13
|
+
children,
|
|
14
|
+
classes: propClasses,
|
|
15
|
+
disabled,
|
|
16
|
+
field,
|
|
17
|
+
id,
|
|
18
|
+
items,
|
|
19
|
+
message,
|
|
20
|
+
isSubFilter,
|
|
21
|
+
...rest
|
|
22
|
+
} = props;
|
|
23
|
+
const fieldState = useFieldState(field);
|
|
24
|
+
const classes = useStyle(defaultClasses, propClasses);
|
|
25
|
+
|
|
26
|
+
const options =
|
|
27
|
+
children ||
|
|
28
|
+
items.map(({ value, ...item }) => (
|
|
29
|
+
<Radio
|
|
30
|
+
data-cy=""
|
|
31
|
+
key={value}
|
|
32
|
+
disabled={disabled}
|
|
33
|
+
{...item}
|
|
34
|
+
classes={{
|
|
35
|
+
label: classes.radioLabel,
|
|
36
|
+
root: classes.radioContainer
|
|
37
|
+
}}
|
|
38
|
+
id={`${field}--${value}`}
|
|
39
|
+
value={value}
|
|
40
|
+
/>
|
|
41
|
+
));
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Fragment>
|
|
45
|
+
<div data-cy="RadioGroup-root" className={isSubFilter ? classes.sub_root : classes.root}>
|
|
46
|
+
<InformedRadioGroup {...rest} field={field} id={id}>
|
|
47
|
+
{options}
|
|
48
|
+
</InformedRadioGroup>
|
|
49
|
+
</div>
|
|
50
|
+
<Message className={classes.message} fieldState={fieldState}>
|
|
51
|
+
{message}
|
|
52
|
+
</Message>
|
|
53
|
+
</Fragment>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default RadioGroup;
|
|
58
|
+
|
|
59
|
+
RadioGroup.propTypes = {
|
|
60
|
+
children: node,
|
|
61
|
+
classes: shape({
|
|
62
|
+
message: string,
|
|
63
|
+
radioContainer: string,
|
|
64
|
+
radioLabel: string,
|
|
65
|
+
root: string
|
|
66
|
+
}),
|
|
67
|
+
field: string.isRequired,
|
|
68
|
+
id: string,
|
|
69
|
+
items: arrayOf(
|
|
70
|
+
shape({
|
|
71
|
+
key: oneOfType([number, string]),
|
|
72
|
+
label: node,
|
|
73
|
+
value: oneOfType([number, string])
|
|
74
|
+
})
|
|
75
|
+
),
|
|
76
|
+
message: node
|
|
77
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
composes: gap-2xs from global;
|
|
3
|
+
composes: grid from global;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.sub_root {
|
|
7
|
+
composes: gap-2xs from global;
|
|
8
|
+
composes: grid from global;
|
|
9
|
+
composes: pl-5 from global;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.radioContainer {
|
|
13
|
+
composes: gap-3 from global;
|
|
14
|
+
composes: grid from global;
|
|
15
|
+
composes: grid-flow-col from global;
|
|
16
|
+
composes: justify-center from global;
|
|
17
|
+
composes: leading-normal from global;
|
|
18
|
+
grid-template-areas: 'input label';
|
|
19
|
+
grid-template-columns: min-content 1fr;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.message {
|
|
23
|
+
composes: mt-xs from global;
|
|
24
|
+
composes: text-colorDefault from global;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* TODO @TW: cannot compose */
|
|
28
|
+
.message:empty {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|