@commercetools-frontend-extensions/import-resources-modal 1.11.2 → 1.11.4

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.
Files changed (26) hide show
  1. package/dist/commercetools-frontend-extensions-import-resources-modal.cjs.dev.js +2086 -53
  2. package/dist/commercetools-frontend-extensions-import-resources-modal.cjs.prod.js +2062 -53
  3. package/dist/commercetools-frontend-extensions-import-resources-modal.esm.js +2071 -51
  4. package/dist/declarations/src/@types/index.d.ts +0 -6
  5. package/package.json +2 -2
  6. package/dist/active-drag-drop-area-3ad5dd22.esm.js +0 -60
  7. package/dist/active-drag-drop-area-94cea372.cjs.prod.js +0 -62
  8. package/dist/active-drag-drop-area-edf9d7a9.cjs.dev.js +0 -62
  9. package/dist/declarations/src/@types/api.d.ts +0 -13
  10. package/dist/declarations/src/@types/file-upload.d.ts +0 -60
  11. package/dist/declarations/src/@types/import-container.d.ts +0 -36
  12. package/dist/declarations/src/@types/import-states.d.ts +0 -9
  13. package/dist/declarations/src/@types/import-summary.d.ts +0 -12
  14. package/dist/declarations/src/@types/shared.d.ts +0 -7
  15. package/dist/disabled-drop-area-6af7f861.cjs.dev.js +0 -105
  16. package/dist/disabled-drop-area-d068b119.esm.js +0 -92
  17. package/dist/disabled-drop-area-d8a66b62.cjs.prod.js +0 -105
  18. package/dist/enabled-drop-area-819e5dd2.cjs.dev.js +0 -79
  19. package/dist/enabled-drop-area-b6fe0252.cjs.prod.js +0 -79
  20. package/dist/enabled-drop-area-d5d394ff.esm.js +0 -77
  21. package/dist/file-dropped-area-0e55c4a0.cjs.prod.js +0 -82
  22. package/dist/file-dropped-area-b64c266f.esm.js +0 -80
  23. package/dist/file-dropped-area-d4d52da4.cjs.dev.js +0 -82
  24. package/dist/index-c0e77d3f.cjs.dev.js +0 -2733
  25. package/dist/index-f14adfdc.esm.js +0 -2699
  26. package/dist/index-f96fadf7.cjs.prod.js +0 -2701
