@commercetools-frontend-extensions/export-resources-modal 0.0.0-canary-20240507102123
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/LICENSE +29 -0
- package/README.md +283 -0
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.dev.js +1258 -0
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.js +7 -0
- package/dist/commercetools-frontend-extensions-export-resources-modal.cjs.prod.js +1241 -0
- package/dist/commercetools-frontend-extensions-export-resources-modal.esm.js +1219 -0
- package/package.json +71 -0
|
@@ -0,0 +1,1241 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
6
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
7
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
8
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
9
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
10
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
11
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
12
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
13
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
14
|
+
var uiKit = require('@commercetools-frontend/ui-kit');
|
|
15
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
16
|
+
require('@commercetools-uikit/design-system');
|
|
17
|
+
var reactIntl = require('react-intl');
|
|
18
|
+
var _valuesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/values');
|
|
19
|
+
var applicationComponents = require('@commercetools-frontend/application-components');
|
|
20
|
+
var applicationShellConnectors = require('@commercetools-frontend/application-shell-connectors');
|
|
21
|
+
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
22
|
+
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
23
|
+
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
24
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
25
|
+
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
26
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
27
|
+
var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
|
|
28
|
+
var React = require('react');
|
|
29
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
30
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
31
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
32
|
+
var moment = require('moment');
|
|
33
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
34
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
35
|
+
var omitEmpty = require('omit-empty-es');
|
|
36
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
37
|
+
var _flatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat');
|
|
38
|
+
var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
|
|
39
|
+
var _sortInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/sort');
|
|
40
|
+
require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
41
|
+
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/index-of');
|
|
42
|
+
var sdk = require('@commercetools-frontend/sdk');
|
|
43
|
+
var actionsGlobal = require('@commercetools-frontend/actions-global');
|
|
44
|
+
var constants = require('@commercetools-frontend/constants');
|
|
45
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
46
|
+
var _styled = require('@emotion/styled/base');
|
|
47
|
+
var _everyInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/every');
|
|
48
|
+
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
49
|
+
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
50
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
51
|
+
var throttle = require('lodash/throttle');
|
|
52
|
+
var react = require('@emotion/react');
|
|
53
|
+
var get = require('lodash/get');
|
|
54
|
+
require('prop-types');
|
|
55
|
+
var formik = require('formik');
|
|
56
|
+
|
|
57
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
58
|
+
|
|
59
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
60
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
61
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
62
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
63
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
64
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
65
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
66
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
67
|
+
var _valuesInstanceProperty__default = /*#__PURE__*/_interopDefault(_valuesInstanceProperty);
|
|
68
|
+
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
69
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
70
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
71
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
72
|
+
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
73
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
74
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
75
|
+
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
76
|
+
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
77
|
+
var _flatInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatInstanceProperty);
|
|
78
|
+
var _Set__default = /*#__PURE__*/_interopDefault(_Set);
|
|
79
|
+
var _sortInstanceProperty__default = /*#__PURE__*/_interopDefault(_sortInstanceProperty);
|
|
80
|
+
var _indexOfInstanceProperty__default = /*#__PURE__*/_interopDefault(_indexOfInstanceProperty);
|
|
81
|
+
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
82
|
+
var _everyInstanceProperty__default = /*#__PURE__*/_interopDefault(_everyInstanceProperty);
|
|
83
|
+
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
84
|
+
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
85
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
86
|
+
var throttle__default = /*#__PURE__*/_interopDefault(throttle);
|
|
87
|
+
var get__default = /*#__PURE__*/_interopDefault(get);
|
|
88
|
+
|
|
89
|
+
function getBold(msg) {
|
|
90
|
+
return jsxRuntime.jsx(uiKit.Text.Body, {
|
|
91
|
+
as: "span",
|
|
92
|
+
isBold: true,
|
|
93
|
+
children: msg
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getNewLine() {
|
|
98
|
+
return jsxRuntime.jsx("br", {});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var messages = reactIntl.defineMessages({
|
|
102
|
+
modalTitle: {
|
|
103
|
+
id: 'ExportResourcesModal.modalTitle',
|
|
104
|
+
description: 'Label for the modal title',
|
|
105
|
+
defaultMessage: 'Export {resourceType}'
|
|
106
|
+
},
|
|
107
|
+
outputFormat: {
|
|
108
|
+
id: 'ExportResourcesModal.outputFormat',
|
|
109
|
+
description: 'File format like (csv, xls, ...etc)',
|
|
110
|
+
defaultMessage: 'File format'
|
|
111
|
+
},
|
|
112
|
+
fileName: {
|
|
113
|
+
id: 'ExportResourcesModal.fileName',
|
|
114
|
+
description: 'exported file name',
|
|
115
|
+
defaultMessage: 'File name'
|
|
116
|
+
},
|
|
117
|
+
locale: {
|
|
118
|
+
id: 'ExportResourcesModal.locale',
|
|
119
|
+
description: 'Locale',
|
|
120
|
+
defaultMessage: 'Locale'
|
|
121
|
+
},
|
|
122
|
+
exportSelection: {
|
|
123
|
+
id: 'ExportResourcesModal.exportSelection',
|
|
124
|
+
description: 'Export selection',
|
|
125
|
+
defaultMessage: 'Export selection'
|
|
126
|
+
},
|
|
127
|
+
exportAllResources: {
|
|
128
|
+
id: 'ExportResourcesModal.exportAllResources',
|
|
129
|
+
description: 'Export All selection',
|
|
130
|
+
defaultMessage: 'Export all {resourceType} ({count})'
|
|
131
|
+
},
|
|
132
|
+
exportOnlySelectedResources: {
|
|
133
|
+
id: 'ExportResourcesModal.exportOnlySelectedResources',
|
|
134
|
+
description: 'Export only selected resources',
|
|
135
|
+
defaultMessage: 'Export selected {resourceType} ({count})'
|
|
136
|
+
},
|
|
137
|
+
exportAllMessage: {
|
|
138
|
+
id: 'ExportResourcesModal.exportAllMessage',
|
|
139
|
+
description: 'All resources will be exported',
|
|
140
|
+
defaultMessage: 'All <b>{count}</b> {resourceType} will be exported.'
|
|
141
|
+
},
|
|
142
|
+
exportMatchingMessage: {
|
|
143
|
+
id: 'ExportResourcesModal.exportMatchingMessage',
|
|
144
|
+
description: 'resources will be exported',
|
|
145
|
+
defaultMessage: '<b>{count}</b> {resourceType} will be exported.'
|
|
146
|
+
},
|
|
147
|
+
exportSelectedMessage: {
|
|
148
|
+
id: 'ExportResourcesModal.exportSelectedMessage',
|
|
149
|
+
description: 'resources are selected and will be exported',
|
|
150
|
+
defaultMessage: '<b>{count}</b> {resourceType} are selected and will be exported.'
|
|
151
|
+
},
|
|
152
|
+
exportBasedOnMyViewsMessage: {
|
|
153
|
+
id: 'ExportResourcesModal.exportBasedOnMyViewsMessage',
|
|
154
|
+
description: 'Select Export setttings based on my views',
|
|
155
|
+
defaultMessage: 'Select export settings based on:'
|
|
156
|
+
},
|
|
157
|
+
propertiesPanelLabel: {
|
|
158
|
+
id: 'ExportResourcesModal.propertiesPanelLabel',
|
|
159
|
+
description: 'properties panel label',
|
|
160
|
+
defaultMessage: 'Properties'
|
|
161
|
+
},
|
|
162
|
+
exportOperationSuccessMessage: {
|
|
163
|
+
id: 'ExportResourcesModal.exportOperationSuccessMessage',
|
|
164
|
+
description: 'Success message',
|
|
165
|
+
defaultMessage: '<b>Your export has started.</b> <newline></newline><logsLink>Go to Export logs</logsLink> to view the progress and download the file.'
|
|
166
|
+
},
|
|
167
|
+
nothingApplied: {
|
|
168
|
+
id: 'ExportResourcesModal.nothingApplied',
|
|
169
|
+
description: 'Shown when there is no filter applied',
|
|
170
|
+
defaultMessage: 'nothing applied'
|
|
171
|
+
},
|
|
172
|
+
selectAllLocales: {
|
|
173
|
+
id: 'ExportResourcesModal.selectAllLocales',
|
|
174
|
+
description: 'label for "Select all locales" checkbox',
|
|
175
|
+
defaultMessage: 'Select all locales'
|
|
176
|
+
},
|
|
177
|
+
missingFileNameError: {
|
|
178
|
+
id: 'ExportResourcesModal.missingFileNameError',
|
|
179
|
+
description: 'Error when file name field is missing',
|
|
180
|
+
defaultMessage: 'Please enter a file name'
|
|
181
|
+
},
|
|
182
|
+
invalidFileNameError: {
|
|
183
|
+
id: 'ExportResourcesModal.invalidFileNameError',
|
|
184
|
+
description: 'Error when file name field is not valid',
|
|
185
|
+
defaultMessage: 'File name may only contain alphanumeric characters, hyphens and underscores'
|
|
186
|
+
},
|
|
187
|
+
missingLocaleError: {
|
|
188
|
+
id: 'ExportResourcesModal.missingLocaleError',
|
|
189
|
+
description: 'Error when no locale is selected',
|
|
190
|
+
defaultMessage: 'Please select at least one locale'
|
|
191
|
+
},
|
|
192
|
+
myViews: {
|
|
193
|
+
id: 'ExportResourcesModal.myViews',
|
|
194
|
+
description: 'Label for "My Views" Select Field',
|
|
195
|
+
defaultMessage: 'My Views'
|
|
196
|
+
},
|
|
197
|
+
selectFieldsToExport: {
|
|
198
|
+
id: 'ExportResourcesModal.selectFieldsToExport',
|
|
199
|
+
defaultMessage: 'Select fields to export'
|
|
200
|
+
},
|
|
201
|
+
back: {
|
|
202
|
+
id: 'ExportResourcesModal.back',
|
|
203
|
+
description: 'Label for "Back" button',
|
|
204
|
+
defaultMessage: 'Back'
|
|
205
|
+
},
|
|
206
|
+
startExport: {
|
|
207
|
+
id: 'ExportResourcesModal.startExport',
|
|
208
|
+
description: 'Label for "Start export" button',
|
|
209
|
+
defaultMessage: 'Start export'
|
|
210
|
+
},
|
|
211
|
+
continue: {
|
|
212
|
+
id: 'ExportResourcesModal.continue',
|
|
213
|
+
description: 'Label for "Continue" button',
|
|
214
|
+
defaultMessage: 'Continue'
|
|
215
|
+
},
|
|
216
|
+
fieldDefinitions: {
|
|
217
|
+
id: 'ExportResourcesModal.fieldDefinitions',
|
|
218
|
+
description: 'Label for "Field definitions" link',
|
|
219
|
+
defaultMessage: 'Field definitions'
|
|
220
|
+
},
|
|
221
|
+
allGeneralFields: {
|
|
222
|
+
id: 'ExportResourcesModal.allGeneralFields',
|
|
223
|
+
description: 'Label for "All general fields" checkbox',
|
|
224
|
+
defaultMessage: 'All general fields'
|
|
225
|
+
},
|
|
226
|
+
allCustomFields: {
|
|
227
|
+
id: 'ExportResourcesModal.allCustomFields',
|
|
228
|
+
description: 'Label for "All custom fields" checkbox',
|
|
229
|
+
defaultMessage: 'All custom fields'
|
|
230
|
+
},
|
|
231
|
+
customTypeKeyAndTypeId: {
|
|
232
|
+
id: 'ExportResourcesModal.customTypeKeyAndTypeId',
|
|
233
|
+
description: 'Label for "Custom type key and typeId" checkbox',
|
|
234
|
+
defaultMessage: 'Custom type key and typeId'
|
|
235
|
+
},
|
|
236
|
+
unexpectedError: {
|
|
237
|
+
id: 'ExportResourcesModal.unexpectedError',
|
|
238
|
+
description: 'Generic notification message when starting export process fails',
|
|
239
|
+
defaultMessage: 'An error occurred while starting the export process. Please try again or contact support if the problem persists.'
|
|
240
|
+
},
|
|
241
|
+
searchForFields: {
|
|
242
|
+
id: 'ExportResourcesModal.searchForFields',
|
|
243
|
+
description: 'Placeholder for "Search for fields" search input',
|
|
244
|
+
defaultMessage: 'Search for fields'
|
|
245
|
+
},
|
|
246
|
+
thereAreNoResults: {
|
|
247
|
+
id: 'ExportResourcesModal.thereAreNoResults',
|
|
248
|
+
description: 'No search results message',
|
|
249
|
+
defaultMessage: 'There are no results that match your search.'
|
|
250
|
+
},
|
|
251
|
+
suggestions: {
|
|
252
|
+
id: 'ExportResourcesModal.suggestions',
|
|
253
|
+
description: 'In Export fields selection - Suggestions message',
|
|
254
|
+
defaultMessage: 'Suggestions:'
|
|
255
|
+
},
|
|
256
|
+
checkTheSpelling: {
|
|
257
|
+
id: 'ExportResourcesModal.checkTheSpelling',
|
|
258
|
+
description: 'In Export fields selection - Check the spelling message',
|
|
259
|
+
defaultMessage: 'Check the spelling.'
|
|
260
|
+
},
|
|
261
|
+
searchByEnteringTheExactFieldName: {
|
|
262
|
+
id: 'ExportResourcesModal.searchByEnteringTheExactFieldName',
|
|
263
|
+
description: 'In Export fields selection - Search by entering the exact field name message',
|
|
264
|
+
defaultMessage: 'Try searching by entering the exact field name.'
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
function ownKeys$6(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
269
|
+
function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$6(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$6(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
270
|
+
function renderFileNameError(key) {
|
|
271
|
+
switch (key) {
|
|
272
|
+
case 'missing':
|
|
273
|
+
return jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$6({}, messages.missingFileNameError));
|
|
274
|
+
case 'invalidInput':
|
|
275
|
+
return jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$6({}, messages.invalidFileNameError));
|
|
276
|
+
default:
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function renderLocaleError(key) {
|
|
281
|
+
switch (key) {
|
|
282
|
+
case 'missing':
|
|
283
|
+
return jsxRuntime.jsx(reactIntl.FormattedMessage, _objectSpread$6({}, messages.missingLocaleError));
|
|
284
|
+
default:
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const Z_INDEX_DROPDOWN = 30000;
|
|
290
|
+
|
|
291
|
+
const EXPORT_OPERATION_STATES = {
|
|
292
|
+
PROCESSING: 'processing',
|
|
293
|
+
COMPLETED: 'completed',
|
|
294
|
+
FAILED: 'failed'
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const EXPORT_TYPES = {
|
|
298
|
+
ALL: 'all',
|
|
299
|
+
FILTERED: 'filtered',
|
|
300
|
+
SELECTED: 'selected'
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const EXPORTABLE_RESOURCES = {
|
|
304
|
+
CATEGORY: 'category',
|
|
305
|
+
PRODUCT: 'product',
|
|
306
|
+
DISCOUNT_CODE: 'discountCode'
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const OUTPUT_FORMATS = {
|
|
310
|
+
JSON: 'json',
|
|
311
|
+
CSV: 'csv'
|
|
312
|
+
};
|
|
313
|
+
const OUTPUT_FORMAT_OPTIONS = [{
|
|
314
|
+
value: OUTPUT_FORMATS.CSV,
|
|
315
|
+
label: 'CSV'
|
|
316
|
+
}, {
|
|
317
|
+
value: OUTPUT_FORMATS.JSON,
|
|
318
|
+
label: 'JSON'
|
|
319
|
+
}];
|
|
320
|
+
|
|
321
|
+
const FIELD_DEFINITIONS_URLS = {
|
|
322
|
+
category: 'https://docs.commercetools.com/merchant-center/import-categories#supported-headers-and-values'
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
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); }; }
|
|
326
|
+
function _isNativeReflectConstruct$4() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$4 = function () { return !!t; })(); }
|
|
327
|
+
let UnexpectedExportTypeError = /*#__PURE__*/function (_Error) {
|
|
328
|
+
_inherits(UnexpectedExportTypeError, _Error);
|
|
329
|
+
var _super = _createSuper$4(UnexpectedExportTypeError);
|
|
330
|
+
function UnexpectedExportTypeError(exportType) {
|
|
331
|
+
var _this;
|
|
332
|
+
_classCallCheck(this, UnexpectedExportTypeError);
|
|
333
|
+
_this = _super.call(this, "Unexpected export type: ".concat(exportType));
|
|
334
|
+
_this.name = 'UnexpectedExportTypeError';
|
|
335
|
+
return _this;
|
|
336
|
+
}
|
|
337
|
+
return _createClass(UnexpectedExportTypeError);
|
|
338
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
339
|
+
|
|
340
|
+
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); }; }
|
|
341
|
+
function _isNativeReflectConstruct$3() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$3 = function () { return !!t; })(); }
|
|
342
|
+
let MissingExportResourceProviderError = /*#__PURE__*/function (_Error) {
|
|
343
|
+
_inherits(MissingExportResourceProviderError, _Error);
|
|
344
|
+
var _super = _createSuper$3(MissingExportResourceProviderError);
|
|
345
|
+
function MissingExportResourceProviderError() {
|
|
346
|
+
var _this;
|
|
347
|
+
_classCallCheck(this, MissingExportResourceProviderError);
|
|
348
|
+
_this = _super.call(this, 'useExportResourcesContext must be used within ExportResourcesProvider');
|
|
349
|
+
_this.name = 'MissingExportResourceProviderError';
|
|
350
|
+
return _this;
|
|
351
|
+
}
|
|
352
|
+
return _createClass(MissingExportResourceProviderError);
|
|
353
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
354
|
+
|
|
355
|
+
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); }; }
|
|
356
|
+
function _isNativeReflectConstruct$2() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$2 = function () { return !!t; })(); }
|
|
357
|
+
let UnexpectedExportOperationStateError = /*#__PURE__*/function (_Error) {
|
|
358
|
+
_inherits(UnexpectedExportOperationStateError, _Error);
|
|
359
|
+
var _super = _createSuper$2(UnexpectedExportOperationStateError);
|
|
360
|
+
function UnexpectedExportOperationStateError(state) {
|
|
361
|
+
var _this;
|
|
362
|
+
_classCallCheck(this, UnexpectedExportOperationStateError);
|
|
363
|
+
_this = _super.call(this, "Unexpected export operation state \"".concat(state, "\""));
|
|
364
|
+
_this.name = 'UnexpectedExportOperationStateError';
|
|
365
|
+
return _this;
|
|
366
|
+
}
|
|
367
|
+
return _createClass(UnexpectedExportOperationStateError);
|
|
368
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
369
|
+
|
|
370
|
+
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); }; }
|
|
371
|
+
function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function () { return !!t; })(); }
|
|
372
|
+
let UnexpectedResourceTypeError = /*#__PURE__*/function (_Error) {
|
|
373
|
+
_inherits(UnexpectedResourceTypeError, _Error);
|
|
374
|
+
var _super = _createSuper$1(UnexpectedResourceTypeError);
|
|
375
|
+
function UnexpectedResourceTypeError(resourceType) {
|
|
376
|
+
var _this;
|
|
377
|
+
_classCallCheck(this, UnexpectedResourceTypeError);
|
|
378
|
+
_this = _super.call(this, "Unexpected resource type: ".concat(resourceType));
|
|
379
|
+
_this.name = 'UnexpectedResourceTypeError';
|
|
380
|
+
return _this;
|
|
381
|
+
}
|
|
382
|
+
return _createClass(UnexpectedResourceTypeError);
|
|
383
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
384
|
+
|
|
385
|
+
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); }; }
|
|
386
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
387
|
+
let InvalidResponseError = /*#__PURE__*/function (_Error) {
|
|
388
|
+
_inherits(InvalidResponseError, _Error);
|
|
389
|
+
var _super = _createSuper(InvalidResponseError);
|
|
390
|
+
function InvalidResponseError(message) {
|
|
391
|
+
var _this;
|
|
392
|
+
_classCallCheck(this, InvalidResponseError);
|
|
393
|
+
_this = _super.call(this, message);
|
|
394
|
+
_this.name = 'InvalidResponseError';
|
|
395
|
+
return _this;
|
|
396
|
+
}
|
|
397
|
+
return _createClass(InvalidResponseError);
|
|
398
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
399
|
+
|
|
400
|
+
function useExportResourcesContext() {
|
|
401
|
+
const context = React.useContext(ExportResourcesContext);
|
|
402
|
+
if (!context) {
|
|
403
|
+
throw new MissingExportResourceProviderError();
|
|
404
|
+
}
|
|
405
|
+
return context;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function checkAtLeastOneFieldChecked$1(fields) {
|
|
409
|
+
return _someInstanceProperty__default["default"](fields).call(fields, field => {
|
|
410
|
+
if (field.fields) {
|
|
411
|
+
return field.isChecked || checkAtLeastOneFieldChecked$1(field.fields);
|
|
412
|
+
}
|
|
413
|
+
return field.isChecked;
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function validate(_ref) {
|
|
417
|
+
let values = _valuesInstanceProperty__default["default"](_ref),
|
|
418
|
+
step = _ref.step;
|
|
419
|
+
const fileName = values.fileName,
|
|
420
|
+
locales = values.locales,
|
|
421
|
+
groups = values.groups;
|
|
422
|
+
const errors = {
|
|
423
|
+
fileName: {},
|
|
424
|
+
locales: {},
|
|
425
|
+
fields: {}
|
|
426
|
+
};
|
|
427
|
+
if (uiKit.TextInput.isEmpty(fileName)) {
|
|
428
|
+
// @ts-ignore
|
|
429
|
+
errors.fileName.missing = true;
|
|
430
|
+
} else if (!/^[a-zA-Z0-9-_.]+$/.test(fileName)) {
|
|
431
|
+
// @ts-ignore
|
|
432
|
+
errors.fileName.invalidInput = true;
|
|
433
|
+
}
|
|
434
|
+
if (locales.length < 1) {
|
|
435
|
+
// @ts-ignore
|
|
436
|
+
errors.locales.missing = true;
|
|
437
|
+
}
|
|
438
|
+
if (step === 2) {
|
|
439
|
+
const allFields = _reduceInstanceProperty__default["default"](groups).call(groups, (acc, group) => _concatInstanceProperty__default["default"](acc).call(acc, group.fields), []);
|
|
440
|
+
const checkedFieldsCount = _filterInstanceProperty__default["default"](allFields).call(allFields, field => {
|
|
441
|
+
if (field.fields) return checkAtLeastOneFieldChecked$1(field.fields);
|
|
442
|
+
return !field.isRequired && !field.isReadOnly && field.isChecked;
|
|
443
|
+
}).length;
|
|
444
|
+
if (checkedFieldsCount < 1) {
|
|
445
|
+
// @ts-ignore
|
|
446
|
+
errors.fields.missing = true;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return omitEmpty__default["default"](errors);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
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; }
|
|
453
|
+
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var _context5, _context6; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context5 = ownKeys$5(Object(t), !0)).call(_context5, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context6 = ownKeys$5(Object(t))).call(_context6, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
454
|
+
function resourceTypeToDisplayName(_ref) {
|
|
455
|
+
let resourceType = _ref.resourceType,
|
|
456
|
+
_ref$isUpperCase = _ref.isUpperCase,
|
|
457
|
+
isUpperCase = _ref$isUpperCase === void 0 ? false : _ref$isUpperCase,
|
|
458
|
+
_ref$isPlural = _ref.isPlural,
|
|
459
|
+
isPlural = _ref$isPlural === void 0 ? false : _ref$isPlural;
|
|
460
|
+
let displayName;
|
|
461
|
+
switch (resourceType) {
|
|
462
|
+
case EXPORTABLE_RESOURCES.CATEGORY:
|
|
463
|
+
displayName = isPlural ? 'Categories' : 'Category';
|
|
464
|
+
break;
|
|
465
|
+
case EXPORTABLE_RESOURCES.PRODUCT:
|
|
466
|
+
displayName = isPlural ? 'Products' : 'Product';
|
|
467
|
+
break;
|
|
468
|
+
case EXPORTABLE_RESOURCES.DISCOUNT_CODE:
|
|
469
|
+
displayName = isPlural ? 'Discount codes' : 'Discount code';
|
|
470
|
+
break;
|
|
471
|
+
default:
|
|
472
|
+
throw UnexpectedResourceTypeError(resourceType);
|
|
473
|
+
}
|
|
474
|
+
return isUpperCase ? displayName : displayName.toLowerCase();
|
|
475
|
+
}
|
|
476
|
+
function mapLocalesToOptions(locales) {
|
|
477
|
+
return _mapInstanceProperty__default["default"](locales).call(locales, locale => ({
|
|
478
|
+
value: locale,
|
|
479
|
+
label: locale
|
|
480
|
+
}));
|
|
481
|
+
}
|
|
482
|
+
function isFilledArray(maybeArray) {
|
|
483
|
+
return _Array$isArray__default["default"](maybeArray) && maybeArray.length;
|
|
484
|
+
}
|
|
485
|
+
function appendCsvOrJsonExtensionIfAbsent(fileName, fileFormat) {
|
|
486
|
+
var _context;
|
|
487
|
+
const extensionRegex = /\.(csv|json)$/i;
|
|
488
|
+
if (!extensionRegex.test(fileName)) return _concatInstanceProperty__default["default"](_context = "".concat(fileName, ".")).call(_context, fileFormat);
|
|
489
|
+
return fileName;
|
|
490
|
+
}
|
|
491
|
+
function flattenNestedFields(fields) {
|
|
492
|
+
const result = (fields === null || fields === void 0 ? void 0 : _mapInstanceProperty__default["default"](fields).call(fields, field => {
|
|
493
|
+
if (isFilledArray(field.fields)) {
|
|
494
|
+
var _context2;
|
|
495
|
+
return _mapInstanceProperty__default["default"](_context2 = flattenNestedFields(field.fields)).call(_context2, nestedField => {
|
|
496
|
+
var _context3;
|
|
497
|
+
return _objectSpread$5(_objectSpread$5({}, nestedField), {}, {
|
|
498
|
+
name: _concatInstanceProperty__default["default"](_context3 = "".concat(field.name, ".")).call(_context3, nestedField.name)
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
return field;
|
|
503
|
+
})) || [];
|
|
504
|
+
return _flatInstanceProperty__default["default"](result).call(result);
|
|
505
|
+
}
|
|
506
|
+
function checkRequiredFields(fields) {
|
|
507
|
+
return _mapInstanceProperty__default["default"](fields).call(fields, field => field.isRequired ? _objectSpread$5(_objectSpread$5({}, field), {}, {
|
|
508
|
+
isChecked: true
|
|
509
|
+
}) : field);
|
|
510
|
+
}
|
|
511
|
+
function getExportLogsLink(projectKey, msg) {
|
|
512
|
+
return jsxRuntime.jsx(uiKit.Link, {
|
|
513
|
+
to: "/".concat(projectKey, "/operations/export/logs"),
|
|
514
|
+
children: msg
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
function setInitialCheckedStateForCustomFields(customFields) {
|
|
518
|
+
return _mapInstanceProperty__default["default"](customFields).call(customFields, customType => {
|
|
519
|
+
var _context4;
|
|
520
|
+
return _objectSpread$5(_objectSpread$5({}, customType), {}, {
|
|
521
|
+
fields: _mapInstanceProperty__default["default"](_context4 = customType.fields).call(_context4, field => _objectSpread$5(_objectSpread$5({}, field), {}, {
|
|
522
|
+
isChecked: false
|
|
523
|
+
}))
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
const extractFieldNamesAndAdditionalFieldExtensions = fields => {
|
|
528
|
+
const result = _reduceInstanceProperty__default["default"](fields).call(fields, (acc, field) => {
|
|
529
|
+
if (field.additionalFieldExtensions) {
|
|
530
|
+
return [...acc, ...field.additionalFieldExtensions, field.name];
|
|
531
|
+
}
|
|
532
|
+
return [...acc, field.name];
|
|
533
|
+
}, []);
|
|
534
|
+
return [...new _Set__default["default"](result)];
|
|
535
|
+
};
|
|
536
|
+
function sortFieldsByFieldOrder(_ref2) {
|
|
537
|
+
let fields = _ref2.fields,
|
|
538
|
+
fieldOrder = _ref2.fieldOrder;
|
|
539
|
+
if (isFilledArray(fieldOrder)) {
|
|
540
|
+
return _sortInstanceProperty__default["default"](fields).call(fields, (a, b) => {
|
|
541
|
+
let orderA = _indexOfInstanceProperty__default["default"](fieldOrder).call(fieldOrder, a) !== -1 ? _indexOfInstanceProperty__default["default"](fieldOrder).call(fieldOrder, a) : _indexOfInstanceProperty__default["default"](fieldOrder).call(fieldOrder, a.split('.')[0]);
|
|
542
|
+
let orderB = _indexOfInstanceProperty__default["default"](fieldOrder).call(fieldOrder, b) !== -1 ? _indexOfInstanceProperty__default["default"](fieldOrder).call(fieldOrder, b) : _indexOfInstanceProperty__default["default"](fieldOrder).call(fieldOrder, b.split('.')[0]);
|
|
543
|
+
|
|
544
|
+
// If a field is not 'custom',then consider it as '*'
|
|
545
|
+
orderA = orderA === -1 ? _indexOfInstanceProperty__default["default"](fieldOrder).call(fieldOrder, '*') : orderA;
|
|
546
|
+
orderB = orderB === -1 ? _indexOfInstanceProperty__default["default"](fieldOrder).call(fieldOrder, '*') : orderB;
|
|
547
|
+
return orderA - orderB;
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
return fields;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// TODO: remove this function when filters are passed directly from parent views
|
|
554
|
+
// This function is temporary and will be removed in the future
|
|
555
|
+
// Later, filters will be passed directly from parent views (category, product...) instead of being built within the Export resources modal
|
|
556
|
+
// The `selectedResourceIds` prop will also be removed
|
|
557
|
+
function tmpBuildFilters(selectedResourceIds) {
|
|
558
|
+
if (!selectedResourceIds || (selectedResourceIds === null || selectedResourceIds === void 0 ? void 0 : selectedResourceIds.length) === 0) return undefined;
|
|
559
|
+
const formattedIds = _mapInstanceProperty__default["default"](selectedResourceIds).call(selectedResourceIds, id => "\"".concat(id, "\"")).join(', ');
|
|
560
|
+
return ["id in (".concat(formattedIds, ")")];
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
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; }
|
|
564
|
+
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$4(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$4(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
565
|
+
const updateFieldGroupsWithIsCheckedValue = groups => {
|
|
566
|
+
const updateFields = (fields, parentChecked) => {
|
|
567
|
+
return _mapInstanceProperty__default["default"](fields).call(fields, field => {
|
|
568
|
+
var _field$isRequired;
|
|
569
|
+
let isChecked = ((_field$isRequired = field.isRequired) !== null && _field$isRequired !== void 0 ? _field$isRequired : !field.isReadOnly && field.isSelectedByDefault) || parentChecked;
|
|
570
|
+
if (field.fields) {
|
|
571
|
+
const updatedFields = updateFields(field.fields, isChecked);
|
|
572
|
+
isChecked = false;
|
|
573
|
+
field.fields = updatedFields;
|
|
574
|
+
}
|
|
575
|
+
return _objectSpread$4(_objectSpread$4({}, field), {}, {
|
|
576
|
+
isChecked
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
};
|
|
580
|
+
return _mapInstanceProperty__default["default"](groups).call(groups, group => {
|
|
581
|
+
const updatedFields = updateFields(group.fields, false);
|
|
582
|
+
return _objectSpread$4(_objectSpread$4({}, group), {}, {
|
|
583
|
+
fields: updatedFields
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
};
|
|
587
|
+
const updateFieldGroupWithAdditionalFieldExtensions = groups => {
|
|
588
|
+
function updateAdditionalFieldExtensions(fields, additionalFieldExtensions) {
|
|
589
|
+
return _mapInstanceProperty__default["default"](fields).call(fields, field => {
|
|
590
|
+
const updatedAdditionalFieldExtensions = [...additionalFieldExtensions, ...(field.additionalFieldExtensions || [])];
|
|
591
|
+
if (field.fields) {
|
|
592
|
+
field.fields = updateAdditionalFieldExtensions(field.fields, updatedAdditionalFieldExtensions);
|
|
593
|
+
}
|
|
594
|
+
return _objectSpread$4(_objectSpread$4({}, field), {}, {
|
|
595
|
+
additionalFieldExtensions: updatedAdditionalFieldExtensions
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
return _mapInstanceProperty__default["default"](groups).call(groups, group => {
|
|
600
|
+
return _objectSpread$4(_objectSpread$4({}, group), {}, {
|
|
601
|
+
fields: updateAdditionalFieldExtensions(group.fields, group.additionalFieldExtensions || [])
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
const _excluded = ["isSelectedByDefault"];
|
|
607
|
+
function ownKeys$3(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
608
|
+
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$3(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$3(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
609
|
+
const useInitialValues = props => {
|
|
610
|
+
var _context;
|
|
611
|
+
const todayFormatted = moment__default["default"]().format('DD-MM-YY_HH-mm');
|
|
612
|
+
const _useApplicationContex = applicationShellConnectors.useApplicationContext(applicationContext => ({
|
|
613
|
+
locale: applicationContext.dataLocale
|
|
614
|
+
})),
|
|
615
|
+
locale = _useApplicationContex.locale;
|
|
616
|
+
const fields = _mapInstanceProperty__default["default"](_context = flattenNestedFields(props.fields)).call(_context, _ref => {
|
|
617
|
+
let isSelectedByDefault = _ref.isSelectedByDefault,
|
|
618
|
+
field = _objectWithoutProperties(_ref, _excluded);
|
|
619
|
+
return _objectSpread$3(_objectSpread$3({}, field), {}, {
|
|
620
|
+
isChecked: isSelectedByDefault !== null && isSelectedByDefault !== void 0 ? isSelectedByDefault : true
|
|
621
|
+
});
|
|
622
|
+
});
|
|
623
|
+
const groups = updateFieldGroupsWithIsCheckedValue(props.fieldGroups);
|
|
624
|
+
return React__default["default"].useMemo(() => {
|
|
625
|
+
var _context2;
|
|
626
|
+
return {
|
|
627
|
+
outputFormat: props.outputFormat,
|
|
628
|
+
fileName: _concatInstanceProperty__default["default"](_context2 = "".concat(resourceTypeToDisplayName({
|
|
629
|
+
resourceType: props.resourceType,
|
|
630
|
+
isUpperCase: true,
|
|
631
|
+
isPlural: true
|
|
632
|
+
}), "_Export_")).call(_context2, todayFormatted),
|
|
633
|
+
locales: [locale],
|
|
634
|
+
fields: checkRequiredFields(fields),
|
|
635
|
+
customFields: setInitialCheckedStateForCustomFields(props.customFields),
|
|
636
|
+
groups: updateFieldGroupWithAdditionalFieldExtensions(groups)
|
|
637
|
+
};
|
|
638
|
+
}, [props, locale, todayFormatted, fields, groups]);
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
async function createExportOperation(_ref) {
|
|
642
|
+
let projectKey = _ref.projectKey,
|
|
643
|
+
resourceType = _ref.resourceType,
|
|
644
|
+
fileName = _ref.fileName,
|
|
645
|
+
fileFormat = _ref.fileFormat,
|
|
646
|
+
fields = _ref.fields,
|
|
647
|
+
locales = _ref.locales,
|
|
648
|
+
filters = _ref.filters,
|
|
649
|
+
asyncDispatchFn = _ref.asyncDispatchFn;
|
|
650
|
+
const uri = "/proxy/export/".concat(projectKey, "/export-operations");
|
|
651
|
+
const response = await asyncDispatchFn(sdk.actions.post({
|
|
652
|
+
// FIXME: EXPORT is undefined
|
|
653
|
+
mcApiProxyTarget: constants.MC_API_PROXY_TARGETS.EXPORT,
|
|
654
|
+
uri: uri,
|
|
655
|
+
headers: {
|
|
656
|
+
accept: 'application/json'
|
|
657
|
+
},
|
|
658
|
+
payload: {
|
|
659
|
+
resourceType,
|
|
660
|
+
fileName,
|
|
661
|
+
fileFormat,
|
|
662
|
+
fields,
|
|
663
|
+
locales,
|
|
664
|
+
filters
|
|
665
|
+
}
|
|
666
|
+
}));
|
|
667
|
+
if (!response.state) throw new InvalidResponseError('Invalid response');
|
|
668
|
+
return response;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const useStartExportOperation = props => {
|
|
672
|
+
const intl = reactIntl.useIntl();
|
|
673
|
+
const asyncDispatch = sdk.useAsyncDispatch();
|
|
674
|
+
const showNotification = actionsGlobal.useShowNotification();
|
|
675
|
+
const _useApplicationContex = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
676
|
+
var _applicationContext$p;
|
|
677
|
+
return {
|
|
678
|
+
locale: applicationContext.dataLocale,
|
|
679
|
+
projectKey: (_applicationContext$p = applicationContext.project) === null || _applicationContext$p === void 0 ? void 0 : _applicationContext$p.key
|
|
680
|
+
};
|
|
681
|
+
}),
|
|
682
|
+
projectKey = _useApplicationContex.projectKey;
|
|
683
|
+
const extractFieldsFromGroups = groups => {
|
|
684
|
+
let selectedGeneralFields = [];
|
|
685
|
+
const getSelectedFields = fields => {
|
|
686
|
+
return _filterInstanceProperty__default["default"](fields).call(fields, field => {
|
|
687
|
+
var _field$isChecked;
|
|
688
|
+
if (field.fields) {
|
|
689
|
+
return getSelectedFields(field.fields);
|
|
690
|
+
}
|
|
691
|
+
if (field.isChecked) selectedGeneralFields.push(field);
|
|
692
|
+
return (_field$isChecked = field.isChecked) !== null && _field$isChecked !== void 0 ? _field$isChecked : false;
|
|
693
|
+
});
|
|
694
|
+
};
|
|
695
|
+
_forEachInstanceProperty__default["default"](groups).call(groups, group => {
|
|
696
|
+
getSelectedFields(group.fields);
|
|
697
|
+
});
|
|
698
|
+
return sortFieldsByFieldOrder({
|
|
699
|
+
fields: extractFieldNamesAndAdditionalFieldExtensions(selectedGeneralFields),
|
|
700
|
+
fieldOrder: props.fieldOrder
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
const startExportOperation = async values => {
|
|
704
|
+
try {
|
|
705
|
+
const fields = extractFieldsFromGroups(values.groups);
|
|
706
|
+
const filters = tmpBuildFilters(props.selectedResourceIds);
|
|
707
|
+
const response = await createExportOperation({
|
|
708
|
+
projectKey,
|
|
709
|
+
resourceType: props.resourceType,
|
|
710
|
+
fileName: appendCsvOrJsonExtensionIfAbsent(values.fileName, values.outputFormat),
|
|
711
|
+
fileFormat: values.outputFormat,
|
|
712
|
+
locales: values.locales,
|
|
713
|
+
fields,
|
|
714
|
+
filters,
|
|
715
|
+
asyncDispatchFn: asyncDispatch
|
|
716
|
+
});
|
|
717
|
+
switch (response.state) {
|
|
718
|
+
case EXPORT_OPERATION_STATES.PROCESSING:
|
|
719
|
+
case EXPORT_OPERATION_STATES.COMPLETED:
|
|
720
|
+
showNotification({
|
|
721
|
+
kind: 'info',
|
|
722
|
+
domain: constants.DOMAINS.SIDE,
|
|
723
|
+
// @ts-ignore
|
|
724
|
+
text: intl.formatMessage(messages.exportOperationSuccessMessage, {
|
|
725
|
+
newline: getNewLine,
|
|
726
|
+
logsLink: msg => getExportLogsLink(projectKey, msg),
|
|
727
|
+
b: getBold
|
|
728
|
+
})
|
|
729
|
+
}, {
|
|
730
|
+
dismissAfter: 5000
|
|
731
|
+
});
|
|
732
|
+
if (typeof props.onExportSuccess === 'function') props.onExportSuccess();
|
|
733
|
+
break;
|
|
734
|
+
default:
|
|
735
|
+
throw new UnexpectedExportOperationStateError(response.state);
|
|
736
|
+
}
|
|
737
|
+
} catch (error) {
|
|
738
|
+
// TODO: custom error messages for each error type
|
|
739
|
+
showNotification({
|
|
740
|
+
text: intl.formatMessage(messages.unexpectedError),
|
|
741
|
+
kind: 'error',
|
|
742
|
+
domain: constants.DOMAINS.PAGE
|
|
743
|
+
});
|
|
744
|
+
} finally {
|
|
745
|
+
if (typeof props.onClose === 'function') props.onClose();
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
return {
|
|
749
|
+
startExportOperation
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
754
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$2(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
755
|
+
function ExportTextMessage() {
|
|
756
|
+
const intl = reactIntl.useIntl();
|
|
757
|
+
const _useExportResourcesCo = useExportResourcesContext(),
|
|
758
|
+
resourceType = _useExportResourcesCo.resourceType,
|
|
759
|
+
totalResourcesCount = _useExportResourcesCo.totalResourcesCount,
|
|
760
|
+
selectedResourceIds = _useExportResourcesCo.selectedResourceIds,
|
|
761
|
+
exportType = _useExportResourcesCo.exportType;
|
|
762
|
+
const resourceTypePlural = resourceTypeToDisplayName({
|
|
763
|
+
resourceType: resourceType,
|
|
764
|
+
isPlural: true
|
|
765
|
+
});
|
|
766
|
+
let message;
|
|
767
|
+
let count;
|
|
768
|
+
switch (exportType) {
|
|
769
|
+
case EXPORT_TYPES.ALL:
|
|
770
|
+
message = messages.exportAllMessage;
|
|
771
|
+
count = totalResourcesCount;
|
|
772
|
+
break;
|
|
773
|
+
case EXPORT_TYPES.SELECTED:
|
|
774
|
+
message = messages.exportSelectedMessage;
|
|
775
|
+
count = selectedResourceIds.length;
|
|
776
|
+
break;
|
|
777
|
+
default:
|
|
778
|
+
throw new UnexpectedExportTypeError(exportType);
|
|
779
|
+
}
|
|
780
|
+
return jsxRuntime.jsx(uiKit.Text.Body, {
|
|
781
|
+
"data-testid": "export-description",
|
|
782
|
+
intlMessage: _objectSpread$2(_objectSpread$2({}, message), {}, {
|
|
783
|
+
values: {
|
|
784
|
+
count: intl.formatNumber(count),
|
|
785
|
+
resourceType: resourceTypePlural,
|
|
786
|
+
b: getBold
|
|
787
|
+
}
|
|
788
|
+
})
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const ExportFileSettingsStep = () => {
|
|
793
|
+
const intl = reactIntl.useIntl();
|
|
794
|
+
const _useExportResourcesCo = useExportResourcesContext(),
|
|
795
|
+
formik = _useExportResourcesCo.formik,
|
|
796
|
+
resourceType = _useExportResourcesCo.resourceType,
|
|
797
|
+
onClose = _useExportResourcesCo.onClose;
|
|
798
|
+
const resourceTypePlural = resourceTypeToDisplayName({
|
|
799
|
+
resourceType: resourceType,
|
|
800
|
+
isPlural: true
|
|
801
|
+
});
|
|
802
|
+
const _useApplicationContex = applicationShellConnectors.useApplicationContext(applicationContext => {
|
|
803
|
+
var _applicationContext$p;
|
|
804
|
+
return {
|
|
805
|
+
locale: applicationContext.dataLocale,
|
|
806
|
+
locales: ((_applicationContext$p = applicationContext.project) === null || _applicationContext$p === void 0 ? void 0 : _applicationContext$p.languages) || []
|
|
807
|
+
};
|
|
808
|
+
}),
|
|
809
|
+
locales = _useApplicationContex.locales,
|
|
810
|
+
locale = _useApplicationContex.locale;
|
|
811
|
+
const areAllLocalesChecked = _valuesInstanceProperty__default["default"](formik).locales.length === locales.length;
|
|
812
|
+
return jsxRuntime.jsx(applicationComponents.FormDialog, {
|
|
813
|
+
isOpen: true,
|
|
814
|
+
title: intl.formatMessage(messages.modalTitle, {
|
|
815
|
+
resourceType: resourceTypePlural
|
|
816
|
+
}),
|
|
817
|
+
labelPrimary: intl.formatMessage(messages.continue),
|
|
818
|
+
onPrimaryButtonClick: formik.submitForm,
|
|
819
|
+
isPrimaryButtonDisabled: !formik.isValid,
|
|
820
|
+
onSecondaryButtonClick: onClose,
|
|
821
|
+
onClose: onClose,
|
|
822
|
+
size: 16,
|
|
823
|
+
children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
824
|
+
scale: "xxxl",
|
|
825
|
+
children: [jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
826
|
+
scale: "l",
|
|
827
|
+
children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
|
|
828
|
+
alignItems: "center",
|
|
829
|
+
children: [jsxRuntime.jsx(uiKit.ExportIcon, {
|
|
830
|
+
size: "medium",
|
|
831
|
+
color: "neutral60"
|
|
832
|
+
}), jsxRuntime.jsx(ExportTextMessage, {})]
|
|
833
|
+
}), jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
834
|
+
scale: "m",
|
|
835
|
+
children: [jsxRuntime.jsx(uiKit.SelectField, {
|
|
836
|
+
name: "outputFormat",
|
|
837
|
+
onChange: formik.handleChange,
|
|
838
|
+
onBlur: formik.handleBlur,
|
|
839
|
+
value: _valuesInstanceProperty__default["default"](formik).outputFormat,
|
|
840
|
+
title: intl.formatMessage(messages.outputFormat),
|
|
841
|
+
options: OUTPUT_FORMAT_OPTIONS
|
|
842
|
+
}), jsxRuntime.jsx(uiKit.TextField, {
|
|
843
|
+
name: "fileName",
|
|
844
|
+
onChange: formik.handleChange,
|
|
845
|
+
onBlur: formik.handleBlur,
|
|
846
|
+
value: _valuesInstanceProperty__default["default"](formik).fileName,
|
|
847
|
+
title: intl.formatMessage(messages.fileName),
|
|
848
|
+
touched: formik.touched.fileName,
|
|
849
|
+
errors: formik.errors.fileName,
|
|
850
|
+
renderError: renderFileNameError
|
|
851
|
+
}), jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
852
|
+
scale: "xs",
|
|
853
|
+
children: [jsxRuntime.jsx(uiKit.SelectField, {
|
|
854
|
+
id: "locales",
|
|
855
|
+
name: "locales",
|
|
856
|
+
value: _valuesInstanceProperty__default["default"](formik).locales,
|
|
857
|
+
title: intl.formatMessage(messages.locale),
|
|
858
|
+
options: mapLocalesToOptions(locales),
|
|
859
|
+
isMulti: true,
|
|
860
|
+
onChange: formik.handleChange,
|
|
861
|
+
onBlur: formik.handleBlur,
|
|
862
|
+
touched: formik.touched.locales,
|
|
863
|
+
errors: formik.errors.locales,
|
|
864
|
+
renderError: renderLocaleError,
|
|
865
|
+
menuPortalTarget: document.body,
|
|
866
|
+
menuPortalZIndex: Z_INDEX_DROPDOWN
|
|
867
|
+
}), jsxRuntime.jsx(uiKit.CheckboxInput, {
|
|
868
|
+
isChecked: areAllLocalesChecked,
|
|
869
|
+
onChange: e => {
|
|
870
|
+
if (e.target.checked) formik.setFieldValue('locales', locales);else formik.setFieldValue('locales', [locale]);
|
|
871
|
+
},
|
|
872
|
+
children: intl.formatMessage(messages.selectAllLocales)
|
|
873
|
+
})]
|
|
874
|
+
})]
|
|
875
|
+
})]
|
|
876
|
+
}), jsxRuntime.jsx("div", {})]
|
|
877
|
+
})
|
|
878
|
+
});
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
var _ref = {
|
|
882
|
+
name: "ti75j2",
|
|
883
|
+
styles: "margin:0"
|
|
884
|
+
} ;
|
|
885
|
+
const NoSearchResults = () => {
|
|
886
|
+
return jsxRuntime.jsxs(uiKit.Card, {
|
|
887
|
+
insetScale: "xl",
|
|
888
|
+
children: [jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
889
|
+
scale: "s",
|
|
890
|
+
children: [jsxRuntime.jsx(uiKit.Text.Body, {
|
|
891
|
+
fontWeight: "medium",
|
|
892
|
+
intlMessage: messages.thereAreNoResults
|
|
893
|
+
}), jsxRuntime.jsx(uiKit.Text.Body, {
|
|
894
|
+
intlMessage: messages.suggestions
|
|
895
|
+
})]
|
|
896
|
+
}), jsxRuntime.jsxs("ul", {
|
|
897
|
+
css: _ref,
|
|
898
|
+
children: [jsxRuntime.jsx("li", {
|
|
899
|
+
children: jsxRuntime.jsx(uiKit.Text.Body, {
|
|
900
|
+
intlMessage: messages.checkTheSpelling
|
|
901
|
+
})
|
|
902
|
+
}), jsxRuntime.jsx("li", {
|
|
903
|
+
children: jsxRuntime.jsx(uiKit.Text.Body, {
|
|
904
|
+
intlMessage: messages.searchByEnteringTheExactFieldName
|
|
905
|
+
})
|
|
906
|
+
})]
|
|
907
|
+
})]
|
|
908
|
+
});
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
function ownKeys$1(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
912
|
+
function _objectSpread$1(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$1(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$1(Object(t))).call(_context8, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
913
|
+
const StyledGroupCard = /*#__PURE__*/_styled__default["default"](uiKit.Card, {
|
|
914
|
+
target: "e3xiyhb1"
|
|
915
|
+
} )("border-right:", uiKit.designTokens.borderWidth1, " solid ", uiKit.designTokens.colorNeutral90, ";background-color:", uiKit.designTokens.colorNeutral98, ";height:100%;border-radius:0;", props => props.showTopBorder && /*#__PURE__*/react.css("border-top:", uiKit.designTokens.borderWidth1, " solid ", uiKit.designTokens.colorNeutral90, ";" + ("" ), "" ), ";" + ("" ));
|
|
916
|
+
const StyledFieldsCard = /*#__PURE__*/_styled__default["default"](uiKit.Card, {
|
|
917
|
+
target: "e3xiyhb0"
|
|
918
|
+
} )("border-radius:0;", props => props.showTopBorder && /*#__PURE__*/react.css("border-top:", uiKit.designTokens.borderWidth1, " solid ", uiKit.designTokens.colorNeutral90, ";" + ("" ), "" ), ";" + ("" ));
|
|
919
|
+
const FieldSections = _ref => {
|
|
920
|
+
let fields = _ref.fields,
|
|
921
|
+
parentKeys = _ref.parentKeys,
|
|
922
|
+
formik = _ref.formik,
|
|
923
|
+
isAnySiblingChecked = _ref.isAnySiblingChecked;
|
|
924
|
+
return jsxRuntime.jsx(uiKit.Spacings.Stack, {
|
|
925
|
+
scale: "s",
|
|
926
|
+
children: fields === null || fields === void 0 ? void 0 : _mapInstanceProperty__default["default"](fields).call(fields, (field, index) => {
|
|
927
|
+
var _context, _field$fields3;
|
|
928
|
+
const isAtleastOneChildChecked = () => {
|
|
929
|
+
function checkAtLeastOneFieldChecked(fields) {
|
|
930
|
+
return fields === null || fields === void 0 ? void 0 : _someInstanceProperty__default["default"](fields).call(fields, field => {
|
|
931
|
+
if (field.fields) {
|
|
932
|
+
return field.isChecked || checkAtLeastOneFieldChecked(field.fields);
|
|
933
|
+
}
|
|
934
|
+
return field.isChecked;
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
return checkAtLeastOneFieldChecked(field.fields);
|
|
938
|
+
};
|
|
939
|
+
const isAnyOfTheChildFieldsChecked = isAtleastOneChildChecked();
|
|
940
|
+
if (field.isHidden) return null;
|
|
941
|
+
return jsxRuntime.jsxs(React__default["default"].Fragment, {
|
|
942
|
+
children: [jsxRuntime.jsxs(uiKit.CheckboxInput, {
|
|
943
|
+
isChecked: field.isReadOnly ? isAnySiblingChecked : isAnyOfTheChildFieldsChecked || field.isChecked,
|
|
944
|
+
isReadOnly: field.isReadOnly || field.isRequired,
|
|
945
|
+
onChange: e => {
|
|
946
|
+
var _context2, _field$fields2;
|
|
947
|
+
const path = _concatInstanceProperty__default["default"](_context2 = "".concat(parentKeys.join('.'), ".fields[")).call(_context2, index, "]");
|
|
948
|
+
// Update all child fields
|
|
949
|
+
const updateAllChildFieldsChecked = (path, checked) => {
|
|
950
|
+
const item = get__default["default"](_valuesInstanceProperty__default["default"](formik), path);
|
|
951
|
+
if (item && item.fields) {
|
|
952
|
+
var _context3;
|
|
953
|
+
_forEachInstanceProperty__default["default"](_context3 = item.fields).call(_context3, (field, i) => {
|
|
954
|
+
var _context4, _field$fields;
|
|
955
|
+
const fieldPath = _concatInstanceProperty__default["default"](_context4 = "".concat(path, ".fields[")).call(_context4, i, "]");
|
|
956
|
+
if (!((_field$fields = field.fields) !== null && _field$fields !== void 0 && _field$fields.length)) {
|
|
957
|
+
formik.setFieldValue("".concat(fieldPath, ".isChecked"), checked,
|
|
958
|
+
// pass `false` to avoid revalidating the form with intermediate values
|
|
959
|
+
false);
|
|
960
|
+
}
|
|
961
|
+
updateAllChildFieldsChecked(fieldPath, checked);
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
if (!((_field$fields2 = field.fields) !== null && _field$fields2 !== void 0 && _field$fields2.length)) {
|
|
966
|
+
formik.setFieldValue("".concat(path, ".isChecked"), e.target.checked,
|
|
967
|
+
// pass `false` to avoid revalidating the form with intermediate values
|
|
968
|
+
false);
|
|
969
|
+
}
|
|
970
|
+
updateAllChildFieldsChecked(path, e.target.checked);
|
|
971
|
+
},
|
|
972
|
+
children: [field.label, " ", field.isRequired && '*']
|
|
973
|
+
}), field.fields && ((_field$fields3 = field.fields) === null || _field$fields3 === void 0 ? void 0 : _field$fields3.length) > 0 && jsxRuntime.jsxs(uiKit.Spacings.Inline, {
|
|
974
|
+
scale: "l",
|
|
975
|
+
children: [jsxRuntime.jsx("div", {}), jsxRuntime.jsx(FieldSections, {
|
|
976
|
+
fields: field.fields,
|
|
977
|
+
formik: formik,
|
|
978
|
+
parentKeys: [...parentKeys, "fields[".concat(index, "]")],
|
|
979
|
+
isAnySiblingChecked: isAnySiblingChecked
|
|
980
|
+
})]
|
|
981
|
+
})]
|
|
982
|
+
}, _concatInstanceProperty__default["default"](_context = "".concat(field.name, "-")).call(_context, index));
|
|
983
|
+
})
|
|
984
|
+
});
|
|
985
|
+
};
|
|
986
|
+
function checkAllFieldsSelected(fields) {
|
|
987
|
+
return _everyInstanceProperty__default["default"](fields).call(fields, field => {
|
|
988
|
+
if (field.fields) {
|
|
989
|
+
return checkAllFieldsSelected(field.fields);
|
|
990
|
+
}
|
|
991
|
+
return field.isChecked || field.isRequired || field.isReadOnly;
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
function checkAtLeastOneFieldChecked(fields) {
|
|
995
|
+
return _someInstanceProperty__default["default"](fields).call(fields, field => {
|
|
996
|
+
if (field.fields) {
|
|
997
|
+
return field.isChecked || checkAtLeastOneFieldChecked(field.fields);
|
|
998
|
+
}
|
|
999
|
+
return field.isChecked;
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
const FieldGroupSection = _ref2 => {
|
|
1003
|
+
let group = _ref2.group,
|
|
1004
|
+
index = _ref2.index,
|
|
1005
|
+
formik = _ref2.formik;
|
|
1006
|
+
const allAllFieldsSelected = React__default["default"].useMemo(() => checkAllFieldsSelected(group.fields), [group.fields]);
|
|
1007
|
+
const isAtleastOneFieldChecked = React__default["default"].useMemo(() => checkAtLeastOneFieldChecked(group.fields), [group.fields]);
|
|
1008
|
+
const parentKey = "groups[".concat(index, "]");
|
|
1009
|
+
const handleChangeAllFields = e => {
|
|
1010
|
+
const item = get__default["default"](_valuesInstanceProperty__default["default"](formik), parentKey);
|
|
1011
|
+
function updateAllFields(fields, checked) {
|
|
1012
|
+
return _mapInstanceProperty__default["default"](fields).call(fields, field => {
|
|
1013
|
+
if (field.fields) {
|
|
1014
|
+
return _objectSpread$1(_objectSpread$1({}, field), {}, {
|
|
1015
|
+
fields: updateAllFields(field.fields, checked)
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
if (field.isReadOnly || field.isRequired) return field;
|
|
1019
|
+
return _objectSpread$1(_objectSpread$1({}, field), {}, {
|
|
1020
|
+
isChecked: checked
|
|
1021
|
+
});
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
formik.setFieldValue(parentKey, _objectSpread$1(_objectSpread$1({}, item), {}, {
|
|
1025
|
+
fields: updateAllFields(item.fields, e.target.checked)
|
|
1026
|
+
}));
|
|
1027
|
+
};
|
|
1028
|
+
if (group.isHidden) return null;
|
|
1029
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1030
|
+
children: [jsxRuntime.jsx(uiKit.Grid.Item, {
|
|
1031
|
+
children: jsxRuntime.jsx(StyledGroupCard, {
|
|
1032
|
+
type: "flat",
|
|
1033
|
+
insetScale: "l",
|
|
1034
|
+
showTopBorder: true,
|
|
1035
|
+
children: jsxRuntime.jsx(uiKit.CheckboxInput, {
|
|
1036
|
+
isIndeterminate: !allAllFieldsSelected && isAtleastOneFieldChecked,
|
|
1037
|
+
isChecked: allAllFieldsSelected,
|
|
1038
|
+
onChange: handleChangeAllFields,
|
|
1039
|
+
children: group.groupLabel
|
|
1040
|
+
})
|
|
1041
|
+
})
|
|
1042
|
+
}), jsxRuntime.jsx(uiKit.Grid.Item, {
|
|
1043
|
+
children: jsxRuntime.jsx(StyledFieldsCard, {
|
|
1044
|
+
type: "flat",
|
|
1045
|
+
insetScale: "l",
|
|
1046
|
+
showTopBorder: true,
|
|
1047
|
+
children: jsxRuntime.jsx(uiKit.Spacings.Stack, {
|
|
1048
|
+
scale: "s",
|
|
1049
|
+
children: jsxRuntime.jsx(FieldSections, {
|
|
1050
|
+
fields: group.fields,
|
|
1051
|
+
formik: formik,
|
|
1052
|
+
parentKeys: [parentKey],
|
|
1053
|
+
isAnySiblingChecked: isAtleastOneFieldChecked
|
|
1054
|
+
})
|
|
1055
|
+
})
|
|
1056
|
+
})
|
|
1057
|
+
})]
|
|
1058
|
+
});
|
|
1059
|
+
};
|
|
1060
|
+
const ExportFieldsSelectionStep = () => {
|
|
1061
|
+
const intl = reactIntl.useIntl();
|
|
1062
|
+
const _React$useState = React__default["default"].useState(''),
|
|
1063
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
1064
|
+
fieldSearchTerm = _React$useState2[0],
|
|
1065
|
+
setFieldSearchTerm = _React$useState2[1];
|
|
1066
|
+
const _useExportResourcesCo = useExportResourcesContext(),
|
|
1067
|
+
formik = _useExportResourcesCo.formik,
|
|
1068
|
+
setCurrentStep = _useExportResourcesCo.setCurrentStep,
|
|
1069
|
+
resourceType = _useExportResourcesCo.resourceType,
|
|
1070
|
+
onClose = _useExportResourcesCo.onClose;
|
|
1071
|
+
const resourceTypePlural = resourceTypeToDisplayName({
|
|
1072
|
+
resourceType: resourceType,
|
|
1073
|
+
isPlural: true
|
|
1074
|
+
});
|
|
1075
|
+
React__default["default"].useEffect(() => {
|
|
1076
|
+
formik.validateForm();
|
|
1077
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1078
|
+
}, [_valuesInstanceProperty__default["default"](formik).groups]);
|
|
1079
|
+
// adds `isHidden` property to each field based on search term
|
|
1080
|
+
const filteredGroups = React__default["default"].useMemo(() => {
|
|
1081
|
+
var _fieldSearchTerm$trim, _context6;
|
|
1082
|
+
const updateFields = (fields, parentMatches) => {
|
|
1083
|
+
return _mapInstanceProperty__default["default"](fields).call(fields, field => {
|
|
1084
|
+
var _context5;
|
|
1085
|
+
const matches = _includesInstanceProperty__default["default"](_context5 = field.label.toLowerCase()).call(_context5, fieldSearchTerm.toLowerCase());
|
|
1086
|
+
let isHidden = !matches && !parentMatches;
|
|
1087
|
+
if (field.fields) {
|
|
1088
|
+
const updatedFields = updateFields(field.fields, matches);
|
|
1089
|
+
isHidden = isHidden && _everyInstanceProperty__default["default"](updatedFields).call(updatedFields, f => f.isHidden);
|
|
1090
|
+
field = _objectSpread$1(_objectSpread$1({}, field), {}, {
|
|
1091
|
+
fields: updatedFields
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
return _objectSpread$1(_objectSpread$1({}, field), {}, {
|
|
1095
|
+
isHidden
|
|
1096
|
+
});
|
|
1097
|
+
});
|
|
1098
|
+
};
|
|
1099
|
+
if (!(fieldSearchTerm !== null && fieldSearchTerm !== void 0 && (_fieldSearchTerm$trim = _trimInstanceProperty__default["default"](fieldSearchTerm).call(fieldSearchTerm)) !== null && _fieldSearchTerm$trim !== void 0 && _fieldSearchTerm$trim.length)) return _valuesInstanceProperty__default["default"](formik).groups;
|
|
1100
|
+
return _mapInstanceProperty__default["default"](_context6 = _valuesInstanceProperty__default["default"](formik).groups).call(_context6, group => {
|
|
1101
|
+
const updatedFields = updateFields(group.fields, false);
|
|
1102
|
+
const isHidden = _everyInstanceProperty__default["default"](updatedFields).call(updatedFields, field => field.isHidden);
|
|
1103
|
+
return _objectSpread$1(_objectSpread$1({}, group), {}, {
|
|
1104
|
+
fields: updatedFields,
|
|
1105
|
+
isHidden
|
|
1106
|
+
});
|
|
1107
|
+
});
|
|
1108
|
+
}, [_valuesInstanceProperty__default["default"](formik).groups, fieldSearchTerm]);
|
|
1109
|
+
const onSearchChange = React__default["default"].useCallback(event => {
|
|
1110
|
+
setFieldSearchTerm(event.target.value);
|
|
1111
|
+
}, [setFieldSearchTerm]);
|
|
1112
|
+
const hasResults = Boolean(_findInstanceProperty__default["default"](filteredGroups).call(filteredGroups, group => !group.isHidden));
|
|
1113
|
+
const onSearchChangeThrottled = React__default["default"].useMemo(() => throttle__default["default"](onSearchChange, 300), [onSearchChange]);
|
|
1114
|
+
const onSearchReset = () => {
|
|
1115
|
+
setFieldSearchTerm('');
|
|
1116
|
+
};
|
|
1117
|
+
return jsxRuntime.jsx(applicationComponents.FormDialog, {
|
|
1118
|
+
isOpen: true,
|
|
1119
|
+
title: intl.formatMessage(messages.modalTitle, {
|
|
1120
|
+
resourceType: resourceTypePlural
|
|
1121
|
+
}),
|
|
1122
|
+
labelPrimary: intl.formatMessage(messages.startExport),
|
|
1123
|
+
onPrimaryButtonClick: formik.submitForm,
|
|
1124
|
+
isPrimaryButtonDisabled: !formik.isValid,
|
|
1125
|
+
labelSecondary: intl.formatMessage(messages.back),
|
|
1126
|
+
onSecondaryButtonClick: () => setCurrentStep(1),
|
|
1127
|
+
onClose: onClose,
|
|
1128
|
+
size: 16,
|
|
1129
|
+
children: jsxRuntime.jsx(uiKit.Spacings.Stack, {
|
|
1130
|
+
scale: "xl",
|
|
1131
|
+
children: jsxRuntime.jsxs(uiKit.Spacings.Stack, {
|
|
1132
|
+
scale: "m",
|
|
1133
|
+
children: [jsxRuntime.jsxs(uiKit.Spacings.Inline, {
|
|
1134
|
+
justifyContent: "space-between",
|
|
1135
|
+
children: [jsxRuntime.jsx(uiKit.Text.Body, {
|
|
1136
|
+
intlMessage: messages.selectFieldsToExport
|
|
1137
|
+
}), jsxRuntime.jsx(uiKit.Link, {
|
|
1138
|
+
isExternal: true,
|
|
1139
|
+
tone: "secondary",
|
|
1140
|
+
intlMessage: messages.fieldDefinitions,
|
|
1141
|
+
to: FIELD_DEFINITIONS_URLS[resourceType]
|
|
1142
|
+
})]
|
|
1143
|
+
}), jsxRuntime.jsx(uiKit.SearchTextInput, {
|
|
1144
|
+
placeholder: intl.formatMessage(messages.searchForFields),
|
|
1145
|
+
value: fieldSearchTerm,
|
|
1146
|
+
onChange: onSearchChangeThrottled,
|
|
1147
|
+
onReset: onSearchReset
|
|
1148
|
+
// TODO: `SearchTextInput` props to be improved. The `onSubmit` callback shouldn't be mandatory
|
|
1149
|
+
,
|
|
1150
|
+
onSubmit: () => {}
|
|
1151
|
+
}), hasResults ? jsxRuntime.jsx(uiKit.Card, {
|
|
1152
|
+
insetScale: "none",
|
|
1153
|
+
children: jsxRuntime.jsx(uiKit.Grid, {
|
|
1154
|
+
gridAutoFlow: "row",
|
|
1155
|
+
gridTemplateColumns: "".concat(uiKit.designTokens.constraint5, " auto"),
|
|
1156
|
+
children: _mapInstanceProperty__default["default"](filteredGroups).call(filteredGroups, (group, index) => jsxRuntime.jsx(FieldGroupSection, {
|
|
1157
|
+
group: group,
|
|
1158
|
+
index: index,
|
|
1159
|
+
formik: formik
|
|
1160
|
+
}, group.groupLabel))
|
|
1161
|
+
})
|
|
1162
|
+
}) : jsxRuntime.jsx(NoSearchResults, {})]
|
|
1163
|
+
})
|
|
1164
|
+
})
|
|
1165
|
+
});
|
|
1166
|
+
};
|
|
1167
|
+
|
|
1168
|
+
const ExportResourcesContext = /*#__PURE__*/React.createContext();
|
|
1169
|
+
|
|
1170
|
+
const ExportResourcesProvider = props => {
|
|
1171
|
+
const initialValues = useInitialValues(props);
|
|
1172
|
+
const _useStartExportOperat = useStartExportOperation(props),
|
|
1173
|
+
startExportOperation = _useStartExportOperat.startExportOperation;
|
|
1174
|
+
const _React$useState = React__default["default"].useState(1),
|
|
1175
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
1176
|
+
currentStep = _React$useState2[0],
|
|
1177
|
+
setCurrentStep = _React$useState2[1];
|
|
1178
|
+
const onSubmit = async values => {
|
|
1179
|
+
if (currentStep === 1) {
|
|
1180
|
+
setCurrentStep(2);
|
|
1181
|
+
} else {
|
|
1182
|
+
startExportOperation(values);
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
const formik$1 = formik.useFormik({
|
|
1186
|
+
initialValues,
|
|
1187
|
+
validate: values => validate({
|
|
1188
|
+
values,
|
|
1189
|
+
step: currentStep
|
|
1190
|
+
}),
|
|
1191
|
+
onSubmit
|
|
1192
|
+
});
|
|
1193
|
+
React__default["default"].useEffect(() => {
|
|
1194
|
+
formik$1.validateForm();
|
|
1195
|
+
}, [currentStep]);
|
|
1196
|
+
return jsxRuntime.jsx(ExportResourcesContext.Provider, {
|
|
1197
|
+
value: {
|
|
1198
|
+
formik: formik$1,
|
|
1199
|
+
currentStep,
|
|
1200
|
+
setCurrentStep,
|
|
1201
|
+
onClose: props.onClose,
|
|
1202
|
+
resourceType: props.resourceType,
|
|
1203
|
+
exportType: props.exportType,
|
|
1204
|
+
totalResourcesCount: props.totalResourcesCount,
|
|
1205
|
+
selectedResourceIds: props.selectedResourceIds
|
|
1206
|
+
},
|
|
1207
|
+
children: props.children
|
|
1208
|
+
});
|
|
1209
|
+
};
|
|
1210
|
+
|
|
1211
|
+
const CurrentStep = () => {
|
|
1212
|
+
const _useExportResourcesCo = useExportResourcesContext(),
|
|
1213
|
+
currentStep = _useExportResourcesCo.currentStep;
|
|
1214
|
+
const steps = {
|
|
1215
|
+
1: jsxRuntime.jsx(ExportFileSettingsStep, {}),
|
|
1216
|
+
2: jsxRuntime.jsx(ExportFieldsSelectionStep, {})
|
|
1217
|
+
};
|
|
1218
|
+
return steps[currentStep] || null;
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
1222
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
1223
|
+
const ExportResourcesModal = props => {
|
|
1224
|
+
if (!props.isOpen) return null;
|
|
1225
|
+
return jsxRuntime.jsx(ExportResourcesProvider, _objectSpread(_objectSpread({}, props), {}, {
|
|
1226
|
+
children: jsxRuntime.jsx(CurrentStep, {})
|
|
1227
|
+
}));
|
|
1228
|
+
};
|
|
1229
|
+
ExportResourcesModal.displayName = 'ExportResourcesModal';
|
|
1230
|
+
ExportResourcesModal.defaultProps = {
|
|
1231
|
+
isOpen: false,
|
|
1232
|
+
selectedResourceIds: [],
|
|
1233
|
+
exportType: EXPORT_TYPES.ALL,
|
|
1234
|
+
outputFormat: OUTPUT_FORMATS.CSV,
|
|
1235
|
+
customFields: [],
|
|
1236
|
+
fieldGroups: []
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1239
|
+
exports.EXPORTABLE_RESOURCES = EXPORTABLE_RESOURCES;
|
|
1240
|
+
exports.EXPORT_TYPES = EXPORT_TYPES;
|
|
1241
|
+
exports["default"] = ExportResourcesModal;
|