@commercetools-frontend-extensions/delete-resources-modal 1.1.8 → 1.1.9

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.
@@ -1,1810 +0,0 @@
1
- 'use strict';
2
-
3
- var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
4
- var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
5
- var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
- var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
7
- var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
8
- var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
9
- var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
10
- var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
11
- var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
12
- var reactIntl = require('react-intl');
13
- var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
14
- var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
15
- var React = require('react');
16
- var sdk = require('@commercetools-frontend/sdk');
17
- var constants = require('@commercetools-frontend/constants');
18
- var pluralize = require('pluralize');
19
- var _everyInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/every');
20
- var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
21
- var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
22
- var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
23
- var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
24
- var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
25
- var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
26
- var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
27
- var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
28
- var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
29
- var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
30
- var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
31
- var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
32
- var Papa = require('papaparse');
33
- var jsxRuntime = require('@emotion/react/jsx-runtime');
34
- var applicationComponents = require('@commercetools-frontend/application-components');
35
- var fullstory = require('@commercetools-frontend/fullstory');
36
- var uiKit = require('@commercetools-frontend/ui-kit');
37
- var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
38
- var reactDropzone = require('react-dropzone');
39
- var actionsGlobal = require('@commercetools-frontend/actions-global');
40
- var _styled = require('@emotion/styled/base');
41
- var react = require('@emotion/react');
42
- var sentry = require('@commercetools-frontend/sentry');
43
- var applicationShell = require('@commercetools-frontend/application-shell');
44
- var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
45
- var i18n = require('@commercetools-frontend/i18n');
46
-
47
- function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
48
-
49
- var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
50
- var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
51
- var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
52
- var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
53
- var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
54
- var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
55
- var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
56
- var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
57
- var React__default = /*#__PURE__*/_interopDefault(React);
58
- var _everyInstanceProperty__default = /*#__PURE__*/_interopDefault(_everyInstanceProperty);
59
- var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
60
- var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
61
- var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
62
- var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
63
- var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
64
- var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
65
- var Papa__default = /*#__PURE__*/_interopDefault(Papa);
66
- var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
67
- var _styled__default = /*#__PURE__*/_interopDefault(_styled);
68
- var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
69
-
70
- function ownKeys$b(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; }
71
- function _objectSpread$b(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$b(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$b(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
72
- function reducer(state, action) {
73
- if (action.type === 'setCurrentStep') return _objectSpread$b(_objectSpread$b({}, state), {}, {
74
- currentStep: action.currentStep,
75
- progress: 0
76
- });
77
- if (action.type === 'setContainerKey') return _objectSpread$b(_objectSpread$b({}, state), {}, {
78
- containerKey: action.containerKey
79
- });
80
- if (action.type === 'cancelImport') return _objectSpread$b(_objectSpread$b({}, state), {}, {
81
- currentStep: 'upload',
82
- containerKey: undefined,
83
- droppedFile: undefined,
84
- dropAreaState: 'ready-for-drop',
85
- progress: 0
86
- });
87
- if (action.type === 'uploadNewFile') return _objectSpread$b(_objectSpread$b({}, state), {}, {
88
- currentStep: 'upload',
89
- containerKey: undefined,
90
- droppedFile: undefined,
91
- dropAreaState: 'ready-for-drop',
92
- progress: 0
93
- });
94
- if (action.type === 'setDroppedFile') {
95
- return _objectSpread$b(_objectSpread$b({}, state), {}, {
96
- droppedFile: action.droppedFile
97
- });
98
- }
99
- if (action.type === 'setAbortController') {
100
- return _objectSpread$b(_objectSpread$b({}, state), {}, {
101
- abortController: action.abortController
102
- });
103
- }
104
- if (action.type === 'setProgress') {
105
- return _objectSpread$b(_objectSpread$b({}, state), {}, {
106
- progress: action.progress
107
- });
108
- }
109
- if (action.type === 'setUploadFileResponse') {
110
- return _objectSpread$b(_objectSpread$b({}, state), {}, {
111
- uploadFileResponse: action.uploadFileResponse
112
- });
113
- }
114
- if (action.type === 'setFileUploadErrors') {
115
- return _objectSpread$b(_objectSpread$b({}, state), {}, {
116
- fileUploadErrors: action.fileUploadErrors
117
- });
118
- }
119
- throw new Error(getUnknownActionError(action));
120
- }
121
- function getUnknownActionError(actionType) {
122
- return `Unkown type: ${actionType}`;
123
- }
124
- const initialState = {
125
- currentStep: 'upload',
126
- abortController: new AbortController(),
127
- dropAreaState: 'ready-for-drop',
128
- containerKey: undefined,
129
- progress: 0,
130
- uploadFileResponse: undefined,
131
- fileUploadErrors: []
132
- };
133
- const initialActions = {
134
- setCurrentStep(_currentStep) {
135
- /**/
136
- },
137
- cancelImport() {
138
- /**/
139
- },
140
- uploadNewFile() {
141
- /**/
142
- },
143
- setDroppedFile(_nextDroppedFile) {
144
- /**/
145
- },
146
- setUploadFileResponse(_uploadFileResponse) {
147
- /**/
148
- },
149
- setFileUploadErrors(_fileUploadErrors) {
150
- /**/
151
- },
152
- setContainerKey(_containerKey) {
153
- /**/
154
- },
155
- setAbortController(_abortController) {
156
- /**/
157
- },
158
- setProgress(_progress) {
159
- /**/
160
- }
161
- };
162
-
163
- function getCreateImportContainerURL(projectKey) {
164
- return `/${projectKey}/import-containers`;
165
- }
166
- function getDeleteImportContainerURL(_ref) {
167
- let projectKey = _ref.projectKey,
168
- containerKey = _ref.containerKey;
169
- return `/${projectKey}/import-containers/${containerKey}`;
170
- }
171
- function getFileUploadURL(_ref2) {
172
- let projectKey = _ref2.projectKey,
173
- containerKey = _ref2.containerKey,
174
- resourceType = _ref2.resourceType;
175
- const resourceTypePlural = pluralize.plural(resourceType);
176
- return `/${projectKey}/${resourceTypePlural}/import-containers/${containerKey}/file-upload`;
177
- }
178
- function getProccessFileURL(_ref3) {
179
- let projectKey = _ref3.projectKey,
180
- containerKey = _ref3.containerKey;
181
- return `/${projectKey}/import-containers/${containerKey}/tasks`;
182
- }
183
-
184
- function ownKeys$a(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; }
185
- function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$a(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$a(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
186
- function createImportContainerForFileUpload(importContainerDraft, projectKey, asyncDispatch) {
187
- return asyncDispatch(sdk.actions.post({
188
- mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.IMPORT,
189
- uri: getCreateImportContainerURL(projectKey),
190
- headers: {
191
- accept: 'application/json',
192
- 'Content-Type': 'application/json'
193
- },
194
- payload: _objectSpread$a({
195
- retentionPolicy: {
196
- strategy: 'ttl',
197
- config: {
198
- timeToLive: '54h' // 2 days and 6 hours
199
- }
200
- }
201
- }, importContainerDraft)
202
- }));
203
- }
204
- function deleteImportContainer(projectKey, containerKey, asyncDispatch) {
205
- return asyncDispatch(sdk.actions.del({
206
- mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.IMPORT,
207
- uri: getDeleteImportContainerURL({
208
- projectKey,
209
- containerKey
210
- }),
211
- headers: {
212
- accept: 'application/json'
213
- }
214
- }));
215
- }
216
-
217
- function _callSuper$2(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$2() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
218
- function _isNativeReflectConstruct$2() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$2 = function () { return !!t; })(); }
219
- let HttpError = /*#__PURE__*/function (_Error) {
220
- function HttpError(statusCode, statusText, errorData) {
221
- var _this;
222
- _classCallCheck(this, HttpError);
223
- _this = _callSuper$2(this, HttpError, [`HTTP Error! Status code: ${statusCode}, message: "${statusText ? statusText : ''}"`]);
224
- _this.statusCode = void 0;
225
- _this.errorData = void 0;
226
- _this.name = 'HttpError';
227
- _this.statusCode = statusCode;
228
- _this.errorData = errorData;
229
- return _this;
230
- }
231
- _inherits(HttpError, _Error);
232
- return _createClass(HttpError);
233
- }(/*#__PURE__*/_wrapNativeSuper(Error));
234
-
235
- function _callSuper$1(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$1() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
236
- function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function () { return !!t; })(); }
237
- let MissingDeleteResourcesProviderError = /*#__PURE__*/function (_Error) {
238
- function MissingDeleteResourcesProviderError() {
239
- var _this;
240
- _classCallCheck(this, MissingDeleteResourcesProviderError);
241
- _this = _callSuper$1(this, MissingDeleteResourcesProviderError, ['useDeleteResourcesProviderError must be used within MissingDeleteResourcesProviderError']);
242
- _this.name = 'MissingDeleteResourcesProviderError';
243
- return _this;
244
- }
245
- _inherits(MissingDeleteResourcesProviderError, _Error);
246
- return _createClass(MissingDeleteResourcesProviderError);
247
- }(/*#__PURE__*/_wrapNativeSuper(Error));
248
-
249
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct__default["default"](o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
250
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
251
- let UnexpectedResourceTypeError = /*#__PURE__*/function (_Error) {
252
- function UnexpectedResourceTypeError(resourceType) {
253
- var _this;
254
- _classCallCheck(this, UnexpectedResourceTypeError);
255
- _this = _callSuper(this, UnexpectedResourceTypeError, [`Unexpected resource type "${resourceType}"`]);
256
- _this.name = 'UnexpectedResourceTypeError';
257
- return _this;
258
- }
259
- _inherits(UnexpectedResourceTypeError, _Error);
260
- return _createClass(UnexpectedResourceTypeError);
261
- }(/*#__PURE__*/_wrapNativeSuper(Error));
262
-
263
- var sharedMessages = reactIntl.defineMessages({
264
- deleteModalTitle: {
265
- id: 'DeleteResourcesModal.deleteModalTitle',
266
- description: 'The title of the modal',
267
- defaultMessage: 'Bulk delete via CSV'
268
- },
269
- startBulkDelete: {
270
- id: 'DeleteResourcesModal.startBulkDelete',
271
- description: 'Start bulk delete button',
272
- defaultMessage: 'Start bulk delete'
273
- },
274
- cancel: {
275
- id: 'DeleteResourcesModal.cancel',
276
- description: 'The label for the cancel button',
277
- defaultMessage: 'Cancel'
278
- },
279
- product: {
280
- id: 'DeleteResourcesModal.product',
281
- description: 'Label for the product resource type',
282
- defaultMessage: 'product'
283
- },
284
- products: {
285
- id: 'DeleteResourcesModal.products',
286
- description: 'Plural form of product',
287
- defaultMessage: 'products'
288
- },
289
- inventory: {
290
- id: 'DeleteResourcesModal.inventory',
291
- description: 'Label for the inventory entry resource type',
292
- defaultMessage: 'inventory entry'
293
- },
294
- inventories: {
295
- id: 'DeleteResourcesModal.inventories',
296
- description: 'Plural form of inventory entry',
297
- defaultMessage: 'inventory entries'
298
- },
299
- category: {
300
- id: 'DeleteResourcesModal.category',
301
- description: 'Label for the category resource type',
302
- defaultMessage: 'category'
303
- },
304
- categories: {
305
- id: 'DeleteResourcesModal.categories',
306
- description: 'Plural form of category',
307
- defaultMessage: 'categories'
308
- },
309
- customer: {
310
- id: 'DeleteResourcesModal.customer',
311
- description: 'Label for the customer resource type',
312
- defaultMessage: 'customer'
313
- },
314
- customers: {
315
- id: 'DeleteResourcesModal.customers',
316
- description: 'Plural form of customer',
317
- defaultMessage: 'customers'
318
- },
319
- order: {
320
- id: 'DeleteResourcesModal.order',
321
- description: 'Label for the order resource type',
322
- defaultMessage: 'order'
323
- },
324
- orders: {
325
- id: 'DeleteResourcesModal.orders',
326
- description: 'Plural form of order',
327
- defaultMessage: 'orders'
328
- },
329
- price: {
330
- id: 'DeleteResourcesModal.price',
331
- description: 'Label for the price resource type',
332
- defaultMessage: 'price'
333
- },
334
- prices: {
335
- id: 'DeleteResourcesModal.prices',
336
- description: 'Plural form of price',
337
- defaultMessage: 'prices'
338
- },
339
- 'product-draft': {
340
- id: 'DeleteResourcesModal.product-draft',
341
- description: 'Label for the product-draft resource type',
342
- defaultMessage: 'product draft'
343
- },
344
- 'product-drafts': {
345
- id: 'DeleteResourcesModal.product-drafts',
346
- description: 'Plural form of product draft',
347
- defaultMessage: 'product drafts'
348
- },
349
- 'product-type': {
350
- id: 'DeleteResourcesModal.product-type',
351
- description: 'Label for the product-type resource type',
352
- defaultMessage: 'product type'
353
- },
354
- 'product-types': {
355
- id: 'DeleteResourcesModal.product-types',
356
- description: 'Plural form of product type',
357
- defaultMessage: 'product types'
358
- },
359
- 'product-variant': {
360
- id: 'DeleteResourcesModal.product-variant',
361
- description: 'Label for the product-variant resource type',
362
- defaultMessage: 'product variant'
363
- },
364
- 'product-variants': {
365
- id: 'DeleteResourcesModal.product-variants',
366
- description: 'Plural form of product variant',
367
- defaultMessage: 'product variants'
368
- },
369
- 'product-variant-patch': {
370
- id: 'DeleteResourcesModal.product-variant-patch',
371
- description: 'Label for the product-variant-patch resource type',
372
- defaultMessage: 'product variant patch'
373
- },
374
- 'product-variant-patches': {
375
- id: 'DeleteResourcesModal.product-variant-patches',
376
- description: 'Plural form of product variant patch',
377
- defaultMessage: 'product variant patches'
378
- },
379
- 'standalone-price': {
380
- id: 'DeleteResourcesModal.standalone-price',
381
- description: 'Label for the standalone-price resource type',
382
- defaultMessage: 'standalone price'
383
- },
384
- 'standalone-prices': {
385
- id: 'DeleteResourcesModal.standalone-prices',
386
- description: 'Plural form of standalone price',
387
- defaultMessage: 'standalone prices'
388
- },
389
- 'discount-code': {
390
- id: 'DeleteResourcesModal.discount-code',
391
- description: 'Label for the discount-code resource type',
392
- defaultMessage: 'discount code'
393
- },
394
- 'discount-codes': {
395
- id: 'DeleteResourcesModal.discount-codes',
396
- description: 'Plural form of discount code',
397
- defaultMessage: 'discount codes'
398
- },
399
- unknownResourceType: {
400
- id: 'DeleteResourcesModal.unknown-resource-type',
401
- description: 'Label for the unknown resource type',
402
- defaultMessage: 'unknown resource type'
403
- }
404
- });
405
-
406
- function convertFileSizeToKB(sizeInBytes) {
407
- return sizeInBytes / 1000;
408
- }
409
- function hasOwnProperty(obj, prop) {
410
- return typeof obj === 'object' && obj !== null && obj.hasOwnProperty(prop);
411
- }
412
- function hasRequiredFields(maybeValidObject, requiredFields) {
413
- return typeof maybeValidObject === 'object' && maybeValidObject !== null && _everyInstanceProperty__default["default"](requiredFields).call(requiredFields, property => hasOwnProperty(maybeValidObject, property));
414
- }
415
- function isAbortError(error) {
416
- return error instanceof DOMException && error.name === 'AbortError';
417
- }
418
- function resourceTypeToMessage(resourceType) {
419
- const resourceTypeMap = {
420
- category: sharedMessages.category,
421
- product: sharedMessages.product,
422
- 'product-type': sharedMessages['product-type'],
423
- order: sharedMessages.order,
424
- customer: sharedMessages.customer,
425
- 'discount-code': sharedMessages['discount-code'],
426
- inventory: sharedMessages.inventory,
427
- // TODO: remove `inventory` after aligning the resource type names in the file upload API
428
- 'inventory-entry': sharedMessages.inventory,
429
- 'order-patch': sharedMessages['order-patch'],
430
- price: sharedMessages.price,
431
- 'product-draft': sharedMessages['product-draft'],
432
- 'product-variant': sharedMessages['product-variant'],
433
- 'product-variant-patch': sharedMessages['product-variant-patch'],
434
- 'standalone-price': sharedMessages['standalone-price']
435
- };
436
- const message = resourceTypeMap[resourceType];
437
- if (!message) {
438
- console.warn(new UnexpectedResourceTypeError(resourceType));
439
- return sharedMessages.unknownResourceType;
440
- }
441
- return message;
442
- }
443
- function resourceTypeToPluralMessage(resourceType) {
444
- const resourceTypePluralMap = {
445
- category: sharedMessages.categories,
446
- product: sharedMessages.products,
447
- 'product-type': sharedMessages['product-types'],
448
- order: sharedMessages.orders,
449
- customer: sharedMessages.customers,
450
- 'discount-code': sharedMessages['discount-codes'],
451
- inventory: sharedMessages.inventories,
452
- // TODO: remove `inventory` after aligning the resource type names in the file upload API
453
- 'inventory-entry': sharedMessages.inventories,
454
- 'order-patch': sharedMessages['order-patches'],
455
- price: sharedMessages.prices,
456
- 'product-draft': sharedMessages['product-drafts'],
457
- 'product-variant': sharedMessages['product-variants'],
458
- 'product-variant-patch': sharedMessages['product-variant-patches'],
459
- 'standalone-price': sharedMessages['standalone-prices']
460
- };
461
- const message = resourceTypePluralMap[resourceType];
462
- if (!message) {
463
- console.warn(new UnexpectedResourceTypeError(resourceType));
464
- return sharedMessages.unknownResourceType;
465
- }
466
- return message;
467
- }
468
-
469
- const encodeFileNameWithTimestampToContainerKey = fileName => {
470
- return btoa(_JSON$stringify__default["default"]({
471
- timestamp: new Date().getTime(),
472
- fileName
473
- })).replace(/=+$/g, '');
474
- };
475
-
476
- function ownKeys$9(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; }
477
- function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$9(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$9(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
478
- /**
479
- * Returns the number of rows in a CSV file excluding the header
480
- * @param file The CSV file to process.
481
- * @returns A promise that resolves to the number of rows
482
- */
483
- const getRowCount = file => {
484
- return new _Promise__default["default"](resolve => {
485
- let lineCount = 0;
486
- Papa__default["default"].parse(file, {
487
- step: _ref => {
488
- let data = _ref.data;
489
- // empty lines at the end of the file should not be counted
490
- if (_Array$isArray__default["default"](data) && _findInstanceProperty__default["default"](data).call(data, Boolean)) lineCount++;
491
- },
492
- complete: () => {
493
- // Subtract 1 for the header row
494
- // We use Math.max to make sure the count is not less than 0, this is needed for empty files
495
- resolve(Math.max(0, lineCount - 1));
496
- }
497
- });
498
- });
499
- };
500
-
501
- /**
502
- * Checks if the CSV file only contains a single column named 'key'
503
- * @param file The CSV file to process
504
- * @returns A promise that resolves to true if the file contains only one column named 'key', otherwise false
505
- */
506
- const hasSingleKeyColumn = file => {
507
- return new _Promise__default["default"](resolve => {
508
- Papa__default["default"].parse(file, {
509
- header: true,
510
- // Only parse the first row (header)
511
- preview: 1,
512
- complete: results => {
513
- const fields = results?.meta?.fields;
514
- resolve(fields?.length === 1 && fields[0] === 'key');
515
- }
516
- });
517
- });
518
- };
519
- const toBytes = megabytes => megabytes * 1024 * 1024;
520
- const mapFileUploadErrorsToUploadFileErrorRows = uploadFileErrors => {
521
- let idCounter = 1;
522
- return _mapInstanceProperty__default["default"](uploadFileErrors).call(uploadFileErrors, uploadFileError => _objectSpread$9(_objectSpread$9({}, uploadFileError), {}, {
523
- id: String(idCounter++)
524
- }));
525
- };
526
-
527
- async function processUploadedFile(_ref) {
528
- let projectKey = _ref.projectKey,
529
- containerKey = _ref.containerKey,
530
- asyncDispatch = _ref.asyncDispatch,
531
- resourceType = _ref.resourceType;
532
- const uri = getProccessFileURL({
533
- projectKey,
534
- containerKey
535
- });
536
- const response = await asyncDispatch(sdk.actions.post({
537
- mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.IMPORT,
538
- uri: uri,
539
- headers: {
540
- accept: 'application/json',
541
- 'Content-Type': 'application/json'
542
- },
543
- payload: {
544
- task: 'process-file',
545
- parameter: {
546
- resourceType,
547
- action: 'delete'
548
- }
549
- }
550
- }));
551
- assertProcessFileResponse(response);
552
- return response;
553
- }
554
- function assertProcessFileResponse(maybeProcessFileResponse) {
555
- const requiredFields = ['message'];
556
- if (hasRequiredFields(maybeProcessFileResponse, requiredFields)) return;
557
- throw new Error('Invalid response');
558
- }
559
-
560
- const DeleteResourcesContext = /*#__PURE__*/React__default["default"].createContext({
561
- state: initialState,
562
- actions: initialActions,
563
- onClose: () => {}
564
- });
565
- const DeleteResourcesProvider = props => {
566
- const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
567
- projectKey: context.project?.key
568
- })),
569
- projectKey = _useApplicationContex.projectKey;
570
- const asyncDispatch = sdk.useAsyncDispatch();
571
- const _React$useReducer = React__default["default"].useReducer(reducer, initialState),
572
- _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
573
- state = _React$useReducer2[0],
574
- dispatch = _React$useReducer2[1];
575
- const setCurrentStep = currentStep => dispatch({
576
- type: 'setCurrentStep',
577
- currentStep
578
- });
579
- const setContainerKey = containerKey => dispatch({
580
- type: 'setContainerKey',
581
- containerKey
582
- });
583
- const cancelImport = () => dispatch({
584
- type: 'cancelImport'
585
- });
586
- const uploadNewFile = () => dispatch({
587
- type: 'uploadNewFile'
588
- });
589
- const setDroppedFile = droppedFile => dispatch({
590
- type: 'setDroppedFile',
591
- droppedFile: droppedFile
592
- });
593
- const setFileUploadErrors = fileUploadErrors => {
594
- dispatch({
595
- type: 'setFileUploadErrors',
596
- fileUploadErrors
597
- });
598
- };
599
- const setAbortController = abortController => dispatch({
600
- type: 'setAbortController',
601
- abortController: abortController
602
- });
603
- const setProgress = progress => dispatch({
604
- type: 'setProgress',
605
- progress
606
- });
607
- const setUploadFileResponse = uploadFileResponse => {
608
- dispatch({
609
- type: 'setUploadFileResponse',
610
- uploadFileResponse
611
- });
612
- };
613
- const handleClose = function () {
614
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
615
- if (state.abortController) state.abortController.abort();
616
- if (typeof props.onClose === 'function') props.onClose();
617
- // Removes the associated import container when the import is closed
618
- if (options.shouldDeleteImportContainer && projectKey && state.containerKey) deleteImportContainer(projectKey, state.containerKey, asyncDispatch);
619
- };
620
- return jsxRuntime.jsx(DeleteResourcesContext.Provider, {
621
- value: {
622
- resourceType: props.resourceType,
623
- state,
624
- onClose: handleClose,
625
- actions: {
626
- setCurrentStep,
627
- cancelImport,
628
- uploadNewFile,
629
- setDroppedFile,
630
- setUploadFileResponse,
631
- setFileUploadErrors,
632
- setContainerKey,
633
- setAbortController,
634
- setProgress
635
- }
636
- },
637
- children: props.children
638
- });
639
- };
640
-
641
- const getBorderColor = state => {
642
- const borderColors = {
643
- default: '#909dbc',
644
- error: '#e60050',
645
- active: uiKit.customProperties.colorPrimary
646
- };
647
- return borderColors[state] || borderColors.default;
648
- };
649
- const getDashedBorder = function () {
650
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
651
- const color = getBorderColor(state);
652
- const svgContent = `
653
- <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
654
- <rect width="100%" height="100%" fill="none" stroke="${color}" stroke-width="2px" stroke-dasharray="6,6" stroke-dashoffset="0" stroke-linecap="square"/>
655
- </svg>
656
- `;
657
- return `data:image/svg+xml,${encodeURIComponent(svgContent)}`;
658
- };
659
- const base = /*#__PURE__*/react.css("border-radius:", uiKit.customProperties.borderRadius6, ";min-height:136px;display:flex;justify-content:center;align-items:center;" + ("" ), "" );
660
- const readyForDrop = /*#__PURE__*/react.css("background-image:url(\"", getDashedBorder(), "\");background-color:", uiKit.customProperties.colorSurface, ";" + ("" ), "" );
661
- const activeDrag = /*#__PURE__*/react.css("background-image:url(\"", getDashedBorder('active'), "\");background-color:", uiKit.customProperties.colorPrimary95, ";padding:", uiKit.customProperties.spacing50, " 100px;" + ("" ), "" );
662
- const fileDropped = /*#__PURE__*/react.css("background-image:url(\"", getDashedBorder(), "\");background-color:", uiKit.customProperties.colorSurface, ";padding:", uiKit.customProperties.spacing50, " 100px;" + ("" ), "" );
663
- const styles = {
664
- base,
665
- readyForDrop,
666
- fileDropped,
667
- activeDrag
668
- };
669
-
670
- const DropWrapper = /*#__PURE__*/_styled__default["default"]("div", {
671
- target: "e16mdg0x0"
672
- } )(styles.base, " ", props => {
673
- if (props.dropAreaState === 'ready-for-drop') {
674
- return styles.readyForDrop;
675
- }
676
- if (props.dropAreaState === 'active-drag') {
677
- return styles.activeDrag;
678
- }
679
- if (props.dropAreaState === 'file-dropped') {
680
- return styles.fileDropped;
681
- }
682
- return getDefaultDropWrapperStyles(props.dropAreaState);
683
- }, ";" + ("" ));
684
- function getDefaultDropWrapperStyles(_dropAreaState) {
685
- return /*#__PURE__*/react.css("" , "" );
686
- }
687
-
688
- var ActiveDragDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./active-drag-drop-area-ab4c7782.cjs.prod.js'); }));
689
-
690
- var EnabledDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./enabled-drop-area-a5f9c0a2.cjs.prod.js'); }));
691
-
692
- var FileDropped = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./file-dropped-area-708f8ff4.cjs.prod.js'); }));
693
-
694
- function getDropArea(_ref) {
695
- let dropAreaState = _ref.dropAreaState,
696
- isFileDropped = _ref.isFileDropped;
697
- if (dropAreaState === 'ready-for-drop') {
698
- return jsxRuntime.jsx(EnabledDropArea, {});
699
- }
700
- if (dropAreaState === 'file-dropped') {
701
- return jsxRuntime.jsx(FileDropped, {});
702
- }
703
- if (dropAreaState === 'active-drag') {
704
- return jsxRuntime.jsx(ActiveDragDropArea, {
705
- isFileDropped: isFileDropped
706
- });
707
- }
708
- return fallbackDropArea();
709
- }
710
- function fallbackDropArea(_invalidDropAreaState) {
711
- return jsxRuntime.jsx(FileDropped, {});
712
- }
713
- function getDropAreaState(flags) {
714
- if (flags.isDragActive) {
715
- return 'active-drag';
716
- }
717
- if (flags.isReady) {
718
- return 'file-dropped';
719
- }
720
- return 'ready-for-drop';
721
- }
722
-
723
- var messages$4 = reactIntl.defineMessages({
724
- dragAndDropCSV: {
725
- id: 'DeleteResourcesModal.dragAndDropCSV',
726
- description: 'The message telling the user to drag and drop CSV file in the file drop area',
727
- defaultMessage: 'Drag and drop CSV'
728
- },
729
- or: {
730
- id: 'DeleteResourcesModal.or',
731
- description: 'The word "or" in the drag and drop message',
732
- defaultMessage: 'or'
733
- },
734
- browseButton: {
735
- id: 'DeleteResourcesModal.browseFile',
736
- defaultMessage: 'Browse file'
737
- },
738
- uploadAndPreview: {
739
- id: 'DeleteResourcesModal.uploadAndPreview',
740
- description: 'Label for the button that uploads the file and shows the preview',
741
- defaultMessage: 'Upload and preview'
742
- },
743
- chooseFile: {
744
- id: 'DeleteResourcesModal.chooseFile',
745
- description: 'Label for a button on the file upload page, shown on ready to upload state',
746
- defaultMessage: 'Choose file'
747
- },
748
- fileUploadFailed: {
749
- id: 'DeleteResourcesModal.fileUploadFailed',
750
- description: 'A title on the file upload page, shown on file upload error state',
751
- defaultMessage: 'File upload failed'
752
- },
753
- fileFormatNotSupported: {
754
- id: 'DeleteResourcesModal.fileFormatNotSupported',
755
- description: 'Error message displayed when a user drags and drops a non-CSV file',
756
- defaultMessage: 'Invalid file format: The file is not in CSV format and cannot be processed.'
757
- },
758
- tooManyFilesError: {
759
- id: 'DeleteResourcesModal.tooManyFilesError',
760
- description: 'Error message displayed when a user drags and drops multiple files at once',
761
- defaultMessage: 'Multiple files detected: You can only drag and drop one file at a time.'
762
- },
763
- genericError: {
764
- id: 'DeleteResourcesModal.genericError',
765
- description: 'Default error message for unexpected file upload issues (for unhandled cases)',
766
- defaultMessage: 'Error occurred: Please try uploading the file again or contact our support team for assistance.'
767
- },
768
- dataType: {
769
- id: 'DeleteResourcesModal.dataType',
770
- description: 'Label for the data type selection dropdown',
771
- defaultMessage: 'Data type'
772
- },
773
- instructions: {
774
- id: 'DeleteResourcesModal.instructions',
775
- description: 'Label for the instructions section',
776
- defaultMessage: 'Instructions'
777
- }
778
- });
779
-
780
- const useDeleteResourcesContext = () => {
781
- const context = React.useContext(DeleteResourcesContext);
782
- if (!context) {
783
- throw new MissingDeleteResourcesProviderError();
784
- }
785
- return context;
786
- };
787
-
788
- var messages$3 = reactIntl.defineMessages({
789
- fileSizeExceededTitle: {
790
- id: 'DeleteResourcesModal.sizeExceededTitle',
791
- defaultMessage: 'File size exceeded'
792
- },
793
- fileSizeExceededDescription: {
794
- id: 'DeleteResourcesModal.sizeExceededDescription',
795
- description: 'Error description when the file size exceeds the allowable limit',
796
- defaultMessage: 'The file exceeds the maximum allowed size of {fileSizeLimit} MB'
797
- },
798
- rowLimitExceededTitle: {
799
- id: 'DeleteResourcesModal.rowLimitExceededTitle',
800
- defaultMessage: 'Row limit exceeded'
801
- },
802
- rowLimitExceededDescription: {
803
- id: 'DeleteResourcesModal.rowLimitExceededDescription',
804
- description: 'Error description when the file contains more rows than the allowable maximum',
805
- defaultMessage: 'The file contains more than the allowable maximum of {rowLimit} rows'
806
- },
807
- dropAreaNotEnoughRowsTitle: {
808
- id: 'DeleteResourcesModal.dropAreaNotEnoughRowsTitle',
809
- description: 'Error title shown when the uploaded CSV file does not contain a header and at least one row of data',
810
- defaultMessage: 'Invalid CSV file'
811
- },
812
- dropAreaNotEnoughRowsDescription: {
813
- id: 'DeleteResourcesModal.dropAreaNotEnoughRowsDescription',
814
- description: 'Error description shown when the uploaded CSV file does not contain a header and at least one row of data',
815
- defaultMessage: 'Make sure the file contains a header and at least one row of data'
816
- },
817
- unexpectedError: {
818
- id: 'DeleteResourcesModal.unexpectedError',
819
- description: 'Generic notification message when file upload fails',
820
- defaultMessage: 'An unexpected error occurred during the file upload. Please try again, or contact support if this error occurs again.'
821
- },
822
- missingRequiredField: {
823
- id: 'DeleteResourcesModal.missingRequiredField',
824
- description: 'Error message displayed when a required field is missing',
825
- defaultMessage: 'Missing required field'
826
- },
827
- missingKeyError: {
828
- id: 'DeleteResourcesModal.missingKeyError',
829
- description: 'Error message displayed when the uploaded file is missing the key field',
830
- defaultMessage: "The 'key' field is missing or incomplete in some rows. Please ensure every row has a 'key' value."
831
- },
832
- csvFormatErrorTitle: {
833
- id: 'DeleteResourcesModal.csvFormatErrorTitle',
834
- description: 'Error title shown when the uploaded CSV file is not formatted correctly',
835
- defaultMessage: 'Invalid CSV file'
836
- },
837
- csvFormatErrorDescription: {
838
- id: 'UnpublishProductsModal.csvFormatErrorDescription',
839
- description: 'Error message displayed when the CSV file is not formatted correctly',
840
- defaultMessage: "Your CSV file is not formatted correctly. Make sure the file contains only one column named 'key', which includes the product keys"
841
- }
842
- });
843
-
844
- const IMPORT_TAG_KEYS = {
845
- source: 'source'
846
- };
847
- const IMPORT_TAG_VALUES = {
848
- fileUpload: 'file-upload'
849
- };
850
- const TAG_KEY_SOURCE_FILE_UPLOAD = `${IMPORT_TAG_KEYS.source}:${IMPORT_TAG_VALUES.fileUpload}`;
851
- const FILE_SIZE_LIMIT_MB = 35;
852
- const ROW_COUNT_LIMIT = 80_000;
853
- const DOCUMENTATION_LINKS = {
854
- product: 'https://docs.commercetools.com/merchant-center/product-list#bulk-delete-via-csv-import'
855
- };
856
- const TEMPLATE_DOWNLOAD_LINKS = {
857
- product: 'https://docs.commercetools.com/merchant-center/downloads/product_delete_import_template.csv'
858
- };
859
-
860
- function ownKeys$8(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; }
861
- function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$8(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$8(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
862
- const addProxyPrefixToUrl = (uri, proxy) => {
863
- return proxy ? `/proxy/${proxy}${uri}` : uri;
864
- };
865
- const fetchUsingXhr = _ref2 => {
866
- let url = _ref2.url,
867
- payload = _ref2.payload,
868
- config = _ref2.config,
869
- onProgress = _ref2.onProgress,
870
- onSuccess = _ref2.onSuccess,
871
- onError = _ref2.onError;
872
- const options = applicationShell.createHttpClientOptions({
873
- headers: _objectSpread$8({
874
- 'Content-Type': 'application/json'
875
- }, config?.headers)
876
- });
877
- const xhr = new XMLHttpRequest();
878
- xhr.open(config?.method, applicationShell.buildApiUrl(addProxyPrefixToUrl(url, config?.proxy)), true);
879
- // Include cookies in the request
880
- xhr.withCredentials = true;
881
- if (options.headers) {
882
- var _context;
883
- _forEachInstanceProperty__default["default"](_context = _Object$keys__default["default"](options.headers)).call(_context, key => {
884
- xhr.setRequestHeader(key, options.headers[key]);
885
- });
886
- }
887
- xhr.upload.onprogress = function (event) {
888
- if (event.lengthComputable) {
889
- const percentComplete = event.loaded / event.total * 100;
890
- onProgress(percentComplete);
891
- }
892
- };
893
- xhr.onload = function () {
894
- const data = JSON.parse(xhr.responseText);
895
- // Code copied from `executeHttpClientRequest` to replicate the same behavior
896
- const refreshedSessionToken = xhr.getResponseHeader('x-refreshed-session-token');
897
- if (refreshedSessionToken) {
898
- applicationShellConnectors.oidcStorage.setActiveSession(refreshedSessionToken);
899
- }
900
- if (xhr.status >= 200 && xhr.status < 300) {
901
- onSuccess(data);
902
- } else {
903
- onError(new HttpError(xhr.status, xhr.statusText, data));
904
- }
905
- };
906
- xhr.onerror = function () {
907
- const errorData = JSON.parse(xhr.responseText);
908
- onError(new HttpError(xhr.status, xhr.statusText, errorData));
909
- };
910
- xhr.onabort = function () {
911
- onError(new DOMException('Aborted', 'AbortError'));
912
- };
913
- xhr.send(payload);
914
- return xhr;
915
- };
916
-
917
- function uploadFileForImport(_ref) {
918
- let projectKey = _ref.projectKey,
919
- containerKey = _ref.containerKey,
920
- resourceType = _ref.resourceType,
921
- file = _ref.file,
922
- abortSignal = _ref.abortSignal,
923
- onSuccess = _ref.onSuccess,
924
- onProgress = _ref.onProgress,
925
- onError = _ref.onError;
926
- const uri = getFileUploadURL({
927
- projectKey,
928
- containerKey,
929
- resourceType
930
- });
931
- const formData = new FormData();
932
- formData.append('file', file, file.name);
933
- return fetchUsingXhr({
934
- url: uri,
935
- payload: formData,
936
- config: {
937
- abortSignal,
938
- proxy: constants.MC_API_PROXY_TARGETS.IMPORT,
939
- method: 'POST',
940
- headers: {
941
- 'Content-Type': null
942
- }
943
- },
944
- onProgress,
945
- onSuccess,
946
- onError
947
- });
948
- }
949
-
950
- const useUpload = () => {
951
- const intl = reactIntl.useIntl();
952
- const projectKey = applicationShellConnectors.useApplicationContext(context => context.project?.key);
953
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
954
- resourceType = _useDeleteResourcesCo.resourceType,
955
- state = _useDeleteResourcesCo.state,
956
- actions = _useDeleteResourcesCo.actions;
957
- const asyncDispatch = sdk.useAsyncDispatch();
958
- const showNotification = actionsGlobal.useShowNotification();
959
- React__default["default"].useEffect(() => {
960
- return () => {
961
- if (state.abortController) state.abortController.abort();
962
- };
963
- }, [state.abortController]);
964
- const isFileValid = async file => {
965
- const errors = [];
966
- const rowCount = await getRowCount(file);
967
- if (rowCount < 1) errors.push({
968
- title: intl.formatMessage(messages$3.dropAreaNotEnoughRowsTitle),
969
- description: intl.formatMessage(messages$3.dropAreaNotEnoughRowsDescription)
970
- });
971
- if (file.size > toBytes(FILE_SIZE_LIMIT_MB)) errors.push({
972
- title: intl.formatMessage(messages$3.fileSizeExceededTitle),
973
- description: intl.formatMessage(messages$3.fileSizeExceededDescription, {
974
- fileSizeLimit: intl.formatNumber(FILE_SIZE_LIMIT_MB)
975
- })
976
- });
977
- if (!(await hasSingleKeyColumn(file))) {
978
- errors.push({
979
- title: intl.formatMessage(messages$3.csvFormatErrorTitle),
980
- description: intl.formatMessage(messages$3.csvFormatErrorDescription)
981
- });
982
- }
983
- if (rowCount > ROW_COUNT_LIMIT) errors.push({
984
- title: intl.formatMessage(messages$3.rowLimitExceededTitle),
985
- description: intl.formatMessage(messages$3.rowLimitExceededDescription, {
986
- rowLimit: intl.formatNumber(ROW_COUNT_LIMIT)
987
- })
988
- });
989
- if (errors.length > 0) {
990
- actions.setFileUploadErrors(errors);
991
- actions.setCurrentStep('upload-error');
992
- return false;
993
- }
994
- return true;
995
- };
996
- const handleUploadError = error => {
997
- if (isAbortError(error)) {
998
- actions.cancelImport();
999
- return;
1000
- }
1001
- if (error instanceof HttpError) {
1002
- if (error.errorData?.code === 'MISSING_KEY_ERROR') {
1003
- actions.setFileUploadErrors([{
1004
- title: intl.formatMessage(messages$3.missingRequiredField),
1005
- description: intl.formatMessage(messages$3.missingKeyError)
1006
- }]);
1007
- actions.setCurrentStep('upload-error');
1008
- } else {
1009
- actions.cancelImport();
1010
- showNotification({
1011
- kind: 'error',
1012
- domain: constants.DOMAINS.PAGE,
1013
- text: intl.formatMessage(messages$3.unexpectedError)
1014
- });
1015
- }
1016
- } else {
1017
- actions.cancelImport();
1018
- showNotification({
1019
- kind: 'error',
1020
- domain: constants.DOMAINS.PAGE,
1021
- text: String(error)
1022
- });
1023
- sentry.reportErrorToSentry(new Error('Upload File Error: An unexpected issue occurred while uploading the file'), {
1024
- extra: {
1025
- error,
1026
- projectKey,
1027
- containerKey: state.containerKey,
1028
- fileSizeInBytes: state.droppedFile?.size
1029
- }
1030
- });
1031
- }
1032
- };
1033
- const handleUploadAndValidation = async () => {
1034
- if (!projectKey || !state.droppedFile) return;
1035
- const canUpload = await isFileValid(state.droppedFile);
1036
- if (!canUpload) return;
1037
- actions.setCurrentStep('uploading');
1038
- const containerKey = encodeFileNameWithTimestampToContainerKey(state.droppedFile.name);
1039
- actions.setContainerKey(containerKey);
1040
- try {
1041
- await createImportContainerForFileUpload({
1042
- key: containerKey,
1043
- tags: [TAG_KEY_SOURCE_FILE_UPLOAD],
1044
- resourceType
1045
- }, projectKey, asyncDispatch);
1046
- const newAbortController = uploadFileForImport({
1047
- projectKey,
1048
- containerKey,
1049
- resourceType,
1050
- file: state.droppedFile,
1051
- onSuccess: fileUploadResponse => {
1052
- actions.setUploadFileResponse(fileUploadResponse);
1053
- actions.setCurrentStep('upload-preview');
1054
- },
1055
- onProgress: progress => {
1056
- actions.setProgress(progress);
1057
- },
1058
- onError: error => {
1059
- deleteImportContainer(projectKey, containerKey, asyncDispatch);
1060
- handleUploadError(error);
1061
- }
1062
- });
1063
- actions.setAbortController(newAbortController);
1064
- } catch (error) {
1065
- deleteImportContainer(projectKey, containerKey, asyncDispatch);
1066
- handleUploadError(error);
1067
- }
1068
- };
1069
- return {
1070
- handleUploadAndValidation
1071
- };
1072
- };
1073
-
1074
- function ownKeys$7(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; }
1075
- function _objectSpread$7(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$7(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$7(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1076
- const FileDropArea = () => {
1077
- const intl = reactIntl.useIntl();
1078
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
1079
- state = _useDeleteResourcesCo.state,
1080
- actions = _useDeleteResourcesCo.actions;
1081
- const showNotification = actionsGlobal.useShowNotification();
1082
- const onDrop = React__default["default"].useCallback(_ref => {
1083
- let _ref2 = _slicedToArray(_ref, 1),
1084
- file = _ref2[0];
1085
- if (!file) return;
1086
- actions.setDroppedFile(file);
1087
- }, [actions]);
1088
- const _useDropzone = reactDropzone.useDropzone({
1089
- onDrop,
1090
- multiple: false,
1091
- accept: {
1092
- 'text/csv': ['.csv']
1093
- },
1094
- onDropRejected: _ref3 => {
1095
- var _context, _context2;
1096
- let _ref4 = _slicedToArray(_ref3, 1),
1097
- rejectedFile = _ref4[0];
1098
- if (_someInstanceProperty__default["default"](_context = rejectedFile.errors).call(_context, error => error.code === 'too-many-files')) {
1099
- showNotification({
1100
- kind: 'error',
1101
- domain: constants.DOMAINS.PAGE,
1102
- text: intl.formatMessage(messages$4.tooManyFilesError)
1103
- });
1104
- return;
1105
- }
1106
- if (_someInstanceProperty__default["default"](_context2 = rejectedFile.errors).call(_context2, error => error.code === 'file-invalid-type')) {
1107
- showNotification({
1108
- kind: 'error',
1109
- domain: constants.DOMAINS.PAGE,
1110
- text: intl.formatMessage(messages$4.fileFormatNotSupported)
1111
- });
1112
- } else {
1113
- showNotification({
1114
- kind: 'error',
1115
- domain: constants.DOMAINS.PAGE,
1116
- text: intl.formatMessage(messages$4.genericError)
1117
- });
1118
- }
1119
- }
1120
- }),
1121
- getRootProps = _useDropzone.getRootProps,
1122
- getInputProps = _useDropzone.getInputProps,
1123
- isDragActive = _useDropzone.isDragActive;
1124
- const dropAreaState = React__default["default"].useMemo(() => getDropAreaState({
1125
- isReady: Boolean(state.droppedFile),
1126
- isDragActive
1127
- }), [state.droppedFile, isDragActive]);
1128
- const dropArea = getDropArea({
1129
- dropAreaState,
1130
- isFileDropped: Boolean(state.droppedFile)
1131
- });
1132
- return jsxRuntime.jsxs(DropWrapper, _objectSpread$7(_objectSpread$7({
1133
- role: "presentation"
1134
- }, getRootProps()), {}, {
1135
- dropAreaState: dropAreaState,
1136
- children: [jsxRuntime.jsx("input", _objectSpread$7({
1137
- "data-testid": "file-input"
1138
- }, getInputProps())), jsxRuntime.jsx(uiKit.Constraints.Horizontal, {
1139
- children: dropArea
1140
- })]
1141
- }));
1142
- };
1143
-
1144
- var messages$2 = reactIntl.defineMessages({
1145
- fileUploadInstruction: {
1146
- id: 'DeleteResourcesModal.fileUploadInstruction',
1147
- description: 'Instructions for uploading a CSV file with resource keys to delete',
1148
- defaultMessage: "The CSV file must contain the {resourceType} keys to be deleted under the header 'key'."
1149
- },
1150
- fileUploadInstructionForMaxFileSize: {
1151
- id: 'DeleteResourcesModal.fileUploadInstructionForMaxFileSize',
1152
- description: 'Instructions for uploading a CSV file with a max file size',
1153
- defaultMessage: 'Maximum file size is {maxFileSize} MB with a limit of {maxRowCount} rows. Download <csvTemplateLink>the CSV template</csvTemplateLink> or refer to <documentationLink>the documentation</documentationLink>.'
1154
- },
1155
- unpublishNote: {
1156
- id: 'DeleteResourcesModal.unpublishNote',
1157
- description: 'Note to unpublish products before deleting them',
1158
- defaultMessage: 'Please note that published products <b>must be unpublished</b> before they can be deleted.'
1159
- }
1160
- });
1161
-
1162
- function ownKeys$6(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; }
1163
- function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$6(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$6(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1164
- const Instructions = () => {
1165
- const intl = reactIntl.useIntl();
1166
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
1167
- resourceType = _useDeleteResourcesCo.resourceType;
1168
- const documentTemplateLink = TEMPLATE_DOWNLOAD_LINKS[resourceType];
1169
- const documentationLink = DOCUMENTATION_LINKS[resourceType];
1170
- return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1171
- scale: "m",
1172
- children: [jsxRuntime.jsxs(uiKit.Text.Body, {
1173
- children: [intl.formatMessage(messages$2.fileUploadInstruction, {
1174
- resourceType: intl.formatMessage(resourceTypeToMessage(resourceType))
1175
- }), ' ', intl.formatMessage(messages$2.unpublishNote, {
1176
- b: msg => jsxRuntime.jsx("b", {
1177
- children: msg
1178
- }, "bold")
1179
- })]
1180
- }), jsxRuntime.jsx(uiKit.Text.Body, {
1181
- intlMessage: _objectSpread$6(_objectSpread$6({}, messages$2.fileUploadInstructionForMaxFileSize), {}, {
1182
- values: {
1183
- maxFileSize: intl.formatNumber(FILE_SIZE_LIMIT_MB),
1184
- maxRowCount: intl.formatNumber(ROW_COUNT_LIMIT),
1185
- csvTemplateLink: msg => jsxRuntime.jsx(uiKit.Link, {
1186
- tone: "secondary",
1187
- isExternal: true,
1188
- to: documentTemplateLink,
1189
- children: msg
1190
- }, "csvTemplateLink"),
1191
- documentationLink: msg => jsxRuntime.jsx(uiKit.Link, {
1192
- tone: "secondary",
1193
- isExternal: true,
1194
- to: documentationLink,
1195
- children: msg
1196
- }, "documentationLink")
1197
- }
1198
- })
1199
- })]
1200
- });
1201
- };
1202
-
1203
- const Upload = () => {
1204
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
1205
- state = _useDeleteResourcesCo.state,
1206
- onClose = _useDeleteResourcesCo.onClose;
1207
- const intl = reactIntl.useIntl();
1208
- const _useUpload = useUpload(),
1209
- handleUploadAndValidation = _useUpload.handleUploadAndValidation;
1210
- return jsxRuntime.jsx(applicationComponents.FormDialog, {
1211
- size: 16,
1212
- isOpen: true,
1213
- title: intl.formatMessage(sharedMessages.deleteModalTitle),
1214
- labelPrimary: intl.formatMessage(messages$4.uploadAndPreview),
1215
- onPrimaryButtonClick: handleUploadAndValidation,
1216
- isPrimaryButtonDisabled: !Boolean(state.droppedFile),
1217
- onSecondaryButtonClick: () => onClose({
1218
- shouldDeleteImportContainer: true
1219
- }),
1220
- onClose: () => onClose({
1221
- shouldDeleteImportContainer: true
1222
- }),
1223
- children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
1224
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1225
- scale: "m",
1226
- children: [jsxRuntime.jsx(Instructions, {}), jsxRuntime.jsx(FileDropArea, {})]
1227
- })
1228
- })
1229
- });
1230
- };
1231
-
1232
- const Uploading = () => {
1233
- const intl = reactIntl.useIntl();
1234
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
1235
- state = _useDeleteResourcesCo.state,
1236
- actions = _useDeleteResourcesCo.actions,
1237
- onClose = _useDeleteResourcesCo.onClose;
1238
- if (state.droppedFile?.name) return jsxRuntime.jsx(applicationComponents.InfoDialog, {
1239
- size: 16,
1240
- isOpen: true,
1241
- title: intl.formatMessage(sharedMessages.deleteModalTitle),
1242
- onClose: () => onClose({
1243
- shouldDeleteImportContainer: true
1244
- }),
1245
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1246
- scale: "m",
1247
- children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1248
- alignItems: "center",
1249
- justifyContent: "space-between",
1250
- children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1251
- alignItems: "center",
1252
- children: [jsxRuntime.jsx(FileIcon, {}), jsxRuntime.jsx(uiKit.Spacings.Inline, {
1253
- children: jsxRuntime.jsx(uiKit.Constraints.Horizontal, {
1254
- max: 10,
1255
- children: jsxRuntime.jsx(uiKit.Text.Body, {
1256
- truncate: true,
1257
- fontWeight: "bold",
1258
- children: state.droppedFile.name
1259
- })
1260
- })
1261
- }), jsxRuntime.jsxs(uiKit.Text.Body, {
1262
- tone: "secondary",
1263
- children: ["(", intl.formatNumber(convertFileSizeToKB(state.droppedFile.size)), ' ', "KB)"]
1264
- })]
1265
- }), jsxRuntime.jsx(uiKit.SecondaryButton, {
1266
- tone: "secondary",
1267
- size: "medium",
1268
- label: intl.formatMessage(sharedMessages.cancel),
1269
- onClick: () => {
1270
- actions.setCurrentStep('upload');
1271
- state.abortController.abort();
1272
- }
1273
- })]
1274
- }), jsxRuntime.jsx(uiKit.ProgressBar, {
1275
- barWidth: "scale",
1276
- height: "10",
1277
- progress: state.progress
1278
- }), jsxRuntime.jsx("div", {})]
1279
- })
1280
- });
1281
- return null;
1282
- };
1283
-
1284
- var messages$1 = reactIntl.defineMessages({
1285
- uploadNewFile: {
1286
- id: 'DeleteResourcesModal.uploadNewFile',
1287
- defaultMessage: 'Upload new file'
1288
- },
1289
- uploadErrorDescription: {
1290
- id: 'DeleteResourcesModal.uploadError',
1291
- description: 'Title when errors detected while uploading file',
1292
- defaultMessage: 'There {errorsCount, plural, one {is <b>1</b> error} other {are <b>{errorsCount}</b> errors}} detected while uploading the file "{fileName}".'
1293
- },
1294
- errorType: {
1295
- id: 'DeleteResourcesModal.errorType',
1296
- description: 'Error type" column',
1297
- defaultMessage: 'Error type'
1298
- },
1299
- details: {
1300
- id: 'DeleteResourcesModal.details',
1301
- description: '"Details" column',
1302
- defaultMessage: 'Details'
1303
- }
1304
- });
1305
-
1306
- function ownKeys$5(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; }
1307
- function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$5(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$5(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1308
- const getColumns = () => [{
1309
- key: 'errorType',
1310
- label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$5({}, messages$1.errorType)),
1311
- width: 'max-content'
1312
- }, {
1313
- key: 'details',
1314
- label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$5({}, messages$1.details))
1315
- }];
1316
- const UploadErrorTable = props => {
1317
- var _context;
1318
- const pagination = uiKit.usePaginationState({
1319
- perPage: 10
1320
- });
1321
- const startIndex = (pagination.page.value - 1) * pagination.perPage.value;
1322
- const endIndex = startIndex + pagination.perPage.value;
1323
- const currentPageRows = _sliceInstanceProperty__default["default"](_context = props.rows).call(_context, startIndex, endIndex);
1324
- const shouldShowPagination = props.rows.length > pagination.perPage.value;
1325
- return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1326
- scale: "l",
1327
- children: [jsxRuntime.jsx(uiKit.DataTable, {
1328
- verticalCellAlignment: "center",
1329
- isCondensed: true,
1330
- rows: currentPageRows,
1331
- columns: getColumns(),
1332
- itemRenderer: itemRenderer
1333
- }), shouldShowPagination && jsxRuntime.jsx(uiKit.PageNavigator, {
1334
- onPageChange: pagination.page.onChange,
1335
- page: pagination.page.value,
1336
- totalPages: Math.ceil(props.rows.length / pagination.perPage.value)
1337
- })]
1338
- });
1339
- };
1340
- function itemRenderer(item, column) {
1341
- switch (column.key) {
1342
- case 'errorType':
1343
- return jsxRuntime.jsx(uiKit.Stamp, {
1344
- isCondensed: true,
1345
- label: item.title,
1346
- tone: "critical"
1347
- });
1348
- case 'details':
1349
- return jsxRuntime.jsx(uiKit.Text.Body, {
1350
- children: item.description
1351
- });
1352
- default:
1353
- return null;
1354
- }
1355
- }
1356
-
1357
- function ownKeys$4(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; }
1358
- function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$4(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$4(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1359
- const UploadErrorsModal = () => {
1360
- const intl = reactIntl.useIntl();
1361
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
1362
- state = _useDeleteResourcesCo.state,
1363
- actions = _useDeleteResourcesCo.actions,
1364
- onClose = _useDeleteResourcesCo.onClose;
1365
- const errorsCount = state.fileUploadErrors.length;
1366
- return jsxRuntime.jsx(applicationComponents.InfoDialog, {
1367
- size: 16,
1368
- isOpen: true,
1369
- title: intl.formatMessage(sharedMessages.deleteModalTitle),
1370
- onClose: () => onClose(),
1371
- children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
1372
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1373
- scale: "l",
1374
- children: [jsxRuntime.jsx(fullstory.Masking.Mask, {
1375
- children: jsxRuntime.jsx(uiKit.Text.Body, {
1376
- intlMessage: _objectSpread$4(_objectSpread$4({}, messages$1.uploadErrorDescription), {}, {
1377
- values: {
1378
- fileName: state.droppedFile?.name,
1379
- errorsCount: intl.formatNumber(errorsCount),
1380
- b: getBold$2
1381
- }
1382
- })
1383
- })
1384
- }), jsxRuntime.jsx(UploadErrorTable, {
1385
- rows: mapFileUploadErrorsToUploadFileErrorRows(state.fileUploadErrors)
1386
- }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1387
- scale: "m",
1388
- justifyContent: "flex-end",
1389
- children: [jsxRuntime.jsx(uiKit.SecondaryButton, {
1390
- label: intl.formatMessage(sharedMessages.cancel),
1391
- onClick: () => onClose()
1392
- }), jsxRuntime.jsx(uiKit.PrimaryButton, {
1393
- iconLeft: jsxRuntime.jsx(uiKit.ImportIcon, {}),
1394
- label: intl.formatMessage(messages$1.uploadNewFile),
1395
- onClick: () => actions.uploadNewFile()
1396
- })]
1397
- })]
1398
- })
1399
- })
1400
- });
1401
- };
1402
- function getBold$2(msg) {
1403
- return jsxRuntime.jsx(uiKit.Text.Body, {
1404
- as: "span",
1405
- isBold: true,
1406
- children: msg
1407
- }, crypto.randomUUID());
1408
- }
1409
-
1410
- var messages = reactIntl.defineMessages({
1411
- continue: {
1412
- id: 'DeleteResourcesModal.continue',
1413
- description: 'Continue button',
1414
- defaultMessage: 'Continue'
1415
- },
1416
- heresAPreview: {
1417
- id: 'DeleteResourcesModal.heresAPreview',
1418
- description: 'Here is a preview',
1419
- defaultMessage: "Here's a preview:"
1420
- },
1421
- resourcesToBeDeleted: {
1422
- id: 'DeleteResourcesModal.resourcesToBeDeleted',
1423
- description: 'Resources to be deleted',
1424
- defaultMessage: '{count, plural, one {<b>{count}</b> {resourceType} to be deleted} other {<b>{count}</b> {resourceTypePlural} to be deleted}}'
1425
- },
1426
- confirmationQuestion: {
1427
- id: 'DeleteResourcesModal.confirmationQuestion',
1428
- description: 'Confirmation question',
1429
- defaultMessage: 'Are you sure you want to delete the {resourceTypePlural}? '
1430
- },
1431
- confirmationText: {
1432
- id: 'DeleteResourcesModal.confirmationText',
1433
- description: 'Confirmation text',
1434
- defaultMessage: '{count, plural, one {You are about to delete <b>{count}</b> {resourceType} in the project: <b>{projectName}</b>.} other {You are about to deleted <b>{count}</b> {resourceTypePlural} in the project: <b>{projectName}</b>.}}'
1435
- },
1436
- cannotBeUndoneNote: {
1437
- id: 'DeleteResourcesModal.cannotBeUndoneNote',
1438
- description: 'Cannot be undone note in the confirmation dialog',
1439
- defaultMessage: 'This action cannot be undone.'
1440
- },
1441
- importStarted: {
1442
- id: 'DeleteResourcesModal.importStarted',
1443
- description: 'Import started',
1444
- defaultMessage: '<b>Your import for bulk delete has started.</b><newline></newline>Go to <logsLink>Import logs</logsLink> to view the progress.'
1445
- },
1446
- preparingImport: {
1447
- id: 'DeleteResourcesModal.preparingImport',
1448
- description: 'Preparing import',
1449
- defaultMessage: '<b>Prepare bulk delete.</b><newline></newline>Once preparation is complete, you can track the progress <logsLink>in the Import logs</logsLink>. The data will be deleted after the import is finalized.'
1450
- }
1451
- });
1452
-
1453
- function ownKeys$3(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; }
1454
- function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$3(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$3(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1455
- const getNewLine = () => jsxRuntime.jsx("br", {}, "break");
1456
- const getImportLogsLink = (msg, projectKey) => jsxRuntime.jsx(uiKit.Link, {
1457
- to: `/${projectKey}/operations/import/logs`,
1458
- children: msg
1459
- }, "link");
1460
- var _ref2 = {
1461
- name: "1vs9i7r",
1462
- styles: "width:360px"
1463
- } ;
1464
- const ImportRunningTextNotification = props => jsxRuntime.jsx("div", {
1465
- css: _ref2,
1466
- children: jsxRuntime.jsx(uiKit.Text.Body, {
1467
- intlMessage: _objectSpread$3(_objectSpread$3({}, messages.importStarted), {}, {
1468
- values: {
1469
- newline: getNewLine,
1470
- logsLink: msg => getImportLogsLink(msg, props.projectKey),
1471
- b: getBold$1
1472
- }
1473
- })
1474
- })
1475
- });
1476
- var _ref = {
1477
- name: "1vs9i7r",
1478
- styles: "width:360px"
1479
- } ;
1480
- const ImportPreparingTextNotification = props => jsxRuntime.jsx("div", {
1481
- css: _ref,
1482
- children: jsxRuntime.jsx(uiKit.Text.Body, {
1483
- intlMessage: _objectSpread$3(_objectSpread$3({}, messages.preparingImport), {}, {
1484
- values: {
1485
- newline: getNewLine,
1486
- logsLink: msg => getImportLogsLink(msg, props.projectKey),
1487
- b: getBold$1
1488
- }
1489
- })
1490
- })
1491
- });
1492
- const DeleteResourcesConfirmationModal = () => {
1493
- const intl = reactIntl.useIntl();
1494
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
1495
- resourceType = _useDeleteResourcesCo.resourceType,
1496
- state = _useDeleteResourcesCo.state,
1497
- onClose = _useDeleteResourcesCo.onClose;
1498
- const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
1499
- projectKey: context.project?.key,
1500
- projectName: context.project?.name
1501
- })),
1502
- projectKey = _useApplicationContex.projectKey,
1503
- projectName = _useApplicationContex.projectName;
1504
- const asyncDispatch = sdk.useAsyncDispatch();
1505
- const showNotification = actionsGlobal.useShowNotification();
1506
- const onStartImport = async () => {
1507
- try {
1508
- const canConfirm = projectKey && state.containerKey && state.droppedFile?.name;
1509
- if (!canConfirm) return;
1510
- onClose();
1511
- showNotification({
1512
- kind: 'info',
1513
- domain: constants.DOMAINS.SIDE,
1514
- // @ts-ignore
1515
- text: jsxRuntime.jsx(ImportPreparingTextNotification, {
1516
- projectKey: projectKey
1517
- })
1518
- }, {
1519
- dismissAfter: 5000
1520
- });
1521
- await processUploadedFile({
1522
- projectKey,
1523
- containerKey: state.containerKey,
1524
- asyncDispatch,
1525
- resourceType
1526
- });
1527
- showNotification({
1528
- kind: 'info',
1529
- domain: constants.DOMAINS.SIDE,
1530
- // @ts-ignore
1531
- text: jsxRuntime.jsx(ImportRunningTextNotification, {
1532
- projectKey: projectKey
1533
- })
1534
- }, {
1535
- dismissAfter: 5000
1536
- });
1537
- } catch (error) {
1538
- onClose({
1539
- shouldDeleteImportContainer: true
1540
- });
1541
- showNotification({
1542
- kind: 'error',
1543
- domain: constants.DOMAINS.PAGE,
1544
- text: String(error)
1545
- });
1546
- }
1547
- };
1548
- return jsxRuntime.jsx(applicationComponents.InfoDialog, {
1549
- title: intl.formatMessage(sharedMessages.deleteModalTitle),
1550
- isOpen: true,
1551
- onClose: () => onClose({
1552
- shouldDeleteImportContainer: true
1553
- }),
1554
- size: 16,
1555
- children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
1556
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1557
- scale: "xl",
1558
- children: [jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1559
- scale: "m",
1560
- children: [jsxRuntime.jsxs("div", {
1561
- children: [jsxRuntime.jsx(uiKit.Text.Body, {
1562
- intlMessage: _objectSpread$3(_objectSpread$3({}, messages.confirmationText), {}, {
1563
- values: {
1564
- projectName: projectName,
1565
- resourceTypePlural: intl.formatMessage(resourceTypeToPluralMessage(resourceType)),
1566
- resourceType: intl.formatMessage(resourceTypeToMessage(resourceType)),
1567
- count: intl.formatNumber(state.uploadFileResponse?.rowsCount),
1568
- b: getBold$1
1569
- }
1570
- })
1571
- }), jsxRuntime.jsx(uiKit.Text.Body, {
1572
- intlMessage: _objectSpread$3(_objectSpread$3({}, messages.confirmationQuestion), {}, {
1573
- values: {
1574
- resourceTypePlural: intl.formatMessage(resourceTypeToPluralMessage(resourceType))
1575
- }
1576
- })
1577
- })]
1578
- }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1579
- scale: "s",
1580
- alignItems: "center",
1581
- children: [jsxRuntime.jsx(uiKit.WarningIcon, {
1582
- size: "40",
1583
- color: "warning"
1584
- }), jsxRuntime.jsx(uiKit.Text.Body, {
1585
- intlMessage: messages.cannotBeUndoneNote
1586
- })]
1587
- })]
1588
- }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1589
- scale: "m",
1590
- justifyContent: "flex-end",
1591
- children: [jsxRuntime.jsx(uiKit.SecondaryButton, {
1592
- "data-test-id": "confirmation-dialog-cancel",
1593
- label: intl.formatMessage(sharedMessages.cancel),
1594
- onClick: () => onClose({
1595
- shouldDeleteImportContainer: true
1596
- })
1597
- }), jsxRuntime.jsx(uiKit.PrimaryButton, {
1598
- tone: "critical",
1599
- "data-test-id": "confirmation-dialog-confirm",
1600
- label: intl.formatMessage(sharedMessages.startBulkDelete),
1601
- onClick: onStartImport
1602
- })]
1603
- })]
1604
- })
1605
- })
1606
- });
1607
- };
1608
- function getBold$1(msg) {
1609
- return jsxRuntime.jsx(uiKit.Text.Body, {
1610
- as: "span",
1611
- isBold: true,
1612
- children: msg
1613
- }, crypto.randomUUID());
1614
- }
1615
-
1616
- function ownKeys$2(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; }
1617
- function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$2(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1618
- function UploadPreviewModal() {
1619
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
1620
- resourceType = _useDeleteResourcesCo.resourceType,
1621
- state = _useDeleteResourcesCo.state,
1622
- onClose = _useDeleteResourcesCo.onClose,
1623
- actions = _useDeleteResourcesCo.actions;
1624
- const intl = reactIntl.useIntl();
1625
- return jsxRuntime.jsx(applicationComponents.FormDialog, {
1626
- size: 16,
1627
- isOpen: true,
1628
- title: intl.formatMessage(sharedMessages.deleteModalTitle),
1629
- labelPrimary: intl.formatMessage(messages.continue),
1630
- onSecondaryButtonClick: () => onClose({
1631
- shouldDeleteImportContainer: true
1632
- }),
1633
- onPrimaryButtonClick: () => {
1634
- actions.setCurrentStep('delete-confirmation');
1635
- },
1636
- onClose: () => onClose({
1637
- shouldDeleteImportContainer: true
1638
- }),
1639
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1640
- scale: "m",
1641
- children: [jsxRuntime.jsx(uiKit.Text.Body, {
1642
- intlMessage: messages.heresAPreview
1643
- }), jsxRuntime.jsx(uiKit.Card, {
1644
- insetScale: "xl",
1645
- children: jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1646
- scale: "m",
1647
- alignItems: "center",
1648
- children: [jsxRuntime.jsx(uiKit.BinLinearIcon, {
1649
- size: "40",
1650
- color: "neutral60"
1651
- }), jsxRuntime.jsx(uiKit.Text.Body, {
1652
- intlMessage: _objectSpread$2(_objectSpread$2({}, messages.resourcesToBeDeleted), {}, {
1653
- values: {
1654
- resourceType: intl.formatMessage(resourceTypeToMessage(resourceType)),
1655
- resourceTypePlural: intl.formatMessage(resourceTypeToPluralMessage(resourceType)),
1656
- count: intl.formatNumber(state.uploadFileResponse?.rowsCount),
1657
- b: getBold
1658
- }
1659
- })
1660
- })]
1661
- })
1662
- })]
1663
- })
1664
- });
1665
- }
1666
- function getBold(msg) {
1667
- return jsxRuntime.jsx(uiKit.Text.Body, {
1668
- as: "span",
1669
- isBold: true,
1670
- children: msg
1671
- }, `bold-${msg}`);
1672
- }
1673
-
1674
- const steps = {
1675
- upload: jsxRuntime.jsx(Upload, {}),
1676
- uploading: jsxRuntime.jsx(Uploading, {}),
1677
- 'upload-preview': jsxRuntime.jsx(UploadPreviewModal, {}),
1678
- 'upload-error': jsxRuntime.jsx(UploadErrorsModal, {}),
1679
- 'delete-confirmation': jsxRuntime.jsx(DeleteResourcesConfirmationModal, {})
1680
- };
1681
- const CurrentStep = () => {
1682
- const _useDeleteResourcesCo = useDeleteResourcesContext(),
1683
- state = _useDeleteResourcesCo.state;
1684
- return steps[state.currentStep] || null;
1685
- };
1686
-
1687
- function ownKeys$1(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; }
1688
- function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1689
- const FileIcon = props => jsxRuntime.jsxs("svg", _objectSpread$1(_objectSpread$1({
1690
- width: "32",
1691
- height: "32",
1692
- viewBox: "0 0 32 32",
1693
- fill: "none",
1694
- xmlns: "http://www.w3.org/2000/svg"
1695
- }, props), {}, {
1696
- children: [jsxRuntime.jsx("mask", {
1697
- id: "mask0_17_6643",
1698
- style: {
1699
- maskType: 'alpha'
1700
- },
1701
- maskUnits: "userSpaceOnUse",
1702
- x: "0",
1703
- y: "0",
1704
- width: "32",
1705
- height: "32",
1706
- children: jsxRuntime.jsx("rect", {
1707
- width: "32",
1708
- height: "32",
1709
- fill: "#D9D9D9"
1710
- })
1711
- }), jsxRuntime.jsx("g", {
1712
- mask: "url(#mask0_17_6643)",
1713
- children: jsxRuntime.jsx("path", {
1714
- d: "M14.6667 25.3333H17.3333V19.7667L19.4667 21.9L21.3333 20L16 14.6667L10.6667 20L12.5667 21.8667L14.6667 19.7667V25.3333ZM8 29.3333C7.26667 29.3333 6.63889 29.0722 6.11667 28.55C5.59444 28.0278 5.33333 27.4 5.33333 26.6667V5.33332C5.33333 4.59999 5.59444 3.97221 6.11667 3.44999C6.63889 2.92777 7.26667 2.66666 8 2.66666H18.6667L26.6667 10.6667V26.6667C26.6667 27.4 26.4056 28.0278 25.8833 28.55C25.3611 29.0722 24.7333 29.3333 24 29.3333H8ZM17.3333 12H24L17.3333 5.33332V12Z",
1715
- fill: "#B1ACFF"
1716
- })
1717
- })]
1718
- }));
1719
-
1720
- const getChunkImport = locale => {
1721
- const intlLocale = i18n.mapLocaleToIntlLocale(locale);
1722
- switch (intlLocale) {
1723
- case 'de':
1724
- return Promise.resolve().then(function () { return require('./de-9dc6c41a.cjs.prod.js'); });
1725
- case 'es':
1726
- return Promise.resolve().then(function () { return require('./es-64fd0c08.cjs.prod.js'); });
1727
- case 'fr-FR':
1728
- return Promise.resolve().then(function () { return require('./fr-FR-90c7194f.cjs.prod.js'); });
1729
- case 'ja':
1730
- return Promise.resolve().then(function () { return require('./ja-37632763.cjs.prod.js'); });
1731
- case 'pt-BR':
1732
- return Promise.resolve().then(function () { return require('./pt-BR-2da91387.cjs.prod.js'); });
1733
- default:
1734
- return Promise.resolve().then(function () { return require('./en-a983f180.cjs.prod.js'); });
1735
- }
1736
- };
1737
- const loadMessages = async locale => {
1738
- try {
1739
- const chunkImport = await getChunkImport(locale);
1740
- return i18n.parseChunkImport(chunkImport);
1741
- } catch (error) {
1742
- // eslint-disable-next-line no-console
1743
- console.warn(`Something went wrong while loading the delete-resources-modal messages for ${locale}`, error);
1744
- sentry.reportErrorToSentry(new Error(`Something went wrong while loading the delete-resources-modal messages for ${locale}`), {
1745
- extra: error
1746
- });
1747
- return {};
1748
- }
1749
- };
1750
-
1751
- const useAsyncIntlMessages = (locale, loader) => {
1752
- const _useState = React.useState({
1753
- isLoading: true,
1754
- messages: undefined,
1755
- error: undefined
1756
- }),
1757
- _useState2 = _slicedToArray(_useState, 2),
1758
- state = _useState2[0],
1759
- setState = _useState2[1];
1760
- React.useEffect(() => {
1761
- let _isUnmounting = false;
1762
- async function load() {
1763
- try {
1764
- if (!_isUnmounting) {
1765
- const messages = await loader(locale);
1766
- setState({
1767
- isLoading: false,
1768
- messages
1769
- });
1770
- }
1771
- } catch (error) {
1772
- setState({
1773
- isLoading: false,
1774
- error
1775
- });
1776
- }
1777
- }
1778
- if (locale) load();
1779
- return () => {
1780
- _isUnmounting = true;
1781
- };
1782
- }, [locale, loader]);
1783
- return state;
1784
- };
1785
-
1786
- function ownKeys(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; }
1787
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1788
- const DeleteResourcesModal = props => {
1789
- const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
1790
- locale: context.user && context.user.locale
1791
- })),
1792
- locale = _useApplicationContex.locale;
1793
- const messages = useAsyncIntlMessages(locale, loadMessages);
1794
- if (!props.isOpen || messages.isLoading) return null;
1795
- return jsxRuntime.jsx(reactIntl.IntlProvider, {
1796
- locale: locale,
1797
- messages: messages.messages,
1798
- children: jsxRuntime.jsx(DeleteResourcesProvider, _objectSpread(_objectSpread({}, props), {}, {
1799
- children: jsxRuntime.jsx(CurrentStep, {})
1800
- }))
1801
- });
1802
- };
1803
- DeleteResourcesModal.displayName = 'DeleteResourcesModal';
1804
-
1805
- exports.DeleteResourcesModal = DeleteResourcesModal;
1806
- exports.EnabledDropArea = EnabledDropArea;
1807
- exports.FileDropped = FileDropped;
1808
- exports.FileIcon = FileIcon;
1809
- exports.messages = messages$4;
1810
- exports.useDeleteResourcesContext = useDeleteResourcesContext;