fuse-importer 0.1.4-testing → 0.1.5-testing
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/Importer/ImporterWithContext.js +38 -7
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/index.js +1 -1
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/index.js +4 -3
- package/lib/esm/Importer/Matcher/HeaderMatcher/index.js +14 -9
- package/lib/esm/Importer/PreviewFirstTime.js +1 -1
- package/lib/esm/Importer/Review/ReviewContextProvider.d.ts +6 -6
- package/lib/esm/Importer/Review/ReviewContextProvider.js +51 -223
- package/lib/esm/Importer/Review/ReviewWithContext.js +2 -2
- package/lib/esm/Importer/Stepper/StepperSubmitModal.d.ts +2 -1
- package/lib/esm/Importer/Stepper/StepperSubmitModal.js +4 -2
- package/lib/esm/Importer/Stepper/UnmatchedHeadersModal.js +1 -1
- package/lib/esm/Importer/Stepper/index.js +20 -69
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterDropzone.d.ts +2 -1
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterDropzone.js +14 -86
- package/lib/esm/Importer/Uploader/DragAndDropImporter/index.js +11 -3
- package/lib/esm/Importer/Uploader/HeadersPreview.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/DataSetContextProvider/index.d.ts +16 -0
- package/lib/esm/Importer/common/Spreadsheet/DataSetContextProvider/index.js +63 -0
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.d.ts +18 -0
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.js +101 -0
- package/lib/esm/Importer/common/Spreadsheet/FilteredDataContextProvider/index.d.ts +29 -0
- package/lib/esm/Importer/common/Spreadsheet/FilteredDataContextProvider/index.js +150 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/filterMethods.d.ts +6 -4
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/filterMethods.js +37 -37
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.d.ts +6 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.js +138 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.d.ts +7 -29
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.js +11 -193
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.d.ts +5 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.js +72 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.d.ts +4 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js +46 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/utils.js +2 -1
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.d.ts +31 -0
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.js +304 -0
- package/lib/esm/Importer/common/Spreadsheet/common/index.js +5 -4
- package/lib/esm/Importer/common/Spreadsheet/common/types.d.ts +2 -3
- package/lib/esm/Importer/common/Spreadsheet/components/FieldHeader.d.ts +0 -2
- package/lib/esm/Importer/common/Spreadsheet/components/FieldHeader.js +26 -11
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.js +21 -13
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.js +35 -36
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowNumbers.js +3 -3
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpreadsheetInput.js +5 -1
- package/lib/esm/Importer/common/Spreadsheet/components/fields/index.js +43 -17
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/index.js +1 -2
- package/lib/esm/Importer/common/Spreadsheet/index.d.ts +0 -1
- package/lib/esm/Importer/common/Spreadsheet/index.js +1 -84
- package/lib/esm/Importer/common/Spreadsheet/styles.d.ts +1 -2
- package/lib/esm/Importer/common/Spreadsheet/styles.js +13 -1
- package/lib/esm/Importer/common/Spreadsheet/useFieldSorting.d.ts +5 -0
- package/lib/esm/Importer/common/Spreadsheet/useFieldSorting.js +81 -0
- package/lib/esm/Importer/common/Spreadsheet/validation/index.d.ts +5 -3
- package/lib/esm/Importer/common/Spreadsheet/validation/index.js +13 -17
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.d.ts +3 -2
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.js +16 -7
- package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +4 -2
- package/lib/esm/Importer/contexts/ImporterContextProvider.js +121 -13
- package/lib/esm/Importer/data/index.js +7 -5
- package/lib/esm/Importer/hooks/useExportDataToFile.d.ts +5 -0
- package/lib/esm/Importer/hooks/useExportDataToFile.js +54 -0
- package/lib/esm/Importer/hooks/useSubmitToServer.d.ts +7 -0
- package/lib/esm/Importer/hooks/useSubmitToServer.js +192 -0
- package/lib/esm/common/EventManagerContextProvider/index.d.ts +22 -0
- package/lib/esm/common/EventManagerContextProvider/index.js +38 -0
- package/lib/esm/common/FileUploadDropzone/ImporterDropzone.d.ts +16 -0
- package/lib/esm/common/FileUploadDropzone/ImporterDropzone.js +108 -0
- package/lib/esm/common/FileUploadDropzone/index.d.ts +1 -0
- package/lib/esm/common/FileUploadDropzone/index.js +1 -0
- package/lib/esm/common/Table/TableActions/CustomActions/CustomActions.js +55 -41
- package/lib/esm/common/Table/TableActions/DeleteSelectedRows.js +25 -16
- package/lib/esm/common/Table/TableActions/ExportData.js +5 -3
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +36 -9
- package/lib/esm/common/Table/TableActions/RowFilters.js +53 -5
- package/lib/esm/common/Table/TableActions/SearchRows.js +3 -1
- package/lib/esm/common/Table/TableActions/TableActions.js +2 -1
- package/lib/esm/common/Table/TableActions/TransformedRecordsCount.js +16 -9
- package/lib/esm/common/Table/TableActions/ValidationProgress.d.ts +2 -0
- package/lib/esm/common/Table/TableActions/ValidationProgress.js +22 -0
- package/lib/esm/common/Table/TableView/TableRows/TableRow.d.ts +1 -1
- package/lib/esm/common/Table/TableView/TableRows/TableRow.js +2 -2
- package/lib/esm/common/Table/TableView/TableRows/index.js +21 -6
- package/lib/esm/common/Table/TableView/index.d.ts +1 -1
- package/lib/esm/common/Table/TableView/index.js +6 -15
- package/lib/esm/common/Table/TableView/types.d.ts +8 -9
- package/lib/esm/common/Table/index.d.ts +2 -1
- package/lib/esm/common/Table/index.js +2 -2
- package/lib/esm/common/Toast.js +3 -2
- package/lib/esm/common/TooltipProvider.d.ts +2 -0
- package/lib/esm/common/TooltipProvider.js +12 -9
- package/lib/esm/common/buttons.d.ts +5 -1
- package/lib/esm/common/buttons.js +13 -7
- package/lib/esm/common/columnsTransformations.js +1 -1
- package/lib/esm/common/icons/index.d.ts +1 -0
- package/lib/esm/common/icons/index.js +1 -0
- package/lib/esm/common/index.d.ts +1 -0
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/inputs/Autocomplete.js +1 -1
- package/lib/esm/locales/de.d.ts +1 -1
- package/lib/esm/locales/de.js +1 -1
- package/lib/esm/locales/en.d.ts +1 -1
- package/lib/esm/locales/en.js +4 -4
- package/lib/esm/locales/es.d.ts +1 -1
- package/lib/esm/locales/es.js +1 -1
- package/lib/esm/locales/fr.d.ts +1 -1
- package/lib/esm/locales/fr.js +1 -1
- package/lib/esm/types.d.ts +20 -5
- package/lib/main.js +2 -2
- package/package.json +6 -4
- package/lib/esm/Importer/Stepper/common/getEnumFieldValueMatchingsInitialValue.d.ts +0 -8
- package/lib/esm/Importer/Stepper/common/getEnumFieldValueMatchingsInitialValue.js +0 -36
- package/lib/esm/Importer/common/Spreadsheet/components/ValidationProgress.d.ts +0 -5
- package/lib/esm/Importer/common/Spreadsheet/components/ValidationProgress.js +0 -19
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/EmailInput.d.ts +0 -3
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/EmailInput.js +0 -14
- package/lib/esm/Importer/common/Spreadsheet/hooks.d.ts +0 -33
- package/lib/esm/Importer/common/Spreadsheet/hooks.js +0 -256
- package/lib/esm/common/Table/TableActions/FilterByErrors/functions.d.ts +0 -11
- package/lib/esm/common/Table/TableActions/FilterByErrors/functions.js +0 -35
- package/lib/esm/common/Table/TableActions/hooks.d.ts +0 -18
- package/lib/esm/common/Table/TableActions/hooks.js +0 -41
|
@@ -89,9 +89,9 @@ function safeCallOnValidateRecord(_a) {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
function safeCallValidator(_a) {
|
|
92
|
-
var field = _a.field, record = _a.record, validator = _a.validator, validatorFunction = _a.validatorFunction,
|
|
92
|
+
var field = _a.field, record = _a.record, validator = _a.validator, validatorFunction = _a.validatorFunction, duplicateValues = _a.duplicateValues;
|
|
93
93
|
try {
|
|
94
|
-
return validatorFunction(field, record[field.name], validator,
|
|
94
|
+
return validatorFunction(field, record[field.name], validator, duplicateValues);
|
|
95
95
|
}
|
|
96
96
|
catch (e) {
|
|
97
97
|
console.error("Validator ".concat(validator === null || validator === void 0 ? void 0 : validator.validation_type, " for field ").concat(JSON.stringify(field), " and value ").concat(record[field.name], " failed."), e);
|
|
@@ -102,7 +102,7 @@ function mergeErrorsAndWarnings(currentErrors, errors) {
|
|
|
102
102
|
return __assign(__assign({}, currentErrors), { errors: __assign(__assign({}, (currentErrors.errors || {})), errors), warnings: __assign({}, (currentErrors.warnings || {})) });
|
|
103
103
|
}
|
|
104
104
|
function runValidatorsFor(_a) {
|
|
105
|
-
var record = _a.record,
|
|
105
|
+
var record = _a.record, validators = _a.validators, duplicateValues = _a.duplicateValues;
|
|
106
106
|
return validators.reduce(function (currentErrors, _a) {
|
|
107
107
|
var field = _a.field, validators = _a.validators;
|
|
108
108
|
var errors = {};
|
|
@@ -115,8 +115,8 @@ function runValidatorsFor(_a) {
|
|
|
115
115
|
field: field,
|
|
116
116
|
record: record,
|
|
117
117
|
validator: validator,
|
|
118
|
-
data: data,
|
|
119
118
|
validatorFunction: validatorFunction,
|
|
119
|
+
duplicateValues: duplicateValues,
|
|
120
120
|
});
|
|
121
121
|
if (error) {
|
|
122
122
|
errors[field.name] = error;
|
|
@@ -159,29 +159,25 @@ export function selectValidatorsFor(fields) {
|
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
export function validateRecord(_a) {
|
|
162
|
-
var
|
|
163
|
-
var record = _a.record, fields = _a.fields, data = _a.data, onValidateRecord = _a.onValidateRecord, validatorsCache = _a.validatorsCache;
|
|
162
|
+
var record = _a.record, fields = _a.fields, onValidateRecord = _a.onValidateRecord, validatorsCache = _a.validatorsCache, duplicateValues = _a.duplicateValues, backendErrors = _a.backendErrors;
|
|
164
163
|
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
-
var
|
|
166
|
-
return __generator(this, function (
|
|
167
|
-
switch (
|
|
164
|
+
var validators, _b, validatorErrors, validatorWarnings, errors, warnings, _c, onValidateRecordErrors, onValidateRecordWarnings;
|
|
165
|
+
return __generator(this, function (_d) {
|
|
166
|
+
switch (_d.label) {
|
|
168
167
|
case 0:
|
|
169
168
|
if (isRecordEmpty(record, fields)) {
|
|
170
169
|
//TODO: Check this logic because this can skip the validation of touched rows because all fields are empty
|
|
171
170
|
return [2 /*return*/, { errors: {}, warnings: {} }];
|
|
172
171
|
}
|
|
173
|
-
|
|
174
|
-
backendErrors = ((_c = record._meta) === null || _c === void 0 ? void 0 : _c.backendErrors) || {};
|
|
175
|
-
hasBackendErrors = Object.keys(backendErrors).length > 0;
|
|
176
|
-
if (!isTouched && hasBackendErrors) {
|
|
172
|
+
if (backendErrors) {
|
|
177
173
|
return [2 /*return*/, { errors: backendErrors, warnings: {} }];
|
|
178
174
|
}
|
|
179
175
|
validators = validatorsCache !== null && validatorsCache !== void 0 ? validatorsCache : selectValidatorsFor(fields);
|
|
180
|
-
|
|
176
|
+
_b = runValidatorsFor({
|
|
181
177
|
record: record,
|
|
182
|
-
data: data,
|
|
183
178
|
validators: validators,
|
|
184
|
-
|
|
179
|
+
duplicateValues: duplicateValues,
|
|
180
|
+
}), validatorErrors = _b.errors, validatorWarnings = _b.warnings;
|
|
185
181
|
errors = ignoreNullOrUndefinedKeyValues(validatorErrors);
|
|
186
182
|
warnings = ignoreNullOrUndefinedKeyValues(validatorWarnings);
|
|
187
183
|
if (!!isNullOrUndefined(onValidateRecord)) return [3 /*break*/, 2];
|
|
@@ -190,7 +186,7 @@ export function validateRecord(_a) {
|
|
|
190
186
|
record: record,
|
|
191
187
|
})];
|
|
192
188
|
case 1:
|
|
193
|
-
|
|
189
|
+
_c = _d.sent(), onValidateRecordErrors = _c.errors, onValidateRecordWarnings = _c.warnings;
|
|
194
190
|
return [2 /*return*/, {
|
|
195
191
|
errors: __assign(__assign({}, errors), onValidateRecordErrors),
|
|
196
192
|
warnings: __assign(__assign({}, warnings), onValidateRecordWarnings),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Field, FieldValidation
|
|
2
|
-
|
|
1
|
+
import { DuplicateValuesCollection, Field, FieldValidation } from "../../../../types";
|
|
2
|
+
import { MutableRefObject } from "react";
|
|
3
|
+
export type FieldValidator = (field: Field, fieldValue: any, validation?: FieldValidation, duplicateValues?: MutableRefObject<DuplicateValuesCollection>, customErrorMessage?: string) => null | string;
|
|
3
4
|
export type FieldValidations = Partial<{
|
|
4
5
|
[key: string]: FieldValidator;
|
|
5
6
|
}>;
|
|
@@ -85,7 +85,9 @@ export var fieldValidations = {
|
|
|
85
85
|
if (!isNullOrUndefined(field.pattern) &&
|
|
86
86
|
!isNullOrUndefined(fieldValue) &&
|
|
87
87
|
!DateTime.fromFormat(fieldValue, field.pattern).isValid) {
|
|
88
|
-
var randomDate = DateTime.fromISO("1990-01-15T14:35:55.150"
|
|
88
|
+
var randomDate = DateTime.fromISO("1990-01-15T14:35:55.150", {
|
|
89
|
+
zone: "utc",
|
|
90
|
+
});
|
|
89
91
|
var transformedValue = randomDate === null || randomDate === void 0 ? void 0 : randomDate.toFormat(field.pattern);
|
|
90
92
|
var defaultMessage = "".concat(field.label, " must match the pattern ").concat(field.pattern);
|
|
91
93
|
return transformedValue
|
|
@@ -93,18 +95,25 @@ export var fieldValidations = {
|
|
|
93
95
|
: defaultMessage;
|
|
94
96
|
}
|
|
95
97
|
},
|
|
96
|
-
unique_case_sensitive: function (field, fieldValue, validator,
|
|
98
|
+
unique_case_sensitive: function (field, fieldValue, validator, duplicateValues) {
|
|
97
99
|
var _a;
|
|
98
|
-
if (!isNullOrUndefined(fieldValue) &&
|
|
99
|
-
|
|
100
|
+
if (!isNullOrUndefined(fieldValue) &&
|
|
101
|
+
!isNullOrUndefined(duplicateValues.current)) {
|
|
102
|
+
var isDuplicated = duplicateValues.current[field.name] &&
|
|
103
|
+
duplicateValues.current[field.name][fieldValue] &&
|
|
104
|
+
duplicateValues.current[field.name][fieldValue].length > 1;
|
|
100
105
|
var message = (_a = validator.message) !== null && _a !== void 0 ? _a : "".concat(field.label, " must be unique case sensitive");
|
|
101
106
|
return isDuplicated ? message : undefined;
|
|
102
107
|
}
|
|
103
108
|
},
|
|
104
|
-
unique_case_insensitive: function (field, fieldValue, validator,
|
|
109
|
+
unique_case_insensitive: function (field, fieldValue, validator, duplicateValues) {
|
|
105
110
|
var _a;
|
|
106
|
-
if (!isNullOrUndefined(fieldValue) &&
|
|
107
|
-
|
|
111
|
+
if (!isNullOrUndefined(fieldValue) &&
|
|
112
|
+
!isNullOrUndefined(duplicateValues.current)) {
|
|
113
|
+
var isDuplicated = duplicateValues.current[field.name] &&
|
|
114
|
+
duplicateValues.current[field.name][fieldValue.toLowerCase()] &&
|
|
115
|
+
duplicateValues.current[field.name][fieldValue.toLowerCase()].length >
|
|
116
|
+
1;
|
|
108
117
|
var message = (_a = validator.message) !== null && _a !== void 0 ? _a : "".concat(field.label, " must be unique case insensitive");
|
|
109
118
|
return isDuplicated ? message : undefined;
|
|
110
119
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { CustomAction, FormatRecord, ImporterOptions, Integration, OnSubmit, OnValidateRecord, Record, TemplateHeader } from "../../types";
|
|
3
3
|
import { FuseApi } from "../common/FuseApi";
|
|
4
4
|
export type HeaderMatchings = {
|
|
5
5
|
[templateHeaderLabel: string]: string;
|
|
@@ -23,6 +23,7 @@ export type State = {
|
|
|
23
23
|
initialRecords: Record[];
|
|
24
24
|
enumFieldValueMatchings: EnumFieldValueMatchings;
|
|
25
25
|
templateHeaders: TemplateHeader[];
|
|
26
|
+
userDynamicColumns: string[];
|
|
26
27
|
templateHeaderMatchings: HeaderMatchings;
|
|
27
28
|
uploadedDataHeaders: string[];
|
|
28
29
|
matcherSubstep: number;
|
|
@@ -55,8 +56,9 @@ export type State = {
|
|
|
55
56
|
isUsingManualImport: React.MutableRefObject<boolean>;
|
|
56
57
|
resetImporterWhenUsingManualImport: () => void;
|
|
57
58
|
manualDataImportSelected: () => void;
|
|
58
|
-
columnMappingsAttributes: ColumnMapping[];
|
|
59
59
|
customActions: CustomAction[];
|
|
60
|
+
headerMappingsLoaded: boolean;
|
|
61
|
+
valueMappingsLoaded: boolean;
|
|
60
62
|
};
|
|
61
63
|
export type Props = {
|
|
62
64
|
templateSlug: string;
|
|
@@ -71,22 +71,51 @@ export var ImporterContextProvider = function (_a) {
|
|
|
71
71
|
var _g = useState(null), uploadedData = _g[0], setUploadedData = _g[1];
|
|
72
72
|
var _h = useState(null), organization = _h[0], setOrganization = _h[1];
|
|
73
73
|
var _j = useState(null), previewFirstTime = _j[0], setPreviewFirstTime = _j[1];
|
|
74
|
-
var _k = useState(null),
|
|
75
|
-
var _l = useState(
|
|
76
|
-
var _m = useState({
|
|
74
|
+
var _k = useState(null), headersMappings = _k[0], setHeadersMappings = _k[1];
|
|
75
|
+
var _l = useState({
|
|
77
76
|
theme: theme,
|
|
78
77
|
logoURL: null,
|
|
79
|
-
}), style =
|
|
80
|
-
var
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
var
|
|
78
|
+
}), style = _l[0], setStyle = _l[1];
|
|
79
|
+
var _m = useState(null), templateHeaderMatchings = _m[0], setTemplateHeaderMatchings = _m[1];
|
|
80
|
+
var _o = useState(null), enumFieldValueMatchings = _o[0], setEnumFieldValueMatchings = _o[1];
|
|
81
|
+
var _p = useState(null), uploadedDataEnumFieldValues = _p[0], setUploadedDataEnumFieldValues = _p[1];
|
|
82
|
+
var _q = useState([]), selectedRows = _q[0], setSelectedRows = _q[1];
|
|
84
83
|
var isUsingManualImport = useRef(false);
|
|
85
|
-
var
|
|
84
|
+
var _r = useState(0), headerRowIndex = _r[0], setHeaderRowIndex = _r[1];
|
|
85
|
+
var _s = useState(false), headerMappingsLoaded = _s[0], setHeaderMappingsLoaded = _s[1];
|
|
86
|
+
var _t = useState(false), valueMappingsLoaded = _t[0], setValueMappingsLoaded = _t[1];
|
|
86
87
|
var fuseApi = useMemo(function () { return new FuseApi(options.env, apiToken); }, [
|
|
87
88
|
options.env,
|
|
88
89
|
apiToken,
|
|
89
90
|
]);
|
|
91
|
+
var fetchColumnMappings = function (userDynamicColumns) { return __awaiter(void 0, void 0, void 0, function () {
|
|
92
|
+
var mappings;
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0: return [4 /*yield*/, fuseApi.post("/api/v1/importer/templates/".concat(templateSlug, "/column_mappings"), {
|
|
96
|
+
file_headers: uploadedDataHeaders,
|
|
97
|
+
dynamic_columns: userDynamicColumns,
|
|
98
|
+
})];
|
|
99
|
+
case 1:
|
|
100
|
+
mappings = (_a.sent()).data.mappings;
|
|
101
|
+
return [2 /*return*/, mappings];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}); };
|
|
105
|
+
var fetchValueMappings = function (_uploadedDataEnumFieldValues, userDynamicValues) { return __awaiter(void 0, void 0, void 0, function () {
|
|
106
|
+
var mappings;
|
|
107
|
+
return __generator(this, function (_a) {
|
|
108
|
+
switch (_a.label) {
|
|
109
|
+
case 0: return [4 /*yield*/, fuseApi.post("/api/v1/importer/templates/".concat(templateSlug, "/value_mappings"), {
|
|
110
|
+
file_values: _uploadedDataEnumFieldValues,
|
|
111
|
+
dynamic_values: userDynamicValues,
|
|
112
|
+
})];
|
|
113
|
+
case 1:
|
|
114
|
+
mappings = (_a.sent()).data.mappings;
|
|
115
|
+
return [2 /*return*/, mappings];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}); };
|
|
90
119
|
var uploadedDataHeaders = useMemo(function () {
|
|
91
120
|
var _a;
|
|
92
121
|
if (!uploadedData)
|
|
@@ -101,6 +130,79 @@ export var ImporterContextProvider = function (_a) {
|
|
|
101
130
|
return typeof ud === "number" ? ud.toString() : ud;
|
|
102
131
|
});
|
|
103
132
|
}, [uploadedData, headerRowIndex]);
|
|
133
|
+
var userDynamicColumns = dynamicColumns.map(function (value) { return value.label; });
|
|
134
|
+
// use the API to match selected headers to the template
|
|
135
|
+
var loadHeaderMappings = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
136
|
+
var mappings, e_1;
|
|
137
|
+
return __generator(this, function (_a) {
|
|
138
|
+
switch (_a.label) {
|
|
139
|
+
case 0:
|
|
140
|
+
setHeaderMappingsLoaded(false);
|
|
141
|
+
_a.label = 1;
|
|
142
|
+
case 1:
|
|
143
|
+
_a.trys.push([1, 3, , 4]);
|
|
144
|
+
return [4 /*yield*/, fetchColumnMappings(userDynamicColumns)];
|
|
145
|
+
case 2:
|
|
146
|
+
mappings = _a.sent();
|
|
147
|
+
setHeadersMappings(mappings);
|
|
148
|
+
return [3 /*break*/, 4];
|
|
149
|
+
case 3:
|
|
150
|
+
e_1 = _a.sent();
|
|
151
|
+
setHeadersMappings([]);
|
|
152
|
+
console.error("Error occurred while fetching header mappings", e_1);
|
|
153
|
+
return [3 /*break*/, 4];
|
|
154
|
+
case 4:
|
|
155
|
+
setHeaderMappingsLoaded(true);
|
|
156
|
+
return [2 /*return*/];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}); };
|
|
160
|
+
useEffect(function () {
|
|
161
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
if (uploadedDataHeaders) {
|
|
164
|
+
loadHeaderMappings();
|
|
165
|
+
}
|
|
166
|
+
return [2 /*return*/];
|
|
167
|
+
});
|
|
168
|
+
}); })();
|
|
169
|
+
}, [uploadedDataHeaders]);
|
|
170
|
+
// Values mappings for enum columns
|
|
171
|
+
var loadValueMappings = function (_uploadedDataEnumFieldValues) { return __awaiter(void 0, void 0, void 0, function () {
|
|
172
|
+
var dynamicValues, mappings, e_2;
|
|
173
|
+
return __generator(this, function (_a) {
|
|
174
|
+
switch (_a.label) {
|
|
175
|
+
case 0:
|
|
176
|
+
setValueMappingsLoaded(false);
|
|
177
|
+
if (!(!!_uploadedDataEnumFieldValues &&
|
|
178
|
+
Object.keys(_uploadedDataEnumFieldValues).length > 0)) return [3 /*break*/, 4];
|
|
179
|
+
_a.label = 1;
|
|
180
|
+
case 1:
|
|
181
|
+
_a.trys.push([1, 3, , 4]);
|
|
182
|
+
dynamicValues = userDynamicColumns.reduce(function (acc, column) {
|
|
183
|
+
var _a;
|
|
184
|
+
var values = (_a = templateHeaders.find(function (header) { return header.label === column; })) === null || _a === void 0 ? void 0 : _a.values;
|
|
185
|
+
if (values) {
|
|
186
|
+
acc[column] = values;
|
|
187
|
+
}
|
|
188
|
+
return acc;
|
|
189
|
+
}, {});
|
|
190
|
+
return [4 /*yield*/, fetchValueMappings(_uploadedDataEnumFieldValues, dynamicValues)];
|
|
191
|
+
case 2:
|
|
192
|
+
mappings = _a.sent();
|
|
193
|
+
setEnumFieldValueMatchings(mappings);
|
|
194
|
+
return [3 /*break*/, 4];
|
|
195
|
+
case 3:
|
|
196
|
+
e_2 = _a.sent();
|
|
197
|
+
setEnumFieldValueMatchings({});
|
|
198
|
+
console.error("Error occurred while fetching value mappings", e_2);
|
|
199
|
+
return [3 /*break*/, 4];
|
|
200
|
+
case 4:
|
|
201
|
+
setValueMappingsLoaded(true);
|
|
202
|
+
return [2 /*return*/];
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}); };
|
|
104
206
|
useEffect(function () {
|
|
105
207
|
var setHeadersFromDataset = function () {
|
|
106
208
|
var _templateHeaderMatchings = {};
|
|
@@ -150,10 +252,11 @@ export var ImporterContextProvider = function (_a) {
|
|
|
150
252
|
});
|
|
151
253
|
});
|
|
152
254
|
setUploadedDataEnumFieldValues(_uploadedDataEnumFieldValues);
|
|
255
|
+
loadValueMappings(_uploadedDataEnumFieldValues);
|
|
153
256
|
}, [templateHeaderMatchings, uploadedDataHeaders]);
|
|
154
257
|
useEffect(function () {
|
|
155
258
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
156
|
-
var _a, organization_1, columns_1, importer_style_preferences, integrations_1, preview_first_time,
|
|
259
|
+
var _a, organization_1, columns_1, importer_style_preferences, integrations_1, preview_first_time, error_1, errorMsg;
|
|
157
260
|
var _b, _c;
|
|
158
261
|
return __generator(this, function (_d) {
|
|
159
262
|
switch (_d.label) {
|
|
@@ -161,7 +264,7 @@ export var ImporterContextProvider = function (_a) {
|
|
|
161
264
|
_d.trys.push([0, 2, , 3]);
|
|
162
265
|
return [4 /*yield*/, fuseApi.get("/api/v1/importer/templates/".concat(templateSlug))];
|
|
163
266
|
case 1:
|
|
164
|
-
_a = (_d.sent()).data, organization_1 = _a.organization, columns_1 = _a.columns, importer_style_preferences = _a.importer_style_preferences, integrations_1 = _a.integrations, preview_first_time = _a.preview_first_time
|
|
267
|
+
_a = (_d.sent()).data, organization_1 = _a.organization, columns_1 = _a.columns, importer_style_preferences = _a.importer_style_preferences, integrations_1 = _a.integrations, preview_first_time = _a.preview_first_time;
|
|
165
268
|
setOrganization(organization_1);
|
|
166
269
|
setTemplateHeaders(function () {
|
|
167
270
|
// user has created dynamic columns
|
|
@@ -178,7 +281,6 @@ export var ImporterContextProvider = function (_a) {
|
|
|
178
281
|
});
|
|
179
282
|
setIntegrations(integrations_1);
|
|
180
283
|
setPreviewFirstTime(preview_first_time);
|
|
181
|
-
setColumnMappingsAttributes(column_mappings_attributes);
|
|
182
284
|
if (organization_1.plan && organization_1.plan.allow_style_customization) {
|
|
183
285
|
setStyle(getCustomTheme(importer_style_preferences));
|
|
184
286
|
}
|
|
@@ -197,6 +299,10 @@ export var ImporterContextProvider = function (_a) {
|
|
|
197
299
|
var resetImport = function () {
|
|
198
300
|
setUploadedData(null);
|
|
199
301
|
setTemplateHeaderMatchings(null);
|
|
302
|
+
setHeadersMappings(null);
|
|
303
|
+
setEnumFieldValueMatchings(null);
|
|
304
|
+
setSelectedRows([]);
|
|
305
|
+
setHeaderRowIndex(0);
|
|
200
306
|
};
|
|
201
307
|
var resetImporterWhenUsingManualImport = function () {
|
|
202
308
|
setCurrentStepIndex(0);
|
|
@@ -216,6 +322,7 @@ export var ImporterContextProvider = function (_a) {
|
|
|
216
322
|
initialRecords: initialRecords,
|
|
217
323
|
currentStepIndex: currentStepIndex,
|
|
218
324
|
templateHeaders: templateHeaders,
|
|
325
|
+
userDynamicColumns: userDynamicColumns,
|
|
219
326
|
enumFieldValueMatchings: enumFieldValueMatchings,
|
|
220
327
|
templateHeaderMatchings: templateHeaderMatchings,
|
|
221
328
|
uploadedDataEnumFieldValues: uploadedDataEnumFieldValues,
|
|
@@ -231,7 +338,6 @@ export var ImporterContextProvider = function (_a) {
|
|
|
231
338
|
theme: style.theme,
|
|
232
339
|
logoURL: style.logoURL,
|
|
233
340
|
integrations: integrations,
|
|
234
|
-
columnMappingsAttributes: columnMappingsAttributes,
|
|
235
341
|
previewFirstTime: previewFirstTime,
|
|
236
342
|
headerRowIndex: headerRowIndex,
|
|
237
343
|
setHeaderRowIndex: setHeaderRowIndex,
|
|
@@ -253,6 +359,8 @@ export var ImporterContextProvider = function (_a) {
|
|
|
253
359
|
resetImporterWhenUsingManualImport: resetImporterWhenUsingManualImport,
|
|
254
360
|
manualDataImportSelected: manualDataImportSelected,
|
|
255
361
|
customActions: customActions,
|
|
362
|
+
headerMappingsLoaded: headerMappingsLoaded,
|
|
363
|
+
valueMappingsLoaded: valueMappingsLoaded,
|
|
256
364
|
};
|
|
257
365
|
return (_jsx(ImporterContext.Provider, __assign({ value: value }, { children: children })));
|
|
258
366
|
};
|
|
@@ -23,8 +23,7 @@ import { FieldTypes, } from "../../types";
|
|
|
23
23
|
import { parseValue } from "../common/Spreadsheet/common";
|
|
24
24
|
var MINIMUM_ROW_COUNT = 20;
|
|
25
25
|
var getRowId = function (index) {
|
|
26
|
-
|
|
27
|
-
return "r".concat(index, "-").concat(uniqueTimestamp);
|
|
26
|
+
return index.toString();
|
|
28
27
|
};
|
|
29
28
|
export var addEmptyRows = function (data, fields) {
|
|
30
29
|
var emptyRecord = fields.reduce(function (obj, f) {
|
|
@@ -43,7 +42,7 @@ export var addMeta = function (record, index, uploadedRow, transformedRow) {
|
|
|
43
42
|
if (transformedRow === void 0) { transformedRow = null; }
|
|
44
43
|
var rId = getRowId(index);
|
|
45
44
|
var meta = (_a = record._meta) !== null && _a !== void 0 ? _a : {};
|
|
46
|
-
return __assign(__assign({}, record), { _meta: __assign(__assign({}, meta), { id: rId, rowIndex: index,
|
|
45
|
+
return __assign(__assign({}, record), { _meta: __assign(__assign({}, meta), { id: rId, rowIndex: index, uploadedRow: uploadedRow, transformedRow: __assign(__assign({}, meta.transformedRow), transformedRow) }) });
|
|
47
46
|
};
|
|
48
47
|
export var recordListToDataSet = function (data, fields) {
|
|
49
48
|
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; });
|
|
@@ -119,7 +118,8 @@ export var transformToRecords = function (_a) {
|
|
|
119
118
|
export var getPreviewDataSet = function (_a) {
|
|
120
119
|
var uploadedData = _a.uploadedData;
|
|
121
120
|
var rowLen = 0;
|
|
122
|
-
|
|
121
|
+
var previewSize = Math.min(100, uploadedData.length);
|
|
122
|
+
for (var i = 0; i < previewSize; i++)
|
|
123
123
|
rowLen = Math.max(rowLen, uploadedData[i].length);
|
|
124
124
|
var fields = new Array(rowLen).fill(null).map(function (_, i) {
|
|
125
125
|
var key = String.fromCharCode(65 + i);
|
|
@@ -131,7 +131,9 @@ export var getPreviewDataSet = function (_a) {
|
|
|
131
131
|
};
|
|
132
132
|
});
|
|
133
133
|
var getInitialDataSet = function () {
|
|
134
|
-
var data = uploadedData
|
|
134
|
+
var data = uploadedData
|
|
135
|
+
.slice(0, previewSize)
|
|
136
|
+
.map(function (row, index) {
|
|
135
137
|
var entry = addMeta({}, index);
|
|
136
138
|
fields.forEach(function (field, index) {
|
|
137
139
|
entry[field.name] = row[index];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { useCallback } from "react";
|
|
13
|
+
import Papa from "papaparse";
|
|
14
|
+
import { useImporterContext } from "../contexts/ImporterContextProvider";
|
|
15
|
+
function downloadCsv(data, fileName) {
|
|
16
|
+
var blob = new Blob([data], { type: "text/csv;charset=utf-8;" });
|
|
17
|
+
var link = document.createElement("a");
|
|
18
|
+
link.href = URL.createObjectURL(blob);
|
|
19
|
+
link.download = fileName;
|
|
20
|
+
document.body.appendChild(link);
|
|
21
|
+
link.click();
|
|
22
|
+
document.body.removeChild(link);
|
|
23
|
+
}
|
|
24
|
+
function csvExport(data) {
|
|
25
|
+
var valuesWithQuotesWhenNecessary = data.map(function (obj) {
|
|
26
|
+
var newObj = {};
|
|
27
|
+
for (var key in obj) {
|
|
28
|
+
var value = obj[key];
|
|
29
|
+
newObj[key] =
|
|
30
|
+
typeof value === "string" && value.includes(",") ? "\"".concat(value, "\"") : value;
|
|
31
|
+
}
|
|
32
|
+
return newObj;
|
|
33
|
+
});
|
|
34
|
+
var csv = Papa.unparse(valuesWithQuotesWhenNecessary);
|
|
35
|
+
downloadCsv(csv, "export.csv");
|
|
36
|
+
}
|
|
37
|
+
export var useExportDataToFile = function () {
|
|
38
|
+
var selectedRows = useImporterContext().selectedRows;
|
|
39
|
+
var onExport = useCallback(function (dataSet, dataType) {
|
|
40
|
+
if (!dataSet)
|
|
41
|
+
return;
|
|
42
|
+
var dataSetValues = Object.values(dataSet);
|
|
43
|
+
if (dataType === "csv") {
|
|
44
|
+
var valuesWithoutMeta = dataSetValues.map(function (_a) {
|
|
45
|
+
var _meta = _a._meta, rest = __rest(_a, ["_meta"]);
|
|
46
|
+
return rest;
|
|
47
|
+
});
|
|
48
|
+
csvExport(valuesWithoutMeta);
|
|
49
|
+
}
|
|
50
|
+
}, [selectedRows]);
|
|
51
|
+
return {
|
|
52
|
+
onExport: onExport,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AppResponse, RecordDataSet } from "../../types";
|
|
2
|
+
export declare const useSubmitToServer: () => {
|
|
3
|
+
appResponse: AppResponse;
|
|
4
|
+
isSubmitting: boolean;
|
|
5
|
+
onSubmitToServer: (dataSet: RecordDataSet, afterSubmitCallback: (dataSet: RecordDataSet) => void) => Promise<void>;
|
|
6
|
+
importWasSuccessful: boolean;
|
|
7
|
+
};
|