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