fuse-importer 0.25.9 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/Importer/Matcher/EnumFieldsMatchers/EnumFieldMatcher/index.js +11 -1
- package/lib/esm/Importer/Review/ReviewWithContext.js +4 -8
- package/lib/esm/Importer/Uploader/HeadersPreview.js +5 -9
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider.d.ts +3 -3
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider.js +30 -12
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetData.js +28 -2
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.d.ts +1 -2
- package/lib/esm/Importer/common/Spreadsheet/components/SpreadsheetRowCheckboxes.js +1 -1
- package/lib/esm/Importer/common/Spreadsheet/hooks.d.ts +4 -2
- package/lib/esm/Importer/common/Spreadsheet/hooks.js +3 -66
- package/lib/esm/Importer/common/Spreadsheet/index.d.ts +1 -2
- package/lib/esm/Importer/common/Spreadsheet/index.js +2 -2
- package/lib/esm/Importer/common/Spreadsheet/styles.d.ts +1 -1
- package/lib/esm/Importer/common/Spreadsheet/styles.js +2 -2
- package/lib/esm/Importer/common/utils.d.ts +0 -1
- package/lib/esm/Importer/common/utils.js +0 -4
- package/lib/esm/Importer/data/index.d.ts +7 -2
- package/lib/esm/Importer/data/index.js +18 -10
- package/lib/esm/Importer/index.js +0 -2
- package/lib/esm/common/Table/TableActions/DeleteSelectedRows.js +10 -4
- package/lib/esm/common/Table/TableActions/ExportData.js +3 -1
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.d.ts +1 -0
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +35 -0
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.styles.d.ts +6 -0
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.styles.js +24 -0
- package/lib/esm/common/Table/TableActions/FilterByErrors/functions.d.ts +11 -0
- package/lib/esm/common/Table/TableActions/FilterByErrors/functions.js +35 -0
- package/lib/esm/common/Table/TableActions/FilterByErrors/index.d.ts +1 -0
- package/lib/esm/common/Table/TableActions/FilterByErrors/index.js +1 -0
- 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/TableActions.styles.js +1 -1
- package/lib/esm/common/Table/TableActions/hooks.d.ts +21 -0
- package/lib/esm/common/Table/TableActions/hooks.js +84 -0
- package/lib/esm/common/Table/TableView/TableHeaders.d.ts +6 -8
- package/lib/esm/common/Table/TableView/TableHeaders.js +15 -14
- package/lib/esm/common/Table/TableView/{TableRow.d.ts → TableRows/TableRow.d.ts} +5 -5
- package/lib/esm/common/Table/TableView/{TableRow.js → TableRows/TableRow.js} +9 -6
- package/lib/esm/common/Table/TableView/TableRows/index.d.ts +4 -0
- package/lib/esm/common/Table/TableView/{TableCells.js → TableRows/index.js} +13 -11
- package/lib/esm/common/Table/TableView/common/index.d.ts +5 -0
- package/lib/esm/common/Table/TableView/{common.js → common/index.js} +18 -5
- package/lib/esm/common/Table/TableView/index.d.ts +4 -39
- package/lib/esm/common/Table/TableView/index.js +48 -65
- package/lib/esm/common/Table/TableView/types.d.ts +37 -0
- package/lib/esm/common/Table/TableView/types.js +1 -0
- package/lib/esm/common/Table/index.d.ts +2 -2
- package/lib/esm/common/Table/index.js +6 -6
- package/lib/esm/common/inputs/Autocomplete.d.ts +2 -1
- package/lib/esm/common/inputs/Autocomplete.js +2 -2
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +15 -0
- package/lib/esm/locales/de.d.ts +21 -0
- package/lib/esm/locales/de.js +21 -0
- package/lib/esm/locales/en.d.ts +21 -0
- package/lib/esm/locales/en.js +21 -0
- package/lib/esm/locales/es.d.ts +21 -0
- package/lib/esm/locales/es.js +21 -0
- package/lib/esm/locales/fr.d.ts +21 -0
- package/lib/esm/locales/fr.js +21 -0
- package/lib/esm/types.d.ts +1 -0
- package/lib/main.js +12 -12
- package/package.json +1 -1
- package/lib/esm/Importer/useFullscreenOverlay.d.ts +0 -1
- package/lib/esm/Importer/useFullscreenOverlay.js +0 -14
- package/lib/esm/common/Table/TableView/TableCells.d.ts +0 -4
- package/lib/esm/common/Table/TableView/common.d.ts +0 -9
|
@@ -42,7 +42,17 @@ export var EnumFieldMatcher = function (_a) {
|
|
|
42
42
|
index: index,
|
|
43
43
|
isMatched: !!enumFieldValueMatching[uploadedDataValue],
|
|
44
44
|
}); })
|
|
45
|
-
.sort(function (a, b) {
|
|
45
|
+
.sort(function (a, b) {
|
|
46
|
+
if (a.isMatched === b.isMatched) {
|
|
47
|
+
return a.index - b.index;
|
|
48
|
+
}
|
|
49
|
+
else if (a.isMatched) {
|
|
50
|
+
return -1;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
46
56
|
//sort data based on automatched items
|
|
47
57
|
var sortedData = dataSortingOrderRef.current.map(function (sorting) { return data[sorting.index]; });
|
|
48
58
|
var tableRowHeight = 100;
|
|
@@ -14,23 +14,19 @@ var __assign = (this && this.__assign) || function () {
|
|
|
14
14
|
return __assign.apply(this, arguments);
|
|
15
15
|
};
|
|
16
16
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
-
import {
|
|
17
|
+
import { useTranslation } from "react-i18next";
|
|
18
|
+
import styled from "styled-components";
|
|
18
19
|
import { Div } from "../../styled/utils";
|
|
19
20
|
import Spreadsheet from "../common/Spreadsheet";
|
|
20
|
-
import {
|
|
21
|
+
import { useImporterContext } from "../contexts/ImporterContextProvider";
|
|
21
22
|
import { AppResponseModal } from "./AppResponseModal";
|
|
22
23
|
import { useReviewContext } from "./ReviewContextProvider";
|
|
23
|
-
import styled from "styled-components";
|
|
24
|
-
import { useTranslation } from "react-i18next";
|
|
25
|
-
import useWindowDimensions from "../../utils/hooks/useWindowSize";
|
|
26
24
|
var TitleContainer = styled(Div)(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""])));
|
|
27
25
|
var ReviewWithContext = function () {
|
|
28
26
|
var _a = useReviewContext(), fields = _a.reviewFields, initialDataSet = _a.reviewInitialDataSet, options = _a.options, onValidateRecord = _a.onValidateRecord, onDataSetChanged = _a.onDataSetChanged, onValidationStateChanged = _a.onValidationStateChanged;
|
|
29
|
-
var isOnSmallScreens = useWindowDimensions().isOnSmallScreens;
|
|
30
27
|
var _b = useImporterContext(), selectedRows = _b.selectedRows, setSelectedRows = _b.setSelectedRows, isUsingManualImport = _b.isUsingManualImport;
|
|
31
28
|
var t = useTranslation("review").t;
|
|
32
|
-
var
|
|
33
|
-
var spreadsheetUI = initialDataSet && (_jsx(Spreadsheet, { options: __assign(__assign({}, options), { showCheckboxColumn: true }), selectedRows: selectedRows, setSelectedRows: setSelectedRows, initialDataSet: initialDataSet, fields: fields, rowWidth: rowWidth, onDataSetChanged: onDataSetChanged, onValidateRecord: onValidateRecord, onValidationStateChanged: onValidationStateChanged }));
|
|
29
|
+
var spreadsheetUI = initialDataSet && (_jsx(Spreadsheet, { options: __assign(__assign({}, options), { showCheckboxColumn: true }), selectedRows: selectedRows, setSelectedRows: setSelectedRows, initialDataSet: initialDataSet, fields: fields, onDataSetChanged: onDataSetChanged, onValidateRecord: onValidateRecord, onValidationStateChanged: onValidationStateChanged }));
|
|
34
30
|
return (_jsxs(Div, __assign({ centered: true, flexColumn: true, h100: true }, { children: [_jsx(AppResponseModal, {}), _jsxs(Div, __assign({ w100: true, h100: true, flexColumn: true }, { children: [_jsx(TitleContainer, __assign({ flexColumn: true, ml: 32 }, { children: _jsx(Div, __assign({ h2: true, mt: 40, mb: 40 }, { children: t(isUsingManualImport.current ? "manual_importer_title" : "title") })) })), _jsx(Div, __assign({ h100: true, w100: true, justifyCenter: true }, { children: spreadsheetUI }))] }))] })));
|
|
35
31
|
};
|
|
36
32
|
export default ReviewWithContext;
|
|
@@ -14,24 +14,20 @@ var __assign = (this && this.__assign) || function () {
|
|
|
14
14
|
return __assign.apply(this, arguments);
|
|
15
15
|
};
|
|
16
16
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
import { useTranslation } from "react-i18next";
|
|
18
|
+
import styled from "styled-components";
|
|
17
19
|
import { Div } from "../../styled/utils";
|
|
18
|
-
import Spreadsheet from "../common/Spreadsheet";
|
|
19
|
-
import { getSpreadsheetRowWidth } from "../common/utils";
|
|
20
20
|
import { useReviewContext } from "../Review/ReviewContextProvider";
|
|
21
|
-
import
|
|
21
|
+
import Spreadsheet from "../common/Spreadsheet";
|
|
22
22
|
import { useImporterContext } from "../contexts/ImporterContextProvider";
|
|
23
|
-
import {
|
|
24
|
-
import styled from "styled-components";
|
|
25
|
-
import useWindowDimensions from "../../utils/hooks/useWindowSize";
|
|
23
|
+
import { HeaderButtons } from "./HeaderButtons";
|
|
26
24
|
var HeaderContainer = styled(Div)(templateObject_1 || (templateObject_1 = __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
25
|
var DescriptionAndButtons = styled(Div)(templateObject_2 || (templateObject_2 = __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"])));
|
|
28
26
|
var HeadersPreview = function () {
|
|
29
27
|
var _a = useReviewContext(), fields = _a.previewFields, initialDataSet = _a.previewInitialDataSet;
|
|
30
|
-
var isOnSmallScreens = useWindowDimensions().isOnSmallScreens;
|
|
31
28
|
var t = useTranslation("upload").t;
|
|
32
29
|
var _b = useImporterContext(), selectedRows = _b.selectedRows, setSelectedRows = _b.setSelectedRows;
|
|
33
|
-
|
|
34
|
-
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, { rowWidth: rowWidth, isReadOnly: true, initialDataSet: initialDataSet, fields: fields, highlightFirstRow: true, options: {
|
|
30
|
+
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, highlightFirstRow: true, options: {
|
|
35
31
|
showCheckboxColumn: true,
|
|
36
32
|
firstRowIsHeader: true,
|
|
37
33
|
}, selectedRows: selectedRows, setSelectedRows: setSelectedRows })) }))] })));
|
|
@@ -5,7 +5,6 @@ import { ValidationState } from "./hooks";
|
|
|
5
5
|
export type OnDataSetChanged = (dataSet: RecordDataSet) => void;
|
|
6
6
|
export type OnValidationStateChanged = (state: ValidationState) => void;
|
|
7
7
|
type State = {
|
|
8
|
-
rowWidth?: number;
|
|
9
8
|
data: Record[];
|
|
10
9
|
fields: Field[];
|
|
11
10
|
isLoading: boolean;
|
|
@@ -24,13 +23,14 @@ type State = {
|
|
|
24
23
|
lastClickedIndexRef: React.MutableRefObject<number | null>;
|
|
25
24
|
filteredInputValue: string;
|
|
26
25
|
setFilteredInputValue: React.Dispatch<React.SetStateAction<string>>;
|
|
26
|
+
selectedErrorToFilter: string;
|
|
27
|
+
setSelectedErrorToFilter: React.Dispatch<React.SetStateAction<string>>;
|
|
27
28
|
addNewRowsToSpreadsheet: () => void;
|
|
28
29
|
checkboxColumnWidth: number;
|
|
29
30
|
isFiltering: boolean;
|
|
30
31
|
} & ValidationState;
|
|
31
32
|
type Props = {
|
|
32
33
|
initialDataSet: RecordDataSet;
|
|
33
|
-
rowWidth?: number;
|
|
34
34
|
isReadOnly?: boolean;
|
|
35
35
|
children: JSX.Element;
|
|
36
36
|
fields: Field[];
|
|
@@ -42,6 +42,6 @@ type Props = {
|
|
|
42
42
|
selectedRows: string[];
|
|
43
43
|
setSelectedRows: React.Dispatch<React.SetStateAction<string[]>>;
|
|
44
44
|
};
|
|
45
|
-
export declare const SpreadsheetContextProvider: ({ initialDataSet,
|
|
45
|
+
export declare const SpreadsheetContextProvider: ({ initialDataSet, fields, options, isReadOnly, highlightFirstRow, children, onValidateRecord, onDataSetChanged, onValidationStateChanged, selectedRows, setSelectedRows, }: Props) => JSX.Element;
|
|
46
46
|
export declare const useSpreadsheetContext: () => State;
|
|
47
47
|
export {};
|
|
@@ -23,16 +23,17 @@ 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 { useValidationState } from "./hooks";
|
|
27
26
|
import { addMeta } from "../../../Importer/data";
|
|
27
|
+
import { useValidationState } from "./hooks";
|
|
28
28
|
var SpreadsheetContext = createContext({});
|
|
29
29
|
export var SpreadsheetContextProvider = function (_a) {
|
|
30
|
-
var initialDataSet = _a.initialDataSet,
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
30
|
+
var initialDataSet = _a.initialDataSet, fields = _a.fields, options = _a.options, isReadOnly = _a.isReadOnly, highlightFirstRow = _a.highlightFirstRow, children = _a.children, onValidateRecord = _a.onValidateRecord, onDataSetChanged = _a.onDataSetChanged, onValidationStateChanged = _a.onValidationStateChanged, selectedRows = _a.selectedRows, setSelectedRows = _a.setSelectedRows;
|
|
31
|
+
var _b = useState(initialDataSet), dataSet = _b[0], setDataSet = _b[1];
|
|
32
|
+
var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
|
|
33
|
+
var _d = useState(null), sortByFieldErrors = _d[0], setSortByFieldErrors = _d[1];
|
|
34
|
+
var _e = useState(null), sortByFieldWarnings = _e[0], setSortByFieldWarnings = _e[1];
|
|
35
|
+
var _f = useState(""), filteredInputValue = _f[0], setFilteredInputValue = _f[1];
|
|
36
|
+
var _g = useState(""), selectedErrorToFilter = _g[0], setSelectedErrorToFilter = _g[1];
|
|
36
37
|
var sortByCurrentErrorsRef = useRef({});
|
|
37
38
|
var sortByCurrentWarningsRef = useRef({});
|
|
38
39
|
var _h = useValidationState({
|
|
@@ -44,7 +45,7 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
44
45
|
setDataSet: setDataSet,
|
|
45
46
|
setIsLoading: setIsLoading,
|
|
46
47
|
onValidateRecord: onValidateRecord,
|
|
47
|
-
}), errorsRef = _h.errorsRef, warningsRef = _h.warningsRef, updateRecordAndRevalidate = _h.updateRecordAndRevalidate, deleteRecords = _h.deleteRecords, filterRecordsBySearchValue = _h.filterRecordsBySearchValue, validationState = __rest(_h, ["errorsRef", "warningsRef", "updateRecordAndRevalidate", "deleteRecords", "filterRecordsBySearchValue"]);
|
|
48
|
+
}), errorsRef = _h.errorsRef, warningsRef = _h.warningsRef, updateRecordAndRevalidate = _h.updateRecordAndRevalidate, deleteRecords = _h.deleteRecords, filterRecordsBySearchValue = _h.filterRecordsBySearchValue, filterRecordsByError = _h.filterRecordsByError, validationState = __rest(_h, ["errorsRef", "warningsRef", "updateRecordAndRevalidate", "deleteRecords", "filterRecordsBySearchValue", "filterRecordsByError"]);
|
|
48
49
|
var addNewRowsToSpreadsheet = useCallback(function () {
|
|
49
50
|
var highestRowIndex = Math.max.apply(Math, Object.values(dataSet).map(function (obj) { return obj._meta.rowIndex; }));
|
|
50
51
|
var newRow = addMeta({}, highestRowIndex + 1);
|
|
@@ -53,10 +54,21 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
53
54
|
return (__assign(__assign({}, oldValues), (_a = {}, _a[newRow._meta.id] = newRow, _a)));
|
|
54
55
|
});
|
|
55
56
|
}, [dataSet]);
|
|
57
|
+
var handleDeleteErrors = useCallback(function (selectedRows) {
|
|
58
|
+
deleteRecords(dataSet, selectedRows, errorsRef.current, warningsRef.current);
|
|
59
|
+
}, []);
|
|
56
60
|
// sort data based on errors (errors group on top and not errors group at bottom)
|
|
57
61
|
var data = useMemo(function () {
|
|
58
|
-
var
|
|
59
|
-
|
|
62
|
+
var filteredDatasetByString = filteredInputValue
|
|
63
|
+
? filterRecordsBySearchValue(dataSet, filteredInputValue, fields)
|
|
64
|
+
: dataSet;
|
|
65
|
+
var filteredDatasetByError = selectedErrorToFilter
|
|
66
|
+
? filterRecordsByError(filteredDatasetByString, selectedErrorToFilter, errorsRef.current, fields)
|
|
67
|
+
: filteredDatasetByString;
|
|
68
|
+
var dataSetValues = Object.values(filteredDatasetByError);
|
|
69
|
+
if (dataSetValues.length === 0) {
|
|
70
|
+
setSelectedErrorToFilter("");
|
|
71
|
+
}
|
|
60
72
|
var errors = sortByCurrentErrorsRef.current; //Sort errors snapshot
|
|
61
73
|
var warnings = sortByCurrentWarningsRef.current; //Sort warnings snapshot
|
|
62
74
|
if (!sortByFieldErrors && !sortByFieldWarnings)
|
|
@@ -69,7 +81,13 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
69
81
|
}
|
|
70
82
|
return bHasErrors ? 1 : -1;
|
|
71
83
|
});
|
|
72
|
-
}, [
|
|
84
|
+
}, [
|
|
85
|
+
dataSet,
|
|
86
|
+
filteredInputValue,
|
|
87
|
+
selectedErrorToFilter,
|
|
88
|
+
sortByFieldErrors,
|
|
89
|
+
sortByFieldWarnings,
|
|
90
|
+
]);
|
|
73
91
|
var isFiltering = useMemo(function () { return !!filteredInputValue; }, [filteredInputValue]);
|
|
74
92
|
useEffect(function () {
|
|
75
93
|
onDataSetChanged && onDataSetChanged(dataSet);
|
|
@@ -112,7 +130,7 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
112
130
|
var baseCheckboxColumnWidth = lastRowIndexLength * singleLetterWidth + horizontalSpacing;
|
|
113
131
|
return baseCheckboxColumnWidth < 40 ? 40 : baseCheckboxColumnWidth;
|
|
114
132
|
}, [data]);
|
|
115
|
-
var value = __assign(__assign({ data: data, fields: fields, isLoading: isLoading }, validationState), { isReadOnly: isReadOnly,
|
|
133
|
+
var value = __assign(__assign({ data: data, fields: fields, isLoading: isLoading }, validationState), { isReadOnly: isReadOnly, sortByFieldErrors: sortByFieldErrors, sortByFieldWarnings: sortByFieldWarnings, highlightFirstRow: highlightFirstRow, options: options, setIsLoading: setIsLoading, setSortByFieldErrors: handleSortByFieldErrors, setSortByFieldWarnings: handleSortByFieldWarnings, onValidateRecord: onValidateRecord, updateRecord: updateRecordAndRevalidate, selectedRows: selectedRows, setSelectedRows: setSelectedRows, deleteRecords: handleDeleteErrors, filteredInputValue: filteredInputValue, setFilteredInputValue: setFilteredInputValue, lastClickedIndexRef: lastClickedIndexRef, addNewRowsToSpreadsheet: addNewRowsToSpreadsheet, checkboxColumnWidth: checkboxColumnWidth, selectedErrorToFilter: selectedErrorToFilter, setSelectedErrorToFilter: setSelectedErrorToFilter, isFiltering: isFiltering });
|
|
116
134
|
return (_jsx(SpreadsheetContext.Provider, __assign({ value: value }, { children: children })));
|
|
117
135
|
};
|
|
118
136
|
export var useSpreadsheetContext = function () { return useContext(SpreadsheetContext); };
|
|
@@ -35,13 +35,39 @@ import { SpreadsheetRowCheckboxes } from "./SpreadsheetRowCheckboxes";
|
|
|
35
35
|
import ValidationProgress from "./ValidationProgress";
|
|
36
36
|
import { TableActions } from "../../../../common/Table/TableActions";
|
|
37
37
|
import { useImporterContext } from "../../../../Importer/contexts/ImporterContextProvider";
|
|
38
|
+
import useWindowDimensions from "../../../../utils/hooks/useWindowSize";
|
|
38
39
|
var getItemKey = function (record) { return record._meta.id; };
|
|
39
40
|
var SpreadsheetData = function () {
|
|
40
|
-
var _a = useSpreadsheetContext(), fields = _a.fields, data = _a.data, isLoading = _a.isLoading, isReadOnly = _a.isReadOnly,
|
|
41
|
+
var _a = useSpreadsheetContext(), fields = _a.fields, data = _a.data, isLoading = _a.isLoading, isReadOnly = _a.isReadOnly, totalErrors = _a.totalErrors, validationPercentage = _a.validationPercentage, setSortByFieldErrors = _a.setSortByFieldErrors, options = _a.options, setSortByFieldWarnings = _a.setSortByFieldWarnings, selectedRows = _a.selectedRows, checkboxColumnWidth = _a.checkboxColumnWidth, isFiltering = _a.isFiltering;
|
|
41
42
|
var currentStepIndex = useImporterContext().currentStepIndex;
|
|
43
|
+
var isOnSmallScreens = useWindowDimensions().isOnSmallScreens;
|
|
42
44
|
var canShowCheckboxOnCheckboxRowHover = currentStepIndex === 2;
|
|
43
45
|
var rowNumbersGridRef = useRef();
|
|
44
46
|
var rowCheckboxesGridRef = useRef();
|
|
47
|
+
var rowWidthScalingFactor = (function () {
|
|
48
|
+
// Spreadsheet will display 6 columns on the viewport and a small portion of the
|
|
49
|
+
// 7th column in the right side to let the user know they can scroll horizontally
|
|
50
|
+
var visibleColumnsOnTableViewport = 6;
|
|
51
|
+
// by multiplying by horizontalScrollVisibilityRatio the final rowWidth for the spreadsheet
|
|
52
|
+
// will be reduced in order to partially display the last column on the right side
|
|
53
|
+
// 0.95 was chosen because it's the ratio that looks better on the UI on desktop
|
|
54
|
+
// 0.9 was chosen because it's the ratio that looks better on the UI on mobile
|
|
55
|
+
var horizontalScrollVisibilityRatio = 0.95;
|
|
56
|
+
if (isOnSmallScreens) {
|
|
57
|
+
// When the screen is too small the Spreadsheet will display 3 columns on the viewport
|
|
58
|
+
// and a small portion of the 4th column in the right side to let the user know they can scroll horizontally
|
|
59
|
+
visibleColumnsOnTableViewport = 3;
|
|
60
|
+
horizontalScrollVisibilityRatio = 0.9;
|
|
61
|
+
}
|
|
62
|
+
var res = fields.length / visibleColumnsOnTableViewport;
|
|
63
|
+
if (res <= 1)
|
|
64
|
+
return 1;
|
|
65
|
+
/*
|
|
66
|
+
multiply the rowWidthScalingFactor by 0.95/0.9 to let the user know they can scroll
|
|
67
|
+
horizontally (will display partial column on the right)
|
|
68
|
+
*/
|
|
69
|
+
return res * horizontalScrollVisibilityRatio;
|
|
70
|
+
})();
|
|
45
71
|
var sortByErrors = useCallback(function (field) {
|
|
46
72
|
return setSortByFieldErrors(function (sortByFieldErrors) {
|
|
47
73
|
return sortByFieldErrors === field ? null : field;
|
|
@@ -84,6 +110,6 @@ var SpreadsheetData = function () {
|
|
|
84
110
|
}, [dataLength]);
|
|
85
111
|
var showValidationProgress = !isReadOnly && validationPercentage < 100;
|
|
86
112
|
var isReviewStep = currentStepIndex === 2;
|
|
87
|
-
return (_jsxs(S.SpreadSheetData, __assign({ h100: true, flexColumn: true }, { children: [_jsx(GlobalStyle, {}), showValidationProgress && (_jsx(Div, __assign({ h: 32 }, { children: _jsx(ValidationProgress, { totalErrors: totalErrors, validationPercentage: validationPercentage }) }))), _jsxs(S.SpreadSheetContainer, __assign({ flexColumn: true, w100: true, h100: true }, { children: [_jsx(Div, __assign({ w100: true, justifyCenter: true }, { children: isReviewStep && _jsx(TableActions, {}) })), _jsxs(S.SpreadSheetWrapper, __assign({ canShowCheckboxOnHover: !showValidationProgress && canShowCheckboxOnCheckboxRowHover, shouldShowOnlyCheckbox: !showValidationProgress && selectedRows.length > 0, dflex: true, h100: true }, { children: [(options === null || options === void 0 ? void 0 : options.showCheckboxColumn) && (_jsx(SpreadsheetRowCheckboxes, { gridRef: rowCheckboxesGridRef,
|
|
113
|
+
return (_jsxs(S.SpreadSheetData, __assign({ h100: true, flexColumn: true }, { children: [_jsx(GlobalStyle, {}), showValidationProgress && (_jsx(Div, __assign({ h: 32 }, { children: _jsx(ValidationProgress, { totalErrors: totalErrors, validationPercentage: validationPercentage }) }))), _jsxs(S.SpreadSheetContainer, __assign({ flexColumn: true, w100: true, h100: true }, { children: [_jsx(Div, __assign({ w100: true, justifyCenter: true }, { children: isReviewStep && _jsx(TableActions, {}) })), _jsxs(S.SpreadSheetWrapper, __assign({ canShowCheckboxOnHover: !showValidationProgress && canShowCheckboxOnCheckboxRowHover, shouldShowOnlyCheckbox: !showValidationProgress && selectedRows.length > 0, dflex: true, h100: true }, { children: [(options === null || options === void 0 ? void 0 : options.showCheckboxColumn) && (_jsx(SpreadsheetRowCheckboxes, { gridRef: rowCheckboxesGridRef, height: spreadsheetHeight, firstRowIsHeader: options === null || options === void 0 ? void 0 : options.firstRowIsHeader, isLoadingData: showValidationProgress })), _jsx(S.TableView, { tableHeadersHeight: spreadsheetHeaderHeightPx, highlightFirstRow: isReadOnly, rowHeight: spreadsheetRowHeightPx, h: null, rowWidthScalingFactor: rowWidthScalingFactor, data: data, columns: columns, isLoading: isLoading, onTableScroll: onTableScroll, getItemKey: getItemKey, checkboxColumnWidth: checkboxColumnWidth, isFiltering: isFiltering })] }))] }))] })));
|
|
88
114
|
};
|
|
89
115
|
export default React.memo(SpreadsheetData, areEqual);
|
|
@@ -2,10 +2,9 @@ import React from "react";
|
|
|
2
2
|
import { DivCSSProps } from "../../../../styled/utils";
|
|
3
3
|
type Props = {
|
|
4
4
|
height?: number;
|
|
5
|
-
spreadsheetHasXScroll?: boolean;
|
|
6
5
|
gridRef: React.MutableRefObject<any>;
|
|
7
6
|
firstRowIsHeader?: boolean;
|
|
8
7
|
isLoadingData?: boolean;
|
|
9
8
|
} & DivCSSProps;
|
|
10
|
-
export declare const SpreadsheetRowCheckboxes: ({ height,
|
|
9
|
+
export declare const SpreadsheetRowCheckboxes: ({ height, gridRef, firstRowIsHeader, isLoadingData, ...props }: Props) => JSX.Element;
|
|
11
10
|
export {};
|
|
@@ -62,7 +62,7 @@ var rowIsEmpty = function (row) {
|
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
64
|
export var SpreadsheetRowCheckboxes = function (_a) {
|
|
65
|
-
var height = _a.height,
|
|
65
|
+
var height = _a.height, gridRef = _a.gridRef, _b = _a.firstRowIsHeader, firstRowIsHeader = _b === void 0 ? false : _b, isLoadingData = _a.isLoadingData, props = __rest(_a, ["height", "gridRef", "firstRowIsHeader", "isLoadingData"]);
|
|
66
66
|
var _c = useSpreadsheetContext(), data = _c.data, selectedRows = _c.selectedRows, lastClickedIndexRef = _c.lastClickedIndexRef, setSelectedRows = _c.setSelectedRows, checkboxColumnWidth = _c.checkboxColumnWidth;
|
|
67
67
|
var currentStepIndex = useImporterContext().currentStepIndex;
|
|
68
68
|
var nonEmptyRows = useMemo(function () { return data.filter(function (row) { return !rowIsEmpty(row); }); }, [
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { SpreadsheetOptions } from "../../..";
|
|
3
3
|
import { BatchValidationErrors, Field, OnValidateRecord, Record, RecordDataSet } from "../../../types";
|
|
4
|
+
import { DeleteRecords, FilterRecordsByError, FilterRecordsBySearchValue } from "../../../common/Table/TableActions/hooks";
|
|
4
5
|
type UseValidationStateArgs = {
|
|
5
6
|
onValidateRecord?: OnValidateRecord;
|
|
6
7
|
setDataSet: React.Dispatch<React.SetStateAction<RecordDataSet>>;
|
|
@@ -26,8 +27,9 @@ export type ValidationState = {
|
|
|
26
27
|
};
|
|
27
28
|
};
|
|
28
29
|
type UseValidationStateReturnValue = ValidationState & {
|
|
29
|
-
deleteRecords:
|
|
30
|
-
filterRecordsBySearchValue:
|
|
30
|
+
deleteRecords: DeleteRecords;
|
|
31
|
+
filterRecordsBySearchValue: FilterRecordsBySearchValue;
|
|
32
|
+
filterRecordsByError: FilterRecordsByError;
|
|
31
33
|
updateRecordAndRevalidate: (record: Record) => Promise<void>;
|
|
32
34
|
errorsRef: React.MutableRefObject<BatchValidationErrors>;
|
|
33
35
|
warningsRef: React.MutableRefObject<BatchValidationErrors>;
|
|
@@ -49,45 +49,10 @@ import { omit, set } from "lodash";
|
|
|
49
49
|
import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
|
|
50
50
|
import { sleep } from "../../..";
|
|
51
51
|
import { selectValidatorsFor, validateRecord } from "./validation";
|
|
52
|
-
import {
|
|
52
|
+
import { useTableActions, } from "../../../common/Table/TableActions/hooks";
|
|
53
53
|
var checkIfHasErrors = function (errors) {
|
|
54
54
|
return errors && Object.keys(errors).length > 0;
|
|
55
55
|
};
|
|
56
|
-
var removeItemsFromObject = function (obj, idsToRemove) {
|
|
57
|
-
var _a;
|
|
58
|
-
var idSet = new Set(idsToRemove);
|
|
59
|
-
var newObj = {};
|
|
60
|
-
for (var key in obj) {
|
|
61
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
62
|
-
var meta = (_a = obj[key]) === null || _a === void 0 ? void 0 : _a._meta;
|
|
63
|
-
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))) {
|
|
64
|
-
newObj[key] = obj[key];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return newObj;
|
|
69
|
-
};
|
|
70
|
-
var removeErrorsOrWarningsFromObject = function (obj, keysToRemove) {
|
|
71
|
-
var keysSet = new Set(keysToRemove);
|
|
72
|
-
var newObj = {};
|
|
73
|
-
for (var key in obj) {
|
|
74
|
-
if (Object.prototype.hasOwnProperty.call(obj, key) && !(keysSet === null || keysSet === void 0 ? void 0 : keysSet.has(key))) {
|
|
75
|
-
newObj[key] = obj[key];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return newObj;
|
|
79
|
-
};
|
|
80
|
-
var isObject = function (value) {
|
|
81
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
82
|
-
};
|
|
83
|
-
var includesSearchValue = function (value, searchValue) {
|
|
84
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
85
|
-
var stringValue = String(value).toLowerCase();
|
|
86
|
-
var searchValueLower = searchValue.toLowerCase();
|
|
87
|
-
return stringValue.includes(searchValueLower);
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
};
|
|
91
56
|
export var useValidationState = function (_a) {
|
|
92
57
|
var initialDataSet = _a.initialDataSet, //Initial Data Set, used to run the initial validation
|
|
93
58
|
dataSet = _a.dataSet, //Current Updated Data Set
|
|
@@ -98,36 +63,7 @@ export var useValidationState = function (_a) {
|
|
|
98
63
|
var validatorsCache = useMemo(function () { return selectValidatorsFor(fields); }, [fields]);
|
|
99
64
|
var errorsRef = useRef(errors);
|
|
100
65
|
var warningsRef = useRef(warnings);
|
|
101
|
-
|
|
102
|
-
var deleteRecords = function (selectedRecords) {
|
|
103
|
-
var newDataSet = removeItemsFromObject(dataSet, selectedRecords);
|
|
104
|
-
var newErrors = removeErrorsOrWarningsFromObject(errors, selectedRecords);
|
|
105
|
-
var newWarnings = removeErrorsOrWarningsFromObject(warnings, selectedRecords);
|
|
106
|
-
setDataSet(newDataSet);
|
|
107
|
-
setErrors(newErrors);
|
|
108
|
-
setWarnings(newWarnings);
|
|
109
|
-
};
|
|
110
|
-
//Filter records by search value
|
|
111
|
-
var filterRecordsBySearchValue = function (obj, value) {
|
|
112
|
-
var filteredObj = {};
|
|
113
|
-
for (var _i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
|
|
114
|
-
var _b = _a[_i], key = _b[0], currentObj = _b[1];
|
|
115
|
-
if (isObject(currentObj)) {
|
|
116
|
-
var matches = Object.values(currentObj).some(function (propertyValue) {
|
|
117
|
-
return includesSearchValue(propertyValue, value);
|
|
118
|
-
});
|
|
119
|
-
if (matches) {
|
|
120
|
-
filteredObj[key] = currentObj;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// To ensure that rows are always displayed, even when the search query is empty,
|
|
125
|
-
// we return an empty record list when the search yields no results.
|
|
126
|
-
if (Object.keys(filteredObj).length === 0) {
|
|
127
|
-
return recordListToDataSet(addEmptyRows([], fields), fields);
|
|
128
|
-
}
|
|
129
|
-
return filteredObj;
|
|
130
|
-
};
|
|
66
|
+
var _e = useTableActions({ setDataSet: setDataSet, setErrors: setErrors, setWarnings: setWarnings }), deleteRecords = _e.deleteRecords, filterRecordsByError = _e.filterRecordsByError, filterRecordsBySearchValue = _e.filterRecordsBySearchValue;
|
|
131
67
|
//Validate record and update dataSet
|
|
132
68
|
var updateRecordAndRevalidate = useCallback(function (record) { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
69
|
var recordId, newDataSet, data, _a, recordErrors, recordWarnings, hasError, hasWarning;
|
|
@@ -298,5 +234,6 @@ export var useValidationState = function (_a) {
|
|
|
298
234
|
updateRecordAndRevalidate: updateRecordAndRevalidate,
|
|
299
235
|
deleteRecords: deleteRecords,
|
|
300
236
|
filterRecordsBySearchValue: filterRecordsBySearchValue,
|
|
237
|
+
filterRecordsByError: filterRecordsByError,
|
|
301
238
|
};
|
|
302
239
|
};
|
|
@@ -3,7 +3,6 @@ import { Field, OnValidateRecord, Record, RecordDataSet, SpreadsheetOptions } fr
|
|
|
3
3
|
import { OnDataSetChanged, OnValidationStateChanged } from "./SpreadsheetContextProvider";
|
|
4
4
|
export type SpreadsheetProps = {
|
|
5
5
|
initialDataSet: RecordDataSet;
|
|
6
|
-
rowWidth?: number;
|
|
7
6
|
isReadOnly?: boolean;
|
|
8
7
|
fields?: Field[];
|
|
9
8
|
submittedData?: Record[];
|
|
@@ -15,7 +14,7 @@ export type SpreadsheetProps = {
|
|
|
15
14
|
selectedRows?: string[];
|
|
16
15
|
setSelectedRows?: React.Dispatch<React.SetStateAction<string[]>>;
|
|
17
16
|
};
|
|
18
|
-
declare const _default: React.MemoExoticComponent<({ isReadOnly, initialDataSet,
|
|
17
|
+
declare const _default: React.MemoExoticComponent<({ isReadOnly, initialDataSet, fields, options, highlightFirstRow, onValidateRecord, onDataSetChanged, onValidationStateChanged, selectedRows, setSelectedRows, }: SpreadsheetProps) => JSX.Element>;
|
|
19
18
|
export default _default;
|
|
20
19
|
export * from "./hooks";
|
|
21
20
|
export * from "./SpreadsheetContextProvider";
|
|
@@ -15,8 +15,8 @@ import { areEqual } from "react-window";
|
|
|
15
15
|
import SpreadsheetData from "./components/SpreadsheetData";
|
|
16
16
|
import { SpreadsheetContextProvider, } from "./SpreadsheetContextProvider";
|
|
17
17
|
var Spreadsheet = function (_a) {
|
|
18
|
-
var isReadOnly = _a.isReadOnly, initialDataSet = _a.initialDataSet,
|
|
19
|
-
return (_jsx(SpreadsheetContextProvider, __assign({
|
|
18
|
+
var isReadOnly = _a.isReadOnly, initialDataSet = _a.initialDataSet, fields = _a.fields, _b = _a.options, options = _b === void 0 ? {} : _b, _c = _a.highlightFirstRow, highlightFirstRow = _c === void 0 ? false : _c, _d = _a.onValidateRecord, onValidateRecord = _d === void 0 ? null : _d, onDataSetChanged = _a.onDataSetChanged, onValidationStateChanged = _a.onValidationStateChanged, selectedRows = _a.selectedRows, setSelectedRows = _a.setSelectedRows;
|
|
19
|
+
return (_jsx(SpreadsheetContextProvider, __assign({ isReadOnly: isReadOnly, fields: fields, initialDataSet: initialDataSet, highlightFirstRow: highlightFirstRow, options: options, onDataSetChanged: onDataSetChanged, onValidateRecord: onValidateRecord, onValidationStateChanged: onValidationStateChanged, selectedRows: selectedRows, setSelectedRows: setSelectedRows }, { children: _jsx(SpreadsheetData, {}) })));
|
|
20
20
|
};
|
|
21
21
|
export default React.memo(Spreadsheet, areEqual);
|
|
22
22
|
export * from "./hooks";
|
|
@@ -6,5 +6,5 @@ interface SpreadSheetWrapperProps {
|
|
|
6
6
|
export declare const SpreadSheetData: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, import("../../../styled/utils").CSSProps, never>;
|
|
7
7
|
export declare const SpreadSheetWrapper: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, import("../../../styled/utils").CSSProps & SpreadSheetWrapperProps, never>;
|
|
8
8
|
export declare const SpreadSheetContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, import("../../../styled/utils").CSSProps, never>;
|
|
9
|
-
export declare const TableView: import("styled-components").StyledComponent<import("react").MemoExoticComponent<({ data, columns, pageSize, onRowClick, sortBy, isLoading, highlightFirstRow, setSortBy,
|
|
9
|
+
export declare const TableView: import("styled-components").StyledComponent<import("react").MemoExoticComponent<({ data, columns, pageSize, onRowClick, sortBy, isLoading, highlightFirstRow, setSortBy, rowWidthScalingFactor, onSectionRendered, tableHeadersHeight, rowHeight, h, onTableScroll, getItemKey, isDraggable, checkboxColumnWidth, isFiltering, ...props }: import("../../../common/Table/TableView/types").TableViewProps) => JSX.Element>, import("styled-components").DefaultTheme, {}, never>;
|
|
10
10
|
export {};
|
|
@@ -6,11 +6,11 @@ import styled, { css } from "styled-components";
|
|
|
6
6
|
import { TableView as TableViewBase, TableViewCellContainer, TableViewRow, } from "../../../common/Table/TableView";
|
|
7
7
|
import { Div } from "../../../styled/utils";
|
|
8
8
|
export var SpreadSheetData = styled(Div)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n justify-content: center;\n width: 100%;\n"], ["\n display: flex;\n justify-content: center;\n width: 100%;\n"])));
|
|
9
|
-
export var SpreadSheetWrapper = styled(Div)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n border: solid 1px ", ";\n background: ", ";\n overflow: hidden !important;\n flex-grow: 1;\n\n ", "\n"], ["\n border: solid 1px ", ";\n background: ", ";\n overflow: hidden !important;\n flex-grow: 1;\n\n ", "\n"])), function (p) { return p.theme.colors.gray300; }, function (p) { return p.theme.colors.white; }, function (_a) {
|
|
9
|
+
export var SpreadSheetWrapper = styled(Div)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n border-bottom: solid 1px ", ";\n border-top: solid 1px ", ";\n background: ", ";\n overflow: hidden !important;\n flex-grow: 1;\n\n ", "\n"], ["\n border-bottom: solid 1px ", ";\n border-top: solid 1px ", ";\n background: ", ";\n overflow: hidden !important;\n flex-grow: 1;\n\n ", "\n"])), function (p) { return p.theme.colors.gray300; }, function (p) { return p.theme.colors.gray300; }, function (p) { return p.theme.colors.white; }, function (_a) {
|
|
10
10
|
var canShowCheckboxOnHover = _a.canShowCheckboxOnHover, shouldShowOnlyCheckbox = _a.shouldShowOnlyCheckbox;
|
|
11
11
|
return css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n .spreadsheet-row-container {\n ", "\n\n ", "\n }\n "], ["\n .spreadsheet-row-container {\n ", "\n\n ", "\n }\n "])), shouldShowOnlyCheckbox && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n .row-numbers-cell {\n visibility: hidden;\n }\n\n .checkbox-cell {\n visibility: visible;\n }\n "], ["\n .row-numbers-cell {\n visibility: hidden;\n }\n\n .checkbox-cell {\n visibility: visible;\n }\n "]))), !shouldShowOnlyCheckbox &&
|
|
12
12
|
canShowCheckboxOnHover && css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n &:hover {\n .row-numbers-cell {\n visibility: hidden;\n }\n\n .checkbox-cell {\n visibility: visible;\n }\n }\n "], ["\n &:hover {\n .row-numbers-cell {\n visibility: hidden;\n }\n\n .checkbox-cell {\n visibility: visible;\n }\n }\n "]))));
|
|
13
13
|
});
|
|
14
14
|
export var SpreadSheetContainer = styled(Div)(templateObject_6 || (templateObject_6 = __makeTemplateObject([""], [""])));
|
|
15
|
-
export var TableView = styled(TableViewBase)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n width: 100%;\n border: none;\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n overflow: hidden;\n background-color: ", ";\n ", " {\n border-bottom: none;\n height: 40px;\n }\n ", " {\n padding: 0;\n
|
|
15
|
+
export var TableView = styled(TableViewBase)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n width: 100%;\n border: none;\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n overflow: hidden;\n background-color: ", ";\n ", " {\n border-bottom: none;\n height: 40px;\n }\n ", " {\n padding: 0 !important;\n box-shadow: inset 0 -1px 0 ", ",\n inset -1px 0 0 ", ";\n &.last-column {\n box-shadow: inset 0 -1px 0 ", ",\n inset 1px 0 0 transparent, inset -1px 0 0 transparent !important;\n }\n }\n"], ["\n width: 100%;\n border: none;\n border-top-left-radius: 0;\n border-bottom-left-radius: 0;\n overflow: hidden;\n background-color: ", ";\n ", " {\n border-bottom: none;\n height: 40px;\n }\n ", " {\n padding: 0 !important;\n box-shadow: inset 0 -1px 0 ", ",\n inset -1px 0 0 ", ";\n &.last-column {\n box-shadow: inset 0 -1px 0 ", ",\n inset 1px 0 0 transparent, inset -1px 0 0 transparent !important;\n }\n }\n"])), function (p) { return p.theme.colors.gray50; }, TableViewRow, TableViewCellContainer, function (p) { return p.theme.colors.gray300; }, function (p) { return p.theme.colors.gray300; }, function (p) { return p.theme.colors.gray300; });
|
|
16
16
|
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
|
|
@@ -35,10 +35,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import axios from "axios";
|
|
38
|
-
export var getSpreadsheetRowWidth = function (fields, visibleRowsOnTableViewport) {
|
|
39
|
-
var res = Math.ceil(fields.length / visibleRowsOnTableViewport);
|
|
40
|
-
return res > 1 ? res : 1;
|
|
41
|
-
};
|
|
42
38
|
export var getColumnType = function (_a) {
|
|
43
39
|
var _b;
|
|
44
40
|
var templateLabel = _a.templateLabel, templateHeaders = _a.templateHeaders;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Field, FieldTypes, FormatRecord, Record, RecordDataSet, TemplateHeader } from "../../types";
|
|
2
2
|
import { EnumFieldValueMatchings, HeaderMatchings } from "../contexts/ImporterContextProvider";
|
|
3
|
-
export declare const addEmptyRows: (data: Record[], fields: Field[]) =>
|
|
4
|
-
|
|
3
|
+
export declare const addEmptyRows: (data: Record[], fields: Field[]) => {
|
|
4
|
+
_meta: {
|
|
5
|
+
id: string;
|
|
6
|
+
rowIndex: number;
|
|
7
|
+
};
|
|
8
|
+
}[];
|
|
9
|
+
export declare const addMeta: (record: any, index: number, uploadedRow?: any) => Record;
|
|
5
10
|
export declare const recordListToDataSet: (data: Record[], fields: Field[]) => RecordDataSet;
|
|
6
11
|
type transformToRecordsArgs = {
|
|
7
12
|
templateHeaderMatchings: HeaderMatchings;
|
|
@@ -9,6 +9,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
12
21
|
import { FieldTypes, } from "../../types";
|
|
13
22
|
import { parseValue } from "../common/Spreadsheet/common";
|
|
14
23
|
var MINIMUM_ROW_COUNT = 20;
|
|
@@ -21,19 +30,18 @@ export var addEmptyRows = function (data, fields) {
|
|
|
21
30
|
var _a;
|
|
22
31
|
return (__assign(__assign({}, obj), (_a = {}, _a[f.name] = null, _a)));
|
|
23
32
|
}, {});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return data;
|
|
33
|
+
var newData = Array.from({ length: MINIMUM_ROW_COUNT - data.length }, function (_, index) { return (__assign(__assign({}, emptyRecord), { _meta: {
|
|
34
|
+
id: getRowId(data.length + index),
|
|
35
|
+
rowIndex: data.length + index,
|
|
36
|
+
} })); });
|
|
37
|
+
return __spreadArray(__spreadArray([], data, true), newData, true);
|
|
31
38
|
};
|
|
32
|
-
export var addMeta = function (record, index) {
|
|
39
|
+
export var addMeta = function (record, index, uploadedRow) {
|
|
33
40
|
var _a;
|
|
41
|
+
if (uploadedRow === void 0) { uploadedRow = null; }
|
|
34
42
|
var rId = getRowId(index);
|
|
35
43
|
var meta = (_a = record._meta) !== null && _a !== void 0 ? _a : {};
|
|
36
|
-
return __assign(__assign({}, record), { _meta: __assign(__assign({}, meta), { id: rId, rowIndex: index, touched: false }) });
|
|
44
|
+
return __assign(__assign({}, record), { _meta: __assign(__assign({}, meta), { id: rId, rowIndex: index, touched: false, uploadedRow: uploadedRow }) });
|
|
37
45
|
};
|
|
38
46
|
export var recordListToDataSet = function (data, fields) {
|
|
39
47
|
var initialData = data;
|
|
@@ -59,7 +67,7 @@ var transformToRecords = function (_a) {
|
|
|
59
67
|
return (__assign(__assign({}, byLabel), (_a = {}, _a[header.label] = header, _a)));
|
|
60
68
|
}, {});
|
|
61
69
|
var getRecord = function (row, index) {
|
|
62
|
-
var record = addMeta({}, index);
|
|
70
|
+
var record = addMeta({}, index, row);
|
|
63
71
|
matchedColumnsLabels.forEach(function (_a) {
|
|
64
72
|
var label = _a.label, index = _a.index;
|
|
65
73
|
var enumSet = enumFieldValueMatchings
|
|
@@ -12,7 +12,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { ImporterContextProvider } from "./contexts/ImporterContextProvider";
|
|
14
14
|
import { ImporterWithContext } from "./ImporterWithContext";
|
|
15
|
-
import { useFullscreenOverlay } from "./useFullscreenOverlay";
|
|
16
15
|
export var ACCOUNT_ROUTES = {
|
|
17
16
|
TEMPLATES: "/importers",
|
|
18
17
|
};
|
|
@@ -21,7 +20,6 @@ var p = function (path) { return "".concat(ACCOUNT_VIEW_PATH).concat(path); };
|
|
|
21
20
|
export var TEMPLATES_ROUTE = p(ACCOUNT_ROUTES.TEMPLATES);
|
|
22
21
|
var Importer = function (_a) {
|
|
23
22
|
var templateSlug = _a.templateSlug, apiToken = _a.apiToken, options = _a.options, formatRecord = _a.formatRecord, onValidateRecord = _a.onValidateRecord, onSubmit = _a.onSubmit, onClose = _a.onClose;
|
|
24
|
-
useFullscreenOverlay();
|
|
25
23
|
return (_jsx(ImporterContextProvider, __assign({ options: options, templateSlug: templateSlug, apiToken: apiToken, formatRecord: formatRecord, onValidateRecord: onValidateRecord, onClose: onClose, onSubmit: onSubmit }, { children: _jsx(ImporterWithContext, {}) })));
|
|
26
24
|
};
|
|
27
25
|
export * from "./common/Spreadsheet";
|
|
@@ -24,6 +24,7 @@ import { DeleteIcon, ConfirmationDeleteIcon } from "./icons";
|
|
|
24
24
|
import { addToast } from "../../../common/Toast";
|
|
25
25
|
import { Div } from "../../../styled/utils";
|
|
26
26
|
import { ActionButton } from "./TableActions.styles";
|
|
27
|
+
import { useTranslation } from "react-i18next";
|
|
27
28
|
var StyledTooltipProvider = styled(TooltipProvider)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: fit-content;\n"], ["\n width: fit-content;\n"])));
|
|
28
29
|
var filterByRecordsThatContainsValues = function (mainObject) {
|
|
29
30
|
return mainObject.filter(function (obj) {
|
|
@@ -40,6 +41,7 @@ export var DeleteSelectedRows = function (_a) {
|
|
|
40
41
|
var _c = useState(false), isConfirmationModalOpen = _c[0], setIsConfirmationModalOpen = _c[1];
|
|
41
42
|
var _d = useSpreadsheetContext(), data = _d.data, filteredInputValue = _d.filteredInputValue, deleteRecords = _d.deleteRecords, selectedRows = _d.selectedRows, setSelectedRows = _d.setSelectedRows, setFilteredInputValue = _d.setFilteredInputValue;
|
|
42
43
|
var _e = useImporterContext(), setCurrentStepIndex = _e.setCurrentStepIndex, isUsingManualImport = _e.isUsingManualImport;
|
|
44
|
+
var t = useTranslation("review").t;
|
|
43
45
|
var toggleModalVisibility = function () {
|
|
44
46
|
setIsConfirmationModalOpen(function (oldValue) { return !oldValue; });
|
|
45
47
|
};
|
|
@@ -53,13 +55,17 @@ export var DeleteSelectedRows = function (_a) {
|
|
|
53
55
|
!filteredInputValue &&
|
|
54
56
|
selectedRows.length === validData.length) {
|
|
55
57
|
setCurrentStepIndex(0);
|
|
56
|
-
return addToast("
|
|
58
|
+
return addToast(t("table_actions.delete_rows.delete_toast"), "success");
|
|
57
59
|
}
|
|
58
60
|
deleteRecords(selectedRows);
|
|
59
61
|
};
|
|
60
|
-
var DescriptionUI = function () { return (_jsx(_Fragment, { children: _jsxs(Div, { children: ["
|
|
61
|
-
|
|
62
|
+
var DescriptionUI = function () { return (_jsx(_Fragment, { children: _jsxs(Div, { children: [t("table_actions.delete_rows.confirmation_modal", {
|
|
63
|
+
length: selectedRows.length,
|
|
64
|
+
}), selectedRows.length > 1 ? "s" : "", "?"] }) })); };
|
|
65
|
+
var confirmationModalUI = (_jsx(ConfirmationModal, { isOpen: isConfirmationModalOpen, handleClose: toggleModalVisibility, title: "".concat(t("table_actions.delete_rows.modal_title")).concat(selectedRows.length > 1 ? "s" : ""), description: _jsx(DescriptionUI, {}), onSubmit: handleDeleteRecord, buttonText: t("table_actions.delete_rows.yes_delete"), icon: ConfirmationDeleteIcon }));
|
|
62
66
|
var isDeleteButtonDisabled = selectedRows.length <= 0;
|
|
63
|
-
return (_jsxs(_Fragment, { children: [confirmationModalUI, _jsx(StyledTooltipProvider, __assign({ tooltip: isDeleteButtonDisabled
|
|
67
|
+
return (_jsxs(_Fragment, { children: [confirmationModalUI, _jsx(StyledTooltipProvider, __assign({ tooltip: isDeleteButtonDisabled
|
|
68
|
+
? t("table_actions.delete_rows.select_rows")
|
|
69
|
+
: t("table_actions.delete_rows.delete_row"), placement: "right", flip: false, centered: true, "data-testid": testId }, { children: _jsx(ActionButton, __assign({ onClick: toggleModalVisibility, disabled: isDeleteButtonDisabled }, { children: _jsx(DeleteIcon, {}) })) }))] }));
|
|
64
70
|
};
|
|
65
71
|
var templateObject_1;
|