@commercetools-frontend-extensions/delete-resources-modal 2.0.4 → 2.1.0

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.
@@ -11,7 +11,7 @@ import { defineMessages, useIntl, FormattedMessage, IntlProvider } from 'react-i
11
11
  import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';
12
12
  import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
13
13
  import React, { useContext, useState, useEffect } from 'react';
14
- import { deleteImportContainer, EnabledDropArea, FileDroppedArea, ActiveDragDropArea, useFileUpload, getRowCount, toBytes, IMPORT_MAX_FILE_SIZE_MB, hasSingleKeyColumn, IMPORT_MAX_ITEM_COUNT, isAbortError, HttpError, PollingTimeoutError, FileDropArea as FileDropArea$1, UploadingModal, mapFileUploadErrorsToUploadFileErrorRows, processFileImportJob, processUploadedFile } from '@commercetools-frontend-extensions/operations';
14
+ import { deleteImportContainer, EnabledDropArea, FileDroppedArea, ActiveDragDropArea, useFileUpload, getRowCount, toBytes, IMPORT_MAX_FILE_SIZE_MB, hasSingleKeyColumn, IMPORT_MAX_ITEM_COUNT, isAbortError, HttpError, PollingTimeoutError, FileDropArea as FileDropArea$1, isPublishableResourceType, UploadingModal, mapFileUploadErrorsToUploadFileErrorRows, processFileImportJob, processUploadedFile } from '@commercetools-frontend-extensions/operations';
15
15
  import { jsx, jsxs } from '@emotion/react/jsx-runtime';
16
16
  import { FormDialog, InfoDialog } from '@commercetools-frontend/application-components';
17
17
  import { Masking } from '@commercetools-frontend/fullstory';
@@ -440,12 +440,206 @@ var messages$4 = defineMessages({
440
440
  defaultMessage: 'Invalid CSV file'
441
441
  },
442
442
  csvFormatErrorDescription: {
443
- id: 'UnpublishProductsModal.csvFormatErrorDescription',
443
+ id: 'DeleteResourcesModal.csvFormatErrorDescription',
444
444
  description: 'Error message displayed when the CSV file is not formatted correctly',
445
- defaultMessage: "Your CSV file is not formatted correctly. Make sure the file contains only one column named 'key', which includes the product keys"
445
+ defaultMessage: "Your CSV file is not formatted correctly. Make sure the file contains only one column named 'key', which includes the {resourceType} keys"
446
446
  }
447
447
  });
448
448
 
