@crystaldesign/widget-library 25.9.0-beta.6 → 25.9.0-beta.7

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.
@@ -3,6 +3,7 @@ import { useDivaCore, getLogger, DivaError, useTranslation } from '@crystaldesig
3
3
  import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
4
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
5
  import _regeneratorRuntime from '@babel/runtime/regenerator';
6
+ import DivaUtils from '@crystaldesign/diva-utils';
6
7
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
7
8
  import { Navigation, Thumbs, Pagination } from 'swiper/modules';
8
9
  import { Swiper, SwiperSlide } from 'swiper/react';
@@ -290,6 +291,10 @@ function useProductData(_ref) {
290
291
  _useState8 = _slicedToArray(_useState7, 2),
291
292
  error = _useState8[0],
292
293
  setError = _useState8[1];
294
+ var _useState9 = useState(true),
295
+ _useState10 = _slicedToArray(_useState9, 2),
296
+ initialProduct = _useState10[0],
297
+ setInitialProduct = _useState10[1];
293
298
  var fetchProducts = useCallback(/*#__PURE__*/function () {
294
299
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(ids) {
295
300
  var productPromises, results, flattenedResults;
@@ -416,15 +421,39 @@ function useProductData(_ref) {
416
421
  }
417
422
  setError(false);
418
423
  setLoading(true);
419
- fetchProducts(normalizedProductIds).then(function (variants) {
420
- LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Successfully loaded ").concat(variants.length, " product variants"));
421
- setProductVariants(variants);
422
- var variantToUse = variants.find(function (v) {
423
- return v._id === normalizedProductIds[0];
424
- });
425
- setSelectedProduct(variantToUse !== null && variantToUse !== void 0 ? variantToUse : variants[0]);
426
- setLoading(false);
427
- })["catch"](function (error) {
424
+ fetchProducts(normalizedProductIds).then(/*#__PURE__*/function () {
425
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(variants) {
426
+ var variantToUse, _variantToUse$catCode;
427
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
428
+ while (1) switch (_context4.prev = _context4.next) {
429
+ case 0:
430
+ LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Successfully loaded ").concat(variants.length, " product variants"));
431
+ setProductVariants(variants);
432
+ variantToUse = variants.find(function (v) {
433
+ return v._id === normalizedProductIds[0];
434
+ });
435
+ setSelectedProduct(variantToUse !== null && variantToUse !== void 0 ? variantToUse : variants[0]);
436
+ setLoading(false);
437
+ if (!initialProduct) {
438
+ _context4.next = 10;
439
+ break;
440
+ }
441
+ DivaUtils.businessMetrics.setConfiguratorSessionId(undefined, true);
442
+ setInitialProduct(false);
443
+ _context4.next = 10;
444
+ return logSelectedProduct(normalizedProductIds[0], widgetType, variantToUse === null || variantToUse === void 0 ? void 0 : variantToUse.variantId, variantToUse === null || variantToUse === void 0 ? void 0 : variantToUse.modelName, variantToUse === null || variantToUse === void 0 || (_variantToUse$catCode = variantToUse.catCodex) === null || _variantToUse$catCode === void 0 ? void 0 : _variantToUse$catCode.toString(), variantToUse === null || variantToUse === void 0 ? void 0 : variantToUse.configuration.OrderSets.map(function (set) {
445
+ return set.SupplierGUID;
446
+ }), 'onWidgetInitialProduct');
447
+ case 10:
448
+ case "end":
449
+ return _context4.stop();
450
+ }
451
+ }, _callee4);
452
+ }));
453
+ return function (_x4) {
454
+ return _ref5.apply(this, arguments);
455
+ };
456
+ }())["catch"](function (error) {
428
457
  LOG.error(new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Error loading products"), {
429
458
  cause: error
430
459
  }));
@@ -434,17 +463,17 @@ function useProductData(_ref) {
434
463
  });
435
464
  }, [normalizedProductIds]);
436
465
  var setSelectedProductId = useCallback(/*#__PURE__*/function () {
437
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(productId) {
438
- var product, _variants2, _product;
439
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
440
- while (1) switch (_context4.prev = _context4.next) {
466
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(productId) {
467
+ var product, _product$catCodex, _variants2, _product, _product$catCodex2;
468
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
469
+ while (1) switch (_context5.prev = _context5.next) {
441
470
  case 0:
442
471
  if (!((selectedProduct === null || selectedProduct === void 0 ? void 0 : selectedProduct._id) === productId)) {
443
- _context4.next = 3;
472
+ _context5.next = 3;
444
473
  break;
445
474
  }
446
475
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " already selected, skipping"));
447
- return _context4.abrupt("return");
476
+ return _context5.abrupt("return");
448
477
  case 3:
449
478
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] setSelectedProductId called with productId: ").concat(productId));
450
479
 
@@ -454,74 +483,84 @@ function useProductData(_ref) {
454
483
  return p._id === productId;
455
484
  });
456
485
  if (!product) {
457
- _context4.next = 10;
486
+ _context5.next = 12;
458
487
  break;
459
488
  }
460
489
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " found in current variants, setting as selected"));
461
490
  setSelectedProduct(product);
