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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fuse-importer",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5-testing",
|
|
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": [
|
|
@@ -40,7 +40,7 @@
|
|
|
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",
|
|
@@ -60,6 +60,7 @@
|
|
|
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,36 +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
|
-
var fusejsOptions = {
|
|
14
|
-
includeScore: true,
|
|
15
|
-
threshold: 0.35,
|
|
16
|
-
};
|
|
17
|
-
export var getEnumFieldValueMatchingsInitialValue = function (_a) {
|
|
18
|
-
var uploadedDataEnumFieldValues = _a.uploadedDataEnumFieldValues, templateHeaders = _a.templateHeaders;
|
|
19
|
-
var res = {};
|
|
20
|
-
var setEnumFieldValueMathings = function (templateLabel) {
|
|
21
|
-
uploadedDataEnumFieldValues[templateLabel].forEach(function (uploadedValue, _index) {
|
|
22
|
-
var _a, _b;
|
|
23
|
-
var templateOptions = (_a = templateHeaders.find(function (th) { return th.label === templateLabel; })) === null || _a === void 0 ? void 0 : _a.values;
|
|
24
|
-
var fuzzySearch = new Fuse(templateOptions, fusejsOptions);
|
|
25
|
-
var fuzzySearchResults = fuzzySearch.search(uploadedValue);
|
|
26
|
-
var previousRes = __assign({}, (res[templateLabel] || {}));
|
|
27
|
-
res[templateLabel] = previousRes;
|
|
28
|
-
res[templateLabel][uploadedValue] = (_b = fuzzySearchResults[0]) === null || _b === void 0 ? void 0 : _b.item;
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
var templateLabels = Object.keys(uploadedDataEnumFieldValues);
|
|
32
|
-
templateLabels.forEach(function (templateLabel) {
|
|
33
|
-
setEnumFieldValueMathings(templateLabel);
|
|
34
|
-
});
|
|
35
|
-
return res;
|
|
36
|
-
};
|
|
@@ -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,33 +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
|
-
initialDataSet: RecordDataSet;
|
|
9
|
-
dataSet: RecordDataSet;
|
|
10
|
-
fields: Field[];
|
|
11
|
-
options: SpreadsheetOptions;
|
|
12
|
-
isReadOnly: boolean;
|
|
13
|
-
};
|
|
14
|
-
export type ValidationState = {
|
|
15
|
-
isValid: boolean;
|
|
16
|
-
isValidationCompleted: boolean;
|
|
17
|
-
validationPercentage: number;
|
|
18
|
-
errors: BatchValidationErrors;
|
|
19
|
-
warnings: BatchValidationErrors;
|
|
20
|
-
totalErrors: number;
|
|
21
|
-
columnErrorCounts: {
|
|
22
|
-
[column: string]: number;
|
|
23
|
-
};
|
|
24
|
-
columnWarningCounts: {
|
|
25
|
-
[column: string]: number;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
type UseValidationStateReturnValue = ValidationState & {
|
|
29
|
-
deleteRecords: DeleteRecords;
|
|
30
|
-
updateRecordAndRevalidate: (record: Record) => Promise<void>;
|
|
31
|
-
};
|
|
32
|
-
export declare const useValidationState: ({ initialDataSet, dataSet, fields, options, isReadOnly, setDataSet, onValidateRecord, }: UseValidationStateArgs) => UseValidationStateReturnValue;
|
|
33
|
-
export {};
|
|
@@ -1,256 +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 { useCallback, useEffect, useMemo, useState } from "react";
|
|
49
|
-
import { useTableActions, } from "../../../common/Table/TableActions/hooks";
|
|
50
|
-
import { selectValidatorsFor, validateRecord } from "./validation";
|
|
51
|
-
import { useAppLoadingContext } from "../../../common/AppLoadingContextProvider";
|
|
52
|
-
var checkIfHasErrors = function (errors) {
|
|
53
|
-
return errors && Object.keys(errors).length > 0;
|
|
54
|
-
};
|
|
55
|
-
export var useValidationState = function (_a) {
|
|
56
|
-
var initialDataSet = _a.initialDataSet, //Initial Data Set, used to run the initial validation
|
|
57
|
-
dataSet = _a.dataSet, //Current Updated Data Set
|
|
58
|
-
fields = _a.fields, options = _a.options, isReadOnly = _a.isReadOnly, setDataSet = _a.setDataSet, onValidateRecord = _a.onValidateRecord;
|
|
59
|
-
var _b = useState({}), errors = _b[0], setErrors = _b[1];
|
|
60
|
-
var _c = useState({}), warnings = _c[0], setWarnings = _c[1];
|
|
61
|
-
var _d = useState(0), validationPercentage = _d[0], setValidationPercentage = _d[1];
|
|
62
|
-
var validatorsCache = useMemo(function () { return selectValidatorsFor(fields); }, [fields]);
|
|
63
|
-
var setIsLoadingApp = useAppLoadingContext().setIsLoadingApp;
|
|
64
|
-
var deleteRecords = useTableActions({
|
|
65
|
-
setDataSet: setDataSet,
|
|
66
|
-
setErrors: setErrors,
|
|
67
|
-
setWarnings: setWarnings,
|
|
68
|
-
}).deleteRecords;
|
|
69
|
-
// Validate record and update dataSet
|
|
70
|
-
var updateRecordAndRevalidate = useCallback(function (records) { return __awaiter(void 0, void 0, void 0, function () {
|
|
71
|
-
var recordsArray, newDataSet, newErrors, newWarnings, i, record, recordId, data, _a, recordErrors, recordWarnings, hasError, hasWarning;
|
|
72
|
-
return __generator(this, function (_b) {
|
|
73
|
-
switch (_b.label) {
|
|
74
|
-
case 0:
|
|
75
|
-
recordsArray = Array.isArray(records) ? records : [records];
|
|
76
|
-
newDataSet = __assign({}, dataSet);
|
|
77
|
-
newErrors = __assign({}, errors);
|
|
78
|
-
newWarnings = __assign({}, warnings);
|
|
79
|
-
i = 0;
|
|
80
|
-
_b.label = 1;
|
|
81
|
-
case 1:
|
|
82
|
-
if (!(i < recordsArray.length)) return [3 /*break*/, 4];
|
|
83
|
-
record = recordsArray[i];
|
|
84
|
-
recordId = record._meta.id;
|
|
85
|
-
newDataSet[recordId] = __assign({}, record);
|
|
86
|
-
// 'touched' should be set before validation
|
|
87
|
-
newDataSet[recordId]._meta.touched = true;
|
|
88
|
-
data = Object.values(newDataSet);
|
|
89
|
-
return [4 /*yield*/, validateRecord({
|
|
90
|
-
validatorsCache: validatorsCache,
|
|
91
|
-
onValidateRecord: onValidateRecord,
|
|
92
|
-
data: data,
|
|
93
|
-
fields: fields,
|
|
94
|
-
record: record,
|
|
95
|
-
})];
|
|
96
|
-
case 2:
|
|
97
|
-
_a = _b.sent(), recordErrors = _a.errors, recordWarnings = _a.warnings;
|
|
98
|
-
hasError = checkIfHasErrors(recordErrors);
|
|
99
|
-
hasWarning = checkIfHasErrors(recordWarnings);
|
|
100
|
-
newDataSet[recordId]._meta.isInvalid = hasError;
|
|
101
|
-
newDataSet[recordId]._meta.hasWarning = hasWarning;
|
|
102
|
-
if (hasError) {
|
|
103
|
-
newErrors[recordId] = recordErrors;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
delete newErrors[recordId];
|
|
107
|
-
}
|
|
108
|
-
if (hasWarning) {
|
|
109
|
-
newWarnings[recordId] = recordWarnings;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
delete newWarnings[recordId];
|
|
113
|
-
}
|
|
114
|
-
_b.label = 3;
|
|
115
|
-
case 3:
|
|
116
|
-
i++;
|
|
117
|
-
return [3 /*break*/, 1];
|
|
118
|
-
case 4:
|
|
119
|
-
setErrors(newErrors);
|
|
120
|
-
setWarnings(newWarnings);
|
|
121
|
-
setDataSet(newDataSet); // Update the dataSet
|
|
122
|
-
return [2 /*return*/];
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}); }, [dataSet, errors, warnings, validatorsCache]);
|
|
126
|
-
// Initial data validation and update dataSet
|
|
127
|
-
useEffect(function () {
|
|
128
|
-
if (!initialDataSet || isReadOnly)
|
|
129
|
-
return;
|
|
130
|
-
setIsLoadingApp(true);
|
|
131
|
-
var initialValidation = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
-
var errors, warnings, initialData, length, _a, batchValidationDelayMs, _b, batchValidationSize, batchSize, batchCount, batchIdx, idx, batch, index, record, recordId, _c, recordErrors, recordWarnings, hasError, hasWarning, validationPercentage_1;
|
|
133
|
-
return __generator(this, function (_d) {
|
|
134
|
-
switch (_d.label) {
|
|
135
|
-
case 0:
|
|
136
|
-
errors = {};
|
|
137
|
-
warnings = {};
|
|
138
|
-
initialData = Object.values(initialDataSet);
|
|
139
|
-
length = initialData.length;
|
|
140
|
-
_a = options.batchValidationDelayMs, batchValidationDelayMs = _a === void 0 ? 400 : _a, _b = options.batchValidationSize, batchValidationSize = _b === void 0 ? length : _b;
|
|
141
|
-
batchSize = Math.min(Math.floor(batchValidationSize), length) || length;
|
|
142
|
-
batchCount = Math.ceil(length / batchSize);
|
|
143
|
-
batchIdx = 0;
|
|
144
|
-
_d.label = 1;
|
|
145
|
-
case 1:
|
|
146
|
-
if (!(batchIdx < batchCount)) return [3 /*break*/, 8];
|
|
147
|
-
idx = batchIdx * batchSize;
|
|
148
|
-
batch = initialData.slice(idx, idx + batchSize);
|
|
149
|
-
index = 0;
|
|
150
|
-
_d.label = 2;
|
|
151
|
-
case 2:
|
|
152
|
-
if (!(index < batch.length)) return [3 /*break*/, 5];
|
|
153
|
-
record = batch[index];
|
|
154
|
-
recordId = record._meta.id;
|
|
155
|
-
return [4 /*yield*/, validateRecord({
|
|
156
|
-
onValidateRecord: onValidateRecord,
|
|
157
|
-
data: initialData,
|
|
158
|
-
fields: fields,
|
|
159
|
-
record: record,
|
|
160
|
-
validatorsCache: validatorsCache,
|
|
161
|
-
})];
|
|
162
|
-
case 3:
|
|
163
|
-
_c = _d.sent(), recordErrors = _c.errors, recordWarnings = _c.warnings;
|
|
164
|
-
hasError = checkIfHasErrors(recordErrors);
|
|
165
|
-
hasWarning = checkIfHasErrors(recordWarnings);
|
|
166
|
-
record._meta.isInvalid = hasError;
|
|
167
|
-
record._meta.hasWarning = hasWarning;
|
|
168
|
-
if (hasError)
|
|
169
|
-
errors[recordId] = recordErrors;
|
|
170
|
-
if (hasWarning)
|
|
171
|
-
warnings[recordId] = recordWarnings;
|
|
172
|
-
_d.label = 4;
|
|
173
|
-
case 4:
|
|
174
|
-
index++;
|
|
175
|
-
return [3 /*break*/, 2];
|
|
176
|
-
case 5:
|
|
177
|
-
validationPercentage_1 = (Math.min(idx + batchSize, initialData.length) / initialData.length) *
|
|
178
|
-
100;
|
|
179
|
-
setValidationPercentage(Math.round((validationPercentage_1 + Number.EPSILON) * 10) / 10);
|
|
180
|
-
return [4 /*yield*/, sleep(batchValidationDelayMs)];
|
|
181
|
-
case 6:
|
|
182
|
-
_d.sent();
|
|
183
|
-
setErrors(errors);
|
|
184
|
-
setWarnings(warnings);
|
|
185
|
-
_d.label = 7;
|
|
186
|
-
case 7:
|
|
187
|
-
batchIdx++;
|
|
188
|
-
return [3 /*break*/, 1];
|
|
189
|
-
case 8: return [2 /*return*/];
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}); };
|
|
193
|
-
var sleep = function (n) { return new Promise(function (resolve) { return setTimeout(resolve, n); }); };
|
|
194
|
-
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
195
|
-
return __generator(this, function (_a) {
|
|
196
|
-
switch (_a.label) {
|
|
197
|
-
case 0:
|
|
198
|
-
setIsLoadingApp(true);
|
|
199
|
-
if (!(Object.values(initialDataSet).length > 10000)) return [3 /*break*/, 2];
|
|
200
|
-
// wait for the first render to complete before blocking main thread with review step logic
|
|
201
|
-
return [4 /*yield*/, sleep(200)];
|
|
202
|
-
case 1:
|
|
203
|
-
// wait for the first render to complete before blocking main thread with review step logic
|
|
204
|
-
_a.sent();
|
|
205
|
-
_a.label = 2;
|
|
206
|
-
case 2: return [4 /*yield*/, initialValidation()];
|
|
207
|
-
case 3:
|
|
208
|
-
_a.sent();
|
|
209
|
-
setIsLoadingApp(false);
|
|
210
|
-
return [2 /*return*/];
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
}); })();
|
|
214
|
-
}, [initialDataSet]);
|
|
215
|
-
var columnErrorCounts = useMemo(function () {
|
|
216
|
-
return Object.keys(errors).reduce(function (errorsByColumns, rowId) {
|
|
217
|
-
var recordErrors = errors[rowId];
|
|
218
|
-
return Object.keys(recordErrors).reduce(function (internalErrorsByColumns, fieldKey) {
|
|
219
|
-
var _a;
|
|
220
|
-
var hasError = !!recordErrors[fieldKey];
|
|
221
|
-
var count = (_a = internalErrorsByColumns[fieldKey]) !== null && _a !== void 0 ? _a : 0;
|
|
222
|
-
internalErrorsByColumns[fieldKey] = hasError ? count + 1 : count;
|
|
223
|
-
return internalErrorsByColumns;
|
|
224
|
-
}, errorsByColumns);
|
|
225
|
-
}, {});
|
|
226
|
-
}, [errors]);
|
|
227
|
-
var columnWarningCounts = useMemo(function () {
|
|
228
|
-
return Object.keys(warnings).reduce(function (errorsByColumns, rowId) {
|
|
229
|
-
var recordWarnings = warnings[rowId];
|
|
230
|
-
return Object.keys(recordWarnings).reduce(function (internalErrorsByColumns, fieldKey) {
|
|
231
|
-
var _a;
|
|
232
|
-
var hasError = !!recordWarnings[fieldKey];
|
|
233
|
-
var count = (_a = internalErrorsByColumns[fieldKey]) !== null && _a !== void 0 ? _a : 0;
|
|
234
|
-
internalErrorsByColumns[fieldKey] = hasError ? count + 1 : count;
|
|
235
|
-
return internalErrorsByColumns;
|
|
236
|
-
}, errorsByColumns);
|
|
237
|
-
}, {});
|
|
238
|
-
}, [warnings]);
|
|
239
|
-
var totalErrors = useMemo(function () {
|
|
240
|
-
return Object.keys(columnErrorCounts).reduce(function (count, column) { return count + columnErrorCounts[column]; }, 0);
|
|
241
|
-
}, [columnErrorCounts]);
|
|
242
|
-
var isValidationCompleted = validationPercentage === 100;
|
|
243
|
-
var isValid = isValidationCompleted && totalErrors === 0;
|
|
244
|
-
return {
|
|
245
|
-
errors: errors,
|
|
246
|
-
warnings: warnings,
|
|
247
|
-
totalErrors: totalErrors,
|
|
248
|
-
columnErrorCounts: columnErrorCounts,
|
|
249
|
-
columnWarningCounts: columnWarningCounts,
|
|
250
|
-
validationPercentage: validationPercentage,
|
|
251
|
-
isValidationCompleted: isValidationCompleted,
|
|
252
|
-
isValid: isValid,
|
|
253
|
-
updateRecordAndRevalidate: updateRecordAndRevalidate,
|
|
254
|
-
deleteRecords: deleteRecords,
|
|
255
|
-
};
|
|
256
|
-
};
|
|
@@ -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 {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
var removeErrorsOrWarningsFromObject = function (obj, keysToRemove) {
|
|
2
|
-
var keysSet = new Set(keysToRemove);
|
|
3
|
-
var newObj = {};
|
|
4
|
-
for (var key in obj) {
|
|
5
|
-
if (Object.prototype.hasOwnProperty.call(obj, key) && !(keysSet === null || keysSet === void 0 ? void 0 : keysSet.has(key))) {
|
|
6
|
-
newObj[key] = obj[key];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return newObj;
|
|
10
|
-
};
|
|
11
|
-
var removeItemsFromObject = function (obj, idsToRemove) {
|
|
12
|
-
var _a;
|
|
13
|
-
var idSet = new Set(idsToRemove);
|
|
14
|
-
var newObj = {};
|
|
15
|
-
for (var key in obj) {
|
|
16
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
17
|
-
var meta = (_a = obj[key]) === null || _a === void 0 ? void 0 : _a._meta;
|
|
18
|
-
if (meta && (meta === null || meta === void 0 ? void 0 : meta.id) && !(idSet === null || idSet === void 0 ? void 0 : idSet.has(meta === null || meta === void 0 ? void 0 : meta.id))) {
|
|
19
|
-
newObj[key] = obj[key];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return newObj;
|
|
24
|
-
};
|
|
25
|
-
export var useTableActions = function (_a) {
|
|
26
|
-
var setDataSet = _a.setDataSet, setErrors = _a.setErrors, setWarnings = _a.setWarnings;
|
|
27
|
-
// Delete records from dataSet and from validations
|
|
28
|
-
var deleteRecords = function (selectedRecords, errors, warnings) {
|
|
29
|
-
var newErrors = removeErrorsOrWarningsFromObject(errors, selectedRecords);
|
|
30
|
-
var newWarnings = removeErrorsOrWarningsFromObject(warnings, selectedRecords);
|
|
31
|
-
setErrors(newErrors);
|
|
32
|
-
setWarnings(newWarnings);
|
|
33
|
-
setDataSet(function (prev) {
|
|
34
|
-
var newDataSet = removeItemsFromObject(prev, selectedRecords);
|
|
35
|
-
return newDataSet;
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
deleteRecords: deleteRecords,
|
|
40
|
-
};
|
|
41
|
-
};
|