@shopgate/pwa-common-commerce 7.30.0-alpha.7 → 7.30.0-alpha.8
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/cart/action-creators/addCouponsToCart.js +9 -2
- package/cart/action-creators/addProductsToCart.js +9 -2
- package/cart/action-creators/deleteCouponsFromCart.js +9 -2
- package/cart/action-creators/deleteProductsFromCart.js +9 -2
- package/cart/action-creators/errorAddCouponsToCart.js +10 -2
- package/cart/action-creators/errorAddProductsToCart.js +10 -2
- package/cart/action-creators/errorCart.js +8 -2
- package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
- package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
- package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
- package/cart/action-creators/receiveCart.js +9 -2
- package/cart/action-creators/requestCart.js +8 -2
- package/cart/action-creators/setCartProductPendingCount.js +9 -2
- package/cart/action-creators/setCouponFieldError.js +9 -2
- package/cart/action-creators/setCouponFieldValue.js +9 -2
- package/cart/action-creators/setFulfillmentSlot.js +9 -2
- package/cart/action-creators/successAddCouponsToCart.js +10 -2
- package/cart/action-creators/successAddProductsToCart.js +8 -2
- package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
- package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
- package/cart/action-creators/successUpdateProductsInCart.js +8 -2
- package/cart/action-creators/updateProductsInCart.js +9 -2
- package/cart/actions/addCouponsToCart.js +52 -8
- package/cart/actions/addProductsToCart.js +80 -11
- package/cart/actions/deleteCouponsFromCart.js +39 -6
- package/cart/actions/deleteProductsFromCart.js +38 -6
- package/cart/actions/fetchCart.js +52 -8
- package/cart/actions/updateProductsInCart.js +44 -6
- package/cart/constants/PipelineErrors.js +6 -1
- package/cart/constants/Pipelines.js +6 -1
- package/cart/constants/Portals.js +85 -1
- package/cart/constants/index.js +39 -2
- package/cart/helpers/config.js +47 -2
- package/cart/helpers/createPipelineErrorList.js +30 -4
- package/cart/helpers/fulfillmentSlots.js +37 -4
- package/cart/helpers/index.js +14 -3
- package/cart/helpers/quantity.js +23 -4
- package/cart/helpers/shipping.js +57 -2
- package/cart/helpers/tax.js +26 -2
- package/cart/index.js +25 -5
- package/cart/mock.js +130 -1
- package/cart/reducers/couponField.js +30 -2
- package/cart/reducers/data.js +98 -6
- package/cart/reducers/index.js +7 -1
- package/cart/selectors/index.js +181 -31
- package/cart/selectors/spec.js +189 -2
- package/cart/streams/index.js +176 -29
- package/cart/subscriptions/index.js +307 -30
- package/category/action-creators/errorCategory.js +10 -2
- package/category/action-creators/errorCategoryChildren.js +9 -2
- package/category/action-creators/errorRootCategories.js +8 -2
- package/category/action-creators/receiveCategory.js +12 -2
- package/category/action-creators/receiveCategoryChildren.js +10 -2
- package/category/action-creators/receiveRootCategories.js +9 -2
- package/category/action-creators/requestCategory.js +9 -2
- package/category/action-creators/requestCategoryChildren.js +9 -2
- package/category/action-creators/requestRootCategories.js +8 -2
- package/category/actions/fetchCategory.js +47 -5
- package/category/actions/fetchCategoryChildren.js +30 -2
- package/category/actions/fetchCategoryOrRootCategories.js +16 -2
- package/category/actions/fetchCategoryProducts.js +36 -2
- package/category/actions/fetchRootCategories.js +31 -2
- package/category/actions/getCategory.js +10 -2
- package/category/constants/Pipelines.js +3 -1
- package/category/constants/Portals.js +56 -3
- package/category/constants/index.js +17 -2
- package/category/helpers/index.js +27 -3
- package/category/index.js +19 -5
- package/category/mock.js +176 -1
- package/category/reducers/categoriesById.js +65 -3
- package/category/reducers/childrenByCategoryId.js +55 -4
- package/category/reducers/helpers/handleCategoryCollection.js +24 -3
- package/category/reducers/helpers/handleReceivedCategories.js +3 -1
- package/category/reducers/index.js +12 -2
- package/category/reducers/rootCategories.js +31 -2
- package/category/selectors/index.js +115 -16
- package/category/streams/index.js +82 -4
- package/category/subscriptions/index.js +96 -3
- package/checkout/action-creators/successCheckout.js +9 -2
- package/checkout/actions/fetchCheckoutUrl.js +28 -3
- package/checkout/constants/Pipelines.js +1 -1
- package/checkout/constants/index.js +3 -2
- package/checkout/index.js +11 -4
- package/checkout/selectors/index.js +7 -2
- package/checkout/streams/index.js +8 -2
- package/checkout/subscriptions/index.js +35 -6
- package/favorites/action-creators/index.js +206 -24
- package/favorites/actions/addFavorites.js +41 -3
- package/favorites/actions/addFavoritesList.js +27 -2
- package/favorites/actions/fetchFavoriteIds.js +49 -5
- package/favorites/actions/fetchFavorites.js +60 -5
- package/favorites/actions/fetchFavoritesList.js +47 -3
- package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
- package/favorites/actions/getFavorites.js +6 -2
- package/favorites/actions/removeFavorites.js +32 -3
- package/favorites/actions/removeFavoritesList.js +24 -2
- package/favorites/actions/toggleFavorites.js +68 -10
- package/favorites/actions/updateFavorites.js +39 -3
- package/favorites/actions/updateFavoritesList.js +26 -2
- package/favorites/constants/Pipelines.js +9 -1
- package/favorites/constants/Portals.js +32 -4
- package/favorites/constants/index.js +37 -5
- package/favorites/index.js +14 -4
- package/favorites/mock.js +89 -4
- package/favorites/reducers/index.js +7 -1
- package/favorites/reducers/lists.js +74 -2
- package/favorites/reducers/products.js +231 -24
- package/favorites/selectors/index.js +188 -24
- package/favorites/streams/index.js +135 -23
- package/favorites/streams/spec.js +517 -8
- package/favorites/subscriptions/index.js +260 -25
- package/favorites/subscriptions/spec.js +701 -28
- package/filter/action-creators/errorFilters.js +9 -2
- package/filter/action-creators/index.js +4 -1
- package/filter/action-creators/receiveFilters.js +10 -2
- package/filter/action-creators/requestFilters.js +9 -2
- package/filter/action-creators/updateFilters.js +8 -2
- package/filter/actions/fetchFilters.js +46 -3
- package/filter/actions/getFilters.js +6 -2
- package/filter/actions/helpers/buildFilterParams.js +34 -2
- package/filter/actions/helpers/buildRequestFilters.js +35 -2
- package/filter/actions/helpers/processFilters.js +10 -2
- package/filter/actions/helpers/processParams.js +26 -2
- package/filter/constants/Pipelines.js +1 -1
- package/filter/constants/Portals.js +39 -3
- package/filter/constants/index.js +8 -1
- package/filter/index.js +12 -4
- package/filter/reducers/helpers/enrichFilters.js +11 -3
- package/filter/reducers/index.js +5 -1
- package/filter/reducers/resultsByHash.js +43 -3
- package/filter/selectors/index.js +47 -6
- package/filter/streams/index.js +30 -1
- package/filter/subscriptions/index.js +34 -2
- package/market/constants/Portals.js +22 -4
- package/market/constants/index.js +2 -1
- package/market/helpers/showReturnPolicy.js +3 -1
- package/market/helpers/showTaxDisclaimer.js +3 -1
- package/market/index.js +6 -2
- package/orders/constants.js +2 -1
- package/package.json +3 -3
- package/product/action-creators/deleteProductsByIds.js +10 -2
- package/product/action-creators/errorProduct.js +10 -2
- package/product/action-creators/errorProductDescription.js +10 -2
- package/product/action-creators/errorProductImages.js +10 -2
- package/product/action-creators/errorProductMedia.js +10 -2
- package/product/action-creators/errorProductOptions.js +10 -2
- package/product/action-creators/errorProductProperties.js +10 -2
- package/product/action-creators/errorProductRelations.js +9 -2
- package/product/action-creators/errorProductShipping.js +10 -2
- package/product/action-creators/errorProductVariants.js +10 -2
- package/product/action-creators/errorProducts.js +9 -2
- package/product/action-creators/expireProductById.js +10 -2
- package/product/action-creators/expireProductData.js +11 -2
- package/product/action-creators/expireProductsByHash.js +9 -2
- package/product/action-creators/productNotAvailable.js +10 -2
- package/product/action-creators/provideProduct.js +9 -2
- package/product/action-creators/receiveProduct.js +10 -2
- package/product/action-creators/receiveProductCached.js +9 -2
- package/product/action-creators/receiveProductDescription.js +10 -2
- package/product/action-creators/receiveProductImages.js +10 -2
- package/product/action-creators/receiveProductMedia.js +10 -2
- package/product/action-creators/receiveProductOptions.js +10 -2
- package/product/action-creators/receiveProductProperties.js +10 -2
- package/product/action-creators/receiveProductRelations.js +12 -2
- package/product/action-creators/receiveProductShipping.js +10 -2
- package/product/action-creators/receiveProductVariants.js +10 -2
- package/product/action-creators/receiveProducts.js +16 -2
- package/product/action-creators/receiveProductsCached.js +9 -2
- package/product/action-creators/refreshExpiredPDPData.js +8 -2
- package/product/action-creators/requestProduct.js +10 -2
- package/product/action-creators/requestProductDescription.js +9 -2
- package/product/action-creators/requestProductImages.js +9 -2
- package/product/action-creators/requestProductMedia.js +9 -2
- package/product/action-creators/requestProductOptions.js +9 -2
- package/product/action-creators/requestProductProperties.js +9 -2
- package/product/action-creators/requestProductRelations.js +10 -2
- package/product/action-creators/requestProductShipping.js +9 -2
- package/product/action-creators/requestProductVariants.js +9 -2
- package/product/action-creators/requestProducts.js +9 -2
- package/product/action-creators/setProductId.js +9 -2
- package/product/action-creators/setProductQuantity.js +9 -2
- package/product/action-creators/setProductVariantId.js +9 -2
- package/product/actions/changeSortOrder.js +21 -2
- package/product/actions/fetchHighlightProducts.js +18 -2
- package/product/actions/fetchLiveshoppingProducts.js +14 -2
- package/product/actions/fetchProduct.js +52 -3
- package/product/actions/fetchProductDescription.js +30 -2
- package/product/actions/fetchProductImages.js +31 -2
- package/product/actions/fetchProductMedia.js +35 -2
- package/product/actions/fetchProductOptions.js +31 -2
- package/product/actions/fetchProductProperties.js +30 -2
- package/product/actions/fetchProductRelations.js +63 -2
- package/product/actions/fetchProductShipping.js +31 -2
- package/product/actions/fetchProductVariants.js +31 -2
- package/product/actions/fetchProducts.js +189 -17
- package/product/actions/fetchProductsById.js +68 -8
- package/product/actions/fetchProductsByQuery.js +102 -18
- package/product/actions/getHighlightProducts.js +6 -2
- package/product/actions/getLiveshoppingProducts.js +6 -2
- package/product/actions/getProduct.js +6 -2
- package/product/actions/getProductDescription.js +6 -2
- package/product/actions/getProductImages.js +6 -2
- package/product/actions/getProductOptions.js +6 -2
- package/product/actions/getProductProperties.js +6 -2
- package/product/actions/getProductRelations.js +6 -2
- package/product/actions/getProductShipping.js +6 -2
- package/product/actions/getProductVariants.js +6 -2
- package/product/actions/getProducts.js +6 -2
- package/product/actions/getProductsById.js +6 -2
- package/product/actions/getProductsByQuery.js +6 -2
- package/product/actions/processProductFlags.js +35 -3
- package/product/actions/updateMetadata.js +17 -2
- package/product/collections/ProductImageFormats.js +48 -8
- package/product/collections/index.js +1 -1
- package/product/constants/Pipelines.js +12 -1
- package/product/constants/Portals.js +200 -33
- package/product/constants/index.js +90 -18
- package/product/helpers/index.js +61 -8
- package/product/index.js +36 -6
- package/product/mock.js +1002 -2
- package/product/reducers/descriptionsByProductId.js +54 -5
- package/product/reducers/helpers/formatOptions.js +17 -2
- package/product/reducers/helpers/handleProductCollection.js +19 -2
- package/product/reducers/imagesByProductId.js +51 -4
- package/product/reducers/index.js +23 -1
- package/product/reducers/mediaByProductId.js +55 -3
- package/product/reducers/optionsByProductId.js +41 -2
- package/product/reducers/productRelationsByHash.js +43 -2
- package/product/reducers/productsById.js +122 -7
- package/product/reducers/propertiesByProductId.js +48 -2
- package/product/reducers/resultsByHash.js +125 -9
- package/product/reducers/shippingByProductId.js +37 -2
- package/product/reducers/variantsByProductId.js +56 -2
- package/product/selectors/options.js +90 -13
- package/product/selectors/page.js +62 -13
- package/product/selectors/price.js +81 -18
- package/product/selectors/product.js +549 -59
- package/product/selectors/product.mock.js +327 -12
- package/product/selectors/relations.js +35 -5
- package/product/selectors/variants.js +91 -15
- package/product/streams/index.js +167 -13
- package/product/subscriptions/index.js +210 -4
- package/reviews/action-creators/errorProductReviews.js +9 -2
- package/reviews/action-creators/errorReviews.js +9 -2
- package/reviews/action-creators/errorSubmitReview.js +9 -2
- package/reviews/action-creators/errorUserReview.js +9 -2
- package/reviews/action-creators/flushUserReview.js +8 -2
- package/reviews/action-creators/receiveProductReviews.js +11 -2
- package/reviews/action-creators/receiveReviews.js +12 -2
- package/reviews/action-creators/receiveSubmitReview.js +9 -2
- package/reviews/action-creators/receiveUserReview.js +10 -2
- package/reviews/action-creators/requestProductReviews.js +10 -2
- package/reviews/action-creators/requestReviews.js +9 -2
- package/reviews/action-creators/requestSubmitReview.js +9 -2
- package/reviews/action-creators/requestUserReview.js +9 -2
- package/reviews/action-creators/resetSubmittedReview.js +9 -2
- package/reviews/action-creators/spec.js +40 -1
- package/reviews/actions/fetchProductReviews.js +37 -2
- package/reviews/actions/fetchReviews.js +38 -2
- package/reviews/actions/fetchUserReview.js +31 -2
- package/reviews/actions/flushUserReview.js +5 -1
- package/reviews/actions/getProductReviews.js +6 -2
- package/reviews/actions/getUserReview.js +6 -2
- package/reviews/actions/spec.js +241 -4
- package/reviews/actions/submitReview.js +63 -3
- package/reviews/constants/Pipelines.js +4 -1
- package/reviews/constants/Portals.js +4 -1
- package/reviews/constants/index.js +26 -7
- package/reviews/index.js +15 -4
- package/reviews/mock.js +172 -11
- package/reviews/reducers/index.js +11 -1
- package/reviews/reducers/mock.js +14 -2
- package/reviews/reducers/reviewsByHash.js +52 -6
- package/reviews/reducers/reviewsById.js +27 -2
- package/reviews/reducers/reviewsByProductId.js +47 -2
- package/reviews/reducers/spec.js +211 -2
- package/reviews/reducers/userReviewsByProductId.js +68 -2
- package/reviews/selectors/index.js +123 -19
- package/reviews/selectors/mock.js +100 -1
- package/reviews/selectors/spec.js +100 -1
- package/reviews/streams/index.js +37 -5
- package/reviews/streams/spec.js +25 -1
- package/reviews/subscriptions/index.js +27 -2
- package/scanner/action-creators/errorHandleScanner.js +11 -2
- package/scanner/action-creators/scannerFinished.js +11 -2
- package/scanner/action-creators/startScanner.js +8 -2
- package/scanner/action-creators/successHandleScanner.js +11 -2
- package/scanner/actions/handleBarCode.js +22 -2
- package/scanner/actions/handleNoResults.js +23 -2
- package/scanner/actions/handleQrCode.js +116 -6
- package/scanner/actions/handleSearch.js +33 -2
- package/scanner/constants/Portals.js +22 -1
- package/scanner/constants/index.js +17 -1
- package/scanner/helpers/index.js +115 -5
- package/scanner/index.js +19 -5
- package/scanner/streams/index.js +36 -1
- package/scanner/subscriptions/index.js +78 -8
- package/search/action-creators/errorSearchResults.js +10 -2
- package/search/action-creators/receiveSearchResults.js +11 -2
- package/search/action-creators/receiveSearchSuggestions.js +10 -2
- package/search/action-creators/requestSearchResults.js +10 -2
- package/search/action-creators/requestSearchSuggestions.js +9 -2
- package/search/actions/fetchSearchResults.js +66 -8
- package/search/actions/fetchSearchSuggestions.js +36 -2
- package/search/constants/Pipelines.js +1 -1
- package/search/constants/Portals.js +9 -2
- package/search/constants/index.js +10 -2
- package/search/helpers/index.js +5 -2
- package/search/helpers/removeHighlightingPlaceholders.js +4 -1
- package/search/helpers/spec.js +19 -1
- package/search/index.js +17 -5
- package/search/reducers/index.js +38 -2
- package/search/selectors/index.js +23 -4
- package/search/streams/index.js +51 -3
- package/search/subscriptions/index.js +132 -5
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { ITEMS_PER_LOAD } from '@shopgate/pwa-common/constants/DisplayOptions';
|
|
2
|
+
import { getSortOrder } from '@shopgate/pwa-common/selectors/history';
|
|
3
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
4
|
+
import fetchProducts from "../../product/actions/fetchProducts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* Retrieves category products by a category id.
|
|
3
8
|
* @param {string} categoryId The category id to requests products for.
|
|
4
9
|
* @param {Object} [filters=null] The filters.
|
|
@@ -9,4 +14,33 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
9
14
|
* @param {null|number} [cachedTime=null] The cache TTL.
|
|
10
15
|
* @param {Object} params additional params.
|
|
11
16
|
* @return {Function} The dispatched action.
|
|
12
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
const fetchCategoryProducts = ({
|
|
19
|
+
categoryId,
|
|
20
|
+
filters = null,
|
|
21
|
+
offset = 0,
|
|
22
|
+
limit = ITEMS_PER_LOAD,
|
|
23
|
+
sort,
|
|
24
|
+
cached = true,
|
|
25
|
+
cachedTime = null,
|
|
26
|
+
params
|
|
27
|
+
}) => (dispatch, getState) => {
|
|
28
|
+
const sortOrder = sort || getSortOrder(getState(), {
|
|
29
|
+
categoryId
|
|
30
|
+
});
|
|
31
|
+
return dispatch(fetchProducts({
|
|
32
|
+
cached,
|
|
33
|
+
cachedTime,
|
|
34
|
+
params: {
|
|
35
|
+
categoryId,
|
|
36
|
+
offset,
|
|
37
|
+
limit,
|
|
38
|
+
sort: sortOrder,
|
|
39
|
+
...params
|
|
40
|
+
},
|
|
41
|
+
filters
|
|
42
|
+
}));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** @mixes {MutableFunction} */
|
|
46
|
+
export default mutable(fetchCategoryProducts);
|
|
@@ -1,4 +1,33 @@
|
|
|
1
|
-
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
3
|
+
import { SHOPGATE_CATALOG_GET_ROOT_CATEGORIES } from "../constants/Pipelines";
|
|
4
|
+
import requestRootCategories from "../action-creators/requestRootCategories";
|
|
5
|
+
import receiveRootCategories from "../action-creators/receiveRootCategories";
|
|
6
|
+
import errorRootCategories from "../action-creators/errorRootCategories";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Retrieves the root categories from store.
|
|
3
10
|
* @return {Function} The dispatched action.
|
|
4
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
function fetchRootCategories() {
|
|
13
|
+
return (dispatch, getState) => {
|
|
14
|
+
const state = getState();
|
|
15
|
+
const {
|
|
16
|
+
rootCategories
|
|
17
|
+
} = state.category;
|
|
18
|
+
if (!shouldFetchData(rootCategories, 'categories')) {
|
|
19
|
+
return Promise.resolve(null);
|
|
20
|
+
}
|
|
21
|
+
dispatch(requestRootCategories());
|
|
22
|
+
const request = new PipelineRequest(SHOPGATE_CATALOG_GET_ROOT_CATEGORIES).dispatch();
|
|
23
|
+
request.then(result => {
|
|
24
|
+
dispatch(receiveRootCategories(result.categories));
|
|
25
|
+
}).catch(() => {
|
|
26
|
+
dispatch(errorRootCategories());
|
|
27
|
+
});
|
|
28
|
+
return request;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @mixes {MutableFunction} */
|
|
33
|
+
export default mutable(fetchRootCategories);
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import{logDeprecationMessage}from'@shopgate/pwa-core/helpers';
|
|
1
|
+
import { logDeprecationMessage } from '@shopgate/pwa-core/helpers';
|
|
2
|
+
import fetchCategoryOrRootCategories from "./fetchCategoryOrRootCategories";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Deprecation fallback for the fetchCategoryOrRootCategories action
|
|
3
6
|
* @deprecated
|
|
4
7
|
* @param {string} categoryId The category ID.
|
|
5
8
|
* @return {Function} The dispatched action.
|
|
6
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const getCategory = categoryId => {
|
|
11
|
+
logDeprecationMessage('The fetch action getCategory will be removed in future versions due naming conflict with getCategory selector. Please use fetchCategoryOrRootCategories as a replacement');
|
|
12
|
+
return fetchCategoryOrRootCategories(categoryId);
|
|
13
|
+
};
|
|
14
|
+
export default getCategory;
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const SHOPGATE_CATALOG_GET_CATEGORY = 'shopgate.catalog.getCategory';
|
|
2
|
+
export const SHOPGATE_CATALOG_GET_CATEGORY_CHILDREN = 'shopgate.catalog.getCategoryChildren';
|
|
3
|
+
export const SHOPGATE_CATALOG_GET_ROOT_CATEGORIES = 'shopgate.catalog.getRootCategories';
|
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
// FEATURES
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const CATEGORY = 'category';
|
|
3
|
+
const PRODUCT = 'product';
|
|
4
|
+
const NAV_MENU = 'nav-menu';
|
|
5
|
+
|
|
6
|
+
// CONTENTS
|
|
7
|
+
const LIST = 'list';
|
|
8
|
+
const ITEM = 'item';
|
|
9
|
+
const IMAGE = 'image';
|
|
10
|
+
const PRICE = 'price';
|
|
11
|
+
const DISCOUNT = 'discount';
|
|
12
|
+
const FAVORITES_BUTTON = 'favorites-button';
|
|
13
|
+
const NAME = 'name';
|
|
14
|
+
const MANUFACTURER = 'manufacturer';
|
|
15
|
+
const AVAILABILITY = 'availability';
|
|
16
|
+
const CATEGORIES = 'categories';
|
|
17
|
+
|
|
18
|
+
// POSITIONS
|
|
19
|
+
const BEFORE = 'before';
|
|
20
|
+
const AFTER = 'after';
|
|
21
|
+
const INSIDE = 'inside';
|
|
22
|
+
export const CATEGORY_LIST = `${CATEGORY}.${LIST}`;
|
|
23
|
+
export const CATEGORY_LIST_BEFORE = `${CATEGORY}.${LIST}.${BEFORE}`;
|
|
24
|
+
export const CATEGORY_LIST_AFTER = `${CATEGORY}.${LIST}.${AFTER}`;
|
|
25
|
+
export const CATEGORY_ITEM = `${CATEGORY}.${ITEM}`;
|
|
26
|
+
export const PRODUCT_LIST = `${PRODUCT}.${LIST}`;
|
|
27
|
+
export const PRODUCT_LIST_BEFORE = `${PRODUCT}.${LIST}.${BEFORE}`;
|
|
28
|
+
export const PRODUCT_LIST_AFTER = `${PRODUCT}.${LIST}.${AFTER}`;
|
|
29
|
+
export const PRODUCT_ITEM_BEFORE = `${PRODUCT}.${ITEM}.${BEFORE}`;
|
|
30
|
+
export const PRODUCT_ITEM = `${PRODUCT}.${ITEM}`;
|
|
31
|
+
export const PRODUCT_ITEM_AFTER = `${PRODUCT}.${ITEM}.${AFTER}`;
|
|
32
|
+
export const PRODUCT_ITEM_IMAGE_BEFORE = `${PRODUCT}-${ITEM}.${IMAGE}.${BEFORE}`;
|
|
33
|
+
export const PRODUCT_ITEM_IMAGE = `${PRODUCT}-${ITEM}.${IMAGE}`;
|
|
34
|
+
export const PRODUCT_ITEM_IMAGE_AFTER = `${PRODUCT}-${ITEM}.${IMAGE}.${AFTER}`;
|
|
35
|
+
export const PRODUCT_ITEM_DISCOUNT_BEFORE = `${PRODUCT}-${ITEM}.${DISCOUNT}.${BEFORE}`;
|
|
36
|
+
export const PRODUCT_ITEM_DISCOUNT = `${PRODUCT}-${ITEM}.${DISCOUNT}`;
|
|
37
|
+
export const PRODUCT_ITEM_DISCOUNT_AFTER = `${PRODUCT}-${ITEM}.${DISCOUNT}.${AFTER}`;
|
|
38
|
+
export const PRODUCT_ITEM_FAVORITES_BUTTON_BEFORE = `${PRODUCT}-${ITEM}.${FAVORITES_BUTTON}.${BEFORE}`;
|
|
39
|
+
export const PRODUCT_ITEM_FAVORITES_BUTTON = `${PRODUCT}-${ITEM}.${FAVORITES_BUTTON}`;
|
|
40
|
+
export const PRODUCT_ITEM_FAVORITES_BUTTON_AFTER = `${PRODUCT}-${ITEM}.${FAVORITES_BUTTON}.${AFTER}`;
|
|
41
|
+
export const PRODUCT_ITEM_NAME_BEFORE = `${PRODUCT}-${ITEM}.${NAME}.${BEFORE}`;
|
|
42
|
+
export const PRODUCT_ITEM_NAME = `${PRODUCT}-${ITEM}.${NAME}`;
|
|
43
|
+
export const PRODUCT_ITEM_NAME_AFTER = `${PRODUCT}-${ITEM}.${NAME}.${AFTER}`;
|
|
44
|
+
export const PRODUCT_ITEM_PRICE_BEFORE = `${PRODUCT}-${ITEM}.${PRICE}.${BEFORE}`;
|
|
45
|
+
export const PRODUCT_ITEM_PRICE_INSIDE_BEFORE = `${PRODUCT}-${ITEM}-${INSIDE}.${PRICE}.${BEFORE}`;
|
|
46
|
+
export const PRODUCT_ITEM_PRICE = `${PRODUCT}-${ITEM}.${PRICE}`;
|
|
47
|
+
export const PRODUCT_ITEM_PRICE_INSIDE_AFTER = `${PRODUCT}-${ITEM}-${INSIDE}.${PRICE}.${AFTER}`;
|
|
48
|
+
export const PRODUCT_ITEM_PRICE_AFTER = `${PRODUCT}-${ITEM}.${PRICE}.${AFTER}`;
|
|
49
|
+
export const PRODUCT_ITEM_MANUFACTURER_BEFORE = `${PRODUCT}-${ITEM}.${MANUFACTURER}.${BEFORE}`;
|
|
50
|
+
export const PRODUCT_ITEM_MANUFACTURER = `${PRODUCT}-${ITEM}.${MANUFACTURER}`;
|
|
51
|
+
export const PRODUCT_ITEM_MANUFACTURER_AFTER = `${PRODUCT}-${ITEM}.${MANUFACTURER}.${AFTER}`;
|
|
52
|
+
export const PRODUCT_ITEM_AVAILABILITY_BEFORE = `${PRODUCT}-${ITEM}.${AVAILABILITY}.${BEFORE}`;
|
|
53
|
+
export const PRODUCT_ITEM_AVAILABILITY = `${PRODUCT}-${ITEM}.${AVAILABILITY}`;
|
|
54
|
+
export const PRODUCT_ITEM_AVAILABILITY_AFTER = `${PRODUCT}-${ITEM}.${AVAILABILITY}.${AFTER}`;
|
|
55
|
+
export const NAV_MENU_CATEGORIES_BEFORE = `${NAV_MENU}.${CATEGORIES}.${BEFORE}`;
|
|
56
|
+
export const NAV_MENU_CATEGORIES = `${NAV_MENU}.${CATEGORIES}`;
|
|
57
|
+
export const NAV_MENU_CATEGORIES_AFTER = `${NAV_MENU}.${CATEGORIES}.${AFTER}`;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export const CATEGORY_PATH = '/category';
|
|
2
|
+
export const ROOT_CATEGORY_PATTERN = CATEGORY_PATH;
|
|
3
|
+
export const CATEGORY_PATTERN = `${CATEGORY_PATH}/:categoryId`;
|
|
4
|
+
export const CATEGORY_FILTER_PATTERN = `${CATEGORY_PATH}/:categoryId/filter`;
|
|
5
|
+
export const CATEGORY_ALL_PATTERN = `${CATEGORY_PATH}/:categoryId/all`;
|
|
6
|
+
export const CATEGORY_ALL_FILTER_PATTERN = `${CATEGORY_PATH}/:categoryId/all/filter`;
|
|
7
|
+
export const CATEGORY_LIFETIME = 3600000; // 1 hour in milliseconds
|
|
8
|
+
|
|
9
|
+
export const REQUEST_ROOT_CATEGORIES = 'REQUEST_ROOT_CATEGORIES';
|
|
10
|
+
export const RECEIVE_ROOT_CATEGORIES = 'RECEIVE_ROOT_CATEGORIES';
|
|
11
|
+
export const ERROR_ROOT_CATEGORIES = 'ERROR_ROOT_CATEGORIES';
|
|
12
|
+
export const REQUEST_CATEGORY = 'REQUEST_CATEGORY';
|
|
13
|
+
export const RECEIVE_CATEGORY = 'RECEIVE_CATEGORY';
|
|
14
|
+
export const ERROR_CATEGORY = 'ERROR_CATEGORY';
|
|
15
|
+
export const REQUEST_CATEGORY_CHILDREN = 'REQUEST_CATEGORY_CHILDREN';
|
|
16
|
+
export const RECEIVE_CATEGORY_CHILDREN = 'RECEIVE_CATEGORY_CHILDREN';
|
|
17
|
+
export const ERROR_CATEGORY_CHILDREN = 'ERROR_CATEGORY_CHILDREN';
|
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
import{bin2hex}from'@shopgate/pwa-common/helpers/data';
|
|
1
|
+
import { bin2hex } from '@shopgate/pwa-common/helpers/data';
|
|
2
|
+
import { i18n } from '@shopgate/engage/core';
|
|
3
|
+
import { CATEGORY_PATH } from "../constants";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Generate category route for navigation.
|
|
3
7
|
* @param {string} id category Id
|
|
4
8
|
* @returns {string}
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
export const getCategoryRoute = id => `${CATEGORY_PATH}/${bin2hex(id)}`;
|
|
11
|
+
|
|
12
|
+
/**
|
|
6
13
|
* Generate filters for show all products.
|
|
7
14
|
* @param {Object} parentCategory parent category
|
|
8
15
|
* @returns {Object}
|
|
9
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
export const getShowAllProductsFilters = parentCategory => {
|
|
18
|
+
const filters = {
|
|
19
|
+
categories: {
|
|
20
|
+
id: 'categories',
|
|
21
|
+
label: i18n.text('filter.label.category'),
|
|
22
|
+
source: 'categories',
|
|
23
|
+
type: 'multiselect',
|
|
24
|
+
value: [{
|
|
25
|
+
id: parentCategory ? parentCategory.path : null,
|
|
26
|
+
label: parentCategory ? parentCategory.name : null,
|
|
27
|
+
isHidden: true,
|
|
28
|
+
useForFetchFilters: true
|
|
29
|
+
}]
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return filters;
|
|
33
|
+
};
|
package/category/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
// ACTIONS
|
|
2
|
-
export{default as fetchCategory
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
2
|
+
export { default as fetchCategory } from "./actions/fetchCategory";
|
|
3
|
+
export { default as fetchCategoryOrRootCategories } from "./actions/fetchCategoryOrRootCategories";
|
|
4
|
+
export { default as fetchCategoryChildren } from "./actions/fetchCategoryChildren";
|
|
5
|
+
export { default as fetchCategoryProducts } from "./actions/fetchCategoryProducts";
|
|
6
|
+
export { default as fetchRootCategories } from "./actions/fetchRootCategories";
|
|
7
|
+
|
|
8
|
+
// CONSTANTS
|
|
9
|
+
export * from "./constants/index";
|
|
10
|
+
export * from "./constants/Pipelines";
|
|
11
|
+
export * from "./constants/Portals";
|
|
12
|
+
|
|
13
|
+
// SELECTORS
|
|
14
|
+
export * from "./selectors";
|
|
15
|
+
|
|
16
|
+
// STREAMS
|
|
17
|
+
export * from "./streams";
|
|
18
|
+
|
|
19
|
+
// HELPERS
|
|
20
|
+
export * from "./helpers";
|
package/category/mock.js
CHANGED
|
@@ -1 +1,176 @@
|
|
|
1
|
-
|
|
1
|
+
const initialCategoryState = {
|
|
2
|
+
category: {
|
|
3
|
+
rootCategories: {},
|
|
4
|
+
categoriesById: {},
|
|
5
|
+
childrenByCategoryId: {},
|
|
6
|
+
currentCategoryId: null
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
const categoryState = {
|
|
10
|
+
category: {
|
|
11
|
+
rootCategories: {
|
|
12
|
+
categories: ['men', 'women'],
|
|
13
|
+
expires: 9999999999999,
|
|
14
|
+
isFetching: false
|
|
15
|
+
},
|
|
16
|
+
categoriesById: {
|
|
17
|
+
men: {
|
|
18
|
+
id: 'men',
|
|
19
|
+
name: 'Men',
|
|
20
|
+
parent: {
|
|
21
|
+
id: null,
|
|
22
|
+
name: 'Default- category'
|
|
23
|
+
},
|
|
24
|
+
path: 'Men',
|
|
25
|
+
description: '',
|
|
26
|
+
imageUrl: 'https://shopgate-public.s3.amazonaws.com/categories/24453/1346609@2x.jpg',
|
|
27
|
+
externalUrl: 'http://material-fashion.myshopify.com/collections/men',
|
|
28
|
+
sort: 0,
|
|
29
|
+
productCount: 6,
|
|
30
|
+
childrenSort: 'import',
|
|
31
|
+
childrenCount: 0,
|
|
32
|
+
children: [],
|
|
33
|
+
isFetching: false,
|
|
34
|
+
expires: 9999999999999
|
|
35
|
+
},
|
|
36
|
+
women: {
|
|
37
|
+
id: 'women',
|
|
38
|
+
name: 'Women',
|
|
39
|
+
parent: {
|
|
40
|
+
id: null,
|
|
41
|
+
name: 'Default- category'
|
|
42
|
+
},
|
|
43
|
+
path: 'Women',
|
|
44
|
+
description: '',
|
|
45
|
+
imageUrl: 'https://shopgate-public.s3.amazonaws.com/categories/24453/1346610@2x.jpg',
|
|
46
|
+
externalUrl: 'http://material-fashion.myshopify.com/collections/women',
|
|
47
|
+
sort: 0,
|
|
48
|
+
productCount: 6,
|
|
49
|
+
childrenSort: 'import',
|
|
50
|
+
childrenCount: 1,
|
|
51
|
+
children: [],
|
|
52
|
+
isFetching: false,
|
|
53
|
+
expires: 9999999999999
|
|
54
|
+
},
|
|
55
|
+
test: {
|
|
56
|
+
id: 'test',
|
|
57
|
+
name: 'test',
|
|
58
|
+
parent: {
|
|
59
|
+
id: 'women',
|
|
60
|
+
name: 'Women'
|
|
61
|
+
},
|
|
62
|
+
path: 'Default- category=>Women=>test',
|
|
63
|
+
description: '',
|
|
64
|
+
imageUrl: null,
|
|
65
|
+
externalUrl: '',
|
|
66
|
+
sort: 10001,
|
|
67
|
+
productCount: 0,
|
|
68
|
+
childrenSort: 'import',
|
|
69
|
+
childrenCount: 0,
|
|
70
|
+
children: [],
|
|
71
|
+
isFetching: false,
|
|
72
|
+
expires: 9999999999999
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
childrenByCategoryId: {
|
|
76
|
+
women: {
|
|
77
|
+
children: ['test'],
|
|
78
|
+
isFetching: false,
|
|
79
|
+
expires: 9999999999999
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
currentCategoryId: null
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const homeRoute = {
|
|
86
|
+
id: 'a4bf3a32-0ed8-4138-bb94-098f32f3aeb3',
|
|
87
|
+
params: {},
|
|
88
|
+
pathname: '/',
|
|
89
|
+
pattern: '/',
|
|
90
|
+
query: {},
|
|
91
|
+
state: {}
|
|
92
|
+
};
|
|
93
|
+
const categoryRouteMock = {
|
|
94
|
+
id: 'c8256921-3667-45d0-a0fe-a7a8bb5ed3b8',
|
|
95
|
+
params: {},
|
|
96
|
+
pathname: '/category',
|
|
97
|
+
pattern: '/category',
|
|
98
|
+
query: {},
|
|
99
|
+
state: {
|
|
100
|
+
title: 'Categories'
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const childCategoryRouteMock = {
|
|
104
|
+
id: '5a227cfd-c55a-4e9b-9deb-d2ee20154030',
|
|
105
|
+
params: {
|
|
106
|
+
categoryId: '776f6d656e'
|
|
107
|
+
},
|
|
108
|
+
pathname: '/category/776f6d656e',
|
|
109
|
+
pattern: '/category/:categoryId',
|
|
110
|
+
query: {},
|
|
111
|
+
state: {
|
|
112
|
+
title: 'Women'
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const routerState = {
|
|
116
|
+
router: {
|
|
117
|
+
routing: false,
|
|
118
|
+
stack: [{
|
|
119
|
+
...homeRoute
|
|
120
|
+
}]
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const uiState = {
|
|
124
|
+
ui: {
|
|
125
|
+
general: {}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const emptyState = {
|
|
129
|
+
...initialCategoryState,
|
|
130
|
+
category: {
|
|
131
|
+
...initialCategoryState.category,
|
|
132
|
+
categoriesById: {
|
|
133
|
+
test: {
|
|
134
|
+
id: 'test',
|
|
135
|
+
name: 'test',
|
|
136
|
+
parent: {
|
|
137
|
+
id: 'women',
|
|
138
|
+
name: 'Women'
|
|
139
|
+
},
|
|
140
|
+
path: 'Default- category=>Women=>test',
|
|
141
|
+
description: '',
|
|
142
|
+
imageUrl: null,
|
|
143
|
+
externalUrl: '',
|
|
144
|
+
sort: 10001,
|
|
145
|
+
productCount: 0,
|
|
146
|
+
childrenSort: 'import',
|
|
147
|
+
childrenCount: 0,
|
|
148
|
+
children: [],
|
|
149
|
+
isFetching: false,
|
|
150
|
+
expires: 9999999999999
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
product: {
|
|
155
|
+
resultsByHash: {}
|
|
156
|
+
},
|
|
157
|
+
filter: {
|
|
158
|
+
activeFilters: null
|
|
159
|
+
},
|
|
160
|
+
router: {
|
|
161
|
+
...routerState.router,
|
|
162
|
+
stack: [...routerState.router.stack, {
|
|
163
|
+
id: '5a227cfd-c55a-4e9b-9deb-d2ee20154030',
|
|
164
|
+
params: {
|
|
165
|
+
categoryId: '74657374'
|
|
166
|
+
},
|
|
167
|
+
pathname: '/category/74657374',
|
|
168
|
+
pattern: '/category/:categoryId',
|
|
169
|
+
query: {},
|
|
170
|
+
state: {
|
|
171
|
+
title: 'test'
|
|
172
|
+
}
|
|
173
|
+
}]
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
export { initialCategoryState, emptyState, categoryState, routerState, categoryRouteMock, childCategoryRouteMock, uiState };
|
|
@@ -1,7 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
import { ENOTFOUND } from '@shopgate/pwa-core/constants/Pipeline';
|
|
2
|
+
import { CATEGORY_LIFETIME, RECEIVE_ROOT_CATEGORIES, REQUEST_CATEGORY, RECEIVE_CATEGORY, RECEIVE_CATEGORY_CHILDREN, ERROR_CATEGORY } from "../constants";
|
|
3
|
+
import handleCategoryCollection from "./helpers/handleCategoryCollection";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Stores categories by their ID.
|
|
3
7
|
* @param {Object} [state={}] The current state.
|
|
4
8
|
* @param {Object} action The action object.
|
|
5
9
|
* @return {Object} The new state.
|
|
6
|
-
*/
|
|
7
|
-
|
|
10
|
+
*/
|
|
11
|
+
const categoriesById = (state = {}, action) => {
|
|
12
|
+
switch (action.type) {
|
|
13
|
+
case REQUEST_CATEGORY:
|
|
14
|
+
return {
|
|
15
|
+
...state,
|
|
16
|
+
[action.categoryId]: {
|
|
17
|
+
...state[action.categoryId],
|
|
18
|
+
expires: 0,
|
|
19
|
+
isFetching: true
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
case RECEIVE_CATEGORY:
|
|
23
|
+
{
|
|
24
|
+
const {
|
|
25
|
+
children: ignore,
|
|
26
|
+
...categoryData
|
|
27
|
+
} = action.categoryData;
|
|
28
|
+
return {
|
|
29
|
+
...state,
|
|
30
|
+
[action.categoryId]: {
|
|
31
|
+
...state[action.categoryId],
|
|
32
|
+
...categoryData,
|
|
33
|
+
expires: Date.now() + CATEGORY_LIFETIME,
|
|
34
|
+
isFetching: false
|
|
35
|
+
},
|
|
36
|
+
...handleCategoryCollection(action.categoryChildren)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
case RECEIVE_ROOT_CATEGORIES:
|
|
40
|
+
return {
|
|
41
|
+
...state,
|
|
42
|
+
...handleCategoryCollection(action.categories)
|
|
43
|
+
};
|
|
44
|
+
case RECEIVE_CATEGORY_CHILDREN:
|
|
45
|
+
return {
|
|
46
|
+
...state,
|
|
47
|
+
...handleCategoryCollection(action.categoryChildren)
|
|
48
|
+
};
|
|
49
|
+
case ERROR_CATEGORY:
|
|
50
|
+
if (action.errorCode === ENOTFOUND) {
|
|
51
|
+
// Remove the temporary entry from the state when noting was found for the categoryId.
|
|
52
|
+
const {
|
|
53
|
+
[action.categoryId]: ignore,
|
|
54
|
+
...rest
|
|
55
|
+
} = state;
|
|
56
|
+
return rest;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...state,
|
|
60
|
+
[action.categoryId]: {
|
|
61
|
+
...state[action.categoryId],
|
|
62
|
+
isFetching: false
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
default:
|
|
66
|
+
return state;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export default categoriesById;
|
|
@@ -1,8 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
import { ENOTFOUND } from '@shopgate/pwa-core/constants/Pipeline';
|
|
2
|
+
import { CATEGORY_LIFETIME, REQUEST_CATEGORY, RECEIVE_CATEGORY, REQUEST_CATEGORY_CHILDREN, RECEIVE_CATEGORY_CHILDREN, ERROR_CATEGORY, ERROR_CATEGORY_CHILDREN } from "../constants";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Stores a collection of child category IDs by their parent's category ID.
|
|
3
6
|
* @param {Object} [state={}] The current state.
|
|
4
7
|
* @param {Object} action The action object.
|
|
5
8
|
* @returns {Object} The new state.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
*/
|
|
10
|
+
const childrenByCategoryId = (state = {}, action) => {
|
|
11
|
+
switch (action.type) {
|
|
12
|
+
case REQUEST_CATEGORY:
|
|
13
|
+
case REQUEST_CATEGORY_CHILDREN:
|
|
14
|
+
return {
|
|
15
|
+
...state,
|
|
16
|
+
[action.categoryId]: {
|
|
17
|
+
...state[action.categoryId],
|
|
18
|
+
children: null,
|
|
19
|
+
isFetching: true,
|
|
20
|
+
expires: 0
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
case RECEIVE_CATEGORY:
|
|
24
|
+
case RECEIVE_CATEGORY_CHILDREN:
|
|
25
|
+
{
|
|
26
|
+
const actionChildren = action.categoryChildren;
|
|
27
|
+
return {
|
|
28
|
+
...state,
|
|
29
|
+
[action.categoryId]: {
|
|
30
|
+
...state[action.categoryId],
|
|
31
|
+
// If it has children, append them.
|
|
32
|
+
children: actionChildren ? action.categoryChildren.map(child => child.id) : null,
|
|
33
|
+
isFetching: false,
|
|
34
|
+
expires: Date.now() + CATEGORY_LIFETIME
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
case ERROR_CATEGORY:
|
|
39
|
+
case ERROR_CATEGORY_CHILDREN:
|
|
40
|
+
if (action.errorCode === ENOTFOUND) {
|
|
41
|
+
// Remove the temporary entry from the state when noting was found for the categoryId.
|
|
42
|
+
const {
|
|
43
|
+
[action.categoryId]: ignore,
|
|
44
|
+
...rest
|
|
45
|
+
} = state;
|
|
46
|
+
return rest;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...state,
|
|
50
|
+
[action.categoryId]: {
|
|
51
|
+
...state[action.categoryId],
|
|
52
|
+
isFetching: false
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
default:
|
|
56
|
+
return state;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
export default childrenByCategoryId;
|
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { CATEGORY_LIFETIME } from "../../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Builds state entries from a collection of categories.
|
|
3
5
|
* @param {Array} collection A category collection.
|
|
4
6
|
* @return {Object} The category entries for the state.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
+
*/
|
|
8
|
+
const handleCategoryCollection = collection => {
|
|
9
|
+
const categoryObjects = {};
|
|
10
|
+
// Is used to set them all to the same date because they arrived at the same time.
|
|
11
|
+
const expires = Date.now() + CATEGORY_LIFETIME;
|
|
12
|
+
if (!collection) {
|
|
13
|
+
return categoryObjects;
|
|
14
|
+
}
|
|
15
|
+
collection.forEach(category => {
|
|
16
|
+
const {
|
|
17
|
+
...categoryData
|
|
18
|
+
} = category;
|
|
19
|
+
categoryObjects[category.id] = {
|
|
20
|
+
...categoryData,
|
|
21
|
+
isFetching: false,
|
|
22
|
+
expires
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
return categoryObjects;
|
|
26
|
+
};
|
|
27
|
+
export default handleCategoryCollection;
|
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
* Handles the received category id's by mapping to store and returning results.
|
|
3
3
|
* @param {Array} categories The received categories.
|
|
4
4
|
* @returns {Array} An array of category objects.
|
|
5
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
const handleReceivedCategories = categories => categories.length ? categories.map(category => category.id) : null;
|
|
7
|
+
export default handleReceivedCategories;
|