fuse-importer 0.27.0 → 0.30.0
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.d.ts +2 -0
- package/lib/esm/Importer/ImporterWithContext.js +51 -13
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/index.js +2 -2
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/index.js +4 -3
- package/lib/esm/Importer/Matcher/HeaderMatcher/index.js +14 -9
- package/lib/esm/Importer/Matcher/index.js +0 -11
- package/lib/esm/Importer/PreviewFirstTime.js +1 -1
- package/lib/esm/Importer/Review/AppResponseModal.js +2 -2
- package/lib/esm/Importer/Review/ReviewContextProvider.d.ts +8 -6
- package/lib/esm/Importer/Review/ReviewContextProvider.js +72 -195
- 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 +36 -13
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterDropzone.d.ts +2 -1
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterDropzone.js +15 -64
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterSectionHeader/index.js +2 -2
- 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 +19 -0
- package/lib/esm/Importer/common/Spreadsheet/DuplicateDataContextProvider/index.js +155 -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 +38 -45
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.d.ts +7 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/hashCalculators.js +152 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.d.ts +7 -30
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/index.js +10 -141
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.d.ts +5 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useBatchProcessing.js +81 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.d.ts +5 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useDataSetManipulation.js +119 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useSpreadsheetFilter.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/utils.d.ts +1 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/utils.js +8 -0
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.d.ts +31 -0
- package/lib/esm/Importer/common/Spreadsheet/ValidationContextProvider/index.js +324 -0
- package/lib/esm/Importer/common/Spreadsheet/common/index.js +18 -9
- 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/FindAndReplace/index.d.ts +6 -0
- package/lib/esm/Importer/common/Spreadsheet/components/FindAndReplace/index.js +88 -0
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.js +25 -17
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.js +48 -47
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowNumbers.js +3 -3
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpeadsheetAutocomplete.d.ts +1 -0
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpeadsheetAutocomplete.js +7 -3
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpreadsheetInput.d.ts +3 -1
- package/lib/esm/Importer/common/Spreadsheet/components/fields/SpreadsheetInput.js +45 -11
- package/lib/esm/Importer/common/Spreadsheet/components/fields/index.d.ts +12 -5
- package/lib/esm/Importer/common/Spreadsheet/components/fields/index.js +81 -26
- package/lib/esm/Importer/common/Spreadsheet/components/fields/utils.d.ts +11 -0
- package/lib/esm/Importer/common/Spreadsheet/components/fields/utils.js +29 -0
- 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/transformation/index.d.ts +2 -2
- package/lib/esm/Importer/common/Spreadsheet/transformation/index.js +35 -13
- 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/index.d.ts +18 -0
- package/lib/esm/Importer/common/Spreadsheet/transformation/transformators/index.js +179 -0
- 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 +23 -7
- package/lib/esm/Importer/common/theme.d.ts +1 -0
- package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +13 -4
- package/lib/esm/Importer/contexts/ImporterContextProvider.js +150 -21
- package/lib/esm/Importer/data/index.d.ts +7 -3
- package/lib/esm/Importer/data/index.js +49 -20
- 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 +214 -0
- package/lib/esm/Importer/index.d.ts +4 -3
- package/lib/esm/Importer/index.js +2 -2
- package/lib/esm/common/CircleSpinner.d.ts +1 -0
- package/lib/esm/common/CircleSpinner.js +13 -0
- package/lib/esm/common/ConfirmationModal.js +1 -1
- 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 +143 -0
- package/lib/esm/common/FileUploadDropzone/index.d.ts +1 -0
- package/lib/esm/common/FileUploadDropzone/index.js +1 -0
- package/lib/esm/common/Modal.js +2 -2
- package/lib/esm/common/Table/TableActions/CustomActions/CustomActions.d.ts +1 -0
- package/lib/esm/common/Table/TableActions/CustomActions/CustomActions.js +150 -0
- package/lib/esm/common/Table/TableActions/CustomActions/index.d.ts +1 -0
- package/lib/esm/common/Table/TableActions/CustomActions/index.js +1 -0
- package/lib/esm/common/Table/TableActions/DeleteSelectedRows.js +25 -8
- package/lib/esm/common/Table/TableActions/ExportData.js +5 -3
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +41 -10
- package/lib/esm/common/Table/TableActions/RowFilters.js +63 -11
- package/lib/esm/common/Table/TableActions/SearchRows.js +28 -17
- package/lib/esm/common/Table/TableActions/TableActions.js +15 -4
- package/lib/esm/common/Table/TableActions/TableActions.styles.d.ts +1 -0
- package/lib/esm/common/Table/TableActions/TableActions.styles.js +4 -3
- package/lib/esm/common/Table/TableActions/TransformedRecordsCount.d.ts +6 -0
- package/lib/esm/common/Table/TableActions/TransformedRecordsCount.js +71 -0
- 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/TableActions/icons.d.ts +3 -0
- package/lib/esm/common/Table/TableActions/icons.js +3 -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.d.ts +1 -1
- package/lib/esm/common/Table/TableView/TableRows/TableRow.js +3 -3
- 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 +7 -16
- package/lib/esm/common/Table/TableView/types.d.ts +9 -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.d.ts +42 -3
- package/lib/esm/common/Toast.js +56 -18
- 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 +19 -13
- package/lib/esm/common/columnsTransformations.d.ts +1 -0
- package/lib/esm/common/columnsTransformations.js +10 -16
- package/lib/esm/common/columnsValidations.d.ts +0 -26
- package/lib/esm/common/columnsValidations.js +1 -31
- package/lib/esm/common/datePatterns.d.ts +26 -0
- package/lib/esm/common/datePatterns.js +327 -0
- package/lib/esm/common/icons/index.d.ts +4 -0
- package/lib/esm/common/icons/index.js +6 -2
- package/lib/esm/common/index.d.ts +2 -0
- package/lib/esm/common/index.js +2 -0
- 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/SelectMenu.d.ts +2 -1
- package/lib/esm/common/inputs/SelectMenu.js +14 -3
- package/lib/esm/common/inputs/TextInput.js +1 -1
- package/lib/esm/index.d.ts +3 -1
- package/lib/esm/index.js +9 -2
- package/lib/esm/locales/de.d.ts +13 -1
- package/lib/esm/locales/de.js +14 -2
- package/lib/esm/locales/en.d.ts +26 -1
- package/lib/esm/locales/en.js +30 -5
- package/lib/esm/locales/es.d.ts +13 -1
- package/lib/esm/locales/es.js +14 -2
- package/lib/esm/locales/fr.d.ts +13 -1
- package/lib/esm/locales/fr.js +14 -2
- 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/styled/theme/textCss.js +1 -1
- package/lib/esm/types.d.ts +48 -5
- package/lib/esm/types.js +0 -1
- package/lib/esm/utils/index.d.ts +1 -0
- package/lib/esm/utils/index.js +4 -0
- package/lib/main.js +24 -24
- package/lib/main.js.LICENSE.txt +2 -0
- package/package.json +8 -6
- package/lib/esm/Importer/Stepper/common/getEnumFieldValueMatchingsInitialValue.d.ts +0 -8
- package/lib/esm/Importer/Stepper/common/getEnumFieldValueMatchingsInitialValue.js +0 -33
- package/lib/esm/Importer/common/Spreadsheet/components/ValidationProgress.d.ts +0 -5
- package/lib/esm/Importer/common/Spreadsheet/components/ValidationProgress.js +0 -19
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/EmailInput.d.ts +0 -3
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/EmailInput.js +0 -14
- package/lib/esm/Importer/common/Spreadsheet/hooks.d.ts +0 -34
- package/lib/esm/Importer/common/Spreadsheet/hooks.js +0 -254
- package/lib/esm/Importer/common/Spreadsheet/transformation/transformators.d.ts +0 -8
- package/lib/esm/Importer/common/Spreadsheet/transformation/transformators.js +0 -106
- 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
- package/lib/esm/common/Table/TableView/CustomScrollbar.d.ts +0 -2
- package/lib/esm/common/Table/TableView/CustomScrollbar.js +0 -34
package/lib/main.js.LICENSE.txt
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fuse-importer",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.30.0",
|
|
5
5
|
"description": "Flatirons Fuse is a customizable and powerful CSV Importer that works with all front-end languages",
|
|
6
6
|
"browserslist": {
|
|
7
7
|
"production": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
]
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": "16.
|
|
19
|
+
"node": ">=16.0.0"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"dev": "webpack-dev-server --open --watch-files src",
|
|
@@ -40,13 +40,12 @@
|
|
|
40
40
|
"@types/styled-components": "^5.1.15",
|
|
41
41
|
"axios": "^0.21.4",
|
|
42
42
|
"color": "^4.2.3",
|
|
43
|
-
"
|
|
43
|
+
"eventemitter3": "^5.0.1",
|
|
44
44
|
"i18next": "^22.4.13",
|
|
45
45
|
"luxon": "^2.2.0",
|
|
46
46
|
"openai": "^3.2.1",
|
|
47
47
|
"papaparse": "^5.4.1",
|
|
48
48
|
"qs": "^6.10.1",
|
|
49
|
-
"react-custom-scrollbars": "^4.2.1",
|
|
50
49
|
"react-dropzone": "^11.3.2",
|
|
51
50
|
"react-helmet": "^6.1.0",
|
|
52
51
|
"react-hot-toast": "^2.1.1",
|
|
@@ -55,11 +54,13 @@
|
|
|
55
54
|
"react-virtualized-auto-sizer": "^1.0.6",
|
|
56
55
|
"react-window": "^1.8.7",
|
|
57
56
|
"styled-components": "^5.3.0",
|
|
57
|
+
"xlsx": "^0.18.5",
|
|
58
58
|
"yup": "0.32.9"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@testing-library/jest-dom": "^5.16.5",
|
|
62
62
|
"@testing-library/react": "^13.3.0",
|
|
63
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
63
64
|
"@types/jest": "^28.1.7",
|
|
64
65
|
"@types/node": "^12.x",
|
|
65
66
|
"@types/react": "^17.x",
|
|
@@ -70,10 +71,11 @@
|
|
|
70
71
|
"@types/testing-library__jest-dom": "^5.14.5",
|
|
71
72
|
"@types/testing-library__react": "^10.2.0",
|
|
72
73
|
"dotenv": "^16.0.3",
|
|
73
|
-
"react": "^17.x",
|
|
74
|
-
"react-dom": "^17.x",
|
|
75
74
|
"html-webpack-plugin": "^5.5.0",
|
|
76
75
|
"jest": "^28.1.3",
|
|
76
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
77
|
+
"react": "^17.x",
|
|
78
|
+
"react-dom": "^17.x",
|
|
77
79
|
"terser-webpack-plugin": "^5.1.2",
|
|
78
80
|
"ts-jest": "^28.0.8",
|
|
79
81
|
"ts-loader": "^9.2.2",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TemplateHeader } from "../../../types";
|
|
2
|
-
import { EnumFieldValueMatchings, UploadedDataEnumFieldValues } from "../../contexts/ImporterContextProvider";
|
|
3
|
-
type GetEnumFieldValueMatchingsInitialValueArgs = {
|
|
4
|
-
uploadedDataEnumFieldValues: UploadedDataEnumFieldValues;
|
|
5
|
-
templateHeaders: TemplateHeader[];
|
|
6
|
-
};
|
|
7
|
-
export declare const getEnumFieldValueMatchingsInitialValue: ({ uploadedDataEnumFieldValues, templateHeaders, }: GetEnumFieldValueMatchingsInitialValueArgs) => EnumFieldValueMatchings;
|
|
8
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
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 Fuse from "fuse.js";
|
|
13
|
-
import { fusejsOptions, } from "../../contexts/ImporterContextProvider";
|
|
14
|
-
export var getEnumFieldValueMatchingsInitialValue = function (_a) {
|
|
15
|
-
var uploadedDataEnumFieldValues = _a.uploadedDataEnumFieldValues, templateHeaders = _a.templateHeaders;
|
|
16
|
-
var res = {};
|
|
17
|
-
var setEnumFieldValueMathings = function (templateLabel) {
|
|
18
|
-
uploadedDataEnumFieldValues[templateLabel].forEach(function (uploadedValue, _index) {
|
|
19
|
-
var _a, _b;
|
|
20
|
-
var templateOptions = (_a = templateHeaders.find(function (th) { return th.label === templateLabel; })) === null || _a === void 0 ? void 0 : _a.values;
|
|
21
|
-
var fuse = new Fuse(templateOptions, fusejsOptions);
|
|
22
|
-
var fuseResults = fuse.search(uploadedValue);
|
|
23
|
-
var previousRes = __assign({}, (res[templateLabel] || {}));
|
|
24
|
-
res[templateLabel] = previousRes;
|
|
25
|
-
res[templateLabel][uploadedValue] = (_b = fuseResults[0]) === null || _b === void 0 ? void 0 : _b.item;
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var templateLabels = Object.keys(uploadedDataEnumFieldValues);
|
|
29
|
-
templateLabels.forEach(function (templateLabel) {
|
|
30
|
-
setEnumFieldValueMathings(templateLabel);
|
|
31
|
-
});
|
|
32
|
-
return res;
|
|
33
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
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 { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import { colors } from "../../../../styled/theme/colorPalette";
|
|
14
|
-
import { Div } from "../../../../styled/utils";
|
|
15
|
-
var ValidationProgress = function (_a) {
|
|
16
|
-
var totalErrors = _a.totalErrors, validationPercentage = _a.validationPercentage;
|
|
17
|
-
return (_jsxs(Div, __assign({ body1: true, dflex: true, ml: 32, mb: 22 }, { children: ["Calculating Data...", _jsxs(Div, __assign({ bold: true, ml: 5 }, { children: [validationPercentage, "%"] })), _jsxs(Div, __assign({ bold: true, c: colors.error, ml: 5 }, { children: ["(", totalErrors, " errors)"] }))] })));
|
|
18
|
-
};
|
|
19
|
-
export default ValidationProgress;
|
|
@@ -1,14 +0,0 @@
|
|
|
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 { SpreadsheetInput, } from "../fields/SpreadsheetInput";
|
|
14
|
-
export var EmailInput = function (props) { return (_jsx(SpreadsheetInput, __assign({}, props, { type: "email" }))); };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { SpreadsheetOptions } from "../../..";
|
|
3
|
-
import { DeleteRecords } from "../../../common/Table/TableActions/hooks";
|
|
4
|
-
import { BatchValidationErrors, Field, OnValidateRecord, Record, RecordDataSet } from "../../../types";
|
|
5
|
-
type UseValidationStateArgs = {
|
|
6
|
-
onValidateRecord?: OnValidateRecord;
|
|
7
|
-
setDataSet: React.Dispatch<React.SetStateAction<RecordDataSet>>;
|
|
8
|
-
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
|
|
9
|
-
initialDataSet: RecordDataSet;
|
|
10
|
-
dataSet: RecordDataSet;
|
|
11
|
-
fields: Field[];
|
|
12
|
-
options: SpreadsheetOptions;
|
|
13
|
-
isReadOnly: boolean;
|
|
14
|
-
};
|
|
15
|
-
export type ValidationState = {
|
|
16
|
-
isValid: boolean;
|
|
17
|
-
isValidationCompleted: boolean;
|
|
18
|
-
validationPercentage: number;
|
|
19
|
-
errors: BatchValidationErrors;
|
|
20
|
-
warnings: BatchValidationErrors;
|
|
21
|
-
totalErrors: number;
|
|
22
|
-
columnErrorCounts: {
|
|
23
|
-
[column: string]: number;
|
|
24
|
-
};
|
|
25
|
-
columnWarningCounts: {
|
|
26
|
-
[column: string]: number;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
type UseValidationStateReturnValue = ValidationState & {
|
|
30
|
-
deleteRecords: DeleteRecords;
|
|
31
|
-
updateRecordAndRevalidate: (record: Record) => Promise<void>;
|
|
32
|
-
};
|
|
33
|
-
export declare const useValidationState: ({ initialDataSet, dataSet, fields, options, isReadOnly, setDataSet, setIsLoading, onValidateRecord, }: UseValidationStateArgs) => UseValidationStateReturnValue;
|
|
34
|
-
export {};
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import { omit, set } from "lodash";
|
|
49
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
50
|
-
import { useTableActions, } from "../../../common/Table/TableActions/hooks";
|
|
51
|
-
import { selectValidatorsFor, validateRecord } from "./validation";
|
|
52
|
-
import { useAppLoadingContext } from "../../../common/AppLoadingContextProvider";
|
|
53
|
-
var checkIfHasErrors = function (errors) {
|
|
54
|
-
return errors && Object.keys(errors).length > 0;
|
|
55
|
-
};
|
|
56
|
-
export var useValidationState = function (_a) {
|
|
57
|
-
var initialDataSet = _a.initialDataSet, //Initial Data Set, used to run the initial validation
|
|
58
|
-
dataSet = _a.dataSet, //Current Updated Data Set
|
|
59
|
-
fields = _a.fields, options = _a.options, isReadOnly = _a.isReadOnly, setDataSet = _a.setDataSet, setIsLoading = _a.setIsLoading, onValidateRecord = _a.onValidateRecord;
|
|
60
|
-
var _b = useState({}), errors = _b[0], setErrors = _b[1];
|
|
61
|
-
var _c = useState({}), warnings = _c[0], setWarnings = _c[1];
|
|
62
|
-
var _d = useState(0), validationPercentage = _d[0], setValidationPercentage = _d[1];
|
|
63
|
-
var validatorsCache = useMemo(function () { return selectValidatorsFor(fields); }, [fields]);
|
|
64
|
-
var setIsLoadingApp = useAppLoadingContext().setIsLoadingApp;
|
|
65
|
-
var deleteRecords = useTableActions({
|
|
66
|
-
setDataSet: setDataSet,
|
|
67
|
-
setErrors: setErrors,
|
|
68
|
-
setWarnings: setWarnings,
|
|
69
|
-
}).deleteRecords;
|
|
70
|
-
// Validate record and update dataSet
|
|
71
|
-
var updateRecordAndRevalidate = useCallback(function (record) { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
-
var recordId, newDataSet, data, _a, recordErrors, recordWarnings, hasError, hasWarning;
|
|
73
|
-
var _b;
|
|
74
|
-
return __generator(this, function (_c) {
|
|
75
|
-
switch (_c.label) {
|
|
76
|
-
case 0:
|
|
77
|
-
recordId = record._meta.id;
|
|
78
|
-
newDataSet = __assign(__assign({}, dataSet), (_b = {}, _b[recordId] = __assign({}, record), _b));
|
|
79
|
-
// 'touched' should be set before validation
|
|
80
|
-
newDataSet[recordId]._meta.touched = true;
|
|
81
|
-
data = Object.values(newDataSet);
|
|
82
|
-
return [4 /*yield*/, validateRecord({
|
|
83
|
-
validatorsCache: validatorsCache,
|
|
84
|
-
onValidateRecord: onValidateRecord,
|
|
85
|
-
data: data,
|
|
86
|
-
fields: fields,
|
|
87
|
-
record: record,
|
|
88
|
-
})];
|
|
89
|
-
case 1:
|
|
90
|
-
_a = _c.sent(), recordErrors = _a.errors, recordWarnings = _a.warnings;
|
|
91
|
-
hasError = checkIfHasErrors(recordErrors);
|
|
92
|
-
hasWarning = checkIfHasErrors(recordWarnings);
|
|
93
|
-
newDataSet[recordId]._meta.isInvalid = hasError;
|
|
94
|
-
newDataSet[recordId]._meta.hasWarning = hasWarning;
|
|
95
|
-
setErrors(function (errors) {
|
|
96
|
-
var newErrors = __assign({}, errors);
|
|
97
|
-
var newState = hasError
|
|
98
|
-
? set(newErrors, recordId, recordErrors)
|
|
99
|
-
: omit(newErrors, recordId);
|
|
100
|
-
return newState;
|
|
101
|
-
});
|
|
102
|
-
setWarnings(function (warnings) {
|
|
103
|
-
var newWarnings = __assign({}, warnings);
|
|
104
|
-
var newState = hasWarning
|
|
105
|
-
? set(newWarnings, recordId, recordWarnings)
|
|
106
|
-
: omit(newWarnings, recordId);
|
|
107
|
-
return newState;
|
|
108
|
-
});
|
|
109
|
-
setDataSet(newDataSet); //Update the dataSet
|
|
110
|
-
return [2 /*return*/];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}); }, [dataSet, validatorsCache]);
|
|
114
|
-
// Initial data validation and update dataSet
|
|
115
|
-
useEffect(function () {
|
|
116
|
-
if (!initialDataSet || isReadOnly)
|
|
117
|
-
return;
|
|
118
|
-
var isCancelled = false;
|
|
119
|
-
setIsLoading(true);
|
|
120
|
-
var initialValidation = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
121
|
-
var errors, warnings, initialData, length, _a, batchValidationDelayMs, _b, batchValidationSize, batchSize, batchCount, batchIdx, idx, batch, index, record, recordId, _c, recordErrors, recordWarnings, hasError, hasWarning, validationPercentage_1;
|
|
122
|
-
return __generator(this, function (_d) {
|
|
123
|
-
switch (_d.label) {
|
|
124
|
-
case 0:
|
|
125
|
-
errors = {};
|
|
126
|
-
warnings = {};
|
|
127
|
-
initialData = Object.values(initialDataSet);
|
|
128
|
-
length = initialData.length;
|
|
129
|
-
_a = options.batchValidationDelayMs, batchValidationDelayMs = _a === void 0 ? 400 : _a, _b = options.batchValidationSize, batchValidationSize = _b === void 0 ? length : _b;
|
|
130
|
-
batchSize = Math.min(Math.floor(batchValidationSize), length) || length;
|
|
131
|
-
batchCount = Math.ceil(length / batchSize);
|
|
132
|
-
batchIdx = 0;
|
|
133
|
-
_d.label = 1;
|
|
134
|
-
case 1:
|
|
135
|
-
if (!(batchIdx < batchCount)) return [3 /*break*/, 8];
|
|
136
|
-
if (isCancelled)
|
|
137
|
-
return [2 /*return*/];
|
|
138
|
-
idx = batchIdx * batchSize;
|
|
139
|
-
batch = initialData.slice(idx, idx + batchSize);
|
|
140
|
-
index = 0;
|
|
141
|
-
_d.label = 2;
|
|
142
|
-
case 2:
|
|
143
|
-
if (!(index < batch.length)) return [3 /*break*/, 5];
|
|
144
|
-
if (isCancelled)
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
record = batch[index];
|
|
147
|
-
recordId = record._meta.id;
|
|
148
|
-
return [4 /*yield*/, validateRecord({
|
|
149
|
-
onValidateRecord: onValidateRecord,
|
|
150
|
-
data: initialData,
|
|
151
|
-
fields: fields,
|
|
152
|
-
record: record,
|
|
153
|
-
validatorsCache: validatorsCache,
|
|
154
|
-
})];
|
|
155
|
-
case 3:
|
|
156
|
-
_c = _d.sent(), recordErrors = _c.errors, recordWarnings = _c.warnings;
|
|
157
|
-
hasError = checkIfHasErrors(recordErrors);
|
|
158
|
-
hasWarning = checkIfHasErrors(recordWarnings);
|
|
159
|
-
record._meta.isInvalid = hasError;
|
|
160
|
-
record._meta.hasWarning = hasWarning;
|
|
161
|
-
if (hasError)
|
|
162
|
-
errors[recordId] = recordErrors;
|
|
163
|
-
if (hasWarning)
|
|
164
|
-
warnings[recordId] = recordWarnings;
|
|
165
|
-
_d.label = 4;
|
|
166
|
-
case 4:
|
|
167
|
-
index++;
|
|
168
|
-
return [3 /*break*/, 2];
|
|
169
|
-
case 5:
|
|
170
|
-
validationPercentage_1 = (Math.min(idx + batchSize, initialData.length) / initialData.length) *
|
|
171
|
-
100;
|
|
172
|
-
setValidationPercentage(Math.round((validationPercentage_1 + Number.EPSILON) * 10) / 10);
|
|
173
|
-
return [4 /*yield*/, sleep(batchValidationDelayMs)];
|
|
174
|
-
case 6:
|
|
175
|
-
_d.sent();
|
|
176
|
-
setErrors(errors);
|
|
177
|
-
setWarnings(warnings);
|
|
178
|
-
_d.label = 7;
|
|
179
|
-
case 7:
|
|
180
|
-
batchIdx++;
|
|
181
|
-
return [3 /*break*/, 1];
|
|
182
|
-
case 8: return [2 /*return*/];
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}); };
|
|
186
|
-
var sleep = function (n) { return new Promise(function (resolve) { return setTimeout(resolve, n); }); };
|
|
187
|
-
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
188
|
-
return __generator(this, function (_a) {
|
|
189
|
-
switch (_a.label) {
|
|
190
|
-
case 0:
|
|
191
|
-
setIsLoadingApp(true);
|
|
192
|
-
if (!(Object.values(initialDataSet).length > 10000)) return [3 /*break*/, 2];
|
|
193
|
-
// wait for the first render to complete before blocking main thread with review step logic
|
|
194
|
-
return [4 /*yield*/, sleep(200)];
|
|
195
|
-
case 1:
|
|
196
|
-
// wait for the first render to complete before blocking main thread with review step logic
|
|
197
|
-
_a.sent();
|
|
198
|
-
_a.label = 2;
|
|
199
|
-
case 2: return [4 /*yield*/, initialValidation()];
|
|
200
|
-
case 3:
|
|
201
|
-
_a.sent();
|
|
202
|
-
if (!isCancelled)
|
|
203
|
-
setIsLoading(false);
|
|
204
|
-
setIsLoadingApp(false);
|
|
205
|
-
return [2 /*return*/];
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}); })();
|
|
209
|
-
return function () {
|
|
210
|
-
isCancelled = true;
|
|
211
|
-
};
|
|
212
|
-
}, [initialDataSet]);
|
|
213
|
-
var columnErrorCounts = useMemo(function () {
|
|
214
|
-
return Object.keys(errors).reduce(function (errorsByColumns, rowId) {
|
|
215
|
-
var recordErrors = errors[rowId];
|
|
216
|
-
return Object.keys(recordErrors).reduce(function (internalErrorsByColumns, fieldKey) {
|
|
217
|
-
var _a;
|
|
218
|
-
var hasError = !!recordErrors[fieldKey];
|
|
219
|
-
var count = (_a = internalErrorsByColumns[fieldKey]) !== null && _a !== void 0 ? _a : 0;
|
|
220
|
-
internalErrorsByColumns[fieldKey] = hasError ? count + 1 : count;
|
|
221
|
-
return internalErrorsByColumns;
|
|
222
|
-
}, errorsByColumns);
|
|
223
|
-
}, {});
|
|
224
|
-
}, [errors]);
|
|
225
|
-
var columnWarningCounts = useMemo(function () {
|
|
226
|
-
return Object.keys(warnings).reduce(function (errorsByColumns, rowId) {
|
|
227
|
-
var recordWarnings = warnings[rowId];
|
|
228
|
-
return Object.keys(recordWarnings).reduce(function (internalErrorsByColumns, fieldKey) {
|
|
229
|
-
var _a;
|
|
230
|
-
var hasError = !!recordWarnings[fieldKey];
|
|
231
|
-
var count = (_a = internalErrorsByColumns[fieldKey]) !== null && _a !== void 0 ? _a : 0;
|
|
232
|
-
internalErrorsByColumns[fieldKey] = hasError ? count + 1 : count;
|
|
233
|
-
return internalErrorsByColumns;
|
|
234
|
-
}, errorsByColumns);
|
|
235
|
-
}, {});
|
|
236
|
-
}, [warnings]);
|
|
237
|
-
var totalErrors = useMemo(function () {
|
|
238
|
-
return Object.keys(columnErrorCounts).reduce(function (count, column) { return count + columnErrorCounts[column]; }, 0);
|
|
239
|
-
}, [columnErrorCounts]);
|
|
240
|
-
var isValidationCompleted = validationPercentage === 100;
|
|
241
|
-
var isValid = isValidationCompleted && totalErrors === 0;
|
|
242
|
-
return {
|
|
243
|
-
errors: errors,
|
|
244
|
-
warnings: warnings,
|
|
245
|
-
totalErrors: totalErrors,
|
|
246
|
-
columnErrorCounts: columnErrorCounts,
|
|
247
|
-
columnWarningCounts: columnWarningCounts,
|
|
248
|
-
validationPercentage: validationPercentage,
|
|
249
|
-
isValidationCompleted: isValidationCompleted,
|
|
250
|
-
isValid: isValid,
|
|
251
|
-
updateRecordAndRevalidate: updateRecordAndRevalidate,
|
|
252
|
-
deleteRecords: deleteRecords,
|
|
253
|
-
};
|
|
254
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Field, FieldTransformation } from "../../../../types";
|
|
2
|
-
export type FieldValidator = (fieldValue: any, transformation?: FieldTransformation, fieldOptions?: Field) => null | any;
|
|
3
|
-
export type FieldTransformations = Partial<{
|
|
4
|
-
[key: string]: FieldValidator;
|
|
5
|
-
}>;
|
|
6
|
-
export declare const fieldTransformations: {
|
|
7
|
-
[x: string]: FieldValidator;
|
|
8
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
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 { DateTime } from "luxon";
|
|
13
|
-
var stringFieldTransformations = {
|
|
14
|
-
sentence_case: function (fieldValue) {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
if (typeof fieldValue !== "string")
|
|
17
|
-
return fieldValue;
|
|
18
|
-
return (((_b = (_a = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.toLowerCase()) === null || _a === void 0 ? void 0 : _a.charAt(0)) === null || _b === void 0 ? void 0 : _b.toUpperCase()) +
|
|
19
|
-
(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.slice(1).toLowerCase()));
|
|
20
|
-
},
|
|
21
|
-
capitalize: function (fieldValue) {
|
|
22
|
-
var _a;
|
|
23
|
-
if (typeof fieldValue !== "string")
|
|
24
|
-
return fieldValue;
|
|
25
|
-
return ((_a = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.charAt(0)) === null || _a === void 0 ? void 0 : _a.toUpperCase()) + (fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.slice(1));
|
|
26
|
-
},
|
|
27
|
-
uppercase: function (fieldValue) {
|
|
28
|
-
if (typeof fieldValue !== "string")
|
|
29
|
-
return fieldValue;
|
|
30
|
-
return fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.toUpperCase();
|
|
31
|
-
},
|
|
32
|
-
lowercase: function (fieldValue) {
|
|
33
|
-
if (typeof fieldValue !== "string")
|
|
34
|
-
return fieldValue;
|
|
35
|
-
return fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.toLowerCase();
|
|
36
|
-
},
|
|
37
|
-
trim_whitespace: function (fieldValue) {
|
|
38
|
-
if (typeof fieldValue !== "string")
|
|
39
|
-
return fieldValue;
|
|
40
|
-
return fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.trim();
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
var datesDateTimesAndTimesTransformations = {
|
|
44
|
-
autoformat: function (fieldValue, _, fieldOptions) {
|
|
45
|
-
var JSDate = new Date(fieldValue);
|
|
46
|
-
if (!fieldValue || isNaN(JSDate.getTime())) {
|
|
47
|
-
return fieldValue;
|
|
48
|
-
}
|
|
49
|
-
var luxonDate = DateTime.fromJSDate(JSDate);
|
|
50
|
-
return luxonDate.toFormat(fieldOptions.pattern);
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
var urlTransformations = {
|
|
54
|
-
prefix: function (fieldValue, transformation) {
|
|
55
|
-
var _a;
|
|
56
|
-
var prefixValue = (_a = transformation === null || transformation === void 0 ? void 0 : transformation.options) === null || _a === void 0 ? void 0 : _a.prefix;
|
|
57
|
-
if (!prefixValue)
|
|
58
|
-
return fieldValue;
|
|
59
|
-
return "".concat(prefixValue).concat(fieldValue);
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
var floatTransformations = {
|
|
63
|
-
number_of_decimals: function (fieldValue, transformation) {
|
|
64
|
-
var _a;
|
|
65
|
-
var numberOfDecimalsValue = Number((_a = transformation === null || transformation === void 0 ? void 0 : transformation.options) === null || _a === void 0 ? void 0 : _a.number_of_decimals);
|
|
66
|
-
if (isNaN(numberOfDecimalsValue) || isNaN(fieldValue))
|
|
67
|
-
return fieldValue;
|
|
68
|
-
return Number(fieldValue.toFixed(numberOfDecimalsValue));
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
var integerTransformations = {
|
|
72
|
-
round: function (fieldValue) {
|
|
73
|
-
if (isNaN(fieldValue))
|
|
74
|
-
return fieldValue;
|
|
75
|
-
return Math.round(fieldValue);
|
|
76
|
-
},
|
|
77
|
-
floor: function (fieldValue) {
|
|
78
|
-
if (isNaN(fieldValue))
|
|
79
|
-
return fieldValue;
|
|
80
|
-
return Math.floor(fieldValue);
|
|
81
|
-
},
|
|
82
|
-
ceiling: function (fieldValue) {
|
|
83
|
-
if (isNaN(fieldValue))
|
|
84
|
-
return fieldValue;
|
|
85
|
-
return Math.ceil(fieldValue);
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
var enumTransformations = {
|
|
89
|
-
autodetect: function (fieldValue, _, fieldOptions) {
|
|
90
|
-
var options = fieldOptions.options.map(function (option) {
|
|
91
|
-
return option.toLowerCase();
|
|
92
|
-
});
|
|
93
|
-
if (!fieldValue || options.length === 0)
|
|
94
|
-
return fieldValue;
|
|
95
|
-
var parsedRecord = String(fieldValue).toLowerCase();
|
|
96
|
-
var trueOptionIndex = options.findIndex(function (option) { return option === "true" || option === "1"; });
|
|
97
|
-
var falseOptionIndex = options.findIndex(function (option) { return option === "false" || option === "0"; });
|
|
98
|
-
if (trueOptionIndex !== -1 && falseOptionIndex !== -1) {
|
|
99
|
-
return parsedRecord === options[trueOptionIndex]
|
|
100
|
-
? fieldOptions.options[trueOptionIndex]
|
|
101
|
-
: fieldOptions.options[falseOptionIndex];
|
|
102
|
-
}
|
|
103
|
-
return fieldOptions.options[0];
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
export var fieldTransformations = __assign(__assign(__assign(__assign(__assign(__assign({}, stringFieldTransformations), datesDateTimesAndTimesTransformations), urlTransformations), floatTransformations), integerTransformations), enumTransformations);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Field, BatchValidationErrors } from "../../../../types";
|
|
2
|
-
type UniqueError = {
|
|
3
|
-
fieldName: string;
|
|
4
|
-
};
|
|
5
|
-
type Error = {
|
|
6
|
-
value: string;
|
|
7
|
-
label: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const getUniqueErrors: (fields: Field[], errors: BatchValidationErrors) => UniqueError[];
|
|
10
|
-
export declare const formatErrors: (fields: Field[], uniqueErrors: any) => Error[];
|
|
11
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export var getUniqueErrors = function (fields, errors) {
|
|
2
|
-
var fieldKeys = new Set(fields.map(function (field) { return field.name; }));
|
|
3
|
-
var uniqueErrors = [];
|
|
4
|
-
for (var _i = 0, _a = Object.entries(errors); _i < _a.length; _i++) {
|
|
5
|
-
var _b = _a[_i], _1 = _b[0], errorObj = _b[1];
|
|
6
|
-
for (var _c = 0, _d = Object.entries(errorObj); _c < _d.length; _c++) {
|
|
7
|
-
var fieldName = _d[_c][0];
|
|
8
|
-
if (fieldKeys.has(fieldName)) {
|
|
9
|
-
uniqueErrors.push({ fieldName: fieldName });
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return uniqueErrors;
|
|
14
|
-
};
|
|
15
|
-
export var formatErrors = function (fields, uniqueErrors) {
|
|
16
|
-
var errorMap = new Map();
|
|
17
|
-
var orderedErrorArray = [];
|
|
18
|
-
fields.forEach(function (field) {
|
|
19
|
-
errorMap.set(field.name, field);
|
|
20
|
-
});
|
|
21
|
-
fields.forEach(function (field) {
|
|
22
|
-
var name = field.name, label = field.label;
|
|
23
|
-
if (uniqueErrors.some(function (_a) {
|
|
24
|
-
var fieldName = _a.fieldName;
|
|
25
|
-
return fieldName === name;
|
|
26
|
-
}) &&
|
|
27
|
-
!orderedErrorArray.some(function (error) { return error.value === name; })) {
|
|
28
|
-
orderedErrorArray.push({
|
|
29
|
-
value: name,
|
|
30
|
-
label: label,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return orderedErrorArray;
|
|
35
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { BatchValidationErrors, Field, RecordDataSet } from "../../../types";
|
|
3
|
-
interface UseTableActionsProps {
|
|
4
|
-
setErrors: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
|
|
5
|
-
setWarnings: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
|
|
6
|
-
}
|
|
7
|
-
export type DeleteRecords = (selectedRecords: string[], errors: BatchValidationErrors, warnings: BatchValidationErrors) => void;
|
|
8
|
-
export type FilterRecordsBySearchValue = (obj: RecordDataSet, value: string, fields: Field[]) => RecordDataSet;
|
|
9
|
-
export type FilterRecordsByError = (obj: RecordDataSet, keyToFilter: string, errors: BatchValidationErrors, fields: Field[]) => RecordDataSet;
|
|
10
|
-
interface UseTableActionsProps {
|
|
11
|
-
setErrors: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
|
|
12
|
-
setWarnings: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
|
|
13
|
-
setDataSet: React.Dispatch<React.SetStateAction<RecordDataSet>>;
|
|
14
|
-
}
|
|
15
|
-
export declare const useTableActions: ({ setDataSet, setErrors, setWarnings, }: UseTableActionsProps) => {
|
|
16
|
-
deleteRecords: (selectedRecords: string[], errors: BatchValidationErrors, warnings: BatchValidationErrors) => void;
|
|
17
|
-
};
|
|
18
|
-
export {};
|