@@ -1,2701 +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 _everyInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/every');
13
- var reactIntl = require('react-intl');
14
- var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
15
- var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
16
- var React = require('react');
17
- var sdk = require('@commercetools-frontend/sdk');
18
- var constants = require('@commercetools-frontend/constants');
19
- var applicationShell = require('@commercetools-frontend/application-shell');
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 pluralize = require('pluralize');
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 _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
31
- var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
32
- var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
33
- var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
34
- var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
35
- var Papa = require('papaparse');
36
- var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
37
- var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
38
- var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
39
- require('@babel/runtime-corejs3/core-js-stable/instance/bind');
40
- require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
41
- require('@babel/runtime-corejs3/core-js-stable/url-search-params');
42
- require('@babel/runtime-corejs3/core-js-stable/object/entries');
43
- var jsxRuntime = require('@emotion/react/jsx-runtime');
44
- var applicationComponents = require('@commercetools-frontend/application-components');
45
- var fullstory = require('@commercetools-frontend/fullstory');
46
- var uiKit = require('@commercetools-frontend/ui-kit');
47
- var reactDropzone = require('react-dropzone');
48
- var actionsGlobal = require('@commercetools-frontend/actions-global');
49
- var _styled = require('@emotion/styled/base');
50
- var react = require('@emotion/react');
51
- var sentry = require('@commercetools-frontend/sentry');
52
- var permissions = require('@commercetools-frontend/permissions');
53
- var i18n = require('@commercetools-frontend/i18n');
54
-
55
- function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
56
-
57
- var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
58
- var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
59
- var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
60
- var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
61
- var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
62
- var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
63
- var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
64
- var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
65
- var _everyInstanceProperty__default = /*#__PURE__*/_interopDefault(_everyInstanceProperty);
66
- var React__default = /*#__PURE__*/_interopDefault(React);
67
- var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
68
- var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
69
- var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
70
- var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
71
- var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
72
- var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
73
- var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
74
- var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
75
- var Papa__default = /*#__PURE__*/_interopDefault(Papa);
76
- var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
77
- var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
78
- var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
79
- var _styled__default = /*#__PURE__*/_interopDefault(_styled);
80
-
81
- const EnabledResourceType = {
82
- category: true,
83
- product: true,
84
- inventory: true,
85
- 'discount-code': true,
86
- customer: false,
87
- order: false,
88
- 'product-type': false,
89
- 'business-unit': true
90
- };
91
- function isResourceType(maybeResourceType) {
92
- return typeof maybeResourceType === 'string' && maybeResourceType in EnabledResourceType;
93
- }
94
- function assertResourceType(maybeResourceType) {
95
- if (isResourceType(maybeResourceType)) return;
96
- throw new Error(`Invalid value: ${maybeResourceType}`);
97
- }
98
- function isError(maybeError) {
99
- if (maybeError instanceof Error) return true;
100
- return false;
101
- }
102
-
103
- // eslint-disable-next-line @typescript-eslint/ban-types
104
- function hasOwnProperty(obj, prop) {
105
- return typeof obj === 'object' && obj !== null && obj.hasOwnProperty(prop);
106
- }
107
- function hasRequiredFields(maybeValidObject, requiredFields) {
108
- return typeof maybeValidObject === 'object' && maybeValidObject !== null && _everyInstanceProperty__default["default"](requiredFields).call(requiredFields, property => hasOwnProperty(maybeValidObject, property));
109
- }
110
-
111
- let CurrentStep$1 = /*#__PURE__*/function (CurrentStep) {
112
- CurrentStep["Upload"] = "upload";
113
- CurrentStep["Uploading"] = "uploading";
114
- CurrentStep["UploadResult"] = "upload-result";
115
- CurrentStep["ImportConfirmationModal"] = "import-confirmation-modal";
116
- return CurrentStep;
117
- }({});
118
-
119
- function ownKeys$k(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; }
120
- function _objectSpread$k(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$k(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$k(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
121
-
122
- // TODO: make this resource type specific
123
-
124
- function reducer(state, action) {
125
- if (action.type === 'setCurrentStep') return _objectSpread$k(_objectSpread$k({}, state), {}, {
126
- currentStep: action.currentStep,
127
- progress: 0
128
- });
129
- if (action.type === 'setUploadFileResponse') return _objectSpread$k(_objectSpread$k({}, state), {}, {
130
- uploadFileResponse: action.uploadFileResponse
131
- });
132
- if (action.type === 'setResourceType') return _objectSpread$k(_objectSpread$k({}, state), {}, {
133
- resourceType: action.resourceType
134
- });
135
- if (action.type === 'setContainerKey') return _objectSpread$k(_objectSpread$k({}, state), {}, {
136
- containerKey: action.containerKey
137
- });
138
- if (action.type === 'cancelImport') return _objectSpread$k(_objectSpread$k({}, state), {}, {
139
- currentStep: CurrentStep$1.Upload,
140
- containerKey: undefined,
141
- fileUploadErrors: [],
142
- uploadFileResponse: undefined,
143
- droppedFile: undefined,
144
- dropAreaState: 'disabled',
145
- progress: 0
146
- });
147
- if (action.type === 'uploadNewFile') return _objectSpread$k(_objectSpread$k({}, state), {}, {
148
- currentStep: CurrentStep$1.Upload,
149
- containerKey: undefined,
150
- fileUploadErrors: [],
151
- uploadFileResponse: undefined,
152
- droppedFile: undefined,
153
- dropAreaState: 'ready-for-drop',
154
- progress: 0
155
- });
156
- if (action.type === 'setDroppedFile') {
157
- return _objectSpread$k(_objectSpread$k({}, state), {}, {
158
- droppedFile: action.droppedFile
159
- });
160
- }
161
- if (action.type === 'setFileUploadErrors') {
162
- return _objectSpread$k(_objectSpread$k({}, state), {}, {
163
- fileUploadErrors: action.fileUploadErrors
164
- });
165
- }
166
- if (action.type === 'setAbortController') {
167
- return _objectSpread$k(_objectSpread$k({}, state), {}, {
168
- abortController: action.abortController
169
- });
170
- }
171
- if (action.type === 'setProgress') {
172
- return _objectSpread$k(_objectSpread$k({}, state), {}, {
173
- progress: action.progress
174
- });
175
- }
176
- if (action.type === 'setUploadSettings') {
177
- return _objectSpread$k(_objectSpread$k({}, state), {}, {
178
- settings: _objectSpread$k(_objectSpread$k({}, state.settings), action.settings)
179
- });
180
- }
181
- throw new Error(getUnknownActionError(action));
182
- }
183
- function getUnknownActionError(actionType) {
184
- return `Unkown type: ${actionType}`;
185
- }
186
- const initialState = {
187
- currentStep: CurrentStep$1.Upload,
188
- abortController: new AbortController(),
189
- dropAreaState: 'disabled',
190
- uploadFileResponse: undefined,
191
- fileUploadErrors: [],
192
- resourceType: 'category',
193
- containerKey: undefined,
194
- progress: 0,
195
- settings: {
196
- decimalSeparator: '.'
197
- }
198
- };
199
-
200
- 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)); }
201
- function _isNativeReflectConstruct$2() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$2 = function () { return !!t; })(); }
202
- let MissingImportResourceProviderError = /*#__PURE__*/function (_Error) {
203
- function MissingImportResourceProviderError() {
204
- var _this;
205
- _classCallCheck(this, MissingImportResourceProviderError);
206
- _this = _callSuper$2(this, MissingImportResourceProviderError, ['useImportResourcesContext must be used within ImportResourcesProvider']);
207
- _this.name = 'MissingImportResourceProviderError';
208
- return _this;
209
- }
210
- _inherits(MissingImportResourceProviderError, _Error);
211
- return _createClass(MissingImportResourceProviderError);
212
- }(/*#__PURE__*/_wrapNativeSuper(Error));
213
-
214
- 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)); }
215
- function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function () { return !!t; })(); }
216
- let UnexpectedColumnError = /*#__PURE__*/function (_Error) {
217
- function UnexpectedColumnError(columnName) {
218
- var _this;
219
- _classCallCheck(this, UnexpectedColumnError);
220
- _this = _callSuper$1(this, UnexpectedColumnError, [`Unexpected column "${columnName}"`]);
221
- _this.name = 'UnexpectedColumnError';
222
- return _this;
223
- }
224
- _inherits(UnexpectedColumnError, _Error);
225
- return _createClass(UnexpectedColumnError);
226
- }(/*#__PURE__*/_wrapNativeSuper(Error));
227
-
228
- 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)); }
229
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
230
- let HttpError = /*#__PURE__*/function (_Error) {
231
- function HttpError(statusCode, statusText, errorData) {
232
- var _this;
233
- _classCallCheck(this, HttpError);
234
- _this = _callSuper(this, HttpError, [`HTTP Error! Status code: ${statusCode}, message: "${statusText ? statusText : ''}"`]);
235
- _this.statusCode = void 0;
236
- _this.errorData = void 0;
237
- _this.name = 'HttpError';
238
- _this.statusCode = statusCode;
239
- _this.errorData = errorData;
240
- return _this;
241
- }
242
- _inherits(HttpError, _Error);
243
- return _createClass(HttpError);
244
- }(/*#__PURE__*/_wrapNativeSuper(Error));
245
-
246
- function ownKeys$j(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; }
247
- function _objectSpread$j(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$j(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$j(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
248
- const addProxyPrefixToUrl = (uri, proxy) => {
249
- return proxy ? `/proxy/${proxy}${uri}` : uri;
250
- };
251
- const fetchUsingXhr = _ref2 => {
252
- let url = _ref2.url,
253
- payload = _ref2.payload,
254
- config = _ref2.config,
255
- onProgress = _ref2.onProgress,
256
- onSuccess = _ref2.onSuccess,
257
- onError = _ref2.onError;
258
- const options = applicationShell.createHttpClientOptions({
259
- headers: _objectSpread$j({
260
- 'Content-Type': 'application/json'
261
- }, config?.headers)
262
- });
263
- const xhr = new XMLHttpRequest();
264
- xhr.open(config?.method, applicationShell.buildApiUrl(addProxyPrefixToUrl(url, config?.proxy)), true);
265
- // Include cookies in the request
266
- xhr.withCredentials = true;
267
- if (options.headers) {
268
- var _context;
269
- _forEachInstanceProperty__default["default"](_context = _Object$keys__default["default"](options.headers)).call(_context, key => {
270
- xhr.setRequestHeader(key, options.headers[key]);
271
- });
272
- }
273
- xhr.upload.onprogress = function (event) {
274
- if (event.lengthComputable) {
275
- const percentComplete = event.loaded / event.total * 100;
276
- onProgress(percentComplete);
277
- }
278
- };
279
- xhr.onload = function () {
280
- const data = JSON.parse(xhr.responseText);
281
- // Code copied from `executeHttpClientRequest` to replicate the same behavior
282
- const refreshedSessionToken = xhr.getResponseHeader('x-refreshed-session-token');
283
- if (refreshedSessionToken) {
284
- applicationShellConnectors.oidcStorage.setActiveSession(refreshedSessionToken);
285
- }
286
- if (xhr.status >= 200 && xhr.status < 300) {
287
- onSuccess(data);
288
- } else {
289
- onError(new HttpError(xhr.status, xhr.statusText, data));
290
- }
291
- };
292
- xhr.onerror = function () {
293
- const errorData = JSON.parse(xhr.responseText);
294
- onError(new HttpError(xhr.status, xhr.statusText, errorData));
295
- };
296
- xhr.onabort = function () {
297
- onError(new DOMException('Aborted', 'AbortError'));
298
- };
299
- xhr.send(payload);
300
- return xhr;
301
- };
302
-
303
- const DELIMITERS = {
304
- COMMA: ',',
305
- SEMICOLON: ';',
306
- POINT: '.',
307
- TAB: '\t',
308
- PIPE: '|'
309
- };
310
- const COLUMN_DELIMITERS = [DELIMITERS.COMMA, DELIMITERS.SEMICOLON, DELIMITERS.PIPE, DELIMITERS.TAB];
311
- const INITIAL_COLUMN_DISPLAY_COUNT = 8;
312
- const IMPORT_TAG_KEYS = {
313
- source: 'source'
314
- };
315
- const IMPORT_TAG_VALUES = {
316
- fileUpload: 'file-upload'
317
- };
318
- const TAG_KEY_SOURCE_FILE_UPLOAD = `${IMPORT_TAG_KEYS.source}:${IMPORT_TAG_VALUES.fileUpload}`;
319
-
320
- const IMPORTABLE_RESOURCES = {
321
- CATEGORY: 'category',
322
- PRODUCT: 'product',
323
- INVENTORY: 'inventory',
324
- DISCOUNT_CODE: 'discount-code',
325
- CUSTOMER: 'customer',
326
- ORDER: 'order',
327
- PRODUCT_TYPE: 'product-type',
328
- BUSINESS_UNIT: 'business-unit'
329
- };
330
-
331
- const FILE_SIZE_LIMITS_MB = {
332
- [IMPORTABLE_RESOURCES.CATEGORY]: 35,
333
- [IMPORTABLE_RESOURCES.INVENTORY]: 35,
334
- [IMPORTABLE_RESOURCES.PRODUCT]: 35,
335
- [IMPORTABLE_RESOURCES.DISCOUNT_CODE]: 35,
336
- [IMPORTABLE_RESOURCES.CUSTOMER]: 0,
337
- [IMPORTABLE_RESOURCES.ORDER]: 0,
338
- [IMPORTABLE_RESOURCES.PRODUCT_TYPE]: 35,
339
- [IMPORTABLE_RESOURCES.BUSINESS_UNIT]: 35
340
- };
341
- const ROW_LIMITS = {
342
- [IMPORTABLE_RESOURCES.CATEGORY]: 80_000,
343
- [IMPORTABLE_RESOURCES.INVENTORY]: 80_000,
344
- [IMPORTABLE_RESOURCES.PRODUCT]: 80_000,
345
- [IMPORTABLE_RESOURCES.DISCOUNT_CODE]: 80_000,
346
- [IMPORTABLE_RESOURCES.CUSTOMER]: 0,
347
- [IMPORTABLE_RESOURCES.ORDER]: 0,
348
- [IMPORTABLE_RESOURCES.PRODUCT_TYPE]: 80_000,
349
- [IMPORTABLE_RESOURCES.BUSINESS_UNIT]: 80_000
350
- };
351
- const RESOURCE_TYPE_TEMPLATE_DOWNLOAD_LINKS = {
352
- [IMPORTABLE_RESOURCES.CATEGORY]: 'https://docs.commercetools.com/merchant-center/downloads/category_import_template.csv',
353
- [IMPORTABLE_RESOURCES.PRODUCT]: 'https://docs.commercetools.com/merchant-center/import-data#download-a-template',
354
- [IMPORTABLE_RESOURCES.INVENTORY]: 'https://docs.commercetools.com/merchant-center/downloads/inventory_entry_import_template.csv',
355
- [IMPORTABLE_RESOURCES.DISCOUNT_CODE]: 'https://docs.commercetools.com/merchant-center/downloads/discount_code_import_template.csv',
356
- [IMPORTABLE_RESOURCES.CUSTOMER]: 'https://docs.commercetools.com/merchant-center/import-data#download-a-template',
357
- [IMPORTABLE_RESOURCES.ORDER]: 'https://docs.commercetools.com/merchant-center/import-data#download-a-template',
358
- [IMPORTABLE_RESOURCES.PRODUCT_TYPE]: 'https://docs.commercetools.com/merchant-center/downloads/product_type_import_template.csv',
359
- [IMPORTABLE_RESOURCES.BUSINESS_UNIT]: 'https://docs.commercetools.com/merchant-center/downloads/business_unit_import_template.csv'
360
- };
361
- const RESOURCE_TYPE_DOCUMENTATION_LINKS = {
362
- [IMPORTABLE_RESOURCES.CATEGORY]: 'https://docs.commercetools.com/merchant-center/import-categories#supported-headers-and-values',
363
- [IMPORTABLE_RESOURCES.PRODUCT]: 'https://docs.commercetools.com/merchant-center/import-products#supported-headers-and-values',
364
- [IMPORTABLE_RESOURCES.INVENTORY]: 'https://docs.commercetools.com/merchant-center/import-inventory#supported-headers-and-values',
365
- [IMPORTABLE_RESOURCES.DISCOUNT_CODE]: 'https://docs.commercetools.com/merchant-center/import-discount-codes#supported-headers-and-values',
366
- [IMPORTABLE_RESOURCES.CUSTOMER]: 'https://docs.commercetools.com/merchant-center/import-customers#supported-headers-and-values',
367
- [IMPORTABLE_RESOURCES.ORDER]: 'https://docs.commercetools.com/merchant-center/import-orders#supported-headers-and-values',
368
- [IMPORTABLE_RESOURCES.PRODUCT_TYPE]: 'https://docs.commercetools.com/merchant-center/import-product-types#supported-headers-and-values',
369
- [IMPORTABLE_RESOURCES.BUSINESS_UNIT]: 'https://docs.commercetools.com/merchant-center/import-business-units#supported-headers-and-values'
370
- };
371
-
372
- const CT_API_DOCS_URL = 'https://docs.commercetools.com/api/';
373
-
374
- const PERMISSIONS = {
375
- // Categories
376
- ManageCategories: 'ManageCategories',
377
- ViewCategories: 'ViewCategories',
378
- // Products
379
- ManageProducts: 'ManageProducts',
380
- ViewProducts: 'ViewProducts',
381
- // ProductTypes
382
- ManageProductTypes: 'ManageProductTypes',
383
- ViewProductTypes: 'ViewProductTypes',
384
- // DiscountCodes
385
- ManageDiscountCodes: 'ManageDiscountCodes',
386
- ViewDiscountCodes: 'ViewDiscountCodes',
387
- // Customers
388
- ManageCustomers: 'ManageCustomers',
389
- ViewCustomers: 'ViewCustomers',
390
- // Orders
391
- ManageOrders: 'ManageOrders',
392
- ViewOrders: 'ViewOrders',
393
- // KeyValueDocuments
394
- ManageKeyValueDocuments: 'ManageKeyValueDocuments',
395
- ViewKeyValueDocuments: 'ViewKeyValueDocuments',
396
- // BusinessUnits
397
- ManageBusinessUnits: 'ManageBusinessUnits',
398
- ViewBusinessUnits: 'ViewBusinessUnits'
399
- };
400
- const ACTION_RIGHTS = {
401
- PublishProducts: {
402
- group: 'products',
403
- name: 'PublishProducts'
404
- },
405
- UnpublishProducts: {
406
- group: 'products',
407
- name: 'UnpublishProducts'
408
- }
409
- };
410
-
411
- function ownKeys$i(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; }
412
- function _objectSpread$i(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$i(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$i(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
413
- const DEFAULT_SHORT_LIVED_FLAGS = {};
414
- const DEFAULT_LONG_LIVED_FLAGS = {};
415
- _objectSpread$i(_objectSpread$i({}, DEFAULT_SHORT_LIVED_FLAGS), DEFAULT_LONG_LIVED_FLAGS);
416
-
417
- var sharedMessages = reactIntl.defineMessages({
418
- [`modalTitle.${IMPORTABLE_RESOURCES.CATEGORY}`]: {
419
- id: 'ImportResourcesModal.modalTitle.category',
420
- description: 'Label for the categories modal title',
421
- defaultMessage: 'Import categories by CSV'
422
- },
423
- [`modalTitle.${IMPORTABLE_RESOURCES.PRODUCT}`]: {
424
- id: 'ImportResourcesModal.modalTitle.product',
425
- description: 'Label for the products modal title',
426
- defaultMessage: 'Import products by CSV'
427
- },
428
- [`modalTitle.${IMPORTABLE_RESOURCES.INVENTORY}`]: {
429
- id: 'ImportResourcesModal.modalTitle.inventoryEntry',
430
- description: 'Label for the inventories modal title',
431
- defaultMessage: 'Import inventories by CSV'
432
- },
433
- [`modalTitle.${IMPORTABLE_RESOURCES.DISCOUNT_CODE}`]: {
434
- id: 'ImportResourcesModal.modalTitle.discountCode',
435
- description: 'Label for the inventories modal title',
436
- defaultMessage: 'Import discount codes by CSV'
437
- },
438
- [`modalTitle.${IMPORTABLE_RESOURCES.BUSINESS_UNIT}`]: {
439
- id: 'ImportResourcesModal.modalTitle.businessUnit',
440
- description: 'Label for the business units modal title',
441
- defaultMessage: 'Import business units by CSV'
442
- },
443
- [`modalTitle.${IMPORTABLE_RESOURCES.CUSTOMER}`]: {
444
- id: 'ImportResourcesModal.modalTitle.customer',
445
- description: 'Label for the customers modal title',
446
- defaultMessage: 'Import customers by CSV'
447
- },
448
- [`modalTitle.${IMPORTABLE_RESOURCES.ORDER}`]: {
449
- id: 'ImportResourcesModal.modalTitle.order',
450
- description: 'Label for the order modal title',
451
- defaultMessage: 'Import orders by CSV'
452
- },
453
- [`modalTitle.${IMPORTABLE_RESOURCES.PRODUCT_TYPE}`]: {
454
- id: 'ImportResourcesModal.modalTitle.productType',
455
- description: 'Label for the product type modal title',
456
- defaultMessage: 'Import product types by CSV'
457
- },
458
- uploadButton: {
459
- id: 'ImportResourcesModal.uploadButton',
460
- description: 'Label for the upload button',
461
- defaultMessage: 'Upload and preview'
462
- },
463
- cancel: {
464
- id: 'ImportResourcesModal.cancel',
465
- description: 'Label for the cancel button',
466
- defaultMessage: 'Cancel'
467
- },
468
- close: {
469
- id: 'ImportResourcesModal.close',
470
- description: 'Label for the close button',
471
- defaultMessage: 'Close'
472
- },
473
- listConjunctionOr: {
474
- id: 'ImportResourcesModal.listConjunctionOr',
475
- description: 'Label for the list conjunction or',
476
- defaultMessage: 'or'
477
- },
478
- delimiterComma: {
479
- id: 'ImportResourcesModal.delimiterComma',
480
- description: 'Label for the delimiter name comma',
481
- defaultMessage: 'comma'
482
- },
483
- delimiterSemicolon: {
484
- id: 'ImportResourcesModal.delimiterSemicolon',
485
- description: 'Label for the delimiter name semicolon',
486
- defaultMessage: 'semicolon'
487
- },
488
- delimiterPipe: {
489
- id: 'ImportResourcesModal.delimiterPipe',
490
- description: 'Label for the delimiter name pipe',
491
- defaultMessage: 'pipe'
492
- },
493
- delimiterTab: {
494
- id: 'ImportResourcesModal.delimiterTab',
495
- description: 'Label for the delimiter name tab',
496
- defaultMessage: 'tab'
497
- },
498
- // Resource types
499
- product: {
500
- id: 'ImportResourcesModal.product',
501
- description: 'Label for the product resource type',
502
- defaultMessage: 'Product'
503
- },
504
- products: {
505
- id: 'ImportResourcesModal.products',
506
- description: 'Label for the products resource type',
507
- defaultMessage: 'Products'
508
- },
509
- inventory: {
510
- id: 'ImportResourcesModal.inventory',
511
- description: 'Label for the inventory entry resource type',
512
- defaultMessage: 'Inventory'
513
- },
514
- inventories: {
515
- id: 'ImportResourcesModal.inventories',
516
- description: 'Label for the inventories entry resource type',
517
- defaultMessage: 'Inventories'
518
- },
519
- category: {
520
- id: 'ImportResourcesModal.category',
521
- description: 'Label for the category resource type',
522
- defaultMessage: 'Category'
523
- },
524
- categories: {
525
- id: 'ImportResourcesModal.categories',
526
- description: 'Label for the categories resource type',
527
- defaultMessage: 'Categories'
528
- },
529
- 'custom-object': {
530
- id: 'ImportResourcesModal.custom-object',
531
- description: 'Label for the custom-object resource type',
532
- defaultMessage: 'Custom object'
533
- },
534
- 'custom-objects': {
535
- id: 'ImportResourcesModal.custom-objects',
536
- description: 'Label for the custom-objects resource type',
537
- defaultMessage: 'Custom objects'
538
- },
539
- customer: {
540
- id: 'ImportResourcesModal.customer',
541
- description: 'Label for the customer resource type',
542
- defaultMessage: 'Customer'
543
- },
544
- customers: {
545
- id: 'ImportResourcesModal.customers',
546
- description: 'Label for the customers resource type',
547
- defaultMessage: 'Customers'
548
- },
549
- order: {
550
- id: 'ImportResourcesModal.order',
551
- description: 'Label for the order resource type',
552
- defaultMessage: 'Order'
553
- },
554
- orders: {
555
- id: 'ImportResourcesModal.orders',
556
- description: 'Label for the orders resource type',
557
- defaultMessage: 'Orders'
558
- },
559
- 'order-patch': {
560
- id: 'ImportResourcesModal.order-patch',
561
- description: 'Label for the order-patch resource type',
562
- defaultMessage: 'Order patch'
563
- },
564
- 'order-patches': {
565
- id: 'ImportResourcesModal.order-patches',
566
- description: 'Label for the order-patches resource type',
567
- defaultMessage: 'Order patches'
568
- },
569
- price: {
570
- id: 'ImportResourcesModal.price',
571
- description: 'Label for the price resource type',
572
- defaultMessage: 'Price'
573
- },
574
- prices: {
575
- id: 'ImportResourcesModal.prices',
576
- description: 'Label for the prices resource type',
577
- defaultMessage: 'Prices'
578
- },
579
- 'product-draft': {
580
- id: 'ImportResourcesModal.product-draft',
581
- description: 'Label for the product-draft resource type',
582
- defaultMessage: 'Product draft'
583
- },
584
- 'product-drafts': {
585
- id: 'ImportResourcesModal.product-drafts',
586
- description: 'Label for the product-drafts resource type',
587
- defaultMessage: 'Product drafts'
588
- },
589
- 'product-type': {
590
- id: 'ImportResourcesModal.product-type',
591
- description: 'Label for the product-type resource type',
592
- defaultMessage: 'Product type'
593
- },
594
- 'product-types': {
595
- id: 'ImportResourcesModal.product-types',
596
- description: 'Label for the product-types resource type',
597
- defaultMessage: 'Product types'
598
- },
599
- 'product-variant': {
600
- id: 'ImportResourcesModal.product-variant',
601
- description: 'Label for the product-variant resource type',
602
- defaultMessage: 'Product variant'
603
- },
604
- 'product-variants': {
605
- id: 'ImportResourcesModal.product-variants',
606
- description: 'Label for the product-variants resource type',
607
- defaultMessage: 'Product variants'
608
- },
609
- 'product-variant-patch': {
610
- id: 'ImportResourcesModal.product-variant-patch',
611
- description: 'Label for the product-variant-patch resource type',
612
- defaultMessage: 'Product variant patch'
613
- },
614
- 'product-variant-patches': {
615
- id: 'ImportResourcesModal.product-variant-patches',
616
- description: 'Label for the product-variant-patches resource type',
617
- defaultMessage: 'Product variant patches'
618
- },
619
- 'standalone-price': {
620
- id: 'ImportResourcesModal.standalone-price',
621
- description: 'Label for the standalone-price resource type',
622
- defaultMessage: 'Standalone price'
623
- },
624
- 'standalone-prices': {
625
- id: 'ImportResourcesModal.standalone-prices',
626
- description: 'Label for the standalone-prices resource type',
627
- defaultMessage: 'Standalone prices'
628
- },
629
- type: {
630
- id: 'ImportResourcesModal.type',
631
- description: 'Label for the type resource type',
632
- defaultMessage: 'Type'
633
- },
634
- types: {
635
- id: 'ImportResourcesModal.types',
636
- description: 'Label for the types resource type',
637
- defaultMessage: 'Types'
638
- },
639
- 'discount-code': {
640
- id: 'ImportResourcesModal.discount-code',
641
- description: 'Label for the discount-code resource type',
642
- defaultMessage: 'Discount code'
643
- },
644
- 'discount-codes': {
645
- id: 'ImportResourcesModal.discount-codes',
646
- description: 'Label for the discount-codes resource type',
647
- defaultMessage: 'Discount codes'
648
- },
649
- 'business-unit': {
650
- id: 'ImportResourcesModal.business-unit',
651
- description: 'Label for the business-unit resource type',
652
- defaultMessage: 'Business unit'
653
- },
654
- 'business-units': {
655
- id: 'ImportResourcesModal.business-units',
656
- description: 'Label for the business-units resource type',
657
- defaultMessage: 'Business units'
658
- },
659
- unknownResourceType: {
660
- id: 'ImportResourcesModal.unknown-resource-type',
661
- description: 'Label for the unknown resource type',
662
- defaultMessage: 'Unknown resource type'
663
- }
664
- //
665
- });
666
-
667
- function ownKeys$h(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; }
668
- function _objectSpread$h(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$h(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$h(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
669
-
670
- // Delimiters not included in this array may be treated as part of a column content
671
- // potentially causing the file to be parsed as a single-column CSV and pass this validation
672
- const NON_ALLOWED_COLUMN_DELIMITERS = ['%', '.', ' '];
673
- const DELIMITERS_TO_GUESS = [...COLUMN_DELIMITERS, ...NON_ALLOWED_COLUMN_DELIMITERS];
674
- const validateDelimiter = file => {
675
- return new _Promise__default["default"](resolve => {
676
- Papa__default["default"].parse(file, {
677
- delimitersToGuess: DELIMITERS_TO_GUESS,
678
- preview: 10,
679
- complete: result => {
680
- const headerRow = result.data?.[0];
681
- const isOnlyOneColumn = _Array$isArray__default["default"](headerRow) && headerRow.length === 1;
682
- if (isOnlyOneColumn) {
683
- resolve(true);
684
- return;
685
- }
686
- const detectedDelimiter = result.meta.delimiter;
687
- let isValid = false;
688
- if (detectedDelimiter !== null && _includesInstanceProperty__default["default"](COLUMN_DELIMITERS).call(COLUMN_DELIMITERS, detectedDelimiter)) {
689
- var _context;
690
- const isUndetectableDelimiter = _someInstanceProperty__default["default"](_context = result.errors).call(_context, error => error.code === 'UndetectableDelimiter');
691
- if (!isUndetectableDelimiter) {
692
- isValid = true;
693
- }
694
- }
695
- resolve(isValid);
696
- }
697
- });
698
- });
699
- };
700
- const mapUploadFileErrorsResponseToUploadFileErrorRows = uploadFileErrorsResponse => {
701
- if (!uploadFileErrorsResponse || !_Array$isArray__default["default"](uploadFileErrorsResponse)) return [];
702
- let idCounter = 1;
703
- return _flatMapInstanceProperty__default["default"](uploadFileErrorsResponse).call(uploadFileErrorsResponse, rowErrorsResponse => {
704
- var _context2;
705
- return _mapInstanceProperty__default["default"](_context2 = rowErrorsResponse.errors).call(_context2, rowError => ({
706
- // DataTable component requires unique `id` field
707
- id: String(idCounter++),
708
- row: rowErrorsResponse.row,
709
- field: rowError.field,
710
- code: rowError.code,
711
- validationMessage: rowError.message
712
- }));
713
- });
714
- };
715
- const mapFileUploadErrorsToUploadFileErrorRows = uploadFileErrors => {
716
- let idCounter = 1;
717
- return _mapInstanceProperty__default["default"](uploadFileErrors).call(uploadFileErrors, uploadFileError => _objectSpread$h(_objectSpread$h({}, uploadFileError), {}, {
718
- id: String(idCounter++)
719
- }));
720
- };
721
- const extractErrorDescriptionFromValidationMessage = message => {
722
- return message.split('"').pop();
723
- };
724
-
725
- /**
726
- * Returns the number of rows in a CSV file excluding the header
727
- * @param file The CSV file to process.
728
- * @returns A promise that resolves to the number of rows
729
- */
730
- const getRowCount = file => {
731
- return new _Promise__default["default"](resolve => {
732
- let lineCount = 0;
733
- Papa__default["default"].parse(file, {
734
- step: _ref => {
735
- let data = _ref.data;
736
- // empty lines at the end of the file should not be counted
737
- if (_Array$isArray__default["default"](data) && _findInstanceProperty__default["default"](data).call(data, Boolean)) lineCount++;
738
- },
739
- complete: () => {
740
- // Subtract 1 for the header row
741
- // We use Math.max to make sure the count is not less than 0, this is needed for empty files
742
- resolve(Math.max(0, lineCount - 1));
743
- }
744
- });
745
- });
746
- };
747
- const toBytes = megabytes => megabytes * 1024 * 1024;
748
-
749
- /**
750
- * Returns columns from the provided `columns` excluding those specified in the `ignoredColumns`
751
- */
752
- const getValidatedColumns = (columns, ignoredColumns) => {
753
- return _filterInstanceProperty__default["default"](columns).call(columns, column => !_includesInstanceProperty__default["default"](ignoredColumns).call(ignoredColumns, column));
754
- };
755
- const formatAllowedDelimitersForMessageDisplay = intl => {
756
- const localizedOr = intl.formatMessage(sharedMessages.listConjunctionOr);
757
- const descriptions = _mapInstanceProperty__default["default"](COLUMN_DELIMITERS).call(COLUMN_DELIMITERS, delimiter => {
758
- let nameDescriptor;
759
- switch (delimiter) {
760
- case ',':
761
- nameDescriptor = sharedMessages.delimiterComma;
762
- break;
763
- case ';':
764
- nameDescriptor = sharedMessages.delimiterSemicolon;
765
- break;
766
- case '|':
767
- nameDescriptor = sharedMessages.delimiterPipe;
768
- break;
769
- case '\t':
770
- nameDescriptor = sharedMessages.delimiterTab;
771
- break;
772
- default:
773
- nameDescriptor = undefined;
774
- }
775
- const name = nameDescriptor ? intl.formatMessage(nameDescriptor) : delimiter;
776
- return delimiter === '\t' ? name : `${name} (${delimiter})`;
777
- });
778
- if (descriptions.length === 1) {
779
- return descriptions[0];
780
- }
781
- const lastDescription = descriptions.pop();
782
- return `${descriptions.join(', ')} ${localizedOr} ${lastDescription}`;
783
- };
784
-
785
- function getFileUploadErrorsCount(errors) {
786
- if (!errors || !_Array$isArray__default["default"](errors)) return 0;
787
- return _reduceInstanceProperty__default["default"](errors).call(errors, (acc, curr) => acc += curr.errors.length, 0);
788
- }
789
- function convertFileSizeToKB(sizeInBytes) {
790
- return sizeInBytes / 1000;
791
- }
792
- function isAbortError(error) {
793
- return error instanceof DOMException && error.name === 'AbortError';
794
- }
795
- function formatKeys(obj) {
796
- var _context;
797
- if (typeof obj !== 'object' || obj === null) return '';
798
- const keys = _mapInstanceProperty__default["default"](_context = _Object$keys__default["default"](obj)).call(_context, key => key.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase());
799
- if (keys.length === 0) return '';
800
- if (keys.length === 1) return keys[0];
801
- return `${_sliceInstanceProperty__default["default"](keys).call(keys, 0, -1).join(', ')} and ${keys[keys.length - 1]}`;
802
- }
803
- function formatErrorCode(code) {
804
- try {
805
- const formattedCode = code.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/([A-Z])([A-Z][a-z])/g, '$1 $2').toLowerCase();
806
- let result = formattedCode.charAt(0).toUpperCase() + _sliceInstanceProperty__default["default"](formattedCode).call(formattedCode, 1);
807
- return result;
808
- } catch (error) {
809
- return code;
810
- }
811
- }
812
- function resourceTypeToMessage(resourceType) {
813
- const resourceTypeMap = {
814
- category: sharedMessages.category,
815
- product: sharedMessages.product,
816
- 'product-type': sharedMessages['product-type'],
817
- order: sharedMessages.order,
818
- customer: sharedMessages.customer,
819
- 'discount-code': sharedMessages['discount-code'],
820
- inventory: sharedMessages.inventory,
821
- // TODO: remove `inventory` after aligning the resource type names in the file upload API
822
- 'inventory-entry': sharedMessages.inventory,
823
- 'order-patch': sharedMessages['order-patch'],
824
- price: sharedMessages.price,
825
- 'product-draft': sharedMessages['product-draft'],
826
- 'product-variant': sharedMessages['product-variant'],
827
- 'product-variant-patch': sharedMessages['product-variant-patch'],
828
- 'standalone-price': sharedMessages['standalone-price'],
829
- 'custom-object': sharedMessages['custom-object'],
830
- 'business-unit': sharedMessages['business-unit'],
831
- type: sharedMessages.type
832
- };
833
- const message = resourceTypeMap[resourceType];
834
- if (!message) {
835
- return sharedMessages.unknownResourceType;
836
- }
837
- return message;
838
- }
839
- function resourceTypeToPluralMessage(resourceType) {
840
- const resourceTypePluralMap = {
841
- category: sharedMessages.categories,
842
- 'custom-object': sharedMessages['custom-objects'],
843
- product: sharedMessages.products,
844
- 'product-type': sharedMessages['product-types'],
845
- order: sharedMessages.orders,
846
- customer: sharedMessages.customers,
847
- 'discount-code': sharedMessages['discount-codes'],
848
- inventory: sharedMessages.inventories,
849
- // TODO: remove `inventory` after aligning the resource type names in the file upload API
850
- 'inventory-entry': sharedMessages.inventories,
851
- 'order-patch': sharedMessages['order-patches'],
852
- price: sharedMessages.prices,
853
- 'product-draft': sharedMessages['product-drafts'],
854
- 'product-variant': sharedMessages['product-variants'],
855
- 'product-variant-patch': sharedMessages['product-variant-patches'],
856
- 'standalone-price': sharedMessages['standalone-prices'],
857
- 'business-unit': sharedMessages['business-units']
858
- };
859
- const message = resourceTypePluralMap[resourceType];
860
- if (!message) {
861
- return sharedMessages.unknownResourceType;
862
- }
863
- return message;
864
- }
865
-
866
- const encodeFileNameWithTimestampToContainerKey = fileName => {
867
- return btoa(_JSON$stringify__default["default"]({
868
- timestamp: new Date().getTime(),
869
- fileName
870
- })).replace(/=+$/g, '');
871
- };
872
-
873
- function getCreateImportContainerURL(projectKey) {
874
- return `/${projectKey}/import-containers`;
875
- }
876
- function getDeleteImportContainerURL(projectKey, containerKey) {
877
- return `/${projectKey}/import-containers/${containerKey}`;
878
- }
879
- function getFileUploadURL(projectKey, resourceType, containerKey) {
880
- return `/${projectKey}/${pluralize.plural(resourceType)}/import-containers/${containerKey}/file-upload`;
881
- }
882
- function getProccessFileURL(projectKey, resourceType, containerKey) {
883
- return `/${projectKey}/${pluralize.plural(resourceType)}/import-containers/${containerKey}/process-file`;
884
- }
885
-
886
- function uploadFileForImport(_ref) {
887
- let projectKey = _ref.projectKey,
888
- containerKey = _ref.containerKey,
889
- resourceType = _ref.resourceType,
890
- file = _ref.file,
891
- abortSignal = _ref.abortSignal,
892
- onSuccess = _ref.onSuccess,
893
- onProgress = _ref.onProgress,
894
- onError = _ref.onError;
895
- const uri = getFileUploadURL(projectKey, resourceType, containerKey);
896
- const formData = new FormData();
897
- formData.append('file', file, file.name);
898
- return fetchUsingXhr({
899
- url: uri,
900
- payload: formData,
901
- config: {
902
- abortSignal,
903
- proxy: constants.MC_API_PROXY_TARGETS.IMPORT,
904
- method: 'POST',
905
- headers: {
906
- 'Content-Type': null
907
- }
908
- },
909
- onProgress,
910
- onSuccess,
911
- onError
912
- });
913
- }
914
-
915
- function ownKeys$g(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; }
916
- function _objectSpread$g(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$g(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$g(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
917
- function createImportContainerForFileUpload(importContainerDraft, projectKey, asyncDispatch) {
918
- return asyncDispatch(sdk.actions.post({
919
- mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.IMPORT,
920
- uri: getCreateImportContainerURL(projectKey),
921
- headers: {
922
- accept: 'application/json',
923
- 'Content-Type': 'application/json'
924
- },
925
- payload: _JSON$stringify__default["default"](_objectSpread$g({
926
- retentionPolicy: {
927
- strategy: 'ttl',
928
- config: {
929
- timeToLive: '54h' // 2 days and 6 hours
930
- }
931
- }
932
- }, importContainerDraft))
933
- }));
934
- }
935
- function deleteImportContainer(projectKey, containerKey, asyncDispatch) {
936
- return asyncDispatch(sdk.actions.del({
937
- mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.IMPORT,
938
- uri: getDeleteImportContainerURL(projectKey, containerKey),
939
- headers: {
940
- accept: 'application/json'
941
- }
942
- }));
943
- }
944
-
945
- async function processUploadedFile(_ref) {
946
- let projectKey = _ref.projectKey,
947
- containerKey = _ref.containerKey,
948
- resourceType = _ref.resourceType,
949
- asyncDispatch = _ref.asyncDispatch;
950
- const uri = getProccessFileURL(projectKey, resourceType, containerKey);
951
- const response = await asyncDispatch(sdk.actions.post({
952
- mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.IMPORT,
953
- uri: uri,
954
- headers: {
955
- accept: 'application/json',
956
- 'Content-Type': 'application/json'
957
- },
958
- payload: {}
959
- }));
960
- assertProcessFileResponse(response);
961
- return response;
962
- }
963
- function assertProcessFileResponse(maybeProcessFileResponse) {
964
- const requiredFields = ['message'];
965
- if (hasRequiredFields(maybeProcessFileResponse, requiredFields)) return;
966
- throw new Error('Invalid response');
967
- }
968
-
969
- function ownKeys$f(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
970
- function _objectSpread$f(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$f(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$f(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
971
- const ImportResourcesContext = /*#__PURE__*/React__default["default"].createContext();
972
- const ImportResourcesProvider = props => {
973
- const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
974
- projectKey: context.project?.key
975
- })),
976
- projectKey = _useApplicationContex.projectKey;
977
- const asyncDispatch = sdk.useAsyncDispatch();
978
- const _React$useReducer = React__default["default"].useReducer(reducer, _objectSpread$f(_objectSpread$f({}, initialState), {}, {
979
- resourceType: props.resourceTypes[0]
980
- })),
981
- _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
982
- state = _React$useReducer2[0],
983
- dispatch = _React$useReducer2[1];
984
- const setCurrentStep = currentStep => dispatch({
985
- type: 'setCurrentStep',
986
- currentStep
987
- });
988
- const setUploadFileResponse = uploadFileResponse => dispatch({
989
- type: 'setUploadFileResponse',
990
- uploadFileResponse: uploadFileResponse
991
- });
992
- const setResourceType = resourceType => dispatch({
993
- type: 'setResourceType',
994
- resourceType: resourceType
995
- });
996
- const setContainerKey = containerKey => dispatch({
997
- type: 'setContainerKey',
998
- containerKey
999
- });
1000
- const cancelImport = () => dispatch({
1001
- type: 'cancelImport'
1002
- });
1003
- const uploadNewFile = () => dispatch({
1004
- type: 'uploadNewFile'
1005
- });
1006
- const setDroppedFile = droppedFile => dispatch({
1007
- type: 'setDroppedFile',
1008
- droppedFile: droppedFile
1009
- });
1010
- const setAbortController = abortController => dispatch({
1011
- type: 'setAbortController',
1012
- abortController: abortController
1013
- });
1014
- const setFileUploadErrors = fileUploadErrors => dispatch({
1015
- type: 'setFileUploadErrors',
1016
- fileUploadErrors: fileUploadErrors
1017
- });
1018
- const setProgress = progress => dispatch({
1019
- type: 'setProgress',
1020
- progress
1021
- });
1022
- const setUploadSettings = nextSettings => {
1023
- dispatch({
1024
- type: 'setUploadSettings',
1025
- settings: nextSettings
1026
- });
1027
- };
1028
- const handleClose = function () {
1029
- let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1030
- shouldDeleteImportContainer = _ref.shouldDeleteImportContainer;
1031
- if (state.abortController) state.abortController.abort();
1032
- if (typeof props.onClose === 'function') props.onClose();
1033
- // Removes the associated import container when the import is closed
1034
- if (shouldDeleteImportContainer && projectKey && state.containerKey) deleteImportContainer(projectKey, state.containerKey, asyncDispatch);
1035
- };
1036
- const handleStartImportSuccess = () => {
1037
- if (typeof props.onStartImportSuccess === 'function') props.onStartImportSuccess();
1038
- };
1039
- return jsxRuntime.jsx(ImportResourcesContext.Provider, {
1040
- value: {
1041
- state,
1042
- resourceTypes: props.resourceTypes,
1043
- onClose: handleClose,
1044
- onStartImportSuccess: handleStartImportSuccess,
1045
- actions: {
1046
- setCurrentStep,
1047
- cancelImport,
1048
- uploadNewFile,
1049
- setUploadFileResponse,
1050
- setResourceType,
1051
- setDroppedFile,
1052
- setContainerKey,
1053
- setAbortController,
1054
- setFileUploadErrors,
1055
- setProgress,
1056
- setUploadSettings
1057
- }
1058
- },
1059
- children: props.children
1060
- });
1061
- };
1062
-
1063
- const getBorderColor = state => {
1064
- const borderColors = {
1065
- default: '#909dbc',
1066
- error: '#e60050',
1067
- active: uiKit.customProperties.colorPrimary
1068
- };
1069
- return borderColors[state] || borderColors.default;
1070
- };
1071
- const getDashedBorder = function () {
1072
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
1073
- const color = getBorderColor(state);
1074
- const svgContent = `
1075
- <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
1076
- <rect width="100%" height="100%" fill="none" stroke="${color}" stroke-width="2px" stroke-dasharray="6,6" stroke-dashoffset="0" stroke-linecap="square"/>
1077
- </svg>
1078
- `;
1079
- return `data:image/svg+xml,${encodeURIComponent(svgContent)}`;
1080
- };
1081
- const base = /*#__PURE__*/react.css("border-radius:", uiKit.customProperties.borderRadius6, ";min-height:136px;display:flex;justify-content:center;align-items:center;" + ("" ), "" );
1082
- const disabled = /*#__PURE__*/react.css("" , "" );
1083
- const readyForDrop = /*#__PURE__*/react.css("background-image:url(\"", getDashedBorder(), "\");background-color:", uiKit.customProperties.colorSurface, ";" + ("" ), "" );
1084
- const activeDrag = /*#__PURE__*/react.css("background-image:url(\"", getDashedBorder('active'), "\");background-color:", uiKit.customProperties.colorPrimary95, ";padding:", uiKit.customProperties.spacing50, " 100px;" + ("" ), "" );
1085
- const fileDropped = /*#__PURE__*/react.css("background-image:url(\"", getDashedBorder(), "\");background-color:", uiKit.customProperties.colorSurface, ";padding:", uiKit.customProperties.spacing50, " 100px;" + ("" ), "" );
1086
- const styles = {
1087
- base,
1088
- readyForDrop,
1089
- fileDropped,
1090
- disabled,
1091
- activeDrag
1092
- };
1093
-
1094
- const DropWrapper = /*#__PURE__*/_styled__default["default"]("div", {
1095
- target: "ef0z5en0"
1096
- } )(styles.base, " ", props => {
1097
- if (props.dropAreaState === 'disabled') {
1098
- return styles.disabled;
1099
- }
1100
- if (props.dropAreaState === 'ready-for-drop') {
1101
- return styles.readyForDrop;
1102
- }
1103
- if (props.dropAreaState === 'active-drag') {
1104
- return styles.activeDrag;
1105
- }
1106
- if (props.dropAreaState === 'file-dropped') {
1107
- return styles.fileDropped;
1108
- }
1109
- return getDefaultDropWrapperStyles(props.dropAreaState);
1110
- }, ";" + ("" ));
1111
- function getDefaultDropWrapperStyles(_dropAreaState) {
1112
- return /*#__PURE__*/react.css("" , "" );
1113
- }
1114
-
1115
- var ActiveDragDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./active-drag-drop-area-94cea372.cjs.prod.js'); }));
1116
-
1117
- var DisabledDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./disabled-drop-area-d8a66b62.cjs.prod.js'); }));
1118
-
1119
- var EnabledDropArea = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./enabled-drop-area-b6fe0252.cjs.prod.js'); }));
1120
-
1121
- var FileDropped = /*#__PURE__*/React.lazy(() => Promise.resolve().then(function () { return require('./file-dropped-area-0e55c4a0.cjs.prod.js'); }));
1122
-
1123
- function getDropArea(_ref) {
1124
- let dropAreaState = _ref.dropAreaState,
1125
- resourceType = _ref.resourceType,
1126
- isFileDropped = _ref.isFileDropped;
1127
- if (dropAreaState === 'file-dropped') {
1128
- return jsxRuntime.jsx(FileDropped, {});
1129
- }
1130
- if (dropAreaState === 'disabled' || !resourceType) {
1131
- return jsxRuntime.jsx(DisabledDropArea, {});
1132
- }
1133
- if (dropAreaState === 'ready-for-drop') {
1134
- return jsxRuntime.jsx(EnabledDropArea, {});
1135
- }
1136
- if (dropAreaState === 'active-drag') {
1137
- return jsxRuntime.jsx(ActiveDragDropArea, {
1138
- isFileDropped: isFileDropped
1139
- });
1140
- }
1141
- return fallbackDropArea();
1142
- }
1143
- function fallbackDropArea(_invalidDropAreaState) {
1144
- return jsxRuntime.jsx(DisabledDropArea, {});
1145
- }
1146
- function getDropAreaState(flags) {
1147
- if (flags.isDragActive) {
1148
- return 'active-drag';
1149
- }
1150
- if (flags.hasResourceType) {
1151
- return 'disabled';
1152
- }
1153
- if (flags.isReady) {
1154
- return 'file-dropped';
1155
- }
1156
- return 'ready-for-drop';
1157
- }
1158
-
1159
- var messages$8 = reactIntl.defineMessages({
1160
- dragAndDropCSV: {
1161
- id: 'ImportResourcesModal.dragAndDropCSV',
1162
- description: 'The message telling the user to drag and drop CSV file in the file drop area',
1163
- defaultMessage: 'Drag and drop CSV'
1164
- },
1165
- or: {
1166
- id: 'ImportResourcesModal.or',
1167
- description: 'The word "or" in the drag and drop message',
1168
- defaultMessage: 'or'
1169
- },
1170
- browseButton: {
1171
- id: 'ImportResourcesModal.browseFile',
1172
- defaultMessage: 'Browse file'
1173
- },
1174
- uploadFile: {
1175
- id: 'ImportResourcesModal.uploadFile',
1176
- description: 'Label for a button on the file upload page, shown on active drop area state',
1177
- defaultMessage: 'Upload file'
1178
- },
1179
- chooseFile: {
1180
- id: 'ImportResourcesModal.chooseFile',
1181
- description: 'Label for a button on the file upload page, shown on ready to upload state',
1182
- defaultMessage: 'Choose file'
1183
- },
1184
- fileUploadFailed: {
1185
- id: 'ImportResourcesModal.fileUploadFailed',
1186
- description: 'A title on the file upload page, shown on file upload error state',
1187
- defaultMessage: 'File upload failed'
1188
- },
1189
- fileFormatNotSupported: {
1190
- id: 'ImportResourcesModal.fileFormatNotSupported',
1191
- description: 'Error message displayed when a user drags and drops a non-CSV file',
1192
- defaultMessage: 'Invalid file format: The file is not in CSV format and cannot be processed.'
1193
- },
1194
- tooManyFilesError: {
1195
- id: 'ImportResourcesModal.tooManyFilesError',
1196
- description: 'Error message displayed when a user drags and drops multiple files at once',
1197
- defaultMessage: 'Multiple files detected: You can only drag and drop one file at a time.'
1198
- },
1199
- genericError: {
1200
- id: 'ImportResourcesModal.genericError',
1201
- description: 'Default error message for unexpected file upload issues (for unhandled cases)',
1202
- defaultMessage: 'Error occurred: Please try uploading the file again or contact our support team for assistance.'
1203
- },
1204
- dataType: {
1205
- id: 'ImportResourcesModal.dataType',
1206
- description: 'Label for the data type selection dropdown',
1207
- defaultMessage: 'Data type'
1208
- },
1209
- instructions: {
1210
- id: 'ImportResourcesModal.instructions',
1211
- description: 'Label for the instructions section',
1212
- defaultMessage: 'Instructions'
1213
- }
1214
- });
1215
-
1216
- function useImportResourcesContext() {
1217
- const context = React.useContext(ImportResourcesContext);
1218
- if (!context) {
1219
- throw new MissingImportResourceProviderError();
1220
- }
1221
- return context;
1222
- }
1223
-
1224
- var messages$7 = reactIntl.defineMessages({
1225
- fileSizeExceededTitle: {
1226
- id: 'ImportResourcesModal.sizeExceededTitle',
1227
- defaultMessage: 'File size exceeded'
1228
- },
1229
- fileSizeExceededDescription: {
1230
- id: 'ImportResourcesModal.sizeExceededDescription',
1231
- description: 'Error description when the file size exceeds the allowable limit',
1232
- defaultMessage: 'The file exceeds the maximum allowed size of {fileSizeLimit} MB'
1233
- },
1234
- rowLimitExceededTitle: {
1235
- id: 'ImportResourcesModal.rowLimitExceededTitle',
1236
- defaultMessage: 'Row limit exceeded'
1237
- },
1238
- rowLimitExceededDescription: {
1239
- id: 'ImportResourcesModal.rowLimitExceededDescription',
1240
- description: 'Error description when the file contains more rows than the allowable maximum',
1241
- defaultMessage: 'The file contains more than the allowable maximum of {rowLimit} rows'
1242
- },
1243
- wrongSeparatorTitle: {
1244
- id: 'ImportResourcesModal.wrongSeparatorTitle',
1245
- defaultMessage: 'Wrong separator'
1246
- },
1247
- wrongSeparatorDescription: {
1248
- id: 'ImportResourcesModal.wrongSeparatorDescription',
1249
- description: 'Message within the drop area when a CSV file uses an unexpected separator',
1250
- defaultMessage: 'The file is using an unsupported separator. Please use one of the allowed separators: {delimiterList}.'
1251
- },
1252
- dropAreaNotEnoughRowsTitle: {
1253
- id: 'ImportResourcesModal.dropAreaNotEnoughRowsTitle',
1254
- description: 'Error title shown when the uploaded CSV file does not contain a header and at least one row of data',
1255
- defaultMessage: 'Invalid CSV file'
1256
- },
1257
- dropAreaNotEnoughRowsDescription: {
1258
- id: 'ImportResourcesModal.dropAreaNotEnoughRowsDescription',
1259
- description: 'Error description shown when the uploaded CSV file does not contain a header and at least one row of data',
1260
- defaultMessage: 'Make sure the file contains a header and at least one row of data'
1261
- },
1262
- unexpectedError: {
1263
- id: 'ImportResourcesModal.unexpectedError',
1264
- description: 'Generic notification message when file upload fails',
1265
- defaultMessage: 'An unexpected error occurred during the file upload. Please try again, or contact support if this error occurs again.'
1266
- },
1267
- missingRequiredField: {
1268
- id: 'ImportResourcesModal.missingRequiredField',
1269
- description: 'Error message displayed when a required field is missing',
1270
- defaultMessage: 'Missing required field'
1271
- },
1272
- missingKeyError: {
1273
- id: 'ImportResourcesModal.missingKeyError',
1274
- description: 'Error message displayed when the uploaded file is missing the key field',
1275
- defaultMessage: "The 'key' field is missing or incomplete in some rows. Please ensure every row has a 'key' value."
1276
- },
1277
- missingRequiredKeys: {
1278
- id: 'ImportResourcesModal.missingRequiredKeys',
1279
- description: 'Error message displayed when the uploaded file is missing required keys',
1280
- defaultMessage: 'Make sure the file contains required keys for the elements including {fieldNames}'
1281
- }
1282
- });
1283
-
1284
- function ownKeys$e(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; }
1285
- function _objectSpread$e(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$e(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$e(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1286
- const useUpload = () => {
1287
- const intl = reactIntl.useIntl();
1288
- const projectKey = applicationShellConnectors.useApplicationContext(context => context.project?.key);
1289
- const _useImportResourcesCo = useImportResourcesContext(),
1290
- state = _useImportResourcesCo.state,
1291
- actions = _useImportResourcesCo.actions;
1292
- const asyncDispatch = sdk.useAsyncDispatch();
1293
- const showNotification = actionsGlobal.useShowNotification();
1294
- React__default["default"].useEffect(() => {
1295
- return () => {
1296
- if (state.abortController) state.abortController.abort();
1297
- };
1298
- }, [state.abortController]);
1299
- const isFileValid = async file => {
1300
- const errors = [];
1301
- const isDelimiterValid = await validateDelimiter(file);
1302
- if (!isDelimiterValid) errors.push({
1303
- title: intl.formatMessage(messages$7.wrongSeparatorTitle),
1304
- description: intl.formatMessage(messages$7.wrongSeparatorDescription, {
1305
- delimiterList: formatAllowedDelimitersForMessageDisplay(intl)
1306
- })
1307
- });
1308
- const rowCount = await getRowCount(file);
1309
- if (rowCount < 1) errors.push({
1310
- title: intl.formatMessage(messages$7.dropAreaNotEnoughRowsTitle),
1311
- description: intl.formatMessage(messages$7.dropAreaNotEnoughRowsDescription)
1312
- });
1313
- if (state.resourceType && file.size > toBytes(FILE_SIZE_LIMITS_MB[state.resourceType])) errors.push({
1314
- title: intl.formatMessage(messages$7.fileSizeExceededTitle),
1315
- description: intl.formatMessage(messages$7.fileSizeExceededDescription, {
1316
- fileSizeLimit: intl.formatNumber(FILE_SIZE_LIMITS_MB[state.resourceType])
1317
- })
1318
- });
1319
- if (state.resourceType && rowCount > ROW_LIMITS[state.resourceType]) errors.push({
1320
- title: intl.formatMessage(messages$7.rowLimitExceededTitle),
1321
- description: intl.formatMessage(messages$7.rowLimitExceededDescription, {
1322
- rowLimit: intl.formatNumber(ROW_LIMITS[state.resourceType])
1323
- })
1324
- });
1325
- if (errors.length > 0) {
1326
- actions.setFileUploadErrors(errors);
1327
- actions.setCurrentStep(CurrentStep$1.UploadResult);
1328
- return false;
1329
- }
1330
- return true;
1331
- };
1332
- const handleUploadError = error => {
1333
- if (isAbortError(error)) {
1334
- actions.cancelImport();
1335
- return;
1336
- }
1337
- if (error instanceof HttpError) {
1338
- if (error.errorData?.code === 'MISSING_KEY_ERROR') {
1339
- actions.setFileUploadErrors([{
1340
- title: intl.formatMessage(messages$7.missingRequiredField),
1341
- description: intl.formatMessage(messages$7.missingKeyError)
1342
- }]);
1343
- actions.setCurrentStep(CurrentStep$1.UploadResult);
1344
- } else if (error.errorData?.code === 'MissingCsvFieldIdentifier') {
1345
- const MissingCsvFieldIdentifierError = error.errorData;
1346
- const fieldNames = formatKeys(MissingCsvFieldIdentifierError.rowValue);
1347
- actions.setFileUploadErrors([{
1348
- title: intl.formatMessage(messages$7.missingRequiredField),
1349
- description: intl.formatMessage(messages$7.missingRequiredKeys, {
1350
- fieldNames
1351
- })
1352
- }]);
1353
- actions.setCurrentStep(CurrentStep$1.UploadResult);
1354
- } else if (error.errorData?.invalid > 0) {
1355
- actions.setUploadFileResponse(error.errorData);
1356
- actions.setCurrentStep(CurrentStep$1.UploadResult);
1357
- } else {
1358
- actions.cancelImport();
1359
- showNotification({
1360
- kind: 'error',
1361
- domain: constants.DOMAINS.PAGE,
1362
- text: intl.formatMessage(messages$7.unexpectedError)
1363
- });
1364
- }
1365
- } else {
1366
- actions.cancelImport();
1367
- showNotification({
1368
- kind: 'error',
1369
- domain: constants.DOMAINS.PAGE,
1370
- text: isError(error) ? error.toString() : String(error)
1371
- });
1372
- sentry.reportErrorToSentry(new Error('Upload File Error: An unexpected issue occurred while uploading the file'), {
1373
- extra: {
1374
- error,
1375
- projectKey,
1376
- containerKey: state.containerKey,
1377
- resourceType: state.resourceType,
1378
- fileSizeInBytes: state.droppedFile?.size
1379
- }
1380
- });
1381
- }
1382
- };
1383
- const handleUploadAndValidation = async () => {
1384
- if (!projectKey || !state.droppedFile || !state.resourceType) return;
1385
- const canUpload = await isFileValid(state.droppedFile);
1386
- if (!canUpload) return;
1387
- actions.setCurrentStep(CurrentStep$1.Uploading);
1388
- const containerKey = encodeFileNameWithTimestampToContainerKey(state.droppedFile.name);
1389
- actions.setContainerKey(containerKey);
1390
- try {
1391
- const shouldApplyPublishSettings = state.resourceType === 'product';
1392
- await createImportContainerForFileUpload({
1393
- key: containerKey,
1394
- resourceType: state.resourceType,
1395
- tags: [TAG_KEY_SOURCE_FILE_UPLOAD],
1396
- settings: _objectSpread$e({
1397
- format: 'CSV',
1398
- decimalSeparator: state.settings?.decimalSeparator
1399
- }, shouldApplyPublishSettings ? {
1400
- resourceType: state.resourceType === 'product' ? 'product-draft' : state.resourceType,
1401
- options: {
1402
- publishAllChanges: state.settings?.publish ?? false
1403
- }
1404
- } : {})
1405
- }, projectKey, asyncDispatch);
1406
- const newAbortController = uploadFileForImport({
1407
- projectKey,
1408
- containerKey,
1409
- resourceType: state.resourceType,
1410
- file: state.droppedFile,
1411
- onSuccess: fileUploadResponse => {
1412
- actions.setUploadFileResponse(fileUploadResponse);
1413
- actions.setCurrentStep(CurrentStep$1.UploadResult);
1414
- },
1415
- onProgress: progress => {
1416
- actions.setProgress(progress);
1417
- },
1418
- onError: error => {
1419
- deleteImportContainer(projectKey, containerKey, asyncDispatch);
1420
- handleUploadError(error);
1421
- }
1422
- });
1423
- actions.setAbortController(newAbortController);
1424
- } catch (error) {
1425
- deleteImportContainer(projectKey, containerKey, asyncDispatch);
1426
- handleUploadError(error);
1427
- actions.setCurrentStep(CurrentStep$1.UploadResult);
1428
- }
1429
- };
1430
- return {
1431
- handleUploadAndValidation
1432
- };
1433
- };
1434
-
1435
- const useImportPermission = () => {
1436
- const _useApplicationContex = applicationShellConnectors.useApplicationContext(applicationContext => ({
1437
- actionRights: applicationContext.actionRights?.products
1438
- })),
1439
- actionRights = _useApplicationContex.actionRights;
1440
- const canManageProducts = permissions.useIsAuthorized({
1441
- demandedPermissions: [PERMISSIONS.ManageProducts]
1442
- });
1443
- const canManageCustomers = permissions.useIsAuthorized({
1444
- demandedPermissions: [PERMISSIONS.ManageCustomers]
1445
- });
1446
- const canManageOrders = permissions.useIsAuthorized({
1447
- demandedPermissions: [PERMISSIONS.ManageOrders]
1448
- });
1449
- const canManageKeyValueDocuments = permissions.useIsAuthorized({
1450
- demandedPermissions: [PERMISSIONS.ManageKeyValueDocuments]
1451
- });
1452
- const canMAnageCategories = permissions.useIsAuthorized({
1453
- demandedPermissions: [PERMISSIONS.ManageCategories]
1454
- });
1455
- const canManageDiscountCodes = permissions.useIsAuthorized({
1456
- demandedPermissions: [PERMISSIONS.ManageDiscountCodes]
1457
- });
1458
- const canManageBusinessUnits = permissions.useIsAuthorized({
1459
- demandedPermissions: [PERMISSIONS.ManageBusinessUnits]
1460
- });
1461
- const canImportProducts = React.useMemo(() => {
1462
- if (!actionRights) return false;
1463
- const canAddPrices = actionRights.canAddPrices,
1464
- canAddProducts = actionRights.canAddProducts,
1465
- canEditAttributesAll = actionRights['canEditAttributes:all'],
1466
- canEditPrices = actionRights.canEditPrices;
1467
- return canManageProducts && canAddPrices && canAddProducts && canEditAttributesAll && canEditPrices;
1468
- }, [canManageProducts, actionRights]);
1469
- const canManageCustomObjects = React.useMemo(() => {
1470
- return canManageProducts || canManageCustomers || canManageOrders || canManageKeyValueDocuments;
1471
- }, [canManageCustomers, canManageOrders, canManageProducts, canManageKeyValueDocuments]);
1472
- return {
1473
- canImportProducts,
1474
- canImportCategories: canMAnageCategories,
1475
- canImportDiscountCodes: canManageDiscountCodes,
1476
- canImportBusinessUnits: canManageBusinessUnits,
1477
- canImportInventories: canManageProducts,
1478
- canImportProductTypes: canManageProducts,
1479
- canImportCustomObjects: canManageCustomObjects
1480
- };
1481
- };
1482
-
1483
- function ownKeys$d(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; }
1484
- function _objectSpread$d(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$d(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$d(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1485
- const FileDropArea = () => {
1486
- const intl = reactIntl.useIntl();
1487
- const _useImportResourcesCo = useImportResourcesContext(),
1488
- state = _useImportResourcesCo.state,
1489
- actions = _useImportResourcesCo.actions;
1490
- const isResourceTypeSelected = Boolean(state.resourceType);
1491
- const showNotification = actionsGlobal.useShowNotification();
1492
- const onDrop = React__default["default"].useCallback(_ref => {
1493
- let _ref2 = _slicedToArray(_ref, 1),
1494
- file = _ref2[0];
1495
- if (!file) return;
1496
- assertResourceType(state.resourceType);
1497
- actions.setDroppedFile(file);
1498
- }, [state.resourceType]);
1499
- const _useDropzone = reactDropzone.useDropzone({
1500
- onDrop,
1501
- multiple: false,
1502
- disabled: !isResourceTypeSelected,
1503
- accept: {
1504
- 'text/csv': ['.csv']
1505
- },
1506
- onDropRejected: _ref3 => {
1507
- var _context, _context2;
1508
- let _ref4 = _slicedToArray(_ref3, 1),
1509
- rejectedFile = _ref4[0];
1510
- if (_someInstanceProperty__default["default"](_context = rejectedFile.errors).call(_context, error => error.code === 'too-many-files')) {
1511
- showNotification({
1512
- kind: 'error',
1513
- domain: constants.DOMAINS.PAGE,
1514
- text: intl.formatMessage(messages$8.tooManyFilesError)
1515
- });
1516
- return;
1517
- }
1518
- if (_someInstanceProperty__default["default"](_context2 = rejectedFile.errors).call(_context2, error => error.code === 'file-invalid-type')) {
1519
- showNotification({
1520
- kind: 'error',
1521
- domain: constants.DOMAINS.PAGE,
1522
- text: intl.formatMessage(messages$8.fileFormatNotSupported)
1523
- });
1524
- } else {
1525
- showNotification({
1526
- kind: 'error',
1527
- domain: constants.DOMAINS.PAGE,
1528
- text: intl.formatMessage(messages$8.genericError)
1529
- });
1530
- }
1531
- }
1532
- }),
1533
- getRootProps = _useDropzone.getRootProps,
1534
- getInputProps = _useDropzone.getInputProps,
1535
- isDragActive = _useDropzone.isDragActive;
1536
- const dropAreaState = React__default["default"].useMemo(() => getDropAreaState({
1537
- isReady: Boolean(state.droppedFile),
1538
- hasResourceType: !state.resourceType,
1539
- isDragActive
1540
- }), [state.resourceType, state.droppedFile, isDragActive]);
1541
- const dropArea = getDropArea({
1542
- dropAreaState,
1543
- resourceType: 'category',
1544
- isFileDropped: Boolean(state.droppedFile)
1545
- });
1546
- return jsxRuntime.jsxs(DropWrapper, _objectSpread$d(_objectSpread$d({
1547
- role: "presentation"
1548
- }, getRootProps()), {}, {
1549
- dropAreaState: dropAreaState,
1550
- children: [jsxRuntime.jsx("input", _objectSpread$d({
1551
- "data-testid": "file-input"
1552
- }, getInputProps())), jsxRuntime.jsx(uiKit.Constraints.Horizontal, {
1553
- children: dropArea
1554
- })]
1555
- }));
1556
- };
1557
-
1558
- var messages$6 = reactIntl.defineMessages({
1559
- separatorTitle: {
1560
- id: 'ImportResourcesModal.uploadSeparator.separatorTitle',
1561
- description: 'Title for the separator selection',
1562
- defaultMessage: 'Separator'
1563
- },
1564
- decimalsSeparatorDescription: {
1565
- id: 'ImportResourcesModal.uploadSeparator.decimalsSeparatorDescription',
1566
- description: 'Description for the decimals separator selection',
1567
- defaultMessage: 'Select the decimals separator that match your CSV file. The column separator is automatically detected.'
1568
- },
1569
- decimalSeparatorPoint: {
1570
- id: 'ImportResourcesModal.uploadSeparator.decimalSeparatorPoint',
1571
- description: 'Label for point decimal separator option',
1572
- defaultMessage: 'point (.)'
1573
- },
1574
- decimalSeparatorComma: {
1575
- id: 'ImportResourcesModal.uploadSeparator.decimalSeparatorComma',
1576
- description: 'Label for comma decimal separator option',
1577
- defaultMessage: 'comma (,)'
1578
- },
1579
- decimals: {
1580
- id: 'ImportResourcesModal.uploadSeparator.decimals',
1581
- description: 'Label for decimal separator select',
1582
- defaultMessage: 'Decimals'
1583
- }
1584
- });
1585
-
1586
- function ownKeys$c(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; }
1587
- function _objectSpread$c(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$c(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$c(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1588
- const DECIMAL_DELIMITER_OPTIONS = [{
1589
- label: messages$6.decimalSeparatorPoint,
1590
- value: DELIMITERS.POINT
1591
- }, {
1592
- label: messages$6.decimalSeparatorComma,
1593
- value: DELIMITERS.COMMA
1594
- }];
1595
- const decimalSeparatorOptions = _mapInstanceProperty__default["default"](DECIMAL_DELIMITER_OPTIONS).call(DECIMAL_DELIMITER_OPTIONS, option => _objectSpread$c(_objectSpread$c({}, option), {}, {
1596
- label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$c({}, option.label))
1597
- }));
1598
- var _ref$1 = {
1599
- name: "lt3z56",
1600
- styles: "width:calc(50% - 16px)"
1601
- } ;
1602
- const UploadSeparator = () => {
1603
- const intl = reactIntl.useIntl();
1604
- const _useImportResourcesCo = useImportResourcesContext(),
1605
- state = _useImportResourcesCo.state,
1606
- actions = _useImportResourcesCo.actions;
1607
- return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1608
- scale: "m",
1609
- children: [jsxRuntime.jsxs("div", {
1610
- children: [jsxRuntime.jsx(uiKit.Text.Subheadline, {
1611
- as: "h4",
1612
- intlMessage: messages$6.separatorTitle
1613
- }), jsxRuntime.jsx(uiKit.Text.Caption, {
1614
- tone: "tertiary",
1615
- intlMessage: messages$6.decimalsSeparatorDescription
1616
- })]
1617
- }), jsxRuntime.jsx("div", {
1618
- css: _ref$1,
1619
- children: jsxRuntime.jsx(uiKit.SelectField, {
1620
- title: intl.formatMessage(messages$6.decimals),
1621
- isSearchable: false,
1622
- options: decimalSeparatorOptions,
1623
- value: state.settings?.decimalSeparator,
1624
- onChange: e => {
1625
- actions.setUploadSettings({
1626
- decimalSeparator: e.target.value
1627
- });
1628
- }
1629
- })
1630
- })]
1631
- });
1632
- };
1633
-
1634
- var messages$5 = reactIntl.defineMessages({
1635
- publishProducts: {
1636
- id: 'ImportResourcesModal.settings.publishProducts',
1637
- description: 'Label for the publish products checkbox',
1638
- defaultMessage: 'Publish all products in the file'
1639
- }
1640
- });
1641
-
1642
- 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; }
1643
- 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; }
1644
- const UploadProductSettings = () => {
1645
- const _useImportResourcesCo = useImportResourcesContext(),
1646
- state = _useImportResourcesCo.state,
1647
- actions = _useImportResourcesCo.actions;
1648
- return jsxRuntime.jsx(uiKit.CheckboxInput, {
1649
- "data-tracking-target": 'product_import-publish_checkbox',
1650
- isChecked: state.settings?.publish,
1651
- onChange: e => {
1652
- actions.setUploadSettings({
1653
- publish: e.target.checked
1654
- });
1655
- },
1656
- children: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$b({}, messages$5.publishProducts))
1657
- });
1658
- };
1659
- const UploadSettings = () => {
1660
- const _useImportResourcesCo2 = useImportResourcesContext(),
1661
- state = _useImportResourcesCo2.state;
1662
- const canPublishProducts = permissions.useIsAuthorized({
1663
- demandedPermissions: [PERMISSIONS.ManageProducts],
1664
- demandedActionRights: [ACTION_RIGHTS.PublishProducts]
1665
- });
1666
- if (state.resourceType === 'product' && canPublishProducts) return jsxRuntime.jsx(UploadProductSettings, {});
1667
- return null;
1668
- };
1669
-
1670
- const Upload = () => {
1671
- const _useImportResourcesCo = useImportResourcesContext(),
1672
- state = _useImportResourcesCo.state,
1673
- onClose = _useImportResourcesCo.onClose,
1674
- resourceTypes = _useImportResourcesCo.resourceTypes;
1675
- const intl = reactIntl.useIntl();
1676
- const _useUpload = useUpload(),
1677
- handleUploadAndValidation = _useUpload.handleUploadAndValidation;
1678
- const isMultipleResourceTypes = resourceTypes.length > 1;
1679
- return jsxRuntime.jsx(applicationComponents.FormDialog, {
1680
- size: 16,
1681
- isOpen: true,
1682
- title: intl.formatMessage(sharedMessages[`modalTitle.${state.resourceType}`]),
1683
- labelPrimary: intl.formatMessage(sharedMessages.uploadButton),
1684
- onPrimaryButtonClick: handleUploadAndValidation,
1685
- isPrimaryButtonDisabled: !Boolean(state.droppedFile),
1686
- onSecondaryButtonClick: () => onClose({
1687
- shouldDeleteImportContainer: true
1688
- }),
1689
- onClose: () => onClose({
1690
- shouldDeleteImportContainer: true
1691
- }),
1692
- dataAttributesPrimaryButton: {
1693
- 'data-tracking-target': `${state.resourceType}_import-upload_and_preview_button`
1694
- },
1695
- children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
1696
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1697
- scale: "l",
1698
- children: [isMultipleResourceTypes ? jsxRuntime.jsxs(uiKit.Grid, {
1699
- gridRowGap: uiKit.designTokens.spacingL,
1700
- gridTemplateColumns: `calc(${uiKit.designTokens.constraint3} + ${uiKit.designTokens.spacingL}) auto`,
1701
- children: [jsxRuntime.jsx(uiKit.Grid.Item, {
1702
- children: jsxRuntime.jsx(uiKit.Text.Body, {
1703
- isBold: true,
1704
- intlMessage: messages$8.dataType
1705
- })
1706
- }), jsxRuntime.jsx(uiKit.Grid.Item, {
1707
- children: jsxRuntime.jsx(ResourceTypeSelection, {})
1708
- }), jsxRuntime.jsx(uiKit.Grid.Item, {
1709
- children: jsxRuntime.jsx(uiKit.Text.Body, {
1710
- isBold: true,
1711
- intlMessage: messages$8.instructions
1712
- })
1713
- }), jsxRuntime.jsx(uiKit.Grid.Item, {
1714
- children: jsxRuntime.jsx(Instructions, {})
1715
- })]
1716
- }) : jsxRuntime.jsx(jsxRuntime.Fragment, {
1717
- children: jsxRuntime.jsx(Instructions, {})
1718
- }), jsxRuntime.jsx(InfoBox, {}), jsxRuntime.jsx(UploadSeparator, {}), jsxRuntime.jsx(fullstory.Masking.Mask, {
1719
- children: jsxRuntime.jsx(FileDropArea, {})
1720
- }), jsxRuntime.jsx(UploadSettings, {})]
1721
- })
1722
- })
1723
- });
1724
- };
1725
-
1726
- var messages$4 = reactIntl.defineMessages({
1727
- row: {
1728
- id: 'ImportResourcesModal.row',
1729
- description: 'In Upload file error modal - "Row" column',
1730
- defaultMessage: 'Row'
1731
- },
1732
- errorType: {
1733
- id: 'ImportResourcesModal.errorType',
1734
- description: 'In Upload file error modal - "Error type" column',
1735
- defaultMessage: 'Error type'
1736
- },
1737
- details: {
1738
- id: 'ImportResourcesModal.details',
1739
- description: 'In Upload file error modal - "Details" column',
1740
- defaultMessage: 'Details'
1741
- },
1742
- uploadErrorDescription: {
1743
- id: 'ImportResourcesModal.uploadErrorDescription',
1744
- description: 'Title when errors detected while uploading file',
1745
- defaultMessage: 'There {errorsCount, plural, one {is <b>{errorsCount}</b> error} other {are <b>{errorsCount}</b> errors}} detected while uploading the file <b>{fileName}</b>.'
1746
- },
1747
- supportedValuesDocumentation: {
1748
- id: 'ImportResourcesModal.supportedValuesDocumentation',
1749
- description: 'Link to the documentation for supported values',
1750
- defaultMessage: '<documentationLink>View the documentation</documentationLink> for supported values.'
1751
- },
1752
- uploadNewFile: {
1753
- id: 'ImportResourcesModal.uploadNewFile',
1754
- description: 'Upload new file button',
1755
- defaultMessage: 'Upload new file'
1756
- }
1757
- });
1758
-
1759
- 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; }
1760
- function _objectSpread$a(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$a(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$a(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1761
- const getColumns$1 = () => [{
1762
- key: 'errorType',
1763
- label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$a({}, messages$4.errorType)),
1764
- width: 'max-content'
1765
- }, {
1766
- key: 'details',
1767
- label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$a({}, messages$4.details))
1768
- }];
1769
- const UploadErrorTable = props => {
1770
- var _context;
1771
- const pagination = uiKit.usePaginationState({
1772
- perPage: 10
1773
- });
1774
- const startIndex = (pagination.page.value - 1) * pagination.perPage.value;
1775
- const endIndex = startIndex + pagination.perPage.value;
1776
- const currentPageRows = _sliceInstanceProperty__default["default"](_context = props.rows).call(_context, startIndex, endIndex);
1777
- const shouldShowPagination = props.rows.length > pagination.perPage.value;
1778
- return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1779
- scale: "l",
1780
- children: [jsxRuntime.jsx(uiKit.DataTable, {
1781
- verticalCellAlignment: "center",
1782
- isCondensed: true,
1783
- rows: currentPageRows,
1784
- columns: getColumns$1(),
1785
- itemRenderer: itemRenderer$1
1786
- }), shouldShowPagination && jsxRuntime.jsx(uiKit.PageNavigator, {
1787
- onPageChange: pagination.page.onChange,
1788
- page: pagination.page.value,
1789
- totalPages: Math.ceil(props.rows.length / pagination.perPage.value)
1790
- })]
1791
- });
1792
- };
1793
- function itemRenderer$1(item, column) {
1794
- switch (column.key) {
1795
- case 'errorType':
1796
- return jsxRuntime.jsx(uiKit.Stamp, {
1797
- isCondensed: true,
1798
- label: item.title,
1799
- tone: "critical"
1800
- });
1801
- case 'details':
1802
- return jsxRuntime.jsx(uiKit.Text.Body, {
1803
- children: item.description
1804
- });
1805
- default:
1806
- throw new UnexpectedColumnError(column.key);
1807
- }
1808
- }
1809
-
1810
- 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; }
1811
- 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; }
1812
- const UploadErrorsModal = () => {
1813
- const intl = reactIntl.useIntl();
1814
- const _useImportResourcesCo = useImportResourcesContext(),
1815
- state = _useImportResourcesCo.state,
1816
- actions = _useImportResourcesCo.actions,
1817
- onClose = _useImportResourcesCo.onClose;
1818
- const errorsCount = state.fileUploadErrors.length;
1819
- return jsxRuntime.jsx(applicationComponents.InfoDialog, {
1820
- size: 16,
1821
- isOpen: true,
1822
- title: intl.formatMessage(sharedMessages[`modalTitle.${state.resourceType}`]),
1823
- onClose: () => onClose(),
1824
- children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
1825
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1826
- scale: "l",
1827
- children: [jsxRuntime.jsx(fullstory.Masking.Mask, {
1828
- children: jsxRuntime.jsx(uiKit.Text.Body, {
1829
- intlMessage: _objectSpread$9(_objectSpread$9({}, messages$4.uploadErrorDescription), {}, {
1830
- values: {
1831
- fileName: state.droppedFile?.name,
1832
- errorsCount: intl.formatNumber(errorsCount),
1833
- b: getBold$3
1834
- }
1835
- })
1836
- })
1837
- }), jsxRuntime.jsx(UploadErrorTable, {
1838
- rows: mapFileUploadErrorsToUploadFileErrorRows(state.fileUploadErrors)
1839
- }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1840
- scale: "m",
1841
- justifyContent: "flex-end",
1842
- children: [jsxRuntime.jsx(uiKit.SecondaryButton, {
1843
- label: intl.formatMessage(sharedMessages.close),
1844
- onClick: () => onClose()
1845
- }), jsxRuntime.jsx(uiKit.PrimaryButton, {
1846
- iconLeft: jsxRuntime.jsx(uiKit.ImportIcon, {}),
1847
- label: intl.formatMessage(messages$4.uploadNewFile),
1848
- onClick: () => actions.uploadNewFile()
1849
- })]
1850
- })]
1851
- })
1852
- })
1853
- });
1854
- };
1855
- function getBold$3(msg) {
1856
- return jsxRuntime.jsx(uiKit.Text.Body, {
1857
- as: "span",
1858
- isBold: true,
1859
- children: msg
1860
- }, crypto.randomUUID());
1861
- }
1862
-
1863
- 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; }
1864
- 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; }
1865
- const getColumns = () => [{
1866
- key: 'row',
1867
- label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$8({}, messages$4.row)),
1868
- width: 'max-content'
1869
- }, {
1870
- key: 'errorType',
1871
- label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$8({}, messages$4.errorType)),
1872
- width: 'max-content'
1873
- }, {
1874
- key: 'details',
1875
- label: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$8({}, messages$4.details))
1876
- }];
1877
- const UploadRowErrorTable = props => {
1878
- var _context;
1879
- const pagination = uiKit.usePaginationState({
1880
- perPage: 10
1881
- });
1882
- const startIndex = (pagination.page.value - 1) * pagination.perPage.value;
1883
- const endIndex = startIndex + pagination.perPage.value;
1884
- const currentPageRows = _sliceInstanceProperty__default["default"](_context = props.rows).call(_context, startIndex, endIndex);
1885
- const shouldShowPagination = props.rows.length > pagination.perPage.value;
1886
- return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1887
- scale: "l",
1888
- children: [jsxRuntime.jsx(uiKit.DataTable, {
1889
- verticalCellAlignment: "center",
1890
- isCondensed: true,
1891
- rows: currentPageRows,
1892
- columns: getColumns(),
1893
- itemRenderer: itemRenderer
1894
- }), shouldShowPagination && jsxRuntime.jsx(uiKit.PageNavigator, {
1895
- onPageChange: pagination.page.onChange,
1896
- page: pagination.page.value,
1897
- totalPages: Math.ceil(props.rows.length / pagination.perPage.value)
1898
- })]
1899
- });
1900
- };
1901
- function itemRenderer(item, column) {
1902
- switch (column.key) {
1903
- case 'row':
1904
- return item.row;
1905
- case 'errorType':
1906
- return jsxRuntime.jsx(uiKit.Stamp, {
1907
- isCondensed: true,
1908
- label: formatErrorCode(item.code),
1909
- tone: "critical"
1910
- });
1911
- case 'details':
1912
- return jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1913
- scale: "xs",
1914
- children: [jsxRuntime.jsx(uiKit.Text.Body, {
1915
- tone: "information",
1916
- children: item.field
1917
- }), jsxRuntime.jsx(uiKit.Text.Body, {
1918
- children: extractErrorDescriptionFromValidationMessage(item.validationMessage)
1919
- })]
1920
- });
1921
- default:
1922
- throw new UnexpectedColumnError(column.key);
1923
- }
1924
- }
1925
-
1926
- 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; }
1927
- function _objectSpread$7(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$7(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$7(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
1928
- const UploadRowErrorsModal = () => {
1929
- const intl = reactIntl.useIntl();
1930
- const _useImportResourcesCo = useImportResourcesContext(),
1931
- state = _useImportResourcesCo.state,
1932
- actions = _useImportResourcesCo.actions,
1933
- onClose = _useImportResourcesCo.onClose;
1934
- const errorsCount = getFileUploadErrorsCount(state.uploadFileResponse?.results);
1935
- const documentationLink = RESOURCE_TYPE_DOCUMENTATION_LINKS[state.resourceType];
1936
- return jsxRuntime.jsx(applicationComponents.InfoDialog, {
1937
- size: 16,
1938
- isOpen: true,
1939
- title: intl.formatMessage(sharedMessages[`modalTitle.${state.resourceType}`]),
1940
- onClose: onClose,
1941
- children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
1942
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1943
- scale: "l",
1944
- children: [jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1945
- scale: "xs",
1946
- children: [jsxRuntime.jsx(fullstory.Masking.Mask, {
1947
- children: jsxRuntime.jsx(uiKit.Text.Body, {
1948
- intlMessage: _objectSpread$7(_objectSpread$7({}, messages$4.uploadErrorDescription), {}, {
1949
- values: {
1950
- fileName: state.droppedFile?.name,
1951
- errorsCount: intl.formatNumber(errorsCount),
1952
- b: getBold$2
1953
- }
1954
- })
1955
- })
1956
- }), jsxRuntime.jsx(uiKit.Text.Body, {
1957
- intlMessage: _objectSpread$7(_objectSpread$7({}, messages$4.supportedValuesDocumentation), {}, {
1958
- values: {
1959
- documentationLink: msg => jsxRuntime.jsx(uiKit.Link, {
1960
- tone: "secondary",
1961
- isExternal: true,
1962
- to: documentationLink,
1963
- children: msg
1964
- }, "documentationLink")
1965
- }
1966
- })
1967
- })]
1968
- }), jsxRuntime.jsx(UploadRowErrorTable, {
1969
- rows: mapUploadFileErrorsResponseToUploadFileErrorRows(state.uploadFileResponse?.results)
1970
- }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1971
- scale: "m",
1972
- justifyContent: "flex-end",
1973
- children: [jsxRuntime.jsx(uiKit.SecondaryButton, {
1974
- label: intl.formatMessage(sharedMessages.close),
1975
- onClick: () => onClose()
1976
- }), jsxRuntime.jsx(uiKit.PrimaryButton, {
1977
- iconLeft: jsxRuntime.jsx(uiKit.ImportIcon, {}),
1978
- label: intl.formatMessage(messages$4.uploadNewFile),
1979
- onClick: () => actions.uploadNewFile()
1980
- })]
1981
- })]
1982
- })
1983
- })
1984
- });
1985
- };
1986
- function getBold$2(msg) {
1987
- return jsxRuntime.jsx(uiKit.Text.Body, {
1988
- as: "span",
1989
- isBold: true,
1990
- children: msg
1991
- }, crypto.randomUUID());
1992
- }
1993
-
1994
- var messages$3 = reactIntl.defineMessages({
1995
- startImportButton: {
1996
- id: 'ImportResourcesModal.startImportButton',
1997
- description: 'Label for the modal Start import button',
1998
- defaultMessage: 'Start import'
1999
- },
2000
- importNotificationSuccessMessage: {
2001
- id: 'ImportResourcesModal.successMessage',
2002
- description: 'Notification success message',
2003
- defaultMessage: '<b>Your import has started.</b><newline></newline> <logsLink>Go to Import logs</logsLink> to view the progress.'
2004
- },
2005
- importNotificationPrepareMessage: {
2006
- id: 'ImportResourcesModal.prepareMessage',
2007
- description: 'Notification for preparing import',
2008
- defaultMessage: '<b>Prepare import</b><newline></newline>Once preparation is complete, you can track the import progress <logsLink>in the Import logs</logsLink>.'
2009
- },
2010
- previewOfYourImport: {
2011
- id: 'ImportResourcesModal.previewOfYourImport',
2012
- description: 'Label for modal path',
2013
- defaultMessage: "Here's a preview of your import"
2014
- },
2015
- itemsToBeImported: {
2016
- id: 'ImportResourcesModal.itemsToBeImported',
2017
- description: 'This message indicates the number of items that are ready to be imported into the project.',
2018
- defaultMessage: '{itemCount, plural, one {<b>1</b> {resourceType} to be imported{publish, select, true { and published} other {}}} other {<b>{itemCount}</b> {resourceTypePlural} to be imported{publish, select, true { and published} other {}}}}'
2019
- },
2020
- columnsToBeImported: {
2021
- id: 'ImportResourcesModal.columnsToBeImported',
2022
- description: 'This message indicates the number of columns that are ready to be imported into the system.',
2023
- defaultMessage: '<b>{columnCount}</b> columns to be imported'
2024
- },
2025
- columnsToBeIgnored: {
2026
- id: 'ImportResourcesModal.columnsToBeIgnored',
2027
- description: "This message indicates the number of columns that will be deliberately skipped during the import because they can't be imported",
2028
- defaultMessage: "We will intentionally ignore <b>{columnCount}</b> columns as they can't be imported"
2029
- },
2030
- showMore: {
2031
- id: 'ImportResourcesModal.showMore',
2032
- description: 'A button label for expanding the import preview to show more details.',
2033
- defaultMessage: 'Show more'
2034
- },
2035
- showLess: {
2036
- id: 'ImportResourcesModal.showLess',
2037
- description: 'A button label for collapsing the import preview to show fewer details.',
2038
- defaultMessage: 'Show less'
2039
- },
2040
- continue: {
2041
- id: 'ImportResourcesModal.continue',
2042
- description: 'Confirmation dialog continue button',
2043
- defaultMessage: 'Continue'
2044
- },
2045
- confirmationBodyText: {
2046
- id: 'ImportResourcesModal.confirmationBodyText',
2047
- description: 'Confirmation dialog text',
2048
- defaultMessage: 'You are about to import {count, plural, one {<bold>1</bold> row} other {<bold>{count}</bold> rows}} in the project: <bold>{projectName}</bold>.'
2049
- },
2050
- confirmationBodyNote: {
2051
- id: 'ImportResourcesModal.confirmationBodyNote',
2052
- description: 'Confirmation dialog text',
2053
- defaultMessage: 'Please be aware that existing values with the same keys will be overwritten by the data included in the CSV.'
2054
- },
2055
- confirmationBodyQuestion: {
2056
- id: 'ImportResourcesModal.confirmationBodyQuestion',
2057
- description: 'Confirmation question',
2058
- defaultMessage: 'Proceed with the import?'
2059
- }
2060
- });
2061
-
2062
- 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; }
2063
- function _objectSpread$6(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$6(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$6(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
2064
- const AlignedContainer = /*#__PURE__*/_styled__default["default"]("div", {
2065
- target: "e1amawj91"
2066
- } )({
2067
- name: "1x0d6yz",
2068
- styles: "padding-top:5px"
2069
- } );
2070
- const ModifiedTagList = /*#__PURE__*/_styled__default["default"](uiKit.TagList, {
2071
- target: "e1amawj90"
2072
- } )({
2073
- name: "u9abxe",
2074
- styles: ">div{margin:8px 8px 0 0;}"
2075
- } );
2076
- const ColumnList = props => {
2077
- var _context;
2078
- const _React$useState = React__default["default"].useState(false),
2079
- _React$useState2 = _slicedToArray(_React$useState, 2),
2080
- isExpanded = _React$useState2[0],
2081
- setIsExpanded = _React$useState2[1];
2082
- const shouldShowExpandButton = props.columns.length > INITIAL_COLUMN_DISPLAY_COUNT;
2083
- const finalColumns = isExpanded ? props.columns : _sliceInstanceProperty__default["default"](_context = props.columns).call(_context, 0, INITIAL_COLUMN_DISPLAY_COUNT);
2084
- return jsxRuntime.jsxs(ModifiedTagList, {
2085
- children: [_mapInstanceProperty__default["default"](finalColumns).call(finalColumns, (column, index) => jsxRuntime.jsx(uiKit.Stamp, {
2086
- label: column,
2087
- tone: "secondary"
2088
- }, index)), shouldShowExpandButton && jsxRuntime.jsx(AlignedContainer, {
2089
- children: jsxRuntime.jsx(uiKit.Link, {
2090
- to: "",
2091
- tone: "secondary",
2092
- onClick: e => {
2093
- e.preventDefault();
2094
- setIsExpanded(!isExpanded);
2095
- },
2096
- children: isExpanded ? jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$6({}, messages$3.showLess)) : jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$6({}, messages$3.showMore))
2097
- })
2098
- })]
2099
- });
2100
- };
2101
-
2102
- 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; }
2103
- 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__default["default"](_context = ownKeys$5(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$5(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
2104
- function UploadPreviewModal() {
2105
- const _useImportResourcesCo = useImportResourcesContext(),
2106
- state = _useImportResourcesCo.state;
2107
- const intl = reactIntl.useIntl();
2108
- const _useImportResourcesCo2 = useImportResourcesContext(),
2109
- actions = _useImportResourcesCo2.actions,
2110
- onClose = _useImportResourcesCo2.onClose;
2111
- if (!state.resourceType || !state.uploadFileResponse) return null;
2112
- const resourceTypeMessage = resourceTypeToMessage(state.resourceType);
2113
- const resourceType = intl.formatMessage(resourceTypeMessage).toLowerCase();
2114
- const resourceTypePluralMessage = resourceTypeToPluralMessage(state.resourceType);
2115
- const resourceTypePlural = intl.formatMessage(resourceTypePluralMessage).toLowerCase();
2116
- const ignoredColumns = state.uploadFileResponse.ignoredColumns;
2117
- const validatedColumns = getValidatedColumns(state.uploadFileResponse.columns, ignoredColumns);
2118
- return jsxRuntime.jsx(applicationComponents.FormDialog, {
2119
- size: 16,
2120
- isOpen: true,
2121
- title: intl.formatMessage(sharedMessages[`modalTitle.${state.resourceType}`]),
2122
- labelPrimary: intl.formatMessage(messages$3.continue),
2123
- onSecondaryButtonClick: () => onClose({
2124
- shouldDeleteImportContainer: true
2125
- }),
2126
- onPrimaryButtonClick: () => {
2127
- actions.setCurrentStep(CurrentStep$1.ImportConfirmationModal);
2128
- },
2129
- onClose: () => onClose({
2130
- shouldDeleteImportContainer: true
2131
- }),
2132
- children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
2133
- children: jsxRuntime.jsx(applicationComponents.PageContentNarrow, {
2134
- children: jsxRuntime.jsx(uiKit.Spacings.Stack, {
2135
- scale: "xxxl",
2136
- children: jsxRuntime.jsx(uiKit.Spacings.Stack, {
2137
- scale: "xl",
2138
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
2139
- scale: "m",
2140
- children: [jsxRuntime.jsx("div", {}), jsxRuntime.jsx(uiKit.Text.Body, {
2141
- intlMessage: messages$3.previewOfYourImport
2142
- }), jsxRuntime.jsx(uiKit.Card, {
2143
- insetScale: "xl",
2144
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
2145
- scale: "s",
2146
- children: [jsxRuntime.jsxs(uiKit.Spacings.Stack, {
2147
- scale: "xs",
2148
- children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
2149
- alignItems: "center",
2150
- children: [jsxRuntime.jsx(uiKit.CheckBoldIcon, {
2151
- color: "success"
2152
- }), jsxRuntime.jsx(uiKit.Text.Body, {
2153
- intlMessage: _objectSpread$5(_objectSpread$5({}, messages$3.itemsToBeImported), {}, {
2154
- values: {
2155
- resourceType,
2156
- resourceTypePlural,
2157
- itemCount: intl.formatNumber(state.uploadFileResponse.itemsCount),
2158
- publish: state.resourceType === 'product' && state.settings?.publish,
2159
- b: getBold$1
2160
- }
2161
- })
2162
- })]
2163
- }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
2164
- alignItems: "center",
2165
- children: [jsxRuntime.jsx(uiKit.CheckBoldIcon, {
2166
- color: "success"
2167
- }), jsxRuntime.jsx(uiKit.Text.Body, {
2168
- intlMessage: _objectSpread$5(_objectSpread$5({}, messages$3.columnsToBeImported), {}, {
2169
- values: {
2170
- columnCount: intl.formatNumber(validatedColumns.length),
2171
- b: getBold$1
2172
- }
2173
- })
2174
- })]
2175
- })]
2176
- }), jsxRuntime.jsx(ColumnList, {
2177
- columns: validatedColumns
2178
- })]
2179
- })
2180
- }), ignoredColumns.length > 0 && jsxRuntime.jsx(uiKit.Card, {
2181
- insetScale: "xl",
2182
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
2183
- scale: "s",
2184
- children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
2185
- alignItems: "center",
2186
- children: [jsxRuntime.jsx(uiKit.EyeCrossedIcon, {
2187
- color: "neutral60"
2188
- }), jsxRuntime.jsx(uiKit.Text.Body, {
2189
- intlMessage: _objectSpread$5(_objectSpread$5({}, messages$3.columnsToBeIgnored), {}, {
2190
- values: {
2191
- columnCount: intl.formatNumber(ignoredColumns.length),
2192
- b: getBold$1
2193
- }
2194
- })
2195
- })]
2196
- }), jsxRuntime.jsx(ColumnList, {
2197
- columns: ignoredColumns
2198
- })]
2199
- })
2200
- })]
2201
- })
2202
- })
2203
- })
2204
- })
2205
- })
2206
- });
2207
- }
2208
- function getBold$1(msg) {
2209
- return jsxRuntime.jsx(uiKit.Text.Body, {
2210
- as: "span",
2211
- isBold: true,
2212
- children: msg
2213
- }, crypto.randomUUID());
2214
- }
2215
-
2216
- 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; }
2217
- 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; }
2218
- const getNewLine = () => jsxRuntime.jsx("br", {}, "break");
2219
- const getImportLogsLink = (msg, projectKey) => jsxRuntime.jsx(uiKit.Link, {
2220
- to: `/${projectKey}/operations/import/logs`,
2221
- children: msg
2222
- }, "link");
2223
- var _ref2 = {
2224
- name: "1vs9i7r",
2225
- styles: "width:360px"
2226
- } ;
2227
- const ImportRunningTextNotification = props => jsxRuntime.jsx("div", {
2228
- css: _ref2,
2229
- children: jsxRuntime.jsx(uiKit.Text.Body, {
2230
- intlMessage: _objectSpread$4(_objectSpread$4({}, messages$3.importNotificationSuccessMessage), {}, {
2231
- values: {
2232
- newline: getNewLine,
2233
- logsLink: msg => getImportLogsLink(msg, props.projectKey),
2234
- b: getBold
2235
- }
2236
- })
2237
- })
2238
- });
2239
- var _ref = {
2240
- name: "1vs9i7r",
2241
- styles: "width:360px"
2242
- } ;
2243
- const ImportPreparingTextNotification = props => jsxRuntime.jsx("div", {
2244
- css: _ref,
2245
- children: jsxRuntime.jsx(uiKit.Text.Body, {
2246
- intlMessage: _objectSpread$4(_objectSpread$4({}, messages$3.importNotificationPrepareMessage), {}, {
2247
- values: {
2248
- newline: getNewLine,
2249
- logsLink: msg => getImportLogsLink(msg, props.projectKey),
2250
- b: getBold
2251
- }
2252
- })
2253
- })
2254
- });
2255
- const ImportConfirmationModal = () => {
2256
- const intl = reactIntl.useIntl();
2257
- const _useImportResourcesCo = useImportResourcesContext(),
2258
- state = _useImportResourcesCo.state,
2259
- onStartImportSuccess = _useImportResourcesCo.onStartImportSuccess,
2260
- onClose = _useImportResourcesCo.onClose;
2261
- const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
2262
- projectKey: context.project?.key,
2263
- projectName: context.project?.name
2264
- })),
2265
- projectKey = _useApplicationContex.projectKey,
2266
- projectName = _useApplicationContex.projectName;
2267
- const asyncDispatch = sdk.useAsyncDispatch();
2268
- const showNotification = actionsGlobal.useShowNotification();
2269
- return jsxRuntime.jsx(applicationComponents.ConfirmationDialog, {
2270
- title: intl.formatMessage(sharedMessages[`modalTitle.${state.resourceType}`]),
2271
- labelPrimary: intl.formatMessage(messages$3.startImportButton),
2272
- isOpen: true,
2273
- onClose: () => onClose({
2274
- shouldDeleteImportContainer: true
2275
- }),
2276
- onCancel: () => onClose({
2277
- shouldDeleteImportContainer: true
2278
- }),
2279
- dataAttributesPrimaryButton: {
2280
- 'data-test-id': 'confirmation-dialog-confirm'
2281
- },
2282
- dataAttributesSecondaryButton: {
2283
- 'data-test-id': 'confirmation-dialog-cancel',
2284
- 'data-tracking-target': `${state.resourceType}_import-start_import_button`
2285
- },
2286
- onConfirm: async () => {
2287
- try {
2288
- const canConfirm = projectKey && state.containerKey && state.droppedFile?.name && state.resourceType;
2289
- if (!canConfirm) return;
2290
- onClose();
2291
- showNotification({
2292
- kind: 'info',
2293
- domain: constants.DOMAINS.SIDE,
2294
- // @ts-ignore
2295
- text: jsxRuntime.jsx(ImportPreparingTextNotification, {
2296
- projectKey: projectKey
2297
- })
2298
- }, {
2299
- dismissAfter: 5000
2300
- });
2301
- await processUploadedFile({
2302
- projectKey,
2303
- containerKey: state.containerKey,
2304
- resourceType: state.resourceType,
2305
- asyncDispatch
2306
- });
2307
- onStartImportSuccess();
2308
- showNotification({
2309
- kind: 'info',
2310
- domain: constants.DOMAINS.SIDE,
2311
- // @ts-ignore
2312
- text: jsxRuntime.jsx(ImportRunningTextNotification, {
2313
- projectKey: projectKey
2314
- })
2315
- }, {
2316
- dismissAfter: 5000
2317
- });
2318
- } catch (error) {
2319
- onClose({
2320
- shouldDeleteImportContainer: true
2321
- });
2322
- showNotification({
2323
- kind: 'error',
2324
- domain: constants.DOMAINS.PAGE,
2325
- text: isError(error) ? error.toString() : String(error)
2326
- });
2327
- }
2328
- },
2329
- size: 16,
2330
- children: jsxRuntime.jsx(fullstory.Masking.Unmask, {
2331
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
2332
- scale: "xl",
2333
- children: [jsxRuntime.jsxs("div", {
2334
- children: [jsxRuntime.jsx(uiKit.Text.Body, {
2335
- intlMessage: _objectSpread$4(_objectSpread$4({}, messages$3.confirmationBodyText), {}, {
2336
- values: {
2337
- projectName: projectName,
2338
- count: intl.formatNumber(state?.uploadFileResponse?.rowsCount || 0),
2339
- bold: getBold
2340
- }
2341
- })
2342
- }), jsxRuntime.jsx(uiKit.Text.Body, {
2343
- intlMessage: messages$3.confirmationBodyNote
2344
- })]
2345
- }), jsxRuntime.jsx(uiKit.Text.Body, {
2346
- intlMessage: messages$3.confirmationBodyQuestion
2347
- })]
2348
- })
2349
- })
2350
- });
2351
- };
2352
- function getBold(msg) {
2353
- return jsxRuntime.jsx(uiKit.Text.Body, {
2354
- as: "span",
2355
- isBold: true,
2356
- children: msg
2357
- }, crypto.randomUUID());
2358
- }
2359
-
2360
- const UploadResult = () => {
2361
- const _useImportResourcesCo = useImportResourcesContext(),
2362
- state = _useImportResourcesCo.state;
2363
- if (state.fileUploadErrors.length > 0) return jsxRuntime.jsx(UploadErrorsModal, {});
2364
- if (state.uploadFileResponse?.invalid > 0) return jsxRuntime.jsx(UploadRowErrorsModal, {});
2365
- return jsxRuntime.jsx(UploadPreviewModal, {});
2366
- };
2367
-
2368
- const Uploading = () => {
2369
- const intl = reactIntl.useIntl();
2370
- const _useImportResourcesCo = useImportResourcesContext(),
2371
- state = _useImportResourcesCo.state,
2372
- actions = _useImportResourcesCo.actions,
2373
- onClose = _useImportResourcesCo.onClose;
2374
- if (state.droppedFile?.name) return jsxRuntime.jsx(applicationComponents.InfoDialog, {
2375
- size: 16,
2376
- isOpen: true,
2377
- title: intl.formatMessage(sharedMessages[`modalTitle.${state.resourceType}`]),
2378
- onClose: () => onClose({
2379
- shouldDeleteImportContainer: true
2380
- }),
2381
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
2382
- scale: "m",
2383
- children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
2384
- alignItems: "center",
2385
- justifyContent: "space-between",
2386
- children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
2387
- alignItems: "center",
2388
- children: [jsxRuntime.jsx(FileIcon, {}), jsxRuntime.jsx(uiKit.Spacings.Inline, {
2389
- children: jsxRuntime.jsx(uiKit.Constraints.Horizontal, {
2390
- max: 10,
2391
- children: jsxRuntime.jsx(uiKit.Text.Body, {
2392
- truncate: true,
2393
- isBold: true,
2394
- children: state.droppedFile.name
2395
- })
2396
- })
2397
- }), jsxRuntime.jsxs(uiKit.Text.Body, {
2398
- tone: "secondary",
2399
- children: ["(", intl.formatNumber(convertFileSizeToKB(state.droppedFile.size)), ' ', "KB)"]
2400
- })]
2401
- }), jsxRuntime.jsx(uiKit.SecondaryButton, {
2402
- tone: "secondary",
2403
- size: "medium",
2404
- label: intl.formatMessage(sharedMessages.cancel),
2405
- onClick: () => {
2406
- actions.setCurrentStep(CurrentStep$1.Upload);
2407
- state.abortController.abort();
2408
- }
2409
- })]
2410
- }), jsxRuntime.jsx(uiKit.ProgressBar, {
2411
- barWidth: "scale",
2412
- height: "10",
2413
- progress: state.progress
2414
- }), jsxRuntime.jsx("div", {})]
2415
- })
2416
- });
2417
- return null;
2418
- };
2419
-
2420
- const CurrentStep = () => {
2421
- const _useImportResourcesCo = useImportResourcesContext(),
2422
- state = _useImportResourcesCo.state;
2423
- const steps = {
2424
- upload: jsxRuntime.jsx(Upload, {}),
2425
- uploading: jsxRuntime.jsx(Uploading, {}),
2426
- 'upload-result': jsxRuntime.jsx(UploadResult, {}),
2427
- 'import-confirmation-modal': jsxRuntime.jsx(ImportConfirmationModal, {})
2428
- };
2429
- return steps[state.currentStep] || null;
2430
- };
2431
-
2432
- var messages$2 = reactIntl.defineMessages({
2433
- products: {
2434
- id: 'ImportResourcesModal.radio.products',
2435
- description: 'Label for the products radio button',
2436
- defaultMessage: 'Products (including variants, assets, prices and images)'
2437
- },
2438
- inventories: {
2439
- id: 'ImportResourcesModal.radio.inventories',
2440
- description: 'Label for the inventories radio button',
2441
- defaultMessage: 'Inventories'
2442
- },
2443
- categories: {
2444
- id: 'ImportResourcesModal.radio.categories',
2445
- description: 'Label for the categories radio button',
2446
- defaultMessage: 'Categories'
2447
- }
2448
- });
2449
-
2450
- const resourceTypeToDisplayName = resourceType => {
2451
- switch (resourceType) {
2452
- case IMPORTABLE_RESOURCES.PRODUCT:
2453
- return messages$2.products;
2454
- case IMPORTABLE_RESOURCES.INVENTORY:
2455
- return messages$2.inventories;
2456
- case IMPORTABLE_RESOURCES.CATEGORY:
2457
- return messages$2.categories;
2458
- default:
2459
- throw new Error(`Unknown resource type: ${resourceType}`);
2460
- }
2461
- };
2462
- const ResourceTypeSelection = () => {
2463
- const _useImportResourcesCo = useImportResourcesContext(),
2464
- state = _useImportResourcesCo.state,
2465
- actions = _useImportResourcesCo.actions,
2466
- resourceTypes = _useImportResourcesCo.resourceTypes;
2467
- return jsxRuntime.jsx(uiKit.RadioInput.Group, {
2468
- value: state.resourceType,
2469
- onChange: e => {
2470
- actions.setResourceType(e.target.value);
2471
- },
2472
- direction: "stack",
2473
- directionProps: {
2474
- scale: 's'
2475
- },
2476
- children: _mapInstanceProperty__default["default"](resourceTypes).call(resourceTypes, resourceType => jsxRuntime.jsx(uiKit.RadioInput.Option, {
2477
- value: resourceType,
2478
- children: jsxRuntime.jsx(uiKit.Text.Body, {
2479
- intlMessage: resourceTypeToDisplayName(resourceType)
2480
- })
2481
- }, resourceType))
2482
- });
2483
- };
2484
-
2485
- var messages$1 = reactIntl.defineMessages({
2486
- fileUploadInstructions: {
2487
- id: 'ImportResourcesModal.fileUploadInstructions',
2488
- description: 'Label for the modal category description',
2489
- defaultMessage: 'Maximum file size is {fileSize} MB with a limit of {rowLimit} rows. Download <csvTemplateLink>the CSV template</csvTemplateLink> or refer to <documentationLink>the documentation</documentationLink>.'
2490
- }
2491
- });
2492
-
2493
- 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; }
2494
- 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; }
2495
- const Instructions = () => {
2496
- const intl = reactIntl.useIntl();
2497
- const _useImportResourcesCo = useImportResourcesContext(),
2498
- state = _useImportResourcesCo.state;
2499
- const templateLink = RESOURCE_TYPE_TEMPLATE_DOWNLOAD_LINKS[state.resourceType];
2500
- const documentationLink = RESOURCE_TYPE_DOCUMENTATION_LINKS[state.resourceType];
2501
- return jsxRuntime.jsx(uiKit.Text.Body, {
2502
- intlMessage: _objectSpread$3(_objectSpread$3({}, messages$1.fileUploadInstructions), {}, {
2503
- values: {
2504
- fileSize: intl.formatNumber(FILE_SIZE_LIMITS_MB[state.resourceType]),
2505
- rowLimit: intl.formatNumber(ROW_LIMITS[state.resourceType]),
2506
- csvTemplateLink: msg => jsxRuntime.jsx(uiKit.Link, {
2507
- tone: "secondary",
2508
- isExternal: true,
2509
- to: templateLink,
2510
- children: msg
2511
- }, "csvTemplateLink"),
2512
- documentationLink: msg => jsxRuntime.jsx(uiKit.Link, {
2513
- tone: "secondary",
2514
- isExternal: true,
2515
- to: documentationLink,
2516
- children: msg
2517
- }, "documentationLink")
2518
- }
2519
- })
2520
- });
2521
- };
2522
-
2523
- var messages = reactIntl.defineMessages({
2524
- prerequisitesOfImportingData: {
2525
- id: 'ImportResourcesModal.infoBox.prerequisitesOfImportingData',
2526
- description: 'A message to guide users to check the prerequisites of importing data',
2527
- defaultMessage: 'Prerequisites of importing data'
2528
- },
2529
- keysForEveryResource: {
2530
- id: 'ImportResourcesModal.infoBox.keysForEveryResource',
2531
- description: 'A message to guide users to provide keys for every resource they import',
2532
- defaultMessage: 'You must provide keys for every resource you import, including embedded resources such as Prices and Assets. Please consult with your admins to assign keys through <link>the HTTP API</link>.'
2533
- }
2534
- });
2535
-
2536
- 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; }
2537
- 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; }
2538
- const InfoBox = () => {
2539
- const _useImportResourcesCo = useImportResourcesContext(),
2540
- state = _useImportResourcesCo.state;
2541
- if (!state.resourceType) return null;
2542
- return jsxRuntime.jsx(uiKit.ContentNotification, {
2543
- type: "info",
2544
- children: jsxRuntime.jsx(uiKit.Spacings.Inset, {
2545
- scale: "xs",
2546
- children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
2547
- scale: "xs",
2548
- children: [jsxRuntime.jsx(uiKit.Text.Subheadline, {
2549
- as: "h4",
2550
- intlMessage: messages.prerequisitesOfImportingData
2551
- }), jsxRuntime.jsx(uiKit.Text.Body, {
2552
- intlMessage: _objectSpread$2(_objectSpread$2({}, messages.keysForEveryResource), {}, {
2553
- values: {
2554
- link: msg => jsxRuntime.jsx(uiKit.Link, {
2555
- tone: "secondary",
2556
- isExternal: true,
2557
- to: CT_API_DOCS_URL,
2558
- children: msg
2559
- }, "link")
2560
- }
2561
- })
2562
- })]
2563
- })
2564
- })
2565
- });
2566
- };
2567
-
2568
- 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; }
2569
- 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; }
2570
- const FileIcon = props => jsxRuntime.jsxs("svg", _objectSpread$1(_objectSpread$1({
2571
- width: "32",
2572
- height: "32",
2573
- viewBox: "0 0 32 32",
2574
- fill: "none",
2575
- xmlns: "http://www.w3.org/2000/svg"
2576
- }, props), {}, {
2577
- children: [jsxRuntime.jsx("mask", {
2578
- id: "mask0_17_6643",
2579
- style: {
2580
- maskType: 'alpha'
2581
- },
2582
- maskUnits: "userSpaceOnUse",
2583
- x: "0",
2584
- y: "0",
2585
- width: "32",
2586
- height: "32",
2587
- children: jsxRuntime.jsx("rect", {
2588
- width: "32",
2589
- height: "32",
2590
- fill: "#D9D9D9"
2591
- })
2592
- }), jsxRuntime.jsx("g", {
2593
- mask: "url(#mask0_17_6643)",
2594
- children: jsxRuntime.jsx("path", {
2595
- 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",
2596
- fill: "#B1ACFF"
2597
- })
2598
- })]
2599
- }));
2600
-
2601
- const getChunkImport = locale => {
2602
- const intlLocale = i18n.mapLocaleToIntlLocale(locale);
2603
- switch (intlLocale) {
2604
- case 'de':
2605
- return Promise.resolve().then(function () { return require('./de-3cd0305d.cjs.prod.js'); });
2606
- case 'es':
2607
- return Promise.resolve().then(function () { return require('./es-030fcde4.cjs.prod.js'); });
2608
- case 'fr-FR':
2609
- return Promise.resolve().then(function () { return require('./fr-FR-c66b401e.cjs.prod.js'); });
2610
- case 'ja':
2611
- return Promise.resolve().then(function () { return require('./ja-37632763.cjs.prod.js'); });
2612
- case 'pt-BR':
2613
- return Promise.resolve().then(function () { return require('./pt-BR-36893abd.cjs.prod.js'); });
2614
- default:
2615
- return Promise.resolve().then(function () { return require('./en-7d070d59.cjs.prod.js'); });
2616
- }
2617
- };
2618
- const loadMessages = async locale => {
2619
- try {
2620
- const chunkImport = await getChunkImport(locale);
2621
- return i18n.parseChunkImport(chunkImport);
2622
- } catch (error) {
2623
- // eslint-disable-next-line no-console
2624
- console.warn(`Something went wrong while loading the import-resources-modal messages for ${locale}`, error);
2625
- sentry.reportErrorToSentry(new Error(`Something went wrong while loading the import-resources-modal messages for ${locale}`), {
2626
- extra: error
2627
- });
2628
- return {};
2629
- }
2630
- };
2631
-
2632
- const useAsyncIntlMessages = (locale, loader) => {
2633
- const _useState = React.useState({
2634
- isLoading: true,
2635
- messages: undefined,
2636
- error: undefined
2637
- }),
2638
- _useState2 = _slicedToArray(_useState, 2),
2639
- state = _useState2[0],
2640
- setState = _useState2[1];
2641
- React.useEffect(() => {
2642
- let _isUnmounting = false;
2643
- async function load() {
2644
- try {
2645
- if (!_isUnmounting) {
2646
- const messages = await loader(locale);
2647
- setState({
2648
- isLoading: false,
2649
- messages
2650
- });
2651
- }
2652
- } catch (error) {
2653
- setState({
2654
- isLoading: false,
2655
- error
2656
- });
2657
- }
2658
- }
2659
- if (locale) load();
2660
- return () => {
2661
- _isUnmounting = true;
2662
- };
2663
- }, [locale, loader]);
2664
- return state;
2665
- };
2666
-
2667
- 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; }
2668
- function _objectSpread(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(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(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
2669
- const ImportResourcesModal = props => {
2670
- var _context;
2671
- const _useApplicationContex = applicationShellConnectors.useApplicationContext(context => ({
2672
- locale: context.user && context.user.locale
2673
- })),
2674
- locale = _useApplicationContex.locale;
2675
- const messages = useAsyncIntlMessages(locale, loadMessages);
2676
- if (!props.isOpen || messages.isLoading) return null;
2677
- if (!props.resourceTypes?.length) {
2678
- console.error('No resource types provided for import resources modal');
2679
- return null;
2680
- }
2681
- if (!_everyInstanceProperty__default["default"](_context = props.resourceTypes).call(_context, isResourceType)) {
2682
- console.error('Invalid resource types provided for import resources modal');
2683
- return null;
2684
- }
2685
- return jsxRuntime.jsx(reactIntl.IntlProvider, {
2686
- locale: locale,
2687
- messages: messages.messages,
2688
- children: jsxRuntime.jsx(ImportResourcesProvider, _objectSpread(_objectSpread({}, props), {}, {
2689
- children: jsxRuntime.jsx(CurrentStep, {})
2690
- }))
2691
- });
2692
- };
2693
- ImportResourcesModal.displayName = 'ImportResourcesModal';
2694
-
2695
- exports.EnabledDropArea = EnabledDropArea;
2696
- exports.FileDropped = FileDropped;
2697
- exports.FileIcon = FileIcon;
2698
- exports.ImportResourcesModal = ImportResourcesModal;
2699
- exports.messages = messages$8;
2700
- exports.useImportPermission = useImportPermission;
2701
- exports.useImportResourcesContext = useImportResourcesContext;