@commercetools-frontend-extensions/export-resources-modal 3.5.1 → 3.6.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 +28 -23
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.dev.js +39 -7
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.prod.js +39 -7
- package/dist/commercetools-frontend-extensions-export-resources-modal.esm.js +38 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
69
69
|
type:{
|
|
70
70
|
key: 'general-category-attributes',
|
|
71
71
|
label: 'General category attributes',
|
|
72
|
+
resourceTypeIds: ['category'],
|
|
72
73
|
},
|
|
73
74
|
fields: [
|
|
74
75
|
{
|
|
@@ -85,6 +86,7 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
85
86
|
type:{
|
|
86
87
|
key: 'book-category-attributes',
|
|
87
88
|
label: 'Book category attributes',
|
|
89
|
+
resourceTypeIds: ['category', 'asset'],
|
|
88
90
|
},
|
|
89
91
|
fields: [
|
|
90
92
|
{
|
|
@@ -153,6 +155,7 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
153
155
|
type:{
|
|
154
156
|
key: 'general-category-attributes',
|
|
155
157
|
label: 'General category attributes',
|
|
158
|
+
resourceTypeIds: ['category'],
|
|
156
159
|
},
|
|
157
160
|
fields: [
|
|
158
161
|
{
|
|
@@ -169,6 +172,7 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
169
172
|
type:{
|
|
170
173
|
key: 'book-category-attributes',
|
|
171
174
|
label: 'Book category attributes',
|
|
175
|
+
resourceTypeIds: ['category', 'asset'],
|
|
172
176
|
},
|
|
173
177
|
fields: [
|
|
174
178
|
{
|
|
@@ -195,29 +199,30 @@ import { ExportResourcesModal } from '@commercetools-frontend-extensions/export-
|
|
|
195
199
|
|
|
196
200
|
## Properties
|
|
197
201
|
|
|
198
|
-
| Props
|
|
199
|
-
|
|
|
200
|
-
| `isOpen`
|
|
201
|
-
| `outputFormat`
|
|
202
|
-
| `onExportSuccess`
|
|
203
|
-
| `onClose`
|
|
204
|
-
| `resourceType`
|
|
205
|
-
| `totalResourcesCount`
|
|
206
|
-
| `exportType`
|
|
207
|
-
| `selectedResourceIds`
|
|
208
|
-
| `fields`
|
|
209
|
-
| `fields[].name`
|
|
210
|
-
| `fields[].label`
|
|
211
|
-
| `fields[].isRequired`
|
|
212
|
-
| `fields[].isSelectedByDefault`
|
|
213
|
-
| `customFields`
|
|
214
|
-
| `customFields[].type`
|
|
215
|
-
| `customFields[].type.key`
|
|
216
|
-
| `customFields[].type.label`
|
|
217
|
-
| `customFields[].
|
|
218
|
-
| `customFields[].fields
|
|
219
|
-
| `customFields[].fields[].
|
|
220
|
-
| `
|
|
202
|
+
| Props | Type | Required | Default | Description |
|
|
203
|
+
| ------------------------------------- | ------------------------------------------------------- | :--------------------------------------------------: | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
204
|
+
| `isOpen` | `boolean` | | `false` | Controls whether the export modal is open or closed |
|
|
205
|
+
| `outputFormat` | `string`<br/>Possible values: `csv`, `json` | | `csv` | The file format to export |
|
|
206
|
+
| `onExportSuccess` | `function` | | | Callback function that is called when the export operation is successful |
|
|
207
|
+
| `onClose` | `function` | | | Callback function invoked when the modal is requested to close (on overlay click, close button click or `ESC` press). This function is also called after an export operation regardless of its success or failure |
|
|
208
|
+
| `resourceType` | `string` | ✅ | | The type of the resource, example: `category`, `product`... |
|
|
209
|
+
| `totalResourcesCount` | `number` | (✅) Required only if the `exportType` is `all` | | The count of all resources of identified `resourceType` |
|
|
210
|
+
| `exportType` | `string` <br/>Possible values:<br/>`all` and `selected` | | `all` | The type of export, so either export `all` resources or export only `selected` resources |
|
|
211
|
+
| `selectedResourceIds` | `array` | (✅) Required only if the `exportType` is `selected` | | Array of Ids of the selected resources |
|
|
212
|
+
| `fields` | `array` | ✅ | | Array of the fields to export. The fields must align with the [commercetools API schema](https://docs.commercetools.com/api/) |
|
|
213
|
+
| `fields[].name` | `string` | ✅ | | A string that represents the unique identifier for each field |
|
|
214
|
+
| `fields[].label` | `string` | ✅ | | The label of the field to be shown in the export modal |
|
|
215
|
+
| `fields[].isRequired` | `boolean` | | `false` | `isRequired` field indicates whether a field is required for the export process. If `true` the field will be selected by default and cannot be deselected by the user. This is useful for fields that are essential for the export process. Fields marked as required will have a `*` appended to their label in the UI |
|
|
216
|
+
| `fields[].isSelectedByDefault` | `boolean` | | `true` | This field is a part of the `fields` array is used to control the default state of the corresponding checkbox in the UI. If `isSelectedByDefault` is set to true, the checkbox for that particular field will be checked by default when the component loads. The default value of this attribute is `true` which means unless explicitly set to `false`, the checkbox for the field will be checked on initial load. |
|
|
217
|
+
| `customFields` | `array` | | | Array of objects, each representing a group of custom fields defined under a specific type. |
|
|
218
|
+
| `customFields[].type` | `string` | | | The type object. |
|
|
219
|
+
| `customFields[].type.key` | `string` | | | The unique identifier for the type. |
|
|
220
|
+
| `customFields[].type.label` | `string` | | | The label of the type to be shown in the export modal. |
|
|
221
|
+
| `customFields[].type.resourceTypeIds` | `string[]` | | | An array of [resource type IDs](https://docs.commercetools.com/api/projects/types#ctp:api:type:ResourceTypeId) for which the type is defined. |
|
|
222
|
+
| `customFields[].fields` | `array` | | | An array of objects with custom fields defined under the type represented by `type.key`. |
|
|
223
|
+
| `customFields[].fields[].name` | `string` | | | The name of the custom field. |
|
|
224
|
+
| `customFields[].fields[].label` | `string` | | | The label of the custom field to be shown in the export modal. This should match the label of the custom field in the selected locale. |
|
|
225
|
+
| `renderProperties` | `function` | | | A prop to render properties that are resource-specific |
|
|
221
226
|
|
|
222
227
|
## Releasing
|
|
223
228
|
|
|
@@ -36,6 +36,7 @@ var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-arr
|
|
|
36
36
|
var _flatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat');
|
|
37
37
|
var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
|
|
38
38
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
39
|
+
var _sortInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/sort');
|
|
39
40
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
40
41
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
41
42
|
var sdk = require('@commercetools-frontend/sdk');
|
|
@@ -70,6 +71,7 @@ var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
|
70
71
|
var _flatInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatInstanceProperty);
|
|
71
72
|
var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
|
|
72
73
|
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
74
|
+
var _sortInstanceProperty__default = /*#__PURE__*/_interopDefault(_sortInstanceProperty);
|
|
73
75
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
74
76
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
75
77
|
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
@@ -405,7 +407,7 @@ function validate(_ref) {
|
|
|
405
407
|
}
|
|
406
408
|
|
|
407
409
|
function ownKeys$5(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
408
|
-
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
410
|
+
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var _context8, _context9; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context8 = ownKeys$5(Object(t), !0)).call(_context8, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context9 = ownKeys$5(Object(t))).call(_context9, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
409
411
|
function resourceTypeToDisplayName(_ref) {
|
|
410
412
|
let resourceType = _ref.resourceType,
|
|
411
413
|
_ref$isUpperCase = _ref.isUpperCase,
|
|
@@ -496,10 +498,32 @@ function extractGeneralFieldNames(generalFields) {
|
|
|
496
498
|
function extractCustomFieldNamesWithPrefix(customFields) {
|
|
497
499
|
const fields = _flatMapInstanceProperty__default["default"](customFields).call(customFields, customType => {
|
|
498
500
|
var _context6;
|
|
499
|
-
return
|
|
501
|
+
return _flatMapInstanceProperty__default["default"](_context6 = customType.fields).call(_context6, field => {
|
|
502
|
+
return getCustomFieldNameWithPrefix(field, customType.type.resourceTypeIds);
|
|
503
|
+
});
|
|
500
504
|
});
|
|
501
505
|
return [...new _Set__default["default"](fields)];
|
|
502
506
|
}
|
|
507
|
+
function getCustomFieldNameWithPrefix(field, resourceTypeIds) {
|
|
508
|
+
const prefixes = _mapInstanceProperty__default["default"](resourceTypeIds).call(resourceTypeIds, type => {
|
|
509
|
+
switch (type) {
|
|
510
|
+
case 'asset':
|
|
511
|
+
return 'assets.custom.fields.';
|
|
512
|
+
default:
|
|
513
|
+
return 'custom.fields.';
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
return _mapInstanceProperty__default["default"](prefixes).call(prefixes, prefix => {
|
|
517
|
+
var _context7;
|
|
518
|
+
return _concatInstanceProperty__default["default"](_context7 = "".concat(prefix)).call(_context7, field.name);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Sorts an array of custom field names placing those starting with 'assets.custom.fields.' first
|
|
523
|
+
// This function doesn't affect the order of other custom fields
|
|
524
|
+
function sortCustomFields(fields) {
|
|
525
|
+
return _sortInstanceProperty__default["default"](fields).call(fields, (a, b) => _startsWithInstanceProperty__default["default"](b).call(b, 'assets.custom.fields.') - _startsWithInstanceProperty__default["default"](a).call(a, 'assets.custom.fields.'));
|
|
526
|
+
}
|
|
503
527
|
|
|
504
528
|
// TODO: remove this function when filters are passed directly from parent views
|
|
505
529
|
// This function is temporary and will be removed in the future
|
|
@@ -511,16 +535,23 @@ function tmpBuildFilters(selectedResourceIds) {
|
|
|
511
535
|
return ["id in (".concat(formattedIds, ")")];
|
|
512
536
|
}
|
|
513
537
|
|
|
538
|
+
const parentKeyExtension = ['parent.key', 'parent.typeId'];
|
|
539
|
+
const customFieldsExtension = ['custom.type.key', 'custom.type.typeId'];
|
|
540
|
+
const assetsCustomFieldsExtension = ['assets.custom.type.key', 'assets.custom.type.typeId'];
|
|
541
|
+
const assetsExtension = ['assets.key', 'assets.name', 'assets.sources.key', 'assets.sources.uri', 'assets.sources.contentType', 'assets.sources.dimensions.w', 'assets.sources.dimensions.h', 'assets.description', 'assets.tags'];
|
|
514
542
|
const categoryFieldExtension = fields => {
|
|
515
543
|
return _reduceInstanceProperty__default["default"](fields).call(fields, (acc, field) => {
|
|
516
544
|
if (field === 'parent.key') {
|
|
517
|
-
return [...acc,
|
|
545
|
+
return [...acc, ...parentKeyExtension];
|
|
518
546
|
}
|
|
519
547
|
if (_startsWithInstanceProperty__default["default"](field).call(field, 'custom.fields.') && !_includesInstanceProperty__default["default"](acc).call(acc, 'custom.type.key')) {
|
|
520
|
-
return [...acc,
|
|
548
|
+
return [...acc, ...customFieldsExtension, field];
|
|
521
549
|
}
|
|
522
550
|
if (field === 'assets') {
|
|
523
|
-
return [...acc,
|
|
551
|
+
return [...acc, ...assetsExtension];
|
|
552
|
+
}
|
|
553
|
+
if (_startsWithInstanceProperty__default["default"](field).call(field, 'assets.custom.fields.') && !_includesInstanceProperty__default["default"](acc).call(acc, 'assets.custom.type.key')) {
|
|
554
|
+
return [...acc, ...assetsCustomFieldsExtension, field];
|
|
524
555
|
}
|
|
525
556
|
return [...acc, field];
|
|
526
557
|
}, []);
|
|
@@ -618,7 +649,7 @@ const useStartExportOperation = props => {
|
|
|
618
649
|
const selectedGeneralFields = getSelectedGeneralFields(values.fields);
|
|
619
650
|
const selectedCustomFields = getSelectedCustomFields(values.customFields);
|
|
620
651
|
const generalFields = extractGeneralFieldNames(selectedGeneralFields);
|
|
621
|
-
const customFields = extractCustomFieldNamesWithPrefix(selectedCustomFields);
|
|
652
|
+
const customFields = sortCustomFields(extractCustomFieldNamesWithPrefix(selectedCustomFields));
|
|
622
653
|
const filters = tmpBuildFilters(props.selectedResourceIds);
|
|
623
654
|
const response = await createExportOperation({
|
|
624
655
|
projectKey,
|
|
@@ -1046,7 +1077,8 @@ const ExportResourcesModalShape = PropTypes__default["default"].shape({
|
|
|
1046
1077
|
customFields: PropTypes__default["default"].shape({
|
|
1047
1078
|
type: PropTypes__default["default"].shape({
|
|
1048
1079
|
key: PropTypes__default["default"].string.isRequired,
|
|
1049
|
-
label: PropTypes__default["default"].string.isRequired
|
|
1080
|
+
label: PropTypes__default["default"].string.isRequired,
|
|
1081
|
+
resourceTypeIds: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string)
|
|
1050
1082
|
}).isRequired,
|
|
1051
1083
|
fields: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
1052
1084
|
name: PropTypes__default["default"].string.isRequired,
|
|
@@ -36,6 +36,7 @@ var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-arr
|
|
|
36
36
|
var _flatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat');
|
|
37
37
|
var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
|
|
38
38
|
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
39
|
+
var _sortInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/sort');
|
|
39
40
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
40
41
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
41
42
|
var sdk = require('@commercetools-frontend/sdk');
|
|
@@ -70,6 +71,7 @@ var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
|
70
71
|
var _flatInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatInstanceProperty);
|
|
71
72
|
var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
|
|
72
73
|
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
74
|
+
var _sortInstanceProperty__default = /*#__PURE__*/_interopDefault(_sortInstanceProperty);
|
|
73
75
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
74
76
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
75
77
|
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
@@ -405,7 +407,7 @@ function validate(_ref) {
|
|
|
405
407
|
}
|
|
406
408
|
|
|
407
409
|
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; }
|
|
408
|
-
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
410
|
+
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var _context8, _context9; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context8 = ownKeys$4(Object(t), !0)).call(_context8, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context9 = ownKeys$4(Object(t))).call(_context9, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
409
411
|
function resourceTypeToDisplayName(_ref) {
|
|
410
412
|
let resourceType = _ref.resourceType,
|
|
411
413
|
_ref$isUpperCase = _ref.isUpperCase,
|
|
@@ -496,10 +498,32 @@ function extractGeneralFieldNames(generalFields) {
|
|
|
496
498
|
function extractCustomFieldNamesWithPrefix(customFields) {
|
|
497
499
|
const fields = _flatMapInstanceProperty__default["default"](customFields).call(customFields, customType => {
|
|
498
500
|
var _context6;
|
|
499
|
-
return
|
|
501
|
+
return _flatMapInstanceProperty__default["default"](_context6 = customType.fields).call(_context6, field => {
|
|
502
|
+
return getCustomFieldNameWithPrefix(field, customType.type.resourceTypeIds);
|
|
503
|
+
});
|
|
500
504
|
});
|
|
501
505
|
return [...new _Set__default["default"](fields)];
|
|
502
506
|
}
|
|
507
|
+
function getCustomFieldNameWithPrefix(field, resourceTypeIds) {
|
|
508
|
+
const prefixes = _mapInstanceProperty__default["default"](resourceTypeIds).call(resourceTypeIds, type => {
|
|
509
|
+
switch (type) {
|
|
510
|
+
case 'asset':
|
|
511
|
+
return 'assets.custom.fields.';
|
|
512
|
+
default:
|
|
513
|
+
return 'custom.fields.';
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
return _mapInstanceProperty__default["default"](prefixes).call(prefixes, prefix => {
|
|
517
|
+
var _context7;
|
|
518
|
+
return _concatInstanceProperty__default["default"](_context7 = "".concat(prefix)).call(_context7, field.name);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Sorts an array of custom field names placing those starting with 'assets.custom.fields.' first
|
|
523
|
+
// This function doesn't affect the order of other custom fields
|
|
524
|
+
function sortCustomFields(fields) {
|
|
525
|
+
return _sortInstanceProperty__default["default"](fields).call(fields, (a, b) => _startsWithInstanceProperty__default["default"](b).call(b, 'assets.custom.fields.') - _startsWithInstanceProperty__default["default"](a).call(a, 'assets.custom.fields.'));
|
|
526
|
+
}
|
|
503
527
|
|
|
504
528
|
// TODO: remove this function when filters are passed directly from parent views
|
|
505
529
|
// This function is temporary and will be removed in the future
|
|
@@ -511,16 +535,23 @@ function tmpBuildFilters(selectedResourceIds) {
|
|
|
511
535
|
return ["id in (".concat(formattedIds, ")")];
|
|
512
536
|
}
|
|
513
537
|
|
|
538
|
+
const parentKeyExtension = ['parent.key', 'parent.typeId'];
|
|
539
|
+
const customFieldsExtension = ['custom.type.key', 'custom.type.typeId'];
|
|
540
|
+
const assetsCustomFieldsExtension = ['assets.custom.type.key', 'assets.custom.type.typeId'];
|
|
541
|
+
const assetsExtension = ['assets.key', 'assets.name', 'assets.sources.key', 'assets.sources.uri', 'assets.sources.contentType', 'assets.sources.dimensions.w', 'assets.sources.dimensions.h', 'assets.description', 'assets.tags'];
|
|
514
542
|
const categoryFieldExtension = fields => {
|
|
515
543
|
return _reduceInstanceProperty__default["default"](fields).call(fields, (acc, field) => {
|
|
516
544
|
if (field === 'parent.key') {
|
|
517
|
-
return [...acc,
|
|
545
|
+
return [...acc, ...parentKeyExtension];
|
|
518
546
|
}
|
|
519
547
|
if (_startsWithInstanceProperty__default["default"](field).call(field, 'custom.fields.') && !_includesInstanceProperty__default["default"](acc).call(acc, 'custom.type.key')) {
|
|
520
|
-
return [...acc,
|
|
548
|
+
return [...acc, ...customFieldsExtension, field];
|
|
521
549
|
}
|
|
522
550
|
if (field === 'assets') {
|
|
523
|
-
return [...acc,
|
|
551
|
+
return [...acc, ...assetsExtension];
|
|
552
|
+
}
|
|
553
|
+
if (_startsWithInstanceProperty__default["default"](field).call(field, 'assets.custom.fields.') && !_includesInstanceProperty__default["default"](acc).call(acc, 'assets.custom.type.key')) {
|
|
554
|
+
return [...acc, ...assetsCustomFieldsExtension, field];
|
|
524
555
|
}
|
|
525
556
|
return [...acc, field];
|
|
526
557
|
}, []);
|
|
@@ -618,7 +649,7 @@ const useStartExportOperation = props => {
|
|
|
618
649
|
const selectedGeneralFields = getSelectedGeneralFields(values.fields);
|
|
619
650
|
const selectedCustomFields = getSelectedCustomFields(values.customFields);
|
|
620
651
|
const generalFields = extractGeneralFieldNames(selectedGeneralFields);
|
|
621
|
-
const customFields = extractCustomFieldNamesWithPrefix(selectedCustomFields);
|
|
652
|
+
const customFields = sortCustomFields(extractCustomFieldNamesWithPrefix(selectedCustomFields));
|
|
622
653
|
const filters = tmpBuildFilters(props.selectedResourceIds);
|
|
623
654
|
const response = await createExportOperation({
|
|
624
655
|
projectKey,
|
|
@@ -1036,7 +1067,8 @@ PropTypes__default["default"].shape({
|
|
|
1036
1067
|
customFields: PropTypes__default["default"].shape({
|
|
1037
1068
|
type: PropTypes__default["default"].shape({
|
|
1038
1069
|
key: PropTypes__default["default"].string.isRequired,
|
|
1039
|
-
label: PropTypes__default["default"].string.isRequired
|
|
1070
|
+
label: PropTypes__default["default"].string.isRequired,
|
|
1071
|
+
resourceTypeIds: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string)
|
|
1040
1072
|
}).isRequired,
|
|
1041
1073
|
fields: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
|
|
1042
1074
|
name: PropTypes__default["default"].string.isRequired,
|
|
@@ -32,6 +32,7 @@ import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array
|
|
|
32
32
|
import _flatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/flat';
|
|
33
33
|
import _flatMapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/flat-map';
|
|
34
34
|
import _Set from '@babel/runtime-corejs3/core-js-stable/set';
|
|
35
|
+
import _sortInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/sort';
|
|
35
36
|
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
36
37
|
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
37
38
|
import { actions, useAsyncDispatch } from '@commercetools-frontend/sdk';
|
|
@@ -372,7 +373,7 @@ function validate(_ref) {
|
|
|
372
373
|
}
|
|
373
374
|
|
|
374
375
|
function ownKeys$5(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
375
|
-
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
376
|
+
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var _context8, _context9; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context8 = ownKeys$5(Object(t), !0)).call(_context8, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context9 = ownKeys$5(Object(t))).call(_context9, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
376
377
|
function resourceTypeToDisplayName(_ref) {
|
|
377
378
|
let resourceType = _ref.resourceType,
|
|
378
379
|
_ref$isUpperCase = _ref.isUpperCase,
|
|
@@ -463,10 +464,32 @@ function extractGeneralFieldNames(generalFields) {
|
|
|
463
464
|
function extractCustomFieldNamesWithPrefix(customFields) {
|
|
464
465
|
const fields = _flatMapInstanceProperty(customFields).call(customFields, customType => {
|
|
465
466
|
var _context6;
|
|
466
|
-
return
|
|
467
|
+
return _flatMapInstanceProperty(_context6 = customType.fields).call(_context6, field => {
|
|
468
|
+
return getCustomFieldNameWithPrefix(field, customType.type.resourceTypeIds);
|
|
469
|
+
});
|
|
467
470
|
});
|
|
468
471
|
return [...new _Set(fields)];
|
|
469
472
|
}
|
|
473
|
+
function getCustomFieldNameWithPrefix(field, resourceTypeIds) {
|
|
474
|
+
const prefixes = _mapInstanceProperty(resourceTypeIds).call(resourceTypeIds, type => {
|
|
475
|
+
switch (type) {
|
|
476
|
+
case 'asset':
|
|
477
|
+
return 'assets.custom.fields.';
|
|
478
|
+
default:
|
|
479
|
+
return 'custom.fields.';
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
return _mapInstanceProperty(prefixes).call(prefixes, prefix => {
|
|
483
|
+
var _context7;
|
|
484
|
+
return _concatInstanceProperty(_context7 = "".concat(prefix)).call(_context7, field.name);
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Sorts an array of custom field names placing those starting with 'assets.custom.fields.' first
|
|
489
|
+
// This function doesn't affect the order of other custom fields
|
|
490
|
+
function sortCustomFields(fields) {
|
|
491
|
+
return _sortInstanceProperty(fields).call(fields, (a, b) => _startsWithInstanceProperty(b).call(b, 'assets.custom.fields.') - _startsWithInstanceProperty(a).call(a, 'assets.custom.fields.'));
|
|
492
|
+
}
|
|
470
493
|
|
|
471
494
|
// TODO: remove this function when filters are passed directly from parent views
|
|
472
495
|
// This function is temporary and will be removed in the future
|
|
@@ -478,16 +501,23 @@ function tmpBuildFilters(selectedResourceIds) {
|
|
|
478
501
|
return ["id in (".concat(formattedIds, ")")];
|
|
479
502
|
}
|
|
480
503
|
|
|
504
|
+
const parentKeyExtension = ['parent.key', 'parent.typeId'];
|
|
505
|
+
const customFieldsExtension = ['custom.type.key', 'custom.type.typeId'];
|
|
506
|
+
const assetsCustomFieldsExtension = ['assets.custom.type.key', 'assets.custom.type.typeId'];
|
|
507
|
+
const assetsExtension = ['assets.key', 'assets.name', 'assets.sources.key', 'assets.sources.uri', 'assets.sources.contentType', 'assets.sources.dimensions.w', 'assets.sources.dimensions.h', 'assets.description', 'assets.tags'];
|
|
481
508
|
const categoryFieldExtension = fields => {
|
|
482
509
|
return _reduceInstanceProperty(fields).call(fields, (acc, field) => {
|
|
483
510
|
if (field === 'parent.key') {
|
|
484
|
-
return [...acc,
|
|
511
|
+
return [...acc, ...parentKeyExtension];
|
|
485
512
|
}
|
|
486
513
|
if (_startsWithInstanceProperty(field).call(field, 'custom.fields.') && !_includesInstanceProperty(acc).call(acc, 'custom.type.key')) {
|
|
487
|
-
return [...acc,
|
|
514
|
+
return [...acc, ...customFieldsExtension, field];
|
|
488
515
|
}
|
|
489
516
|
if (field === 'assets') {
|
|
490
|
-
return [...acc,
|
|
517
|
+
return [...acc, ...assetsExtension];
|
|
518
|
+
}
|
|
519
|
+
if (_startsWithInstanceProperty(field).call(field, 'assets.custom.fields.') && !_includesInstanceProperty(acc).call(acc, 'assets.custom.type.key')) {
|
|
520
|
+
return [...acc, ...assetsCustomFieldsExtension, field];
|
|
491
521
|
}
|
|
492
522
|
return [...acc, field];
|
|
493
523
|
}, []);
|
|
@@ -585,7 +615,7 @@ const useStartExportOperation = props => {
|
|
|
585
615
|
const selectedGeneralFields = getSelectedGeneralFields(values.fields);
|
|
586
616
|
const selectedCustomFields = getSelectedCustomFields(values.customFields);
|
|
587
617
|
const generalFields = extractGeneralFieldNames(selectedGeneralFields);
|
|
588
|
-
const customFields = extractCustomFieldNamesWithPrefix(selectedCustomFields);
|
|
618
|
+
const customFields = sortCustomFields(extractCustomFieldNamesWithPrefix(selectedCustomFields));
|
|
589
619
|
const filters = tmpBuildFilters(props.selectedResourceIds);
|
|
590
620
|
const response = await createExportOperation({
|
|
591
621
|
projectKey,
|
|
@@ -1013,7 +1043,8 @@ const ExportResourcesModalShape = PropTypes.shape({
|
|
|
1013
1043
|
customFields: PropTypes.shape({
|
|
1014
1044
|
type: PropTypes.shape({
|
|
1015
1045
|
key: PropTypes.string.isRequired,
|
|
1016
|
-
label: PropTypes.string.isRequired
|
|
1046
|
+
label: PropTypes.string.isRequired,
|
|
1047
|
+
resourceTypeIds: PropTypes.arrayOf(PropTypes.string)
|
|
1017
1048
|
}).isRequired,
|
|
1018
1049
|
fields: PropTypes.arrayOf(PropTypes.shape({
|
|
1019
1050
|
name: PropTypes.string.isRequired,
|
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": "3.
|
|
4
|
+
"version": "3.6.0",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@commercetools-frontend/jest-preset-mc-app": "22.23.3",
|
|
39
39
|
"@commercetools-frontend/sdk": "22.23.3",
|
|
40
40
|
"@commercetools-frontend/sentry": "22.23.3",
|
|
41
|
-
"@commercetools-frontend/ui-kit": "19.
|
|
42
|
-
"@commercetools-uikit/design-system": "19.
|
|
41
|
+
"@commercetools-frontend/ui-kit": "19.1.0",
|
|
42
|
+
"@commercetools-uikit/design-system": "19.1.0",
|
|
43
43
|
"@preconstruct/cli": "2.8.3",
|
|
44
44
|
"rimraf": "5.0.5"
|
|
45
45
|
},
|