@wix/bex-core 2.401.0 → 2.402.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useImport.js +5 -0
- package/dist/cjs/hooks/useImport.js.map +1 -1
- package/dist/cjs/state/ImportState/ImportState.js +121 -34
- package/dist/cjs/state/ImportState/ImportState.js.map +1 -1
- package/dist/cjs/state/ImportState/__tests__/ImportState.engine.spec.js +303 -0
- package/dist/cjs/state/ImportState/__tests__/ImportState.engine.spec.js.map +1 -1
- package/dist/cjs/state/ImportState/findExistingImportIds.js +35 -0
- package/dist/cjs/state/ImportState/findExistingImportIds.js.map +1 -0
- package/dist/cjs/types/FieldTypeDefinition.js.map +1 -1
- package/dist/esm/hooks/useImport.js +6 -1
- package/dist/esm/hooks/useImport.js.map +1 -1
- package/dist/esm/state/ImportState/ImportState.js +112 -34
- package/dist/esm/state/ImportState/ImportState.js.map +1 -1
- package/dist/esm/state/ImportState/__tests__/ImportState.engine.spec.js +234 -0
- package/dist/esm/state/ImportState/__tests__/ImportState.engine.spec.js.map +1 -1
- package/dist/esm/state/ImportState/findExistingImportIds.js +24 -0
- package/dist/esm/state/ImportState/findExistingImportIds.js.map +1 -0
- package/dist/esm/types/FieldTypeDefinition.js.map +1 -1
- package/dist/types/hooks/useImport.d.ts +6 -3
- package/dist/types/hooks/useImport.d.ts.map +1 -1
- package/dist/types/state/ImportState/ImportState.d.ts +10 -7
- package/dist/types/state/ImportState/ImportState.d.ts.map +1 -1
- package/dist/types/state/ImportState/findExistingImportIds.d.ts +3 -0
- package/dist/types/state/ImportState/findExistingImportIds.d.ts.map +1 -0
- package/dist/types/types/FieldTypeDefinition.d.ts +3 -2
- package/dist/types/types/FieldTypeDefinition.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -5,9 +5,12 @@ exports.useCreateImport = useCreateImport;
|
|
|
5
5
|
var _react = require("react");
|
|
6
6
|
var _providers = require("../providers");
|
|
7
7
|
var _state = require("../state");
|
|
8
|
+
var _findExistingImportIds = require("../state/ImportState/findExistingImportIds");
|
|
8
9
|
function useCreateImport(params) {
|
|
9
10
|
const {
|
|
10
11
|
config,
|
|
12
|
+
createFieldValidator,
|
|
13
|
+
schemaSource,
|
|
11
14
|
importInputs,
|
|
12
15
|
fieldsSource,
|
|
13
16
|
detectColumnType,
|
|
@@ -27,6 +30,8 @@ function useCreateImport(params) {
|
|
|
27
30
|
return (0, _react.useCallback)(() => {
|
|
28
31
|
return new _state.ImportState({
|
|
29
32
|
config,
|
|
33
|
+
createFieldValidator,
|
|
34
|
+
getExistingIds: schemaSource ? (ids, signal) => (0, _findExistingImportIds.findExistingImportIds)(schemaSource, ids, signal, collection.query.asComputed.extra) : undefined,
|
|
30
35
|
importInputs,
|
|
31
36
|
fieldsSource,
|
|
32
37
|
httpClient,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_providers","_state","useCreateImport","params","config","importInputs","fieldsSource","detectColumnType","isValueCompatible","importModalState","reportBi","container","useWixPatternsContainer","showToast","translate","errorHandler","window","httpClient","collection","useCollectionContext","useCallback","ImportState","downloadCsv","content","fileName","download","encodeURIComponent"],"sources":["../../../src/hooks/useImport.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useWixPatternsContainer, useCollectionContext } from '../providers';\nimport {\n ModalState,\n ImportState,\n ResolvedImportConfig,\n ImportConfig,\n DetectColumnType,\n IsImportValueCompatible,\n} from '../state';\nimport type { FieldsSource } from '../types/FieldsSource';\nimport { FiltersMap } from '../model';\nimport type { ReportBI } from '../services';\n\nexport interface UseImportParams {\n /** Consumer inputs (destination, extra fields, backup, …). The collection,\n * fields, and create-new-field are read from `fieldsSource`. */\n importInputs?: ImportConfig;\n /** The table's live fields source; `ImportState` builds the config from it. */\n fieldsSource?: FieldsSource;\n /** A fully pre-built config, used instead of building from the inputs/source. */\n config?: ResolvedImportConfig;\n detectColumnType?: DetectColumnType;\n isValueCompatible?: IsImportValueCompatible;\n importModalState: ModalState;\n /** BI reporter for the import funnel; defaults to the container's. */\n reportBi?: ReportBI;\n}\n\nexport function useCreateImport<T = unknown, F extends FiltersMap = FiltersMap>(\n params: UseImportParams
|
|
1
|
+
{"version":3,"names":["_react","require","_providers","_state","_findExistingImportIds","useCreateImport","params","config","createFieldValidator","schemaSource","importInputs","fieldsSource","detectColumnType","isValueCompatible","importModalState","reportBi","container","useWixPatternsContainer","showToast","translate","errorHandler","window","httpClient","collection","useCollectionContext","useCallback","ImportState","getExistingIds","ids","signal","findExistingImportIds","query","asComputed","extra","undefined","downloadCsv","content","fileName","download","encodeURIComponent"],"sources":["../../../src/hooks/useImport.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useWixPatternsContainer, useCollectionContext } from '../providers';\nimport {\n ModalState,\n ImportState,\n ResolvedImportConfig,\n ImportConfig,\n DetectColumnType,\n CreateImportFieldValidator,\n IsImportValueCompatible,\n} from '../state';\nimport { findExistingImportIds } from '../state/ImportState/findExistingImportIds';\nimport type { SchemaSource } from '../types/SchemaSource';\nimport type { FieldsSource } from '../types/FieldsSource';\nimport { FiltersMap } from '../model';\nimport type { ReportBI } from '../services';\n\nexport interface UseImportParams<T = unknown> {\n createFieldValidator?: CreateImportFieldValidator;\n schemaSource?: SchemaSource<T>;\n /** Consumer inputs (destination, extra fields, backup, …). The collection,\n * fields, and create-new-field are read from `fieldsSource`. */\n importInputs?: ImportConfig;\n /** The table's live fields source; `ImportState` builds the config from it. */\n fieldsSource?: FieldsSource;\n /** A fully pre-built config, used instead of building from the inputs/source. */\n config?: ResolvedImportConfig;\n detectColumnType?: DetectColumnType;\n isValueCompatible?: IsImportValueCompatible;\n importModalState: ModalState;\n /** BI reporter for the import funnel; defaults to the container's. */\n reportBi?: ReportBI;\n}\n\nexport function useCreateImport<T = unknown, F extends FiltersMap = FiltersMap>(\n params: UseImportParams<T>,\n) {\n const {\n config,\n createFieldValidator,\n schemaSource,\n importInputs,\n fieldsSource,\n detectColumnType,\n isValueCompatible,\n importModalState,\n reportBi,\n } = params;\n const container = useWixPatternsContainer();\n const { showToast, translate, errorHandler, window, httpClient } = container;\n const collection = useCollectionContext<T, F>();\n\n return useCallback(() => {\n return new ImportState({\n config,\n createFieldValidator,\n getExistingIds: schemaSource\n ? (ids, signal) =>\n findExistingImportIds(\n schemaSource,\n ids,\n signal,\n collection.query.asComputed.extra,\n )\n : undefined,\n importInputs,\n fieldsSource,\n httpClient,\n detectColumnType,\n isValueCompatible,\n collection,\n importModalState,\n showToast,\n translate,\n errorHandler,\n reportBi: reportBi ?? container.reportBi,\n downloadCsv: (content, fileName) => {\n window.download(\n `data:text/csv;charset=utf-8,${encodeURIComponent(content)}`,\n fileName,\n );\n },\n });\n }, []);\n}\n"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AASA,IAAAG,sBAAA,GAAAH,OAAA;AAuBO,SAASI,eAAeA,CAC7BC,MAA0B,EAC1B;EACA,MAAM;IACJC,MAAM;IACNC,oBAAoB;IACpBC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZC,gBAAgB;IAChBC,iBAAiB;IACjBC,gBAAgB;IAChBC;EACF,CAAC,GAAGT,MAAM;EACV,MAAMU,SAAS,GAAG,IAAAC,kCAAuB,EAAC,CAAC;EAC3C,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC,YAAY;IAAEC,MAAM;IAAEC;EAAW,CAAC,GAAGN,SAAS;EAC5E,MAAMO,UAAU,GAAG,IAAAC,+BAAoB,EAAO,CAAC;EAE/C,OAAO,IAAAC,kBAAW,EAAC,MAAM;IACvB,OAAO,IAAIC,kBAAW,CAAC;MACrBnB,MAAM;MACNC,oBAAoB;MACpBmB,cAAc,EAAElB,YAAY,GACxB,CAACmB,GAAG,EAAEC,MAAM,KACV,IAAAC,4CAAqB,EACnBrB,YAAY,EACZmB,GAAG,EACHC,MAAM,EACNN,UAAU,CAACQ,KAAK,CAACC,UAAU,CAACC,KAC9B,CAAC,GACHC,SAAS;MACbxB,YAAY;MACZC,YAAY;MACZW,UAAU;MACVV,gBAAgB;MAChBC,iBAAiB;MACjBU,UAAU;MACVT,gBAAgB;MAChBI,SAAS;MACTC,SAAS;MACTC,YAAY;MACZL,QAAQ,EAAEA,QAAQ,IAAIC,SAAS,CAACD,QAAQ;MACxCoB,WAAW,EAAEA,CAACC,OAAO,EAAEC,QAAQ,KAAK;QAClChB,MAAM,CAACiB,QAAQ,CACb,+BAA+BC,kBAAkB,CAACH,OAAO,CAAC,EAAE,EAC5DC,QACF,CAAC;MACH;IACF,CAAC,CAAC;EACJ,CAAC,EAAE,EAAE,CAAC;AACR","ignoreList":[]}
|
|
@@ -20,7 +20,7 @@ var _newFieldDraft = require("./newFieldDraft");
|
|
|
20
20
|
var _ImportStateBIReporter = require("./ImportStateBIReporter");
|
|
21
21
|
/** Outcome of a server-side import job, derived from the job's progress. */
|
|
22
22
|
|
|
23
|
-
/** A rejected row: its index
|
|
23
|
+
/** A rejected row: its index in the input rows and the reason it failed. */
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Optional snapshot taken before the import runs, returning a `restore` used to
|
|
@@ -340,6 +340,11 @@ class ImportState {
|
|
|
340
340
|
(0, _defineProperty2.default)(this, "_detectColumnType", void 0);
|
|
341
341
|
(0, _defineProperty2.default)(this, "_isValueCompatible", void 0);
|
|
342
342
|
(0, _defineProperty2.default)(this, "discardChangesModal", new _ConditionalModalState.ConditionalModalState());
|
|
343
|
+
(0, _defineProperty2.default)(this, "_createFieldValidator", void 0);
|
|
344
|
+
(0, _defineProperty2.default)(this, "_fieldsSource", void 0);
|
|
345
|
+
(0, _defineProperty2.default)(this, "_getExistingIds", void 0);
|
|
346
|
+
(0, _defineProperty2.default)(this, "_uploadedRows", undefined);
|
|
347
|
+
(0, _defineProperty2.default)(this, "_validationFailures", []);
|
|
343
348
|
(0, _defineProperty2.default)(this, "currentStep", 'upload');
|
|
344
349
|
(0, _defineProperty2.default)(this, "importStatus", {
|
|
345
350
|
..._model.queryStatus.idle
|
|
@@ -398,6 +403,9 @@ class ImportState {
|
|
|
398
403
|
this.config = props.config ?? buildImportConfig(props.fieldsSource, props.collection, props.importInputs);
|
|
399
404
|
this.importModalState = props.importModalState;
|
|
400
405
|
this.translate = props.translate;
|
|
406
|
+
this._createFieldValidator = props.createFieldValidator;
|
|
407
|
+
this._fieldsSource = props.fieldsSource;
|
|
408
|
+
this._getExistingIds = props.getExistingIds;
|
|
401
409
|
this.errorHandler = props.errorHandler;
|
|
402
410
|
this.showToast = props.showToast;
|
|
403
411
|
this.downloadCsv = props.downloadCsv;
|
|
@@ -660,6 +668,8 @@ class ImportState {
|
|
|
660
668
|
this.importStatus = {
|
|
661
669
|
..._model.queryStatus.idle
|
|
662
670
|
};
|
|
671
|
+
this._uploadedRows = undefined;
|
|
672
|
+
this._validationFailures = [];
|
|
663
673
|
this.fileName = '';
|
|
664
674
|
this.csvHeaders = [];
|
|
665
675
|
this.csvRows = [];
|
|
@@ -931,34 +941,37 @@ class ImportState {
|
|
|
931
941
|
});
|
|
932
942
|
}
|
|
933
943
|
|
|
934
|
-
/**
|
|
935
|
-
* Builds a re-importable CSV of the rows the server rejected and hands it to
|
|
936
|
-
* `downloadCsv`. Each failed row is prefixed with a leading "why it failed"
|
|
937
|
-
* column holding the server's error message, so the user can see and fix each
|
|
938
|
-
* reason. The failed rows (and their reasons) come from the job's movement
|
|
939
|
-
* logs, mapped back to the parsed `csvRows` we still hold in memory.
|
|
940
|
-
*/
|
|
944
|
+
/** Downloads validation failures and server rejections with their reasons. */
|
|
941
945
|
async downloadFailedRows() {
|
|
942
946
|
var _this$downloadCsv;
|
|
943
947
|
this.bi.onSummaryCtaClicked('Download failed items CSV');
|
|
944
|
-
|
|
945
|
-
if (
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
console.error('Fetching failed rows report failed', error);
|
|
953
|
-
return;
|
|
948
|
+
let serverFailures = [];
|
|
949
|
+
if (this._jobId && this.result.failed > this._validationFailures.length) {
|
|
950
|
+
try {
|
|
951
|
+
serverFailures = await this._fetchFailedRows(this._jobId);
|
|
952
|
+
} catch (error) {
|
|
953
|
+
console.error('Fetching failed rows report failed', error);
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
954
956
|
}
|
|
955
|
-
const rows =
|
|
957
|
+
const rows = [...this._validationFailures.map(({
|
|
956
958
|
index,
|
|
957
959
|
reason
|
|
958
|
-
}) => {
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
}).
|
|
960
|
+
}) => ({
|
|
961
|
+
row: this.csvRows[index],
|
|
962
|
+
reason
|
|
963
|
+
})), ...serverFailures.map(({
|
|
964
|
+
index,
|
|
965
|
+
reason
|
|
966
|
+
}) => ({
|
|
967
|
+
row: (this._uploadedRows ?? this.csvRows)[index],
|
|
968
|
+
reason
|
|
969
|
+
}))].filter(({
|
|
970
|
+
row
|
|
971
|
+
}) => row != null).map(({
|
|
972
|
+
row,
|
|
973
|
+
reason
|
|
974
|
+
}) => [reason, ...row]);
|
|
962
975
|
if (rows.length === 0) {
|
|
963
976
|
return;
|
|
964
977
|
}
|
|
@@ -995,7 +1008,7 @@ class ImportState {
|
|
|
995
1008
|
}
|
|
996
1009
|
const fileLine = Number((_exec = /\d+/.exec(log.sourceItemId)) == null ? void 0 : _exec[0]);
|
|
997
1010
|
const index = fileLine - 2;
|
|
998
|
-
if (Number.isInteger(index) && index >= 0 && index < this.csvRows.length) {
|
|
1011
|
+
if (Number.isInteger(index) && index >= 0 && index < (this._uploadedRows ?? this.csvRows).length) {
|
|
999
1012
|
failures.push({
|
|
1000
1013
|
index,
|
|
1001
1014
|
reason: log.failure.description ?? ''
|
|
@@ -1134,8 +1147,8 @@ class ImportState {
|
|
|
1134
1147
|
* a failed job so `startImport` surfaces the error state; partial success is
|
|
1135
1148
|
* reported via `result.failed` and the partial toast.
|
|
1136
1149
|
*/
|
|
1137
|
-
async _runImportJob(resolvedMapping) {
|
|
1138
|
-
const csv = (0, _rewriteCsv.rewriteParsedCsvForImport)(this.csvHeaders,
|
|
1150
|
+
async _runImportJob(resolvedMapping, rows) {
|
|
1151
|
+
const csv = (0, _rewriteCsv.rewriteParsedCsvForImport)(this.csvHeaders, rows, resolvedMapping);
|
|
1139
1152
|
const file = new File([csv], this.fileName || 'import.csv', {
|
|
1140
1153
|
type: 'text/csv'
|
|
1141
1154
|
});
|
|
@@ -1231,8 +1244,9 @@ class ImportState {
|
|
|
1231
1244
|
_applyJobProgress(job) {
|
|
1232
1245
|
const progress = job.progress;
|
|
1233
1246
|
const succeeded = (progress == null ? void 0 : progress.itemsSuccessful) ?? 0;
|
|
1234
|
-
const
|
|
1235
|
-
const
|
|
1247
|
+
const rejected = (progress == null ? void 0 : progress.itemsRejected) ?? 0;
|
|
1248
|
+
const failed = rejected + this._validationFailures.length;
|
|
1249
|
+
const current = ((progress == null ? void 0 : progress.current) ?? succeeded + rejected) + this._validationFailures.length;
|
|
1236
1250
|
// The server splits successful items into created (new) and updated
|
|
1237
1251
|
// (existing) — the summary step reports each. Some jobs omit this split
|
|
1238
1252
|
// entirely (`itemsSuccessfulInfo` absent); in that case treat every success
|
|
@@ -1241,8 +1255,7 @@ class ImportState {
|
|
|
1241
1255
|
const created = successInfo ? successInfo.itemsCreated ?? 0 : succeeded;
|
|
1242
1256
|
const updated = (successInfo == null ? void 0 : successInfo.itemsUpdated) ?? 0;
|
|
1243
1257
|
|
|
1244
|
-
//
|
|
1245
|
-
// (one uploaded row per CSV row); polling only advances `processedCount`.
|
|
1258
|
+
// Validation failures are already processed; the job advances the rest.
|
|
1246
1259
|
(0, _mobx.runInAction)(() => {
|
|
1247
1260
|
this.processedCount = Math.min(current, this.totalCount);
|
|
1248
1261
|
this.result = {
|
|
@@ -1416,6 +1429,65 @@ class ImportState {
|
|
|
1416
1429
|
console.error('ImportState config.onImportCompleted failed', error);
|
|
1417
1430
|
}
|
|
1418
1431
|
}
|
|
1432
|
+
async _validateRows(mapping, signal) {
|
|
1433
|
+
var _this$_getExistingIds;
|
|
1434
|
+
const rows = [];
|
|
1435
|
+
const failedRows = [];
|
|
1436
|
+
const idIndex = this.csvHeaders.findIndex(header => mapping[header] === this.idFieldKey);
|
|
1437
|
+
const skipExisting = this.writePolicy === _types.WritePolicy.SKIP_EXISTING;
|
|
1438
|
+
const ids = [...new Set(this.csvRows.map(row => row[idIndex]).filter(Boolean))];
|
|
1439
|
+
const skippedIds = new Set(skipExisting && ids.length ? await ((_this$_getExistingIds = this._getExistingIds) == null ? void 0 : _this$_getExistingIds.call(this, ids, signal)) : []);
|
|
1440
|
+
const columns = this.csvHeaders.map(header => {
|
|
1441
|
+
var _this$_pendingFieldsM, _this$_fieldsSource, _sourceField$validati, _this$_createFieldVal;
|
|
1442
|
+
const fieldId = mapping[header];
|
|
1443
|
+
if (!fieldId || fieldId === this.idFieldKey) {
|
|
1444
|
+
return undefined;
|
|
1445
|
+
}
|
|
1446
|
+
const sourceField = ((_this$_pendingFieldsM = this._pendingFieldsMap) == null ? void 0 : _this$_pendingFieldsM[fieldId]) ?? ((_this$_fieldsSource = this._fieldsSource) == null ? void 0 : _this$_fieldsSource.fields.find(field => field.id === fieldId));
|
|
1447
|
+
if (sourceField != null && sourceField.isSystem) {
|
|
1448
|
+
return undefined;
|
|
1449
|
+
}
|
|
1450
|
+
const configField = this.fields.find(field => field.id === fieldId);
|
|
1451
|
+
const field = {
|
|
1452
|
+
...(sourceField ?? {
|
|
1453
|
+
id: fieldId,
|
|
1454
|
+
displayName: (configField == null ? void 0 : configField.header) || fieldId,
|
|
1455
|
+
type: 'UNKNOWN'
|
|
1456
|
+
}),
|
|
1457
|
+
validation: {
|
|
1458
|
+
...(sourceField == null ? void 0 : sourceField.validation),
|
|
1459
|
+
required: !!(configField != null && configField.required || sourceField != null && (_sourceField$validati = sourceField.validation) != null && _sourceField$validati.required)
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
return ((_this$_createFieldVal = this._createFieldValidator) == null ? void 0 : _this$_createFieldVal.call(this, field)) ?? (raw => {
|
|
1463
|
+
var _field$validation;
|
|
1464
|
+
return (_field$validation = field.validation) != null && _field$validation.required && !raw ? [this.translate('cairo.editableTable.field.validation.required', {
|
|
1465
|
+
fieldName: field.displayName
|
|
1466
|
+
})] : [];
|
|
1467
|
+
});
|
|
1468
|
+
});
|
|
1469
|
+
this.csvRows.forEach((row, index) => {
|
|
1470
|
+
if (skippedIds.has(row[idIndex])) {
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
const reasons = columns.flatMap((validate, columnIndex) => (validate == null ? void 0 : validate(row[columnIndex] ?? '')) ?? []);
|
|
1474
|
+
if (reasons.length) {
|
|
1475
|
+
failedRows.push({
|
|
1476
|
+
index,
|
|
1477
|
+
reason: reasons.join('; ')
|
|
1478
|
+
});
|
|
1479
|
+
} else {
|
|
1480
|
+
rows.push(row);
|
|
1481
|
+
if (skipExisting && row[idIndex]) {
|
|
1482
|
+
skippedIds.add(row[idIndex]);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
});
|
|
1486
|
+
return {
|
|
1487
|
+
rows,
|
|
1488
|
+
failedRows
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1419
1491
|
async startImport() {
|
|
1420
1492
|
if (!this.hasMappings) {
|
|
1421
1493
|
return;
|
|
@@ -1448,9 +1520,8 @@ class ImportState {
|
|
|
1448
1520
|
}
|
|
1449
1521
|
this._cancelled = false;
|
|
1450
1522
|
this._abortController = new AbortController();
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
// total is known up front from the parsed CSV and stays fixed through polling.
|
|
1523
|
+
this._validationFailures = [];
|
|
1524
|
+
this._uploadedRows = undefined;
|
|
1454
1525
|
const totalCount = this.csvRows.length;
|
|
1455
1526
|
(0, _mobx.runInAction)(() => {
|
|
1456
1527
|
this.currentStep = 'progress';
|
|
@@ -1488,8 +1559,13 @@ class ImportState {
|
|
|
1488
1559
|
// before uploading. A creation failure surfaces as the error state with a
|
|
1489
1560
|
// "Try again" CTA, like an upload/job failure.
|
|
1490
1561
|
let resolvedMapping;
|
|
1562
|
+
let prepared;
|
|
1491
1563
|
try {
|
|
1492
1564
|
resolvedMapping = await this._resolveFieldMapping();
|
|
1565
|
+
if (this._cancelled) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
prepared = await this._validateRows(resolvedMapping, this._abortController.signal);
|
|
1493
1569
|
} catch (error) {
|
|
1494
1570
|
(0, _mobx.runInAction)(() => {
|
|
1495
1571
|
this.importStatus = {
|
|
@@ -1506,7 +1582,18 @@ class ImportState {
|
|
|
1506
1582
|
if (this._cancelled) {
|
|
1507
1583
|
return;
|
|
1508
1584
|
}
|
|
1509
|
-
const
|
|
1585
|
+
const uploadedRows = prepared.rows;
|
|
1586
|
+
this._uploadedRows = uploadedRows;
|
|
1587
|
+
this._validationFailures = prepared.failedRows;
|
|
1588
|
+
(0, _mobx.runInAction)(() => {
|
|
1589
|
+
this.result = {
|
|
1590
|
+
...this.result,
|
|
1591
|
+
failed: this._validationFailures.length
|
|
1592
|
+
};
|
|
1593
|
+
this.processedCount = this._validationFailures.length;
|
|
1594
|
+
this.totalCount = uploadedRows.length + this._validationFailures.length;
|
|
1595
|
+
});
|
|
1596
|
+
const promise = uploadedRows.length ? this._runImportJob(resolvedMapping, uploadedRows) : Promise.resolve(this.result);
|
|
1510
1597
|
this.importStatus = {
|
|
1511
1598
|
..._model.queryStatus.loading,
|
|
1512
1599
|
promise
|