@shopgate/pwa-common-commerce 7.6.0 → 7.6.1-beta.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.
|
@@ -43,13 +43,15 @@ import{ADD_PRODUCT_TO_FAVORITES,REMOVE_PRODUCT_FROM_FAVORITES,CANCEL_REQUEST_SYN
|
|
|
43
43
|
*/export var requestRemoveFavorites=function requestRemoveFavorites(productId,listId){return{type:REQUEST_REMOVE_FAVORITES,productId:productId,listId:listId};};/**
|
|
44
44
|
* Action to be triggered upon successful removeFavorites (deleteFavorites) pipeline call.
|
|
45
45
|
* @param {string} productId Product identifier.
|
|
46
|
+
* @param {number} takenListId List id
|
|
46
47
|
* @returns {Object}
|
|
47
|
-
*/export var successRemoveFavorites=function successRemoveFavorites(productId){return{type:SUCCESS_REMOVE_FAVORITES,productId:productId};};/**
|
|
48
|
+
*/export var successRemoveFavorites=function successRemoveFavorites(productId,takenListId){return{type:SUCCESS_REMOVE_FAVORITES,productId:productId,listId:takenListId};};/**
|
|
48
49
|
* Action to be triggered upon a failed removeFavorites (deleteFavorites) pipeline call.
|
|
49
50
|
* @param {string} productId Product identifier.
|
|
51
|
+
* @param {number} takenListId List id
|
|
50
52
|
* @param {Error} error The error that occurred.
|
|
51
53
|
* @returns {Object}
|
|
52
|
-
*/export var errorRemoveFavorites=function errorRemoveFavorites(productId,error){return{type:ERROR_REMOVE_FAVORITES,productId:productId,error:error};};/**
|
|
54
|
+
*/export var errorRemoveFavorites=function errorRemoveFavorites(productId,takenListId,error){return{type:ERROR_REMOVE_FAVORITES,productId:productId,listId:takenListId,error:error};};/**
|
|
53
55
|
* Return the flush favorites buffer Now action object
|
|
54
56
|
* @param {string} listId The Id of the wishlist.
|
|
55
57
|
* @return {Object}
|
|
@@ -4,4 +4,4 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
|
|
|
4
4
|
* @param {string} listId Id of the list to be deleted.
|
|
5
5
|
* @returns {Function} A redux thunk.
|
|
6
6
|
*/function removeFavorites(productId,listId){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var lists,defaultList,takenListId,request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:// Fallback for deprecated calls without list id.
|
|
7
|
-
lists=getState().favorites.lists.lists;defaultList=(lists===null||lists===void 0?void 0:lists[0])||{id:'DEFAULT'};takenListId=listId||defaultList.id;request=new PipelineRequest(SHOPGATE_USER_DELETE_FAVORITES).setInput({productId:productId,favoritesListId:takenListId}).setRetries(0).dispatch();_context.prev=4;_context.next=7;return request;case 7:dispatch(successRemoveFavorites(productId));_context.next=13;break;case 10:_context.prev=10;_context.t0=_context["catch"](4);dispatch(errorRemoveFavorites(productId,_context.t0));case 13:return _context.abrupt("return",request);case 14:case"end":return _context.stop();}}},_callee,null,[[4,10]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}export default removeFavorites;
|
|
7
|
+
lists=getState().favorites.lists.lists;defaultList=(lists===null||lists===void 0?void 0:lists[0])||{id:'DEFAULT'};takenListId=listId||defaultList.id;request=new PipelineRequest(SHOPGATE_USER_DELETE_FAVORITES).setInput({productId:productId,favoritesListId:takenListId}).setRetries(0).dispatch();_context.prev=4;_context.next=7;return request;case 7:dispatch(successRemoveFavorites(productId,takenListId));_context.next=13;break;case 10:_context.prev=10;_context.t0=_context["catch"](4);dispatch(errorRemoveFavorites(productId,takenListId,_context.t0));case 13:return _context.abrupt("return",request);case 14:case"end":return _context.stop();}}},_callee,null,[[4,10]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}export default removeFavorites;
|
|
@@ -12,6 +12,11 @@ import{createSelector}from'reselect';import uniq from'lodash/uniq';import{getPro
|
|
|
12
12
|
* @param {Object} state The global state.
|
|
13
13
|
* @return {Object|null}
|
|
14
14
|
*/export var getFavoritesProducts=createSelector(getFavoritesState,function(state){if(!state.products){return null;}return state.products;});export var getFavoritesDefaultList=createSelector(getFavoritesLists,function(lists){return lists[0];});export var hasMultipleFavoritesList=createSelector(getFavoritesLists,function(lists){return lists.length>1;});/**
|
|
15
|
+
* A selector that gets the id of the favorites list by the given name
|
|
16
|
+
* @param {Object} state The current application state.
|
|
17
|
+
* @param {Object} props The component props.
|
|
18
|
+
* @returns {string} the id of the favorites list
|
|
19
|
+
*/export var getFavoritesListIdByName=createSelector(getFavoritesLists,function(state,props){return props.listName;},function(favLists,listName){var _ref=favLists.find(function(list){return list.name===listName;})||{},id=_ref.id;return id;});/**
|
|
15
20
|
* @param {Object} state The global state.
|
|
16
21
|
* @returns {Array}
|
|
17
22
|
* @deprecated
|
|
@@ -19,11 +24,16 @@ import{createSelector}from'reselect';import uniq from'lodash/uniq';import{getPro
|
|
|
19
24
|
* @param {Object} state The global state.
|
|
20
25
|
* @deprecated
|
|
21
26
|
*/export var getFavorites=createSelector(getFavoritesProductsIds,getProducts,function(productIds,products){return productIds.filter(function(id){return!!products[id]&&products[id].productData;}).map(function(id){return products[id].productData;});});/**
|
|
27
|
+
* Creates a selector that selects all ids that belong
|
|
28
|
+
* to the given favorite list.
|
|
29
|
+
* @param {Function} getListCode Selects the list code.
|
|
30
|
+
* @returns {Function}
|
|
31
|
+
*/export var makeGetFavoritesIdsByList=function makeGetFavoritesIdsByList(getListCode){return createSelector(getFavoritesProducts,getListCode,function(favProducts,listId){var _favProducts$byList$l;var ids=((_favProducts$byList$l=favProducts.byList[listId])===null||_favProducts$byList$l===void 0?void 0:_favProducts$byList$l.ids)||[];return ids;});};/**
|
|
22
32
|
* Creates a selector that selects all products that belong
|
|
23
33
|
* to the given favorite list.
|
|
24
34
|
* @param {Function} getListCode Selects the list code.
|
|
25
35
|
* @returns {Function}
|
|
26
|
-
*/export var makeGetFavorites=function makeGetFavorites(getListCode){return createSelector(
|
|
36
|
+
*/export var makeGetFavorites=function makeGetFavorites(getListCode){var getFavoritesIdsByList=makeGetFavoritesIdsByList(getListCode);return createSelector(getFavoritesIdsByList,getProducts,function(ids,products){return ids.filter(function(id){return!!products[id]&&products[id].productData;}).map(function(id){return products[id].productData;});});};/**
|
|
27
37
|
* True when favorites where not yet fetched for the first time.
|
|
28
38
|
* @param {Object} state The global state.
|
|
29
39
|
* @returns {boolean}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-common-commerce",
|
|
3
|
-
"version": "7.6.
|
|
3
|
+
"version": "7.6.1-beta.1",
|
|
4
4
|
"description": "Commerce library for the Shopgate Connect PWA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"reselect": "^3.0.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@shopgate/pwa-common": "7.6.
|
|
23
|
-
"@shopgate/pwa-core": "7.6.
|
|
22
|
+
"@shopgate/pwa-common": "7.6.1-beta.1",
|
|
23
|
+
"@shopgate/pwa-core": "7.6.1-beta.1",
|
|
24
24
|
"lodash": "^4.17.4",
|
|
25
25
|
"react": "~16.12.0",
|
|
26
26
|
"react-dom": "~16.12.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{shouldFetchData}from'@shopgate/pwa-common/helpers/redux';import fetchProducts from"./fetchProducts";/**
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{getProductDataById}from'@shopgate/engage/product/selectors/product';import{shouldFetchData}from'@shopgate/pwa-common/helpers/redux';import fetchProducts from"./fetchProducts";/**
|
|
2
2
|
* Retrieves products by id from the store.
|
|
3
3
|
* @param {Array} productIds The product id's to request.
|
|
4
4
|
* @param {string} [componentId=null] A unique id for the component that is using this action.
|
|
@@ -7,5 +7,4 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
7
7
|
* @return {Function} A Redux Thunk
|
|
8
8
|
*/var fetchProductsById=function fetchProductsById(productIds){var componentId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var cached=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;var includeFulfillment=arguments.length>3&&arguments[3]!==undefined?arguments[3]:true;return function(dispatch,getState){var state=getState();var products=state.product.productsById;// Filter out only the products that are not yet available in the store.
|
|
9
9
|
var missingIds=productIds.filter(function(id){return shouldFetchData(products[id]);});// Then only perform a pipeline request if there are products missing.
|
|
10
|
-
if(!missingIds.length){return;}
|
|
11
|
-
return dispatch(fetchProducts(_extends({},componentId&&{id:componentId},{cached:cached,params:{productIds:missingIds},includeFulfillment:includeFulfillment,includeFilters:false,includeSort:false})));};};export default fetchProductsById;
|
|
10
|
+
if(!missingIds.length){var productsById=productIds.map(function(id){return getProductDataById(state,{productId:id});});var totalProductCount=productsById.length;return{products:productsById,totalProductCount:totalProductCount};}return dispatch(fetchProducts(_extends({},componentId&&{id:componentId},{cached:cached,params:{productIds:missingIds},includeFulfillment:includeFulfillment,includeFilters:false,includeSort:false})));};};export default fetchProductsById;
|