fuse-importer 0.26.6 → 0.26.8
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 +13 -11
- package/lib/esm/Importer/Review/ReviewContextProvider.d.ts +5 -3
- package/lib/esm/Importer/Review/ReviewContextProvider.js +54 -39
- package/lib/esm/Importer/Stepper/index.js +14 -13
- package/lib/esm/Importer/Uploader/HeadersPreview.js +16 -8
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/filterMethods.d.ts +5 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/filterMethods.js +67 -0
- package/lib/esm/Importer/common/Spreadsheet/{SpreadsheetContextProvider.d.ts → SpreadsheetContextProvider/index.d.ts} +12 -8
- package/lib/esm/Importer/common/Spreadsheet/{SpreadsheetContextProvider.js → SpreadsheetContextProvider/index.js} +23 -17
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useSpreadsheetFilter.d.ts +14 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useSpreadsheetFilter.js +45 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/utils.d.ts +2 -0
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/utils.js +14 -0
- package/lib/esm/Importer/common/Spreadsheet/common/types.d.ts +2 -2
- package/lib/esm/Importer/common/Spreadsheet/components/FieldHeader.js +5 -2
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.d.ts +2 -1
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.js +9 -4
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.d.ts +1 -2
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.js +18 -13
- package/lib/esm/Importer/common/Spreadsheet/hooks.d.ts +1 -3
- package/lib/esm/Importer/common/Spreadsheet/hooks.js +7 -4
- package/lib/esm/Importer/common/Spreadsheet/index.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/styles.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/transformation/index.d.ts +7 -0
- package/lib/esm/Importer/common/Spreadsheet/transformation/index.js +25 -0
- package/lib/esm/Importer/common/Spreadsheet/transformation/transformators.d.ts +8 -0
- package/lib/esm/Importer/common/Spreadsheet/transformation/transformators.js +106 -0
- package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +6 -2
- package/lib/esm/Importer/contexts/ImporterContextProvider.js +26 -22
- package/lib/esm/Importer/data/index.d.ts +19 -3
- package/lib/esm/Importer/data/index.js +27 -30
- package/lib/esm/Importer/index.js +1 -1
- package/lib/esm/common/Table/TableActions/ExportData.js +1 -1
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +18 -8
- package/lib/esm/common/Table/TableActions/RowFilters.d.ts +1 -0
- package/lib/esm/common/Table/TableActions/RowFilters.js +42 -0
- package/lib/esm/common/Table/TableActions/TableActions.js +2 -1
- package/lib/esm/common/Table/TableActions/hooks.d.ts +0 -2
- package/lib/esm/common/Table/TableActions/hooks.js +0 -39
- package/lib/esm/common/Table/TableView/TableRows/TableRow.d.ts +2 -2
- package/lib/esm/common/Table/TableView/TableRows/TableRow.js +4 -4
- package/lib/esm/common/Table/TableView/TableRows/index.js +7 -4
- package/lib/esm/common/Table/TableView/index.d.ts +1 -1
- package/lib/esm/common/Table/TableView/index.js +1 -2
- package/lib/esm/common/Table/TableView/types.d.ts +0 -1
- package/lib/esm/common/columnsTransformations.d.ts +15 -0
- package/lib/esm/common/columnsTransformations.js +92 -0
- package/lib/esm/common/columnsValidations.js +83 -3
- 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/common/inputs/Checkbox.js +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +3 -0
- package/lib/esm/locales/de.d.ts +5 -0
- package/lib/esm/locales/de.js +6 -1
- package/lib/esm/locales/en.d.ts +5 -0
- package/lib/esm/locales/en.js +6 -1
- package/lib/esm/locales/es.d.ts +5 -0
- package/lib/esm/locales/es.js +6 -1
- package/lib/esm/locales/fr.d.ts +5 -0
- package/lib/esm/locales/fr.js +6 -1
- package/lib/esm/types.d.ts +33 -2
- package/lib/esm/types.js +15 -0
- package/lib/main.js +24 -24
- package/lib/main.js.LICENSE.txt +0 -2
- package/package.json +1 -1
|
@@ -15,13 +15,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
15
15
|
};
|
|
16
16
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
17
17
|
import { useEffect, useRef } from "react";
|
|
18
|
-
import
|
|
18
|
+
import { useTranslation } from "react-i18next";
|
|
19
|
+
import styled, { ThemeProvider, css } from "styled-components";
|
|
19
20
|
import { Toast } from "../common";
|
|
20
21
|
import { Div } from "../styled";
|
|
21
|
-
import { Footer } from "./common/Footer";
|
|
22
|
-
import { GlobalStyle } from "./common/GlobalStyle";
|
|
23
|
-
import { ImporterFonts } from "./common/ImporterFonts";
|
|
24
|
-
import { useImporterContext } from "./contexts/ImporterContextProvider";
|
|
25
22
|
import Matcher from "./Matcher";
|
|
26
23
|
import { PreviewFirstTime } from "./PreviewFirstTime";
|
|
27
24
|
import { PreviewModeBanner } from "./PreviewModeBanner";
|
|
@@ -30,7 +27,11 @@ import { ReviewContextProvider } from "./Review/ReviewContextProvider";
|
|
|
30
27
|
import { Stepper } from "./Stepper/index";
|
|
31
28
|
import { TrialModeBanner } from "./TrialModeBanner";
|
|
32
29
|
import Uploader from "./Uploader";
|
|
33
|
-
import {
|
|
30
|
+
import { AppLoading } from "./common/AppLoading";
|
|
31
|
+
import { Footer } from "./common/Footer";
|
|
32
|
+
import { GlobalStyle } from "./common/GlobalStyle";
|
|
33
|
+
import { ImporterFonts } from "./common/ImporterFonts";
|
|
34
|
+
import { useImporterContext } from "./contexts/ImporterContextProvider";
|
|
34
35
|
export var Layout = styled(Div)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background: ", ";\n display: flex;\n flex-direction: column;\n height: 100vh;\n left: 0;\n overflow-y: auto;\n position: fixed;\n top: 0;\n width: 100vw;\n z-index: ", ";\n ", ";\n"], ["\n background: ", ";\n display: flex;\n flex-direction: column;\n height: 100vh;\n left: 0;\n overflow-y: auto;\n position: fixed;\n top: 0;\n width: 100vw;\n z-index: ", ";\n ", ";\n"])), function (_a) {
|
|
35
36
|
var theme = _a.theme;
|
|
36
37
|
return theme.colors.backgroundInterface;
|
|
@@ -40,21 +41,22 @@ var Content = styled(Div)(templateObject_3 || (templateObject_3 = __makeTemplate
|
|
|
40
41
|
return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background-color: ", ";\n flex: ", ";\n "], ["\n background-color: ", ";\n flex: ", ";\n "])), colors.backgroundInterface, inTrialMode ? "none" : 1);
|
|
41
42
|
});
|
|
42
43
|
export var ImporterWithContext = function () {
|
|
43
|
-
var _a = useImporterContext(), inTrialMode = _a.inTrialMode, currentStepIndex = _a.currentStepIndex, matcherSubstep = _a.matcherSubstep, theme = _a.theme, logoURL = _a.logoURL, previewFirstTime = _a.previewFirstTime, _b = _a.importerOptions, zIndex = _b.zIndex, previewMode = _b.previewMode;
|
|
44
|
+
var _a = useImporterContext(), inTrialMode = _a.inTrialMode, currentStepIndex = _a.currentStepIndex, matcherSubstep = _a.matcherSubstep, templateHeaders = _a.templateHeaders, theme = _a.theme, logoURL = _a.logoURL, previewFirstTime = _a.previewFirstTime, headerRowIndex = _a.headerRowIndex, initialRecords = _a.initialRecords, _b = _a.importerOptions, zIndex = _b.zIndex, previewMode = _b.previewMode;
|
|
44
45
|
var layoutRef = useRef(null);
|
|
45
46
|
var t = useTranslation().t;
|
|
46
47
|
useEffect(function () {
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
var _a;
|
|
49
|
+
(_a = layoutRef === null || layoutRef === void 0 ? void 0 : layoutRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo(0, 0);
|
|
50
|
+
}, [currentStepIndex, matcherSubstep, layoutRef.current]);
|
|
49
51
|
var stepLabels = [
|
|
50
52
|
t("general:steps.upload"),
|
|
51
53
|
t("general:steps.match"),
|
|
52
54
|
t("general:steps.review"),
|
|
53
55
|
];
|
|
54
56
|
function renderContent() {
|
|
55
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Div, { children: [previewMode && _jsx(PreviewModeBanner, {}), !previewMode && _jsx(TrialModeBanner, {}), _jsx(Stepper, { stepLabels: stepLabels, logoURL: logoURL })] }), _jsxs(Content, { children: [currentStepIndex === 0 && _jsx(Uploader, {}), currentStepIndex === 1 && _jsx(Matcher, {}), currentStepIndex === 2 && _jsx(Review, {})] }), inTrialMode && (_jsx(Content, __assign({ inTrialMode: inTrialMode }, { children: _jsx(Footer, {}) })))] }));
|
|
57
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Div, { children: [previewMode && _jsx(PreviewModeBanner, {}), !previewMode && _jsx(TrialModeBanner, {}), _jsx(Stepper, { stepLabels: stepLabels, logoURL: logoURL })] }), _jsxs(Content, { children: [currentStepIndex === 0 && _jsx(Uploader, {}), currentStepIndex === 1 && _jsx(Matcher, {}), currentStepIndex === 2 && templateHeaders && _jsx(Review, {})] }), inTrialMode && (_jsx(Content, __assign({ inTrialMode: inTrialMode }, { children: _jsx(Footer, {}) })))] }));
|
|
56
58
|
}
|
|
57
59
|
var shouldShowPreviewFirstTime = previewFirstTime && previewMode;
|
|
58
|
-
return (_jsxs(ThemeProvider, __assign({ theme: theme }, { children: [_jsx(Toast, {}), _jsx(GlobalStyle, {}), _jsx(ImporterFonts, {}), _jsx(ReviewContextProvider, { children: _jsx(Layout, __assign({ zIndex: zIndex, ref: layoutRef }, { children: shouldShowPreviewFirstTime ? _jsx(PreviewFirstTime, {}) : renderContent() })) })] })));
|
|
60
|
+
return (_jsxs(ThemeProvider, __assign({ theme: theme }, { children: [_jsx(Toast, {}), _jsx(GlobalStyle, {}), _jsx(ImporterFonts, {}), templateHeaders ? (_jsx(ReviewContextProvider, __assign({ initialRecords: initialRecords }, { children: _jsx(Layout, __assign({ zIndex: zIndex, ref: layoutRef }, { children: shouldShowPreviewFirstTime ? (_jsx(PreviewFirstTime, {})) : (renderContent()) })) }))) : (_jsx(AppLoading, {}))] })));
|
|
59
61
|
};
|
|
60
62
|
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppResponse, Field, OnValidateRecord, RecordDataSet } from "../../types";
|
|
1
|
+
import { AppResponse, Field, OnValidateRecord, Record, RecordDataSet } from "../../types";
|
|
2
2
|
import { OnDataSetChanged, OnValidationStateChanged } from "../common/Spreadsheet";
|
|
3
3
|
type State = {
|
|
4
4
|
previewInitialDataSet: RecordDataSet;
|
|
@@ -17,11 +17,13 @@ type State = {
|
|
|
17
17
|
onDataSetChanged: OnDataSetChanged;
|
|
18
18
|
onValidationStateChanged: OnValidationStateChanged;
|
|
19
19
|
onSubmit: () => void;
|
|
20
|
-
onExport: () => void;
|
|
20
|
+
onExport: (dataType: ExportDataType) => void;
|
|
21
21
|
};
|
|
22
|
+
type ExportDataType = "csv" | "excel";
|
|
22
23
|
type Props = {
|
|
24
|
+
initialRecords?: Record[];
|
|
23
25
|
children: JSX.Element;
|
|
24
26
|
};
|
|
25
|
-
export declare const ReviewContextProvider: ({ children }: Props) => JSX.Element;
|
|
27
|
+
export declare const ReviewContextProvider: ({ initialRecords, children }: Props) => JSX.Element;
|
|
26
28
|
export declare const useReviewContext: () => State;
|
|
27
29
|
export {};
|
|
@@ -45,6 +45,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
45
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
|
+
var t = {};
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
+
t[p] = s[p];
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
+
t[p[i]] = s[p[i]];
|
|
56
|
+
}
|
|
57
|
+
return t;
|
|
58
|
+
};
|
|
48
59
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
60
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
61
|
if (ar || !(i in from)) {
|
|
@@ -56,11 +67,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
56
67
|
};
|
|
57
68
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
58
69
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
70
|
+
import { utils, writeFile } from "xlsx";
|
|
59
71
|
import { AppLoading } from "../common/AppLoading";
|
|
60
72
|
import { isRecordEmpty } from "../common/Spreadsheet/common";
|
|
61
73
|
import { sendRecordsToIntegrations } from "../common/utils";
|
|
62
74
|
import { useImporterContext } from "../contexts/ImporterContextProvider";
|
|
63
|
-
import {
|
|
75
|
+
import { transformToRecords } from "../data/index";
|
|
76
|
+
import { getPreviewDataSet, getReviewDataSet, getTemplateFields, recordListToDataSet, } from "../data";
|
|
64
77
|
var ReviewContext = createContext({});
|
|
65
78
|
var trackImportedRowsCount = function (fuseApi, templateSlug, rowCount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
79
|
var error_1, errorMessage;
|
|
@@ -94,22 +107,25 @@ var filterAndMapWithBackendErrors = function (dataSet, errors) {
|
|
|
94
107
|
return __assign(__assign({}, record), { _meta: __assign(__assign({}, meta), { isInvalid: true, backendErrors: errors[rId] }) });
|
|
95
108
|
}, []);
|
|
96
109
|
};
|
|
97
|
-
function
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
csvRows.push(row.join(","));
|
|
110
|
+
function csvExport(data) {
|
|
111
|
+
var valuesWithQuotesWhenNecessary = data.map(function (obj) {
|
|
112
|
+
var newObj = {};
|
|
113
|
+
for (var key in obj) {
|
|
114
|
+
var value = obj[key];
|
|
115
|
+
newObj[key] =
|
|
116
|
+
typeof value === "string" && value.includes(",") ? "\"".concat(value, "\"") : value;
|
|
117
|
+
}
|
|
118
|
+
return newObj;
|
|
107
119
|
});
|
|
108
|
-
|
|
120
|
+
var worksheet = utils.json_to_sheet(valuesWithQuotesWhenNecessary);
|
|
121
|
+
var workbook = utils.book_new();
|
|
122
|
+
utils.book_append_sheet(workbook, worksheet, "Data");
|
|
123
|
+
utils.sheet_to_csv(worksheet);
|
|
124
|
+
writeFile(workbook, "export.csv");
|
|
109
125
|
}
|
|
110
126
|
export var ReviewContextProvider = function (_a) {
|
|
111
|
-
var children = _a.children;
|
|
112
|
-
var _b = useImporterContext(), templateHeaderMatchings = _b.templateHeaderMatchings, enumFieldValueMatchings = _b.enumFieldValueMatchings, templateHeaders = _b.templateHeaders, uploadedDataHeaders = _b.uploadedDataHeaders, uploadedData = _b.uploadedData, currentStepIndex = _b.currentStepIndex, integrations = _b.integrations, templateSlug = _b.templateSlug, fuseApi = _b.fuseApi, _c = _b.importerOptions, disableSubmitIfInvalid = _c.disableSubmitIfInvalid, batchValidationDelayMs = _c.batchValidationDelayMs, batchValidationSize = _c.batchValidationSize, previewMode = _c.previewMode, loadingComponent = _c.loadingComponent, onSubmit = _b.onSubmit, onValidateRecord = _b.onValidateRecord, formatRecord = _b.formatRecord, selectedRows = _b.selectedRows;
|
|
127
|
+
var initialRecords = _a.initialRecords, children = _a.children;
|
|
128
|
+
var _b = useImporterContext(), templateHeaderMatchings = _b.templateHeaderMatchings, enumFieldValueMatchings = _b.enumFieldValueMatchings, templateHeaders = _b.templateHeaders, uploadedDataHeaders = _b.uploadedDataHeaders, headerRowIndex = _b.headerRowIndex, uploadedData = _b.uploadedData, currentStepIndex = _b.currentStepIndex, integrations = _b.integrations, templateSlug = _b.templateSlug, fuseApi = _b.fuseApi, setSelectedRows = _b.setSelectedRows, _c = _b.importerOptions, disableSubmitIfInvalid = _c.disableSubmitIfInvalid, batchValidationDelayMs = _c.batchValidationDelayMs, batchValidationSize = _c.batchValidationSize, previewMode = _c.previewMode, loadingComponent = _c.loadingComponent, onSubmit = _b.onSubmit, onValidateRecord = _b.onValidateRecord, formatRecord = _b.formatRecord, selectedRows = _b.selectedRows;
|
|
113
129
|
var _d = useState(false), isSubmitting = _d[0], setIsSubmitting = _d[1];
|
|
114
130
|
var _e = useState(false), isSubmitDisabled = _e[0], setIsSubmitDisabled = _e[1];
|
|
115
131
|
var _f = useState(false), importWasSuccessful = _f[0], setImportWasSuccessful = _f[1];
|
|
@@ -127,18 +143,18 @@ export var ReviewContextProvider = function (_a) {
|
|
|
127
143
|
batchValidationDelayMs: batchValidationDelayMs,
|
|
128
144
|
batchValidationSize: batchValidationSize,
|
|
129
145
|
}); }, [batchValidationDelayMs, batchValidationSize]);
|
|
130
|
-
var onExport = useCallback(function () {
|
|
146
|
+
var onExport = useCallback(function (dataType) {
|
|
131
147
|
if (!reviewDataSetRef.current)
|
|
132
148
|
return;
|
|
133
149
|
var dataSet = reviewDataSetRef.current;
|
|
134
150
|
var dataSetValues = Object.values(dataSet);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
151
|
+
if (dataType === "csv") {
|
|
152
|
+
var valuesWithoutMeta = dataSetValues.map(function (_a) {
|
|
153
|
+
var _meta = _a._meta, rest = __rest(_a, ["_meta"]);
|
|
154
|
+
return rest;
|
|
155
|
+
});
|
|
156
|
+
csvExport(valuesWithoutMeta);
|
|
157
|
+
}
|
|
142
158
|
}, [reviewFields, selectedRows]);
|
|
143
159
|
var onSubmitData = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
144
160
|
var dataSet, dataSetValues, validDataSetValues, validDataSetLength, invalidRecords_1, applicationResponse, isAppResponseSuccessful, _a, errors, isDataValid, recordsToDisplayFiltered, invalidDataSet, error_2;
|
|
@@ -223,27 +239,26 @@ export var ReviewContextProvider = function (_a) {
|
|
|
223
239
|
setPreviewInitialDataSet(initialDataSet);
|
|
224
240
|
}
|
|
225
241
|
else if (currentStepIndex === 2) {
|
|
242
|
+
var fields = getTemplateFields({ templateHeaders: templateHeaders });
|
|
226
243
|
//Review spreadsheet data
|
|
227
|
-
var
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
244
|
+
var _records = initialRecords ||
|
|
245
|
+
transformToRecords({
|
|
246
|
+
templateHeaderMatchings: templateHeaderMatchings,
|
|
247
|
+
enumFieldValueMatchings: enumFieldValueMatchings,
|
|
248
|
+
templateHeaders: templateHeaders,
|
|
249
|
+
uploadedDataHeaders: uploadedDataHeaders,
|
|
250
|
+
uploadedData: uploadedData.slice(headerRowIndex + 1),
|
|
251
|
+
formatRecord: formatRecord,
|
|
252
|
+
});
|
|
253
|
+
var initialDataSet = getReviewDataSet({
|
|
254
|
+
records: _records,
|
|
255
|
+
fields: fields,
|
|
256
|
+
}).initialDataSet;
|
|
257
|
+
setSelectedRows([]);
|
|
235
258
|
setReviewFields(fields);
|
|
236
259
|
setReviewInitialDataSet(initialDataSet);
|
|
237
260
|
}
|
|
238
|
-
}, [
|
|
239
|
-
uploadedData,
|
|
240
|
-
currentStepIndex,
|
|
241
|
-
enumFieldValueMatchings,
|
|
242
|
-
templateHeaderMatchings,
|
|
243
|
-
templateHeaders,
|
|
244
|
-
uploadedDataHeaders,
|
|
245
|
-
uploadedData,
|
|
246
|
-
]);
|
|
261
|
+
}, [uploadedData, currentStepIndex, templateHeaders, uploadedData]);
|
|
247
262
|
var value = {
|
|
248
263
|
previewInitialDataSet: previewInitialDataSet,
|
|
249
264
|
previewFields: previewFields,
|
|
@@ -15,18 +15,18 @@ var __assign = (this && this.__assign) || function () {
|
|
|
15
15
|
};
|
|
16
16
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
17
17
|
import { useState } from "react";
|
|
18
|
+
import { useTranslation } from "react-i18next";
|
|
18
19
|
import styled, { css } from "styled-components";
|
|
19
|
-
import { Button,
|
|
20
|
+
import { Button, ChevronRightIcon, closeIconCondensed } from "../../common";
|
|
20
21
|
import { Div } from "../../styled/utils";
|
|
21
|
-
import { useImporterContext } from "../contexts/ImporterContextProvider";
|
|
22
|
-
import { useReviewContext } from "../Review/ReviewContextProvider";
|
|
23
22
|
import { ColumnType } from "../Matcher/common/types";
|
|
24
|
-
import {
|
|
23
|
+
import { useReviewContext } from "../Review/ReviewContextProvider";
|
|
24
|
+
import { useImporterContext } from "../contexts/ImporterContextProvider";
|
|
25
|
+
import { ConfirmCloseModal } from "./ConfirmCloseModal";
|
|
25
26
|
import { Step } from "./Step";
|
|
26
27
|
import { StepperSubmitModal } from "./StepperSubmitModal";
|
|
27
28
|
import { UnmatchedHeadersModal } from "./UnmatchedHeadersModal";
|
|
28
|
-
import {
|
|
29
|
-
import { useTranslation } from "react-i18next";
|
|
29
|
+
import { getEnumFieldValueMatchingsInitialValue } from "./common/getEnumFieldValueMatchingsInitialValue";
|
|
30
30
|
var StepperWrapper = styled(Div)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background-color: ", ";\n border-bottom: 1px solid ", ";\n user-select: none;\n"], ["\n background-color: ", ";\n border-bottom: 1px solid ", ";\n user-select: none;\n"])), function (p) { return p.theme.colors.white; }, function (p) { return p.theme.colors.gray300; });
|
|
31
31
|
var StepperContainer = styled(Div)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n align-items: center;\n display: flex;\n gap: 16px;\n justify-content: space-between;\n padding-left: 32px;\n padding-right: 32px;\n width: 100%;\n"], ["\n align-items: center;\n display: flex;\n gap: 16px;\n justify-content: space-between;\n padding-left: 32px;\n padding-right: 32px;\n width: 100%;\n"])));
|
|
32
32
|
var Steps = styled(Div)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n @media (max-width: 630px) {\n display: none;\n }\n"], ["\n @media (max-width: 630px) {\n display: none;\n }\n"])));
|
|
@@ -44,7 +44,7 @@ export var Stepper = function (_a) {
|
|
|
44
44
|
var _c = useState(false), isSubmitModalOpen = _c[0], setIsSubmitModalOpen = _c[1];
|
|
45
45
|
var _d = useState(false), isConfirmCloseModalOpen = _d[0], setIsConfirmCloseModalOpen = _d[1];
|
|
46
46
|
var _e = useReviewContext(), appResponse = _e.appResponse, isSubmitDisabled = _e.isSubmitDisabled, onSubmit = _e.onSubmit;
|
|
47
|
-
var _f = useImporterContext(), currentStepIndex = _f.currentStepIndex, templateHeaderMatchings = _f.templateHeaderMatchings, matcherSubstep = _f.matcherSubstep, templateHeaders = _f.templateHeaders, uploadedDataEnumFieldValues = _f.uploadedDataEnumFieldValues, setEnumFieldValueMatchings = _f.setEnumFieldValueMatchings, setMatcherSubstep = _f.setMatcherSubstep, setCurrentStepIndex = _f.setCurrentStepIndex, onClose = _f.onClose, isUsingManualImport = _f.isUsingManualImport, resetImporterWhenUsingManualImport = _f.resetImporterWhenUsingManualImport, uploadedData = _f.uploadedData;
|
|
47
|
+
var _f = useImporterContext(), initialRecords = _f.initialRecords, currentStepIndex = _f.currentStepIndex, templateHeaderMatchings = _f.templateHeaderMatchings, matcherSubstep = _f.matcherSubstep, templateHeaders = _f.templateHeaders, uploadedDataEnumFieldValues = _f.uploadedDataEnumFieldValues, setEnumFieldValueMatchings = _f.setEnumFieldValueMatchings, setMatcherSubstep = _f.setMatcherSubstep, setCurrentStepIndex = _f.setCurrentStepIndex, onClose = _f.onClose, isUsingManualImport = _f.isUsingManualImport, resetImporterWhenUsingManualImport = _f.resetImporterWhenUsingManualImport, uploadedData = _f.uploadedData;
|
|
48
48
|
var templateHeaderLabels = Object.keys(templateHeaderMatchings || []);
|
|
49
49
|
var unmatchedHeadersCount = templateHeaderLabels.filter(function (templateHeaderLabel) { return !templateHeaderMatchings[templateHeaderLabel]; }).length;
|
|
50
50
|
var isLastSubMatchStep = matcherSubstep === 1;
|
|
@@ -103,12 +103,13 @@ export var Stepper = function (_a) {
|
|
|
103
103
|
var isVerifyStep = currentStepIndex === 0 && !!uploadedData;
|
|
104
104
|
var isMatchStep = currentStepIndex === 1;
|
|
105
105
|
var isReviewStep = currentStepIndex === 2;
|
|
106
|
-
var stepsUI = (_jsx(Div, __assign({ dflex: true, centered: true }, { children:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
var stepsUI = (_jsx(Div, __assign({ dflex: true, centered: true }, { children: !initialRecords &&
|
|
107
|
+
stepLabels.map(function (label, index) {
|
|
108
|
+
var isLast = index === stepLabels.length - 1;
|
|
109
|
+
var isCompleted = index < currentStepIndex;
|
|
110
|
+
return (_jsxs(Div, __assign({ centered: true }, { children: [_jsx(Step, { index: index, label: label, isCompleted: isCompleted, isSelected: index === currentStepIndex }), !isLast && (_jsx(Div, __assign({ ml: 18, mr: 18, dflex: true }, { children: _jsx(ChevronRightIcon, {}) })))] }), index));
|
|
111
|
+
}) })));
|
|
112
|
+
var leftButtonUI = (_jsx(Div, __assign({ style: { flex: 1 } }, { children: !initialRecords && (_jsxs(StepperButtonContainer, __assign({ align: "left" }, { children: [logoURL && (_jsx(Div, __assign({ forDesktop: true }, { children: _jsx(Logo, { src: logoURL, alt: "" }) }))), currentStepIndex > 0 && !appResponse && (_jsx(GoBackButtonWrapper, { children: _jsx(Button, __assign({ variant: "secondary", onClick: goBack }, { children: t("stepper.go_back") })) }))] }))) })));
|
|
112
113
|
var rightButtonUI = (_jsxs(StepperButtonContainer, __assign({ align: "right" }, { children: [(isMatchStep || isVerifyStep) && (_jsx(Button, __assign({ variant: "primary", onClick: continueToNextStep }, { children: t("stepper.continue") }))), isReviewStep && (_jsx(Button, __assign({ variant: "primary", isDisabled: isSubmitDisabled, onClick: function () { return setIsSubmitModalOpen(true); } }, { children: t("stepper.submit") }))), _jsx(CloseIcon, __assign({ "data-test-id": "close-importer", centered: true, clickable: true, onClick: handleOnClose }, { children: closeIconCondensed }))] })));
|
|
113
114
|
return (_jsxs(_Fragment, { children: [_jsx(StepperWrapper, __assign({ pRelative: true, alignCenter: true, w100: true, h: 72, centered: true }, { children: _jsxs(StepperContainer, { children: [leftButtonUI, _jsx(Steps, __assign({ alignCenter: true }, { children: stepsUI })), rightButtonUI] }) })), _jsx(UnmatchedHeadersModal, { isUnmatchedHeadersModalOpen: isUnmatchedHeadersModalOpen, unmatchedHeadersCount: unmatchedHeadersCount, onSetStep: function () { return setStep(); }, onCloseUnmatchedHeadersModal: function () {
|
|
114
115
|
return setIsUnmatchedHeadersModalOpen(false);
|
|
@@ -15,22 +15,30 @@ var __assign = (this && this.__assign) || function () {
|
|
|
15
15
|
};
|
|
16
16
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
17
|
import { useTranslation } from "react-i18next";
|
|
18
|
-
import styled from "styled-components";
|
|
18
|
+
import styled, { css } from "styled-components";
|
|
19
19
|
import { Div } from "../../styled/utils";
|
|
20
20
|
import { useReviewContext } from "../Review/ReviewContextProvider";
|
|
21
|
-
import
|
|
21
|
+
import SpreadsheetBase from "../common/Spreadsheet";
|
|
22
22
|
import { useImporterContext } from "../contexts/ImporterContextProvider";
|
|
23
23
|
import { HeaderButtons } from "./HeaderButtons";
|
|
24
|
-
|
|
25
|
-
var
|
|
24
|
+
import { useEffect } from "react";
|
|
25
|
+
var Spreadsheet = styled(SpreadsheetBase)(function () { return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n /* rows will be removed for match and review steps */\n .before-selected-row {\n opacity: 0.2;\n }\n "], ["\n /* rows will be removed for match and review steps */\n .before-selected-row {\n opacity: 0.2;\n }\n "]))); });
|
|
26
|
+
var HeaderContainer = styled(Div)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin-left: 32px;\n\n @media (max-width: 1050px) {\n margin-left: 0px;\n\n > div:first-of-type {\n text-align: center;\n }\n\n div:last-of-type {\n margin-left: 0px;\n }\n }\n"], ["\n margin-left: 32px;\n\n @media (max-width: 1050px) {\n margin-left: 0px;\n\n > div:first-of-type {\n text-align: center;\n }\n\n div:last-of-type {\n margin-left: 0px;\n }\n }\n"])));
|
|
27
|
+
var DescriptionAndButtons = styled(Div)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n @media (max-width: 1050px) {\n flex-direction: column;\n gap: 16px;\n }\n"], ["\n @media (max-width: 1050px) {\n flex-direction: column;\n gap: 16px;\n }\n"])));
|
|
26
28
|
var HeadersPreview = function () {
|
|
27
29
|
var _a = useReviewContext(), fields = _a.previewFields, initialDataSet = _a.previewInitialDataSet;
|
|
28
30
|
var t = useTranslation("upload").t;
|
|
29
|
-
var _b = useImporterContext(), selectedRows = _b.selectedRows, setSelectedRows = _b.setSelectedRows;
|
|
30
|
-
|
|
31
|
+
var _b = useImporterContext(), selectedRows = _b.selectedRows, setSelectedRows = _b.setSelectedRows, setHeaderRowIndex = _b.setHeaderRowIndex;
|
|
32
|
+
useEffect(function () {
|
|
33
|
+
if (initialDataSet && selectedRows[0]) {
|
|
34
|
+
var headerRowIndex = Object.keys(initialDataSet).findIndex(function (key) { return key === selectedRows[0]; });
|
|
35
|
+
setHeaderRowIndex(headerRowIndex);
|
|
36
|
+
}
|
|
37
|
+
}, [initialDataSet, selectedRows]);
|
|
38
|
+
return (_jsxs(Div, __assign({ flexColumn: true, h100: true }, { children: [_jsxs(HeaderContainer, { children: [_jsx(Div, __assign({ h2: true, mt: 40, mb: 16 }, { children: t("headers_preview.title") })), _jsxs(DescriptionAndButtons, __assign({ body1: true, mb: 24, alignCenter: true }, { children: [t("headers_preview.description"), _jsx(HeaderButtons, {})] }))] }), _jsx(Div, __assign({ w100: true, h100: true, justifyCenter: true }, { children: initialDataSet && (_jsx(Spreadsheet, { isReadOnly: true, initialDataSet: initialDataSet, fields: fields, options: {
|
|
31
39
|
showCheckboxColumn: true,
|
|
32
|
-
|
|
40
|
+
withSingleRowSelect: true,
|
|
33
41
|
}, selectedRows: selectedRows, setSelectedRows: setSelectedRows })) }))] })));
|
|
34
42
|
};
|
|
35
43
|
export default HeadersPreview;
|
|
36
|
-
var templateObject_1, templateObject_2;
|
|
44
|
+
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BatchValidationErrors, RecordDataSet } from "../../../../types";
|
|
2
|
+
import { SpreadsheetFilter } from "./useSpreadsheetFilter";
|
|
3
|
+
export declare const filterRecordsBySearchValue: (obj: RecordDataSet, value: string) => RecordDataSet;
|
|
4
|
+
export declare const filterRecordsByType: (obj: RecordDataSet, filterType: SpreadsheetFilter["byRow"]) => RecordDataSet;
|
|
5
|
+
export declare const filterRecordsByError: (obj: RecordDataSet, keyToFilter: string, errors: BatchValidationErrors) => RecordDataSet;
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
//Filter records by search value
|
|
13
|
+
export var filterRecordsBySearchValue = function (obj, value) {
|
|
14
|
+
var isObject = function (value) {
|
|
15
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
|
+
};
|
|
17
|
+
var includesSearchValue = function (value, searchValue) {
|
|
18
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
19
|
+
var stringValue = String(value).toLowerCase();
|
|
20
|
+
var searchValueLower = searchValue.toLowerCase();
|
|
21
|
+
return stringValue.includes(searchValueLower);
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
25
|
+
var filteredObj = {};
|
|
26
|
+
for (var _i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
|
|
27
|
+
var _b = _a[_i], key = _b[0], currentObj = _b[1];
|
|
28
|
+
if (!isObject(currentObj)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
var matches = Object.values(currentObj).some(function (propertyValue) {
|
|
32
|
+
return includesSearchValue(propertyValue, value);
|
|
33
|
+
});
|
|
34
|
+
if (matches) {
|
|
35
|
+
filteredObj[key] = currentObj;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return filteredObj;
|
|
39
|
+
};
|
|
40
|
+
export var filterRecordsByType = function (obj, filterType) {
|
|
41
|
+
var rowIsEmpty = function (row) {
|
|
42
|
+
return Object.keys(row).every(function (key) {
|
|
43
|
+
if (key === "_meta")
|
|
44
|
+
return true;
|
|
45
|
+
return !row[key];
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
var filteredKeys = Object.keys(obj).filter(function (key) {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return filterType === "all" ||
|
|
51
|
+
(((_b = (_a = obj[key]) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.isInvalid) !== (filterType === "valid") &&
|
|
52
|
+
!rowIsEmpty(obj[key]));
|
|
53
|
+
});
|
|
54
|
+
return filteredKeys.reduce(function (acc, key) {
|
|
55
|
+
var _a;
|
|
56
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[key] = obj[key], _a)));
|
|
57
|
+
}, {});
|
|
58
|
+
};
|
|
59
|
+
//Filter records by selected column error
|
|
60
|
+
export var filterRecordsByError = function (obj, keyToFilter, errors) {
|
|
61
|
+
var filteredObj = {};
|
|
62
|
+
var filteredKeys = Object.keys(errors).filter(function (key) { var _a, _b; return ((_b = (_a = obj[key]) === null || _a === void 0 ? void 0 : _a._meta) === null || _b === void 0 ? void 0 : _b.isInvalid) && errors[key][keyToFilter]; });
|
|
63
|
+
for (var i = 0; i < filteredKeys.length; i++) {
|
|
64
|
+
filteredObj[filteredKeys[i]] = obj[filteredKeys[i]];
|
|
65
|
+
}
|
|
66
|
+
return filteredObj;
|
|
67
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { SpreadsheetOptions } from "
|
|
3
|
-
import { BatchValidationErrors, Field, Record, RecordDataSet } from "
|
|
4
|
-
import { SortBy, SpreadsheetProps } from "
|
|
5
|
-
import { ValidationState } from "
|
|
2
|
+
import { SpreadsheetOptions } from "../../../..";
|
|
3
|
+
import { BatchValidationErrors, Field, Record, RecordDataSet } from "../../../../types";
|
|
4
|
+
import { SortBy, SpreadsheetProps } from "../common/types";
|
|
5
|
+
import { ValidationState } from "../hooks";
|
|
6
|
+
import { SpreadsheetFilter } from "./useSpreadsheetFilter";
|
|
6
7
|
export type OnDataSetChanged = (dataSet: RecordDataSet) => void;
|
|
7
8
|
export type OnValidationStateChanged = (state: ValidationState) => void;
|
|
8
9
|
type State = {
|
|
@@ -12,7 +13,6 @@ type State = {
|
|
|
12
13
|
isReadOnly?: boolean;
|
|
13
14
|
errors: BatchValidationErrors;
|
|
14
15
|
warnings: BatchValidationErrors;
|
|
15
|
-
highlightFirstRow: boolean;
|
|
16
16
|
options: SpreadsheetOptions;
|
|
17
17
|
sortByFieldErrors: string;
|
|
18
18
|
sortByFieldWarnings: string;
|
|
@@ -26,9 +26,13 @@ type State = {
|
|
|
26
26
|
lastClickedIndexRef: React.MutableRefObject<number | null>;
|
|
27
27
|
filteredInputValue: string;
|
|
28
28
|
setFilteredInputValue: React.Dispatch<React.SetStateAction<string>>;
|
|
29
|
-
selectedErrorToFilter: string;
|
|
30
|
-
setSelectedErrorToFilter: React.Dispatch<React.SetStateAction<string>>;
|
|
31
29
|
addNewRowsToSpreadsheet: () => void;
|
|
30
|
+
spreadsheetFilter: SpreadsheetFilter;
|
|
31
|
+
filterRecordsByRowType: (filterByRow: SpreadsheetFilter["byRow"]) => void;
|
|
32
|
+
filterRecordsByFieldErrors: (filterByColumn: string) => void;
|
|
33
|
+
resetSpreadsheetFilter: () => void;
|
|
34
|
+
recordsWithValuesCount: number;
|
|
35
|
+
filteredDataCount: number;
|
|
32
36
|
checkboxColumnWidth: number;
|
|
33
37
|
isFiltering: boolean;
|
|
34
38
|
sortBy: SortBy | null;
|
|
@@ -37,6 +41,6 @@ type State = {
|
|
|
37
41
|
type Props = SpreadsheetProps & {
|
|
38
42
|
children: JSX.Element;
|
|
39
43
|
};
|
|
40
|
-
export declare const SpreadsheetContextProvider: ({ initialDataSet, fields, options, isReadOnly,
|
|
44
|
+
export declare const SpreadsheetContextProvider: ({ initialDataSet, fields, options, isReadOnly, children, onValidateRecord, onDataSetChanged, onValidationStateChanged, selectedRows, setSelectedRows, getSortCompareFn, }: Props) => JSX.Element;
|
|
41
45
|
export declare const useSpreadsheetContext: () => State;
|
|
42
46
|
export {};
|
|
@@ -23,8 +23,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import { get } from "lodash";
|
|
25
25
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
26
|
-
import { addMeta } from "../../../
|
|
27
|
-
import { useValidationState } from "
|
|
26
|
+
import { addMeta } from "../../../data";
|
|
27
|
+
import { useValidationState } from "../hooks";
|
|
28
|
+
import { useSpreadsheetFilter, } from "./useSpreadsheetFilter";
|
|
29
|
+
import { filterRecordsByType, filterRecordsByError, filterRecordsBySearchValue, } from "./filterMethods";
|
|
30
|
+
import { hasValueInAnyField } from "./utils";
|
|
28
31
|
var getDefaultSortCompareFn = function (sortBy) {
|
|
29
32
|
return function (a, b) {
|
|
30
33
|
var aField = get(a, sortBy.field);
|
|
@@ -42,15 +45,15 @@ var getDefaultSortCompareFn = function (sortBy) {
|
|
|
42
45
|
};
|
|
43
46
|
var SpreadsheetContext = createContext({});
|
|
44
47
|
export var SpreadsheetContextProvider = function (_a) {
|
|
45
|
-
var initialDataSet = _a.initialDataSet, fields = _a.fields, options = _a.options, isReadOnly = _a.isReadOnly,
|
|
48
|
+
var initialDataSet = _a.initialDataSet, fields = _a.fields, options = _a.options, isReadOnly = _a.isReadOnly, children = _a.children, onValidateRecord = _a.onValidateRecord, onDataSetChanged = _a.onDataSetChanged, onValidationStateChanged = _a.onValidationStateChanged, selectedRows = _a.selectedRows, setSelectedRows = _a.setSelectedRows, _b = _a.getSortCompareFn, getSortCompareFn = _b === void 0 ? getDefaultSortCompareFn : _b;
|
|
46
49
|
var _c = useState(initialDataSet), dataSet = _c[0], setDataSet = _c[1];
|
|
47
50
|
var _d = useState(false), isLoading = _d[0], setIsLoading = _d[1];
|
|
48
51
|
var _e = useState(null), sortByFieldErrors = _e[0], setSortByFieldErrors = _e[1];
|
|
49
52
|
var _f = useState(null), sortByFieldWarnings = _f[0], setSortByFieldWarnings = _f[1];
|
|
50
53
|
var _g = useState(""), filteredInputValue = _g[0], setFilteredInputValue = _g[1];
|
|
51
|
-
var _h = useState(
|
|
52
|
-
var _j = useState(null), sortBy = _j[0], setSortBy = _j[1];
|
|
54
|
+
var _h = useState(null), sortBy = _h[0], setSortBy = _h[1];
|
|
53
55
|
var addRowTimeoutRef = useRef(null);
|
|
56
|
+
var _j = useSpreadsheetFilter(), spreadsheetFilter = _j.spreadsheetFilter, filterRecordsByRowType = _j.filterRecordsByRowType, filterRecordsByFieldErrors = _j.filterRecordsByFieldErrors, resetSpreadsheetFilter = _j.resetSpreadsheetFilter;
|
|
54
57
|
var _k = useValidationState({
|
|
55
58
|
dataSet: dataSet,
|
|
56
59
|
initialDataSet: initialDataSet,
|
|
@@ -60,7 +63,7 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
60
63
|
setDataSet: setDataSet,
|
|
61
64
|
setIsLoading: setIsLoading,
|
|
62
65
|
onValidateRecord: onValidateRecord,
|
|
63
|
-
}), updateRecordAndRevalidate = _k.updateRecordAndRevalidate, deleteRecords = _k.deleteRecords,
|
|
66
|
+
}), updateRecordAndRevalidate = _k.updateRecordAndRevalidate, deleteRecords = _k.deleteRecords, warnings = _k.warnings, errors = _k.errors, validationState = __rest(_k, ["updateRecordAndRevalidate", "deleteRecords", "warnings", "errors"]);
|
|
64
67
|
var addNewRowsToSpreadsheet = function () {
|
|
65
68
|
addRowTimeoutRef.current = setTimeout(function () {
|
|
66
69
|
var highestRowIndex = Math.max.apply(Math, Object.values(dataSet).map(function (obj) { return obj._meta.rowIndex; }));
|
|
@@ -76,16 +79,13 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
76
79
|
deleteRecords(selectedRows, errors, warnings);
|
|
77
80
|
};
|
|
78
81
|
var dataSnapshot = useMemo(function () {
|
|
82
|
+
var filteredData = spreadsheetFilter.type === "rowBased"
|
|
83
|
+
? filterRecordsByType(dataSet, spreadsheetFilter.byRow)
|
|
84
|
+
: filterRecordsByError(dataSet, spreadsheetFilter.byColumn.field, errors);
|
|
79
85
|
var filteredDatasetByString = filteredInputValue
|
|
80
|
-
? filterRecordsBySearchValue(
|
|
81
|
-
:
|
|
82
|
-
var
|
|
83
|
-
? filterRecordsByError(filteredDatasetByString, selectedErrorToFilter, errors, fields)
|
|
84
|
-
: filteredDatasetByString;
|
|
85
|
-
var dataSetValues = Object.values(filteredDatasetByError);
|
|
86
|
-
if (dataSetValues.length === 0) {
|
|
87
|
-
setSelectedErrorToFilter("");
|
|
88
|
-
}
|
|
86
|
+
? filterRecordsBySearchValue(filteredData, filteredInputValue)
|
|
87
|
+
: filteredData;
|
|
88
|
+
var dataSetValues = Object.values(filteredDatasetByString);
|
|
89
89
|
if (sortBy) {
|
|
90
90
|
return dataSetValues.sort(getSortCompareFn(sortBy));
|
|
91
91
|
}
|
|
@@ -101,12 +101,18 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
101
101
|
return dataSetValues;
|
|
102
102
|
}, [
|
|
103
103
|
filteredInputValue,
|
|
104
|
-
|
|
104
|
+
spreadsheetFilter,
|
|
105
105
|
sortBy,
|
|
106
106
|
Object.keys(dataSet).length,
|
|
107
107
|
sortByFieldErrors,
|
|
108
108
|
sortByFieldWarnings,
|
|
109
109
|
]);
|
|
110
|
+
var recordsWithValuesCount = useMemo(function () {
|
|
111
|
+
return Object.values(dataSet).filter(hasValueInAnyField).length;
|
|
112
|
+
}, [dataSet]);
|
|
113
|
+
var filteredDataCount = useMemo(function () {
|
|
114
|
+
return Object.values(dataSnapshot).filter(hasValueInAnyField).length;
|
|
115
|
+
}, [dataSnapshot]);
|
|
110
116
|
var isFiltering = useMemo(function () { return !!filteredInputValue; }, [filteredInputValue]);
|
|
111
117
|
useEffect(function () {
|
|
112
118
|
onDataSetChanged && onDataSetChanged(dataSet);
|
|
@@ -155,7 +161,7 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
155
161
|
return updatedData;
|
|
156
162
|
});
|
|
157
163
|
}, [dataSet, dataSnapshot]);
|
|
158
|
-
var value = __assign(__assign({ data: updatedDataSnapshot, fields: fields, isLoading: isLoading }, validationState), { isReadOnly: isReadOnly, sortByFieldErrors: sortByFieldErrors, sortByFieldWarnings: sortByFieldWarnings,
|
|
164
|
+
var value = __assign(__assign({ data: updatedDataSnapshot, fields: fields, isLoading: isLoading }, validationState), { isReadOnly: isReadOnly, sortByFieldErrors: sortByFieldErrors, sortByFieldWarnings: sortByFieldWarnings, options: options, recordsWithValuesCount: recordsWithValuesCount, filteredDataCount: filteredDataCount, sortBy: sortBy, warnings: warnings, errors: errors, setIsLoading: setIsLoading, setSortByFieldErrors: handleSortByFieldErrors, setSortByFieldWarnings: handleSortByFieldWarnings, onValidateRecord: onValidateRecord, updateRecord: updateRecordAndRevalidate, selectedRows: selectedRows, setSelectedRows: setSelectedRows, deleteRecords: handleDeleteErrors, filteredInputValue: filteredInputValue, setFilteredInputValue: setFilteredInputValue, lastClickedIndexRef: lastClickedIndexRef, addNewRowsToSpreadsheet: addNewRowsToSpreadsheet, spreadsheetFilter: spreadsheetFilter, resetSpreadsheetFilter: resetSpreadsheetFilter, filterRecordsByRowType: filterRecordsByRowType, filterRecordsByFieldErrors: filterRecordsByFieldErrors, checkboxColumnWidth: checkboxColumnWidth, setSortBy: setSortBy, isFiltering: isFiltering });
|
|
159
165
|
return (_jsx(SpreadsheetContext.Provider, __assign({ value: value }, { children: children })));
|
|
160
166
|
};
|
|
161
167
|
export var useSpreadsheetContext = function () { return useContext(SpreadsheetContext); };
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useSpreadsheetFilter.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type SpreadsheetFilter = {
|
|
2
|
+
type: "rowBased" | "columnBased";
|
|
3
|
+
byRow?: "all" | "invalid" | "valid";
|
|
4
|
+
byColumn?: {
|
|
5
|
+
type: "fieldWithErrors";
|
|
6
|
+
field: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const useSpreadsheetFilter: () => {
|
|
10
|
+
spreadsheetFilter: SpreadsheetFilter;
|
|
11
|
+
filterRecordsByRowType: (filterByRow: SpreadsheetFilter["byRow"]) => void;
|
|
12
|
+
filterRecordsByFieldErrors: (filterByColumn: string) => void;
|
|
13
|
+
resetSpreadsheetFilter: () => void;
|
|
14
|
+
};
|
package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider/useSpreadsheetFilter.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useReducer } from "react";
|
|
2
|
+
export var useSpreadsheetFilter = function () {
|
|
3
|
+
var filtersInitialState = {
|
|
4
|
+
type: "rowBased",
|
|
5
|
+
byRow: "all",
|
|
6
|
+
};
|
|
7
|
+
function reducer(state, action) {
|
|
8
|
+
switch (action.type) {
|
|
9
|
+
case "FILTER_BY_ROW_TYPE":
|
|
10
|
+
return { type: "rowBased", byRow: action.payload, byColumn: null };
|
|
11
|
+
case "FILTER_BY_FIELD_ERRORS":
|
|
12
|
+
return {
|
|
13
|
+
type: "columnBased",
|
|
14
|
+
byColumn: {
|
|
15
|
+
type: "fieldWithErrors",
|
|
16
|
+
field: action.payload,
|
|
17
|
+
},
|
|
18
|
+
byRow: null,
|
|
19
|
+
};
|
|
20
|
+
case "RESTORE_FILTERS":
|
|
21
|
+
return filtersInitialState;
|
|
22
|
+
default:
|
|
23
|
+
return state;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var _a = useReducer(reducer, filtersInitialState), spreadsheetFilter = _a[0], filtersDispatch = _a[1];
|
|
27
|
+
var resetSpreadsheetFilter = function () {
|
|
28
|
+
filtersDispatch({ type: "RESTORE_FILTERS" });
|
|
29
|
+
};
|
|
30
|
+
var filterRecordsByRowType = function (filterByRow) {
|
|
31
|
+
filtersDispatch({ type: "FILTER_BY_ROW_TYPE", payload: filterByRow });
|
|
32
|
+
};
|
|
33
|
+
var filterRecordsByFieldErrors = function (filterByColumn) {
|
|
34
|
+
filtersDispatch({
|
|
35
|
+
type: "FILTER_BY_FIELD_ERRORS",
|
|
36
|
+
payload: filterByColumn,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
spreadsheetFilter: spreadsheetFilter,
|
|
41
|
+
filterRecordsByRowType: filterRecordsByRowType,
|
|
42
|
+
filterRecordsByFieldErrors: filterRecordsByFieldErrors,
|
|
43
|
+
resetSpreadsheetFilter: resetSpreadsheetFilter,
|
|
44
|
+
};
|
|
45
|
+
};
|