fuse-importer 0.1.7-testing → 0.2.0-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 +11 -9
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/index.js +3 -3
- package/lib/esm/Importer/PreviewFirstTime.js +1 -1
- package/lib/esm/Importer/PreviewModeBanner.js +2 -2
- package/lib/esm/Importer/Review/AppResponseModal.js +2 -2
- package/lib/esm/Importer/Review/ReviewContextProvider.d.ts +2 -2
- package/lib/esm/Importer/Review/ReviewContextProvider.js +6 -6
- package/lib/esm/Importer/Stepper/StepperSubmitModal.js +21 -4
- package/lib/esm/Importer/Stepper/index.js +35 -20
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterSectionHeader/index.js +1 -1
- package/lib/esm/Importer/WarningsBanner.d.ts +3 -0
- package/lib/esm/Importer/WarningsBanner.js +42 -0
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.d.ts +5 -4
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.js +104 -50
- package/lib/esm/Importer/common/Spreadsheet/FilteredDataContextProvider/index.d.ts +1 -0
- package/lib/esm/Importer/common/Spreadsheet/FilteredDataContextProvider/index.js +6 -1
- package/lib/esm/Importer/common/Spreadsheet/KeyboardEventContextProvider/index.d.ts +7 -0
- package/lib/esm/Importer/common/Spreadsheet/KeyboardEventContextProvider/index.js +73 -0
- package/lib/esm/Importer/common/Spreadsheet/SearchContextProvider/index.d.ts +15 -0
- package/lib/esm/Importer/common/Spreadsheet/SearchContextProvider/index.js +43 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.d.ts +3 -2
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.js +40 -26
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.d.ts +2 -1
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.js +2 -1
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.d.ts +2 -2
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.js +13 -4
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useCellSelection.d.ts +24 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useCellSelection.js +207 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.d.ts +4 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js +118 -12
- package/lib/esm/Importer/common/Spreadsheet/UndoRedoContextProvider/index.d.ts +16 -0
- package/lib/esm/Importer/common/Spreadsheet/UndoRedoContextProvider/index.js +104 -0
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.js +39 -14
- package/lib/esm/Importer/common/Spreadsheet/common/index.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/common/index.js +13 -5
- package/lib/esm/Importer/common/Spreadsheet/components/FindAndReplace/index.d.ts +6 -0
- package/lib/esm/Importer/common/Spreadsheet/components/FindAndReplace/index.js +94 -0
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData/CellContextProvider.d.ts +23 -0
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData/CellContextProvider.js +128 -0
- package/lib/esm/Importer/common/Spreadsheet/components/{SpreadsheetData.d.ts → SpreadsheetData/index.d.ts} +1 -1
- package/lib/esm/Importer/common/Spreadsheet/components/{SpreadsheetData.js → SpreadsheetData/index.js} +19 -18
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.js +7 -7
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpeadsheetAutocomplete.js +3 -4
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpreadsheetInput.js +8 -8
- package/lib/esm/Importer/common/Spreadsheet/components/fields/index.d.ts +11 -0
- package/lib/esm/Importer/common/Spreadsheet/components/fields/index.js +26 -18
- package/lib/esm/Importer/common/Spreadsheet/transformation/index.d.ts +1 -2
- package/lib/esm/Importer/common/Spreadsheet/transformation/index.js +4 -8
- package/lib/esm/Importer/common/Spreadsheet/transformation/transformators/dateTimeAutoformatUtils.d.ts +5 -0
- package/lib/esm/Importer/common/Spreadsheet/transformation/transformators/dateTimeAutoformatUtils.js +231 -0
- package/lib/esm/Importer/common/Spreadsheet/transformation/{transformators.d.ts → transformators/index.d.ts} +6 -6
- package/lib/esm/Importer/common/Spreadsheet/transformation/{transformators.js → transformators/index.js} +24 -45
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.js +2 -0
- package/lib/esm/Importer/common/theme.d.ts +1 -0
- package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +8 -1
- package/lib/esm/Importer/contexts/ImporterContextProvider.js +18 -5
- package/lib/esm/Importer/data/index.d.ts +0 -1
- package/lib/esm/Importer/data/index.js +0 -37
- package/lib/esm/Importer/hooks/useSubmitToServer.d.ts +1 -1
- package/lib/esm/Importer/hooks/useSubmitToServer.js +55 -9
- package/lib/esm/common/CircleSpinner.d.ts +1 -0
- package/lib/esm/common/CircleSpinner.js +13 -0
- package/lib/esm/common/FileUploadDropzone/ImporterDropzone.js +56 -21
- package/lib/esm/common/Table/TableActions/CustomActions/CustomActions.js +28 -23
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +3 -3
- package/lib/esm/common/Table/TableActions/RowFilters.js +3 -3
- package/lib/esm/common/Table/TableActions/SearchRows.js +25 -25
- package/lib/esm/common/Table/TableActions/TableActions.js +7 -4
- package/lib/esm/common/Table/TableActions/TableActions.styles.js +2 -2
- package/lib/esm/common/Table/TableActions/TransformedRecordsCount.js +3 -3
- package/lib/esm/common/Table/TableActions/icons.d.ts +1 -0
- package/lib/esm/common/Table/TableActions/icons.js +1 -0
- package/lib/esm/common/Table/TableActions/useFindAndReplace.d.ts +5 -0
- package/lib/esm/common/Table/TableActions/useFindAndReplace.js +45 -0
- package/lib/esm/common/Table/TableView/TableRows/TableRow.js +1 -1
- package/lib/esm/common/Table/TableView/index.d.ts +1 -1
- package/lib/esm/common/Table/TableView/index.js +2 -2
- package/lib/esm/common/Table/TableView/types.d.ts +1 -0
- package/lib/esm/common/Toast.d.ts +42 -3
- package/lib/esm/common/Toast.js +56 -19
- package/lib/esm/common/datePatterns.d.ts +0 -1
- package/lib/esm/common/datePatterns.js +0 -10
- package/lib/esm/common/icons/index.d.ts +3 -0
- package/lib/esm/common/icons/index.js +5 -2
- package/lib/esm/common/inputs/Autocomplete.js +2 -2
- package/lib/esm/common/inputs/Checkbox.d.ts +2 -1
- package/lib/esm/common/inputs/Checkbox.js +9 -7
- package/lib/esm/common/inputs/TextInput.d.ts +1 -0
- package/lib/esm/common/inputs/TextInput.js +10 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/locales/de.d.ts +10 -0
- package/lib/esm/locales/de.js +10 -0
- package/lib/esm/locales/en.d.ts +23 -0
- package/lib/esm/locales/en.js +23 -0
- package/lib/esm/locales/es.d.ts +10 -0
- package/lib/esm/locales/es.js +10 -0
- package/lib/esm/locales/fr.d.ts +10 -0
- package/lib/esm/locales/fr.js +10 -0
- package/lib/esm/styled/theme/colorPalette.d.ts +2 -0
- package/lib/esm/styled/theme/colorPalette.js +1 -0
- package/lib/esm/styled/theme/index.d.ts +1 -0
- package/lib/esm/types.d.ts +1 -0
- package/lib/main.js +6 -6
- package/package.json +1 -1
- package/lib/esm/Importer/TrialModeBanner.d.ts +0 -1
- package/lib/esm/Importer/TrialModeBanner.js +0 -22
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { useEffect, useState } from "react";
|
|
49
|
+
import { fuseImporterId } from "../../../../common";
|
|
50
|
+
import { useDataSetContext } from "../DataSetContextProvider";
|
|
51
|
+
import { useFilteredDataContext } from "../FilteredDataContextProvider";
|
|
52
|
+
import { useValidationContext } from "../ValidationContextProvider";
|
|
53
|
+
import { useImporterContext } from "../../../contexts/ImporterContextProvider";
|
|
54
|
+
import { useDataSetManipulation } from "./useDataSetManipulation";
|
|
55
|
+
import { parseValue } from "../common";
|
|
56
|
+
import { useSpreadsheetContext } from ".";
|
|
57
|
+
export var defaultSelectionRect = {
|
|
58
|
+
start: { rowIndex: 0, colIndex: 0 },
|
|
59
|
+
end: { rowIndex: 0, colIndex: 0 },
|
|
60
|
+
initialCell: { rowIndex: 0, colIndex: 0 },
|
|
61
|
+
};
|
|
62
|
+
var getIframeBody = function (layoutRef) {
|
|
63
|
+
var iframeElement = document.getElementById(fuseImporterId);
|
|
64
|
+
var isCypressTestingEnv = !iframeElement.contentDocument;
|
|
65
|
+
if (isCypressTestingEnv)
|
|
66
|
+
return layoutRef.current;
|
|
67
|
+
return iframeElement.contentDocument.body;
|
|
68
|
+
};
|
|
69
|
+
export var useCellSelection = function (fields) {
|
|
70
|
+
var getRecord = useDataSetContext().getRecord;
|
|
71
|
+
var _a = useFilteredDataContext(), filteredDataIds = _a.filteredDataIds, isSortingOrFiltering = _a.isSortingOrFiltering;
|
|
72
|
+
var updateRecordAndRevalidate = useValidationContext().updateRecordAndRevalidate;
|
|
73
|
+
var layoutRef = useImporterContext().layoutRef;
|
|
74
|
+
var _b = useState(defaultSelectionRect), selectedCellRect = _b[0], setSelectedCellRect = _b[1];
|
|
75
|
+
var enumFieldValueMatchings = useImporterContext().enumFieldValueMatchings;
|
|
76
|
+
var isReadOnly = useSpreadsheetContext().isReadOnly;
|
|
77
|
+
var _c = useDataSetManipulation(), insertRecordsIntoSpreadsheet = _c.insertRecordsIntoSpreadsheet, addNewRecord = _c.addNewRecord;
|
|
78
|
+
useEffect(function () {
|
|
79
|
+
var iframeBody = getIframeBody(layoutRef);
|
|
80
|
+
iframeBody.addEventListener("paste", onPaste, true);
|
|
81
|
+
return function () {
|
|
82
|
+
iframeBody.removeEventListener("paste", onPaste, true);
|
|
83
|
+
};
|
|
84
|
+
}, [
|
|
85
|
+
selectedCellRect,
|
|
86
|
+
filteredDataIds,
|
|
87
|
+
isSortingOrFiltering,
|
|
88
|
+
enumFieldValueMatchings,
|
|
89
|
+
insertRecordsIntoSpreadsheet,
|
|
90
|
+
updateRecordAndRevalidate,
|
|
91
|
+
fields,
|
|
92
|
+
]);
|
|
93
|
+
useEffect(function () {
|
|
94
|
+
var handleCopy = function () { return handleCopyCutOperation(false); };
|
|
95
|
+
var handleCut = function () { return handleCopyCutOperation(true); };
|
|
96
|
+
var iframeBody = getIframeBody(layoutRef);
|
|
97
|
+
iframeBody.addEventListener("copy", handleCopy);
|
|
98
|
+
iframeBody.addEventListener("cut", handleCut);
|
|
99
|
+
return function () {
|
|
100
|
+
iframeBody.removeEventListener("copy", handleCopy);
|
|
101
|
+
iframeBody.removeEventListener("cut", handleCut);
|
|
102
|
+
};
|
|
103
|
+
}, [selectedCellRect]);
|
|
104
|
+
var onPaste = function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
105
|
+
var text, rows, maxCells, structuredData, startRowIndex, startColIndex, pastedRecordIds, newRecordId, pastedRecordValues;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0:
|
|
109
|
+
if (isReadOnly)
|
|
110
|
+
return [2 /*return*/];
|
|
111
|
+
text = event.clipboardData.getData("text");
|
|
112
|
+
if (!text.includes("\t") && !text.includes("\n")) {
|
|
113
|
+
return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
rows = text.split(/\r\n|\n|\r/);
|
|
116
|
+
maxCells = rows.reduce(function (max, row) { return Math.max(max, row.split("\t").length); }, 0);
|
|
117
|
+
structuredData = rows.map(function (row) {
|
|
118
|
+
var cells = row.split("\t");
|
|
119
|
+
while (cells.length < maxCells) {
|
|
120
|
+
cells.push("");
|
|
121
|
+
}
|
|
122
|
+
return cells;
|
|
123
|
+
});
|
|
124
|
+
startRowIndex = selectedCellRect.start.rowIndex;
|
|
125
|
+
startColIndex = selectedCellRect.start.colIndex;
|
|
126
|
+
pastedRecordIds = filteredDataIds.slice(startRowIndex, startRowIndex + structuredData.length);
|
|
127
|
+
if (!isSortingOrFiltering) {
|
|
128
|
+
while (pastedRecordIds.length < structuredData.length) {
|
|
129
|
+
newRecordId = addNewRecord();
|
|
130
|
+
pastedRecordIds.push(newRecordId);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
pastedRecordValues = pastedRecordIds.map(function (id) { return (__assign({}, getRecord(id))); });
|
|
134
|
+
structuredData.forEach(function (row, startRowIndex) {
|
|
135
|
+
row.forEach(function (value, colIndex) {
|
|
136
|
+
var field = fields[startColIndex + colIndex];
|
|
137
|
+
if (!field)
|
|
138
|
+
return;
|
|
139
|
+
var pastedRecordValue = pastedRecordValues[startRowIndex];
|
|
140
|
+
if (pastedRecordValue) {
|
|
141
|
+
var enumSet = Object.keys(enumFieldValueMatchings).length > 0
|
|
142
|
+
? enumFieldValueMatchings[field.label]
|
|
143
|
+
: field.options.reduce(function (acc, option) {
|
|
144
|
+
acc[option] = option;
|
|
145
|
+
return acc;
|
|
146
|
+
}, {});
|
|
147
|
+
pastedRecordValue[field.name] = parseValue(field.type, value, enumSet);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
if (!!isSortingOrFiltering) return [3 /*break*/, 2];
|
|
152
|
+
return [4 /*yield*/, insertRecordsIntoSpreadsheet(pastedRecordValues)];
|
|
153
|
+
case 1:
|
|
154
|
+
_a.sent();
|
|
155
|
+
return [3 /*break*/, 4];
|
|
156
|
+
case 2: return [4 /*yield*/, updateRecordAndRevalidate(pastedRecordValues)];
|
|
157
|
+
case 3:
|
|
158
|
+
_a.sent();
|
|
159
|
+
_a.label = 4;
|
|
160
|
+
case 4:
|
|
161
|
+
setSelectedCellRect({
|
|
162
|
+
start: { rowIndex: startRowIndex, colIndex: startColIndex },
|
|
163
|
+
end: {
|
|
164
|
+
rowIndex: startRowIndex + structuredData.length - 1,
|
|
165
|
+
colIndex: startColIndex + maxCells - 1,
|
|
166
|
+
},
|
|
167
|
+
initialCell: { rowIndex: startRowIndex, colIndex: startColIndex },
|
|
168
|
+
});
|
|
169
|
+
return [2 /*return*/];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}); };
|
|
173
|
+
var handleCopyCutOperation = function (isCut) {
|
|
174
|
+
var start = selectedCellRect.start, end = selectedCellRect.end;
|
|
175
|
+
var selectedCellsCount = (end.rowIndex - start.rowIndex + 1) * (end.colIndex - start.colIndex + 1);
|
|
176
|
+
if (selectedCellsCount <= 1)
|
|
177
|
+
return;
|
|
178
|
+
var updatedRecords = [];
|
|
179
|
+
var data = [];
|
|
180
|
+
for (var i = start.rowIndex; i <= end.rowIndex; i++) {
|
|
181
|
+
var rowData = [];
|
|
182
|
+
for (var j = start.colIndex; j <= end.colIndex; j++) {
|
|
183
|
+
var recordId = filteredDataIds[i];
|
|
184
|
+
var record = getRecord(recordId);
|
|
185
|
+
var cellData = record[fields[j].name];
|
|
186
|
+
rowData.push(cellData);
|
|
187
|
+
if (isCut) {
|
|
188
|
+
record[fields[j].name] = "";
|
|
189
|
+
updatedRecords.push(record);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
data.push(rowData);
|
|
193
|
+
}
|
|
194
|
+
if (isCut)
|
|
195
|
+
updateRecordAndRevalidate(updatedRecords);
|
|
196
|
+
var clipboardText = data.map(function (row) { return row.join("\t"); }).join("\n");
|
|
197
|
+
navigator.clipboard.writeText(clipboardText);
|
|
198
|
+
setSelectedCellRect(__assign(__assign({}, selectedCellRect), { isDashed: true }));
|
|
199
|
+
};
|
|
200
|
+
useEffect(function () {
|
|
201
|
+
setSelectedCellRect(defaultSelectionRect);
|
|
202
|
+
}, [filteredDataIds]);
|
|
203
|
+
return {
|
|
204
|
+
selectedCellRect: selectedCellRect,
|
|
205
|
+
setSelectedCellRect: setSelectedCellRect,
|
|
206
|
+
};
|
|
207
|
+
};
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { Record } from "../../../../types";
|
|
1
2
|
export declare const useDataSetManipulation: () => {
|
|
3
|
+
addNewRecord: () => string;
|
|
4
|
+
insertRecordsIntoSpreadsheet: (records: Record[]) => Promise<void>;
|
|
2
5
|
appendNewRecordToSpreadsheet: () => void;
|
|
3
6
|
deleteRecordsFromSpreadsheet: (recordIds: string[]) => void;
|
|
7
|
+
findAndReplaceInSpreadsheet: (searchText: string, replaceText: string, matchCase: boolean, useRegex: boolean) => Promise<any[]>;
|
|
4
8
|
};
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js
CHANGED
|
@@ -1,46 +1,152 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { useImporterContext } from "../../../../Importer/contexts/ImporterContextProvider";
|
|
4
49
|
import { addMeta } from "../../../../Importer/data";
|
|
5
50
|
import { useEventManagerContext } from "../../../../common/EventManagerContextProvider";
|
|
6
|
-
import
|
|
51
|
+
import useFindAndReplace from "../../../../common/Table/TableActions/useFindAndReplace";
|
|
52
|
+
import { useDataSetContext } from "../DataSetContextProvider";
|
|
7
53
|
import { useDuplicateDataContext } from "../DuplicateDataContextProvider";
|
|
54
|
+
import { useFilteredDataContext } from "../FilteredDataContextProvider";
|
|
55
|
+
import { useUndoRedoContext } from "../UndoRedoContextProvider";
|
|
56
|
+
import { useValidationContext } from "../ValidationContextProvider";
|
|
57
|
+
import { useBatchProcessing } from "./useBatchProcessing";
|
|
58
|
+
import { hasValueInAnyField } from "./utils";
|
|
8
59
|
export var useDataSetManipulation = function () {
|
|
9
60
|
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;
|
|
61
|
+
var _b = useDataSetContext(), getRecord = _b.getRecord, setRecord = _b.setRecord, dataSet = _b.dataSet, deleteRecord = _b.deleteRecord, emptyRecordIds = _b.emptyRecordIds, dataSetLength = _b.dataSetLength;
|
|
11
62
|
var _c = useEventManagerContext(), emit = _c.emit, EVENTS = _c.EVENTS;
|
|
12
63
|
var _d = useValidationContext(), errors = _d.errors, warnings = _d.warnings, calculateColumnErrorCounts = _d.calculateColumnErrorCounts, calculateColumnWarningCounts = _d.calculateColumnWarningCounts;
|
|
13
64
|
var updateDuplicateValues = useDuplicateDataContext().updateDuplicateValues;
|
|
14
65
|
var updateRecordAndRevalidate = useValidationContext().updateRecordAndRevalidate;
|
|
66
|
+
var processInBatches = useBatchProcessing().processInBatches;
|
|
67
|
+
var replaceInRecord = useFindAndReplace().replaceInRecord;
|
|
68
|
+
var trackRecordDeletion = useUndoRedoContext().trackRecordDeletion;
|
|
69
|
+
var layoutRef = useImporterContext().layoutRef;
|
|
70
|
+
var addNewRecord = function () {
|
|
71
|
+
var newRow = addMeta({}, dataSetLength.current);
|
|
72
|
+
setRecord(newRow._meta.id, newRow);
|
|
73
|
+
return newRow._meta.id;
|
|
74
|
+
};
|
|
15
75
|
var appendNewRecordToSpreadsheet = function () {
|
|
16
|
-
var _a, _b;
|
|
17
76
|
var _record = getRecord(lastFilteredRecordId.current);
|
|
18
77
|
if (!hasValueInAnyField(_record)) {
|
|
19
78
|
return;
|
|
20
79
|
}
|
|
21
|
-
|
|
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);
|
|
80
|
+
addNewRecord();
|
|
27
81
|
emit(EVENTS.ON_LAST_ROW_CHANGED);
|
|
28
82
|
};
|
|
83
|
+
var insertRecordsIntoSpreadsheet = function (records) { return __awaiter(void 0, void 0, void 0, function () {
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
switch (_a.label) {
|
|
86
|
+
case 0:
|
|
87
|
+
records.forEach(function (record) {
|
|
88
|
+
setRecord(record._meta.id, { _meta: record._meta });
|
|
89
|
+
});
|
|
90
|
+
return [4 /*yield*/, updateRecordAndRevalidate(records)];
|
|
91
|
+
case 1:
|
|
92
|
+
_a.sent();
|
|
93
|
+
setRecalculateFilters(function (prev) { return !prev; });
|
|
94
|
+
emit(EVENTS.UPDATE_COLUMN_ERROR_COUNT);
|
|
95
|
+
emit(EVENTS.UPDATE_TOTAL_ERROR_COUNT);
|
|
96
|
+
emit(EVENTS.UPDATE_TOTAL_ROW_COUNT);
|
|
97
|
+
layoutRef.current.querySelector(".input-content").focus();
|
|
98
|
+
return [2 /*return*/];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}); };
|
|
29
102
|
var deleteRecordsFromSpreadsheet = function (recordIds) {
|
|
103
|
+
trackRecordDeletion(recordIds, insertRecordsIntoSpreadsheet, function (records) {
|
|
104
|
+
var ids = records.map(function (r) { return r._meta.id; });
|
|
105
|
+
deleteRecordsFromSpreadsheet(ids);
|
|
106
|
+
});
|
|
107
|
+
var records = [];
|
|
30
108
|
recordIds.forEach(function (recordId) {
|
|
109
|
+
records.push(getRecord(recordId));
|
|
31
110
|
updateDuplicateValues(getRecord(recordId), {}, false, updateRecordAndRevalidate);
|
|
32
111
|
deleteRecord(recordId);
|
|
33
112
|
calculateColumnErrorCounts(errors.current[recordId], {});
|
|
34
113
|
calculateColumnWarningCounts(warnings.current[recordId], {});
|
|
114
|
+
delete errors.current[recordId];
|
|
115
|
+
delete warnings.current[recordId];
|
|
35
116
|
emptyRecordIds.current.delete(recordId);
|
|
36
117
|
});
|
|
37
118
|
setRecalculateFilters(function (prev) { return !prev; });
|
|
38
119
|
emit(EVENTS.UPDATE_COLUMN_ERROR_COUNT);
|
|
39
120
|
emit(EVENTS.UPDATE_TOTAL_ERROR_COUNT);
|
|
40
121
|
emit(EVENTS.UPDATE_TOTAL_ROW_COUNT);
|
|
122
|
+
layoutRef.current.querySelector(".input-content input").focus();
|
|
41
123
|
};
|
|
124
|
+
var findAndReplaceInSpreadsheet = function (searchText, replaceText, matchCase, useRegex) { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
+
var cellsWithText;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
cellsWithText = [];
|
|
130
|
+
return [4 /*yield*/, processInBatches(dataSet.current, function (batch) {
|
|
131
|
+
for (var recordKey in batch) {
|
|
132
|
+
var record = __assign({}, batch[recordKey]);
|
|
133
|
+
if (replaceInRecord(record, searchText, replaceText, matchCase, useRegex)) {
|
|
134
|
+
cellsWithText.push(record);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})];
|
|
138
|
+
case 1:
|
|
139
|
+
_a.sent();
|
|
140
|
+
updateRecordAndRevalidate(cellsWithText);
|
|
141
|
+
return [2 /*return*/, cellsWithText];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}); };
|
|
42
145
|
return {
|
|
146
|
+
addNewRecord: addNewRecord,
|
|
147
|
+
insertRecordsIntoSpreadsheet: insertRecordsIntoSpreadsheet,
|
|
43
148
|
appendNewRecordToSpreadsheet: appendNewRecordToSpreadsheet,
|
|
44
149
|
deleteRecordsFromSpreadsheet: deleteRecordsFromSpreadsheet,
|
|
150
|
+
findAndReplaceInSpreadsheet: findAndReplaceInSpreadsheet,
|
|
45
151
|
};
|
|
46
152
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MutableRefObject } from "react";
|
|
2
|
+
import { Record } from "../../../../types";
|
|
3
|
+
type ContextArgs = {
|
|
4
|
+
children: any;
|
|
5
|
+
};
|
|
6
|
+
type State = {
|
|
7
|
+
trackRecordChanges: (records: Record[], undo: any, redo: any) => void;
|
|
8
|
+
trackRecordDeletion: (recordIds: string[], undo: any, redo: any) => void;
|
|
9
|
+
undoTrackingEnabled: MutableRefObject<boolean>;
|
|
10
|
+
undo: () => void;
|
|
11
|
+
redo: () => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const UndoRedoContext: import("react").Context<State>;
|
|
14
|
+
export declare const UndoRedoContextProvider: ({ children }: ContextArgs) => JSX.Element;
|
|
15
|
+
export declare const useUndoRedoContext: () => State;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { createContext, useContext, useRef, } from "react";
|
|
14
|
+
import { useDataSetContext } from "../DataSetContextProvider";
|
|
15
|
+
import { useImporterContext } from "../../../../Importer/contexts/ImporterContextProvider";
|
|
16
|
+
export var UndoRedoContext = createContext({});
|
|
17
|
+
export var UndoRedoContextProvider = function (_a) {
|
|
18
|
+
var children = _a.children;
|
|
19
|
+
var changeStack = useRef([]);
|
|
20
|
+
var getRecord = useDataSetContext().getRecord;
|
|
21
|
+
var stackPointer = useRef(0);
|
|
22
|
+
var undoTrackingEnabled = useRef(false);
|
|
23
|
+
var layoutRef = useImporterContext().layoutRef;
|
|
24
|
+
var changeStackSizeLimit = 15;
|
|
25
|
+
var undo = function () {
|
|
26
|
+
var topItem = changeStack.current[stackPointer.current];
|
|
27
|
+
if (!topItem)
|
|
28
|
+
return;
|
|
29
|
+
var records = [];
|
|
30
|
+
for (var key in topItem.changes) {
|
|
31
|
+
var change = topItem.changes[key];
|
|
32
|
+
records.push(change.oldRecord);
|
|
33
|
+
}
|
|
34
|
+
undoTrackingEnabled.current = false;
|
|
35
|
+
topItem.undo(records);
|
|
36
|
+
undoTrackingEnabled.current = true;
|
|
37
|
+
stackPointer.current -= 1;
|
|
38
|
+
};
|
|
39
|
+
var redo = function () {
|
|
40
|
+
if (stackPointer.current >= changeStack.current.length - 1) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
stackPointer.current += 1;
|
|
44
|
+
var topItem = changeStack.current[stackPointer.current];
|
|
45
|
+
var records = [];
|
|
46
|
+
for (var key in topItem.changes) {
|
|
47
|
+
var change = topItem.changes[key];
|
|
48
|
+
records.push(change.newRecord);
|
|
49
|
+
}
|
|
50
|
+
undoTrackingEnabled.current = false;
|
|
51
|
+
topItem.redo(records);
|
|
52
|
+
undoTrackingEnabled.current = true;
|
|
53
|
+
};
|
|
54
|
+
var trackRecordChanges = function (records, undo, redo) {
|
|
55
|
+
if (!undoTrackingEnabled.current)
|
|
56
|
+
return;
|
|
57
|
+
var recordChanges = [];
|
|
58
|
+
for (var key in records) {
|
|
59
|
+
recordChanges.push({
|
|
60
|
+
oldRecord: __assign({}, getRecord(records[key]._meta.id)),
|
|
61
|
+
newRecord: __assign({}, records[key]),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
var change = {
|
|
65
|
+
type: "records_changed",
|
|
66
|
+
changes: recordChanges,
|
|
67
|
+
undo: undo,
|
|
68
|
+
redo: redo,
|
|
69
|
+
};
|
|
70
|
+
trackChange(change);
|
|
71
|
+
stackPointer.current = changeStack.current.length - 1;
|
|
72
|
+
};
|
|
73
|
+
var trackRecordDeletion = function (recordIds, undo, redo) {
|
|
74
|
+
var recordChanges = [];
|
|
75
|
+
recordIds.forEach(function (recordId) {
|
|
76
|
+
recordChanges.push({
|
|
77
|
+
oldRecord: __assign({}, getRecord(recordId)),
|
|
78
|
+
newRecord: __assign({}, getRecord(recordId)),
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
var change = {
|
|
82
|
+
type: "records_deleted",
|
|
83
|
+
changes: recordChanges,
|
|
84
|
+
undo: undo,
|
|
85
|
+
redo: redo,
|
|
86
|
+
};
|
|
87
|
+
trackChange(change);
|
|
88
|
+
stackPointer.current = changeStack.current.length - 1;
|
|
89
|
+
};
|
|
90
|
+
var trackChange = function (change) {
|
|
91
|
+
changeStack.current.push(change);
|
|
92
|
+
// limit the number of items we keep in memory
|
|
93
|
+
changeStack.current = changeStack.current.slice(Math.max(changeStack.current.length - changeStackSizeLimit, 0));
|
|
94
|
+
};
|
|
95
|
+
var value = {
|
|
96
|
+
trackRecordChanges: trackRecordChanges,
|
|
97
|
+
trackRecordDeletion: trackRecordDeletion,
|
|
98
|
+
undoTrackingEnabled: undoTrackingEnabled,
|
|
99
|
+
undo: undo,
|
|
100
|
+
redo: redo,
|
|
101
|
+
};
|
|
102
|
+
return (_jsx(UndoRedoContext.Provider, __assign({ value: value }, { children: children })));
|
|
103
|
+
};
|
|
104
|
+
export var useUndoRedoContext = function () { return useContext(UndoRedoContext); };
|
|
@@ -22,7 +22,7 @@ export type ValidationState = {
|
|
|
22
22
|
calculateColumnWarningCounts?: CalculateColumnCount;
|
|
23
23
|
};
|
|
24
24
|
type UseValidationStateReturnValue = ValidationState & {
|
|
25
|
-
updateRecordAndRevalidate: (record: Record | Record[], initialValidation?: boolean) => Promise<void>;
|
|
25
|
+
updateRecordAndRevalidate: (record: Record | Record[], initialValidation?: boolean, loadingIndicator?: boolean) => Promise<void>;
|
|
26
26
|
spreadsheetInitialized: boolean;
|
|
27
27
|
};
|
|
28
28
|
export declare const ValidationContext: import("react").Context<UseValidationStateReturnValue>;
|
|
@@ -58,10 +58,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
58
58
|
import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
59
59
|
import { useAppLoadingContext } from "../../../../common/AppLoadingContextProvider";
|
|
60
60
|
import { useEventManagerContext } from "../../../../common/EventManagerContextProvider";
|
|
61
|
+
import { useImporterContext } from "../../../contexts/ImporterContextProvider";
|
|
61
62
|
import { useDataSetContext } from "../DataSetContextProvider";
|
|
62
63
|
import { useDuplicateDataContext } from "../DuplicateDataContextProvider";
|
|
63
64
|
import { useBatchProcessing } from "../SpreadsheetContextProvider/useBatchProcessing";
|
|
64
65
|
import { selectValidatorsFor, validateRecord } from "../validation";
|
|
66
|
+
import { useUndoRedoContext } from "../UndoRedoContextProvider";
|
|
65
67
|
// this is the fastest check for empty object as per
|
|
66
68
|
// https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object/785768#785768
|
|
67
69
|
var isObjectEmpty = function (obj) {
|
|
@@ -101,16 +103,23 @@ export var ValidationContextProvider = function (_a) {
|
|
|
101
103
|
var columnsWithWarningCounts = useRef({});
|
|
102
104
|
var totalErrorCount = useRef(0);
|
|
103
105
|
var invalidRowsCountRef = useRef(0);
|
|
104
|
-
var _c =
|
|
105
|
-
var _d =
|
|
106
|
-
var _e =
|
|
107
|
-
var _f = useDuplicateDataContext(), duplicateValues = _f.duplicateValues, updateDuplicateValues = _f.updateDuplicateValues;
|
|
106
|
+
var _c = useEventManagerContext(), emit = _c.emit, EVENTS = _c.EVENTS;
|
|
107
|
+
var _d = useDataSetContext(), getRecord = _d.getRecord, setRecord = _d.setRecord, dataSet = _d.dataSet, dataSetLength = _d.dataSetLength;
|
|
108
|
+
var _e = useDuplicateDataContext(), duplicateValues = _e.duplicateValues, updateDuplicateValues = _e.updateDuplicateValues, resetDuplicateProvider = _e.resetDuplicateProvider;
|
|
108
109
|
var processRecordsInBatches = useBatchProcessing(10000).processRecordsInBatches;
|
|
110
|
+
var _f = useState(false), spreadsheetInitialized = _f[0], setSpreadsheetInitialized = _f[1];
|
|
111
|
+
var _g = useImporterContext(), currentStepIndex = _g.currentStepIndex, templateSlug = _g.templateSlug;
|
|
112
|
+
var _h = useState(false), dataSetChanged = _h[0], setDataSetChanged = _h[1];
|
|
113
|
+
var _j = useUndoRedoContext(), trackRecordChanges = _j.trackRecordChanges, undoTrackingEnabled = _j.undoTrackingEnabled;
|
|
109
114
|
var reset = function () {
|
|
110
115
|
columnsWithErrorCounts.current = {};
|
|
111
116
|
columnsWithWarningCounts.current = {};
|
|
112
117
|
totalErrorCount.current = 0;
|
|
113
118
|
invalidRowsCountRef.current = 0;
|
|
119
|
+
errors.current = {};
|
|
120
|
+
warnings.current = {};
|
|
121
|
+
setSpreadsheetInitialized(false);
|
|
122
|
+
setDataSetChanged(function (prev) { return !prev; });
|
|
114
123
|
};
|
|
115
124
|
var calculateColumnErrorCounts = function (oldErrors, newErrors) {
|
|
116
125
|
if (oldErrors === void 0) { oldErrors = {}; }
|
|
@@ -177,7 +186,7 @@ export var ValidationContextProvider = function (_a) {
|
|
|
177
186
|
else {
|
|
178
187
|
delete warnings.current[recordId];
|
|
179
188
|
}
|
|
180
|
-
if (backendErrors) {
|
|
189
|
+
if (backendErrors && spreadsheetInitialized) {
|
|
181
190
|
record._meta.backendErrors = {};
|
|
182
191
|
}
|
|
183
192
|
emit(recordId, newRecord);
|
|
@@ -191,16 +200,18 @@ export var ValidationContextProvider = function (_a) {
|
|
|
191
200
|
setValidationPercentage(Math.round((validationPercentage + Number.EPSILON) * 10) / 10);
|
|
192
201
|
};
|
|
193
202
|
// Validate record and update dataSet
|
|
194
|
-
var updateRecordAndRevalidate = function (records, initialValidation) {
|
|
203
|
+
var updateRecordAndRevalidate = function (records, initialValidation, loadingIndicator) {
|
|
195
204
|
if (initialValidation === void 0) { initialValidation = false; }
|
|
205
|
+
if (loadingIndicator === void 0) { loadingIndicator = true; }
|
|
196
206
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
197
207
|
var recordsArray, length, recordsProcessed;
|
|
198
208
|
return __generator(this, function (_a) {
|
|
199
209
|
switch (_a.label) {
|
|
200
210
|
case 0:
|
|
201
211
|
recordsArray = Array.isArray(records) ? records : [records];
|
|
212
|
+
trackRecordChanges(recordsArray, updateRecordAndRevalidate, updateRecordAndRevalidate);
|
|
202
213
|
length = recordsArray.length;
|
|
203
|
-
if (!(length > 10000)) return [3 /*break*/, 2];
|
|
214
|
+
if (!(loadingIndicator && length > 10000)) return [3 /*break*/, 2];
|
|
204
215
|
setIsLoadingApp(true);
|
|
205
216
|
// wait for the first render to complete
|
|
206
217
|
// before blocking main thread with review step logic
|
|
@@ -244,7 +255,9 @@ export var ValidationContextProvider = function (_a) {
|
|
|
244
255
|
}); })];
|
|
245
256
|
case 3:
|
|
246
257
|
_a.sent();
|
|
247
|
-
|
|
258
|
+
if (loadingIndicator) {
|
|
259
|
+
setIsLoadingApp(false);
|
|
260
|
+
}
|
|
248
261
|
return [2 /*return*/];
|
|
249
262
|
}
|
|
250
263
|
});
|
|
@@ -252,21 +265,33 @@ export var ValidationContextProvider = function (_a) {
|
|
|
252
265
|
};
|
|
253
266
|
// Initial data validation and update dataSet
|
|
254
267
|
useEffect(function () {
|
|
268
|
+
if (dataSet.current && !isReadOnly) {
|
|
269
|
+
resetDuplicateProvider();
|
|
270
|
+
}
|
|
255
271
|
reset();
|
|
256
|
-
|
|
272
|
+
}, [dataSet.current]);
|
|
273
|
+
useEffect(function () {
|
|
274
|
+
var isDataSetInvalid = !dataSet.current || dataSetLength.current === 0;
|
|
275
|
+
if (isDataSetInvalid ||
|
|
276
|
+
isReadOnly ||
|
|
277
|
+
currentStepIndex !== 2 ||
|
|
278
|
+
(fields === null || fields === void 0 ? void 0 : fields.length) === 0)
|
|
257
279
|
return;
|
|
258
|
-
setIsLoadingApp(true);
|
|
259
280
|
var initialValidation = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
260
281
|
var initialData;
|
|
261
282
|
return __generator(this, function (_a) {
|
|
262
283
|
switch (_a.label) {
|
|
263
284
|
case 0:
|
|
264
285
|
initialData = Object.values(dataSet.current);
|
|
286
|
+
if (!(initialData.length > 0)) return [3 /*break*/, 2];
|
|
287
|
+
setIsLoadingApp(true);
|
|
288
|
+
undoTrackingEnabled.current = false;
|
|
265
289
|
return [4 /*yield*/, updateRecordAndRevalidate(initialData, true)];
|
|
266
290
|
case 1:
|
|
267
291
|
_a.sent();
|
|
268
|
-
|
|
269
|
-
|
|
292
|
+
undoTrackingEnabled.current = true;
|
|
293
|
+
_a.label = 2;
|
|
294
|
+
case 2: return [2 /*return*/];
|
|
270
295
|
}
|
|
271
296
|
});
|
|
272
297
|
}); };
|
|
@@ -276,12 +301,12 @@ export var ValidationContextProvider = function (_a) {
|
|
|
276
301
|
case 0: return [4 /*yield*/, initialValidation()];
|
|
277
302
|
case 1:
|
|
278
303
|
_a.sent();
|
|
279
|
-
|
|
304
|
+
setSpreadsheetInitialized(true);
|
|
280
305
|
return [2 /*return*/];
|
|
281
306
|
}
|
|
282
307
|
});
|
|
283
308
|
}); })();
|
|
284
|
-
}, [
|
|
309
|
+
}, [currentStepIndex, dataSetChanged]);
|
|
285
310
|
var isValidationCompleted = validationPercentage === 100;
|
|
286
311
|
var isValid = isValidationCompleted && totalErrorCount.current === 0;
|
|
287
312
|
var value = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Field, FieldTypes, Record } from "../../../../types";
|
|
2
2
|
export declare const spreadsheetRowHeightPx = 40;
|
|
3
3
|
export declare const spreadsheetHeaderHeightPx = 40;
|
|
4
4
|
export declare const isNullOrUndefined: (value: any) => boolean;
|