Skip to content

Commit e8f4c78

Browse files
authored
revert(viewReducer): sw-3443 rollback to focused reset (#1567)
1 parent b1b66f2 commit e8f4c78

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

src/redux/reducers/__tests__/__snapshots__/viewReducer.test.js.snap

+24-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,30 @@ exports[`ViewReducer should handle clearing state with defined types: defined ty
44
{
55
"result": {
66
"graphTallyQuery": {},
7-
"inventoryGuestsQuery": {},
8-
"inventoryHostsQuery": {},
9-
"inventorySubscriptionsQuery": {},
10-
"query": {},
7+
"inventoryGuestsQuery": {
8+
"another_test_id": {
9+
"offset": 10,
10+
},
11+
},
12+
"inventoryHostsQuery": {
13+
"another_test_id": {
14+
"dir": "lorem desc direction",
15+
"offset": 90,
16+
"sort": "lorem sort",
17+
},
18+
},
19+
"inventorySubscriptionsQuery": {
20+
"another_test_id": {
21+
"dir": "dolor desc direction",
22+
"offset": 40,
23+
"sort": "dolor sort",
24+
},
25+
},
26+
"query": {
27+
"another_test_id": {
28+
"lorem": "ipsum",
29+
},
30+
},
1131
},
1232
"type": "SET_PRODUCT_VARIANT_QUERY_RESET_ALL",
1333
}

src/redux/reducers/viewReducer.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,27 @@ const initialState = {
3636
const viewReducer = (state = initialState, action) => {
3737
switch (action.type) {
3838
/*
39-
* Note: Hard reset query state/object associated with a variant/productId. Remove this action type if restoring
40-
* queries based on product variant is needed, also review toolbar reducer for restoring/removing legend state.
39+
* Note: Hard reset causes query state/object updates for ALL variants/productIds that have a filter selected,
40+
* instead we focus the update to the specific variant to remove the extra API calls. Remove this entire
41+
* action type if restoring queries based on product variant is needed, also review toolbar reducer for
42+
* restoring/removing legend state.
4143
*/
4244
case reduxTypes.app.SET_PRODUCT_VARIANT_QUERY_RESET_ALL:
45+
const updateVariantResetQueries = (query = {}, id) => {
46+
const updatedQuery = query;
47+
delete updatedQuery[id];
48+
return updatedQuery;
49+
};
50+
4351
return reduxHelpers.setStateProp(
4452
null,
4553
{
4654
...state,
47-
query: {},
48-
graphTallyQuery: {},
49-
inventoryGuestsQuery: {},
50-
inventoryHostsQuery: {},
51-
inventorySubscriptionsQuery: {}
55+
query: updateVariantResetQueries(state.query, action.variant),
56+
graphTallyQuery: updateVariantResetQueries(state.graphTallyQuery, action.variant),
57+
inventoryGuestsQuery: updateVariantResetQueries(state.inventoryGuestsQuery, action.variant),
58+
inventoryHostsQuery: updateVariantResetQueries(state.inventoryHostsQuery, action.variant),
59+
inventorySubscriptionsQuery: updateVariantResetQueries(state.inventorySubscriptionsQuery, action.variant)
5260
},
5361
{
5462
state,

0 commit comments

Comments
 (0)