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
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
var runTransformation = function (fieldValue, transformation, field
|
|
1
|
+
import { fieldTransformations } from "./transformators";
|
|
2
|
+
var runTransformation = function (fieldValue, transformation, field) {
|
|
3
3
|
var transformationType = transformation.transformation_type;
|
|
4
4
|
var transformerFunction = fieldTransformations[transformationType];
|
|
5
|
-
if (Object.keys(datesDateTimesAndTimesTransformations).includes(transformationType)) {
|
|
6
|
-
var dateTimeTransformFunction = transformerFunction;
|
|
7
|
-
return dateTimeTransformFunction(fieldValue, transformation, field, possibleDateFormats);
|
|
8
|
-
}
|
|
9
5
|
return transformerFunction(fieldValue, transformation, field);
|
|
10
6
|
};
|
|
11
7
|
export var transformRecord = function (_a) {
|
|
12
|
-
var record = _a.record, fields = _a.fields
|
|
8
|
+
var record = _a.record, fields = _a.fields;
|
|
13
9
|
var transformedRecords = {};
|
|
14
10
|
for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) {
|
|
15
11
|
var currentField = fields_1[_i];
|
|
@@ -27,7 +23,7 @@ export var transformRecord = function (_a) {
|
|
|
27
23
|
var fieldWasTransformed = false;
|
|
28
24
|
for (var i = 0; i < fieldTransformations_1.length; i++) {
|
|
29
25
|
var currentTransformation = fieldTransformations_1[i];
|
|
30
|
-
var transformed = runTransformation(transformedField.transformed, currentTransformation, currentField
|
|
26
|
+
var transformed = runTransformation(transformedField.transformed, currentTransformation, currentField);
|
|
31
27
|
if (transformed.transformationWasNeeded) {
|
|
32
28
|
fieldWasTransformed = true;
|
|
33
29
|
transformedField = {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
export declare const parseDateFromUserInput: (userInput: string) => DateTime | null;
|
|
3
|
+
export declare const parseTimeFromUserInput: (input: any) => DateTime;
|
|
4
|
+
export declare const parseTimeFromDateTimeorTimeInput: (userInput: any) => DateTime;
|
|
5
|
+
export declare const parseDateTimeFromUserInput: (userInput: any) => DateTime;
|
package/lib/esm/Importer/common/Spreadsheet/transformation/transformators/dateTimeAutoformatUtils.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
var MONTH_NAMES = [
|
|
3
|
+
"january",
|
|
4
|
+
"february",
|
|
5
|
+
"march",
|
|
6
|
+
"april",
|
|
7
|
+
"may",
|
|
8
|
+
"june",
|
|
9
|
+
"july",
|
|
10
|
+
"august",
|
|
11
|
+
"september",
|
|
12
|
+
"october",
|
|
13
|
+
"november",
|
|
14
|
+
"december",
|
|
15
|
+
];
|
|
16
|
+
var MONTH_ABBREVIATIONS = [
|
|
17
|
+
"jan",
|
|
18
|
+
"feb",
|
|
19
|
+
"mar",
|
|
20
|
+
"apr",
|
|
21
|
+
"may",
|
|
22
|
+
"jun",
|
|
23
|
+
"jul",
|
|
24
|
+
"aug",
|
|
25
|
+
"sep",
|
|
26
|
+
"oct",
|
|
27
|
+
"nov",
|
|
28
|
+
"dec",
|
|
29
|
+
];
|
|
30
|
+
var DAY_NAMES = [
|
|
31
|
+
"sunday",
|
|
32
|
+
"monday",
|
|
33
|
+
"tuesday",
|
|
34
|
+
"wednesday",
|
|
35
|
+
"thursday",
|
|
36
|
+
"friday",
|
|
37
|
+
"saturday",
|
|
38
|
+
];
|
|
39
|
+
var DAY_ABBREVIATIONS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
40
|
+
var tryParseCommonDateFormats = function (input) {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
var trimmedInput = input.trim();
|
|
43
|
+
var len = trimmedInput.length;
|
|
44
|
+
if (len < 6 || len > 10)
|
|
45
|
+
return null;
|
|
46
|
+
var parts = input.split(/[-/.]/);
|
|
47
|
+
if (parts.length !== 3)
|
|
48
|
+
return null;
|
|
49
|
+
var _d = parts.map(Number), first = _d[0], second = _d[1], third = _d[2];
|
|
50
|
+
var year, month, day;
|
|
51
|
+
if (parts[2].length === 4) {
|
|
52
|
+
_a = [first, second, third], month = _a[0], day = _a[1], year = _a[2];
|
|
53
|
+
}
|
|
54
|
+
else if (parts[0].length === 4) {
|
|
55
|
+
_b = [first, second, third], year = _b[0], month = _b[1], day = _b[2];
|
|
56
|
+
}
|
|
57
|
+
else if (parts[2].length === 2) {
|
|
58
|
+
// Handles the case where year is two digits
|
|
59
|
+
_c = [first, second, third], month = _c[0], day = _c[1], year = _c[2];
|
|
60
|
+
year += year < 50 ? 2000 : 1900; // Convert to 4 digits
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return null; // Unknown format
|
|
64
|
+
}
|
|
65
|
+
if (year >= 0 && month >= 1 && month <= 12 && day >= 1 && day <= 31) {
|
|
66
|
+
var dt = DateTime.fromObject({ day: day, month: month, year: year });
|
|
67
|
+
return dt.isValid ? dt : null;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
export var parseDateFromUserInput = function (userInput) {
|
|
72
|
+
var datePart = userInput;
|
|
73
|
+
var hasTimePart = userInput.indexOf(":") !== -1 && userInput.split(":").length > 1;
|
|
74
|
+
if (hasTimePart) {
|
|
75
|
+
var parts = userInput.trim().split(" ");
|
|
76
|
+
datePart =
|
|
77
|
+
parts.length === 2
|
|
78
|
+
? parts[0].indexOf(":") !== -1
|
|
79
|
+
? parts[1]
|
|
80
|
+
: parts[0]
|
|
81
|
+
: userInput;
|
|
82
|
+
}
|
|
83
|
+
var commonFormatResult = tryParseCommonDateFormats(datePart);
|
|
84
|
+
if (commonFormatResult)
|
|
85
|
+
return commonFormatResult;
|
|
86
|
+
var cleanedInput = datePart
|
|
87
|
+
.trim()
|
|
88
|
+
.split(/[\s;|:.\/-]+/)
|
|
89
|
+
.filter(Boolean)
|
|
90
|
+
.map(function (word) { return word.toLowerCase(); });
|
|
91
|
+
var possibleDay = null, possibleMonth = null, possibleYear = null;
|
|
92
|
+
for (var _i = 0, cleanedInput_1 = cleanedInput; _i < cleanedInput_1.length; _i++) {
|
|
93
|
+
var word = cleanedInput_1[_i];
|
|
94
|
+
if (DAY_NAMES.includes(word) || DAY_ABBREVIATIONS.includes(word))
|
|
95
|
+
continue;
|
|
96
|
+
var num = parseInt(word, 10);
|
|
97
|
+
if (!possibleDay && num > 0 && num <= 31) {
|
|
98
|
+
possibleDay = num;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (!possibleMonth) {
|
|
102
|
+
var monthIndex = MONTH_NAMES.indexOf(word);
|
|
103
|
+
if (monthIndex === -1)
|
|
104
|
+
monthIndex = MONTH_ABBREVIATIONS.indexOf(word);
|
|
105
|
+
if (monthIndex !== -1) {
|
|
106
|
+
possibleMonth = monthIndex + 1;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
else if (num > 0 && num <= 12) {
|
|
110
|
+
possibleMonth = num;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!possibleYear && num >= 0) {
|
|
115
|
+
possibleYear = num < 100 ? num + (num < 50 ? 2000 : 1900) : num;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (possibleDay && possibleMonth && possibleYear) {
|
|
120
|
+
return DateTime.fromObject({
|
|
121
|
+
day: possibleDay,
|
|
122
|
+
month: possibleMonth,
|
|
123
|
+
year: possibleYear,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
};
|
|
128
|
+
export var parseTimeFromUserInput = function (input) {
|
|
129
|
+
var cleanedInput = input
|
|
130
|
+
.trim()
|
|
131
|
+
.replace(/\s*:\s*/g, ":")
|
|
132
|
+
.replace(/\s+(AM|PM|am|pm)\s*$/, " $1");
|
|
133
|
+
var len = cleanedInput.length;
|
|
134
|
+
if (len < 4 || len > 16)
|
|
135
|
+
return null;
|
|
136
|
+
var hour = 0, minute = 0, second = 0, millisecond = 0;
|
|
137
|
+
var meridiem = null;
|
|
138
|
+
var parts = cleanedInput.split(" ");
|
|
139
|
+
if (parts.length > 2)
|
|
140
|
+
return null;
|
|
141
|
+
if (parts.length === 2) {
|
|
142
|
+
meridiem = parts[1].toUpperCase();
|
|
143
|
+
if (meridiem !== "AM" && meridiem !== "PM")
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
var timeParts = parts[0].split(":");
|
|
147
|
+
if (timeParts.length < 2 || timeParts.length > 3)
|
|
148
|
+
return null;
|
|
149
|
+
hour = parseInt(timeParts[0], 10);
|
|
150
|
+
minute = parseInt(timeParts[1], 10);
|
|
151
|
+
if (isNaN(hour) || isNaN(minute))
|
|
152
|
+
return null;
|
|
153
|
+
if (timeParts.length === 3) {
|
|
154
|
+
var secondParts = timeParts[2].split("."); // Split to consider milliseconds
|
|
155
|
+
second = parseInt(secondParts[0], 10);
|
|
156
|
+
if (secondParts.length === 2) {
|
|
157
|
+
millisecond = parseInt(secondParts[1], 10);
|
|
158
|
+
}
|
|
159
|
+
if (isNaN(second) || isNaN(millisecond))
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
if (hour < 0 ||
|
|
163
|
+
hour > 23 ||
|
|
164
|
+
minute < 0 ||
|
|
165
|
+
minute > 59 ||
|
|
166
|
+
second < 0 ||
|
|
167
|
+
second > 59 ||
|
|
168
|
+
millisecond < 0 ||
|
|
169
|
+
millisecond > 999)
|
|
170
|
+
return null;
|
|
171
|
+
if (meridiem === "PM" && hour < 12) {
|
|
172
|
+
hour += 12;
|
|
173
|
+
}
|
|
174
|
+
else if (meridiem === "AM" && hour === 12) {
|
|
175
|
+
hour = 0;
|
|
176
|
+
}
|
|
177
|
+
var dateTime = DateTime.fromObject({ hour: hour, minute: minute, second: second, millisecond: millisecond });
|
|
178
|
+
return dateTime.isValid ? dateTime : null;
|
|
179
|
+
};
|
|
180
|
+
export var parseTimeFromDateTimeorTimeInput = function (userInput) {
|
|
181
|
+
var res1 = parseTimeFromUserInput(userInput);
|
|
182
|
+
if (res1)
|
|
183
|
+
return res1;
|
|
184
|
+
var res2 = parseDateTimeFromUserInput(userInput);
|
|
185
|
+
if (res2)
|
|
186
|
+
return res2;
|
|
187
|
+
return null;
|
|
188
|
+
};
|
|
189
|
+
export var parseDateTimeFromUserInput = function (userInput) {
|
|
190
|
+
var fromISO = DateTime.fromISO(userInput);
|
|
191
|
+
if (fromISO.isValid && userInput.includes("T"))
|
|
192
|
+
return fromISO;
|
|
193
|
+
var cleanedInput = userInput.trim().replace(/\s+/g, " ").toLowerCase();
|
|
194
|
+
var words = cleanedInput.split(" ");
|
|
195
|
+
var datePart = "";
|
|
196
|
+
var timePart = "";
|
|
197
|
+
var meridiem = "";
|
|
198
|
+
for (var _i = 0, words_1 = words; _i < words_1.length; _i++) {
|
|
199
|
+
var word = words_1[_i];
|
|
200
|
+
if (word === "am" || word === "pm") {
|
|
201
|
+
meridiem = word.toUpperCase();
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (word.includes(":")) {
|
|
205
|
+
timePart = word;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
datePart = "".concat(datePart, " ").concat(word);
|
|
209
|
+
}
|
|
210
|
+
if (meridiem) {
|
|
211
|
+
timePart = "".concat(timePart, " ").concat(meridiem);
|
|
212
|
+
}
|
|
213
|
+
var dateObject = parseDateFromUserInput(datePart.trim());
|
|
214
|
+
if (!dateObject || !dateObject.isValid)
|
|
215
|
+
return null;
|
|
216
|
+
var timeObject = parseTimeFromUserInput(timePart.trim());
|
|
217
|
+
if (!timeObject || !timeObject.isValid)
|
|
218
|
+
return null;
|
|
219
|
+
if (!timeObject || !timeObject.isValid)
|
|
220
|
+
return null;
|
|
221
|
+
var combinedDateTime = DateTime.fromObject({
|
|
222
|
+
year: dateObject.year,
|
|
223
|
+
month: dateObject.month,
|
|
224
|
+
day: dateObject.day,
|
|
225
|
+
hour: timeObject.hour,
|
|
226
|
+
minute: timeObject.minute,
|
|
227
|
+
second: timeObject.second,
|
|
228
|
+
millisecond: timeObject.millisecond,
|
|
229
|
+
});
|
|
230
|
+
return combinedDateTime.isValid ? combinedDateTime : null;
|
|
231
|
+
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Field, FieldTransformation } from "
|
|
1
|
+
import { Field, FieldTransformation } from "../../../../../types";
|
|
2
2
|
export type FieldTransformator = (fieldValue: any, transformation?: FieldTransformation, fieldOptions?: Field) => {
|
|
3
3
|
transformationWasNeeded: boolean;
|
|
4
4
|
original: any;
|
|
5
5
|
transformed: any;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
7
|
+
export type FieldTransformations = Partial<{
|
|
8
|
+
[key: string]: FieldTransformator;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const isTransformationNeeded: (fieldValue: any, transformedValue: any) => {
|
|
8
11
|
transformationWasNeeded: boolean;
|
|
9
12
|
original: any;
|
|
10
13
|
transformed: any;
|
|
11
14
|
};
|
|
12
|
-
export type FieldTransformations = Partial<{
|
|
13
|
-
[key: string]: FieldTransformator | DateTimeTransformator;
|
|
14
|
-
}>;
|
|
15
15
|
export declare const datesDateTimesAndTimesTransformations: FieldTransformations;
|
|
16
16
|
export declare const fieldTransformations: {
|
|
17
|
-
[x: string]: FieldTransformator
|
|
17
|
+
[x: string]: FieldTransformator;
|
|
18
18
|
};
|
|
@@ -9,11 +9,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import {
|
|
13
|
-
var isTransformationNeeded = function (fieldValue, transformedValue) { return ({
|
|
14
|
-
transformationWasNeeded:
|
|
12
|
+
import { parseDateFromUserInput, parseDateTimeFromUserInput, parseTimeFromDateTimeorTimeInput, } from "./dateTimeAutoformatUtils";
|
|
13
|
+
export var isTransformationNeeded = function (fieldValue, transformedValue) { return ({
|
|
14
|
+
transformationWasNeeded: !!transformedValue
|
|
15
|
+
? fieldValue !== transformedValue
|
|
16
|
+
: false,
|
|
15
17
|
original: fieldValue,
|
|
16
|
-
transformed: fieldValue === transformedValue
|
|
18
|
+
transformed: fieldValue === transformedValue || transformedValue === undefined
|
|
19
|
+
? null
|
|
20
|
+
: transformedValue,
|
|
17
21
|
}); };
|
|
18
22
|
var isNotANumber = function (fieldValue) {
|
|
19
23
|
return fieldValue === null || fieldValue === undefined || isNaN(fieldValue);
|
|
@@ -79,49 +83,24 @@ var stringFieldTransformations = {
|
|
|
79
83
|
return isTransformationNeeded(fieldValue, transformedValue);
|
|
80
84
|
},
|
|
81
85
|
};
|
|
82
|
-
var parseDate = function (date, possibleFormats) {
|
|
83
|
-
if (!date)
|
|
84
|
-
return null;
|
|
85
|
-
for (var i = 0; i < possibleFormats.length; i++) {
|
|
86
|
-
var format = possibleFormats[i];
|
|
87
|
-
try {
|
|
88
|
-
var currentDate = DateTime.fromFormat(date, format, { zone: "utc" });
|
|
89
|
-
if (currentDate.isValid) {
|
|
90
|
-
return currentDate;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return null;
|
|
98
|
-
};
|
|
99
86
|
export var datesDateTimesAndTimesTransformations = {
|
|
100
|
-
autoformat: function (fieldValue, _, fieldOptions
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var
|
|
108
|
-
var
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
};
|
|
113
|
-
if (!fieldValue || !pattern || !luxonDate || isNaN(luxonDate.toSeconds())) {
|
|
114
|
-
return defaultObj;
|
|
115
|
-
}
|
|
116
|
-
if (!luxonDate.isValid) {
|
|
117
|
-
return defaultObj;
|
|
118
|
-
}
|
|
119
|
-
var transformedValue = luxonDate.toFormat(pattern);
|
|
120
|
-
return {
|
|
121
|
-
transformationWasNeeded: fieldValue !== transformedValue,
|
|
122
|
-
original: fieldValue,
|
|
123
|
-
transformed: transformedValue,
|
|
87
|
+
autoformat: function (fieldValue, _, fieldOptions) {
|
|
88
|
+
if (fieldValue === null || fieldValue === undefined)
|
|
89
|
+
return {
|
|
90
|
+
transformationWasNeeded: false,
|
|
91
|
+
original: fieldValue,
|
|
92
|
+
transformed: null,
|
|
93
|
+
};
|
|
94
|
+
var type = fieldOptions.type, pattern = fieldOptions.pattern;
|
|
95
|
+
var parseFunctions = {
|
|
96
|
+
date: parseDateFromUserInput,
|
|
97
|
+
datetime: parseDateTimeFromUserInput,
|
|
98
|
+
time: parseTimeFromDateTimeorTimeInput,
|
|
124
99
|
};
|
|
100
|
+
var parseFn = parseFunctions[type];
|
|
101
|
+
var dateValue = parseFn(fieldValue);
|
|
102
|
+
var transformedValue = dateValue === null || dateValue === void 0 ? void 0 : dateValue.toFormat(pattern);
|
|
103
|
+
return isTransformationNeeded(fieldValue, transformedValue);
|
|
125
104
|
},
|
|
126
105
|
};
|
|
127
106
|
var urlTransformations = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DuplicateValuesCollection, Field, FieldValidation } from "../../../../types";
|
|
2
1
|
import { MutableRefObject } from "react";
|
|
2
|
+
import { DuplicateValuesCollection, Field, FieldValidation } from "../../../../types";
|
|
3
3
|
export type FieldValidator = (field: Field, fieldValue: any, validation?: FieldValidation, duplicateValues?: MutableRefObject<DuplicateValuesCollection>, customErrorMessage?: string) => null | string;
|
|
4
4
|
export type FieldValidations = Partial<{
|
|
5
5
|
[key: string]: FieldValidator;
|
|
@@ -99,6 +99,7 @@ export var fieldValidations = {
|
|
|
99
99
|
var _a;
|
|
100
100
|
if (!isNullOrUndefined(fieldValue) &&
|
|
101
101
|
!isNullOrUndefined(duplicateValues.current)) {
|
|
102
|
+
fieldValue = String(fieldValue);
|
|
102
103
|
var isDuplicated = duplicateValues.current[field.name] &&
|
|
103
104
|
duplicateValues.current[field.name][fieldValue] &&
|
|
104
105
|
duplicateValues.current[field.name][fieldValue].length > 1;
|
|
@@ -110,6 +111,7 @@ export var fieldValidations = {
|
|
|
110
111
|
var _a;
|
|
111
112
|
if (!isNullOrUndefined(fieldValue) &&
|
|
112
113
|
!isNullOrUndefined(duplicateValues.current)) {
|
|
114
|
+
fieldValue = String(fieldValue);
|
|
113
115
|
var isDuplicated = duplicateValues.current[field.name] &&
|
|
114
116
|
duplicateValues.current[field.name][fieldValue.toLowerCase()] &&
|
|
115
117
|
duplicateValues.current[field.name][fieldValue.toLowerCase()].length >
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { MutableRefObject } from "react";
|
|
2
2
|
import { CustomAction, FormatRecord, ImporterOptions, Integration, OnSubmit, OnValidateRecord, Record, TemplateHeader } from "../../types";
|
|
3
3
|
import { FuseApi } from "../common/FuseApi";
|
|
4
4
|
export type HeaderMatchings = {
|
|
@@ -31,6 +31,7 @@ export type State = {
|
|
|
31
31
|
templateSlug: string;
|
|
32
32
|
apiToken: string;
|
|
33
33
|
inTrialMode: boolean;
|
|
34
|
+
hasValidSubmitFn: boolean;
|
|
34
35
|
previewFirstTime: boolean;
|
|
35
36
|
fuseApi: FuseApi;
|
|
36
37
|
importerOptions: ImporterOptions;
|
|
@@ -59,6 +60,8 @@ export type State = {
|
|
|
59
60
|
customActions: CustomAction[];
|
|
60
61
|
headerMappingsLoaded: boolean;
|
|
61
62
|
valueMappingsLoaded: boolean;
|
|
63
|
+
headersMappings: HeaderMappings[];
|
|
64
|
+
layoutRef: MutableRefObject<HTMLDivElement>;
|
|
62
65
|
};
|
|
63
66
|
export type Props = {
|
|
64
67
|
templateSlug: string;
|
|
@@ -73,5 +76,9 @@ export type Props = {
|
|
|
73
76
|
dynamicColumns: TemplateHeader[] | null;
|
|
74
77
|
customActions: CustomAction[];
|
|
75
78
|
};
|
|
79
|
+
type HeaderMappings = {
|
|
80
|
+
[key: string]: string;
|
|
81
|
+
};
|
|
76
82
|
export declare const ImporterContextProvider: ({ templateSlug, initialRecords, apiToken, children, options, onSubmit, onClose, formatRecord, onValidateRecord, dynamicColumns, customActions, }: Props) => JSX.Element;
|
|
77
83
|
export declare const useImporterContext: () => State;
|
|
84
|
+
export {};
|
|
@@ -77,13 +77,14 @@ export var ImporterContextProvider = function (_a) {
|
|
|
77
77
|
logoURL: null,
|
|
78
78
|
}), style = _l[0], setStyle = _l[1];
|
|
79
79
|
var _m = useState(null), templateHeaderMatchings = _m[0], setTemplateHeaderMatchings = _m[1];
|
|
80
|
-
var _o = useState(
|
|
80
|
+
var _o = useState({}), enumFieldValueMatchings = _o[0], setEnumFieldValueMatchings = _o[1];
|
|
81
81
|
var _p = useState(null), uploadedDataEnumFieldValues = _p[0], setUploadedDataEnumFieldValues = _p[1];
|
|
82
82
|
var _q = useState([]), selectedRows = _q[0], setSelectedRows = _q[1];
|
|
83
83
|
var isUsingManualImport = useRef(false);
|
|
84
84
|
var _r = useState(0), headerRowIndex = _r[0], setHeaderRowIndex = _r[1];
|
|
85
85
|
var _s = useState(false), headerMappingsLoaded = _s[0], setHeaderMappingsLoaded = _s[1];
|
|
86
86
|
var _t = useState(false), valueMappingsLoaded = _t[0], setValueMappingsLoaded = _t[1];
|
|
87
|
+
var layoutRef = useRef(null);
|
|
87
88
|
var fuseApi = useMemo(function () { return new FuseApi(options.env, apiToken); }, [
|
|
88
89
|
options.env,
|
|
89
90
|
apiToken,
|
|
@@ -230,7 +231,9 @@ export var ImporterContextProvider = function (_a) {
|
|
|
230
231
|
}
|
|
231
232
|
}, [uploadedDataHeaders, headersMappings]);
|
|
232
233
|
useEffect(function () {
|
|
233
|
-
if (!templateHeaderMatchings ||
|
|
234
|
+
if (!templateHeaderMatchings ||
|
|
235
|
+
!uploadedDataHeaders ||
|
|
236
|
+
!headerMappingsLoaded)
|
|
234
237
|
return;
|
|
235
238
|
var _uploadedDataEnumFieldValues = {};
|
|
236
239
|
var templateLabels = Object.keys(templateHeaderMatchings);
|
|
@@ -252,8 +255,13 @@ export var ImporterContextProvider = function (_a) {
|
|
|
252
255
|
});
|
|
253
256
|
});
|
|
254
257
|
setUploadedDataEnumFieldValues(_uploadedDataEnumFieldValues);
|
|
255
|
-
|
|
256
|
-
|
|
258
|
+
var valueLimitPerEnumField = Math.ceil(40 / enumFieldsLabels.length);
|
|
259
|
+
var enumFieldsLabelsLimited = {};
|
|
260
|
+
Object.keys(_uploadedDataEnumFieldValues).forEach(function (key) {
|
|
261
|
+
enumFieldsLabelsLimited[key] = _uploadedDataEnumFieldValues[key].slice(0, valueLimitPerEnumField);
|
|
262
|
+
});
|
|
263
|
+
loadValueMappings(enumFieldsLabelsLimited);
|
|
264
|
+
}, [headerMappingsLoaded, matcherSubstep]);
|
|
257
265
|
useEffect(function () {
|
|
258
266
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
259
267
|
var _a, organization_1, columns_1, importer_style_preferences, integrations_1, preview_first_time, error_1, errorMsg;
|
|
@@ -300,7 +308,8 @@ export var ImporterContextProvider = function (_a) {
|
|
|
300
308
|
setUploadedData(null);
|
|
301
309
|
setTemplateHeaderMatchings(null);
|
|
302
310
|
setHeadersMappings(null);
|
|
303
|
-
setEnumFieldValueMatchings(
|
|
311
|
+
setEnumFieldValueMatchings({});
|
|
312
|
+
setUploadedDataEnumFieldValues(null);
|
|
304
313
|
setSelectedRows([]);
|
|
305
314
|
setHeaderRowIndex(0);
|
|
306
315
|
};
|
|
@@ -318,6 +327,7 @@ export var ImporterContextProvider = function (_a) {
|
|
|
318
327
|
}
|
|
319
328
|
};
|
|
320
329
|
var inTrialMode = organization === null || organization === void 0 ? void 0 : organization.trial_mode;
|
|
330
|
+
var hasValidSubmitFn = typeof onSubmit === "function";
|
|
321
331
|
var value = {
|
|
322
332
|
initialRecords: initialRecords,
|
|
323
333
|
currentStepIndex: currentStepIndex,
|
|
@@ -334,6 +344,7 @@ export var ImporterContextProvider = function (_a) {
|
|
|
334
344
|
apiToken: apiToken,
|
|
335
345
|
templateSlug: templateSlug,
|
|
336
346
|
inTrialMode: inTrialMode,
|
|
347
|
+
hasValidSubmitFn: hasValidSubmitFn,
|
|
337
348
|
fuseApi: fuseApi,
|
|
338
349
|
theme: style.theme,
|
|
339
350
|
logoURL: style.logoURL,
|
|
@@ -361,6 +372,8 @@ export var ImporterContextProvider = function (_a) {
|
|
|
361
372
|
customActions: customActions,
|
|
362
373
|
headerMappingsLoaded: headerMappingsLoaded,
|
|
363
374
|
valueMappingsLoaded: valueMappingsLoaded,
|
|
375
|
+
headersMappings: headersMappings,
|
|
376
|
+
layoutRef: layoutRef,
|
|
364
377
|
};
|
|
365
378
|
return (_jsx(ImporterContext.Provider, __assign({ value: value }, { children: children })));
|
|
366
379
|
};
|
|
@@ -7,7 +7,6 @@ export declare const addEmptyRows: (data: Record[], fields: Field[]) => (Record
|
|
|
7
7
|
};
|
|
8
8
|
})[];
|
|
9
9
|
export declare const addMeta: (record: any, index: number, uploadedRow?: any, transformedRow?: TransformedRecord) => Record;
|
|
10
|
-
export declare const calculatePossibleDateFormats: (fieldsWithDateTransformations: Field[], sample: Record[]) => string[];
|
|
11
10
|
export declare const recordListToDataSet: (data: Record[], fields: Field[], withTransformations?: boolean) => {
|
|
12
11
|
isDatasetTransformed: boolean;
|
|
13
12
|
dataSet: RecordDataSet;
|
|
@@ -18,13 +18,9 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
18
18
|
}
|
|
19
19
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
20
|
};
|
|
21
|
-
import { datesDateTimesAndTimesTransformations } from "../../Importer/common/Spreadsheet/transformation/transformators";
|
|
22
21
|
import { transformRecord } from "../../Importer/common/Spreadsheet/transformation";
|
|
23
22
|
import { FieldTypes, } from "../../types";
|
|
24
23
|
import { parseValue } from "../common/Spreadsheet/common";
|
|
25
|
-
import { DateTime } from "luxon";
|
|
26
|
-
import { allowedPatternValues } from "../../common/datePatterns";
|
|
27
|
-
import _ from "lodash";
|
|
28
24
|
var MINIMUM_ROW_COUNT = 20;
|
|
29
25
|
var getRowId = function (index) {
|
|
30
26
|
return index.toString();
|
|
@@ -48,29 +44,6 @@ export var addMeta = function (record, index, uploadedRow, transformedRow) {
|
|
|
48
44
|
var meta = (_a = record._meta) !== null && _a !== void 0 ? _a : {};
|
|
49
45
|
return __assign(__assign({}, record), { _meta: __assign(__assign({}, meta), { id: rId, rowIndex: index, uploadedRow: uploadedRow, transformedRow: transformedRow }) });
|
|
50
46
|
};
|
|
51
|
-
export var calculatePossibleDateFormats = function (fieldsWithDateTransformations, sample) {
|
|
52
|
-
var possibleDateFormats = [];
|
|
53
|
-
for (var _i = 0, sample_1 = sample; _i < sample_1.length; _i++) {
|
|
54
|
-
var record = sample_1[_i];
|
|
55
|
-
for (var _a = 0, fieldsWithDateTransformations_1 = fieldsWithDateTransformations; _a < fieldsWithDateTransformations_1.length; _a++) {
|
|
56
|
-
var field = fieldsWithDateTransformations_1[_a];
|
|
57
|
-
var value = record[field.name];
|
|
58
|
-
if (!value)
|
|
59
|
-
continue;
|
|
60
|
-
for (var i = 0; i < allowedPatternValues.length; i++) {
|
|
61
|
-
var format = allowedPatternValues[i];
|
|
62
|
-
try {
|
|
63
|
-
var currentDate = DateTime.fromFormat(value, format);
|
|
64
|
-
if (currentDate.isValid) {
|
|
65
|
-
possibleDateFormats.push(format);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (e) { }
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return Array.from(new Set(possibleDateFormats));
|
|
73
|
-
};
|
|
74
47
|
export var recordListToDataSet = function (data, fields, withTransformations) {
|
|
75
48
|
if (withTransformations === void 0) { withTransformations = true; }
|
|
76
49
|
var fieldWithTransformations = fields.filter(function (field) { var _a; return ((_a = field === null || field === void 0 ? void 0 : field.transformations) === null || _a === void 0 ? void 0 : _a.length) > 0; });
|
|
@@ -78,15 +51,6 @@ export var recordListToDataSet = function (data, fields, withTransformations) {
|
|
|
78
51
|
if (data.length < MINIMUM_ROW_COUNT) {
|
|
79
52
|
initialData = addEmptyRows(data, fields);
|
|
80
53
|
}
|
|
81
|
-
var fieldsWithDateTransformations = fieldWithTransformations.filter(function (field) {
|
|
82
|
-
return field.transformations.some(function (t) {
|
|
83
|
-
return Object.keys(datesDateTimesAndTimesTransformations).includes(t.transformation_type);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
var possibleDateFormats = [];
|
|
87
|
-
if (fieldsWithDateTransformations.length > 0) {
|
|
88
|
-
possibleDateFormats.push.apply(possibleDateFormats, calculatePossibleDateFormats(fieldsWithDateTransformations, _.sampleSize(initialData, 100)));
|
|
89
|
-
}
|
|
90
54
|
var isDatasetTransformed = false;
|
|
91
55
|
var res = initialData.reduce(function (dataSet, record, i) {
|
|
92
56
|
var transformedRecord = {};
|
|
@@ -94,7 +58,6 @@ export var recordListToDataSet = function (data, fields, withTransformations) {
|
|
|
94
58
|
transformedRecord = transformRecord({
|
|
95
59
|
record: record,
|
|
96
60
|
fields: fieldWithTransformations,
|
|
97
|
-
possibleDateFormats: possibleDateFormats,
|
|
98
61
|
});
|
|
99
62
|
}
|
|
100
63
|
if (JSON.stringify(transformedRecord) !== "{}")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AppResponse, RecordDataSet } from "../../types";
|
|
2
|
-
export declare const useSubmitToServer: (
|
|
2
|
+
export declare const useSubmitToServer: (setHasTransformedRecords: any) => {
|
|
3
3
|
appResponse: AppResponse;
|
|
4
4
|
isSubmitting: boolean;
|
|
5
5
|
onSubmitToServer: (dataSet: RecordDataSet, afterSubmitCallback: (dataSet: RecordDataSet) => void) => Promise<void>;
|