fuse-importer 0.1.8-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/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 +19 -17
- 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 -1
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js +101 -24
- 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 +28 -12
- 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.js +65 -15
- 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 +8 -8
- 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/validation/validators.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.js +2 -0
- package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +8 -1
- package/lib/esm/Importer/contexts/ImporterContextProvider.js +18 -5
- 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 +2 -2
- package/lib/esm/common/Table/TableActions/SearchRows.js +18 -26
- package/lib/esm/common/Table/TableActions/TableActions.js +7 -4
- package/lib/esm/common/Table/TableActions/TableActions.styles.js +1 -1
- package/lib/esm/common/Table/TableActions/TransformedRecordsCount.js +3 -3
- 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 +9 -1
- package/lib/esm/common/Toast.js +29 -8
- package/lib/esm/common/icons/index.js +3 -3
- package/lib/esm/common/inputs/Autocomplete.js +2 -2
- 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 +10 -0
- package/lib/esm/locales/en.js +10 -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/types.d.ts +1 -0
- package/lib/main.js +8 -8
- package/package.json +1 -1
- package/lib/esm/Importer/TrialModeBanner.d.ts +0 -1
- package/lib/esm/Importer/TrialModeBanner.js +0 -22
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js
CHANGED
|
@@ -9,65 +9,142 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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";
|
|
15
49
|
import { addMeta } from "../../../../Importer/data";
|
|
16
50
|
import { useEventManagerContext } from "../../../../common/EventManagerContextProvider";
|
|
17
|
-
import
|
|
51
|
+
import useFindAndReplace from "../../../../common/Table/TableActions/useFindAndReplace";
|
|
52
|
+
import { useDataSetContext } from "../DataSetContextProvider";
|
|
18
53
|
import { useDuplicateDataContext } from "../DuplicateDataContextProvider";
|
|
54
|
+
import { useFilteredDataContext } from "../FilteredDataContextProvider";
|
|
55
|
+
import { useUndoRedoContext } from "../UndoRedoContextProvider";
|
|
56
|
+
import { useValidationContext } from "../ValidationContextProvider";
|
|
19
57
|
import { useBatchProcessing } from "./useBatchProcessing";
|
|
20
|
-
import
|
|
58
|
+
import { hasValueInAnyField } from "./utils";
|
|
21
59
|
export var useDataSetManipulation = function () {
|
|
22
60
|
var _a = useFilteredDataContext(), lastFilteredRecordId = _a.lastFilteredRecordId, setRecalculateFilters = _a.setRecalculateFilters;
|
|
23
|
-
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;
|
|
24
62
|
var _c = useEventManagerContext(), emit = _c.emit, EVENTS = _c.EVENTS;
|
|
25
63
|
var _d = useValidationContext(), errors = _d.errors, warnings = _d.warnings, calculateColumnErrorCounts = _d.calculateColumnErrorCounts, calculateColumnWarningCounts = _d.calculateColumnWarningCounts;
|
|
26
64
|
var updateDuplicateValues = useDuplicateDataContext().updateDuplicateValues;
|
|
27
65
|
var updateRecordAndRevalidate = useValidationContext().updateRecordAndRevalidate;
|
|
28
66
|
var processInBatches = useBatchProcessing().processInBatches;
|
|
29
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
|
+
};
|
|
30
75
|
var appendNewRecordToSpreadsheet = function () {
|
|
31
|
-
var _a, _b;
|
|
32
76
|
var _record = getRecord(lastFilteredRecordId.current);
|
|
33
77
|
if (!hasValueInAnyField(_record)) {
|
|
34
78
|
return;
|
|
35
79
|
}
|
|
36
|
-
|
|
37
|
-
for (var recordId in dataSet.current)
|
|
38
|
-
if (((_b = (_a = getRecord(recordId)) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.rowIndex) > highestRowIndex)
|
|
39
|
-
highestRowIndex = getRecord(recordId)._meta.rowIndex;
|
|
40
|
-
var newRow = addMeta({}, highestRowIndex + 1);
|
|
41
|
-
setRecord(newRow._meta.id, newRow);
|
|
80
|
+
addNewRecord();
|
|
42
81
|
emit(EVENTS.ON_LAST_ROW_CHANGED);
|
|
43
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
|
+
}); };
|
|
44
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 = [];
|
|
45
108
|
recordIds.forEach(function (recordId) {
|
|
109
|
+
records.push(getRecord(recordId));
|
|
46
110
|
updateDuplicateValues(getRecord(recordId), {}, false, updateRecordAndRevalidate);
|
|
47
111
|
deleteRecord(recordId);
|
|
48
112
|
calculateColumnErrorCounts(errors.current[recordId], {});
|
|
49
113
|
calculateColumnWarningCounts(warnings.current[recordId], {});
|
|
114
|
+
delete errors.current[recordId];
|
|
115
|
+
delete warnings.current[recordId];
|
|
50
116
|
emptyRecordIds.current.delete(recordId);
|
|
51
117
|
});
|
|
52
118
|
setRecalculateFilters(function (prev) { return !prev; });
|
|
53
119
|
emit(EVENTS.UPDATE_COLUMN_ERROR_COUNT);
|
|
54
120
|
emit(EVENTS.UPDATE_TOTAL_ERROR_COUNT);
|
|
55
121
|
emit(EVENTS.UPDATE_TOTAL_ROW_COUNT);
|
|
122
|
+
layoutRef.current.querySelector(".input-content input").focus();
|
|
56
123
|
};
|
|
57
|
-
var findAndReplaceInSpreadsheet = function (searchText, replaceText, matchCase, useRegex) {
|
|
58
|
-
var cellsWithText
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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];
|
|
65
142
|
}
|
|
66
143
|
});
|
|
67
|
-
|
|
68
|
-
return cellsWithText;
|
|
69
|
-
};
|
|
144
|
+
}); };
|
|
70
145
|
return {
|
|
146
|
+
addNewRecord: addNewRecord,
|
|
147
|
+
insertRecordsIntoSpreadsheet: insertRecordsIntoSpreadsheet,
|
|
71
148
|
appendNewRecordToSpreadsheet: appendNewRecordToSpreadsheet,
|
|
72
149
|
deleteRecordsFromSpreadsheet: deleteRecordsFromSpreadsheet,
|
|
73
150
|
findAndReplaceInSpreadsheet: findAndReplaceInSpreadsheet,
|
|
@@ -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>;
|
|
@@ -63,6 +63,7 @@ import { useDataSetContext } from "../DataSetContextProvider";
|
|
|
63
63
|
import { useDuplicateDataContext } from "../DuplicateDataContextProvider";
|
|
64
64
|
import { useBatchProcessing } from "../SpreadsheetContextProvider/useBatchProcessing";
|
|
65
65
|
import { selectValidatorsFor, validateRecord } from "../validation";
|
|
66
|
+
import { useUndoRedoContext } from "../UndoRedoContextProvider";
|
|
66
67
|
// this is the fastest check for empty object as per
|
|
67
68
|
// https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object/785768#785768
|
|
68
69
|
var isObjectEmpty = function (obj) {
|
|
@@ -103,12 +104,13 @@ export var ValidationContextProvider = function (_a) {
|
|
|
103
104
|
var totalErrorCount = useRef(0);
|
|
104
105
|
var invalidRowsCountRef = useRef(0);
|
|
105
106
|
var _c = useEventManagerContext(), emit = _c.emit, EVENTS = _c.EVENTS;
|
|
106
|
-
var _d = useDataSetContext(), getRecord = _d.getRecord, setRecord = _d.setRecord, dataSet = _d.dataSet;
|
|
107
|
-
var _e = useDuplicateDataContext(), duplicateValues = _e.duplicateValues, updateDuplicateValues = _e.updateDuplicateValues;
|
|
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;
|
|
109
110
|
var _f = useState(false), spreadsheetInitialized = _f[0], setSpreadsheetInitialized = _f[1];
|
|
110
|
-
var
|
|
111
|
-
var
|
|
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;
|
|
112
114
|
var reset = function () {
|
|
113
115
|
columnsWithErrorCounts.current = {};
|
|
114
116
|
columnsWithWarningCounts.current = {};
|
|
@@ -198,16 +200,18 @@ export var ValidationContextProvider = function (_a) {
|
|
|
198
200
|
setValidationPercentage(Math.round((validationPercentage + Number.EPSILON) * 10) / 10);
|
|
199
201
|
};
|
|
200
202
|
// Validate record and update dataSet
|
|
201
|
-
var updateRecordAndRevalidate = function (records, initialValidation) {
|
|
203
|
+
var updateRecordAndRevalidate = function (records, initialValidation, loadingIndicator) {
|
|
202
204
|
if (initialValidation === void 0) { initialValidation = false; }
|
|
205
|
+
if (loadingIndicator === void 0) { loadingIndicator = true; }
|
|
203
206
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
204
207
|
var recordsArray, length, recordsProcessed;
|
|
205
208
|
return __generator(this, function (_a) {
|
|
206
209
|
switch (_a.label) {
|
|
207
210
|
case 0:
|
|
208
211
|
recordsArray = Array.isArray(records) ? records : [records];
|
|
212
|
+
trackRecordChanges(recordsArray, updateRecordAndRevalidate, updateRecordAndRevalidate);
|
|
209
213
|
length = recordsArray.length;
|
|
210
|
-
if (!(length > 10000)) return [3 /*break*/, 2];
|
|
214
|
+
if (!(loadingIndicator && length > 10000)) return [3 /*break*/, 2];
|
|
211
215
|
setIsLoadingApp(true);
|
|
212
216
|
// wait for the first render to complete
|
|
213
217
|
// before blocking main thread with review step logic
|
|
@@ -251,7 +255,9 @@ export var ValidationContextProvider = function (_a) {
|
|
|
251
255
|
}); })];
|
|
252
256
|
case 3:
|
|
253
257
|
_a.sent();
|
|
254
|
-
|
|
258
|
+
if (loadingIndicator) {
|
|
259
|
+
setIsLoadingApp(false);
|
|
260
|
+
}
|
|
255
261
|
return [2 /*return*/];
|
|
256
262
|
}
|
|
257
263
|
});
|
|
@@ -259,22 +265,33 @@ export var ValidationContextProvider = function (_a) {
|
|
|
259
265
|
};
|
|
260
266
|
// Initial data validation and update dataSet
|
|
261
267
|
useEffect(function () {
|
|
268
|
+
if (dataSet.current && !isReadOnly) {
|
|
269
|
+
resetDuplicateProvider();
|
|
270
|
+
}
|
|
262
271
|
reset();
|
|
263
272
|
}, [dataSet.current]);
|
|
264
273
|
useEffect(function () {
|
|
265
|
-
|
|
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)
|
|
266
279
|
return;
|
|
267
|
-
setIsLoadingApp(true);
|
|
268
280
|
var initialValidation = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
269
281
|
var initialData;
|
|
270
282
|
return __generator(this, function (_a) {
|
|
271
283
|
switch (_a.label) {
|
|
272
284
|
case 0:
|
|
273
285
|
initialData = Object.values(dataSet.current);
|
|
286
|
+
if (!(initialData.length > 0)) return [3 /*break*/, 2];
|
|
287
|
+
setIsLoadingApp(true);
|
|
288
|
+
undoTrackingEnabled.current = false;
|
|
274
289
|
return [4 /*yield*/, updateRecordAndRevalidate(initialData, true)];
|
|
275
290
|
case 1:
|
|
276
291
|
_a.sent();
|
|
277
|
-
|
|
292
|
+
undoTrackingEnabled.current = true;
|
|
293
|
+
_a.label = 2;
|
|
294
|
+
case 2: return [2 /*return*/];
|
|
278
295
|
}
|
|
279
296
|
});
|
|
280
297
|
}); };
|
|
@@ -284,13 +301,12 @@ export var ValidationContextProvider = function (_a) {
|
|
|
284
301
|
case 0: return [4 /*yield*/, initialValidation()];
|
|
285
302
|
case 1:
|
|
286
303
|
_a.sent();
|
|
287
|
-
setIsLoadingApp(false);
|
|
288
304
|
setSpreadsheetInitialized(true);
|
|
289
305
|
return [2 /*return*/];
|
|
290
306
|
}
|
|
291
307
|
});
|
|
292
308
|
}); })();
|
|
293
|
-
}, [
|
|
309
|
+
}, [currentStepIndex, dataSetChanged]);
|
|
294
310
|
var isValidationCompleted = validationPercentage === 100;
|
|
295
311
|
var isValid = isValidationCompleted && totalErrorCount.current === 0;
|
|
296
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;
|
|
@@ -11,7 +11,7 @@ export var isEmpty = function (value) {
|
|
|
11
11
|
(value.length === 0 || value.trim().length === 0)));
|
|
12
12
|
};
|
|
13
13
|
export var isEmail = function (value) {
|
|
14
|
-
var emailRegex = /^[\w+.-]+@([\w-]+\.)+[\w-]
|
|
14
|
+
var emailRegex = /^[\w+.-]+@([\w-]+\.)+[\w-]+$/;
|
|
15
15
|
return emailRegex.test(value);
|
|
16
16
|
};
|
|
17
17
|
export var isUrl = function (value) {
|
|
@@ -52,10 +52,18 @@ export var isRecordEmpty = function (record, fields) {
|
|
|
52
52
|
export var parseValue = function (fieldType, value, enumSet) {
|
|
53
53
|
if (isEmpty(value))
|
|
54
54
|
return value;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
var cleanNumber = function (val) {
|
|
56
|
+
// Remove all non-numeric characters except the decimal point.
|
|
57
|
+
return typeof val === "string" ? val.replace(/[^\d.]/g, "") : val;
|
|
58
|
+
};
|
|
59
|
+
if (fieldType === FieldTypes.float) {
|
|
60
|
+
var cleanedValue = cleanNumber(value);
|
|
61
|
+
return isFloat(cleanedValue) ? parseFloat(cleanedValue) : value;
|
|
62
|
+
}
|
|
63
|
+
if (fieldType === FieldTypes.integer) {
|
|
64
|
+
var cleanedValue = cleanNumber(value);
|
|
65
|
+
return isInteger(cleanedValue) ? parseInt(cleanedValue, 10) : value;
|
|
66
|
+
}
|
|
59
67
|
if (fieldType === FieldTypes.boolean)
|
|
60
68
|
return isTrue(value) ? true : false;
|
|
61
69
|
if (fieldType === FieldTypes.enum && enumSet)
|
|
@@ -9,13 +9,49 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
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
|
+
};
|
|
12
48
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
49
|
import { Div } from "../../../../../styled";
|
|
14
50
|
import { Button, Modal, addToast } from "../../../../../common";
|
|
15
51
|
import { useTranslation } from "react-i18next";
|
|
16
52
|
import { TextInput } from "../../../../../common/inputs/TextInput";
|
|
17
53
|
import { Checkbox } from "../../../../../common";
|
|
18
|
-
import { useState } from "react";
|
|
54
|
+
import { useEffect, useRef, useState } from "react";
|
|
19
55
|
import { useDataSetManipulation } from "../../SpreadsheetContextProvider/useDataSetManipulation";
|
|
20
56
|
import { useFilteredDataContext } from "../../FilteredDataContextProvider";
|
|
21
57
|
export var FindAndReplaceModal = function (_a) {
|
|
@@ -27,18 +63,32 @@ export var FindAndReplaceModal = function (_a) {
|
|
|
27
63
|
var _d = useState(false), useRegex = _d[0], setUseRegex = _d[1];
|
|
28
64
|
var _e = useState(true), matchCase = _e[0], setMatchCase = _e[1];
|
|
29
65
|
var setFilteredInputValue = useFilteredDataContext().setFilteredInputValue;
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
66
|
+
var findRef = useRef();
|
|
67
|
+
useEffect(function () {
|
|
68
|
+
if (!findRef.current)
|
|
69
|
+
return;
|
|
70
|
+
findRef.current.focus();
|
|
71
|
+
}, [findRef.current]);
|
|
72
|
+
var findAndReplace = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
73
|
+
var records;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, findAndReplaceInSpreadsheet(searchText, replaceText, matchCase, useRegex)];
|
|
77
|
+
case 1:
|
|
78
|
+
records = _a.sent();
|
|
79
|
+
if (records.length > 0) {
|
|
80
|
+
addToast(t("find_and_replace_modal.records_replaced", {
|
|
81
|
+
length: records.length,
|
|
82
|
+
}), "success");
|
|
83
|
+
onClose();
|
|
84
|
+
setFilteredInputValue("");
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
addToast(t("find_and_replace_modal.no_records_found"), "error");
|
|
88
|
+
}
|
|
89
|
+
return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}); };
|
|
93
|
+
return (_jsx(Modal, __assign({ isOpen: true, onClose: function () { return onClose(); } }, { children: _jsxs(Div, __assign({ p: "17px 20px", w: 500 }, { children: [_jsx(Div, __assign({ textAlignCenter: true, h5: true }, { children: t("find_and_replace_modal.title") })), _jsx(Div, __assign({ mt: 20, mb: 20, textAlignCenter: true, body1: true }, { children: t("find_and_replace_modal.description") })), _jsxs(Div, __assign({ mb: 20, w: 500, textAlignCenter: true, body1: true }, { children: [_jsx(TextInput, { setInputRef: findRef, "data-cy": "find-input", mb: 20, name: t("find_and_replace_modal.find"), label: t("find_and_replace_modal.find"), value: searchText, onChange: function (value) { return setSearchText(value); } }), _jsx(TextInput, { "data-cy": "replace-input", label: t("find_and_replace_modal.replace_with"), value: replaceText, onChange: function (value) { return setReplaceText(value); } })] })), _jsx(Div, __assign({ mb: 12 }, { children: _jsx(Checkbox, { "data-cy": "use-regex", label: t("find_and_replace_modal.use_regex"), isChecked: useRegex, onChange: function (v) { return setUseRegex(v); } }) })), _jsx(Div, __assign({ mb: 12 }, { children: _jsx(Checkbox, { "data-cy": "case-sensitive", label: t("find_and_replace_modal.use_case_sensitive"), isChecked: matchCase, onChange: function (v) { return setMatchCase(v); } }) })), _jsxs(Div, __assign({ dflex: true, centered: true, mt: 40 }, { children: [_jsx(Button, __assign({ variant: "secondary", onClick: function () { return onClose(); }, w: 160, mr: 16 }, { children: t("find_and_replace_modal.cancel") })), _jsx(Button, __assign({ "data-cy": "find-replace-submit", variant: "primary", onClick: function () { return findAndReplace(); } }, { children: t("find_and_replace_modal.submit") }))] }))] })) })));
|
|
44
94
|
};
|
package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData/CellContextProvider.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { css } from "styled-components";
|
|
3
|
+
type SelectionProps = {
|
|
4
|
+
onClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
5
|
+
onDragStart: (e: React.DragEvent<HTMLDivElement>) => void;
|
|
6
|
+
onDragEnd: () => void;
|
|
7
|
+
onDragOver: () => void;
|
|
8
|
+
onBlur: () => void;
|
|
9
|
+
draggable: boolean;
|
|
10
|
+
};
|
|
11
|
+
type State = {
|
|
12
|
+
isSelected: boolean;
|
|
13
|
+
selectedCellStyles: ReturnType<typeof css>;
|
|
14
|
+
selectionProps: SelectionProps | {};
|
|
15
|
+
};
|
|
16
|
+
type Props = {
|
|
17
|
+
children: JSX.Element;
|
|
18
|
+
rowIndex: number;
|
|
19
|
+
colIndex: number;
|
|
20
|
+
};
|
|
21
|
+
export declare const CellContextProvider: ({ children, rowIndex, colIndex, }: Props) => JSX.Element;
|
|
22
|
+
export declare const useCellContext: () => State;
|
|
23
|
+
export {};
|