449
+ var sharedMessages = defineMessages({
450
+ deleteModalTitle: {
451
+ id: 'DeleteResourcesModal.deleteModalTitle',
452
+ description: 'The title of the modal',
453
+ defaultMessage: 'Bulk delete via CSV'
454
+ },
455
+ startBulkDelete: {
456
+ id: 'DeleteResourcesModal.startBulkDelete',
457
+ description: 'Start bulk delete button',
458
+ defaultMessage: 'Start bulk delete'
459
+ },
460
+ cancel: {
461
+ id: 'DeleteResourcesModal.cancel',
462
+ description: 'The label for the cancel button',
463
+ defaultMessage: 'Cancel'
464
+ },
465
+ product: {
466
+ id: 'DeleteResourcesModal.product',
467
+ description: 'Label for the product resource type',
468
+ defaultMessage: 'product'
469
+ },
470
+ products: {
471
+ id: 'DeleteResourcesModal.products',
472
+ description: 'Plural form of product',
473
+ defaultMessage: 'products'
474
+ },
475
+ inventory: {
476
+ id: 'DeleteResourcesModal.inventory',
477
+ description: 'Label for the inventory entry resource type',
478
+ defaultMessage: 'inventory entry'
479
+ },
480
+ inventories: {
481
+ id: 'DeleteResourcesModal.inventories',
482
+ description: 'Plural form of inventory entry',
483
+ defaultMessage: 'inventory entries'
484
+ },
485
+ category: {
486
+ id: 'DeleteResourcesModal.category',
487
+ description: 'Label for the category resource type',
488
+ defaultMessage: 'category'
489
+ },
490
+ categories: {
491
+ id: 'DeleteResourcesModal.categories',
492
+ description: 'Plural form of category',
493
+ defaultMessage: 'categories'
494
+ },
495
+ customer: {
496
+ id: 'DeleteResourcesModal.customer',
497
+ description: 'Label for the customer resource type',
498
+ defaultMessage: 'customer'
499
+ },
500
+ customers: {
501
+ id: 'DeleteResourcesModal.customers',
502
+ description: 'Plural form of customer',
503
+ defaultMessage: 'customers'
504
+ },
505
+ order: {
506
+ id: 'DeleteResourcesModal.order',
507
+ description: 'Label for the order resource type',
508
+ defaultMessage: 'order'
509
+ },
510
+ orders: {
511
+ id: 'DeleteResourcesModal.orders',
512
+ description: 'Plural form of order',
513
+ defaultMessage: 'orders'
514
+ },
515
+ price: {
516
+ id: 'DeleteResourcesModal.price',
517
+ description: 'Label for the price resource type',
518
+ defaultMessage: 'price'
519
+ },
520
+ prices: {
521
+ id: 'DeleteResourcesModal.prices',
522
+ description: 'Plural form of price',
523
+ defaultMessage: 'prices'
524
+ },
525
+ 'product-draft': {
526
+ id: 'DeleteResourcesModal.product-draft',
527
+ description: 'Label for the product-draft resource type',
528
+ defaultMessage: 'product draft'
529
+ },
530
+ 'product-drafts': {
531
+ id: 'DeleteResourcesModal.product-drafts',
532
+ description: 'Plural form of product draft',
533
+ defaultMessage: 'product drafts'
534
+ },
535
+ 'product-type': {
536
+ id: 'DeleteResourcesModal.product-type',
537
+ description: 'Label for the product-type resource type',
538
+ defaultMessage: 'product type'
539
+ },
540
+ 'product-types': {
541
+ id: 'DeleteResourcesModal.product-types',
542
+ description: 'Plural form of product type',
543
+ defaultMessage: 'product types'
544
+ },
545
+ 'product-variant': {
546
+ id: 'DeleteResourcesModal.product-variant',
547
+ description: 'Label for the product-variant resource type',
548
+ defaultMessage: 'product variant'
549
+ },
550
+ 'product-variants': {
551
+ id: 'DeleteResourcesModal.product-variants',
552
+ description: 'Plural form of product variant',
553
+ defaultMessage: 'product variants'
554
+ },
555
+ 'product-variant-patch': {
556
+ id: 'DeleteResourcesModal.product-variant-patch',
557
+ description: 'Label for the product-variant-patch resource type',
558
+ defaultMessage: 'product variant patch'
559
+ },
560
+ 'product-variant-patches': {
561
+ id: 'DeleteResourcesModal.product-variant-patches',
562
+ description: 'Plural form of product variant patch',
563
+ defaultMessage: 'product variant patches'
564
+ },
565
+ 'standalone-price': {
566
+ id: 'DeleteResourcesModal.standalone-price',
567
+ description: 'Label for the standalone-price resource type',
568
+ defaultMessage: 'standalone price'
569
+ },
570
+ 'standalone-prices': {
571
+ id: 'DeleteResourcesModal.standalone-prices',
572
+ description: 'Plural form of standalone price',
573
+ defaultMessage: 'standalone prices'
574
+ },
575
+ 'discount-code': {
576
+ id: 'DeleteResourcesModal.discount-code',
577
+ description: 'Label for the discount-code resource type',
578
+ defaultMessage: 'discount code'
579
+ },
580
+ 'discount-codes': {
581
+ id: 'DeleteResourcesModal.discount-codes',
582
+ description: 'Plural form of discount code',
583
+ defaultMessage: 'discount codes'
584
+ },
585
+ unknownResourceType: {
586
+ id: 'DeleteResourcesModal.unknown-resource-type',
587
+ description: 'Label for the unknown resource type',
588
+ defaultMessage: 'unknown resource type'
589
+ }
590
+ });
591
+
592
+ function resourceTypeToMessage(resourceType) {
593
+ const resourceTypeMap = {
594
+ category: sharedMessages.category,
595
+ product: sharedMessages.product,
596
+ 'product-type': sharedMessages['product-type'],
597
+ order: sharedMessages.order,
598
+ customer: sharedMessages.customer,
599
+ 'discount-code': sharedMessages['discount-code'],
600
+ inventory: sharedMessages.inventory,
601
+ // TODO: remove `inventory` after aligning the resource type names in the file upload API
602
+ 'inventory-entry': sharedMessages.inventory,
603
+ 'order-patch': sharedMessages['order-patch'],
604
+ price: sharedMessages.price,
605
+ 'product-draft': sharedMessages['product-draft'],
606
+ 'product-variant': sharedMessages['product-variant'],
607
+ 'product-variant-patch': sharedMessages['product-variant-patch'],
608
+ 'standalone-price': sharedMessages['standalone-price']
609
+ };
610
+ const message = resourceTypeMap[resourceType];
611
+ if (!message) {
612
+ console.warn(new UnexpectedResourceTypeError(resourceType));
613
+ return sharedMessages.unknownResourceType;
614
+ }
615
+ return message;
616
+ }
617
+ function resourceTypeToPluralMessage(resourceType) {
618
+ const resourceTypePluralMap = {
619
+ category: sharedMessages.categories,
620
+ product: sharedMessages.products,
621
+ 'product-type': sharedMessages['product-types'],
622
+ order: sharedMessages.orders,
623
+ customer: sharedMessages.customers,
624
+ 'discount-code': sharedMessages['discount-codes'],
625
+ inventory: sharedMessages.inventories,
626
+ // TODO: remove `inventory` after aligning the resource type names in the file upload API
627
+ 'inventory-entry': sharedMessages.inventories,
628
+ 'order-patch': sharedMessages['order-patches'],
629
+ price: sharedMessages.prices,
630
+ 'product-draft': sharedMessages['product-drafts'],
631
+ 'product-variant': sharedMessages['product-variants'],
632
+ 'product-variant-patch': sharedMessages['product-variant-patches'],
633
+ 'standalone-price': sharedMessages['standalone-prices']
634
+ };
635
+ const message = resourceTypePluralMap[resourceType];
636
+ if (!message) {
637
+ console.warn(new UnexpectedResourceTypeError(resourceType));
638
+ return sharedMessages.unknownResourceType;
639
+ }
640
+ return message;
641
+ }
642
+
449
643
  const useUpload = () => {
450
644
  const intl = useIntl();
451
645
  const _useApplicationContex = useApplicationContext(context => ({
@@ -477,7 +671,9 @@ const useUpload = () => {
477
671
  if (!(await hasSingleKeyColumn(file))) {
478
672
  errors.push({
479
673
  title: intl.formatMessage(messages$4.csvFormatErrorTitle),
480
- description: intl.formatMessage(messages$4.csvFormatErrorDescription)
674
+ description: intl.formatMessage(messages$4.csvFormatErrorDescription, {
675
+ resourceType: intl.formatMessage(resourceTypeToMessage(resourceType))
676
+ })
481
677
  });
482
678
  }
483
679
  if (rowCount > IMPORT_MAX_ITEM_COUNT) errors.push({
@@ -669,149 +865,6 @@ const FileDropArea = () => {
669
865
  });
670
866
  };
671
867
 
672
- var sharedMessages = defineMessages({
673
- deleteModalTitle: {
674
- id: 'DeleteResourcesModal.deleteModalTitle',
675
- description: 'The title of the modal',
676
- defaultMessage: 'Bulk delete via CSV'
677
- },
678
- startBulkDelete: {
679
- id: 'DeleteResourcesModal.startBulkDelete',
680
- description: 'Start bulk delete button',
681
- defaultMessage: 'Start bulk delete'
682
- },
683
- cancel: {
684
- id: 'DeleteResourcesModal.cancel',
685
- description: 'The label for the cancel button',
686
- defaultMessage: 'Cancel'
687
- },
688
- product: {
689
- id: 'DeleteResourcesModal.product',
690
- description: 'Label for the product resource type',
691
- defaultMessage: 'product'
692
- },
693
- products: {
694
- id: 'DeleteResourcesModal.products',
695
- description: 'Plural form of product',
696
- defaultMessage: 'products'
697
- },
698
- inventory: {
699
- id: 'DeleteResourcesModal.inventory',
700
- description: 'Label for the inventory entry resource type',
701
- defaultMessage: 'inventory entry'
702
- },
703
- inventories: {
704
- id: 'DeleteResourcesModal.inventories',
705
- description: 'Plural form of inventory entry',
706
- defaultMessage: 'inventory entries'
707
- },
708
- category: {
709
- id: 'DeleteResourcesModal.category',
710
- description: 'Label for the category resource type',
711
- defaultMessage: 'category'
712
- },
713
- categories: {
714
- id: 'DeleteResourcesModal.categories',
715
- description: 'Plural form of category',
716
- defaultMessage: 'categories'
717
- },
718
- customer: {
719
- id: 'DeleteResourcesModal.customer',
720
- description: 'Label for the customer resource type',
721
- defaultMessage: 'customer'
722
- },
723
- customers: {
724
- id: 'DeleteResourcesModal.customers',
725
- description: 'Plural form of customer',
726
- defaultMessage: 'customers'
727
- },
728
- order: {
729
- id: 'DeleteResourcesModal.order',
730
- description: 'Label for the order resource type',
731
- defaultMessage: 'order'
732
- },
733
- orders: {
734
- id: 'DeleteResourcesModal.orders',
735
- description: 'Plural form of order',
736
- defaultMessage: 'orders'
737
- },
738
- price: {
739
- id: 'DeleteResourcesModal.price',
740
- description: 'Label for the price resource type',
741
- defaultMessage: 'price'
742
- },
743
- prices: {
744
- id: 'DeleteResourcesModal.prices',
745
- description: 'Plural form of price',
746
- defaultMessage: 'prices'
747
- },
748
- 'product-draft': {
749
- id: 'DeleteResourcesModal.product-draft',
750
- description: 'Label for the product-draft resource type',
751
- defaultMessage: 'product draft'
752
- },
753
- 'product-drafts': {
754
- id: 'DeleteResourcesModal.product-drafts',
755
- description: 'Plural form of product draft',
756
- defaultMessage: 'product drafts'
757
- },
758
- 'product-type': {
759
- id: 'DeleteResourcesModal.product-type',
760
- description: 'Label for the product-type resource type',
761
- defaultMessage: 'product type'
762
- },
763
- 'product-types': {
764
- id: 'DeleteResourcesModal.product-types',
765
- description: 'Plural form of product type',
766
- defaultMessage: 'product types'
767
- },
768
- 'product-variant': {
769
- id: 'DeleteResourcesModal.product-variant',
770
- description: 'Label for the product-variant resource type',
771
- defaultMessage: 'product variant'
772
- },
773
- 'product-variants': {
774
- id: 'DeleteResourcesModal.product-variants',
775
- description: 'Plural form of product variant',
776
- defaultMessage: 'product variants'
777
- },
778
- 'product-variant-patch': {
779
- id: 'DeleteResourcesModal.product-variant-patch',
780
- description: 'Label for the product-variant-patch resource type',
781
- defaultMessage: 'product variant patch'
782
- },
783
- 'product-variant-patches': {
784
- id: 'DeleteResourcesModal.product-variant-patches',
785
- description: 'Plural form of product variant patch',
786
- defaultMessage: 'product variant patches'
787
- },
788
- 'standalone-price': {
789
- id: 'DeleteResourcesModal.standalone-price',
790
- description: 'Label for the standalone-price resource type',
791
- defaultMessage: 'standalone price'
792
- },
793
- 'standalone-prices': {
794
- id: 'DeleteResourcesModal.standalone-prices',
795
- description: 'Plural form of standalone price',
796
- defaultMessage: 'standalone prices'
797
- },
798
- 'discount-code': {
799
- id: 'DeleteResourcesModal.discount-code',
800
- description: 'Label for the discount-code resource type',
801
- defaultMessage: 'discount code'
802
- },
803
- 'discount-codes': {
804
- id: 'DeleteResourcesModal.discount-codes',
805
- description: 'Plural form of discount code',
806
- defaultMessage: 'discount codes'
807
- },
808
- unknownResourceType: {
809
- id: 'DeleteResourcesModal.unknown-resource-type',
810
- description: 'Label for the unknown resource type',
811
- defaultMessage: 'unknown resource type'
812
- }
813
- });
814
-
815
868
  var messages$3 = defineMessages({
816
869
  fileUploadInstruction: {
817
870
  id: 'DeleteResourcesModal.fileUploadInstruction',
@@ -831,63 +884,14 @@ var messages$3 = defineMessages({
831
884
  });
832
885
 
833
886
  const DOCUMENTATION_LINKS = {
834
- product: 'https://docs.commercetools.com/merchant-center/product-list#bulk-delete-via-csv-import'
887
+ product: 'https://docs.commercetools.com/merchant-center/product-list#bulk-delete-via-csv-import',
888
+ 'standalone-price': 'https://docs.commercetools.com/merchant-center/prices#bulk-delete-via-csv-import'
835
889
  };
836
890
  const TEMPLATE_DOWNLOAD_LINKS = {
837
- product: 'https://docs.commercetools.com/merchant-center/downloads/product_delete_import_template.csv'
891
+ product: 'https://docs.commercetools.com/merchant-center/downloads/product_delete_import_template.csv',
892
+ 'standalone-price': 'https://docs.commercetools.com/merchant-center/downloads/standalone_price_delete_import_template.csv'
838
893
  };
839
894
 
840
- function resourceTypeToMessage(resourceType) {
841
- const resourceTypeMap = {
842
- category: sharedMessages.category,
843
- product: sharedMessages.product,
844
- 'product-type': sharedMessages['product-type'],
845
- order: sharedMessages.order,
846
- customer: sharedMessages.customer,
847
- 'discount-code': sharedMessages['discount-code'],
848
- inventory: sharedMessages.inventory,
849
- // TODO: remove `inventory` after aligning the resource type names in the file upload API
850
- 'inventory-entry': sharedMessages.inventory,
851
- 'order-patch': sharedMessages['order-patch'],
852
- price: sharedMessages.price,
853
- 'product-draft': sharedMessages['product-draft'],
854
- 'product-variant': sharedMessages['product-variant'],
855
- 'product-variant-patch': sharedMessages['product-variant-patch'],
856
- 'standalone-price': sharedMessages['standalone-price']
857
- };
858
- const message = resourceTypeMap[resourceType];
859
- if (!message) {
860
- console.warn(new UnexpectedResourceTypeError(resourceType));
861
- return sharedMessages.unknownResourceType;
862
- }
863
- return message;
864
- }
865
- function resourceTypeToPluralMessage(resourceType) {
866
- const resourceTypePluralMap = {
867
- category: sharedMessages.categories,
868
- product: sharedMessages.products,
869
- 'product-type': sharedMessages['product-types'],
870
- order: sharedMessages.orders,
871
- customer: sharedMessages.customers,
872
- 'discount-code': sharedMessages['discount-codes'],
873
- inventory: sharedMessages.inventories,
874
- // TODO: remove `inventory` after aligning the resource type names in the file upload API
875
- 'inventory-entry': sharedMessages.inventories,
876
- 'order-patch': sharedMessages['order-patches'],
877
- price: sharedMessages.prices,
878
- 'product-draft': sharedMessages['product-drafts'],
879
- 'product-variant': sharedMessages['product-variants'],
880
- 'product-variant-patch': sharedMessages['product-variant-patches'],
881
- 'standalone-price': sharedMessages['standalone-prices']
882
- };
883
- const message = resourceTypePluralMap[resourceType];
884
- if (!message) {
885
- console.warn(new UnexpectedResourceTypeError(resourceType));
886
- return sharedMessages.unknownResourceType;
887
- }
888
- return message;
889
- }
890
-
891
895
  function ownKeys$5(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
892
896
  function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys$5(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys$5(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
893
897
  const Instructions = () => {
@@ -901,7 +905,7 @@ const Instructions = () => {
901
905
  children: [jsxs(Text.Body, {
902
906
  children: [intl.formatMessage(messages$3.fileUploadInstruction, {
903
907
  resourceType: intl.formatMessage(resourceTypeToMessage(resourceType))
904
- }), ' ', intl.formatMessage(messages$3.unpublishNote, {
908
+ }), ' ', isPublishableResourceType(resourceType) && intl.formatMessage(messages$3.unpublishNote, {
905
909
  b: msg => jsx("b", {
906
910
  children: msg
907
911
  }, "bold")
@@ -1,6 +1,9 @@
1
- import type { ResourceTypeId } from '@commercetools/importapi-sdk';
1
+ /**
2
+ * Resource types that support bulk deletion via the delete resources modal.
3
+ */
4
+ export type DeletableResourceType = 'product' | 'standalone-price';
2
5
  export interface DeleteResourcesModalProps {
3
6
  isOpen: boolean;
4
- resourceType: ResourceTypeId;
7
+ resourceType: DeletableResourceType;
5
8
  onClose?: () => void;
6
9
  }
@@ -1,2 +1,3 @@
1
1
  import DeleteResourcesModal from "./delete-resources-modal.js";
2
+ export * from "./@types/index.js";
2
3
  export default DeleteResourcesModal;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@commercetools-frontend-extensions/delete-resources-modal",
3
3
  "description": "Shared import modal for deleting resources",
4
- "version": "2.0.4",
4
+ "version": "2.1.0",
5
5
  "license": "BSD-3-Clause",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -31,7 +31,7 @@
31
31
  "pluralize": "8.0.0",
32
32
  "prop-types": "15.8.1",
33
33
  "ramda": "^0.32.0",
34
- "@commercetools-frontend-extensions/operations": "4.3.0"
34
+ "@commercetools-frontend-extensions/operations": "4.4.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@commercetools-frontend/actions-global": "27.5.1",