@commercetools-frontend-extensions/export-resources-modal 3.4.3-next.1 → 3.5.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.dev.js +131 -264
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.prod.js +129 -262
- package/dist/commercetools-frontend-extensions-export-resources-modal.esm.js +129 -259
- package/package.json +17 -17
|
@@ -30,18 +30,14 @@ var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWit
|
|
|
30
30
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
31
31
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
32
32
|
var moment = require('moment');
|
|
33
|
-
var
|
|
34
|
-
var
|
|
33
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
34
|
+
var omitEmpty = require('omit-empty-es');
|
|
35
35
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
36
|
-
var
|
|
37
|
-
var _Object$assign = require('@babel/runtime-corejs3/core-js-stable/object/assign');
|
|
36
|
+
var _flatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat');
|
|
38
37
|
var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
|
|
39
38
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
40
|
-
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
41
|
-
var omitEmpty = require('omit-empty-es');
|
|
42
|
-
var _findIndexInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find-index');
|
|
43
|
-
var _spliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/splice');
|
|
44
39
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
40
|
+
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
45
41
|
var sdk = require('@commercetools-frontend/sdk');
|
|
46
42
|
var actionsGlobal = require('@commercetools-frontend/actions-global');
|
|
47
43
|
var constants = require('@commercetools-frontend/constants');
|
|
@@ -68,17 +64,14 @@ var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construc
|
|
|
68
64
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
69
65
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
70
66
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
71
|
-
var
|
|
67
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
68
|
+
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
72
69
|
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
73
|
-
var
|
|
74
|
-
var _Object$assign__default = /*#__PURE__*/_interopDefault(_Object$assign);
|
|
70
|
+
var _flatInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatInstanceProperty);
|
|
75
71
|
var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
|
|
76
72
|
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
77
|
-
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
78
|
-
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
79
|
-
var _findIndexInstanceProperty__default = /*#__PURE__*/_interopDefault(_findIndexInstanceProperty);
|
|
80
|
-
var _spliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_spliceInstanceProperty);
|
|
81
73
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
74
|
+
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
82
75
|
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
83
76
|
var _everyInstanceProperty__default = /*#__PURE__*/_interopDefault(_everyInstanceProperty);
|
|
84
77
|
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
@@ -230,6 +223,11 @@ var messages = reactIntl.defineMessages({
|
|
|
230
223
|
id: 'ExportResourcesModal.customTypeKeyAndTypeId',
|
|
231
224
|
description: 'Label for "Custom type key and typeId" checkbox',
|
|
232
225
|
defaultMessage: 'Custom type key and typeId'
|
|
226
|
+
},
|
|
227
|
+
unexpectedError: {
|
|
228
|
+
id: 'ExportResourcesModal.unexpectedError',
|
|
229
|
+
description: 'Generic notification message when starting export process fails',
|
|
230
|
+
defaultMessage: 'An error occurred while starting the export process. Please try again or contact support if the problem persists.'
|
|
233
231
|
}
|
|
234
232
|
});
|
|
235
233
|
|
|
@@ -290,11 +288,11 @@ const FIELD_DEFINITIONS_URLS = {
|
|
|
290
288
|
category: 'https://docs.commercetools.com/merchant-center/import-categories#supported-headers-and-values'
|
|
291
289
|
};
|
|
292
290
|
|
|
293
|
-
function _createSuper$
|
|
294
|
-
function _isNativeReflectConstruct$
|
|
291
|
+
function _createSuper$4(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$4(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
292
|
+
function _isNativeReflectConstruct$4() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
295
293
|
let UnexpectedExportTypeError = /*#__PURE__*/function (_Error) {
|
|
296
294
|
_inherits(UnexpectedExportTypeError, _Error);
|
|
297
|
-
var _super = _createSuper$
|
|
295
|
+
var _super = _createSuper$4(UnexpectedExportTypeError);
|
|
298
296
|
function UnexpectedExportTypeError(exportType) {
|
|
299
297
|
var _this;
|
|
300
298
|
_classCallCheck(this, UnexpectedExportTypeError);
|
|
@@ -305,11 +303,11 @@ let UnexpectedExportTypeError = /*#__PURE__*/function (_Error) {
|
|
|
305
303
|
return _createClass(UnexpectedExportTypeError);
|
|
306
304
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
307
305
|
|
|
308
|
-
function _createSuper$
|
|
309
|
-
function _isNativeReflectConstruct$
|
|
306
|
+
function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
307
|
+
function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
310
308
|
let MissingExportResourceProviderError = /*#__PURE__*/function (_Error) {
|
|
311
309
|
_inherits(MissingExportResourceProviderError, _Error);
|
|
312
|
-
var _super = _createSuper$
|
|
310
|
+
var _super = _createSuper$3(MissingExportResourceProviderError);
|
|
313
311
|
function MissingExportResourceProviderError() {
|
|
314
312
|
var _this;
|
|
315
313
|
_classCallCheck(this, MissingExportResourceProviderError);
|
|
@@ -320,11 +318,11 @@ let MissingExportResourceProviderError = /*#__PURE__*/function (_Error) {
|
|
|
320
318
|
return _createClass(MissingExportResourceProviderError);
|
|
321
319
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
322
320
|
|
|
323
|
-
function _createSuper$
|
|
324
|
-
function _isNativeReflectConstruct$
|
|
321
|
+
function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
322
|
+
function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
325
323
|
let UnexpectedExportOperationStateError = /*#__PURE__*/function (_Error) {
|
|
326
324
|
_inherits(UnexpectedExportOperationStateError, _Error);
|
|
327
|
-
var _super = _createSuper$
|
|
325
|
+
var _super = _createSuper$2(UnexpectedExportOperationStateError);
|
|
328
326
|
function UnexpectedExportOperationStateError(state) {
|
|
329
327
|
var _this;
|
|
330
328
|
_classCallCheck(this, UnexpectedExportOperationStateError);
|
|
@@ -335,11 +333,11 @@ let UnexpectedExportOperationStateError = /*#__PURE__*/function (_Error) {
|
|
|
335
333
|
return _createClass(UnexpectedExportOperationStateError);
|
|
336
334
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
337
335
|
|
|
338
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
339
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
336
|
+
function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
337
|
+
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
340
338
|
let UnexpectedResourceTypeError = /*#__PURE__*/function (_Error) {
|
|
341
339
|
_inherits(UnexpectedResourceTypeError, _Error);
|
|
342
|
-
var _super = _createSuper(UnexpectedResourceTypeError);
|
|
340
|
+
var _super = _createSuper$1(UnexpectedResourceTypeError);
|
|
343
341
|
function UnexpectedResourceTypeError(resourceType) {
|
|
344
342
|
var _this;
|
|
345
343
|
_classCallCheck(this, UnexpectedResourceTypeError);
|
|
@@ -350,6 +348,21 @@ let UnexpectedResourceTypeError = /*#__PURE__*/function (_Error) {
|
|
|
350
348
|
return _createClass(UnexpectedResourceTypeError);
|
|
351
349
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
352
350
|
|
|
351
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
352
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
353
|
+
let InvalidResponseError = /*#__PURE__*/function (_Error) {
|
|
354
|
+
_inherits(InvalidResponseError, _Error);
|
|
355
|
+
var _super = _createSuper(InvalidResponseError);
|
|
356
|
+
function InvalidResponseError(message) {
|
|
357
|
+
var _this;
|
|
358
|
+
_classCallCheck(this, InvalidResponseError);
|
|
359
|
+
_this = _super.call(this, message);
|
|
360
|
+
_this.name = 'InvalidResponseError';
|
|
361
|
+
return _this;
|
|
362
|
+
}
|
|
363
|
+
return _createClass(InvalidResponseError);
|
|
364
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
365
|
+
|
|
353
366
|
function useExportResourcesContext() {
|
|
354
367
|
const context = React.useContext(ExportResourcesContext);
|
|
355
368
|
if (!context) {
|
|
@@ -358,7 +371,39 @@ function useExportResourcesContext() {
|
|
|
358
371
|
return context;
|
|
359
372
|
}
|
|
360
373
|
|
|
361
|
-
|
|
374
|
+
function validate(_ref) {
|
|
375
|
+
let values = _valuesInstanceProperty__default["default"](_ref),
|
|
376
|
+
step = _ref.step;
|
|
377
|
+
const fileName = values.fileName,
|
|
378
|
+
locales = values.locales,
|
|
379
|
+
fields = values.fields,
|
|
380
|
+
customFields = values.customFields;
|
|
381
|
+
const errors = {
|
|
382
|
+
fileName: {},
|
|
383
|
+
locales: {},
|
|
384
|
+
fields: {}
|
|
385
|
+
};
|
|
386
|
+
if (uiKit.TextInput.isEmpty(fileName)) {
|
|
387
|
+
errors.fileName.missing = true;
|
|
388
|
+
} else if (!/^[a-zA-Z0-9-_.]+$/.test(fileName)) {
|
|
389
|
+
errors.fileName.invalidInput = true;
|
|
390
|
+
}
|
|
391
|
+
if (locales.length < 1) {
|
|
392
|
+
errors.locales.missing = true;
|
|
393
|
+
}
|
|
394
|
+
if (step === 2) {
|
|
395
|
+
const checkedGeneralFieldsCount = _filterInstanceProperty__default["default"](fields).call(fields, field => field.isChecked).length;
|
|
396
|
+
const checkedCustomFieldsCount = _reduceInstanceProperty__default["default"](customFields).call(customFields, (count, customType) => {
|
|
397
|
+
var _context;
|
|
398
|
+
return count + _filterInstanceProperty__default["default"](_context = customType.fields).call(_context, field => field.isChecked).length;
|
|
399
|
+
}, 0);
|
|
400
|
+
if (checkedGeneralFieldsCount + checkedCustomFieldsCount < 2) {
|
|
401
|
+
errors.fields.missing = true;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return omitEmpty__default["default"](errors);
|
|
405
|
+
}
|
|
406
|
+
|
|
362
407
|
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; }
|
|
363
408
|
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var _context7, _context8; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context7 = ownKeys$4(Object(t), !0)).call(_context7, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context8 = ownKeys$4(Object(t))).call(_context8, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
364
409
|
function resourceTypeToDisplayName(_ref) {
|
|
@@ -383,27 +428,12 @@ function resourceTypeToDisplayName(_ref) {
|
|
|
383
428
|
}
|
|
384
429
|
return isUpperCase ? displayName : displayName.toLowerCase();
|
|
385
430
|
}
|
|
386
|
-
function resourceTypeToOperationName(resourceType) {
|
|
387
|
-
switch (resourceType) {
|
|
388
|
-
case EXPORTABLE_RESOURCES.CATEGORY:
|
|
389
|
-
return 'categories';
|
|
390
|
-
case EXPORTABLE_RESOURCES.PRODUCT:
|
|
391
|
-
return 'products';
|
|
392
|
-
case EXPORTABLE_RESOURCES.DISCOUNT_CODE:
|
|
393
|
-
return 'discountCodes';
|
|
394
|
-
default:
|
|
395
|
-
throw UnexpectedResourceTypeError(resourceType);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
431
|
function mapLocalesToOptions(locales) {
|
|
399
432
|
return _mapInstanceProperty__default["default"](locales).call(locales, locale => ({
|
|
400
433
|
value: locale,
|
|
401
434
|
label: locale
|
|
402
435
|
}));
|
|
403
436
|
}
|
|
404
|
-
function replaceSpecialCharsWithUnderscore(string) {
|
|
405
|
-
return string.replace(/[^a-zA-Z0-9]/g, '_');
|
|
406
|
-
}
|
|
407
437
|
function isFilledArray(maybeArray) {
|
|
408
438
|
return _Array$isArray__default["default"](maybeArray) && maybeArray.length;
|
|
409
439
|
}
|
|
@@ -428,31 +458,6 @@ function flattenNestedFields(fields) {
|
|
|
428
458
|
})) || [];
|
|
429
459
|
return _flatInstanceProperty__default["default"](result).call(result);
|
|
430
460
|
}
|
|
431
|
-
function unflattenNestedFields(flattenedFields) {
|
|
432
|
-
const reconstructed = [];
|
|
433
|
-
_forEachInstanceProperty__default["default"](flattenedFields).call(flattenedFields, field => {
|
|
434
|
-
const fieldNames = field.name.split('.');
|
|
435
|
-
let currentLevel = reconstructed;
|
|
436
|
-
_forEachInstanceProperty__default["default"](fieldNames).call(fieldNames, (name, index) => {
|
|
437
|
-
let existingField = _findInstanceProperty__default["default"](currentLevel).call(currentLevel, f => f.name === name);
|
|
438
|
-
if (!existingField) {
|
|
439
|
-
existingField = {
|
|
440
|
-
name,
|
|
441
|
-
fields: []
|
|
442
|
-
};
|
|
443
|
-
currentLevel.push(existingField);
|
|
444
|
-
}
|
|
445
|
-
if (index === fieldNames.length - 1) {
|
|
446
|
-
field.name;
|
|
447
|
-
const otherProps = _objectWithoutProperties(field, _excluded$1);
|
|
448
|
-
_Object$assign__default["default"](existingField, otherProps);
|
|
449
|
-
} else {
|
|
450
|
-
currentLevel = existingField.fields;
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
return reconstructed;
|
|
455
|
-
}
|
|
456
461
|
function getSelectedGeneralFields(fields) {
|
|
457
462
|
return _filterInstanceProperty__default["default"](fields).call(fields, field => field.isChecked);
|
|
458
463
|
}
|
|
@@ -464,9 +469,6 @@ function getSelectedCustomFields(customFields) {
|
|
|
464
469
|
});
|
|
465
470
|
});
|
|
466
471
|
}
|
|
467
|
-
function flattenCustomFields(customFields) {
|
|
468
|
-
return _flatMapInstanceProperty__default["default"](customFields).call(customFields, customType => customType.fields);
|
|
469
|
-
}
|
|
470
472
|
function checkRequiredFields(fields) {
|
|
471
473
|
return _mapInstanceProperty__default["default"](fields).call(fields, field => field.isRequired ? _objectSpread$4(_objectSpread$4({}, field), {}, {
|
|
472
474
|
isChecked: true
|
|
@@ -488,175 +490,49 @@ function setInitialCheckedStateForCustomFields(customFields) {
|
|
|
488
490
|
});
|
|
489
491
|
});
|
|
490
492
|
}
|
|
491
|
-
function
|
|
493
|
+
function extractGeneralFieldNames(generalFields) {
|
|
492
494
|
return _mapInstanceProperty__default["default"](generalFields).call(generalFields, field => field.name);
|
|
493
495
|
}
|
|
494
|
-
function
|
|
495
|
-
const
|
|
496
|
+
function extractCustomFieldNamesWithPrefix(customFields) {
|
|
497
|
+
const fields = _flatMapInstanceProperty__default["default"](customFields).call(customFields, customType => {
|
|
496
498
|
var _context6;
|
|
497
499
|
return _mapInstanceProperty__default["default"](_context6 = customType.fields).call(_context6, field => "custom.fields.".concat(field.name));
|
|
498
500
|
});
|
|
499
|
-
return [...new _Set__default["default"](
|
|
501
|
+
return [...new _Set__default["default"](fields)];
|
|
500
502
|
}
|
|
501
503
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
function buildGraphQLQuery(exportSettings) {
|
|
511
|
-
var _context;
|
|
512
|
-
const operation = resourceTypeToOperationName(exportSettings.resourceType);
|
|
513
|
-
const generalFields = buildGeneralFieldsForGraphQLQuery({
|
|
514
|
-
fields: exportSettings.fields,
|
|
515
|
-
locales: exportSettings.locales
|
|
516
|
-
});
|
|
517
|
-
const results = [...generalFields];
|
|
518
|
-
if (exportSettings.customFields && exportSettings.customFields.length > 0) {
|
|
519
|
-
const customFields = buildCustomFieldsForGraphQLQuery({
|
|
520
|
-
customFields: exportSettings.customFields
|
|
521
|
-
});
|
|
522
|
-
results.push({
|
|
523
|
-
custom: customFields
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
switch (exportSettings.exportType) {
|
|
527
|
-
case EXPORT_TYPES.ALL:
|
|
528
|
-
return gqlQueryBuilder.query({
|
|
529
|
-
operation,
|
|
530
|
-
fields: [{
|
|
531
|
-
results
|
|
532
|
-
}],
|
|
533
|
-
variables: {}
|
|
534
|
-
});
|
|
535
|
-
case EXPORT_TYPES.SELECTED:
|
|
536
|
-
return gqlQueryBuilder.query({
|
|
537
|
-
operation,
|
|
538
|
-
fields: [{
|
|
539
|
-
results
|
|
540
|
-
}],
|
|
541
|
-
variables: {
|
|
542
|
-
where: "id in (".concat(_mapInstanceProperty__default["default"](_context = exportSettings.selectedResourceIds).call(_context, id => "\"".concat(id, "\"")).join(', '), ")")
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
case EXPORT_TYPES.FILTERED:
|
|
546
|
-
// TODO: gql query for exporting filtered resources.
|
|
547
|
-
throw new UnexpectedExportTypeError(exportSettings.exportType);
|
|
548
|
-
default:
|
|
549
|
-
throw new UnexpectedExportTypeError(exportSettings.exportType);
|
|
550
|
-
}
|
|
504
|
+
// TODO: remove this function when filters are passed directly from parent views
|
|
505
|
+
// This function is temporary and will be removed in the future
|
|
506
|
+
// Later, filters will be passed directly from parent views (category, product...) instead of being built within the Export resources modal
|
|
507
|
+
// The `selectedResourceIds` prop will also be removed
|
|
508
|
+
function tmpBuildFilters(selectedResourceIds) {
|
|
509
|
+
if (!selectedResourceIds || (selectedResourceIds === null || selectedResourceIds === void 0 ? void 0 : selectedResourceIds.length) === 0) return undefined;
|
|
510
|
+
const formattedIds = _mapInstanceProperty__default["default"](selectedResourceIds).call(selectedResourceIds, id => "\"".concat(id, "\"")).join(', ');
|
|
511
|
+
return ["id in (".concat(formattedIds, ")")];
|
|
551
512
|
}
|
|
552
513
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
* This format combines the field and the locale, separated by '______'. This approach is adopted as our system disallows the use of hyphens `-` in these situations
|
|
558
|
-
*
|
|
559
|
-
* Fields that don't vary by locale but contain additional subfields (known as 'nested fields') are also addressed
|
|
560
|
-
* In these cases the function is used recursively on these subfields to generate the appropriate request.
|
|
561
|
-
*
|
|
562
|
-
* Overall, this function enables us to accurately request different types of data, including those varying by locale or containing subfields.
|
|
563
|
-
*
|
|
564
|
-
* More details can be found in the related PR: https://github.com/commercetools/commercetools-exporter/pull/103
|
|
565
|
-
*/
|
|
566
|
-
|
|
567
|
-
function buildGeneralFieldsForGraphQLQuery(_ref) {
|
|
568
|
-
var _context2;
|
|
569
|
-
let fields = _ref.fields,
|
|
570
|
-
locales = _ref.locales;
|
|
571
|
-
return _flatInstanceProperty__default["default"](_context2 = _mapInstanceProperty__default["default"](fields).call(fields, field => {
|
|
572
|
-
if (field.isLocalized) return _mapInstanceProperty__default["default"](locales).call(locales, locale => {
|
|
573
|
-
var _context3, _context4, _context5;
|
|
574
|
-
const alias = replaceSpecialCharsWithUnderscore(_concatInstanceProperty__default["default"](_context3 = "".concat(field.name, "______")).call(_context3, locale));
|
|
575
|
-
return _concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "".concat(alias, ": ")).call(_context5, field.name, "(locale: \"")).call(_context4, locale, "\")");
|
|
576
|
-
});else {
|
|
577
|
-
if (isFilledArray(field.fields)) {
|
|
578
|
-
return {
|
|
579
|
-
[field.name]: buildGeneralFieldsForGraphQLQuery({
|
|
580
|
-
fields: field.fields,
|
|
581
|
-
locales
|
|
582
|
-
})
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
return field.name;
|
|
586
|
-
}
|
|
587
|
-
})).call(_context2);
|
|
588
|
-
}
|
|
589
|
-
function buildCustomFieldsForGraphQLQuery(_ref2) {
|
|
590
|
-
_ref2.customFields;
|
|
591
|
-
// const customFieldNames = customFields.map((customField) => customField.name)
|
|
592
|
-
return [{
|
|
593
|
-
type: ['key']
|
|
594
|
-
}, {
|
|
595
|
-
operation: 'customFieldsRaw',
|
|
596
|
-
fields: ['name', 'value'],
|
|
597
|
-
// TODO: Add custom fields filter to the variables when they are supported on the Export API side
|
|
598
|
-
variables: {
|
|
599
|
-
// includeNames: customFieldNames,
|
|
514
|
+
const categoryFieldExtension = fields => {
|
|
515
|
+
return _reduceInstanceProperty__default["default"](fields).call(fields, (acc, field) => {
|
|
516
|
+
if (field === 'parent.key') {
|
|
517
|
+
return [...acc, field, 'parent.typeId'];
|
|
600
518
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
function validate(_ref) {
|
|
605
|
-
let values = _valuesInstanceProperty__default["default"](_ref),
|
|
606
|
-
step = _ref.step;
|
|
607
|
-
const fileName = values.fileName,
|
|
608
|
-
locales = values.locales,
|
|
609
|
-
fields = values.fields,
|
|
610
|
-
customFields = values.customFields;
|
|
611
|
-
const errors = {
|
|
612
|
-
fileName: {},
|
|
613
|
-
locales: {},
|
|
614
|
-
fields: {}
|
|
615
|
-
};
|
|
616
|
-
if (uiKit.TextInput.isEmpty(fileName)) {
|
|
617
|
-
errors.fileName.missing = true;
|
|
618
|
-
} else if (!/^[a-zA-Z0-9-_.]+$/.test(fileName)) {
|
|
619
|
-
errors.fileName.invalidInput = true;
|
|
620
|
-
}
|
|
621
|
-
if (locales.length < 1) {
|
|
622
|
-
errors.locales.missing = true;
|
|
623
|
-
}
|
|
624
|
-
if (step === 2) {
|
|
625
|
-
const checkedGeneralFieldsCount = _filterInstanceProperty__default["default"](fields).call(fields, field => field.isChecked).length;
|
|
626
|
-
const checkedCustomFieldsCount = _reduceInstanceProperty__default["default"](customFields).call(customFields, (count, customType) => {
|
|
627
|
-
var _context;
|
|
628
|
-
return count + _filterInstanceProperty__default["default"](_context = customType.fields).call(_context, field => field.isChecked).length;
|
|
629
|
-
}, 0);
|
|
630
|
-
if (checkedGeneralFieldsCount + checkedCustomFieldsCount < 2) {
|
|
631
|
-
errors.fields.missing = true;
|
|
519
|
+
if (_startsWithInstanceProperty__default["default"](field).call(field, 'custom.fields.') && !_includesInstanceProperty__default["default"](acc).call(acc, 'custom.type.key')) {
|
|
520
|
+
return [...acc, 'custom.type.key', 'custom.type.typeId', field];
|
|
632
521
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
const categoryColumnExtension = columns => {
|
|
638
|
-
const extendedColumns = [...columns];
|
|
639
|
-
const parentKeyIndex = _findIndexInstanceProperty__default["default"](columns).call(columns, column => column === 'parent.key');
|
|
640
|
-
if (parentKeyIndex !== -1) {
|
|
641
|
-
_spliceInstanceProperty__default["default"](extendedColumns).call(extendedColumns, parentKeyIndex + 1, 0, 'parent.typeId');
|
|
642
|
-
}
|
|
643
|
-
const firstCustomFieldIndex = _findIndexInstanceProperty__default["default"](extendedColumns).call(extendedColumns, column => _startsWithInstanceProperty__default["default"](column).call(column, 'custom.fields.'));
|
|
644
|
-
if (firstCustomFieldIndex !== -1) {
|
|
645
|
-
_spliceInstanceProperty__default["default"](extendedColumns).call(extendedColumns, firstCustomFieldIndex, 0, 'custom.type.key', 'custom.type.typeId');
|
|
646
|
-
}
|
|
647
|
-
return extendedColumns;
|
|
522
|
+
return [...acc, field];
|
|
523
|
+
}, []);
|
|
648
524
|
};
|
|
649
|
-
const
|
|
650
|
-
const
|
|
651
|
-
default:
|
|
652
|
-
category:
|
|
525
|
+
const defaultFieldExtension = fields => fields;
|
|
526
|
+
const fieldExtensionByResourceType = {
|
|
527
|
+
default: defaultFieldExtension,
|
|
528
|
+
category: categoryFieldExtension
|
|
653
529
|
};
|
|
654
530
|
|
|
655
|
-
const
|
|
531
|
+
const extendFields = _ref => {
|
|
656
532
|
let resourceType = _ref.resourceType,
|
|
657
|
-
|
|
658
|
-
const extensionFunction =
|
|
659
|
-
return extensionFunction(
|
|
533
|
+
fields = _ref.fields;
|
|
534
|
+
const extensionFunction = fieldExtensionByResourceType[resourceType] || fieldExtensionByResourceType.default;
|
|
535
|
+
return extensionFunction(fields);
|
|
660
536
|
};
|
|
661
537
|
|
|
662
538
|
const _excluded = ["isSelectedByDefault"];
|
|
@@ -693,12 +569,13 @@ const useInitialValues = props => {
|
|
|
693
569
|
};
|
|
694
570
|
|
|
695
571
|
async function createExportOperation(_ref) {
|
|
696
|
-
let
|
|
572
|
+
let projectKey = _ref.projectKey,
|
|
573
|
+
resourceType = _ref.resourceType,
|
|
574
|
+
fileName = _ref.fileName,
|
|
697
575
|
fileFormat = _ref.fileFormat,
|
|
698
|
-
|
|
576
|
+
fields = _ref.fields,
|
|
699
577
|
locales = _ref.locales,
|
|
700
|
-
|
|
701
|
-
graphQuery = _ref.graphQuery,
|
|
578
|
+
filters = _ref.filters,
|
|
702
579
|
asyncDispatchFn = _ref.asyncDispatchFn;
|
|
703
580
|
const uri = "/proxy/export/".concat(projectKey, "/export-operations");
|
|
704
581
|
const response = await asyncDispatchFn(sdk.actions.post({
|
|
@@ -709,13 +586,15 @@ async function createExportOperation(_ref) {
|
|
|
709
586
|
accept: 'application/json'
|
|
710
587
|
},
|
|
711
588
|
payload: {
|
|
589
|
+
resourceType,
|
|
712
590
|
fileName,
|
|
713
591
|
fileFormat,
|
|
714
|
-
|
|
592
|
+
fields,
|
|
715
593
|
locales,
|
|
716
|
-
|
|
594
|
+
filters
|
|
717
595
|
}
|
|
718
596
|
}));
|
|
597
|
+
if (!response.state) throw new InvalidResponseError('Invalid response');
|
|
719
598
|
return response;
|
|
720
599
|
}
|
|
721
600
|
|
|
@@ -735,26 +614,20 @@ const useStartExportOperation = props => {
|
|
|
735
614
|
try {
|
|
736
615
|
const selectedGeneralFields = getSelectedGeneralFields(values.fields);
|
|
737
616
|
const selectedCustomFields = getSelectedCustomFields(values.customFields);
|
|
738
|
-
const
|
|
739
|
-
const
|
|
740
|
-
const
|
|
741
|
-
resourceType: props.resourceType,
|
|
742
|
-
exportType: props.exportType,
|
|
743
|
-
selectedResourceIds: props.selectedResourceIds,
|
|
744
|
-
fields: unflattenNestedFields(selectedGeneralFields),
|
|
745
|
-
customFields: flattenCustomFields(selectedCustomFields),
|
|
746
|
-
locales: values.locales
|
|
747
|
-
});
|
|
617
|
+
const generalFields = extractGeneralFieldNames(selectedGeneralFields);
|
|
618
|
+
const customFields = extractCustomFieldNamesWithPrefix(selectedCustomFields);
|
|
619
|
+
const filters = tmpBuildFilters(props.selectedResourceIds);
|
|
748
620
|
const response = await createExportOperation({
|
|
621
|
+
projectKey,
|
|
622
|
+
resourceType: props.resourceType,
|
|
749
623
|
fileName: appendCsvOrJsonExtensionIfAbsent(values.fileName, values.outputFormat),
|
|
750
624
|
fileFormat: values.outputFormat,
|
|
751
625
|
locales: values.locales,
|
|
752
|
-
|
|
626
|
+
fields: extendFields({
|
|
753
627
|
resourceType: props.resourceType,
|
|
754
|
-
|
|
628
|
+
fields: [...generalFields, ...customFields]
|
|
755
629
|
}),
|
|
756
|
-
|
|
757
|
-
graphQuery,
|
|
630
|
+
filters,
|
|
758
631
|
asyncDispatchFn: asyncDispatch
|
|
759
632
|
});
|
|
760
633
|
switch (response.state) {
|
|
@@ -776,10 +649,12 @@ const useStartExportOperation = props => {
|
|
|
776
649
|
default:
|
|
777
650
|
throw new UnexpectedExportOperationStateError(response.state);
|
|
778
651
|
}
|
|
779
|
-
} catch (
|
|
652
|
+
} catch (error) {
|
|
780
653
|
// TODO: custom error messages for each error type
|
|
781
|
-
|
|
782
|
-
|
|
654
|
+
showNotification({
|
|
655
|
+
text: intl.formatMessage(messages.unexpectedError),
|
|
656
|
+
kind: 'error',
|
|
657
|
+
domain: constants.DOMAINS.PAGE
|
|
783
658
|
});
|
|
784
659
|
} finally {
|
|
785
660
|
if (typeof props.onClose === 'function') props.onClose();
|
|
@@ -1010,9 +885,7 @@ const ExportFieldsSelectionStep = () => {
|
|
|
1010
885
|
isChecked: field.isRequired ? true : e.target.checked
|
|
1011
886
|
})));
|
|
1012
887
|
},
|
|
1013
|
-
children: jsxRuntime.jsx(
|
|
1014
|
-
intlMessage: messages.allGeneralFields
|
|
1015
|
-
})
|
|
888
|
+
children: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$1({}, messages.allGeneralFields))
|
|
1016
889
|
})
|
|
1017
890
|
})
|
|
1018
891
|
}), jsxRuntime.jsx(uiKit.Grid.Item, {
|
|
@@ -1045,9 +918,7 @@ const ExportFieldsSelectionStep = () => {
|
|
|
1045
918
|
});
|
|
1046
919
|
}));
|
|
1047
920
|
},
|
|
1048
|
-
children: jsxRuntime.jsx(
|
|
1049
|
-
intlMessage: messages.allCustomFields
|
|
1050
|
-
})
|
|
921
|
+
children: jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$1({}, messages.allCustomFields))
|
|
1051
922
|
})
|
|
1052
923
|
})
|
|
1053
924
|
}), jsxRuntime.jsx(uiKit.Grid.Item, {
|
|
@@ -1055,13 +926,11 @@ const ExportFieldsSelectionStep = () => {
|
|
|
1055
926
|
insetScale: "l",
|
|
1056
927
|
children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
1057
928
|
scale: "s",
|
|
1058
|
-
children: [jsxRuntime.
|
|
929
|
+
children: [jsxRuntime.jsxs(uiKit.CheckboxInput, {
|
|
1059
930
|
isReadOnly: true,
|
|
1060
931
|
onChange: () => {},
|
|
1061
932
|
isChecked: isAtLeastOneCustomFieldChecked,
|
|
1062
|
-
children: jsxRuntime.
|
|
1063
|
-
children: [intl.formatMessage(messages.customTypeKeyAndTypeId), ' ', "*"]
|
|
1064
|
-
})
|
|
933
|
+
children: [jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$1({}, messages.customTypeKeyAndTypeId)), ' ', "*"]
|
|
1065
934
|
}), jsxRuntime.jsx(CustomFieldsSelection, {
|
|
1066
935
|
customFields: _valuesInstanceProperty__default["default"](formik).customFields,
|
|
1067
936
|
setFieldValue: formik.setFieldValue
|
|
@@ -1078,7 +947,7 @@ const ExportFieldsSelectionStep = () => {
|
|
|
1078
947
|
const GeneralFieldsSelection = _ref5 => {
|
|
1079
948
|
let fields = _ref5.fields,
|
|
1080
949
|
setFieldValue = _ref5.setFieldValue;
|
|
1081
|
-
return _mapInstanceProperty__default["default"](fields).call(fields, field => jsxRuntime.
|
|
950
|
+
return _mapInstanceProperty__default["default"](fields).call(fields, field => jsxRuntime.jsxs(uiKit.CheckboxInput, {
|
|
1082
951
|
isChecked: field.isChecked,
|
|
1083
952
|
isReadOnly: field.isRequired,
|
|
1084
953
|
onChange: e => {
|
|
@@ -1086,9 +955,7 @@ const GeneralFieldsSelection = _ref5 => {
|
|
|
1086
955
|
isChecked: e.target.checked
|
|
1087
956
|
}) : _field));
|
|
1088
957
|
},
|
|
1089
|
-
children:
|
|
1090
|
-
children: [field.label, " ", field.isRequired && '*']
|
|
1091
|
-
})
|
|
958
|
+
children: [field.label, " ", field.isRequired && '*']
|
|
1092
959
|
}, field.name));
|
|
1093
960
|
};
|
|
1094
961
|
const CustomFieldsSelection = _ref6 => {
|