@jetshop/core 5.9.0 → 5.11.2
Sign up to get free protection for your applications and to get access to all the features.
- package/ChannelHandler/ChannelHandler.d.ts +9 -13
- package/ChannelHandler/ChannelHandler.js +24 -66
- package/ChannelHandler/ChannelHandler.js.map +1 -1
- package/ChannelHandler/channelUtils.d.ts +13 -0
- package/ChannelHandler/channelUtils.js +26 -15
- package/ChannelHandler/channelUtils.js.map +1 -1
- package/ChannelHandler/redirectUtils.d.ts +3 -0
- package/ChannelHandler/redirectUtils.js +48 -0
- package/ChannelHandler/redirectUtils.js.map +1 -0
- package/ChannelHandler/redirectUtils.test.js +8 -0
- package/analytics/AnalyticsProvider.js +2 -1
- package/analytics/AnalyticsProvider.js.map +1 -1
- package/analytics/integrations/ga4.js +10 -1
- package/analytics/integrations/ga4.js.map +1 -1
- package/analytics/integrations/gtag/gtag.d.ts +0 -1
- package/analytics/integrations/gtag/gtag.js +48 -28
- package/analytics/integrations/gtag/gtag.js.map +1 -1
- package/analytics/integrations/gtm/index.d.ts +2 -2
- package/analytics/integrations/gtm/index.js +40 -27
- package/analytics/integrations/gtm/index.js.map +1 -1
- package/analytics/integrations/unslugify.d.ts +1 -0
- package/analytics/integrations/unslugify.js +16 -0
- package/analytics/integrations/unslugify.js.map +1 -0
- package/analytics/trackerRegistry.d.ts +2 -0
- package/analytics/trackerRegistry.js.map +1 -1
- package/analytics/utils/breadcrumbsWithoutProduct.d.ts +1 -0
- package/analytics/utils/breadcrumbsWithoutProduct.js +9 -0
- package/analytics/utils/breadcrumbsWithoutProduct.js.map +1 -0
- package/boot/SharedTree.js +1 -1
- package/boot/SharedTree.js.map +1 -1
- package/boot/apollo.d.ts +5 -4
- package/boot/apollo.js +18 -18
- package/boot/apollo.js.map +1 -1
- package/boot/client/startClient.js +7 -16
- package/boot/client/startClient.js.map +1 -1
- package/boot/server/createRenderer.js +8 -7
- package/boot/server/createRenderer.js.map +1 -1
- package/boot/server/index.js +2 -2
- package/boot/server/index.js.map +1 -1
- package/boot/server/persistedQueries/__tests__/getPersistedQueriesForRequest.test.js +53 -39
- package/boot/server/persistedQueries/getPersistedQueriesForRequest.js +2 -2
- package/boot/server/persistedQueries/getPersistedQueriesForRequest.js.map +1 -1
- package/cart/AddToCartFormik.d.ts +2 -2
- package/cart/AddToCartFormik.js +11 -11
- package/cart/AddToCartFormik.js.map +1 -1
- package/cart/useAddToCart.d.ts +2 -2
- package/cart/useAddToCart.js +13 -12
- package/cart/useAddToCart.js.map +1 -1
- package/components/Auth/CustomerUpdateForm.js +7 -7
- package/components/Auth/CustomerUpdateForm.js.map +1 -1
- package/components/ChannelContext/ChannelProvider.d.ts +1 -3
- package/components/ChannelContext/ChannelProvider.js +6 -13
- package/components/ChannelContext/ChannelProvider.js.map +1 -1
- package/components/ChannelContext/ChannelProvider.test.js +112 -0
- package/components/DynamicRoute/ProductRoute.d.ts +1 -0
- package/components/DynamicRoute/ProductRoute.js +16 -6
- package/components/DynamicRoute/ProductRoute.js.map +1 -1
- package/components/DynamicRoute/RouteResolver.js +1 -1
- package/components/DynamicRoute/RouteResolver.js.map +1 -1
- package/components/Head.js +4 -4
- package/components/Head.js.map +1 -1
- package/components/Mutation/AddToCart/addToCartUtils.d.ts +1 -1
- package/components/Mutation/AddToCart/addToCartUtils.js +10 -3
- package/components/Mutation/AddToCart/addToCartUtils.js.map +1 -1
- package/components/Mutation/RemoveFromCart.d.ts +1 -1
- package/components/Mutation/RemoveFromCart.js +10 -1
- package/components/Mutation/RemoveFromCart.js.map +1 -1
- package/components/Mutation/cartMutationUtils.js +7 -6
- package/components/Mutation/cartMutationUtils.js.map +1 -1
- package/components/Mutation/useDecrementQuantity.js +8 -3
- package/components/Mutation/useDecrementQuantity.js.map +1 -1
- package/components/Mutation/useIncrementQuantity.js +8 -3
- package/components/Mutation/useIncrementQuantity.js.map +1 -1
- package/components/Mutation/useRemoveFromCart.js +10 -1
- package/components/Mutation/useRemoveFromCart.js.map +1 -1
- package/components/OpenGraph/OpenGraphProductData.js +3 -3
- package/components/OpenGraph/OpenGraphProductData.js.map +1 -1
- package/components/Query/CartProvider.js +32 -22
- package/components/Query/CartProvider.js.map +1 -1
- package/components/StructuredData/StructuredBreadcrumbData.d.ts +8 -3
- package/components/StructuredData/StructuredBreadcrumbData.js +42 -23
- package/components/StructuredData/StructuredBreadcrumbData.js.map +1 -1
- package/components/StructuredData/StructuredProductData.js +2 -2
- package/components/StructuredData/StructuredProductData.js.map +1 -1
- package/data/fragments/ProductListsFragments.gql +94 -0
- package/data/fragments/RouteMetaFragment.gql +18 -0
- package/data/mutations/productListMutations.gql +18 -0
- package/data/queries/ProductLists.gql +8 -0
- package/dependencies.d.ts +10 -1
- package/helpers/isRelativeUrl.d.ts +1 -0
- package/helpers/isRelativeUrl.js +5 -0
- package/helpers/isRelativeUrl.js.map +1 -0
- package/hooks/PackageProducts/usePackageProductItem.d.ts +2 -2
- package/hooks/ProductList/ProductListContext.js +49 -14
- package/hooks/ProductList/ProductListContext.js.map +1 -1
- package/hooks/ProductList/ProductLists.gql +0 -0
- package/hooks/ProductList/action-creators.d.ts +20 -7
- package/hooks/ProductList/action-creators.js +138 -44
- package/hooks/ProductList/action-creators.js.map +1 -1
- package/hooks/ProductList/index.d.ts +34 -8
- package/hooks/ProductList/index.js +19 -0
- package/hooks/ProductList/index.js.map +1 -1
- package/hooks/ProductList/list-transforms.d.ts +3 -2
- package/hooks/ProductList/list-transforms.js +22 -22
- package/hooks/ProductList/list-transforms.js.map +1 -1
- package/hooks/ProductList/list-transforms.test.js +103 -100
- package/hooks/ProductList/product-list-reducer.d.ts +37 -14
- package/hooks/ProductList/product-list-reducer.js +106 -43
- package/hooks/ProductList/product-list-reducer.js.map +1 -1
- package/hooks/ProductList/product-list-reducer.test.js +144 -82
- package/hooks/ProductList/useProductList.d.ts +2 -2
- package/hooks/ProductList/useProductList.js +12 -5
- package/hooks/ProductList/useProductList.js.map +1 -1
- package/hooks/ProductList/useProductListItems.d.ts +1 -1
- package/hooks/ProductList/useProductListItems.js +8 -6
- package/hooks/ProductList/useProductListItems.js.map +1 -1
- package/hooks/useAddMultipleToCart.js +11 -5
- package/hooks/useAddMultipleToCart.js.map +1 -1
- package/hooks/useProductVariants/useProductVariants.d.ts +1 -2
- package/hooks/useProductVariants/useProductVariants.js +1 -1
- package/hooks/useProductVariants/useProductVariants.js.map +1 -1
- package/hooks/useRoutePreload.js +2 -2
- package/hooks/useRoutePreload.js.map +1 -1
- package/package.json +5 -5
- package/resolvers/index.d.ts +3 -0
- package/resolvers/index.js +3 -0
- package/resolvers/index.js.map +1 -1
- package/sentry/client.js +9 -4
- package/sentry/client.js.map +1 -1
- package/sentry/common.d.ts +1 -0
- package/sentry/common.js +5 -0
- package/sentry/common.js.map +1 -0
- package/sentry/server.js +11 -2
- package/sentry/server.js.map +1 -1
- package/server/tracking/types.d.ts +1 -1
- package/time.d.ts +1 -0
- package/time.js +6 -0
- package/time.js.map +1 -0
- package/types.d.ts +1 -0
@@ -1,12 +1,12 @@
|
|
1
1
|
import { FlattenedProductListItem, NormalizedProductList, ProductsQuery } from '.';
|
2
|
-
import {
|
2
|
+
import { CustomerProductList, Product } from '../../types';
|
3
3
|
/**
|
4
4
|
* Converts a product list returned from the API to our normalized structure
|
5
5
|
* When a base product is selected, it will have a value for `options`.
|
6
6
|
* When it has variants, it will have one or more keys for `variants`
|
7
7
|
* Either variants or options may be null, but not both.
|
8
8
|
*/
|
9
|
-
export declare function normalizeServerList(
|
9
|
+
export declare function normalizeServerList(productList: CustomerProductList): NormalizedProductList;
|
10
10
|
/**
|
11
11
|
* Takes a flattened product list and result of a products query and returns
|
12
12
|
* product details for each item in the flattened list. */
|
@@ -35,6 +35,7 @@ productQueryResult: ProductsQuery): {
|
|
35
35
|
categories?: import("../../types").Category[];
|
36
36
|
campaigns?: import("../../types").Category[];
|
37
37
|
hasVariants: boolean;
|
38
|
+
hasVariantsWithDifferingPrices: boolean;
|
38
39
|
variants?: import("../../types").ProductVariants;
|
39
40
|
images?: import("../../types").ProductImage[];
|
40
41
|
relatedProducts?: Product[];
|
@@ -6,39 +6,39 @@ import { validateProduct } from './validate-product';
|
|
6
6
|
* When it has variants, it will have one or more keys for `variants`
|
7
7
|
* Either variants or options may be null, but not both.
|
8
8
|
*/
|
9
|
-
export function normalizeServerList(
|
9
|
+
export function normalizeServerList(productList) {
|
10
10
|
var _a, _b, _c, _d, _e;
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
const items = productList.items;
|
12
|
+
const newList = {
|
13
|
+
name: productList.name,
|
14
|
+
items: {}
|
15
|
+
};
|
16
16
|
for (const item of items) {
|
17
17
|
// skip if product is hidden
|
18
18
|
if (!((_a = item === null || item === void 0 ? void 0 : item.product) === null || _a === void 0 ? void 0 : _a.articleNumber)) {
|
19
19
|
continue;
|
20
20
|
}
|
21
21
|
if (item.variant) {
|
22
|
-
newList[item.product.articleNumber] = {
|
23
|
-
options: ((_b = newList[item.product.articleNumber]) === null || _b === void 0 ? void 0 : _b.options) || null,
|
24
|
-
variants: produce(((_c = newList[item.product.articleNumber]) === null || _c === void 0 ? void 0 : _c.variants) || {}, (draft) => {
|
22
|
+
newList.items[item.product.articleNumber] = {
|
23
|
+
options: ((_b = newList.items[item.product.articleNumber]) === null || _b === void 0 ? void 0 : _b.options) || null,
|
24
|
+
variants: produce(((_c = newList.items[item.product.articleNumber]) === null || _c === void 0 ? void 0 : _c.variants) || {}, (draft) => {
|
25
25
|
draft[item.variant.articleNumber] = {
|
26
26
|
options: {
|
27
27
|
quantity: item.quantity || 1,
|
28
|
-
description: item.description
|
28
|
+
description: item.description
|
29
29
|
},
|
30
|
-
parentArticleNumber: item.product.articleNumber
|
30
|
+
parentArticleNumber: item.product.articleNumber
|
31
31
|
};
|
32
|
-
})
|
32
|
+
})
|
33
33
|
};
|
34
34
|
}
|
35
35
|
else {
|
36
|
-
newList[item.product.articleNumber] = {
|
37
|
-
variants: ((_d = newList[item.product.articleNumber]) === null || _d === void 0 ? void 0 : _d.variants) || null,
|
36
|
+
newList.items[item.product.articleNumber] = {
|
37
|
+
variants: ((_d = newList.items[item.product.articleNumber]) === null || _d === void 0 ? void 0 : _d.variants) || null,
|
38
38
|
options: {
|
39
39
|
quantity: (_e = item.quantity) !== null && _e !== void 0 ? _e : 1,
|
40
|
-
description: item.description
|
41
|
-
}
|
40
|
+
description: item.description
|
41
|
+
}
|
42
42
|
};
|
43
43
|
}
|
44
44
|
}
|
@@ -76,29 +76,29 @@ export function getVariantFromProductDetails(variant, product) {
|
|
76
76
|
}
|
77
77
|
export function flattenList(list) {
|
78
78
|
const flattenedList = [];
|
79
|
-
const baseProducts = list ? Object.keys(list) : [];
|
79
|
+
const baseProducts = list ? Object.keys(list.items) : [];
|
80
80
|
for (const baseArticleNumber of baseProducts) {
|
81
|
-
const variants = list[baseArticleNumber].variants;
|
81
|
+
const variants = list.items[baseArticleNumber].variants;
|
82
82
|
if (variants) {
|
83
83
|
const variantArticleNumbers = Object.keys(variants);
|
84
84
|
for (const articleNumber of variantArticleNumbers) {
|
85
85
|
flattenedList.push({
|
86
86
|
articleNumber,
|
87
87
|
parentArticleNumber: baseArticleNumber,
|
88
|
-
options: variants[articleNumber].options
|
88
|
+
options: variants[articleNumber].options
|
89
89
|
});
|
90
90
|
}
|
91
|
-
if (list[baseArticleNumber].options) {
|
91
|
+
if (list.items[baseArticleNumber].options) {
|
92
92
|
flattenedList.push({
|
93
93
|
articleNumber: baseArticleNumber,
|
94
|
-
options: list[baseArticleNumber].options
|
94
|
+
options: list.items[baseArticleNumber].options
|
95
95
|
});
|
96
96
|
}
|
97
97
|
}
|
98
98
|
else {
|
99
99
|
flattenedList.push({
|
100
100
|
articleNumber: baseArticleNumber,
|
101
|
-
options: list[baseArticleNumber].options
|
101
|
+
options: list.items[baseArticleNumber].options
|
102
102
|
});
|
103
103
|
}
|
104
104
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"list-transforms.js","sourceRoot":"","sources":["list-transforms.ts"],"names":[],"mappings":"AAAA,O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,CAAC,CAAC,OAAO;iBAC/C,CAAC,CAAC;aACJ;SACF;aAAM;YACL,aAAa,CAAC,IAAI,CAAC;gBACjB,aAAa,EAAE,iBAAiB;gBAChC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,OAAO;aAC/C,CAAC,CAAC;SACJ;KACF;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
@@ -5,8 +5,8 @@ import {
|
|
5
5
|
normalizeServerList
|
6
6
|
} from './list-transforms';
|
7
7
|
|
8
|
-
const
|
9
|
-
|
8
|
+
const MOCK_LIST_ITEMS = {
|
9
|
+
6952315: {
|
10
10
|
options: { quantity: 1 },
|
11
11
|
variants: {
|
12
12
|
'6952315-170-white': {
|
@@ -17,7 +17,7 @@ const MOCK_LIST = {
|
|
17
17
|
}
|
18
18
|
}
|
19
19
|
},
|
20
|
-
|
20
|
+
502935480: {
|
21
21
|
variants: null,
|
22
22
|
options: {
|
23
23
|
quantity: 1
|
@@ -161,8 +161,7 @@ const MOCK_PRODUCT_QUERY_RESULT = {
|
|
161
161
|
{
|
162
162
|
alt: '441728',
|
163
163
|
title: 'Belt Light',
|
164
|
-
url:
|
165
|
-
'https://www.demostore.se/pub_images/original/VARIANTIMAGE.jpg',
|
164
|
+
url: 'https://www.demostore.se/pub_images/original/VARIANTIMAGE.jpg',
|
166
165
|
__typename: 'ProductImage'
|
167
166
|
}
|
168
167
|
],
|
@@ -181,8 +180,7 @@ const MOCK_PRODUCT_QUERY_RESULT = {
|
|
181
180
|
{
|
182
181
|
alt: 'Belt Light',
|
183
182
|
title: 'Belt Light',
|
184
|
-
url:
|
185
|
-
'https://www.demostore.se/pub_images/original/441728.jpg',
|
183
|
+
url: 'https://www.demostore.se/pub_images/original/441728.jpg',
|
186
184
|
__typename: 'ProductImage'
|
187
185
|
}
|
188
186
|
],
|
@@ -201,8 +199,7 @@ const MOCK_PRODUCT_QUERY_RESULT = {
|
|
201
199
|
{
|
202
200
|
alt: 'Belt Light',
|
203
201
|
title: 'Belt Light',
|
204
|
-
url:
|
205
|
-
'https://www.demostore.se/pub_images/original/441728.jpg',
|
202
|
+
url: 'https://www.demostore.se/pub_images/original/441728.jpg',
|
206
203
|
__typename: 'ProductImage'
|
207
204
|
}
|
208
205
|
],
|
@@ -245,8 +242,7 @@ const MOCK_PRODUCT_QUERY_RESULT = {
|
|
245
242
|
badges: [
|
246
243
|
{
|
247
244
|
name: 'SALE Top Left',
|
248
|
-
url:
|
249
|
-
'https://www.demostore.se/M1/production/images/overlay/overlay8_en-GB.png',
|
245
|
+
url: 'https://www.demostore.se/M1/production/images/overlay/overlay8_en-GB.png',
|
250
246
|
location: 'TOP_LEFT',
|
251
247
|
style: '',
|
252
248
|
text: '',
|
@@ -268,7 +264,10 @@ const MOCK_PRODUCT_QUERY_RESULT = {
|
|
268
264
|
|
269
265
|
describe('flattenList', () => {
|
270
266
|
it('takes a normalized list and returns an array of items', () => {
|
271
|
-
const flattened = flattenList(
|
267
|
+
const flattened = flattenList({
|
268
|
+
name: 'My list',
|
269
|
+
items: MOCK_LIST_ITEMS
|
270
|
+
});
|
272
271
|
|
273
272
|
expect(flattened).toMatchSnapshot();
|
274
273
|
});
|
@@ -277,16 +276,19 @@ describe('flattenList', () => {
|
|
277
276
|
const options = { quantity: 1 };
|
278
277
|
|
279
278
|
const list = {
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
279
|
+
name: 'My list',
|
280
|
+
items: {
|
281
|
+
baseProduct: {
|
282
|
+
options: null,
|
283
|
+
variants: {
|
284
|
+
'variant-one': {
|
285
|
+
options,
|
286
|
+
parentArticleNumber: 'baseProduct'
|
287
|
+
},
|
288
|
+
'variant-two': {
|
289
|
+
options,
|
290
|
+
parentArticleNumber: 'baseProduct'
|
291
|
+
}
|
290
292
|
}
|
291
293
|
}
|
292
294
|
}
|
@@ -301,16 +303,19 @@ describe('flattenList', () => {
|
|
301
303
|
const options = { quantity: 1 };
|
302
304
|
|
303
305
|
const list = {
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
306
|
+
name: 'My funky list',
|
307
|
+
items: {
|
308
|
+
baseProduct: {
|
309
|
+
options: options,
|
310
|
+
variants: {
|
311
|
+
'variant-one': {
|
312
|
+
options,
|
313
|
+
parentArticleNumber: 'baseProduct'
|
314
|
+
},
|
315
|
+
'variant-two': {
|
316
|
+
options,
|
317
|
+
parentArticleNumber: 'baseProduct'
|
318
|
+
}
|
314
319
|
}
|
315
320
|
}
|
316
321
|
}
|
@@ -341,7 +346,7 @@ describe('getVariantFromProductDetails', () => {
|
|
341
346
|
|
342
347
|
expect(result).toBe(
|
343
348
|
MOCK_PRODUCT_WITH_VARIANTS.variants.values.find(
|
344
|
-
variant => variant.articleNumber === '441728-37'
|
349
|
+
(variant) => variant.articleNumber === '441728-37'
|
345
350
|
)
|
346
351
|
);
|
347
352
|
});
|
@@ -396,91 +401,89 @@ describe('normalizeServerList', () => {
|
|
396
401
|
let serverList;
|
397
402
|
beforeEach(() => {
|
398
403
|
serverList = {
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
articleNumber: 'without-variants'
|
406
|
-
},
|
407
|
-
variant: null
|
404
|
+
items: [
|
405
|
+
{
|
406
|
+
quantity: 1,
|
407
|
+
description: 'hello',
|
408
|
+
product: {
|
409
|
+
articleNumber: 'without-variants'
|
408
410
|
},
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
articleNumber: 'the-variant'
|
417
|
-
}
|
411
|
+
variant: null
|
412
|
+
},
|
413
|
+
{
|
414
|
+
quantity: 1,
|
415
|
+
description: 'hello',
|
416
|
+
product: {
|
417
|
+
articleNumber: 'with-variants'
|
418
418
|
},
|
419
|
-
{
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
419
|
+
variant: {
|
420
|
+
articleNumber: 'the-variant'
|
421
|
+
}
|
422
|
+
},
|
423
|
+
{
|
424
|
+
quantity: 1,
|
425
|
+
description: 'hello',
|
426
|
+
product: {
|
427
|
+
articleNumber: 'with-many-variants'
|
428
428
|
},
|
429
|
-
{
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
429
|
+
variant: {
|
430
|
+
articleNumber: 'variant-one'
|
431
|
+
}
|
432
|
+
},
|
433
|
+
{
|
434
|
+
quantity: 1,
|
435
|
+
description: 'hello',
|
436
|
+
product: {
|
437
|
+
articleNumber: 'with-many-variants'
|
438
438
|
},
|
439
|
-
{
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
439
|
+
variant: {
|
440
|
+
articleNumber: 'variant-two'
|
441
|
+
}
|
442
|
+
},
|
443
|
+
{
|
444
|
+
quantity: 1,
|
445
|
+
description: 'hello',
|
446
|
+
product: {
|
447
|
+
articleNumber: 'with-base-and-variants'
|
446
448
|
},
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
449
|
+
variant: null
|
450
|
+
},
|
451
|
+
{
|
452
|
+
quantity: 1,
|
453
|
+
description: 'hello',
|
454
|
+
product: {
|
455
|
+
articleNumber: 'with-base-and-variants'
|
456
|
+
},
|
457
|
+
variant: {
|
458
|
+
articleNumber: 'variant-one'
|
456
459
|
}
|
457
|
-
|
458
|
-
|
460
|
+
}
|
461
|
+
]
|
459
462
|
};
|
460
463
|
});
|
461
|
-
it('returns an empty object if an invalid list if passed in', () => {
|
462
|
-
const result = normalizeServerList({ not: 'a list' });
|
463
464
|
|
464
|
-
expect(result).toEqual({});
|
465
|
-
});
|
466
465
|
it('creates the expected shape', () => {
|
467
466
|
const result = normalizeServerList(serverList);
|
468
467
|
|
469
|
-
expect(result['without-variants'].variants).toBe(null);
|
470
|
-
expect(result['without-variants'].options.quantity).toBe(1);
|
468
|
+
expect(result.items['without-variants'].variants).toBe(null);
|
469
|
+
expect(result.items['without-variants'].options.quantity).toBe(1);
|
471
470
|
|
472
|
-
expect(result['with-variants'].options).toBe(null);
|
471
|
+
expect(result.items['with-variants'].options).toBe(null);
|
473
472
|
expect(
|
474
|
-
result['with-variants'].variants['the-variant'].options.quantity
|
473
|
+
result.items['with-variants'].variants['the-variant'].options.quantity
|
475
474
|
).toBe(1);
|
476
475
|
|
477
|
-
expect(result['with-many-variants'].options).toBe(null);
|
478
|
-
expect(
|
479
|
-
|
476
|
+
expect(result.items['with-many-variants'].options).toBe(null);
|
477
|
+
expect(
|
478
|
+
result.items['with-many-variants'].variants['variant-one']
|
479
|
+
).toBeDefined();
|
480
|
+
expect(
|
481
|
+
result.items['with-many-variants'].variants['variant-two']
|
482
|
+
).toBeDefined();
|
480
483
|
|
481
|
-
expect(result['with-base-and-variants'].options).toBeDefined();
|
484
|
+
expect(result.items['with-base-and-variants'].options).toBeDefined();
|
482
485
|
expect(
|
483
|
-
result['with-base-and-variants'].variants['variant-one']
|
486
|
+
result.items['with-base-and-variants'].variants['variant-one']
|
484
487
|
).toBeDefined();
|
485
488
|
});
|
486
489
|
});
|
@@ -1,20 +1,15 @@
|
|
1
|
-
|
2
|
-
import { ProductListState, ProductListItemOptions, UpdateListOptions, NormalizedProductList } from '.';
|
1
|
+
import { ProductListMap, ProductListState, ProductListItemOptions, ProductListId, UpdateListOptions, NormalizedProductList } from '.';
|
3
2
|
export declare function reducer(state: ProductListState, action: Action): ProductListState;
|
4
|
-
export declare function init(initialState: ProductListState): ProductListState
|
5
|
-
|
6
|
-
loggedIn: boolean;
|
7
|
-
requestIdRef: import("react").MutableRefObject<string>;
|
8
|
-
};
|
9
|
-
export declare function addVariantToList(state: ProductListState, articleNumber: string, { variantArticleNumber, options }: {
|
3
|
+
export declare function init(initialState: ProductListState): ProductListState;
|
4
|
+
export declare function addVariantToList(state: ProductListState, listId: ProductListId, articleNumber: string, { variantArticleNumber, options }: {
|
10
5
|
variantArticleNumber?: string;
|
11
6
|
options: ProductListItemOptions;
|
12
7
|
}): ProductListState;
|
13
|
-
export declare function addBaseProductToList(state: ProductListState, articleNumber: string, options: ProductListItemOptions): ProductListState;
|
14
|
-
export declare function removeFromList(state: ProductListState, articleNumber: string, { variantArticleNumber }: {
|
8
|
+
export declare function addBaseProductToList(state: ProductListState, listId: ProductListId, articleNumber: string, options: ProductListItemOptions): ProductListState;
|
9
|
+
export declare function removeFromList(state: ProductListState, listId: ProductListId, articleNumber: string, { variantArticleNumber }: {
|
15
10
|
variantArticleNumber?: string;
|
16
11
|
}): ProductListState;
|
17
|
-
export declare function replaceItemInList(state: ProductListState, articleNumber: string, { variantToReplace, variantArticleNumber, options }: {
|
12
|
+
export declare function replaceItemInList(state: ProductListState, listId: ProductListId, articleNumber: string, { variantToReplace, variantArticleNumber, options }: {
|
18
13
|
variantToReplace?: string;
|
19
14
|
variantArticleNumber: string;
|
20
15
|
options: ProductListItemOptions;
|
@@ -22,6 +17,7 @@ export declare function replaceItemInList(state: ProductListState, articleNumber
|
|
22
17
|
export declare type Action = {
|
23
18
|
type: 'UPDATE';
|
24
19
|
payload: {
|
20
|
+
listId: ProductListId;
|
25
21
|
articleNumber: string;
|
26
22
|
variantArticleNumber: string;
|
27
23
|
variantToReplace?: string;
|
@@ -30,6 +26,7 @@ export declare type Action = {
|
|
30
26
|
} | {
|
31
27
|
type: 'ADD';
|
32
28
|
payload: {
|
29
|
+
listId: ProductListId;
|
33
30
|
articleNumber: string;
|
34
31
|
variantArticleNumber?: string;
|
35
32
|
options: UpdateListOptions;
|
@@ -37,17 +34,43 @@ export declare type Action = {
|
|
37
34
|
} | {
|
38
35
|
type: 'REMOVE';
|
39
36
|
payload: {
|
37
|
+
listId: ProductListId;
|
40
38
|
articleNumber: string;
|
41
39
|
variantArticleNumber?: string;
|
42
40
|
};
|
43
41
|
} | {
|
44
|
-
type: '
|
42
|
+
type: 'CLEAR_ITEMS';
|
43
|
+
payload: {
|
44
|
+
listId: ProductListId;
|
45
|
+
};
|
45
46
|
} | {
|
46
47
|
type: 'LOGOUT';
|
47
48
|
} | {
|
48
49
|
type: 'LOGIN';
|
49
|
-
payload:
|
50
|
+
payload: {
|
51
|
+
listId: ProductListId;
|
52
|
+
list: NormalizedProductList;
|
53
|
+
};
|
50
54
|
} | {
|
51
55
|
type: 'REPLACE';
|
52
|
-
payload:
|
56
|
+
payload: {
|
57
|
+
listId: ProductListId;
|
58
|
+
list: NormalizedProductList;
|
59
|
+
};
|
60
|
+
} | {
|
61
|
+
type: 'CREATE_LIST';
|
62
|
+
payload: {
|
63
|
+
listId: ProductListId;
|
64
|
+
list: NormalizedProductList;
|
65
|
+
};
|
66
|
+
} | {
|
67
|
+
type: 'SET_LISTS';
|
68
|
+
payload: {
|
69
|
+
lists: ProductListMap;
|
70
|
+
};
|
71
|
+
} | {
|
72
|
+
type: 'DELETE_LIST';
|
73
|
+
payload: {
|
74
|
+
listId: ProductListId;
|
75
|
+
};
|
53
76
|
};
|