462
491
  notifyProductChanged(product);
463
- return _context4.abrupt("return");
464
- case 10:
492
+ _context5.next = 11;
493
+ return logSelectedProduct(productId, widgetType, product.variantId, product.modelName, (_product$catCodex = product.catCodex) === null || _product$catCodex === void 0 ? void 0 : _product$catCodex.toString(), product.configuration ? product.configuration.OrderSets.map(function (set) {
494
+ return set.SupplierGUID;
495
+ }) : undefined);
496
+ case 11:
497
+ return _context5.abrupt("return");
498
+ case 12:
465
499
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " not found in current variants, fetching variants for it"));
466
- _context4.prev = 11;
500
+ _context5.prev = 13;
467
501
  setError(false);
468
502
  setLoading(true);
469
- _context4.next = 16;
503
+ _context5.next = 18;
470
504
  return fetchProducts([productId]);
471
- case 16:
472
- _variants2 = _context4.sent;
505
+ case 18:
506
+ _variants2 = _context5.sent;
473
507
  setProductVariants(_variants2);
474
508
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] New ").concat(_variants2.length, " variants to productVariants"));
475
509
  _product = _variants2.find(function (p) {
476
510
  return p._id === productId;
477
511
  });
478
512
  if (!_product) {
479
- _context4.next = 26;
513
+ _context5.next = 30;
480
514
  break;
481
515
  }
482
516
  LOG.debug("[".concat(widgetType, ":").concat(widgetId, "] Setting product ").concat(productId, " as selected after fetching"));
483
517
  setSelectedProduct(_product);
484
518
  notifyProductChanged(_product);
485
- _context4.next = 27;
519
+ _context5.next = 28;
520
+ return logSelectedProduct(productId, widgetType, _product.variantId, _product.modelName, (_product$catCodex2 = _product.catCodex) === null || _product$catCodex2 === void 0 ? void 0 : _product$catCodex2.toString(), _product.configuration.OrderSets.map(function (set) {
521
+ return set.SupplierGUID;
522
+ }));
523
+ case 28:
524
+ _context5.next = 31;
486
525
  break;
487
- case 26:
526
+ case 30:
488
527
  throw new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Product ").concat(productId, " not found"));
489
- case 27:
490
- _context4.next = 33;
528
+ case 31:
529
+ _context5.next = 37;
491
530
  break;
492
- case 29:
493
- _context4.prev = 29;
494
- _context4.t0 = _context4["catch"](11);
531
+ case 33:
532
+ _context5.prev = 33;
533
+ _context5.t0 = _context5["catch"](13);
495
534
  LOG.error(new DivaError("[".concat(widgetType, ":").concat(widgetId, "] Error loading product"), {
496
- cause: _context4.t0
535
+ cause: _context5.t0
497
536
  }));
498
537
  setError(true);
499
- case 33:
500
- _context4.prev = 33;
538
+ case 37:
539
+ _context5.prev = 37;
501
540
  setLoading(false);
502
- return _context4.finish(33);
503
- case 36:
541
+ return _context5.finish(37);
542
+ case 40:
504
543
  case "end":
505
- return _context4.stop();
544
+ return _context5.stop();
506
545
  }
507
- }, _callee4, null, [[11, 29, 33, 36]]);
546
+ }, _callee5, null, [[13, 33, 37, 40]]);
508
547
  }));
509
- return function (_x4) {
510
- return _ref5.apply(this, arguments);
548
+ return function (_x5) {
549
+ return _ref6.apply(this, arguments);
511
550
  };
512
551
  }(), [selectedProduct, productVariants, fetchProducts, setSelectedProduct, widgetId, widgetType]);
513
- function getProductsByDivaNrs(_x5) {
552
+ function getProductsByDivaNrs(_x6) {
514
553
  return _getProductsByDivaNrs.apply(this, arguments);
515
554
  }
516
555
  function _getProductsByDivaNrs() {
517
- _getProductsByDivaNrs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(divaNrs) {
556
+ _getProductsByDivaNrs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(divaNrs) {
518
557
  var products;
519
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
520
- while (1) switch (_context5.prev = _context5.next) {
558
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
559
+ while (1) switch (_context6.prev = _context6.next) {
521
560
  case 0:
522
561
  // Sort divaNrs array to ensure consistent cache keys
523
562
  divaNrs.sort();
524
- _context5.next = 3;
563
+ _context6.next = 3;
525
564
  return getOrFetch('divaNrs' + divaNrs.join(','), function () {
526
565
  return handler.productHandler.apiGetProductByQuery([{
527
566
  id: 'divaNr',
@@ -534,24 +573,24 @@ function useProductData(_ref) {
534
573
  }], 1000, false);
535
574
  });
536
575
  case 3:
537
- products = _context5.sent;
538
- return _context5.abrupt("return", products);
576
+ products = _context6.sent;
577
+ return _context6.abrupt("return", products);
539
578
  case 5:
540
579
  case "end":
541
- return _context5.stop();
580
+ return _context6.stop();
542
581
  }
543
- }, _callee5);
582
+ }, _callee6);
544
583
  }));
