@commercetools-frontend-extensions/export-resources-modal 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -31,11 +31,17 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
31
31
|
resourceType="category"
|
|
32
32
|
allResourcesCount={143}
|
|
33
33
|
exportSelectionType="allResources"
|
|
34
|
-
|
|
34
|
+
fields={[
|
|
35
35
|
{ key: 'externalId' },
|
|
36
36
|
{ key: 'createdAt' },
|
|
37
37
|
{ key: 'lastModifiedAt' },
|
|
38
38
|
{ key: 'name', isLocalized: true },
|
|
39
|
+
{ key: 'parent', fields: [
|
|
40
|
+
{
|
|
41
|
+
key: 'name',
|
|
42
|
+
isLocalized: true
|
|
43
|
+
}
|
|
44
|
+
]},
|
|
39
45
|
]}
|
|
40
46
|
renderProperties={()=>(
|
|
41
47
|
<>
|
|
@@ -54,11 +60,17 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
54
60
|
resourceType="category"
|
|
55
61
|
allResourcesCount={143}
|
|
56
62
|
exportSelectionType="onlyMatching"
|
|
57
|
-
|
|
63
|
+
fields={[
|
|
58
64
|
{ key: 'externalId' },
|
|
59
65
|
{ key: 'createdAt' },
|
|
60
66
|
{ key: 'lastModifiedAt' },
|
|
61
67
|
{ key: 'name', isLocalized: true },
|
|
68
|
+
{ key: 'parent', fields: [
|
|
69
|
+
{
|
|
70
|
+
key: 'name',
|
|
71
|
+
isLocalized: true
|
|
72
|
+
}
|
|
73
|
+
]},
|
|
62
74
|
]}
|
|
63
75
|
appliedFilters={
|
|
64
76
|
[
|
|
@@ -86,11 +98,17 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
86
98
|
allResourcesCount={143}
|
|
87
99
|
exportSelectionType="onlySelected"
|
|
88
100
|
selectedResourceIds={['02ed9a7d-7c1f-40da-b2b7-4cca6752bf29', '04051276-1641-4e01-a03e-d4de16b7e4eb', 'ac7d9f7b-5c7d-4dd3-b82b-8555ab4a2a6e']}
|
|
89
|
-
|
|
101
|
+
fields={[
|
|
90
102
|
{ key: 'externalId' },
|
|
91
103
|
{ key: 'createdAt' },
|
|
92
104
|
{ key: 'lastModifiedAt' },
|
|
93
105
|
{ key: 'name', isLocalized: true },
|
|
106
|
+
{ key: 'parent', fields: [
|
|
107
|
+
{
|
|
108
|
+
key: 'name',
|
|
109
|
+
isLocalized: true
|
|
110
|
+
}
|
|
111
|
+
]},
|
|
94
112
|
]}
|
|
95
113
|
renderProperties={()=>(
|
|
96
114
|
<>
|
|
@@ -115,9 +133,10 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
115
133
|
| `exportSelectionType` | `string` <br/>Possible values:<br/>`allResources, onlyMatching, onlySelected` | | `allResources` | The type of export, so either export all resources or export only resources that match the filters & search or export only selected resources |
|
|
116
134
|
| `matchingResourcesCount` | `Number` | ✅ Required only if `exportSelectionType` is `onlyMatching` | | The count of resources that matches the filters & search |
|
|
117
135
|
| `selectedResourceIds` | `array` | ✅ Required only if `exportSelectionType` is `onlySelected` | | Array of Ids of the selected resources |
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
136
|
+
| `fields` | `array` | ✅ Required | | Array of the fields to export |
|
|
137
|
+
| `fields[].key` | `string` | ✅ Required | | The unique key of the field that is used to identify data type |
|
|
138
|
+
| `fields[].label` | `string` | | | The label of the field to be shown in the export modal, if it's not set the key will be shown instead |
|
|
139
|
+
| `fields[].isLocalized` | `boolean` | | false | The field is a localized field |
|
|
121
140
|
| `appliedSearchTerms` | `array` | | [] | Array of the search terms that are used when `exportSelectionType` is `onlyMatching` |
|
|
122
141
|
| `appliedFilters` | `array` | | [] | Array of the filters that are used when `exportSelectionType` is `onlyMatching` |
|
|
123
142
|
| `renderProperties` | `function` | | | A prop to render properties that are resource-specific |
|
|
@@ -25,6 +25,7 @@ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
|
25
25
|
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
26
26
|
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
27
27
|
var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
|
|
28
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
28
29
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
29
30
|
var PropTypes = require('prop-types');
|
|
30
31
|
var formik = require('formik');
|
|
@@ -58,6 +59,7 @@ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstancePro
|
|
|
58
59
|
var _flatInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatInstanceProperty);
|
|
59
60
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
60
61
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
62
|
+
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
61
63
|
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
62
64
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
63
65
|
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
@@ -67,7 +69,8 @@ var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRunt
|
|
|
67
69
|
|
|
68
70
|
var EXPORTABLE_RESOURCES = {
|
|
69
71
|
CATEGORY: 'category',
|
|
70
|
-
PRODUCT: 'product'
|
|
72
|
+
PRODUCT: 'product',
|
|
73
|
+
DISCOUNT_CODE: 'discountCode'
|
|
71
74
|
};
|
|
72
75
|
var EXPORT_SELECTION_TYPES = {
|
|
73
76
|
ALL_RESOURCES: 'allResources',
|
|
@@ -84,14 +87,14 @@ var EXPORT_OPERATION_STATES = {
|
|
|
84
87
|
FAILED: 'failed'
|
|
85
88
|
};
|
|
86
89
|
|
|
87
|
-
function _createSuper$
|
|
90
|
+
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); }; }
|
|
88
91
|
|
|
89
|
-
function _isNativeReflectConstruct$
|
|
92
|
+
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; } }
|
|
90
93
|
|
|
91
94
|
var UnexpectedSelectionTypeError = /*#__PURE__*/function (_Error) {
|
|
92
95
|
_inherits(UnexpectedSelectionTypeError, _Error);
|
|
93
96
|
|
|
94
|
-
var _super = _createSuper$
|
|
97
|
+
var _super = _createSuper$3(UnexpectedSelectionTypeError);
|
|
95
98
|
|
|
96
99
|
function UnexpectedSelectionTypeError(exportSelectionType) {
|
|
97
100
|
var _this;
|
|
@@ -106,14 +109,14 @@ var UnexpectedSelectionTypeError = /*#__PURE__*/function (_Error) {
|
|
|
106
109
|
return _createClass(UnexpectedSelectionTypeError);
|
|
107
110
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
108
111
|
|
|
109
|
-
function _createSuper$
|
|
112
|
+
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); }; }
|
|
110
113
|
|
|
111
|
-
function _isNativeReflectConstruct$
|
|
114
|
+
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; } }
|
|
112
115
|
|
|
113
116
|
var MissingExportResourceProviderError = /*#__PURE__*/function (_Error) {
|
|
114
117
|
_inherits(MissingExportResourceProviderError, _Error);
|
|
115
118
|
|
|
116
|
-
var _super = _createSuper$
|
|
119
|
+
var _super = _createSuper$2(MissingExportResourceProviderError);
|
|
117
120
|
|
|
118
121
|
function MissingExportResourceProviderError() {
|
|
119
122
|
var _this;
|
|
@@ -128,14 +131,14 @@ var MissingExportResourceProviderError = /*#__PURE__*/function (_Error) {
|
|
|
128
131
|
return _createClass(MissingExportResourceProviderError);
|
|
129
132
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
130
133
|
|
|
131
|
-
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); }; }
|
|
134
|
+
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); }; }
|
|
132
135
|
|
|
133
|
-
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; } }
|
|
136
|
+
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; } }
|
|
134
137
|
|
|
135
138
|
var UnexpectedExportOperationStateError = /*#__PURE__*/function (_Error) {
|
|
136
139
|
_inherits(UnexpectedExportOperationStateError, _Error);
|
|
137
140
|
|
|
138
|
-
var _super = _createSuper(UnexpectedExportOperationStateError);
|
|
141
|
+
var _super = _createSuper$1(UnexpectedExportOperationStateError);
|
|
139
142
|
|
|
140
143
|
function UnexpectedExportOperationStateError(state) {
|
|
141
144
|
var _this;
|
|
@@ -150,6 +153,28 @@ var UnexpectedExportOperationStateError = /*#__PURE__*/function (_Error) {
|
|
|
150
153
|
return _createClass(UnexpectedExportOperationStateError);
|
|
151
154
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
152
155
|
|
|
156
|
+
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); }; }
|
|
157
|
+
|
|
158
|
+
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; } }
|
|
159
|
+
|
|
160
|
+
var UnexpectedResourceTypeError = /*#__PURE__*/function (_Error) {
|
|
161
|
+
_inherits(UnexpectedResourceTypeError, _Error);
|
|
162
|
+
|
|
163
|
+
var _super = _createSuper(UnexpectedResourceTypeError);
|
|
164
|
+
|
|
165
|
+
function UnexpectedResourceTypeError(resourceType) {
|
|
166
|
+
var _this;
|
|
167
|
+
|
|
168
|
+
_classCallCheck(this, UnexpectedResourceTypeError);
|
|
169
|
+
|
|
170
|
+
_this = _super.call(this, "Unexpected resource type: ".concat(resourceType));
|
|
171
|
+
_this.name = 'UnexpectedResourceTypeError';
|
|
172
|
+
return _this;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return _createClass(UnexpectedResourceTypeError);
|
|
176
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
177
|
+
|
|
153
178
|
function resourceTypeToPlural(_ref) {
|
|
154
179
|
var resourceType = _ref.resourceType,
|
|
155
180
|
_ref$isUpperCase = _ref.isUpperCase,
|
|
@@ -162,38 +187,61 @@ function resourceTypeToPlural(_ref) {
|
|
|
162
187
|
case EXPORTABLE_RESOURCES.PRODUCT:
|
|
163
188
|
return isUpperCase ? 'Products' : 'products';
|
|
164
189
|
|
|
190
|
+
case EXPORTABLE_RESOURCES.DISCOUNT_CODE:
|
|
191
|
+
return isUpperCase ? 'Discount codes' : 'discount codes';
|
|
192
|
+
|
|
165
193
|
default:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
194
|
+
throw UnexpectedResourceTypeError(resourceType);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function resourceTypeToOperationName(resourceType) {
|
|
198
|
+
switch (resourceType) {
|
|
199
|
+
case EXPORTABLE_RESOURCES.CATEGORY:
|
|
200
|
+
return 'categories';
|
|
201
|
+
|
|
202
|
+
case EXPORTABLE_RESOURCES.PRODUCT:
|
|
203
|
+
return 'products';
|
|
204
|
+
|
|
205
|
+
case EXPORTABLE_RESOURCES.DISCOUNT_CODE:
|
|
206
|
+
return 'discountCodes';
|
|
207
|
+
|
|
208
|
+
default:
|
|
209
|
+
throw UnexpectedResourceTypeError(resourceType);
|
|
169
210
|
}
|
|
170
211
|
}
|
|
171
212
|
function replaceSpecialCharsWithUnderscore(string) {
|
|
172
213
|
return string.replace(/[^a-zA-Z0-9]/g, '_');
|
|
173
214
|
}
|
|
215
|
+
function isFilledArray(maybeArray) {
|
|
216
|
+
return _Array$isArray__default["default"](maybeArray) && maybeArray.length;
|
|
217
|
+
}
|
|
174
218
|
|
|
175
219
|
function buildGraphQuery(exportSettings) {
|
|
176
220
|
var _context;
|
|
177
221
|
|
|
178
|
-
var
|
|
179
|
-
resourceType: exportSettings.resourceType
|
|
180
|
-
});
|
|
222
|
+
var operation = resourceTypeToOperationName(exportSettings.resourceType);
|
|
181
223
|
|
|
182
224
|
switch (exportSettings.exportSelectionType) {
|
|
183
225
|
case EXPORT_SELECTION_TYPES.ALL_RESOURCES:
|
|
184
226
|
return gqlQueryBuilder.query({
|
|
185
|
-
operation:
|
|
227
|
+
operation: operation,
|
|
186
228
|
fields: [{
|
|
187
|
-
results:
|
|
229
|
+
results: buildFields({
|
|
230
|
+
fields: exportSettings.fields,
|
|
231
|
+
languages: exportSettings.languages
|
|
232
|
+
})
|
|
188
233
|
}],
|
|
189
234
|
variables: {}
|
|
190
235
|
});
|
|
191
236
|
|
|
192
237
|
case EXPORT_SELECTION_TYPES.ONLY_SELECTED:
|
|
193
238
|
return gqlQueryBuilder.query({
|
|
194
|
-
operation:
|
|
239
|
+
operation: operation,
|
|
195
240
|
fields: [{
|
|
196
|
-
results:
|
|
241
|
+
results: buildFields({
|
|
242
|
+
fields: exportSettings.fields,
|
|
243
|
+
languages: exportSettings.languages
|
|
244
|
+
})
|
|
197
245
|
}],
|
|
198
246
|
variables: {
|
|
199
247
|
where: "id in (".concat(_mapInstanceProperty__default["default"](_context = exportSettings.selectedResourceIds).call(_context, function (id) {
|
|
@@ -211,16 +259,27 @@ function buildGraphQuery(exportSettings) {
|
|
|
211
259
|
}
|
|
212
260
|
}
|
|
213
261
|
|
|
214
|
-
function
|
|
262
|
+
function buildFields(_ref) {
|
|
215
263
|
var _context2;
|
|
216
264
|
|
|
217
|
-
|
|
218
|
-
|
|
265
|
+
var fields = _ref.fields,
|
|
266
|
+
languages = _ref.languages;
|
|
267
|
+
return _flatInstanceProperty__default["default"](_context2 = _mapInstanceProperty__default["default"](fields).call(fields, function (field) {
|
|
268
|
+
if (field.isLocalized) return _mapInstanceProperty__default["default"](languages).call(languages, function (language) {
|
|
219
269
|
var _context3, _context4, _context5;
|
|
220
270
|
|
|
221
|
-
var alias = replaceSpecialCharsWithUnderscore(_concatInstanceProperty__default["default"](_context3 = "".concat(
|
|
222
|
-
return _concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "".concat(alias, ": ")).call(_context5,
|
|
223
|
-
});else
|
|
271
|
+
var alias = replaceSpecialCharsWithUnderscore(_concatInstanceProperty__default["default"](_context3 = "".concat(field.key, "_")).call(_context3, language));
|
|
272
|
+
return _concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "".concat(alias, ": ")).call(_context5, field.key, "(locale: \"")).call(_context4, language, "\")");
|
|
273
|
+
});else {
|
|
274
|
+
if (isFilledArray(field.fields)) {
|
|
275
|
+
return _defineProperty({}, field.key, buildFields({
|
|
276
|
+
fields: field.fields,
|
|
277
|
+
languages: languages
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return field.key;
|
|
282
|
+
}
|
|
224
283
|
})).call(_context2);
|
|
225
284
|
}
|
|
226
285
|
|
|
@@ -382,9 +441,16 @@ var ExportResourcesModalShape = PropTypes__default["default"].shape({
|
|
|
382
441
|
allResourcesCount: PropTypes__default["default"].number.isRequired,
|
|
383
442
|
matchingResourcesCount: PropTypes__default["default"].number,
|
|
384
443
|
selectedResourceIds: PropTypes__default["default"].array,
|
|
385
|
-
|
|
444
|
+
// TODO: Circular reference
|
|
445
|
+
fields: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
386
446
|
key: PropTypes__default["default"].string.isRequired,
|
|
387
|
-
|
|
447
|
+
label: PropTypes__default["default"].string,
|
|
448
|
+
isLocalized: PropTypes__default["default"].bool,
|
|
449
|
+
fields: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
450
|
+
key: PropTypes__default["default"].string.isRequired,
|
|
451
|
+
label: PropTypes__default["default"].string,
|
|
452
|
+
isLocalized: PropTypes__default["default"].bool
|
|
453
|
+
}))
|
|
388
454
|
})).isRequired,
|
|
389
455
|
exportSelectionType: PropTypes__default["default"].string,
|
|
390
456
|
appliedSearchTerms: PropTypes__default["default"].array,
|
|
@@ -435,7 +501,7 @@ var ExportResourcesContextProvider = function ExportResourcesContextProvider(pro
|
|
|
435
501
|
isUpperCase: true
|
|
436
502
|
}), "_Export_")).call(_context, todayFormatted),
|
|
437
503
|
languages: [language],
|
|
438
|
-
|
|
504
|
+
fields: props.fields,
|
|
439
505
|
appliedSearchTerms: props.appliedSearchTerms,
|
|
440
506
|
appliedFilters: props.appliedFilters,
|
|
441
507
|
exportSelectionType: props.exportSelectionType,
|
|
@@ -749,9 +815,46 @@ AppliedSearchTerms.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
749
815
|
|
|
750
816
|
function ownKeys$6(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
751
817
|
|
|
752
|
-
function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
753
|
-
|
|
754
|
-
|
|
818
|
+
function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$6(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$6(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
819
|
+
|
|
820
|
+
function normalizeFields(fields) {
|
|
821
|
+
var result = _mapInstanceProperty__default["default"](fields).call(fields, function (field) {
|
|
822
|
+
if (isFilledArray(field.fields)) {
|
|
823
|
+
var _context;
|
|
824
|
+
|
|
825
|
+
return _mapInstanceProperty__default["default"](_context = normalizeFields(field.fields)).call(_context, function (nestedField) {
|
|
826
|
+
var _context2;
|
|
827
|
+
|
|
828
|
+
return _objectSpread$6(_objectSpread$6({}, nestedField), {}, {
|
|
829
|
+
key: _concatInstanceProperty__default["default"](_context2 = "".concat(field.key, ".")).call(_context2, nestedField.key)
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
return field;
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
return _flatInstanceProperty__default["default"](result).call(result);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function FieldsRenderer(_ref) {
|
|
841
|
+
var fields = _ref.fields;
|
|
842
|
+
var allFields = normalizeFields(fields);
|
|
843
|
+
return jsxRuntime.jsx(TagList, {
|
|
844
|
+
children: _mapInstanceProperty__default["default"](allFields).call(allFields, function (field) {
|
|
845
|
+
return jsxRuntime.jsx("div", {
|
|
846
|
+
"data-testid": "test-field-".concat(field.key),
|
|
847
|
+
children: jsxRuntime.jsx(uiKit.Tag, {
|
|
848
|
+
children: field.label || field.key
|
|
849
|
+
})
|
|
850
|
+
}, field.key);
|
|
851
|
+
})
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
FieldsRenderer.propTypes = process.env.NODE_ENV !== "production" ? ExportFields.propTypes : {};
|
|
856
|
+
function ExportFields(_ref2) {
|
|
857
|
+
var fields = _ref2.fields;
|
|
755
858
|
return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
756
859
|
scale: "s",
|
|
757
860
|
children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
|
|
@@ -764,27 +867,27 @@ function Columns(_ref) {
|
|
|
764
867
|
}), jsxRuntime.jsx(uiKit.Text.Body, {
|
|
765
868
|
intlMessage: _objectSpread$6(_objectSpread$6({}, messages.columnsMessage), {}, {
|
|
766
869
|
values: {
|
|
767
|
-
columnsCount:
|
|
870
|
+
columnsCount: fields.length,
|
|
768
871
|
b: getBold
|
|
769
872
|
}
|
|
770
873
|
})
|
|
771
874
|
})]
|
|
772
|
-
}), jsxRuntime.jsx(
|
|
773
|
-
|
|
774
|
-
return jsxRuntime.jsx("div", {
|
|
775
|
-
"data-testid": "test-column-".concat(column.exportLabel),
|
|
776
|
-
children: jsxRuntime.jsx(uiKit.Tag, {
|
|
777
|
-
children: column.key
|
|
778
|
-
})
|
|
779
|
-
}, column.exportLabel);
|
|
780
|
-
})
|
|
875
|
+
}), jsxRuntime.jsx(FieldsRenderer, {
|
|
876
|
+
fields: fields
|
|
781
877
|
})]
|
|
782
878
|
});
|
|
783
879
|
}
|
|
784
|
-
|
|
785
|
-
|
|
880
|
+
ExportFields.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
881
|
+
// TODO: Circular reference
|
|
882
|
+
fields: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
786
883
|
key: PropTypes__default["default"].string.isRequired,
|
|
787
|
-
|
|
884
|
+
label: PropTypes__default["default"].string,
|
|
885
|
+
isLocalized: PropTypes__default["default"].bool,
|
|
886
|
+
fields: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
887
|
+
key: PropTypes__default["default"].string.isRequired,
|
|
888
|
+
label: PropTypes__default["default"].string,
|
|
889
|
+
isLocalized: PropTypes__default["default"].bool
|
|
890
|
+
}))
|
|
788
891
|
})).isRequired
|
|
789
892
|
} : {};
|
|
790
893
|
|
|
@@ -825,8 +928,8 @@ var ExportSelection = function ExportSelection() {
|
|
|
825
928
|
filters: _valuesInstanceProperty__default["default"](formik).appliedFilters,
|
|
826
929
|
onFilterRemove: onAppliedFilterRemove
|
|
827
930
|
})]
|
|
828
|
-
}), _valuesInstanceProperty__default["default"](formik).
|
|
829
|
-
|
|
931
|
+
}), _valuesInstanceProperty__default["default"](formik).fields.length > 0 && jsxRuntime.jsx(ExportFields, {
|
|
932
|
+
fields: _valuesInstanceProperty__default["default"](formik).fields
|
|
830
933
|
})]
|
|
831
934
|
})
|
|
832
935
|
})]
|
|
@@ -982,32 +1085,30 @@ function _createExportOperation() {
|
|
|
982
1085
|
_createExportOperation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(_ref) {
|
|
983
1086
|
var projectKey, graphQuery, asyncDispatchFn, uri, response;
|
|
984
1087
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
985
|
-
while (1) {
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
}));
|
|
1002
|
-
|
|
1003
|
-
case 4:
|
|
1004
|
-
response = _context.sent;
|
|
1005
|
-
return _context.abrupt("return", response);
|
|
1088
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1089
|
+
case 0:
|
|
1090
|
+
projectKey = _ref.projectKey, graphQuery = _ref.graphQuery, asyncDispatchFn = _ref.asyncDispatchFn;
|
|
1091
|
+
uri = "/proxy/export/".concat(projectKey, "/export-operations");
|
|
1092
|
+
_context.next = 4;
|
|
1093
|
+
return asyncDispatchFn(sdk.actions.post({
|
|
1094
|
+
// FIXME: EXPORT is undefined
|
|
1095
|
+
mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.EXPORT,
|
|
1096
|
+
uri: uri,
|
|
1097
|
+
headers: {
|
|
1098
|
+
accept: 'application/json'
|
|
1099
|
+
},
|
|
1100
|
+
payload: {
|
|
1101
|
+
query: graphQuery
|
|
1102
|
+
}
|
|
1103
|
+
}));
|
|
1006
1104
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1105
|
+
case 4:
|
|
1106
|
+
response = _context.sent;
|
|
1107
|
+
return _context.abrupt("return", response);
|
|
1108
|
+
|
|
1109
|
+
case 6:
|
|
1110
|
+
case "end":
|
|
1111
|
+
return _context.stop();
|
|
1011
1112
|
}
|
|
1012
1113
|
}, _callee);
|
|
1013
1114
|
}));
|
|
@@ -1075,54 +1176,52 @@ function ExportConfirmationModal(props) {
|
|
|
1075
1176
|
onConfirm: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
1076
1177
|
var graphQuery, response;
|
|
1077
1178
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
1078
|
-
while (1) {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
return _context.stop();
|
|
1125
|
-
}
|
|
1179
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1180
|
+
case 0:
|
|
1181
|
+
setExportOperationStarted(false);
|
|
1182
|
+
graphQuery = buildGraphQuery({
|
|
1183
|
+
resourceType: resourceType,
|
|
1184
|
+
selectedResourceIds: selectedResourceIds,
|
|
1185
|
+
fields: _valuesInstanceProperty__default["default"](formik).fields,
|
|
1186
|
+
exportSelectionType: _valuesInstanceProperty__default["default"](formik).exportSelectionType,
|
|
1187
|
+
languages: _valuesInstanceProperty__default["default"](formik).languages
|
|
1188
|
+
});
|
|
1189
|
+
props.closeModal();
|
|
1190
|
+
_context.prev = 3;
|
|
1191
|
+
_context.next = 6;
|
|
1192
|
+
return createExportOperation({
|
|
1193
|
+
projectKey: projectKey,
|
|
1194
|
+
graphQuery: graphQuery,
|
|
1195
|
+
asyncDispatchFn: asyncDispatch
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
case 6:
|
|
1199
|
+
response = _context.sent;
|
|
1200
|
+
_context.t0 = response.state;
|
|
1201
|
+
_context.next = _context.t0 === EXPORT_OPERATION_STATES.PROCESSING ? 10 : _context.t0 === EXPORT_OPERATION_STATES.COMPLETED ? 10 : 12;
|
|
1202
|
+
break;
|
|
1203
|
+
|
|
1204
|
+
case 10:
|
|
1205
|
+
setExportOperationStarted(true);
|
|
1206
|
+
return _context.abrupt("break", 13);
|
|
1207
|
+
|
|
1208
|
+
case 12:
|
|
1209
|
+
throw new UnexpectedExportOperationStateError(response.state);
|
|
1210
|
+
|
|
1211
|
+
case 13:
|
|
1212
|
+
_context.next = 18;
|
|
1213
|
+
break;
|
|
1214
|
+
|
|
1215
|
+
case 15:
|
|
1216
|
+
_context.prev = 15;
|
|
1217
|
+
_context.t1 = _context["catch"](3);
|
|
1218
|
+
actionsGlobal.showApiErrorNotification({
|
|
1219
|
+
errors: _context.t1
|
|
1220
|
+
});
|
|
1221
|
+
|
|
1222
|
+
case 18:
|
|
1223
|
+
case "end":
|
|
1224
|
+
return _context.stop();
|
|
1126
1225
|
}
|
|
1127
1226
|
}, _callee, null, [[3, 15]]);
|
|
1128
1227
|
})),
|
|
@@ -25,6 +25,7 @@ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
|
25
25
|
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
26
26
|
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
27
27
|
var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
|
|
28
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
28
29
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
29
30
|
var PropTypes = require('prop-types');
|
|
30
31
|
var formik = require('formik');
|
|
@@ -58,6 +59,7 @@ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstancePro
|
|
|
58
59
|
var _flatInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatInstanceProperty);
|
|
59
60
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
60
61
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
62
|
+
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
61
63
|
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
62
64
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
63
65
|
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
@@ -67,7 +69,8 @@ var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRunt
|
|
|
67
69
|
|
|
68
70
|
var EXPORTABLE_RESOURCES = {
|
|
69
71
|
CATEGORY: 'category',
|
|
70
|
-
PRODUCT: 'product'
|
|
72
|
+
PRODUCT: 'product',
|
|
73
|
+
DISCOUNT_CODE: 'discountCode'
|
|
71
74
|
};
|
|
72
75
|
var EXPORT_SELECTION_TYPES = {
|
|
73
76
|
ALL_RESOURCES: 'allResources',
|
|
@@ -84,14 +87,14 @@ var EXPORT_OPERATION_STATES = {
|
|
|
84
87
|
FAILED: 'failed'
|
|
85
88
|
};
|
|
86
89
|
|
|
87
|
-
function _createSuper$
|
|
90
|
+
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); }; }
|
|
88
91
|
|
|
89
|
-
function _isNativeReflectConstruct$
|
|
92
|
+
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; } }
|
|
90
93
|
|
|
91
94
|
var UnexpectedSelectionTypeError = /*#__PURE__*/function (_Error) {
|
|
92
95
|
_inherits(UnexpectedSelectionTypeError, _Error);
|
|
93
96
|
|
|
94
|
-
var _super = _createSuper$
|
|
97
|
+
var _super = _createSuper$3(UnexpectedSelectionTypeError);
|
|
95
98
|
|
|
96
99
|
function UnexpectedSelectionTypeError(exportSelectionType) {
|
|
97
100
|
var _this;
|
|
@@ -106,14 +109,14 @@ var UnexpectedSelectionTypeError = /*#__PURE__*/function (_Error) {
|
|
|
106
109
|
return _createClass(UnexpectedSelectionTypeError);
|
|
107
110
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
108
111
|
|
|
109
|
-
function _createSuper$
|
|
112
|
+
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); }; }
|
|
110
113
|
|
|
111
|
-
function _isNativeReflectConstruct$
|
|
114
|
+
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; } }
|
|
112
115
|
|
|
113
116
|
var MissingExportResourceProviderError = /*#__PURE__*/function (_Error) {
|
|
114
117
|
_inherits(MissingExportResourceProviderError, _Error);
|
|
115
118
|
|
|
116
|
-
var _super = _createSuper$
|
|
119
|
+
var _super = _createSuper$2(MissingExportResourceProviderError);
|
|
117
120
|
|
|
118
121
|
function MissingExportResourceProviderError() {
|
|
119
122
|
var _this;
|
|
@@ -128,14 +131,14 @@ var MissingExportResourceProviderError = /*#__PURE__*/function (_Error) {
|
|
|
128
131
|
return _createClass(MissingExportResourceProviderError);
|
|
129
132
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
130
133
|
|
|
131
|
-
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); }; }
|
|
134
|
+
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); }; }
|
|
132
135
|
|
|
133
|
-
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; } }
|
|
136
|
+
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; } }
|
|
134
137
|
|
|
135
138
|
var UnexpectedExportOperationStateError = /*#__PURE__*/function (_Error) {
|
|
136
139
|
_inherits(UnexpectedExportOperationStateError, _Error);
|
|
137
140
|
|
|
138
|
-
var _super = _createSuper(UnexpectedExportOperationStateError);
|
|
141
|
+
var _super = _createSuper$1(UnexpectedExportOperationStateError);
|
|
139
142
|
|
|
140
143
|
function UnexpectedExportOperationStateError(state) {
|
|
141
144
|
var _this;
|
|
@@ -150,6 +153,28 @@ var UnexpectedExportOperationStateError = /*#__PURE__*/function (_Error) {
|
|
|
150
153
|
return _createClass(UnexpectedExportOperationStateError);
|
|
151
154
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
152
155
|
|
|
156
|
+
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); }; }
|
|
157
|
+
|
|
158
|
+
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; } }
|
|
159
|
+
|
|
160
|
+
var UnexpectedResourceTypeError = /*#__PURE__*/function (_Error) {
|
|
161
|
+
_inherits(UnexpectedResourceTypeError, _Error);
|
|
162
|
+
|
|
163
|
+
var _super = _createSuper(UnexpectedResourceTypeError);
|
|
164
|
+
|
|
165
|
+
function UnexpectedResourceTypeError(resourceType) {
|
|
166
|
+
var _this;
|
|
167
|
+
|
|
168
|
+
_classCallCheck(this, UnexpectedResourceTypeError);
|
|
169
|
+
|
|
170
|
+
_this = _super.call(this, "Unexpected resource type: ".concat(resourceType));
|
|
171
|
+
_this.name = 'UnexpectedResourceTypeError';
|
|
172
|
+
return _this;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return _createClass(UnexpectedResourceTypeError);
|
|
176
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
177
|
+
|
|
153
178
|
function resourceTypeToPlural(_ref) {
|
|
154
179
|
var resourceType = _ref.resourceType,
|
|
155
180
|
_ref$isUpperCase = _ref.isUpperCase,
|
|
@@ -162,38 +187,61 @@ function resourceTypeToPlural(_ref) {
|
|
|
162
187
|
case EXPORTABLE_RESOURCES.PRODUCT:
|
|
163
188
|
return isUpperCase ? 'Products' : 'products';
|
|
164
189
|
|
|
190
|
+
case EXPORTABLE_RESOURCES.DISCOUNT_CODE:
|
|
191
|
+
return isUpperCase ? 'Discount codes' : 'discount codes';
|
|
192
|
+
|
|
165
193
|
default:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
194
|
+
throw UnexpectedResourceTypeError(resourceType);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function resourceTypeToOperationName(resourceType) {
|
|
198
|
+
switch (resourceType) {
|
|
199
|
+
case EXPORTABLE_RESOURCES.CATEGORY:
|
|
200
|
+
return 'categories';
|
|
201
|
+
|
|
202
|
+
case EXPORTABLE_RESOURCES.PRODUCT:
|
|
203
|
+
return 'products';
|
|
204
|
+
|
|
205
|
+
case EXPORTABLE_RESOURCES.DISCOUNT_CODE:
|
|
206
|
+
return 'discountCodes';
|
|
207
|
+
|
|
208
|
+
default:
|
|
209
|
+
throw UnexpectedResourceTypeError(resourceType);
|
|
169
210
|
}
|
|
170
211
|
}
|
|
171
212
|
function replaceSpecialCharsWithUnderscore(string) {
|
|
172
213
|
return string.replace(/[^a-zA-Z0-9]/g, '_');
|
|
173
214
|
}
|
|
215
|
+
function isFilledArray(maybeArray) {
|
|
216
|
+
return _Array$isArray__default["default"](maybeArray) && maybeArray.length;
|
|
217
|
+
}
|
|
174
218
|
|
|
175
219
|
function buildGraphQuery(exportSettings) {
|
|
176
220
|
var _context;
|
|
177
221
|
|
|
178
|
-
var
|
|
179
|
-
resourceType: exportSettings.resourceType
|
|
180
|
-
});
|
|
222
|
+
var operation = resourceTypeToOperationName(exportSettings.resourceType);
|
|
181
223
|
|
|
182
224
|
switch (exportSettings.exportSelectionType) {
|
|
183
225
|
case EXPORT_SELECTION_TYPES.ALL_RESOURCES:
|
|
184
226
|
return gqlQueryBuilder.query({
|
|
185
|
-
operation:
|
|
227
|
+
operation: operation,
|
|
186
228
|
fields: [{
|
|
187
|
-
results:
|
|
229
|
+
results: buildFields({
|
|
230
|
+
fields: exportSettings.fields,
|
|
231
|
+
languages: exportSettings.languages
|
|
232
|
+
})
|
|
188
233
|
}],
|
|
189
234
|
variables: {}
|
|
190
235
|
});
|
|
191
236
|
|
|
192
237
|
case EXPORT_SELECTION_TYPES.ONLY_SELECTED:
|
|
193
238
|
return gqlQueryBuilder.query({
|
|
194
|
-
operation:
|
|
239
|
+
operation: operation,
|
|
195
240
|
fields: [{
|
|
196
|
-
results:
|
|
241
|
+
results: buildFields({
|
|
242
|
+
fields: exportSettings.fields,
|
|
243
|
+
languages: exportSettings.languages
|
|
244
|
+
})
|
|
197
245
|
}],
|
|
198
246
|
variables: {
|
|
199
247
|
where: "id in (".concat(_mapInstanceProperty__default["default"](_context = exportSettings.selectedResourceIds).call(_context, function (id) {
|
|
@@ -211,16 +259,27 @@ function buildGraphQuery(exportSettings) {
|
|
|
211
259
|
}
|
|
212
260
|
}
|
|
213
261
|
|
|
214
|
-
function
|
|
262
|
+
function buildFields(_ref) {
|
|
215
263
|
var _context2;
|
|
216
264
|
|
|
217
|
-
|
|
218
|
-
|
|
265
|
+
var fields = _ref.fields,
|
|
266
|
+
languages = _ref.languages;
|
|
267
|
+
return _flatInstanceProperty__default["default"](_context2 = _mapInstanceProperty__default["default"](fields).call(fields, function (field) {
|
|
268
|
+
if (field.isLocalized) return _mapInstanceProperty__default["default"](languages).call(languages, function (language) {
|
|
219
269
|
var _context3, _context4, _context5;
|
|
220
270
|
|
|
221
|
-
var alias = replaceSpecialCharsWithUnderscore(_concatInstanceProperty__default["default"](_context3 = "".concat(
|
|
222
|
-
return _concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "".concat(alias, ": ")).call(_context5,
|
|
223
|
-
});else
|
|
271
|
+
var alias = replaceSpecialCharsWithUnderscore(_concatInstanceProperty__default["default"](_context3 = "".concat(field.key, "_")).call(_context3, language));
|
|
272
|
+
return _concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "".concat(alias, ": ")).call(_context5, field.key, "(locale: \"")).call(_context4, language, "\")");
|
|
273
|
+
});else {
|
|
274
|
+
if (isFilledArray(field.fields)) {
|
|
275
|
+
return _defineProperty({}, field.key, buildFields({
|
|
276
|
+
fields: field.fields,
|
|
277
|
+
languages: languages
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return field.key;
|
|
282
|
+
}
|
|
224
283
|
})).call(_context2);
|
|
225
284
|
}
|
|
226
285
|
|
|
@@ -382,9 +441,16 @@ PropTypes__default["default"].shape({
|
|
|
382
441
|
allResourcesCount: PropTypes__default["default"].number.isRequired,
|
|
383
442
|
matchingResourcesCount: PropTypes__default["default"].number,
|
|
384
443
|
selectedResourceIds: PropTypes__default["default"].array,
|
|
385
|
-
|
|
444
|
+
// TODO: Circular reference
|
|
445
|
+
fields: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
386
446
|
key: PropTypes__default["default"].string.isRequired,
|
|
387
|
-
|
|
447
|
+
label: PropTypes__default["default"].string,
|
|
448
|
+
isLocalized: PropTypes__default["default"].bool,
|
|
449
|
+
fields: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
450
|
+
key: PropTypes__default["default"].string.isRequired,
|
|
451
|
+
label: PropTypes__default["default"].string,
|
|
452
|
+
isLocalized: PropTypes__default["default"].bool
|
|
453
|
+
}))
|
|
388
454
|
})).isRequired,
|
|
389
455
|
exportSelectionType: PropTypes__default["default"].string,
|
|
390
456
|
appliedSearchTerms: PropTypes__default["default"].array,
|
|
@@ -431,7 +497,7 @@ var ExportResourcesContextProvider = function ExportResourcesContextProvider(pro
|
|
|
431
497
|
isUpperCase: true
|
|
432
498
|
}), "_Export_")).call(_context, todayFormatted),
|
|
433
499
|
languages: [language],
|
|
434
|
-
|
|
500
|
+
fields: props.fields,
|
|
435
501
|
appliedSearchTerms: props.appliedSearchTerms,
|
|
436
502
|
appliedFilters: props.appliedFilters,
|
|
437
503
|
exportSelectionType: props.exportSelectionType,
|
|
@@ -726,9 +792,46 @@ AppliedSearchTerms.propTypes = {};
|
|
|
726
792
|
|
|
727
793
|
function ownKeys$6(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
728
794
|
|
|
729
|
-
function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
730
|
-
|
|
731
|
-
|
|
795
|
+
function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$6(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$6(Object(source))).call(_context4, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
796
|
+
|
|
797
|
+
function normalizeFields(fields) {
|
|
798
|
+
var result = _mapInstanceProperty__default["default"](fields).call(fields, function (field) {
|
|
799
|
+
if (isFilledArray(field.fields)) {
|
|
800
|
+
var _context;
|
|
801
|
+
|
|
802
|
+
return _mapInstanceProperty__default["default"](_context = normalizeFields(field.fields)).call(_context, function (nestedField) {
|
|
803
|
+
var _context2;
|
|
804
|
+
|
|
805
|
+
return _objectSpread$6(_objectSpread$6({}, nestedField), {}, {
|
|
806
|
+
key: _concatInstanceProperty__default["default"](_context2 = "".concat(field.key, ".")).call(_context2, nestedField.key)
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
return field;
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
return _flatInstanceProperty__default["default"](result).call(result);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
function FieldsRenderer(_ref) {
|
|
818
|
+
var fields = _ref.fields;
|
|
819
|
+
var allFields = normalizeFields(fields);
|
|
820
|
+
return jsxRuntime.jsx(TagList, {
|
|
821
|
+
children: _mapInstanceProperty__default["default"](allFields).call(allFields, function (field) {
|
|
822
|
+
return jsxRuntime.jsx("div", {
|
|
823
|
+
"data-testid": "test-field-".concat(field.key),
|
|
824
|
+
children: jsxRuntime.jsx(uiKit.Tag, {
|
|
825
|
+
children: field.label || field.key
|
|
826
|
+
})
|
|
827
|
+
}, field.key);
|
|
828
|
+
})
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
FieldsRenderer.propTypes = {};
|
|
833
|
+
function ExportFields(_ref2) {
|
|
834
|
+
var fields = _ref2.fields;
|
|
732
835
|
return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
733
836
|
scale: "s",
|
|
734
837
|
children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
|
|
@@ -741,24 +844,17 @@ function Columns(_ref) {
|
|
|
741
844
|
}), jsxRuntime.jsx(uiKit.Text.Body, {
|
|
742
845
|
intlMessage: _objectSpread$6(_objectSpread$6({}, messages.columnsMessage), {}, {
|
|
743
846
|
values: {
|
|
744
|
-
columnsCount:
|
|
847
|
+
columnsCount: fields.length,
|
|
745
848
|
b: getBold
|
|
746
849
|
}
|
|
747
850
|
})
|
|
748
851
|
})]
|
|
749
|
-
}), jsxRuntime.jsx(
|
|
750
|
-
|
|
751
|
-
return jsxRuntime.jsx("div", {
|
|
752
|
-
"data-testid": "test-column-".concat(column.exportLabel),
|
|
753
|
-
children: jsxRuntime.jsx(uiKit.Tag, {
|
|
754
|
-
children: column.key
|
|
755
|
-
})
|
|
756
|
-
}, column.exportLabel);
|
|
757
|
-
})
|
|
852
|
+
}), jsxRuntime.jsx(FieldsRenderer, {
|
|
853
|
+
fields: fields
|
|
758
854
|
})]
|
|
759
855
|
});
|
|
760
856
|
}
|
|
761
|
-
|
|
857
|
+
ExportFields.propTypes = {};
|
|
762
858
|
|
|
763
859
|
var ExportSelection = function ExportSelection() {
|
|
764
860
|
var _useExportResourcesCo = useExportResourcesContext(),
|
|
@@ -797,8 +893,8 @@ var ExportSelection = function ExportSelection() {
|
|
|
797
893
|
filters: _valuesInstanceProperty__default["default"](formik).appliedFilters,
|
|
798
894
|
onFilterRemove: onAppliedFilterRemove
|
|
799
895
|
})]
|
|
800
|
-
}), _valuesInstanceProperty__default["default"](formik).
|
|
801
|
-
|
|
896
|
+
}), _valuesInstanceProperty__default["default"](formik).fields.length > 0 && jsxRuntime.jsx(ExportFields, {
|
|
897
|
+
fields: _valuesInstanceProperty__default["default"](formik).fields
|
|
802
898
|
})]
|
|
803
899
|
})
|
|
804
900
|
})]
|
|
@@ -950,32 +1046,30 @@ function _createExportOperation() {
|
|
|
950
1046
|
_createExportOperation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(_ref) {
|
|
951
1047
|
var projectKey, graphQuery, asyncDispatchFn, uri, response;
|
|
952
1048
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
953
|
-
while (1) {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
}));
|
|
970
|
-
|
|
971
|
-
case 4:
|
|
972
|
-
response = _context.sent;
|
|
973
|
-
return _context.abrupt("return", response);
|
|
1049
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1050
|
+
case 0:
|
|
1051
|
+
projectKey = _ref.projectKey, graphQuery = _ref.graphQuery, asyncDispatchFn = _ref.asyncDispatchFn;
|
|
1052
|
+
uri = "/proxy/export/".concat(projectKey, "/export-operations");
|
|
1053
|
+
_context.next = 4;
|
|
1054
|
+
return asyncDispatchFn(sdk.actions.post({
|
|
1055
|
+
// FIXME: EXPORT is undefined
|
|
1056
|
+
mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.EXPORT,
|
|
1057
|
+
uri: uri,
|
|
1058
|
+
headers: {
|
|
1059
|
+
accept: 'application/json'
|
|
1060
|
+
},
|
|
1061
|
+
payload: {
|
|
1062
|
+
query: graphQuery
|
|
1063
|
+
}
|
|
1064
|
+
}));
|
|
974
1065
|
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1066
|
+
case 4:
|
|
1067
|
+
response = _context.sent;
|
|
1068
|
+
return _context.abrupt("return", response);
|
|
1069
|
+
|
|
1070
|
+
case 6:
|
|
1071
|
+
case "end":
|
|
1072
|
+
return _context.stop();
|
|
979
1073
|
}
|
|
980
1074
|
}, _callee);
|
|
981
1075
|
}));
|
|
@@ -1043,54 +1137,52 @@ function ExportConfirmationModal(props) {
|
|
|
1043
1137
|
onConfirm: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
1044
1138
|
var graphQuery, response;
|
|
1045
1139
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
1046
|
-
while (1) {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
return _context.stop();
|
|
1093
|
-
}
|
|
1140
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1141
|
+
case 0:
|
|
1142
|
+
setExportOperationStarted(false);
|
|
1143
|
+
graphQuery = buildGraphQuery({
|
|
1144
|
+
resourceType: resourceType,
|
|
1145
|
+
selectedResourceIds: selectedResourceIds,
|
|
1146
|
+
fields: _valuesInstanceProperty__default["default"](formik).fields,
|
|
1147
|
+
exportSelectionType: _valuesInstanceProperty__default["default"](formik).exportSelectionType,
|
|
1148
|
+
languages: _valuesInstanceProperty__default["default"](formik).languages
|
|
1149
|
+
});
|
|
1150
|
+
props.closeModal();
|
|
1151
|
+
_context.prev = 3;
|
|
1152
|
+
_context.next = 6;
|
|
1153
|
+
return createExportOperation({
|
|
1154
|
+
projectKey: projectKey,
|
|
1155
|
+
graphQuery: graphQuery,
|
|
1156
|
+
asyncDispatchFn: asyncDispatch
|
|
1157
|
+
});
|
|
1158
|
+
|
|
1159
|
+
case 6:
|
|
1160
|
+
response = _context.sent;
|
|
1161
|
+
_context.t0 = response.state;
|
|
1162
|
+
_context.next = _context.t0 === EXPORT_OPERATION_STATES.PROCESSING ? 10 : _context.t0 === EXPORT_OPERATION_STATES.COMPLETED ? 10 : 12;
|
|
1163
|
+
break;
|
|
1164
|
+
|
|
1165
|
+
case 10:
|
|
1166
|
+
setExportOperationStarted(true);
|
|
1167
|
+
return _context.abrupt("break", 13);
|
|
1168
|
+
|
|
1169
|
+
case 12:
|
|
1170
|
+
throw new UnexpectedExportOperationStateError(response.state);
|
|
1171
|
+
|
|
1172
|
+
case 13:
|
|
1173
|
+
_context.next = 18;
|
|
1174
|
+
break;
|
|
1175
|
+
|
|
1176
|
+
case 15:
|
|
1177
|
+
_context.prev = 15;
|
|
1178
|
+
_context.t1 = _context["catch"](3);
|
|
1179
|
+
actionsGlobal.showApiErrorNotification({
|
|
1180
|
+
errors: _context.t1
|
|
1181
|
+
});
|
|
1182
|
+
|
|
1183
|
+
case 18:
|
|
1184
|
+
case "end":
|
|
1185
|
+
return _context.stop();
|
|
1094
1186
|
}
|
|
1095
1187
|
}, _callee, null, [[3, 15]]);
|
|
1096
1188
|
})),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend-extensions/export-resources-modal",
|
|
3
3
|
"description": "Shared export modal for exporting resources",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -19,31 +19,44 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "7.19.0",
|
|
21
21
|
"@babel/runtime-corejs3": "7.19.1",
|
|
22
|
-
"@commercetools-frontend/actions-global": "21.21.2",
|
|
23
|
-
"@commercetools-frontend/application-components": "21.21.2",
|
|
24
|
-
"@commercetools-frontend/application-shell-connectors": "21.21.2",
|
|
25
|
-
"@commercetools-frontend/constants": "^21.21.2",
|
|
26
|
-
"@commercetools-frontend/jest-preset-mc-app": "21.21.2",
|
|
27
|
-
"@commercetools-frontend/sdk": "^21.21.2",
|
|
28
|
-
"@commercetools-frontend/sentry": "^21.21.2",
|
|
29
|
-
"@commercetools-frontend/ui-kit": "15.8.0",
|
|
30
|
-
"@commercetools-uikit/design-system": "^15.8.0",
|
|
31
22
|
"@emotion/react": "11.10.4",
|
|
32
23
|
"@emotion/styled": "11.10.4",
|
|
33
|
-
"@formatjs/cli": "
|
|
24
|
+
"@formatjs/cli": "5.1.12",
|
|
34
25
|
"formik": "^2.2.9",
|
|
35
26
|
"gql-query-builder": "^3.8.0",
|
|
36
27
|
"jest": "27.5.1",
|
|
37
28
|
"moment": "^2.29.4",
|
|
38
|
-
"msw": "^0.39.2",
|
|
39
29
|
"omit-empty-es": "^1.1.3",
|
|
40
30
|
"prop-types": "15.8.1",
|
|
41
31
|
"react": "17.0.2",
|
|
42
32
|
"react-intl": "5.25.1"
|
|
43
33
|
},
|
|
44
34
|
"devDependencies": {
|
|
45
|
-
"@commercetools-frontend/
|
|
46
|
-
"@
|
|
35
|
+
"@commercetools-frontend/actions-global": "21.23.1",
|
|
36
|
+
"@commercetools-frontend/application-components": "21.23.1",
|
|
37
|
+
"@commercetools-frontend/application-shell": "21.23.1",
|
|
38
|
+
"@commercetools-frontend/application-shell-connectors": "21.23.1",
|
|
39
|
+
"@commercetools-frontend/constants": "21.23.1",
|
|
40
|
+
"@commercetools-frontend/jest-preset-mc-app": "21.23.1",
|
|
41
|
+
"@commercetools-frontend/sdk": "21.23.1",
|
|
42
|
+
"@commercetools-frontend/sentry": "21.23.1",
|
|
43
|
+
"@commercetools-frontend/ui-kit": "15.9.0",
|
|
44
|
+
"@commercetools-uikit/design-system": "15.9.0",
|
|
45
|
+
"@preconstruct/cli": "2.2.1",
|
|
46
|
+
"msw": "0.49.0",
|
|
47
47
|
"rimraf": "3.0.2"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@commercetools-frontend/actions-global": "21.23.1",
|
|
51
|
+
"@commercetools-frontend/application-components": "21.23.1",
|
|
52
|
+
"@commercetools-frontend/application-shell": "21.23.1",
|
|
53
|
+
"@commercetools-frontend/application-shell-connectors": "21.23.1",
|
|
54
|
+
"@commercetools-frontend/constants": "^21.23.1",
|
|
55
|
+
"@commercetools-frontend/jest-preset-mc-app": "21.23.1",
|
|
56
|
+
"@commercetools-frontend/sdk": "21.23.1",
|
|
57
|
+
"@commercetools-frontend/sentry": "21.23.1",
|
|
58
|
+
"@commercetools-frontend/ui-kit": "15.9.0",
|
|
59
|
+
"@commercetools-uikit/design-system": "15.9.0",
|
|
60
|
+
"msw": "0.49.0"
|
|
48
61
|
}
|
|
49
62
|
}
|