fuse-importer 0.1.3-testing → 0.1.5-testing
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/lib/esm/Importer/ImporterWithContext.js +38 -7
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/index.js +1 -1
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/index.js +4 -3
- package/lib/esm/Importer/Matcher/HeaderMatcher/index.js +14 -9
- package/lib/esm/Importer/Matcher/index.js +0 -11
- package/lib/esm/Importer/PreviewFirstTime.js +1 -1
- package/lib/esm/Importer/Review/ReviewContextProvider.d.ts +6 -6
- package/lib/esm/Importer/Review/ReviewContextProvider.js +53 -184
- package/lib/esm/Importer/Review/ReviewWithContext.js +2 -2
- package/lib/esm/Importer/Stepper/StepperSubmitModal.d.ts +2 -1
- package/lib/esm/Importer/Stepper/StepperSubmitModal.js +4 -2
- package/lib/esm/Importer/Stepper/UnmatchedHeadersModal.js +1 -1
- package/lib/esm/Importer/Stepper/index.js +21 -11
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterDropzone.d.ts +2 -1
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterDropzone.js +14 -86
- package/lib/esm/Importer/Uploader/DragAndDropImporter/index.js +11 -3
- package/lib/esm/Importer/Uploader/HeadersPreview.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/DataSetContextProvider/index.d.ts +16 -0
- package/lib/esm/Importer/common/Spreadsheet/DataSetContextProvider/index.js +63 -0
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.d.ts +18 -0
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.js +101 -0
- package/lib/esm/Importer/common/Spreadsheet/FilteredDataContextProvider/index.d.ts +29 -0
- package/lib/esm/Importer/common/Spreadsheet/FilteredDataContextProvider/index.js +150 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/filterMethods.d.ts +6 -4
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/filterMethods.js +37 -37
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.d.ts +6 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.js +138 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.d.ts +7 -29
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.js +11 -193
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.d.ts +5 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.js +72 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.d.ts +4 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js +46 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/utils.js +2 -1
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.d.ts +31 -0
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.js +304 -0
- package/lib/esm/Importer/common/Spreadsheet/common/index.js +5 -4
- package/lib/esm/Importer/common/Spreadsheet/common/types.d.ts +2 -3
- package/lib/esm/Importer/common/Spreadsheet/components/FieldHeader.d.ts +0 -2
- package/lib/esm/Importer/common/Spreadsheet/components/FieldHeader.js +26 -11
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.js +21 -13
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.js +35 -36
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowNumbers.js +3 -3
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpreadsheetInput.js +5 -1
- package/lib/esm/Importer/common/Spreadsheet/components/fields/index.js +57 -26
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/index.js +1 -2
- package/lib/esm/Importer/common/Spreadsheet/index.d.ts +0 -1
- package/lib/esm/Importer/common/Spreadsheet/index.js +1 -84
- package/lib/esm/Importer/common/Spreadsheet/styles.d.ts +1 -2
- package/lib/esm/Importer/common/Spreadsheet/styles.js +13 -1
- package/lib/esm/Importer/common/Spreadsheet/useFieldSorting.d.ts +5 -0
- package/lib/esm/Importer/common/Spreadsheet/useFieldSorting.js +81 -0
- package/lib/esm/Importer/common/Spreadsheet/validation/index.d.ts +5 -3
- package/lib/esm/Importer/common/Spreadsheet/validation/index.js +13 -17
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.d.ts +3 -2
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.js +16 -7
- package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +4 -2
- package/lib/esm/Importer/contexts/ImporterContextProvider.js +137 -18
- package/lib/esm/Importer/data/index.js +7 -5
- package/lib/esm/Importer/hooks/useExportDataToFile.d.ts +5 -0
- package/lib/esm/Importer/hooks/useExportDataToFile.js +54 -0
- package/lib/esm/Importer/hooks/useSubmitToServer.d.ts +7 -0
- package/lib/esm/Importer/hooks/useSubmitToServer.js +192 -0
- package/lib/esm/common/EventManagerContextProvider/index.d.ts +22 -0
- package/lib/esm/common/EventManagerContextProvider/index.js +38 -0
- package/lib/esm/common/FileUploadDropzone/ImporterDropzone.d.ts +16 -0
- package/lib/esm/common/FileUploadDropzone/ImporterDropzone.js +108 -0
- package/lib/esm/common/FileUploadDropzone/index.d.ts +1 -0
- package/lib/esm/common/FileUploadDropzone/index.js +1 -0
- package/lib/esm/common/Table/TableActions/CustomActions/CustomActions.js +55 -41
- package/lib/esm/common/Table/TableActions/DeleteSelectedRows.js +25 -16
- package/lib/esm/common/Table/TableActions/ExportData.js +5 -3
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +36 -9
- package/lib/esm/common/Table/TableActions/RowFilters.js +53 -5
- package/lib/esm/common/Table/TableActions/SearchRows.js +3 -1
- package/lib/esm/common/Table/TableActions/TableActions.js +2 -1
- package/lib/esm/common/Table/TableActions/TransformedRecordsCount.js +16 -9
- package/lib/esm/common/Table/TableActions/ValidationProgress.d.ts +2 -0
- package/lib/esm/common/Table/TableActions/ValidationProgress.js +22 -0
- package/lib/esm/common/Table/TableView/TableRows/TableRow.d.ts +1 -1
- package/lib/esm/common/Table/TableView/TableRows/TableRow.js +2 -2
- package/lib/esm/common/Table/TableView/TableRows/index.js +21 -6
- package/lib/esm/common/Table/TableView/index.d.ts +1 -1
- package/lib/esm/common/Table/TableView/index.js +6 -15
- package/lib/esm/common/Table/TableView/types.d.ts +8 -9
- package/lib/esm/common/Table/index.d.ts +2 -1
- package/lib/esm/common/Table/index.js +2 -2
- package/lib/esm/common/Toast.js +3 -2
- package/lib/esm/common/TooltipProvider.d.ts +2 -0
- package/lib/esm/common/TooltipProvider.js +12 -9
- package/lib/esm/common/buttons.d.ts +5 -1
- package/lib/esm/common/buttons.js +13 -7
- package/lib/esm/common/columnsTransformations.js +1 -1
- package/lib/esm/common/datePatterns.js +10 -10
- package/lib/esm/common/icons/index.d.ts +1 -0
- package/lib/esm/common/icons/index.js +1 -0
- package/lib/esm/common/index.d.ts +1 -0
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/inputs/Autocomplete.js +1 -1
- package/lib/esm/locales/de.d.ts +1 -1
- package/lib/esm/locales/de.js +1 -1
- package/lib/esm/locales/en.d.ts +1 -1
- package/lib/esm/locales/en.js +4 -4
- package/lib/esm/locales/es.d.ts +1 -1
- package/lib/esm/locales/es.js +1 -1
- package/lib/esm/locales/fr.d.ts +1 -1
- package/lib/esm/locales/fr.js +1 -1
- package/lib/esm/types.d.ts +27 -4
- package/lib/main.js +24 -24
- package/package.json +6 -4
- package/lib/esm/Importer/Stepper/common/getEnumFieldValueMatchingsInitialValue.d.ts +0 -8
- package/lib/esm/Importer/Stepper/common/getEnumFieldValueMatchingsInitialValue.js +0 -33
- package/lib/esm/Importer/common/Spreadsheet/components/ValidationProgress.d.ts +0 -5
- package/lib/esm/Importer/common/Spreadsheet/components/ValidationProgress.js +0 -19
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/EmailInput.d.ts +0 -3
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/EmailInput.js +0 -14
- package/lib/esm/Importer/common/Spreadsheet/hooks.d.ts +0 -33
- package/lib/esm/Importer/common/Spreadsheet/hooks.js +0 -256
- package/lib/esm/common/Table/TableActions/FilterByErrors/functions.d.ts +0 -11
- package/lib/esm/common/Table/TableActions/FilterByErrors/functions.js +0 -35
- package/lib/esm/common/Table/TableActions/hooks.d.ts +0 -18
- package/lib/esm/common/Table/TableActions/hooks.js +0 -41
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DuplicateRecordIds, Record } from "../../../../types";
|
|
2
2
|
import { SpreadsheetFilter } from "./useSpreadsheetFilter";
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
5
|
-
|
|
3
|
+
type FilterCondition = (id: string) => boolean;
|
|
4
|
+
export declare const getFilterConditions: (spreadsheetFilter: SpreadsheetFilter, getRecord: (recordId: string) => Record, errors: {
|
|
5
|
+
current: Record;
|
|
6
|
+
}, filteredInputValue: string, duplicateRecordIds: DuplicateRecordIds) => FilterCondition[];
|
|
7
|
+
export {};
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { rowIsEmpty } from "./utils";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export var getFilterConditions = function (spreadsheetFilter, getRecord, errors, filteredInputValue, duplicateRecordIds) {
|
|
3
|
+
var filterConditions = [];
|
|
4
|
+
switch (spreadsheetFilter.type) {
|
|
5
|
+
case "rowBased":
|
|
6
|
+
if (spreadsheetFilter.byRow === "all") {
|
|
7
|
+
filterConditions.push(function (key) { return true; });
|
|
8
|
+
}
|
|
9
|
+
if (spreadsheetFilter.byRow === "invalid") {
|
|
10
|
+
filterConditions.push(function (key) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
return (((_b = (_a = getRecord(key)) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.isInvalid) && !rowIsEmpty(getRecord(key)));
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (spreadsheetFilter.byRow === "duplicates")
|
|
16
|
+
filterConditions.push(function (key) { return duplicateRecordIds.has(key); });
|
|
17
|
+
break;
|
|
18
|
+
case "columnBased":
|
|
19
|
+
if (spreadsheetFilter.byColumn.type === "fieldWithErrors") {
|
|
20
|
+
filterConditions.push(function (key) {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
return ((_b = (_a = getRecord(key)) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.isInvalid) &&
|
|
23
|
+
((_c = errors.current[key]) === null || _c === void 0 ? void 0 : _c[spreadsheetFilter.byColumn.field]);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
7
28
|
var includesSearchValue = function (value, searchValue) {
|
|
8
29
|
if (typeof value === "string" || typeof value === "number") {
|
|
9
30
|
var stringValue = String(value).toLowerCase();
|
|
@@ -12,38 +33,17 @@ export var filterRecordsBySearchValue = function (obj, value) {
|
|
|
12
33
|
}
|
|
13
34
|
return false;
|
|
14
35
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
if (filteredInputValue) {
|
|
37
|
+
filterConditions.push(function (key) {
|
|
38
|
+
var record = getRecord(key);
|
|
39
|
+
// check if any of the values in the record contain the search input
|
|
40
|
+
for (var fieldName in record) {
|
|
41
|
+
if (includesSearchValue(record[fieldName], filteredInputValue)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
23
46
|
});
|
|
24
|
-
if (matches) {
|
|
25
|
-
filteredObj[key] = currentObj;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return filteredObj;
|
|
29
|
-
};
|
|
30
|
-
export var filterRecordsByType = function (obj, filterType) {
|
|
31
|
-
var _a, _b;
|
|
32
|
-
var filteredObj = {};
|
|
33
|
-
for (var key in obj) {
|
|
34
|
-
if (filterType === "all" ||
|
|
35
|
-
(((_b = (_a = obj[key]) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.isInvalid) && !rowIsEmpty(obj[key]))) {
|
|
36
|
-
filteredObj[key] = obj[key];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return filteredObj;
|
|
40
|
-
};
|
|
41
|
-
//Filter records by selected column error
|
|
42
|
-
export var filterRecordsByError = function (obj, keyToFilter, errors) {
|
|
43
|
-
var filteredObj = {};
|
|
44
|
-
var filteredKeys = Object.keys(errors).filter(function (key) { var _a, _b; return ((_b = (_a = obj[key]) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.isInvalid) && errors[key][keyToFilter]; });
|
|
45
|
-
for (var i = 0; i < filteredKeys.length; i++) {
|
|
46
|
-
filteredObj[filteredKeys[i]] = obj[filteredKeys[i]];
|
|
47
47
|
}
|
|
48
|
-
return
|
|
48
|
+
return filterConditions;
|
|
49
49
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const RecordHashCalculator: () => {
|
|
2
|
+
computeHashesForRecords: (dataSet: any, fields: any, _onHashesComputed: any) => void;
|
|
3
|
+
};
|
|
4
|
+
export declare const RecordValueHashCalculator: () => {
|
|
5
|
+
computeDuplicateValueHashes: (dataSet: any, _field: any, _onDuplicateHashesComputed: any) => Promise<void>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { useBatchProcessing } from "./useBatchProcessing";
|
|
38
|
+
import { rowIsEmpty } from "./utils";
|
|
39
|
+
var findDuplicateHashes = function (sortedHashes) {
|
|
40
|
+
var _a;
|
|
41
|
+
var results = [];
|
|
42
|
+
for (var i = 0; i < sortedHashes.length - 1; i++) {
|
|
43
|
+
if (sortedHashes[i + 1].hash == sortedHashes[i].hash ||
|
|
44
|
+
((_a = sortedHashes[i - 1]) === null || _a === void 0 ? void 0 : _a.hash) == sortedHashes[i].hash) {
|
|
45
|
+
results.push(sortedHashes[i]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return results;
|
|
49
|
+
};
|
|
50
|
+
function compareHashes(a, b) {
|
|
51
|
+
if (a.hash < b.hash)
|
|
52
|
+
return -1;
|
|
53
|
+
if (a.hash > b.hash)
|
|
54
|
+
return 1;
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
// generate hashes that can be used for comparing two records
|
|
58
|
+
// for the sake of tracking duplicates
|
|
59
|
+
// if the hash for one record equals the hash for another,
|
|
60
|
+
// the two records are duplicates
|
|
61
|
+
export var RecordHashCalculator = function () {
|
|
62
|
+
var computeHashesForBatch = function (dataSet, fields) {
|
|
63
|
+
var hashMap = [];
|
|
64
|
+
var _loop_1 = function (recordKey) {
|
|
65
|
+
var record = dataSet[recordKey];
|
|
66
|
+
var key = fields.map(function (field) { return record[field.name]; }).join("|");
|
|
67
|
+
if (!rowIsEmpty(record)) {
|
|
68
|
+
hashMap.push({ id: record._meta.id, hash: key });
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
for (var recordKey in dataSet) {
|
|
72
|
+
_loop_1(recordKey);
|
|
73
|
+
}
|
|
74
|
+
return hashMap;
|
|
75
|
+
};
|
|
76
|
+
var calculatingHashes = false;
|
|
77
|
+
var computeHashesForRecords = function (dataSet, fields, _onHashesComputed) {
|
|
78
|
+
if (!dataSet || calculatingHashes) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
var processInBatches = useBatchProcessing().processInBatches;
|
|
82
|
+
calculatingHashes = true;
|
|
83
|
+
var results = [];
|
|
84
|
+
processInBatches(dataSet, function (batch) {
|
|
85
|
+
results = results.concat(computeHashesForBatch(batch, fields));
|
|
86
|
+
});
|
|
87
|
+
results.sort(compareHashes);
|
|
88
|
+
var duplicateHashes = findDuplicateHashes(results);
|
|
89
|
+
_onHashesComputed(duplicateHashes);
|
|
90
|
+
calculatingHashes = false;
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
computeHashesForRecords: computeHashesForRecords,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
// generate hashes that can be used for comparing the values of a specific field
|
|
97
|
+
// for the sake of tracking uniqueness
|
|
98
|
+
export var RecordValueHashCalculator = function () {
|
|
99
|
+
var columnsBeingCalculated = [];
|
|
100
|
+
var computeHashesForBatch = function (dataSet, field) {
|
|
101
|
+
var hashMap = [];
|
|
102
|
+
var isCaseInsensitive = field.validations.find(function (v) {
|
|
103
|
+
return v.name === "unique_case_insensitive";
|
|
104
|
+
}) !== undefined;
|
|
105
|
+
for (var recordKey in dataSet) {
|
|
106
|
+
var record = dataSet[recordKey];
|
|
107
|
+
var key = record[field.name];
|
|
108
|
+
if (isCaseInsensitive) {
|
|
109
|
+
key = key.toLowerCase();
|
|
110
|
+
}
|
|
111
|
+
if (key) {
|
|
112
|
+
hashMap.push({ id: record._meta.id, hash: key });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return hashMap;
|
|
116
|
+
};
|
|
117
|
+
var computeDuplicateValueHashes = function (dataSet, _field, _onDuplicateHashesComputed) { return __awaiter(void 0, void 0, void 0, function () {
|
|
118
|
+
var processInBatches, results;
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
if (!dataSet || columnsBeingCalculated[_field.name]) {
|
|
121
|
+
return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
columnsBeingCalculated[_field.name] = true;
|
|
124
|
+
processInBatches = useBatchProcessing().processInBatches;
|
|
125
|
+
results = [];
|
|
126
|
+
processInBatches(dataSet, function (batch) {
|
|
127
|
+
results = results.concat(computeHashesForBatch(batch, _field));
|
|
128
|
+
});
|
|
129
|
+
results.sort(compareHashes);
|
|
130
|
+
_onDuplicateHashesComputed(results);
|
|
131
|
+
columnsBeingCalculated[_field.name] = false;
|
|
132
|
+
return [2 /*return*/];
|
|
133
|
+
});
|
|
134
|
+
}); };
|
|
135
|
+
return {
|
|
136
|
+
computeDuplicateValueHashes: computeDuplicateValueHashes,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
@@ -1,47 +1,25 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { SpreadsheetOptions } from "../../../..";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ValidationState } from "../hooks";
|
|
6
|
-
import { SpreadsheetFilter } from "./useSpreadsheetFilter";
|
|
3
|
+
import { Field, RecordDataSet } from "../../../../types";
|
|
4
|
+
import { SpreadsheetProps } from "../common/types";
|
|
7
5
|
export type OnDataSetChanged = (dataSet: RecordDataSet) => void;
|
|
8
|
-
export type OnValidationStateChanged = (state: ValidationState) => void;
|
|
9
6
|
type State = {
|
|
10
|
-
|
|
7
|
+
filteredDataIds: string[];
|
|
11
8
|
fields: Field[];
|
|
12
9
|
isReadOnly?: boolean;
|
|
13
|
-
errors: BatchValidationErrors;
|
|
14
|
-
warnings: BatchValidationErrors;
|
|
15
10
|
options: SpreadsheetOptions;
|
|
16
|
-
sortByFieldErrors: string;
|
|
17
|
-
sortByFieldWarnings: string;
|
|
18
|
-
updateRecord: (record: Record) => void;
|
|
19
|
-
setSortByFieldErrors: React.Dispatch<React.SetStateAction<string>>;
|
|
20
11
|
selectedRows: string[];
|
|
21
12
|
setSelectedRows: React.Dispatch<React.SetStateAction<string[]>>;
|
|
22
|
-
setSortByFieldWarnings: React.Dispatch<React.SetStateAction<string>>;
|
|
23
|
-
deleteRecords: (selectedRecords: string[]) => void;
|
|
24
13
|
lastClickedIndexRef: React.MutableRefObject<number | null>;
|
|
25
|
-
filteredInputValue: string;
|
|
26
|
-
setFilteredInputValue: React.Dispatch<React.SetStateAction<string>>;
|
|
27
|
-
addNewRowsToSpreadsheet: () => void;
|
|
28
|
-
spreadsheetFilter: SpreadsheetFilter;
|
|
29
|
-
filterRecordsByRowType: (filterByRow: SpreadsheetFilter["byRow"]) => void;
|
|
30
|
-
filterRecordsByFieldErrors: (filterByColumn: string) => void;
|
|
31
|
-
resetSpreadsheetFilter: () => void;
|
|
32
|
-
recordsWithValuesCount: number;
|
|
33
|
-
filteredDataCount: number;
|
|
34
14
|
checkboxColumnWidth: number;
|
|
35
|
-
isFiltering: boolean;
|
|
36
|
-
sortBy: SortBy | null;
|
|
37
|
-
setSortBy: React.Dispatch<React.SetStateAction<SortBy>>;
|
|
38
15
|
setIsTransformTooltipOpened: React.Dispatch<React.SetStateAction<boolean>>;
|
|
39
16
|
isTransformTooltipOpened: boolean;
|
|
40
|
-
|
|
41
|
-
|
|
17
|
+
inefficientRerender: boolean;
|
|
18
|
+
setInefficientRerender: React.Dispatch<React.SetStateAction<boolean>>;
|
|
19
|
+
};
|
|
42
20
|
type Props = SpreadsheetProps & {
|
|
43
21
|
children: JSX.Element;
|
|
44
22
|
};
|
|
45
|
-
export declare const SpreadsheetContextProvider: ({
|
|
23
|
+
export declare const SpreadsheetContextProvider: ({ fields, options, isReadOnly, children, onValidateRecord, selectedRows, setSelectedRows, }: Props) => JSX.Element;
|
|
46
24
|
export declare const useSpreadsheetContext: () => State;
|
|
47
25
|
export {};
|
|
@@ -21,207 +21,25 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import { useValidationState } from "../hooks";
|
|
28
|
-
import { useSpreadsheetFilter, } from "./useSpreadsheetFilter";
|
|
29
|
-
import { filterRecordsByType, filterRecordsByError, filterRecordsBySearchValue, } from "./filterMethods";
|
|
30
|
-
import { hasValueInAnyField, rowIsEmpty } from "./utils";
|
|
31
|
-
var getDefaultSortCompareFn = function (sortBy) {
|
|
32
|
-
return function (a, b) {
|
|
33
|
-
var aField = get(a, sortBy.field);
|
|
34
|
-
var bField = get(b, sortBy.field);
|
|
35
|
-
if (aField === bField)
|
|
36
|
-
return a._meta.rowIndex > b._meta.rowIndex ? 1 : -1;
|
|
37
|
-
if (!aField)
|
|
38
|
-
return 1;
|
|
39
|
-
if (!bField)
|
|
40
|
-
return -1;
|
|
41
|
-
if (sortBy.direction === "asc")
|
|
42
|
-
return aField > bField ? 1 : -1;
|
|
43
|
-
return aField < bField ? 1 : -1;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
24
|
+
import { createContext, useContext, useMemo, useRef, useState, } from "react";
|
|
25
|
+
import { useFilteredDataContext } from "../FilteredDataContextProvider";
|
|
26
|
+
import { useValidationContext } from "../ValidationContextProvider";
|
|
46
27
|
var SpreadsheetContext = createContext({});
|
|
47
28
|
export var SpreadsheetContextProvider = function (_a) {
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var _g = useState(null), sortBy = _g[0], setSortBy = _g[1];
|
|
54
|
-
var addRowTimeoutRef = useRef(null);
|
|
55
|
-
var _h = useState(false), isTransformTooltipOpened = _h[0], setIsTransformTooltipOpened = _h[1];
|
|
56
|
-
var _j = useSpreadsheetFilter(), spreadsheetFilter = _j.spreadsheetFilter, filterRecordsByRowType = _j.filterRecordsByRowType, filterRecordsByFieldErrors = _j.filterRecordsByFieldErrors, resetSpreadsheetFilter = _j.resetSpreadsheetFilter;
|
|
57
|
-
var _k = useValidationState({
|
|
58
|
-
dataSet: dataSet,
|
|
59
|
-
initialDataSet: initialDataSet,
|
|
60
|
-
fields: fields,
|
|
61
|
-
options: options,
|
|
62
|
-
isReadOnly: isReadOnly,
|
|
63
|
-
setDataSet: setDataSet,
|
|
64
|
-
onValidateRecord: onValidateRecord,
|
|
65
|
-
}), updateRecordAndRevalidate = _k.updateRecordAndRevalidate, deleteRecords = _k.deleteRecords, warnings = _k.warnings, errors = _k.errors, validationState = __rest(_k, ["updateRecordAndRevalidate", "deleteRecords", "warnings", "errors"]);
|
|
66
|
-
var addNewRowsToSpreadsheet = function () {
|
|
67
|
-
addRowTimeoutRef.current = setTimeout(function () {
|
|
68
|
-
var _a, _b;
|
|
69
|
-
var highestRowIndex = -1;
|
|
70
|
-
for (var key in dataSet)
|
|
71
|
-
if (((_b = (_a = dataSet[key]) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.rowIndex) > highestRowIndex)
|
|
72
|
-
highestRowIndex = dataSet[key]._meta.rowIndex;
|
|
73
|
-
var newRow = addMeta({}, highestRowIndex + 1);
|
|
74
|
-
setDataSet(function (oldValues) {
|
|
75
|
-
var _a;
|
|
76
|
-
return (__assign(__assign({}, oldValues), (_a = {}, _a[newRow._meta.id] = newRow, _a)));
|
|
77
|
-
});
|
|
78
|
-
addRowTimeoutRef.current = null;
|
|
79
|
-
}, 300);
|
|
80
|
-
};
|
|
81
|
-
var handleDeleteErrors = function (selectedRows) {
|
|
82
|
-
deleteRecords(selectedRows, errors, warnings);
|
|
83
|
-
};
|
|
84
|
-
var duplicateRecords = useMemo(function () {
|
|
85
|
-
if (isReadOnly)
|
|
86
|
-
return { records: {}, count: 0 };
|
|
87
|
-
var uniqueRecords = new Map();
|
|
88
|
-
var duplicateGroups = [];
|
|
89
|
-
var _loop_1 = function (recordKey) {
|
|
90
|
-
if (Object.prototype.hasOwnProperty.call(dataSet, recordKey)) {
|
|
91
|
-
var record_1 = dataSet[recordKey];
|
|
92
|
-
if (rowIsEmpty(record_1))
|
|
93
|
-
return "continue";
|
|
94
|
-
var key = fields.map(function (field) { return record_1[field.name]; }).join("|");
|
|
95
|
-
if (uniqueRecords.has(key)) {
|
|
96
|
-
var saved_1 = uniqueRecords.get(key);
|
|
97
|
-
var existingGroup = duplicateGroups.find(function (group) {
|
|
98
|
-
return group.some(function (item) { return item._meta.id === saved_1._meta.id; });
|
|
99
|
-
});
|
|
100
|
-
if (existingGroup) {
|
|
101
|
-
existingGroup.push(record_1);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
duplicateGroups.push([saved_1, record_1]);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
uniqueRecords.set(key, record_1);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
for (var recordKey in dataSet) {
|
|
113
|
-
_loop_1(recordKey);
|
|
114
|
-
}
|
|
115
|
-
var count = duplicateGroups.length;
|
|
116
|
-
var records = {};
|
|
117
|
-
for (var i = 0; i < duplicateGroups.length; i++) {
|
|
118
|
-
var group = duplicateGroups[i];
|
|
119
|
-
for (var j = 0; j < group.length; j++) {
|
|
120
|
-
var record = group[j];
|
|
121
|
-
records[record._meta.id] = __assign({}, record);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return { records: records, count: count };
|
|
125
|
-
}, [dataSet]);
|
|
126
|
-
var dataSnapshot = useMemo(function () {
|
|
127
|
-
var filteredData = dataSet;
|
|
128
|
-
switch (spreadsheetFilter.type) {
|
|
129
|
-
case "rowBased":
|
|
130
|
-
if (spreadsheetFilter.byRow === "duplicates") {
|
|
131
|
-
filteredData = duplicateRecords.records;
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
filteredData = filterRecordsByType(dataSet, spreadsheetFilter.byRow);
|
|
135
|
-
break;
|
|
136
|
-
case "columnBased":
|
|
137
|
-
filteredData = filterRecordsByError(dataSet, spreadsheetFilter.byColumn.field, errors);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
var filteredDatasetByString = filteredInputValue
|
|
141
|
-
? filterRecordsBySearchValue(filteredData, filteredInputValue)
|
|
142
|
-
: filteredData;
|
|
143
|
-
var dataSetValues = Object.values(filteredDatasetByString);
|
|
144
|
-
if (sortBy) {
|
|
145
|
-
return dataSetValues.sort(getSortCompareFn(sortBy));
|
|
146
|
-
}
|
|
147
|
-
else if (!!sortByFieldErrors || !!sortByFieldWarnings)
|
|
148
|
-
return dataSetValues.sort(function (a, b) {
|
|
149
|
-
var aHasErrors = !!get(sortByFieldErrors ? errors : warnings, "".concat(get(a, "_meta.id"), ".").concat(sortByFieldErrors || sortByFieldWarnings), false);
|
|
150
|
-
var bHasErrors = !!get(sortByFieldErrors ? errors : warnings, "".concat(get(b, "_meta.id"), ".").concat(sortByFieldErrors || sortByFieldWarnings), false);
|
|
151
|
-
if (aHasErrors === bHasErrors) {
|
|
152
|
-
return a._meta.rowIndex > b._meta.rowIndex ? 1 : -1;
|
|
153
|
-
}
|
|
154
|
-
return bHasErrors ? 1 : -1;
|
|
155
|
-
});
|
|
156
|
-
return dataSetValues;
|
|
157
|
-
}, [
|
|
158
|
-
filteredInputValue,
|
|
159
|
-
spreadsheetFilter,
|
|
160
|
-
sortBy,
|
|
161
|
-
Object.keys(dataSet).length,
|
|
162
|
-
duplicateRecords.count,
|
|
163
|
-
sortByFieldErrors,
|
|
164
|
-
sortByFieldWarnings,
|
|
165
|
-
]);
|
|
166
|
-
var recordsWithValuesCount = useMemo(function () {
|
|
167
|
-
return Object.values(dataSet).filter(hasValueInAnyField).length;
|
|
168
|
-
}, [dataSet]);
|
|
169
|
-
var filteredDataCount = useMemo(function () {
|
|
170
|
-
return Object.values(dataSnapshot).filter(hasValueInAnyField).length;
|
|
171
|
-
}, [dataSnapshot]);
|
|
172
|
-
var isFiltering = useMemo(function () { return !!filteredInputValue; }, [filteredInputValue]);
|
|
173
|
-
useEffect(function () {
|
|
174
|
-
onDataSetChanged && onDataSetChanged(dataSet);
|
|
175
|
-
if (addRowTimeoutRef.current) {
|
|
176
|
-
// avoid adding new rows when the user is typing
|
|
177
|
-
clearTimeout(addRowTimeoutRef.current);
|
|
178
|
-
}
|
|
179
|
-
var dataSetKeys = Object.keys(dataSet);
|
|
180
|
-
var latestDataSet = dataSet[dataSetKeys[dataSetKeys.length - 1]];
|
|
181
|
-
var latestDataSetValuesWithoutMeta = Object.values(latestDataSet).filter(function (key) { return key !== "_meta"; });
|
|
182
|
-
var hasValueInTheLastObject = latestDataSetValuesWithoutMeta
|
|
183
|
-
.filter(function (value) {
|
|
184
|
-
return value !== null && value !== undefined && typeof value !== "object";
|
|
185
|
-
})
|
|
186
|
-
.some(function (value) { return value !== "null" && value !== "undefined"; });
|
|
187
|
-
if (hasValueInTheLastObject) {
|
|
188
|
-
addNewRowsToSpreadsheet();
|
|
189
|
-
}
|
|
190
|
-
}, [dataSet]);
|
|
191
|
-
// Review this later, this probably isn't the best approach
|
|
192
|
-
useEffect(function () {
|
|
193
|
-
setDataSet(initialDataSet);
|
|
194
|
-
}, [initialDataSet]);
|
|
195
|
-
useEffect(function () {
|
|
196
|
-
onValidationStateChanged &&
|
|
197
|
-
onValidationStateChanged(__assign(__assign({}, validationState), { errors: errors, warnings: warnings }));
|
|
198
|
-
}, [validationState, onValidationStateChanged]);
|
|
199
|
-
var handleSortByFieldErrors = useCallback(function (field) {
|
|
200
|
-
setSortByFieldErrors(field === sortByFieldErrors ? null : field);
|
|
201
|
-
setSortByFieldWarnings(null);
|
|
202
|
-
setSortBy(null);
|
|
203
|
-
}, [sortByFieldErrors]);
|
|
204
|
-
var handleSortByFieldWarnings = useCallback(function (field) {
|
|
205
|
-
setSortByFieldWarnings(field === sortByFieldWarnings ? null : field);
|
|
206
|
-
setSortByFieldErrors(null);
|
|
207
|
-
setSortBy(null);
|
|
208
|
-
}, [sortByFieldWarnings]);
|
|
29
|
+
var fields = _a.fields, options = _a.options, isReadOnly = _a.isReadOnly, children = _a.children, onValidateRecord = _a.onValidateRecord, selectedRows = _a.selectedRows, setSelectedRows = _a.setSelectedRows;
|
|
30
|
+
var _b = useState(false), isTransformTooltipOpened = _b[0], setIsTransformTooltipOpened = _b[1];
|
|
31
|
+
var _c = useState(false), inefficientRerender = _c[0], setInefficientRerender = _c[1];
|
|
32
|
+
var filteredDataIds = useFilteredDataContext().filteredDataIds;
|
|
33
|
+
var _d = useValidationContext(), calculateColumnErrorCounts = _d.calculateColumnErrorCounts, calculateColumnWarningCounts = _d.calculateColumnWarningCounts, warnings = _d.warnings, errors = _d.errors, validationState = __rest(_d, ["calculateColumnErrorCounts", "calculateColumnWarningCounts", "warnings", "errors"]);
|
|
209
34
|
var lastClickedIndexRef = useRef(null);
|
|
210
35
|
var checkboxColumnWidth = useMemo(function () {
|
|
211
|
-
var lastRowIndexLength =
|
|
36
|
+
var lastRowIndexLength = filteredDataIds.length.toString().length;
|
|
212
37
|
var singleLetterWidth = 15;
|
|
213
38
|
var horizontalSpacing = 8;
|
|
214
39
|
var baseCheckboxColumnWidth = lastRowIndexLength * singleLetterWidth + horizontalSpacing;
|
|
215
40
|
return baseCheckboxColumnWidth < 40 ? 40 : baseCheckboxColumnWidth;
|
|
216
|
-
}, [
|
|
217
|
-
var
|
|
218
|
-
return dataSnapshot.map(function (data) {
|
|
219
|
-
var _a;
|
|
220
|
-
var updatedData = dataSet[(_a = data._meta) === null || _a === void 0 ? void 0 : _a.id];
|
|
221
|
-
return updatedData;
|
|
222
|
-
});
|
|
223
|
-
}, [dataSet, dataSnapshot]);
|
|
224
|
-
var value = __assign(__assign({ data: updatedDataSnapshot, fields: fields }, validationState), { isReadOnly: isReadOnly, sortByFieldErrors: sortByFieldErrors, sortByFieldWarnings: sortByFieldWarnings, options: options, recordsWithValuesCount: recordsWithValuesCount, filteredDataCount: filteredDataCount, sortBy: sortBy, warnings: warnings, errors: errors, setSortByFieldErrors: handleSortByFieldErrors, setSortByFieldWarnings: handleSortByFieldWarnings, onValidateRecord: onValidateRecord, updateRecord: updateRecordAndRevalidate, selectedRows: selectedRows, setSelectedRows: setSelectedRows, deleteRecords: handleDeleteErrors, filteredInputValue: filteredInputValue, setFilteredInputValue: setFilteredInputValue, lastClickedIndexRef: lastClickedIndexRef, addNewRowsToSpreadsheet: addNewRowsToSpreadsheet, spreadsheetFilter: spreadsheetFilter, resetSpreadsheetFilter: resetSpreadsheetFilter, filterRecordsByRowType: filterRecordsByRowType, filterRecordsByFieldErrors: filterRecordsByFieldErrors, checkboxColumnWidth: checkboxColumnWidth, setSortBy: setSortBy, isFiltering: isFiltering, setIsTransformTooltipOpened: setIsTransformTooltipOpened, isTransformTooltipOpened: isTransformTooltipOpened, duplicateRecords: duplicateRecords });
|
|
41
|
+
}, [filteredDataIds.length]);
|
|
42
|
+
var value = __assign(__assign({ filteredDataIds: filteredDataIds, fields: fields }, validationState), { isReadOnly: isReadOnly, options: options, onValidateRecord: onValidateRecord, selectedRows: selectedRows, setSelectedRows: setSelectedRows, lastClickedIndexRef: lastClickedIndexRef, checkboxColumnWidth: checkboxColumnWidth, setIsTransformTooltipOpened: setIsTransformTooltipOpened, isTransformTooltipOpened: isTransformTooltipOpened, inefficientRerender: inefficientRerender, setInefficientRerender: setInefficientRerender });
|
|
225
43
|
return (_jsx(SpreadsheetContext.Provider, __assign({ value: value }, { children: children })));
|
|
226
44
|
};
|
|
227
45
|
export var useSpreadsheetContext = function () { return useContext(SpreadsheetContext); };
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Record, RecordDataSet } from "../../../../types";
|
|
2
|
+
export declare const useBatchProcessing: (batchPageSize?: number) => {
|
|
3
|
+
processRecordsInBatches: (records: Record[], handleBatch: any) => Promise<void>;
|
|
4
|
+
processInBatches: (dataSet: RecordDataSet, handleBatch: any) => void;
|
|
5
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export var useBatchProcessing = function (batchPageSize) {
|
|
38
|
+
if (batchPageSize === void 0) { batchPageSize = 10000; }
|
|
39
|
+
var processRecordsInBatches = function (records, handleBatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
40
|
+
var dataSetLength, batchSize, batchCount, i, idx, batch;
|
|
41
|
+
return __generator(this, function (_a) {
|
|
42
|
+
switch (_a.label) {
|
|
43
|
+
case 0:
|
|
44
|
+
dataSetLength = records.length;
|
|
45
|
+
batchSize = Math.min(Math.floor(batchPageSize), dataSetLength) || dataSetLength;
|
|
46
|
+
batchCount = Math.ceil(dataSetLength / batchSize);
|
|
47
|
+
i = 0;
|
|
48
|
+
_a.label = 1;
|
|
49
|
+
case 1:
|
|
50
|
+
if (!(i < batchCount)) return [3 /*break*/, 4];
|
|
51
|
+
idx = i * batchSize;
|
|
52
|
+
batch = records.slice(idx, idx + batchSize);
|
|
53
|
+
return [4 /*yield*/, handleBatch(batch)];
|
|
54
|
+
case 2:
|
|
55
|
+
_a.sent();
|
|
56
|
+
_a.label = 3;
|
|
57
|
+
case 3:
|
|
58
|
+
i++;
|
|
59
|
+
return [3 /*break*/, 1];
|
|
60
|
+
case 4: return [2 /*return*/];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}); };
|
|
64
|
+
var processInBatches = function (dataSet, handleBatch) {
|
|
65
|
+
var records = Object.values(dataSet);
|
|
66
|
+
processRecordsInBatches(records, handleBatch);
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
processRecordsInBatches: processRecordsInBatches,
|
|
70
|
+
processInBatches: processInBatches,
|
|
71
|
+
};
|
|
72
|
+
};
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useFilteredDataContext } from "../FilteredDataContextProvider";
|
|
2
|
+
import { useDataSetContext } from "../DataSetContextProvider";
|
|
3
|
+
import { hasValueInAnyField } from "./utils";
|
|
4
|
+
import { addMeta } from "../../../../Importer/data";
|
|
5
|
+
import { useEventManagerContext } from "../../../../common/EventManagerContextProvider";
|
|
6
|
+
import { useValidationContext } from "../ValidationContextProvider";
|
|
7
|
+
import { useDuplicateDataContext } from "../DuplicateDataContextProvider";
|
|
8
|
+
export var useDataSetManipulation = function () {
|
|
9
|
+
var _a = useFilteredDataContext(), lastFilteredRecordId = _a.lastFilteredRecordId, setRecalculateFilters = _a.setRecalculateFilters;
|
|
10
|
+
var _b = useDataSetContext(), getRecord = _b.getRecord, setRecord = _b.setRecord, dataSet = _b.dataSet, deleteRecord = _b.deleteRecord, emptyRecordIds = _b.emptyRecordIds;
|
|
11
|
+
var _c = useEventManagerContext(), emit = _c.emit, EVENTS = _c.EVENTS;
|
|
12
|
+
var _d = useValidationContext(), errors = _d.errors, warnings = _d.warnings, calculateColumnErrorCounts = _d.calculateColumnErrorCounts, calculateColumnWarningCounts = _d.calculateColumnWarningCounts;
|
|
13
|
+
var updateDuplicateValues = useDuplicateDataContext().updateDuplicateValues;
|
|
14
|
+
var updateRecordAndRevalidate = useValidationContext().updateRecordAndRevalidate;
|
|
15
|
+
var appendNewRecordToSpreadsheet = function () {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
var _record = getRecord(lastFilteredRecordId.current);
|
|
18
|
+
if (!hasValueInAnyField(_record)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var highestRowIndex = -1;
|
|
22
|
+
for (var recordId in dataSet.current)
|
|
23
|
+
if (((_b = (_a = getRecord(recordId)) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.rowIndex) > highestRowIndex)
|
|
24
|
+
highestRowIndex = getRecord(recordId)._meta.rowIndex;
|
|
25
|
+
var newRow = addMeta({}, highestRowIndex + 1);
|
|
26
|
+
setRecord(newRow._meta.id, newRow);
|
|
27
|
+
emit(EVENTS.ON_LAST_ROW_CHANGED);
|
|
28
|
+
};
|
|
29
|
+
var deleteRecordsFromSpreadsheet = function (recordIds) {
|
|
30
|
+
recordIds.forEach(function (recordId) {
|
|
31
|
+
updateDuplicateValues(getRecord(recordId), {}, false, updateRecordAndRevalidate);
|
|
32
|
+
deleteRecord(recordId);
|
|
33
|
+
calculateColumnErrorCounts(errors.current[recordId], {});
|
|
34
|
+
calculateColumnWarningCounts(warnings.current[recordId], {});
|
|
35
|
+
emptyRecordIds.current.delete(recordId);
|
|
36
|
+
});
|
|
37
|
+
setRecalculateFilters(function (prev) { return !prev; });
|
|
38
|
+
emit(EVENTS.UPDATE_COLUMN_ERROR_COUNT);
|
|
39
|
+
emit(EVENTS.UPDATE_TOTAL_ERROR_COUNT);
|
|
40
|
+
emit(EVENTS.UPDATE_TOTAL_ROW_COUNT);
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
appendNewRecordToSpreadsheet: appendNewRecordToSpreadsheet,
|
|
44
|
+
deleteRecordsFromSpreadsheet: deleteRecordsFromSpreadsheet,
|
|
45
|
+
};
|
|
46
|
+
};
|