545
584
  return _getProductsByDivaNrs.apply(this, arguments);
546
585
  }
547
- function getProductByDivaNrAndVariantId(_x6, _x7) {
586
+ function getProductByDivaNrAndVariantId(_x7, _x8) {
548
587
  return _getProductByDivaNrAndVariantId.apply(this, arguments);
549
588
  }
550
589
  function _getProductByDivaNrAndVariantId() {
551
- _getProductByDivaNrAndVariantId = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(divaNr, variantId) {
590
+ _getProductByDivaNrAndVariantId = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(divaNr, variantId) {
552
591
  var filter, product;
553
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
554
- while (1) switch (_context6.prev = _context6.next) {
592
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
593
+ while (1) switch (_context7.prev = _context7.next) {
555
594
  case 0:
556
595
  filter = [{
557
596
  id: 'divaNr',
@@ -569,18 +608,18 @@ function useProductData(_ref) {
569
608
  value: parseInt(variantId)
570
609
  });
571
610
  }
572
- _context6.next = 4;
611
+ _context7.next = 4;
573
612
  return getOrFetch('divaNr' + divaNr + 'variantId' + variantId, function () {
574
613
  return handler.productHandler.apiGetProductByQuery(filter, 1, false);
575
614
  });
576
615
  case 4:
577
- product = _context6.sent;
578
- return _context6.abrupt("return", product);
616
+ product = _context7.sent;
617
+ return _context7.abrupt("return", product);
579
618
  case 6:
580
619
  case "end":
581
- return _context6.stop();
620
+ return _context7.stop();
582
621
  }
583
- }, _callee6);
622
+ }, _callee7);
584
623
  }));
585
624
  return _getProductByDivaNrAndVariantId.apply(this, arguments);
586
625
  }
@@ -590,6 +629,33 @@ function useProductData(_ref) {
590
629
  timestamp: Date.now()
591
630
  });
592
631
  }
632
+ function logSelectedProduct(_x9, _x10, _x11, _x12, _x13, _x14) {
633
+ return _logSelectedProduct.apply(this, arguments);
634
+ }
635
+ function _logSelectedProduct() {
636
+ _logSelectedProduct = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(productId, widgetType, variantId, catalogName, catalogCodex, supplierId) {
637
+ var event,
638
+ _args8 = arguments;
639
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
640
+ while (1) switch (_context8.prev = _context8.next) {
641
+ case 0:
642
+ event = _args8.length > 6 && _args8[6] !== undefined ? _args8[6] : 'onWidgetProductSelected';
643
+ LOG.businessEvent(event, 'DivaWidget', "Product ".concat(productId, " selected in widget ").concat(widgetType), {
644
+ productId: productId,
645
+ variantId: variantId,
646
+ widgetType: widgetType,
647
+ catalogName: catalogName,
648
+ catalogCodex: catalogCodex,
649
+ supplierId: supplierId
650
+ });
651
+ case 2:
652
+ case "end":
653
+ return _context8.stop();
654
+ }
655
+ }, _callee8);
656
+ }));
657
+ return _logSelectedProduct.apply(this, arguments);
658
+ }
593
659
  return {
594
660
  productVariants: productVariants,
595
661
  error: error,
@@ -1 +1 @@
1
- {"version":3,"file":"useProductData.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/useProductData.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAA0B,MAAM,0BAA0B,CAAC;AAM1F,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,mBAAmB;;;;oCA2JzC,MAAM,EAAE,KAAG,OAAO,CAAC,GAAG,CAAC;6CAyBd,MAAM,cAAc,MAAM,KAAG,OAAO,CAAC,GAAG,CAAC;;sCAxE3E,MAAM;2BAmGI,MAAM,QAAQ,GAAG;EAiBhD"}
1
+ {"version":3,"file":"useProductData.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/useProductData.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAA0B,MAAM,0BAA0B,CAAC;AAQ1F,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAKD,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,mBAAmB;;;;oCAyLzC,MAAM,EAAE,KAAG,OAAO,CAAC,GAAG,CAAC;6CAyBd,MAAM,cAAc,MAAM,KAAG,OAAO,CAAC,GAAG,CAAC;;sCAxF3E,MAAM;2BAmHI,MAAM,QAAQ,GAAG;EAoChD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crystaldesign/widget-library",
3
- "version": "25.9.0-beta.6",
3
+ "version": "25.9.0-beta.7",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "storybook": "storybook dev -p 6006",
@@ -36,5 +36,5 @@
36
36
  "suiteName": "widget-library",
37
37
  "outputDirectory": "./test-reports"
38
38
  },
39
- "gitHead": "edef772a37cc1b30728bc0dafad26abf423e2b99"
39
+ "gitHead": "d02d40c037dd9fc40cc9b4a3811c305619ff6c0c"
40
40
  }