fuse-importer 0.23.8 → 0.24.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/README.md +19 -19
- package/lib/esm/Importer/ImporterWithContext.d.ts +7 -0
- package/lib/esm/Importer/ImporterWithContext.js +69 -0
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/index.js +4 -4
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/tableColumns.js +1 -1
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/index.js +2 -2
- package/lib/esm/Importer/Matcher/HeaderMatcher/index.js +2 -3
- package/lib/esm/Importer/Matcher/HeaderMatcher/tableColumns.js +1 -1
- package/lib/esm/Importer/Matcher/index.d.ts +3 -3
- package/lib/esm/Importer/Matcher/index.js +4 -3
- package/lib/esm/Importer/PreviewFirstTime.d.ts +2 -0
- package/lib/esm/Importer/PreviewFirstTime.js +80 -0
- package/lib/esm/Importer/PreviewModeBanner.js +3 -6
- package/lib/esm/Importer/Review/AppResponseModal.js +3 -3
- package/lib/esm/Importer/Review/ReviewContextProvider.d.ts +27 -0
- package/lib/esm/Importer/Review/ReviewContextProvider.js +234 -0
- package/lib/esm/Importer/Review/ReviewWithContext.d.ts +3 -0
- package/lib/esm/Importer/Review/ReviewWithContext.js +23 -0
- package/lib/esm/Importer/Review/index.d.ts +3 -3
- package/lib/esm/Importer/Review/index.js +4 -92
- package/lib/esm/Importer/Stepper/Step.d.ts +7 -0
- package/lib/esm/Importer/Stepper/Step.js +19 -0
- package/lib/esm/Importer/Stepper/StepIndex.d.ts +6 -0
- package/lib/esm/Importer/Stepper/StepIndex.js +27 -0
- package/lib/esm/Importer/Stepper/StepperSubmitModal.d.ts +8 -0
- package/lib/esm/Importer/Stepper/StepperSubmitModal.js +22 -0
- package/lib/esm/Importer/Stepper/UnmatchedHeadersModal.d.ts +9 -0
- package/lib/esm/Importer/Stepper/UnmatchedHeadersModal.js +23 -0
- package/lib/esm/Importer/Stepper/common/getEnumFieldValueMatchingsInitialValue.d.ts +8 -0
- package/lib/esm/Importer/Stepper/common/getEnumFieldValueMatchingsInitialValue.js +33 -0
- package/lib/esm/Importer/Stepper/common/icons.d.ts +3 -0
- package/lib/esm/Importer/Stepper/common/icons.js +18 -0
- package/lib/esm/Importer/{Stepper.d.ts → Stepper/index.d.ts} +2 -2
- package/lib/esm/Importer/Stepper/index.js +97 -0
- package/lib/esm/Importer/TrialModeBanner.js +3 -4
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterDropzone.js +1 -1
- package/lib/esm/Importer/Uploader/DragAndDropImporter/index.js +4 -4
- package/lib/esm/Importer/Uploader/HeaderButtons.d.ts +2 -0
- package/lib/esm/Importer/Uploader/HeaderButtons.js +29 -0
- package/lib/esm/Importer/Uploader/HeadersPreview.js +6 -64
- package/lib/esm/Importer/Uploader/UploaderContextProvider.d.ts +2 -2
- package/lib/esm/Importer/Uploader/index.d.ts +3 -3
- package/lib/esm/Importer/Uploader/index.js +6 -6
- package/lib/esm/Importer/common/AppLoading.js +2 -2
- package/lib/esm/Importer/{Footer.d.ts → common/Footer.d.ts} +0 -0
- package/lib/esm/Importer/common/Footer.js +17 -0
- package/lib/esm/Importer/{FuseApi.d.ts → common/FuseApi.d.ts} +1 -1
- package/lib/esm/Importer/{FuseApi.js → common/FuseApi.js} +2 -2
- package/lib/esm/Importer/{GlobalStyle.d.ts → common/GlobalStyle.d.ts} +0 -0
- package/lib/esm/Importer/common/GlobalStyle.js +7 -0
- package/lib/esm/Importer/{ImporterFonts.d.ts → common/ImporterFonts.d.ts} +0 -0
- package/lib/esm/Importer/{ImporterFonts.js → common/ImporterFonts.js} +0 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider.d.ts +13 -26
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider.js +51 -286
- package/lib/esm/Importer/common/Spreadsheet/common/index.d.ts +8 -15
- package/lib/esm/Importer/common/Spreadsheet/common/index.js +31 -101
- package/lib/esm/Importer/common/Spreadsheet/{common → components}/FieldHeader.d.ts +0 -0
- package/lib/esm/Importer/common/Spreadsheet/{common → components}/FieldHeader.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{GlobalStyle.d.ts → components/GlobalStyle.d.ts} +0 -0
- package/lib/esm/Importer/common/Spreadsheet/{GlobalStyle.js → components/GlobalStyle.js} +0 -0
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.d.ts +3 -0
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.js +74 -0
- package/lib/esm/Importer/common/Spreadsheet/{SpreadsheetRowNumbers.d.ts → components/SpreadsheetRowNumbers.d.ts} +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{SpreadsheetRowNumbers.js → components/SpreadsheetRowNumbers.js} +4 -4
- package/lib/esm/Importer/common/Spreadsheet/components/ValidationProgress.d.ts +6 -0
- package/lib/esm/Importer/common/Spreadsheet/components/ValidationProgress.js +19 -0
- package/lib/esm/Importer/common/Spreadsheet/{common → components}/fields/SpeadsheetAutocomplete.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{common → components}/fields/SpeadsheetAutocomplete.js +2 -4
- package/lib/esm/Importer/common/Spreadsheet/{common → components}/fields/SpreadsheetInput.d.ts +0 -0
- package/lib/esm/Importer/common/Spreadsheet/{common → components}/fields/SpreadsheetInput.js +0 -0
- package/lib/esm/Importer/common/Spreadsheet/{common → components}/fields/index.d.ts +0 -4
- package/lib/esm/Importer/common/Spreadsheet/{common → components}/fields/index.js +11 -64
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/Boolean.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/Boolean.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/EmailInput.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/EmailInput.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/EnumInput.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/EnumInput.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/FloatInput.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/FloatInput.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/IntegerInput.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/IntegerInput.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/StringInput.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/StringInput.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/components/inputs/index.d.ts +13 -0
- package/lib/esm/Importer/common/Spreadsheet/{inputs → components/inputs}/index.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/hooks.d.ts +29 -0
- package/lib/esm/Importer/common/Spreadsheet/hooks.js +201 -0
- package/lib/esm/Importer/common/Spreadsheet/index.d.ts +10 -9
- package/lib/esm/Importer/common/Spreadsheet/index.js +10 -105
- package/lib/esm/Importer/common/Spreadsheet/styles.d.ts +3 -0
- package/lib/esm/Importer/common/Spreadsheet/styles.js +10 -0
- package/lib/esm/Importer/common/Spreadsheet/validation/index.d.ts +20 -0
- package/lib/esm/Importer/common/Spreadsheet/validation/index.js +172 -0
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.d.ts +6 -0
- package/lib/esm/Importer/common/Spreadsheet/validation/validators.js +176 -0
- package/lib/esm/Importer/common/icons/index.d.ts +3 -0
- package/lib/esm/Importer/common/icons/index.js +3 -0
- package/lib/esm/Importer/common/index.js +3 -3
- package/lib/esm/Importer/{theme.d.ts → common/theme.d.ts} +14 -4
- package/lib/esm/Importer/{theme.js → common/theme.js} +1 -1
- package/lib/esm/Importer/common/utils.d.ts +2 -4
- package/lib/esm/Importer/common/utils.js +79 -24
- package/lib/esm/Importer/{ImporterContextProvider.d.ts → contexts/ImporterContextProvider.d.ts} +18 -53
- package/lib/esm/Importer/{ImporterContextProvider.js → contexts/ImporterContextProvider.js} +31 -27
- package/lib/esm/Importer/data/index.d.ts +28 -0
- package/lib/esm/Importer/data/index.js +134 -0
- package/lib/esm/Importer/index.d.ts +10 -10
- package/lib/esm/Importer/index.js +12 -60
- package/lib/esm/common/Modal.js +5 -2
- package/lib/esm/common/Table/TableView/TableHeaders.js +1 -1
- package/lib/esm/common/Table/TableView/TableRow.d.ts +2 -1
- package/lib/esm/common/Table/TableView/TableRow.js +10 -10
- package/lib/esm/common/Table/TableView/index.d.ts +2 -1
- package/lib/esm/common/Table/TableView/index.js +9 -8
- package/lib/esm/common/Table/icons.d.ts +1 -0
- package/lib/esm/common/Table/icons.js +2 -1
- package/lib/esm/common/TooltipProvider.d.ts +5 -1
- package/lib/esm/common/TooltipProvider.js +11 -13
- package/lib/esm/common/buttons.d.ts +6 -3
- package/lib/esm/common/buttons.js +11 -5
- package/lib/esm/common/inputs/Autocomplete.d.ts +2 -1
- package/lib/esm/common/inputs/Autocomplete.js +7 -6
- package/lib/esm/common/inputs/SelectMenu.d.ts +2 -1
- package/lib/esm/common/inputs/SelectMenu.js +8 -8
- package/lib/esm/common/inputs/TextInput.d.ts +10 -6
- package/lib/esm/common/inputs/TextInput.js +12 -3
- package/lib/esm/common/inputs/index.d.ts +1 -0
- package/lib/esm/common/inputs/index.js +1 -0
- package/lib/esm/common/inputs/tooltip.d.ts +5 -0
- package/lib/esm/common/inputs/tooltip.js +38 -0
- package/lib/esm/index.d.ts +1 -2
- package/lib/esm/index.js +0 -1
- package/lib/esm/styled/theme/colorPalette.d.ts +18 -18
- package/lib/esm/styled/theme/debugCss.d.ts +1 -0
- package/lib/esm/styled/theme/debugCss.js +2 -1
- package/lib/esm/styled/theme/dimensionsCss.d.ts +6 -2
- package/lib/esm/styled/theme/dimensionsCss.js +3 -3
- package/lib/esm/styled/theme/globalCss.d.ts +3 -0
- package/lib/esm/styled/theme/globalCss.js +9 -8
- package/lib/esm/styled/theme/index.d.ts +24 -5
- package/lib/esm/styled/theme/textStyles.d.ts +1 -0
- package/lib/esm/styled/theme/textStyles.js +2 -1
- package/lib/esm/types.d.ts +64 -14
- package/lib/main.js +1 -1
- package/package.json +18 -8
- package/lib/esm/Importer/Footer.js +0 -19
- package/lib/esm/Importer/GlobalStyle.js +0 -7
- package/lib/esm/Importer/SpreadsheetReviewContextProvider.d.ts +0 -20
- package/lib/esm/Importer/SpreadsheetReviewContextProvider.js +0 -128
- package/lib/esm/Importer/Stepper.js +0 -153
- package/lib/esm/Importer/common/Spreadsheet/inputs/index.d.ts +0 -13
|
@@ -9,303 +9,68 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 (_) 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
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
-
if (ar || !(i in from)) {
|
|
51
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
-
ar[i] = from[i];
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
53
20
|
}
|
|
54
|
-
|
|
55
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
return t;
|
|
56
22
|
};
|
|
57
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
58
|
-
import {
|
|
59
|
-
import {
|
|
60
|
-
import {
|
|
61
|
-
import { sleep } from "../../../utils";
|
|
62
|
-
import { useImporterContext } from "../../ImporterContextProvider";
|
|
63
|
-
var MINIMUM_ROW_COUNT = 20;
|
|
64
|
-
var getRowId = function (id) { return "r".concat(id); };
|
|
65
|
-
export var getBatchErrors = function (records, onValidateRecord) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
-
var batchErrors;
|
|
67
|
-
return __generator(this, function (_a) {
|
|
68
|
-
switch (_a.label) {
|
|
69
|
-
case 0: return [4 /*yield*/, Promise.all(records.map(function (record) { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
-
var _a;
|
|
71
|
-
return __generator(this, function (_b) {
|
|
72
|
-
switch (_b.label) {
|
|
73
|
-
case 0:
|
|
74
|
-
_a = {
|
|
75
|
-
rowId: record._meta.id
|
|
76
|
-
};
|
|
77
|
-
return [4 /*yield*/, onValidateRecord(record)];
|
|
78
|
-
case 1: return [2 /*return*/, (_a.errors = _b.sent(),
|
|
79
|
-
_a)];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}); }))];
|
|
83
|
-
case 1:
|
|
84
|
-
batchErrors = _a.sent();
|
|
85
|
-
return [2 /*return*/, formatBatchErrors(batchErrors)];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}); };
|
|
24
|
+
import { get } from "lodash";
|
|
25
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
26
|
+
import { useValidationState } from "./hooks";
|
|
89
27
|
var SpreadsheetContext = createContext({});
|
|
90
|
-
var addMeta = function (d, i) { return (__assign(__assign({}, d), { _meta: { id: getRowId(i), rowIndex: i } })); };
|
|
91
28
|
export var SpreadsheetContextProvider = function (_a) {
|
|
92
|
-
var
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
]
|
|
96
|
-
var
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var _h = useState(true), isScrollingEnabled = _h[0], setIsScrollingEnabled = _h[1];
|
|
101
|
-
var _j = useState(null), batchValidationErrors = _j[0], setBatchValidationErrors = _j[1];
|
|
102
|
-
var _k = useState(0), batchValidationPercentage = _k[0], setBatchValidationPercentage = _k[1];
|
|
103
|
-
var _l = useValidationState({
|
|
104
|
-
data: data,
|
|
29
|
+
var initialDataSet = _a.initialDataSet, _b = _a.rowWidth, rowWidth = _b === void 0 ? 1 : _b, fields = _a.fields, options = _a.options, isReadOnly = _a.isReadOnly, highlightFirstRow = _a.highlightFirstRow, children = _a.children, onValidateRecord = _a.onValidateRecord, onDataSetChanged = _a.onDataSetChanged, onValidationStateChanged = _a.onValidationStateChanged;
|
|
30
|
+
var _c = useState(initialDataSet), dataSet = _c[0], setDataSet = _c[1];
|
|
31
|
+
var _d = useState(false), isLoading = _d[0], setIsLoading = _d[1];
|
|
32
|
+
var _e = useState(null), sortByFieldErrors = _e[0], setSortByFieldErrors = _e[1];
|
|
33
|
+
var sortByCurrentErrorsRef = useRef({});
|
|
34
|
+
var _f = useValidationState({
|
|
35
|
+
dataSet: dataSet,
|
|
36
|
+
initialDataSet: initialDataSet,
|
|
105
37
|
fields: fields,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
var
|
|
115
|
-
var
|
|
116
|
-
var batchCount = Math.ceil(data.length / batchSize);
|
|
117
|
-
var isCancelled = false;
|
|
118
|
-
var addEmptyRows = function () {
|
|
119
|
-
var newData = __spreadArray([], data, true);
|
|
120
|
-
var emptyRecord = fields.reduce(function (obj, f) {
|
|
121
|
-
var _a;
|
|
122
|
-
return (__assign(__assign({}, obj), (_a = {}, _a[f.name] = null, _a)));
|
|
123
|
-
}, {});
|
|
124
|
-
for (var i = newData.length; i < MINIMUM_ROW_COUNT; i++) {
|
|
125
|
-
newData.push(__assign(__assign({}, emptyRecord), { _meta: {
|
|
126
|
-
id: getRowId(i),
|
|
127
|
-
rowIndex: i,
|
|
128
|
-
} }));
|
|
129
|
-
}
|
|
130
|
-
updateData(newData);
|
|
131
|
-
};
|
|
132
|
-
var validateInBatches = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
-
var validationErrors, batchIdx, idx, batch, errors, validationPercentage;
|
|
134
|
-
return __generator(this, function (_a) {
|
|
135
|
-
switch (_a.label) {
|
|
136
|
-
case 0:
|
|
137
|
-
validationErrors = {};
|
|
138
|
-
batchIdx = 0;
|
|
139
|
-
_a.label = 1;
|
|
140
|
-
case 1:
|
|
141
|
-
if (!(batchIdx < batchCount)) return [3 /*break*/, 5];
|
|
142
|
-
if (isCancelled)
|
|
143
|
-
return [3 /*break*/, 5];
|
|
144
|
-
idx = batchIdx * batchSize;
|
|
145
|
-
batch = data.slice(idx, idx + batchSize);
|
|
146
|
-
return [4 /*yield*/, (onValidateBatch
|
|
147
|
-
? onValidateBatch(batch)
|
|
148
|
-
: getBatchErrors(batch, onValidateRecord))];
|
|
149
|
-
case 2:
|
|
150
|
-
errors = _a.sent();
|
|
151
|
-
validationErrors = __assign(__assign({}, validationErrors), errors);
|
|
152
|
-
// unblocks main thread for rendering ui
|
|
153
|
-
return [4 /*yield*/, sleep(batchValidationDelayMs)];
|
|
154
|
-
case 3:
|
|
155
|
-
// unblocks main thread for rendering ui
|
|
156
|
-
_a.sent();
|
|
157
|
-
validationPercentage = (Math.min(idx + batchSize, data.length) / data.length) * 100;
|
|
158
|
-
setBatchValidationPercentage(Math.floor(validationPercentage));
|
|
159
|
-
_a.label = 4;
|
|
160
|
-
case 4:
|
|
161
|
-
batchIdx++;
|
|
162
|
-
return [3 /*break*/, 1];
|
|
163
|
-
case 5:
|
|
164
|
-
if (!isCancelled)
|
|
165
|
-
setBatchValidationErrors(validationErrors);
|
|
166
|
-
return [2 /*return*/];
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}); };
|
|
170
|
-
var init = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
171
|
-
return __generator(this, function (_a) {
|
|
172
|
-
if (data.length < MINIMUM_ROW_COUNT)
|
|
173
|
-
addEmptyRows();
|
|
174
|
-
validateInBatches();
|
|
175
|
-
return [2 /*return*/];
|
|
176
|
-
});
|
|
177
|
-
}); };
|
|
178
|
-
if (!isReadOnly)
|
|
179
|
-
init();
|
|
180
|
-
return function () {
|
|
181
|
-
isCancelled = true;
|
|
182
|
-
};
|
|
183
|
-
}, []);
|
|
184
|
-
useEffect(function () {
|
|
185
|
-
var appValidationErrors = appResponse === null || appResponse === void 0 ? void 0 : appResponse.errors;
|
|
186
|
-
if (appValidationErrors) {
|
|
187
|
-
updateData(__spreadArray([], data, true).map(function (record) { return (__assign(__assign({}, record), { _meta: __assign(__assign({}, record._meta), { appValidationErrors: appValidationErrors[record._meta.id] }) })); }));
|
|
188
|
-
}
|
|
189
|
-
}, [appResponse]);
|
|
190
|
-
useEffect(function () {
|
|
191
|
-
if (!setReviewedData)
|
|
192
|
-
return;
|
|
193
|
-
if (isValidationComplete)
|
|
194
|
-
setReviewedData(data.filter(function (r) { return !recordIsEmpty(r, fields); }));
|
|
195
|
-
else
|
|
196
|
-
setReviewedData(null);
|
|
197
|
-
}, [isValidationComplete, data]);
|
|
198
|
-
useEffect(function () {
|
|
38
|
+
options: options,
|
|
39
|
+
isReadOnly: isReadOnly,
|
|
40
|
+
setDataSet: setDataSet,
|
|
41
|
+
setIsLoading: setIsLoading,
|
|
42
|
+
onValidateRecord: onValidateRecord,
|
|
43
|
+
}), errorsRef = _f.errorsRef, updateRecordAndRevalidate = _f.updateRecordAndRevalidate, validationState = __rest(_f, ["errorsRef", "updateRecordAndRevalidate"]);
|
|
44
|
+
// sort data based on errors (errors group on top and not errors group at bottom)
|
|
45
|
+
var data = useMemo(function () {
|
|
46
|
+
var errors = sortByCurrentErrorsRef.current; //Sort errors snapshot
|
|
47
|
+
var dataSetValues = Object.values(dataSet);
|
|
199
48
|
if (!sortByFieldErrors)
|
|
200
|
-
return;
|
|
201
|
-
|
|
202
|
-
var
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
fields: fields,
|
|
206
|
-
batchValidationErrors: batchValidationErrors,
|
|
207
|
-
submittedData: submittedData,
|
|
208
|
-
data: data,
|
|
209
|
-
})[sortByFieldErrors];
|
|
210
|
-
};
|
|
211
|
-
var aHasErrors = recordHasErrors(a);
|
|
212
|
-
var bHasErrors = recordHasErrors(b);
|
|
213
|
-
if (aHasErrors === bHasErrors)
|
|
49
|
+
return dataSetValues;
|
|
50
|
+
return dataSetValues.sort(function (a, b) {
|
|
51
|
+
var aHasErrors = !!get(errors, "".concat(get(a, "_meta.id"), ".").concat(sortByFieldErrors), false);
|
|
52
|
+
var bHasErrors = !!get(errors, "".concat(get(b, "_meta.id"), ".").concat(sortByFieldErrors), false);
|
|
53
|
+
if (aHasErrors === bHasErrors) {
|
|
214
54
|
return a._meta.rowIndex > b._meta.rowIndex ? 1 : -1;
|
|
55
|
+
}
|
|
215
56
|
return bHasErrors ? 1 : -1;
|
|
216
57
|
});
|
|
217
|
-
|
|
218
|
-
}, [sortByFieldErrors]);
|
|
219
|
-
var validateRenderedRecords = useCallback(function (renderedData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
220
|
-
var newData;
|
|
221
|
-
return __generator(this, function (_a) {
|
|
222
|
-
if (isReadOnly)
|
|
223
|
-
return [2 /*return*/];
|
|
224
|
-
setIsLoading(true);
|
|
225
|
-
newData = __spreadArray([], data, true);
|
|
226
|
-
renderedData.forEach(function (record) { return __awaiter(void 0, void 0, void 0, function () {
|
|
227
|
-
var renderedRecordWithErrors, _a, rowIndex;
|
|
228
|
-
var _b;
|
|
229
|
-
return __generator(this, function (_c) {
|
|
230
|
-
switch (_c.label) {
|
|
231
|
-
case 0:
|
|
232
|
-
_a = getRenderedRecordWithErrors;
|
|
233
|
-
_b = {
|
|
234
|
-
record: record
|
|
235
|
-
};
|
|
236
|
-
return [4 /*yield*/, onValidateRecord(record)];
|
|
237
|
-
case 1:
|
|
238
|
-
renderedRecordWithErrors = _a.apply(void 0, [(_b.validationErrors = _c.sent(),
|
|
239
|
-
_b)]);
|
|
240
|
-
rowIndex = newData.findIndex(function (r) { return r._meta.id === record._meta.id; });
|
|
241
|
-
newData[rowIndex] = renderedRecordWithErrors;
|
|
242
|
-
return [2 /*return*/];
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}); });
|
|
246
|
-
setIsLoading(false);
|
|
247
|
-
updateData(newData);
|
|
248
|
-
return [2 /*return*/];
|
|
249
|
-
});
|
|
250
|
-
}); }, [data]);
|
|
251
|
-
var value = {
|
|
252
|
-
data: data,
|
|
253
|
-
dataRef: dataRef,
|
|
254
|
-
fields: fields,
|
|
255
|
-
isLoading: isLoading,
|
|
256
|
-
setIsLoading: setIsLoading,
|
|
257
|
-
isScrollingEnabled: isScrollingEnabled,
|
|
258
|
-
isValidationComplete: isValidationComplete,
|
|
259
|
-
batchValidationErrors: batchValidationErrors,
|
|
260
|
-
batchValidationPercentage: batchValidationPercentage,
|
|
261
|
-
totalErrors: totalErrors,
|
|
262
|
-
columnErrorCounts: columnErrorCounts,
|
|
263
|
-
isReadOnly: isReadOnly,
|
|
264
|
-
rowWidth: rowWidth,
|
|
265
|
-
sortByFieldErrors: sortByFieldErrors,
|
|
266
|
-
submittedData: submittedData,
|
|
267
|
-
setSortByFieldErrors: setSortByFieldErrors,
|
|
268
|
-
setData: updateData,
|
|
269
|
-
onValidateRecord: onValidateRecord,
|
|
270
|
-
validateRenderedRecords: validateRenderedRecords,
|
|
271
|
-
setIsScrollingEnabled: setIsScrollingEnabled,
|
|
272
|
-
highlightFirstRow: highlightFirstRow,
|
|
273
|
-
};
|
|
274
|
-
return (_jsx(SpreadsheetContext.Provider, __assign({ value: value }, { children: children })));
|
|
275
|
-
};
|
|
276
|
-
var useValidationState = function (_a) {
|
|
277
|
-
var data = _a.data, fields = _a.fields, batchValidationErrors = _a.batchValidationErrors, submittedData = _a.submittedData;
|
|
278
|
-
var _b = useState({}), columnErrorCounts = _b[0], setColumnErrorCounts = _b[1];
|
|
279
|
-
var setIsSpreadsheetValid = useImporterContext().setIsSpreadsheetValid;
|
|
58
|
+
}, [dataSet, sortByFieldErrors]);
|
|
280
59
|
useEffect(function () {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
fields: fields,
|
|
294
|
-
batchValidationErrors: batchValidationErrors,
|
|
295
|
-
submittedData: submittedData,
|
|
296
|
-
data: data,
|
|
297
|
-
});
|
|
298
|
-
updateFieldErrorCount(recordErrors);
|
|
299
|
-
});
|
|
300
|
-
setIsSpreadsheetValid(Object.keys(newColumnErrorCounts).length === 0);
|
|
301
|
-
setColumnErrorCounts(newColumnErrorCounts);
|
|
302
|
-
};
|
|
303
|
-
updateErrorCounts();
|
|
304
|
-
}, [data, batchValidationErrors]);
|
|
305
|
-
var totalErrors = useMemo(function () {
|
|
306
|
-
return Object.keys(columnErrorCounts).reduce(function (total, key) { return total + (columnErrorCounts[key] || 0); }, 0);
|
|
60
|
+
onDataSetChanged && onDataSetChanged(dataSet);
|
|
61
|
+
}, [dataSet]);
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
setDataSet(initialDataSet);
|
|
64
|
+
}, [initialDataSet]);
|
|
65
|
+
useEffect(function () {
|
|
66
|
+
onValidationStateChanged && onValidationStateChanged(validationState);
|
|
67
|
+
}, [validationState, onValidationStateChanged]);
|
|
68
|
+
var handleSortByFieldErrors = useCallback(function (value) {
|
|
69
|
+
//current errors snapshot for use on sort to keep data sorted without changing with each edit or revalidation.
|
|
70
|
+
sortByCurrentErrorsRef.current = __assign({}, errorsRef.current);
|
|
71
|
+
setSortByFieldErrors(value);
|
|
307
72
|
}, []);
|
|
308
|
-
var
|
|
309
|
-
return {
|
|
73
|
+
var value = __assign(__assign({ data: data, fields: fields, isLoading: isLoading }, validationState), { isReadOnly: isReadOnly, rowWidth: rowWidth, sortByFieldErrors: sortByFieldErrors, highlightFirstRow: highlightFirstRow, setIsLoading: setIsLoading, setSortByFieldErrors: handleSortByFieldErrors, onValidateRecord: onValidateRecord, updateRecord: updateRecordAndRevalidate });
|
|
74
|
+
return (_jsx(SpreadsheetContext.Provider, __assign({ value: value }, { children: children })));
|
|
310
75
|
};
|
|
311
76
|
export var useSpreadsheetContext = function () { return useContext(SpreadsheetContext); };
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Record, Field, FieldTypes } from "../../../../types";
|
|
2
2
|
export declare const spreadsheetRowHeightPx = 40;
|
|
3
3
|
export declare const spreadsheetHeaderHeightPx = 40;
|
|
4
|
+
export declare const isNullOrUndefined: (value: any) => boolean;
|
|
4
5
|
export declare const isEmpty: (value: any) => boolean;
|
|
5
6
|
export declare const isEmail: (value: any) => boolean;
|
|
6
7
|
export declare const isUrl: (value: any) => boolean;
|
|
7
8
|
export declare const isTrue: (value: string) => boolean;
|
|
9
|
+
export declare const isFalse: (value: string) => boolean;
|
|
10
|
+
export declare const isBoolean: (value: string) => boolean;
|
|
8
11
|
export declare const isInteger: (value: string) => boolean;
|
|
9
12
|
export declare const isFloat: (value: string) => boolean;
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}) => Record;
|
|
15
|
-
declare type GetRecordErrorsArgs = {
|
|
16
|
-
record: Record;
|
|
17
|
-
fields: Field[];
|
|
18
|
-
batchValidationErrors: BatchValidationErrors;
|
|
19
|
-
submittedData: Record[];
|
|
20
|
-
data: Record[];
|
|
21
|
-
};
|
|
22
|
-
export declare const getRecordErrors: ({ record, fields, batchValidationErrors, submittedData, data, }: GetRecordErrorsArgs) => {};
|
|
23
|
-
export {};
|
|
13
|
+
export declare const isEven: (value: number) => boolean;
|
|
14
|
+
export declare const ignoreNullOrUndefinedKeyValues: (obj: any) => {};
|
|
15
|
+
export declare const isRecordEmpty: (record: Record, fields: Field[]) => boolean;
|
|
16
|
+
export declare const parseValue: (fieldType: FieldTypes, value: any, enumSet?: any) => any;
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
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 _a;
|
|
13
|
-
import { FieldTypes, } from "../../../../types";
|
|
14
|
-
import { DateTime } from "luxon";
|
|
1
|
+
import { FieldTypes } from "../../../../types";
|
|
15
2
|
export var spreadsheetRowHeightPx = 40;
|
|
16
3
|
export var spreadsheetHeaderHeightPx = 40;
|
|
4
|
+
export var isNullOrUndefined = function (value) {
|
|
5
|
+
return value === null || value === undefined;
|
|
6
|
+
};
|
|
17
7
|
export var isEmpty = function (value) {
|
|
18
8
|
return (value === undefined ||
|
|
19
9
|
value === null ||
|
|
@@ -29,56 +19,24 @@ export var isUrl = function (value) {
|
|
|
29
19
|
return urlRegex.test(value);
|
|
30
20
|
};
|
|
31
21
|
export var isTrue = function (value) {
|
|
32
|
-
var
|
|
22
|
+
var _a;
|
|
23
|
+
var _value = (_a = value === null || value === void 0 ? void 0 : value.toString()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
33
24
|
return ["true", "yes", "1", "y", "on", "t"].includes(_value);
|
|
34
25
|
};
|
|
26
|
+
export var isFalse = function (value) {
|
|
27
|
+
var _a;
|
|
28
|
+
var _value = (_a = value === null || value === void 0 ? void 0 : value.toString()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
29
|
+
return ["false", "no", "0", "n", "off", "f"].includes(_value);
|
|
30
|
+
};
|
|
31
|
+
export var isBoolean = function (value) {
|
|
32
|
+
return isTrue(value) || isFalse(value);
|
|
33
|
+
};
|
|
35
34
|
export var isInteger = function (value) { return /^-?[0-9]+$/.test(value + ""); };
|
|
36
35
|
export var isFloat = function (value) {
|
|
37
36
|
return /^-?[0-9]+(?:\.[0-9]+)?$/.test(value + "");
|
|
38
37
|
};
|
|
39
|
-
export var
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
export var getRenderedRecordWithErrors = function (_a) {
|
|
43
|
-
var record = _a.record, validationErrors = _a.validationErrors;
|
|
44
|
-
return (__assign(__assign({}, record), { _meta: __assign(__assign({}, (record._meta || {})), { localValidationErrors: validationErrors, wasSeen: true }) }));
|
|
45
|
-
};
|
|
46
|
-
var validateDatePattern = function (field, fieldValue) {
|
|
47
|
-
var date = DateTime.fromFormat(fieldValue, field.pattern);
|
|
48
|
-
if (!date.isValid) {
|
|
49
|
-
return "".concat(field.label, " must match the pattern ").concat(field.pattern);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var validateUnique = function (fieldValue, key, records) {
|
|
53
|
-
var existingRecords = records.filter(function (r) { return r[key] === fieldValue; });
|
|
54
|
-
return existingRecords.length < 2;
|
|
55
|
-
};
|
|
56
|
-
var validations = (_a = {},
|
|
57
|
-
_a[FieldTypes.email] = function (field, fieldValue) {
|
|
58
|
-
if (!isEmail(fieldValue)) {
|
|
59
|
-
return "".concat(field.label, " is not a valid email");
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
_a[FieldTypes.url] = function (field, fieldValue) {
|
|
63
|
-
if (!isUrl(fieldValue)) {
|
|
64
|
-
return "".concat(field.label, " is not a valid url");
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
_a[FieldTypes.integer] = function (field, fieldValue) {
|
|
68
|
-
if (!isInteger(fieldValue)) {
|
|
69
|
-
return "".concat(field.label, " is not a valid integer");
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
_a[FieldTypes.float] = function (field, fieldValue) {
|
|
73
|
-
if (!isFloat(fieldValue)) {
|
|
74
|
-
return "".concat(field.label, " is not a valid float");
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
_a[FieldTypes.date] = validateDatePattern,
|
|
78
|
-
_a[FieldTypes.time] = validateDatePattern,
|
|
79
|
-
_a[FieldTypes.datetime] = validateDatePattern,
|
|
80
|
-
_a);
|
|
81
|
-
var ignoreNullOrUndefinedKeyValues = function (obj) {
|
|
38
|
+
export var isEven = function (value) { return value % 2 === 0; };
|
|
39
|
+
export var ignoreNullOrUndefinedKeyValues = function (obj) {
|
|
82
40
|
var result = {};
|
|
83
41
|
Object.keys(obj || {})
|
|
84
42
|
.filter(function (key) { return obj[key] !== null && obj[key] !== undefined; })
|
|
@@ -87,47 +45,19 @@ var ignoreNullOrUndefinedKeyValues = function (obj) {
|
|
|
87
45
|
});
|
|
88
46
|
return result;
|
|
89
47
|
};
|
|
90
|
-
export var
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (!isFieldUnique) {
|
|
106
|
-
newErrors[field.name] = "".concat(field.label, " must be unique");
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return newErrors;
|
|
111
|
-
}, {});
|
|
112
|
-
var recordValidationErrors = (function () {
|
|
113
|
-
var _a;
|
|
114
|
-
if ((_a = record === null || record === void 0 ? void 0 : record._meta) === null || _a === void 0 ? void 0 : _a.wasSeen)
|
|
115
|
-
return record._meta.localValidationErrors;
|
|
116
|
-
return batchValidationErrors
|
|
117
|
-
? batchValidationErrors[record._meta.id]
|
|
118
|
-
: {};
|
|
119
|
-
})();
|
|
120
|
-
var appValidationErrors = {};
|
|
121
|
-
if (record._meta.appValidationErrors) {
|
|
122
|
-
var appValidationErrorFields = Object.keys(record._meta.appValidationErrors);
|
|
123
|
-
appValidationErrors = appValidationErrorFields.reduce(function (errors, field) {
|
|
124
|
-
var newErrors = __assign({}, errors);
|
|
125
|
-
if (record[field] === submittedRecord[field])
|
|
126
|
-
newErrors[field] = record._meta.appValidationErrors[field];
|
|
127
|
-
return newErrors;
|
|
128
|
-
}, {});
|
|
129
|
-
}
|
|
130
|
-
return __assign(__assign(__assign({}, ignoreNullOrUndefinedKeyValues(recordValidationErrors)), ignoreNullOrUndefinedKeyValues(recordTemplateValidationErrors)), ignoreNullOrUndefinedKeyValues(appValidationErrors));
|
|
131
|
-
}
|
|
132
|
-
return {};
|
|
48
|
+
export var isRecordEmpty = function (record, fields) {
|
|
49
|
+
return fields.reduce(function (isEmptyRecord, f) { return isEmptyRecord && isEmpty(record[f.name]); }, true);
|
|
50
|
+
};
|
|
51
|
+
export var parseValue = function (fieldType, value, enumSet) {
|
|
52
|
+
if (isEmpty(value))
|
|
53
|
+
return value;
|
|
54
|
+
if (fieldType === FieldTypes.float)
|
|
55
|
+
return isFloat(value) ? parseFloat(value) : value;
|
|
56
|
+
if (fieldType === FieldTypes.integer)
|
|
57
|
+
return isInteger(value) ? parseInt(value) : value;
|
|
58
|
+
if (fieldType === FieldTypes.boolean)
|
|
59
|
+
return isTrue(value) ? true : false;
|
|
60
|
+
if (fieldType === FieldTypes.enum && enumSet)
|
|
61
|
+
return enumSet[value];
|
|
62
|
+
return value;
|
|
133
63
|
};
|
|
File without changes
|
|
@@ -14,10 +14,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
14
14
|
return __assign.apply(this, arguments);
|
|
15
15
|
};
|
|
16
16
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
import styled, { css } from "styled-components";
|
|
17
18
|
import { TooltipProvider } from "../../../../common";
|
|
18
19
|
import { Div } from "../../../../styled/utils";
|
|
19
20
|
import { useSpreadsheetContext } from "../SpreadsheetContextProvider";
|
|
20
|
-
import styled, { css } from "styled-components";
|
|
21
21
|
var ErrorCount = styled(Div)(function (_a) {
|
|
22
22
|
var _b = _a.theme, colors = _b.colors, c = _b.css;
|
|
23
23
|
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n color: ", ";\n background: ", ";\n border: solid 1px ", ";\n padding: 4px 7px;\n border-radius: 56px;\n min-width: 24px;\n ", ";\n "], ["\n color: ", ";\n background: ", ";\n border: solid 1px ", ";\n padding: 4px 7px;\n border-radius: 56px;\n min-width: 24px;\n ", ";\n "])), colors.error, colors.red100, colors.error, c.centered);
|
package/lib/esm/Importer/common/Spreadsheet/{GlobalStyle.d.ts → components/GlobalStyle.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
+
import React, { useCallback, useMemo, useRef } from "react";
|
|
25
|
+
import { areEqual } from "react-window";
|
|
26
|
+
import { Div } from "../../../../styled/utils";
|
|
27
|
+
import { getTableHeight } from "../../../common";
|
|
28
|
+
import { spreadsheetHeaderHeightPx, spreadsheetRowHeightPx } from "../common";
|
|
29
|
+
import { useSpreadsheetContext } from "../SpreadsheetContextProvider";
|
|
30
|
+
import * as S from "../styles";
|
|
31
|
+
import { FieldHeader } from "./FieldHeader";
|
|
32
|
+
import GlobalStyle from "./GlobalStyle";
|
|
33
|
+
import { inputTypes } from "./inputs";
|
|
34
|
+
import { SpreadsheetRowNumbers } from "./SpreadsheetRowNumbers";
|
|
35
|
+
import ValidationProgress from "./ValidationProgress";
|
|
36
|
+
var getItemKey = function (record) { return record._meta.id; };
|
|
37
|
+
var SpreadsheetData = function () {
|
|
38
|
+
var _a = useSpreadsheetContext(), fields = _a.fields, data = _a.data, isLoading = _a.isLoading, isReadOnly = _a.isReadOnly, rowWidth = _a.rowWidth, totalErrors = _a.totalErrors, validationPercentage = _a.validationPercentage, setSortByFieldErrors = _a.setSortByFieldErrors;
|
|
39
|
+
var rowNumbersGridRef = useRef();
|
|
40
|
+
var sortByErrors = useCallback(function (field) {
|
|
41
|
+
return setSortByFieldErrors(function (sortByFieldErrors) {
|
|
42
|
+
return sortByFieldErrors === field ? null : field;
|
|
43
|
+
});
|
|
44
|
+
}, []);
|
|
45
|
+
var columns = useMemo(function () {
|
|
46
|
+
return fields.map(function (field) { return ({
|
|
47
|
+
Header: function () { return (_jsx(FieldHeader, { field: field, sortByFieldErrors: sortByErrors })); },
|
|
48
|
+
Content: function (record) {
|
|
49
|
+
var Input = inputTypes[field.type];
|
|
50
|
+
var rowIndex = record.rowIndex, recordProp = __rest(record, ["rowIndex"]);
|
|
51
|
+
return (_jsx(Input, { id: "".concat(field.name, "-").concat(rowIndex), fieldType: field.type, name: field.name, options: field.options, record: recordProp }));
|
|
52
|
+
},
|
|
53
|
+
}); });
|
|
54
|
+
}, [fields, sortByErrors]);
|
|
55
|
+
var onTableScroll = useCallback(function (scrollTop) {
|
|
56
|
+
if (rowNumbersGridRef.current) {
|
|
57
|
+
var grid = rowNumbersGridRef.current;
|
|
58
|
+
grid.scrollTo({ scrollTop: scrollTop });
|
|
59
|
+
}
|
|
60
|
+
}, []);
|
|
61
|
+
var dataLength = data === null || data === void 0 ? void 0 : data.length;
|
|
62
|
+
var spreadsheetHeight = useMemo(function () {
|
|
63
|
+
return getTableHeight({
|
|
64
|
+
headerHeight: spreadsheetHeaderHeightPx,
|
|
65
|
+
rowHeight: spreadsheetRowHeightPx,
|
|
66
|
+
dataCount: dataLength,
|
|
67
|
+
minimumTableHeight: 450,
|
|
68
|
+
maxVisibleRows: 12,
|
|
69
|
+
});
|
|
70
|
+
}, [dataLength]);
|
|
71
|
+
var showValidationProgress = !isReadOnly && validationPercentage < 100;
|
|
72
|
+
return (_jsxs(Div, { children: [_jsx(GlobalStyle, {}), _jsx(Div, __assign({ h: 32 }, { children: showValidationProgress && (_jsx(ValidationProgress, { totalErrors: totalErrors, validationPercentage: validationPercentage })) })), _jsxs(S.SpreadSheetWrapper, __assign({ h: spreadsheetHeight, dflex: true, w: 1400 }, { children: [_jsx(SpreadsheetRowNumbers, { gridRef: rowNumbersGridRef, spreadsheetHasXScroll: rowWidth > 1, height: spreadsheetHeight }), _jsx(S.TableView, { tableHeadersHeight: spreadsheetHeaderHeightPx, highlightFirstRow: isReadOnly, rowHeight: spreadsheetRowHeightPx, h: spreadsheetHeight, rowWidth: rowWidth, data: data, columns: columns, isLoading: isLoading, onTableScroll: onTableScroll, getItemKey: getItemKey })] }))] }));
|
|
73
|
+
};
|
|
74
|
+
export default React.memo(SpreadsheetData, areEqual);
|