@commercetools-frontend-extensions/import-resources-modal 1.7.6 → 1.8.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.
- package/dist/{active-drag-drop-area-a4fd91f7.cjs.dev.js → active-drag-drop-area-b84dd578.cjs.dev.js} +3 -3
- package/dist/{active-drag-drop-area-bfd1ac28.esm.js → active-drag-drop-area-b855fcf6.esm.js} +3 -3
- package/dist/{active-drag-drop-area-abe96e04.cjs.prod.js → active-drag-drop-area-c906211c.cjs.prod.js} +3 -3
- package/dist/commercetools-frontend-extensions-import-resources-modal.cjs.dev.js +7 -7
- package/dist/commercetools-frontend-extensions-import-resources-modal.cjs.prod.js +7 -7
- package/dist/commercetools-frontend-extensions-import-resources-modal.esm.js +7 -7
- package/dist/declarations/src/@types/file-upload.d.ts +0 -4
- package/dist/{disabled-drop-area-c092ebd0.cjs.dev.js → disabled-drop-area-48c8a29e.cjs.dev.js} +7 -7
- package/dist/{disabled-drop-area-093742fc.esm.js → disabled-drop-area-d56b2ffb.esm.js} +7 -7
- package/dist/{disabled-drop-area-25e976d6.cjs.prod.js → disabled-drop-area-ead9d6e5.cjs.prod.js} +7 -7
- package/dist/{enabled-drop-area-db88a5da.esm.js → enabled-drop-area-4745c8da.esm.js} +7 -7
- package/dist/{enabled-drop-area-2e91435a.cjs.dev.js → enabled-drop-area-5c4ea376.cjs.dev.js} +7 -7
- package/dist/{enabled-drop-area-86aff122.cjs.prod.js → enabled-drop-area-e81190f8.cjs.prod.js} +7 -7
- package/dist/{file-dropped-area-88c05907.cjs.dev.js → file-dropped-area-2d51d63b.cjs.dev.js} +7 -7
- package/dist/{file-dropped-area-6279df47.cjs.prod.js → file-dropped-area-48990997.cjs.prod.js} +7 -7
- package/dist/{file-dropped-area-70be944b.esm.js → file-dropped-area-bf648f2e.esm.js} +7 -7
- package/dist/{index-6186162d.cjs.prod.js → index-762eed18.cjs.prod.js} +374 -110
- package/dist/{index-98c1d115.cjs.dev.js → index-a2c55a09.cjs.dev.js} +374 -110
- package/dist/{index-c388b02a.esm.js → index-d6f6d164.esm.js} +372 -108
- package/package.json +35 -34
|
@@ -27,15 +27,15 @@ var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper')
|
|
|
27
27
|
var pluralize = require('pluralize');
|
|
28
28
|
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
29
29
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
30
|
+
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
31
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
30
32
|
var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
|
|
31
33
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
32
34
|
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
33
|
-
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
34
35
|
var Papa = require('papaparse');
|
|
35
36
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
36
37
|
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
37
38
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
38
|
-
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
39
39
|
require('@babel/runtime-corejs3/core-js-stable/instance/bind');
|
|
40
40
|
require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
41
41
|
require('@babel/runtime-corejs3/core-js-stable/url-search-params');
|
|
@@ -67,15 +67,15 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
67
67
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
68
68
|
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
69
69
|
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
70
|
+
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
71
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
70
72
|
var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
|
|
71
73
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
72
74
|
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
73
|
-
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
74
75
|
var Papa__default = /*#__PURE__*/_interopDefault(Papa);
|
|
75
76
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
76
77
|
var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
|
|
77
78
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
78
|
-
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
79
79
|
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
80
80
|
|
|
81
81
|
const EnabledResourceType = {
|
|
@@ -297,7 +297,7 @@ const fetchUsingXhr = _ref2 => {
|
|
|
297
297
|
return xhr;
|
|
298
298
|
};
|
|
299
299
|
|
|
300
|
-
const
|
|
300
|
+
const ALLOWED_DELIMITERS = [',', ';', '|', '\t'];
|
|
301
301
|
const INITIAL_COLUMN_DISPLAY_COUNT = 8;
|
|
302
302
|
const IMPORT_TAG_KEYS = {
|
|
303
303
|
source: 'source'
|
|
@@ -387,41 +387,270 @@ const DEFAULT_SHORT_LIVED_FLAGS = {};
|
|
|
387
387
|
const DEFAULT_LONG_LIVED_FLAGS = {};
|
|
388
388
|
_objectSpread$g(_objectSpread$g({}, DEFAULT_SHORT_LIVED_FLAGS), DEFAULT_LONG_LIVED_FLAGS);
|
|
389
389
|
|
|
390
|
+
var sharedMessages = reactIntl.defineMessages({
|
|
391
|
+
[`modalTitle.${IMPORTABLE_RESOURCES.CATEGORY}`]: {
|
|
392
|
+
id: 'ImportResourcesModal.modalTitle.category',
|
|
393
|
+
description: 'Label for the categories modal title',
|
|
394
|
+
defaultMessage: 'Import categories by CSV'
|
|
395
|
+
},
|
|
396
|
+
[`modalTitle.${IMPORTABLE_RESOURCES.PRODUCT}`]: {
|
|
397
|
+
id: 'ImportResourcesModal.modalTitle.product',
|
|
398
|
+
description: 'Label for the products modal title',
|
|
399
|
+
defaultMessage: 'Import products by CSV'
|
|
400
|
+
},
|
|
401
|
+
[`modalTitle.${IMPORTABLE_RESOURCES.INVENTORY}`]: {
|
|
402
|
+
id: 'ImportResourcesModal.modalTitle.inventoryEntry',
|
|
403
|
+
description: 'Label for the inventories modal title',
|
|
404
|
+
defaultMessage: 'Import inventories by CSV'
|
|
405
|
+
},
|
|
406
|
+
[`modalTitle.${IMPORTABLE_RESOURCES.DISCOUNT_CODE}`]: {
|
|
407
|
+
id: 'ImportResourcesModal.modalTitle.discountCode',
|
|
408
|
+
description: 'Label for the inventories modal title',
|
|
409
|
+
defaultMessage: 'Import discount codes by CSV'
|
|
410
|
+
},
|
|
411
|
+
[`modalTitle.${IMPORTABLE_RESOURCES.CUSTOMER}`]: {
|
|
412
|
+
id: 'ImportResourcesModal.modalTitle.customer',
|
|
413
|
+
description: 'Label for the customers modal title',
|
|
414
|
+
defaultMessage: 'Import customers by CSV'
|
|
415
|
+
},
|
|
416
|
+
[`modalTitle.${IMPORTABLE_RESOURCES.ORDER}`]: {
|
|
417
|
+
id: 'ImportResourcesModal.modalTitle.order',
|
|
418
|
+
description: 'Label for the order modal title',
|
|
419
|
+
defaultMessage: 'Import orders by CSV'
|
|
420
|
+
},
|
|
421
|
+
[`modalTitle.${IMPORTABLE_RESOURCES.PRODUCT_TYPE}`]: {
|
|
422
|
+
id: 'ImportResourcesModal.modalTitle.productType',
|
|
423
|
+
description: 'Label for the product type modal title',
|
|
424
|
+
defaultMessage: 'Import product types by CSV'
|
|
425
|
+
},
|
|
426
|
+
uploadButton: {
|
|
427
|
+
id: 'ImportResourcesModal.uploadButton',
|
|
428
|
+
description: 'Label for the upload button',
|
|
429
|
+
defaultMessage: 'Upload and preview'
|
|
430
|
+
},
|
|
431
|
+
cancel: {
|
|
432
|
+
id: 'ImportResourcesModal.cancel',
|
|
433
|
+
description: 'Label for the cancel button',
|
|
434
|
+
defaultMessage: 'Cancel'
|
|
435
|
+
},
|
|
436
|
+
close: {
|
|
437
|
+
id: 'ImportResourcesModal.close',
|
|
438
|
+
description: 'Label for the close button',
|
|
439
|
+
defaultMessage: 'Close'
|
|
440
|
+
},
|
|
441
|
+
listConjunctionOr: {
|
|
442
|
+
id: 'ImportResourcesModal.listConjunctionOr',
|
|
443
|
+
description: 'Label for the list conjunction or',
|
|
444
|
+
defaultMessage: 'or'
|
|
445
|
+
},
|
|
446
|
+
delimiterComma: {
|
|
447
|
+
id: 'ImportResourcesModal.delimiterComma',
|
|
448
|
+
description: 'Label for the delimiter name comma',
|
|
449
|
+
defaultMessage: 'comma'
|
|
450
|
+
},
|
|
451
|
+
delimiterSemicolon: {
|
|
452
|
+
id: 'ImportResourcesModal.delimiterSemicolon',
|
|
453
|
+
description: 'Label for the delimiter name semicolon',
|
|
454
|
+
defaultMessage: 'semicolon'
|
|
455
|
+
},
|
|
456
|
+
delimiterPipe: {
|
|
457
|
+
id: 'ImportResourcesModal.delimiterPipe',
|
|
458
|
+
description: 'Label for the delimiter name pipe',
|
|
459
|
+
defaultMessage: 'pipe'
|
|
460
|
+
},
|
|
461
|
+
delimiterTab: {
|
|
462
|
+
id: 'ImportResourcesModal.delimiterTab',
|
|
463
|
+
description: 'Label for the delimiter name tab',
|
|
464
|
+
defaultMessage: 'tab'
|
|
465
|
+
},
|
|
466
|
+
// Resource types
|
|
467
|
+
product: {
|
|
468
|
+
id: 'ImportResourcesModal.product',
|
|
469
|
+
description: 'Label for the product resource type',
|
|
470
|
+
defaultMessage: 'Product'
|
|
471
|
+
},
|
|
472
|
+
products: {
|
|
473
|
+
id: 'ImportResourcesModal.products',
|
|
474
|
+
description: 'Label for the products resource type',
|
|
475
|
+
defaultMessage: 'Products'
|
|
476
|
+
},
|
|
477
|
+
inventory: {
|
|
478
|
+
id: 'ImportResourcesModal.inventory',
|
|
479
|
+
description: 'Label for the inventory entry resource type',
|
|
480
|
+
defaultMessage: 'Inventory'
|
|
481
|
+
},
|
|
482
|
+
inventories: {
|
|
483
|
+
id: 'ImportResourcesModal.inventories',
|
|
484
|
+
description: 'Label for the inventories entry resource type',
|
|
485
|
+
defaultMessage: 'Inventories'
|
|
486
|
+
},
|
|
487
|
+
category: {
|
|
488
|
+
id: 'ImportResourcesModal.category',
|
|
489
|
+
description: 'Label for the category resource type',
|
|
490
|
+
defaultMessage: 'Category'
|
|
491
|
+
},
|
|
492
|
+
categories: {
|
|
493
|
+
id: 'ImportResourcesModal.categories',
|
|
494
|
+
description: 'Label for the categories resource type',
|
|
495
|
+
defaultMessage: 'Categories'
|
|
496
|
+
},
|
|
497
|
+
'custom-object': {
|
|
498
|
+
id: 'ImportResourcesModal.custom-object',
|
|
499
|
+
description: 'Label for the custom-object resource type',
|
|
500
|
+
defaultMessage: 'Custom object'
|
|
501
|
+
},
|
|
502
|
+
'custom-objects': {
|
|
503
|
+
id: 'ImportResourcesModal.custom-objects',
|
|
504
|
+
description: 'Label for the custom-objects resource type',
|
|
505
|
+
defaultMessage: 'Custom objects'
|
|
506
|
+
},
|
|
507
|
+
customer: {
|
|
508
|
+
id: 'ImportResourcesModal.customer',
|
|
509
|
+
description: 'Label for the customer resource type',
|
|
510
|
+
defaultMessage: 'Customer'
|
|
511
|
+
},
|
|
512
|
+
customers: {
|
|
513
|
+
id: 'ImportResourcesModal.customers',
|
|
514
|
+
description: 'Label for the customers resource type',
|
|
515
|
+
defaultMessage: 'Customers'
|
|
516
|
+
},
|
|
517
|
+
order: {
|
|
518
|
+
id: 'ImportResourcesModal.order',
|
|
519
|
+
description: 'Label for the order resource type',
|
|
520
|
+
defaultMessage: 'Order'
|
|
521
|
+
},
|
|
522
|
+
orders: {
|
|
523
|
+
id: 'ImportResourcesModal.orders',
|
|
524
|
+
description: 'Label for the orders resource type',
|
|
525
|
+
defaultMessage: 'Orders'
|
|
526
|
+
},
|
|
527
|
+
'order-patch': {
|
|
528
|
+
id: 'ImportResourcesModal.order-patch',
|
|
529
|
+
description: 'Label for the order-patch resource type',
|
|
530
|
+
defaultMessage: 'Order patch'
|
|
531
|
+
},
|
|
532
|
+
'order-patches': {
|
|
533
|
+
id: 'ImportResourcesModal.order-patches',
|
|
534
|
+
description: 'Label for the order-patches resource type',
|
|
535
|
+
defaultMessage: 'Order patches'
|
|
536
|
+
},
|
|
537
|
+
price: {
|
|
538
|
+
id: 'ImportResourcesModal.price',
|
|
539
|
+
description: 'Label for the price resource type',
|
|
540
|
+
defaultMessage: 'Price'
|
|
541
|
+
},
|
|
542
|
+
prices: {
|
|
543
|
+
id: 'ImportResourcesModal.prices',
|
|
544
|
+
description: 'Label for the prices resource type',
|
|
545
|
+
defaultMessage: 'Prices'
|
|
546
|
+
},
|
|
547
|
+
'product-draft': {
|
|
548
|
+
id: 'ImportResourcesModal.product-draft',
|
|
549
|
+
description: 'Label for the product-draft resource type',
|
|
550
|
+
defaultMessage: 'Product draft'
|
|
551
|
+
},
|
|
552
|
+
'product-drafts': {
|
|
553
|
+
id: 'ImportResourcesModal.product-drafts',
|
|
554
|
+
description: 'Label for the product-drafts resource type',
|
|
555
|
+
defaultMessage: 'Product drafts'
|
|
556
|
+
},
|
|
557
|
+
'product-type': {
|
|
558
|
+
id: 'ImportResourcesModal.product-type',
|
|
559
|
+
description: 'Label for the product-type resource type',
|
|
560
|
+
defaultMessage: 'Product type'
|
|
561
|
+
},
|
|
562
|
+
'product-types': {
|
|
563
|
+
id: 'ImportResourcesModal.product-types',
|
|
564
|
+
description: 'Label for the product-types resource type',
|
|
565
|
+
defaultMessage: 'Product types'
|
|
566
|
+
},
|
|
567
|
+
'product-variant': {
|
|
568
|
+
id: 'ImportResourcesModal.product-variant',
|
|
569
|
+
description: 'Label for the product-variant resource type',
|
|
570
|
+
defaultMessage: 'Product variant'
|
|
571
|
+
},
|
|
572
|
+
'product-variants': {
|
|
573
|
+
id: 'ImportResourcesModal.product-variants',
|
|
574
|
+
description: 'Label for the product-variants resource type',
|
|
575
|
+
defaultMessage: 'Product variants'
|
|
576
|
+
},
|
|
577
|
+
'product-variant-patch': {
|
|
578
|
+
id: 'ImportResourcesModal.product-variant-patch',
|
|
579
|
+
description: 'Label for the product-variant-patch resource type',
|
|
580
|
+
defaultMessage: 'Product variant patch'
|
|
581
|
+
},
|
|
582
|
+
'product-variant-patches': {
|
|
583
|
+
id: 'ImportResourcesModal.product-variant-patches',
|
|
584
|
+
description: 'Label for the product-variant-patches resource type',
|
|
585
|
+
defaultMessage: 'Product variant patches'
|
|
586
|
+
},
|
|
587
|
+
'standalone-price': {
|
|
588
|
+
id: 'ImportResourcesModal.standalone-price',
|
|
589
|
+
description: 'Label for the standalone-price resource type',
|
|
590
|
+
defaultMessage: 'Standalone price'
|
|
591
|
+
},
|
|
592
|
+
'standalone-prices': {
|
|
593
|
+
id: 'ImportResourcesModal.standalone-prices',
|
|
594
|
+
description: 'Label for the standalone-prices resource type',
|
|
595
|
+
defaultMessage: 'Standalone prices'
|
|
596
|
+
},
|
|
597
|
+
type: {
|
|
598
|
+
id: 'ImportResourcesModal.type',
|
|
599
|
+
description: 'Label for the type resource type',
|
|
600
|
+
defaultMessage: 'Type'
|
|
601
|
+
},
|
|
602
|
+
types: {
|
|
603
|
+
id: 'ImportResourcesModal.types',
|
|
604
|
+
description: 'Label for the types resource type',
|
|
605
|
+
defaultMessage: 'Types'
|
|
606
|
+
},
|
|
607
|
+
'discount-code': {
|
|
608
|
+
id: 'ImportResourcesModal.discount-code',
|
|
609
|
+
description: 'Label for the discount-code resource type',
|
|
610
|
+
defaultMessage: 'Discount code'
|
|
611
|
+
},
|
|
612
|
+
'discount-codes': {
|
|
613
|
+
id: 'ImportResourcesModal.discount-codes',
|
|
614
|
+
description: 'Label for the discount-codes resource type',
|
|
615
|
+
defaultMessage: 'Discount codes'
|
|
616
|
+
},
|
|
617
|
+
unknownResourceType: {
|
|
618
|
+
id: 'ImportResourcesModal.unknown-resource-type',
|
|
619
|
+
description: 'Label for the unknown resource type',
|
|
620
|
+
defaultMessage: 'Unknown resource type'
|
|
621
|
+
}
|
|
622
|
+
//
|
|
623
|
+
});
|
|
624
|
+
|
|
390
625
|
function ownKeys$f(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
391
|
-
function _objectSpread$f(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* @returns {Promise<DelimiterCheck>} A Promise that resolves to a DelimiterCheck object.
|
|
399
|
-
*/
|
|
400
|
-
const checkDelimiter = function (file) {
|
|
401
|
-
let expectedDelimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_DELIMITER;
|
|
626
|
+
function _objectSpread$f(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$f(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$f(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
627
|
+
|
|
628
|
+
// Delimiters not included in this array may be treated as part of a column content
|
|
629
|
+
// potentially causing the file to be parsed as a single-column CSV and pass this validation
|
|
630
|
+
const NON_ALLOWED_DELIMITERS = ['%', '.', ' '];
|
|
631
|
+
const DELIMITERS_TO_GUESS = [...ALLOWED_DELIMITERS, ...NON_ALLOWED_DELIMITERS];
|
|
632
|
+
const validateDelimiter = file => {
|
|
402
633
|
return new _Promise__default["default"](resolve => {
|
|
403
|
-
let lineCount = 0;
|
|
404
|
-
let correctDelimiterCount = 0;
|
|
405
|
-
let detectedDelimiter = null;
|
|
406
634
|
Papa__default["default"].parse(file, {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (
|
|
413
|
-
|
|
635
|
+
delimitersToGuess: DELIMITERS_TO_GUESS,
|
|
636
|
+
preview: 10,
|
|
637
|
+
complete: result => {
|
|
638
|
+
const headerRow = result.data?.[0];
|
|
639
|
+
const isOnlyOneColumn = _Array$isArray__default["default"](headerRow) && headerRow.length === 1;
|
|
640
|
+
if (isOnlyOneColumn) {
|
|
641
|
+
resolve(true);
|
|
642
|
+
return;
|
|
414
643
|
}
|
|
415
|
-
|
|
416
|
-
|
|
644
|
+
const detectedDelimiter = result.meta.delimiter;
|
|
645
|
+
let isValid = false;
|
|
646
|
+
if (detectedDelimiter !== null && _includesInstanceProperty__default["default"](ALLOWED_DELIMITERS).call(ALLOWED_DELIMITERS, detectedDelimiter)) {
|
|
647
|
+
var _context;
|
|
648
|
+
const isUndetectableDelimiter = _someInstanceProperty__default["default"](_context = result.errors).call(_context, error => error.code === 'UndetectableDelimiter');
|
|
649
|
+
if (!isUndetectableDelimiter) {
|
|
650
|
+
isValid = true;
|
|
651
|
+
}
|
|
417
652
|
}
|
|
418
|
-
|
|
419
|
-
complete: () => {
|
|
420
|
-
const isValid = correctDelimiterCount === lineCount;
|
|
421
|
-
resolve({
|
|
422
|
-
isValid,
|
|
423
|
-
delimiter: detectedDelimiter
|
|
424
|
-
});
|
|
653
|
+
resolve(isValid);
|
|
425
654
|
}
|
|
426
655
|
});
|
|
427
656
|
});
|
|
@@ -430,8 +659,8 @@ const mapUploadFileErrorsResponseToUploadFileErrorRows = uploadFileErrorsRespons
|
|
|
430
659
|
if (!uploadFileErrorsResponse || !_Array$isArray__default["default"](uploadFileErrorsResponse)) return [];
|
|
431
660
|
let idCounter = 1;
|
|
432
661
|
return _flatMapInstanceProperty__default["default"](uploadFileErrorsResponse).call(uploadFileErrorsResponse, rowErrorsResponse => {
|
|
433
|
-
var
|
|
434
|
-
return _mapInstanceProperty__default["default"](
|
|
662
|
+
var _context2;
|
|
663
|
+
return _mapInstanceProperty__default["default"](_context2 = rowErrorsResponse.errors).call(_context2, rowError => ({
|
|
435
664
|
// DataTable component requires unique `id` field
|
|
436
665
|
id: String(idCounter++),
|
|
437
666
|
row: rowErrorsResponse.row,
|
|
@@ -481,6 +710,35 @@ const toBytes = megabytes => megabytes * 1024 * 1024;
|
|
|
481
710
|
const getValidatedColumns = (columns, ignoredColumns) => {
|
|
482
711
|
return _filterInstanceProperty__default["default"](columns).call(columns, column => !_includesInstanceProperty__default["default"](ignoredColumns).call(ignoredColumns, column));
|
|
483
712
|
};
|
|
713
|
+
const formatAllowedDelimitersForMessageDisplay = intl => {
|
|
714
|
+
const localizedOr = intl.formatMessage(sharedMessages.listConjunctionOr);
|
|
715
|
+
const descriptions = _mapInstanceProperty__default["default"](ALLOWED_DELIMITERS).call(ALLOWED_DELIMITERS, delimiter => {
|
|
716
|
+
let nameDescriptor;
|
|
717
|
+
switch (delimiter) {
|
|
718
|
+
case ',':
|
|
719
|
+
nameDescriptor = sharedMessages.delimiterComma;
|
|
720
|
+
break;
|
|
721
|
+
case ';':
|
|
722
|
+
nameDescriptor = sharedMessages.delimiterSemicolon;
|
|
723
|
+
break;
|
|
724
|
+
case '|':
|
|
725
|
+
nameDescriptor = sharedMessages.delimiterPipe;
|
|
726
|
+
break;
|
|
727
|
+
case '\t':
|
|
728
|
+
nameDescriptor = sharedMessages.delimiterTab;
|
|
729
|
+
break;
|
|
730
|
+
default:
|
|
731
|
+
nameDescriptor = undefined;
|
|
732
|
+
}
|
|
733
|
+
const name = nameDescriptor ? intl.formatMessage(nameDescriptor) : delimiter;
|
|
734
|
+
return delimiter === '\t' ? name : `${name} (${delimiter})`;
|
|
735
|
+
});
|
|
736
|
+
if (descriptions.length === 1) {
|
|
737
|
+
return descriptions[0];
|
|
738
|
+
}
|
|
739
|
+
const lastDescription = descriptions.pop();
|
|
740
|
+
return `${descriptions.join(', ')} ${localizedOr} ${lastDescription}`;
|
|
741
|
+
};
|
|
484
742
|
|
|
485
743
|
function getFileUploadErrorsCount(errors) {
|
|
486
744
|
if (!errors || !_Array$isArray__default["default"](errors)) return 0;
|
|
@@ -509,6 +767,57 @@ function formatErrorCode(code) {
|
|
|
509
767
|
return code;
|
|
510
768
|
}
|
|
511
769
|
}
|
|
770
|
+
function resourceTypeToMessage(resourceType) {
|
|
771
|
+
const resourceTypeMap = {
|
|
772
|
+
category: sharedMessages.category,
|
|
773
|
+
product: sharedMessages.product,
|
|
774
|
+
'product-type': sharedMessages['product-type'],
|
|
775
|
+
order: sharedMessages.order,
|
|
776
|
+
customer: sharedMessages.customer,
|
|
777
|
+
'discount-code': sharedMessages['discount-code'],
|
|
778
|
+
inventory: sharedMessages.inventory,
|
|
779
|
+
// TODO: remove `inventory` after aligning the resource type names in the file upload API
|
|
780
|
+
'inventory-entry': sharedMessages.inventory,
|
|
781
|
+
'order-patch': sharedMessages['order-patch'],
|
|
782
|
+
price: sharedMessages.price,
|
|
783
|
+
'product-draft': sharedMessages['product-draft'],
|
|
784
|
+
'product-variant': sharedMessages['product-variant'],
|
|
785
|
+
'product-variant-patch': sharedMessages['product-variant-patch'],
|
|
786
|
+
'standalone-price': sharedMessages['standalone-price'],
|
|
787
|
+
'custom-object': sharedMessages['custom-object'],
|
|
788
|
+
type: sharedMessages.type
|
|
789
|
+
};
|
|
790
|
+
const message = resourceTypeMap[resourceType];
|
|
791
|
+
if (!message) {
|
|
792
|
+
return sharedMessages.unknownResourceType;
|
|
793
|
+
}
|
|
794
|
+
return message;
|
|
795
|
+
}
|
|
796
|
+
function resourceTypeToPluralMessage(resourceType) {
|
|
797
|
+
const resourceTypePluralMap = {
|
|
798
|
+
category: sharedMessages.categories,
|
|
799
|
+
'custom-object': sharedMessages['custom-objects'],
|
|
800
|
+
product: sharedMessages.products,
|
|
801
|
+
'product-type': sharedMessages['product-types'],
|
|
802
|
+
order: sharedMessages.orders,
|
|
803
|
+
customer: sharedMessages.customers,
|
|
804
|
+
'discount-code': sharedMessages['discount-codes'],
|
|
805
|
+
inventory: sharedMessages.inventories,
|
|
806
|
+
// TODO: remove `inventory` after aligning the resource type names in the file upload API
|
|
807
|
+
'inventory-entry': sharedMessages.inventories,
|
|
808
|
+
'order-patch': sharedMessages['order-patches'],
|
|
809
|
+
price: sharedMessages.prices,
|
|
810
|
+
'product-draft': sharedMessages['product-drafts'],
|
|
811
|
+
'product-variant': sharedMessages['product-variants'],
|
|
812
|
+
'product-variant-patch': sharedMessages['product-variant-patches'],
|
|
813
|
+
'standalone-price': sharedMessages['standalone-prices']
|
|
814
|
+
};
|
|
815
|
+
const message = resourceTypePluralMap[resourceType];
|
|
816
|
+
if (!message) {
|
|
817
|
+
return sharedMessages.unknownResourceType;
|
|
818
|
+
}
|
|
819
|
+
return message;
|
|
820
|
+
}
|
|
512
821
|
|
|
513
822
|
const encodeFileNameWithTimestampToContainerKey = fileName => {
|
|
514
823
|
return btoa(_JSON$stringify__default["default"]({
|
|
@@ -753,13 +1062,13 @@ function getDefaultDropWrapperStyles(_dropAreaState) {
|
|
|
753
1062
|
return /*#__PURE__*/react.css(process.env.NODE_ENV === "production" ? "" : ";label:getDefaultDropWrapperStyles;", process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRyb3AtYXJlYS13cmFwcGVyLnRzeCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUE0QlkiLCJmaWxlIjoiZHJvcC1hcmVhLXdyYXBwZXIudHN4Iiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgdHlwZSBEcm9wem9uZVJvb3RQcm9wcyB9IGZyb20gJ3JlYWN0LWRyb3B6b25lJ1xuaW1wb3J0IHsgY3NzIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnXG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCdcbmltcG9ydCB7IHN0eWxlcyB9IGZyb20gJy4vc3R5bGVzJ1xuaW1wb3J0IHsgdHlwZSBEcm9wQXJlYVN0YXRlIH0gZnJvbSAnLi4vLi4vLi4vQHR5cGVzJ1xuXG5pbnRlcmZhY2UgRHJvcFdyYXBwZXJQcm9wcyBleHRlbmRzIERyb3B6b25lUm9vdFByb3BzIHtcbiAgZHJvcEFyZWFTdGF0ZTogRHJvcEFyZWFTdGF0ZVxufVxuZXhwb3J0IGNvbnN0IERyb3BXcmFwcGVyID0gc3R5bGVkLmRpdjxEcm9wV3JhcHBlclByb3BzPmBcbiAgJHtzdHlsZXMuYmFzZX1cbiAgJHsocHJvcHMpID0+IHtcbiAgICBpZiAocHJvcHMuZHJvcEFyZWFTdGF0ZSA9PT0gJ2Rpc2FibGVkJykge1xuICAgICAgcmV0dXJuIHN0eWxlcy5kaXNhYmxlZFxuICAgIH1cbiAgICBpZiAocHJvcHMuZHJvcEFyZWFTdGF0ZSA9PT0gJ3JlYWR5LWZvci1kcm9wJykge1xuICAgICAgcmV0dXJuIHN0eWxlcy5yZWFkeUZvckRyb3BcbiAgICB9XG4gICAgaWYgKHByb3BzLmRyb3BBcmVhU3RhdGUgPT09ICdhY3RpdmUtZHJhZycpIHtcbiAgICAgIHJldHVybiBzdHlsZXMuYWN0aXZlRHJhZ1xuICAgIH1cbiAgICBpZiAocHJvcHMuZHJvcEFyZWFTdGF0ZSA9PT0gJ2ZpbGUtZHJvcHBlZCcpIHtcbiAgICAgIHJldHVybiBzdHlsZXMuZmlsZURyb3BwZWRcbiAgICB9XG4gICAgcmV0dXJuIGdldERlZmF1bHREcm9wV3JhcHBlclN0eWxlcyhwcm9wcy5kcm9wQXJlYVN0YXRlKVxuICB9fVxuYFxuZnVuY3Rpb24gZ2V0RGVmYXVsdERyb3BXcmFwcGVyU3R5bGVzKF9kcm9wQXJlYVN0YXRlOiBuZXZlcikge1xuICByZXR1cm4gY3NzYGBcbn1cbiJdfQ== */");
|
|
754
1063
|
}
|
|
755
1064
|
|
|
756
|
-
var ActiveDragDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./active-drag-drop-area-
|
|
1065
|
+
var ActiveDragDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./active-drag-drop-area-b84dd578.cjs.dev.js' /* webpackChunkName: "active-drag-drop-area" */); }));
|
|
757
1066
|
|
|
758
|
-
var DisabledDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./disabled-drop-area-
|
|
1067
|
+
var DisabledDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./disabled-drop-area-48c8a29e.cjs.dev.js' /* webpackChunkName: "disabled-drop-area" */); }));
|
|
759
1068
|
|
|
760
|
-
var EnabledDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./enabled-drop-area-
|
|
1069
|
+
var EnabledDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./enabled-drop-area-5c4ea376.cjs.dev.js' /* webpackChunkName: "enabled-drop-area" */); }));
|
|
761
1070
|
|
|
762
|
-
var FileDropped = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./file-dropped-area-
|
|
1071
|
+
var FileDropped = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./file-dropped-area-2d51d63b.cjs.dev.js' /* webpackChunkName: "filed-dropped-area" */); }));
|
|
763
1072
|
|
|
764
1073
|
function getDropArea(_ref) {
|
|
765
1074
|
let dropAreaState = _ref.dropAreaState,
|
|
@@ -881,14 +1190,14 @@ var messages$6 = reactIntl.defineMessages({
|
|
|
881
1190
|
description: 'Error description when the file contains more rows than the allowable maximum',
|
|
882
1191
|
defaultMessage: 'The file contains more than the allowable maximum of {rowLimit} rows'
|
|
883
1192
|
},
|
|
884
|
-
|
|
885
|
-
id: 'ImportResourcesModal.
|
|
886
|
-
defaultMessage: 'Wrong
|
|
1193
|
+
wrongSeparatorTitle: {
|
|
1194
|
+
id: 'ImportResourcesModal.wrongSeparatorTitle',
|
|
1195
|
+
defaultMessage: 'Wrong separator'
|
|
887
1196
|
},
|
|
888
|
-
|
|
889
|
-
id: 'ImportResourcesModal.
|
|
1197
|
+
wrongSeparatorDescription: {
|
|
1198
|
+
id: 'ImportResourcesModal.wrongSeparatorDescription',
|
|
890
1199
|
description: 'Message within the drop area when a CSV file uses an unexpected delimiter',
|
|
891
|
-
defaultMessage: 'The file is using an
|
|
1200
|
+
defaultMessage: 'The file is using an unsupported separator. Please use one of the allowed delimiters: {delimiterList}.'
|
|
892
1201
|
},
|
|
893
1202
|
dropAreaNotEnoughRowsTitle: {
|
|
894
1203
|
id: 'ImportResourcesModal.dropAreaNotEnoughRowsTitle',
|
|
@@ -939,10 +1248,12 @@ const useUpload = () => {
|
|
|
939
1248
|
}, [state.abortController]);
|
|
940
1249
|
const isFileValid = async file => {
|
|
941
1250
|
const errors = [];
|
|
942
|
-
const
|
|
943
|
-
if (!
|
|
944
|
-
title: intl.formatMessage(messages$6.
|
|
945
|
-
description: intl.formatMessage(messages$6.
|
|
1251
|
+
const isDelimiterValid = await validateDelimiter(file);
|
|
1252
|
+
if (!isDelimiterValid) errors.push({
|
|
1253
|
+
title: intl.formatMessage(messages$6.wrongSeparatorTitle),
|
|
1254
|
+
description: intl.formatMessage(messages$6.wrongSeparatorDescription, {
|
|
1255
|
+
delimiterList: formatAllowedDelimitersForMessageDisplay(intl)
|
|
1256
|
+
})
|
|
946
1257
|
});
|
|
947
1258
|
const rowCount = await getRowCount(file);
|
|
948
1259
|
if (rowCount < 1) errors.push({
|
|
@@ -1212,59 +1523,6 @@ const UploadSettings = () => {
|
|
|
1212
1523
|
return null;
|
|
1213
1524
|
};
|
|
1214
1525
|
|
|
1215
|
-
var sharedMessages = reactIntl.defineMessages({
|
|
1216
|
-
[`modalTitle.${IMPORTABLE_RESOURCES.CATEGORY}`]: {
|
|
1217
|
-
id: 'ImportResourcesModal.modalTitle.category',
|
|
1218
|
-
description: 'Label for the categories modal title',
|
|
1219
|
-
defaultMessage: 'Import categories by CSV'
|
|
1220
|
-
},
|
|
1221
|
-
[`modalTitle.${IMPORTABLE_RESOURCES.PRODUCT}`]: {
|
|
1222
|
-
id: 'ImportResourcesModal.modalTitle.product',
|
|
1223
|
-
description: 'Label for the products modal title',
|
|
1224
|
-
defaultMessage: 'Import products by CSV'
|
|
1225
|
-
},
|
|
1226
|
-
[`modalTitle.${IMPORTABLE_RESOURCES.INVENTORY}`]: {
|
|
1227
|
-
id: 'ImportResourcesModal.modalTitle.inventoryEntry',
|
|
1228
|
-
description: 'Label for the inventories modal title',
|
|
1229
|
-
defaultMessage: 'Import inventories by CSV'
|
|
1230
|
-
},
|
|
1231
|
-
[`modalTitle.${IMPORTABLE_RESOURCES.DISCOUNT_CODE}`]: {
|
|
1232
|
-
id: 'ImportResourcesModal.modalTitle.discountCode',
|
|
1233
|
-
description: 'Label for the inventories modal title',
|
|
1234
|
-
defaultMessage: 'Import discount codes by CSV'
|
|
1235
|
-
},
|
|
1236
|
-
[`modalTitle.${IMPORTABLE_RESOURCES.CUSTOMER}`]: {
|
|
1237
|
-
id: 'ImportResourcesModal.modalTitle.customer',
|
|
1238
|
-
description: 'Label for the customers modal title',
|
|
1239
|
-
defaultMessage: 'Import customers by CSV'
|
|
1240
|
-
},
|
|
1241
|
-
[`modalTitle.${IMPORTABLE_RESOURCES.ORDER}`]: {
|
|
1242
|
-
id: 'ImportResourcesModal.modalTitle.order',
|
|
1243
|
-
description: 'Label for the order modal title',
|
|
1244
|
-
defaultMessage: 'Import orders by CSV'
|
|
1245
|
-
},
|
|
1246
|
-
[`modalTitle.${IMPORTABLE_RESOURCES.PRODUCT_TYPE}`]: {
|
|
1247
|
-
id: 'ImportResourcesModal.modalTitle.productType',
|
|
1248
|
-
description: 'Label for the product type modal title',
|
|
1249
|
-
defaultMessage: 'Import product types by CSV'
|
|
1250
|
-
},
|
|
1251
|
-
uploadButton: {
|
|
1252
|
-
id: 'ImportResourcesModal.uploadButton',
|
|
1253
|
-
description: 'Label for the upload button',
|
|
1254
|
-
defaultMessage: 'Upload and preview'
|
|
1255
|
-
},
|
|
1256
|
-
cancel: {
|
|
1257
|
-
id: 'ImportResourcesModal.cancel',
|
|
1258
|
-
description: 'Label for the cancel button',
|
|
1259
|
-
defaultMessage: 'Cancel'
|
|
1260
|
-
},
|
|
1261
|
-
close: {
|
|
1262
|
-
id: 'ImportResourcesModal.close',
|
|
1263
|
-
description: 'Label for the close button',
|
|
1264
|
-
defaultMessage: 'Close'
|
|
1265
|
-
}
|
|
1266
|
-
});
|
|
1267
|
-
|
|
1268
1526
|
const Upload = () => {
|
|
1269
1527
|
const _useImportResourcesCo = useImportResourcesContext(),
|
|
1270
1528
|
state = _useImportResourcesCo.state,
|
|
@@ -1610,10 +1868,10 @@ var messages$3 = reactIntl.defineMessages({
|
|
|
1610
1868
|
description: 'Label for modal path',
|
|
1611
1869
|
defaultMessage: "Here's a preview of your import"
|
|
1612
1870
|
},
|
|
1613
|
-
|
|
1614
|
-
id: 'ImportResourcesModal.
|
|
1615
|
-
description: 'This message indicates the number of
|
|
1616
|
-
defaultMessage: '{
|
|
1871
|
+
itemsToBeImported: {
|
|
1872
|
+
id: 'ImportResourcesModal.itemsToBeImported',
|
|
1873
|
+
description: 'This message indicates the number of items that are ready to be imported into the project.',
|
|
1874
|
+
defaultMessage: '{itemCount, plural, one {<b>1</b> {resourceType} to be imported{publish, select, true { and published} other {}}} other {<b>{itemCount}</b> {resourceTypePlural} to be imported{publish, select, true { and published} other {}}}}'
|
|
1617
1875
|
},
|
|
1618
1876
|
columnsToBeImported: {
|
|
1619
1877
|
id: 'ImportResourcesModal.columnsToBeImported',
|
|
@@ -1722,6 +1980,10 @@ function UploadPreviewModal() {
|
|
|
1722
1980
|
actions = _useImportResourcesCo2.actions,
|
|
1723
1981
|
onClose = _useImportResourcesCo2.onClose;
|
|
1724
1982
|
if (!state.resourceType || !state.uploadFileResponse) return null;
|
|
1983
|
+
const resourceTypeMessage = resourceTypeToMessage(state.resourceType);
|
|
1984
|
+
const resourceType = intl.formatMessage(resourceTypeMessage).toLowerCase();
|
|
1985
|
+
const resourceTypePluralMessage = resourceTypeToPluralMessage(state.resourceType);
|
|
1986
|
+
const resourceTypePlural = intl.formatMessage(resourceTypePluralMessage).toLowerCase();
|
|
1725
1987
|
const ignoredColumns = state.uploadFileResponse.ignoredColumns;
|
|
1726
1988
|
const validatedColumns = getValidatedColumns(state.uploadFileResponse.columns, ignoredColumns);
|
|
1727
1989
|
return jsxRuntime.jsx(applicationComponents.FormDialog, {
|
|
@@ -1759,9 +2021,11 @@ function UploadPreviewModal() {
|
|
|
1759
2021
|
children: [jsxRuntime.jsx(uiKit.CheckBoldIcon, {
|
|
1760
2022
|
color: "success"
|
|
1761
2023
|
}), jsxRuntime.jsx(uiKit.Text.Body, {
|
|
1762
|
-
intlMessage: _objectSpread$5(_objectSpread$5({}, messages$3.
|
|
2024
|
+
intlMessage: _objectSpread$5(_objectSpread$5({}, messages$3.itemsToBeImported), {}, {
|
|
1763
2025
|
values: {
|
|
1764
|
-
|
|
2026
|
+
resourceType,
|
|
2027
|
+
resourceTypePlural,
|
|
2028
|
+
itemCount: intl.formatNumber(state.uploadFileResponse.itemsCount),
|
|
1765
2029
|
publish: state.resourceType === 'product' && state.settings?.publish,
|
|
1766
2030
|
b: getBold$1
|
|
1767
2031
|
}
|