fuse-importer 0.26.0 → 0.26.2
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/common/Spreadsheet/SpreadsheetContextProvider.js +7 -2
- package/lib/esm/Importer/common/Spreadsheet/hooks.js +3 -3
- package/lib/esm/Importer/common/index.js +1 -1
- package/lib/esm/Importer/common/utils.d.ts +4 -0
- package/lib/esm/Importer/common/utils.js +15 -0
- package/lib/esm/Importer/contexts/ImporterContextProvider.d.ts +2 -1
- package/lib/esm/Importer/contexts/ImporterContextProvider.js +27 -7
- package/lib/esm/Importer/index.d.ts +3 -2
- package/lib/esm/Importer/index.js +2 -2
- package/lib/esm/common/Table/TableActions/DeleteSelectedRows.js +1 -22
- package/lib/esm/common/Table/TableActions/FilterByErrors/FilterByErrors.js +3 -1
- package/lib/esm/common/Table/TableActions/hooks.d.ts +5 -6
- package/lib/esm/common/Table/TableActions/hooks.js +34 -22
- package/lib/esm/common/Table/index.js +15 -11
- package/lib/esm/common/columnsValidations.d.ts +45 -0
- package/lib/esm/common/columnsValidations.js +351 -0
- package/lib/esm/common/index.d.ts +1 -0
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/inputs/SelectMenu.d.ts +1 -1
- package/lib/esm/common/inputs/SelectMenu.js +17 -9
- package/lib/esm/index.d.ts +3 -1
- package/lib/esm/index.js +41 -10
- package/lib/esm/locales/de.d.ts +0 -1
- package/lib/esm/locales/de.js +0 -1
- package/lib/esm/locales/en.d.ts +0 -1
- package/lib/esm/locales/en.js +0 -1
- package/lib/esm/locales/es.d.ts +0 -1
- package/lib/esm/locales/es.js +0 -1
- package/lib/esm/locales/fr.d.ts +0 -1
- package/lib/esm/locales/fr.js +0 -1
- package/lib/esm/types.d.ts +52 -1
- package/lib/esm/types.js +31 -0
- package/lib/esm/utils/index.d.ts +10 -0
- package/lib/esm/utils/index.js +31 -0
- package/lib/main.js +22 -22
- package/package.json +9 -4
|
@@ -55,8 +55,13 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
55
55
|
});
|
|
56
56
|
}, [dataSet]);
|
|
57
57
|
var handleDeleteErrors = useCallback(function (selectedRows) {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
var errors = errorsRef.current;
|
|
59
|
+
var warnings = errorsRef.current;
|
|
60
|
+
var selectedRecordsLength = selectedRows.length;
|
|
61
|
+
var dataSetLength = Object.keys(dataSet).length - 1;
|
|
62
|
+
var isDeletingAllRows = selectedRecordsLength === dataSetLength;
|
|
63
|
+
deleteRecords(setDataSet, selectedRows, errors, warnings, isDeletingAllRows);
|
|
64
|
+
}, [dataSet, errorsRef.current, errorsRef.current]);
|
|
60
65
|
// sort data based on errors (errors group on top and not errors group at bottom)
|
|
61
66
|
var data = useMemo(function () {
|
|
62
67
|
var filteredDatasetByString = filteredInputValue
|
|
@@ -63,8 +63,8 @@ export var useValidationState = function (_a) {
|
|
|
63
63
|
var validatorsCache = useMemo(function () { return selectValidatorsFor(fields); }, [fields]);
|
|
64
64
|
var errorsRef = useRef(errors);
|
|
65
65
|
var warningsRef = useRef(warnings);
|
|
66
|
-
var _e = useTableActions({
|
|
67
|
-
//Validate record and update dataSet
|
|
66
|
+
var _e = useTableActions({ setErrors: setErrors, setWarnings: setWarnings, fields: fields }), deleteRecords = _e.deleteRecords, filterRecordsByError = _e.filterRecordsByError, filterRecordsBySearchValue = _e.filterRecordsBySearchValue;
|
|
67
|
+
// Validate record and update dataSet
|
|
68
68
|
var updateRecordAndRevalidate = useCallback(function (record) { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
69
|
var recordId, newDataSet, data, _a, recordErrors, recordWarnings, hasError, hasWarning;
|
|
70
70
|
var _b;
|
|
@@ -109,7 +109,7 @@ export var useValidationState = function (_a) {
|
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
}); }, [dataSet, validatorsCache]);
|
|
112
|
-
//Initial data validation and update dataSet
|
|
112
|
+
// Initial data validation and update dataSet
|
|
113
113
|
useEffect(function () {
|
|
114
114
|
if (isReadOnly)
|
|
115
115
|
return;
|
|
@@ -6,7 +6,7 @@ export var baseUrls = {
|
|
|
6
6
|
production: "https://fuse.flatirons.com",
|
|
7
7
|
test: "https://fuse-test.flatirons.com",
|
|
8
8
|
};
|
|
9
|
-
var MINIMUM_TABLE_HEIGHT =
|
|
9
|
+
var MINIMUM_TABLE_HEIGHT = 100;
|
|
10
10
|
export var getTableHeight = function (_a) {
|
|
11
11
|
var _b = _a.headerHeight, headerHeight = _b === void 0 ? defaultTableHeaderHeightPx : _b, _c = _a.rowHeight, rowHeight = _c === void 0 ? defaultTableRowHeightPx : _c, _d = _a.maxVisibleRows, maxVisibleRows = _d === void 0 ? 7 : _d, _e = _a.minimumTableHeight, minimumTableHeight = _e === void 0 ? MINIMUM_TABLE_HEIGHT : _e, dataCount = _a.dataCount;
|
|
12
12
|
return Math.max(headerHeight + rowHeight * Math.min(dataCount, maxVisibleRows + 0.5), minimumTableHeight);
|
|
@@ -5,4 +5,8 @@ type IsEnumFieldArgs = {
|
|
|
5
5
|
};
|
|
6
6
|
export declare const getColumnType: ({ templateLabel, templateHeaders, }: IsEnumFieldArgs) => string;
|
|
7
7
|
export declare const sendRecordsToIntegrations: (reviewedData: Record[], integrations: Integration[]) => Promise<void>;
|
|
8
|
+
type GenericRecord<T> = {
|
|
9
|
+
[key: string]: T;
|
|
10
|
+
};
|
|
11
|
+
export declare const verifyDuplicateValue: (array: GenericRecord<any>[], key: string, shouldThrow?: boolean, message?: string) => boolean;
|
|
8
12
|
export {};
|
|
@@ -83,3 +83,18 @@ export var sendRecordsToIntegrations = function (reviewedData, integrations) { r
|
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
}); };
|
|
86
|
+
export var verifyDuplicateValue = function (array, key, shouldThrow, message) {
|
|
87
|
+
if (shouldThrow === void 0) { shouldThrow = false; }
|
|
88
|
+
var uniqueValues = {};
|
|
89
|
+
for (var i = 0; i < array.length; i++) {
|
|
90
|
+
var currentValue = array[i][key];
|
|
91
|
+
if (uniqueValues[currentValue]) {
|
|
92
|
+
if (shouldThrow) {
|
|
93
|
+
throw new Error(message || "There is a duplicated '".concat(key, "' between your columns."));
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
uniqueValues[currentValue] = true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
};
|
|
@@ -63,6 +63,7 @@ export type Props = {
|
|
|
63
63
|
onSubmit: OnSubmit;
|
|
64
64
|
formatRecord: FormatRecord;
|
|
65
65
|
onValidateRecord?: OnValidateRecord;
|
|
66
|
+
dynamicColumns: TemplateHeader[] | null;
|
|
66
67
|
};
|
|
67
|
-
export declare const ImporterContextProvider: ({ templateSlug, apiToken, children, options, onSubmit, onClose, formatRecord, onValidateRecord, }: Props) => JSX.Element;
|
|
68
|
+
export declare const ImporterContextProvider: ({ templateSlug, apiToken, children, options, onSubmit, onClose, formatRecord, onValidateRecord, dynamicColumns, }: Props) => JSX.Element;
|
|
68
69
|
export declare const useImporterContext: () => State;
|
|
@@ -45,20 +45,29 @@ 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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
+
if (ar || !(i in from)) {
|
|
51
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
+
ar[i] = from[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
+
};
|
|
48
57
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
49
58
|
import Fuse from "fuse.js";
|
|
50
59
|
import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
51
60
|
import { FieldTypes, } from "../../types";
|
|
52
61
|
import { FuseApi } from "../common/FuseApi";
|
|
53
62
|
import { getCustomTheme, theme } from "../common/theme";
|
|
54
|
-
import { getColumnType } from "../common/utils";
|
|
63
|
+
import { getColumnType, verifyDuplicateValue } from "../common/utils";
|
|
55
64
|
export var fusejsOptions = {
|
|
56
65
|
includeScore: true,
|
|
57
66
|
threshold: 0.35,
|
|
58
67
|
};
|
|
59
68
|
var ImporterContext = createContext({});
|
|
60
69
|
export var ImporterContextProvider = function (_a) {
|
|
61
|
-
var templateSlug = _a.templateSlug, apiToken = _a.apiToken, children = _a.children, options = _a.options, onSubmit = _a.onSubmit, onClose = _a.onClose, formatRecord = _a.formatRecord, onValidateRecord = _a.onValidateRecord;
|
|
70
|
+
var templateSlug = _a.templateSlug, apiToken = _a.apiToken, children = _a.children, options = _a.options, onSubmit = _a.onSubmit, onClose = _a.onClose, formatRecord = _a.formatRecord, onValidateRecord = _a.onValidateRecord, dynamicColumns = _a.dynamicColumns;
|
|
62
71
|
var _b = useState(0), currentStepIndex = _b[0], setCurrentStepIndex = _b[1];
|
|
63
72
|
var _c = useState(0), matcherSubstep = _c[0], setMatcherSubstep = _c[1];
|
|
64
73
|
var _d = useState(null), templateError = _d[0], setTemplateError = _d[1];
|
|
@@ -125,7 +134,7 @@ export var ImporterContextProvider = function (_a) {
|
|
|
125
134
|
}, [uploadedData]);
|
|
126
135
|
useEffect(function () {
|
|
127
136
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
128
|
-
var _a, organization_1,
|
|
137
|
+
var _a, organization_1, columns_1, importer_style_preferences, integrations_1, preview_first_time, error_1, errorMsg;
|
|
129
138
|
var _b, _c;
|
|
130
139
|
return __generator(this, function (_d) {
|
|
131
140
|
switch (_d.label) {
|
|
@@ -133,10 +142,21 @@ export var ImporterContextProvider = function (_a) {
|
|
|
133
142
|
_d.trys.push([0, 2, , 3]);
|
|
134
143
|
return [4 /*yield*/, fuseApi.get("/api/v1/importer/templates/".concat(templateSlug))];
|
|
135
144
|
case 1:
|
|
136
|
-
_a = (_d.sent()).data, organization_1 = _a.organization,
|
|
137
|
-
columnsOrderedByPosition = columns.sort(function (a, b) { return a.position - b.position; });
|
|
145
|
+
_a = (_d.sent()).data, organization_1 = _a.organization, columns_1 = _a.columns, importer_style_preferences = _a.importer_style_preferences, integrations_1 = _a.integrations, preview_first_time = _a.preview_first_time;
|
|
138
146
|
setOrganization(organization_1);
|
|
139
|
-
setTemplateHeaders(
|
|
147
|
+
setTemplateHeaders(function () {
|
|
148
|
+
// user has created dynamic columns
|
|
149
|
+
if (dynamicColumns && (dynamicColumns === null || dynamicColumns === void 0 ? void 0 : dynamicColumns.length) >= 0) {
|
|
150
|
+
var allColumns = __spreadArray(__spreadArray([], columns_1, true), dynamicColumns, true);
|
|
151
|
+
var columnsOrderedByPosition_1 = allColumns.sort(function (a, b) { return (a === null || a === void 0 ? void 0 : a.position) - (b === null || b === void 0 ? void 0 : b.position); });
|
|
152
|
+
verifyDuplicateValue(columnsOrderedByPosition_1, "internal_key", true, "There is a duplicated 'internal_key' between your columns.");
|
|
153
|
+
verifyDuplicateValue(columnsOrderedByPosition_1, "label", true, "There is a duplicated 'label' between your columns.");
|
|
154
|
+
return columnsOrderedByPosition_1;
|
|
155
|
+
}
|
|
156
|
+
// user has not created dynamic columns
|
|
157
|
+
var columnsOrderedByPosition = columns_1.sort(function (a, b) { return a.position - b.position; });
|
|
158
|
+
return columnsOrderedByPosition;
|
|
159
|
+
});
|
|
140
160
|
setIntegrations(integrations_1);
|
|
141
161
|
setPreviewFirstTime(preview_first_time);
|
|
142
162
|
if (organization_1.plan && organization_1.plan.allow_style_customization) {
|
|
@@ -153,7 +173,7 @@ export var ImporterContextProvider = function (_a) {
|
|
|
153
173
|
}
|
|
154
174
|
});
|
|
155
175
|
}); })();
|
|
156
|
-
}, []);
|
|
176
|
+
}, [dynamicColumns]);
|
|
157
177
|
var resetImport = function () {
|
|
158
178
|
setUploadedData(null);
|
|
159
179
|
setTemplateHeaderMatchings(null);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormatRecord, ImporterOptions, OnSubmit, OnValidateRecord } from "../types";
|
|
1
|
+
import { FormatRecord, ImporterOptions, OnSubmit, OnValidateRecord, TemplateHeader } from "../types";
|
|
2
2
|
export declare const ACCOUNT_ROUTES: {
|
|
3
3
|
TEMPLATES: string;
|
|
4
4
|
};
|
|
@@ -13,8 +13,9 @@ type ImporterProps = {
|
|
|
13
13
|
onValidateRecord?: OnValidateRecord;
|
|
14
14
|
onSubmit?: OnSubmit;
|
|
15
15
|
onClose: () => void;
|
|
16
|
+
dynamicColumns: TemplateHeader[];
|
|
16
17
|
};
|
|
17
|
-
declare const Importer: ({ templateSlug, apiToken, options, formatRecord, onValidateRecord, onSubmit, onClose, }: ImporterProps) => JSX.Element;
|
|
18
|
+
declare const Importer: ({ templateSlug, apiToken, options, formatRecord, onValidateRecord, onSubmit, onClose, dynamicColumns, }: ImporterProps) => JSX.Element;
|
|
18
19
|
export * from "./common/Spreadsheet";
|
|
19
20
|
export * from "./common/utils";
|
|
20
21
|
export * from "./Review/ReviewContextProvider";
|
|
@@ -19,8 +19,8 @@ export var ACCOUNT_VIEW_PATH = "/account";
|
|
|
19
19
|
var p = function (path) { return "".concat(ACCOUNT_VIEW_PATH).concat(path); };
|
|
20
20
|
export var TEMPLATES_ROUTE = p(ACCOUNT_ROUTES.TEMPLATES);
|
|
21
21
|
var Importer = function (_a) {
|
|
22
|
-
var templateSlug = _a.templateSlug, apiToken = _a.apiToken, options = _a.options, formatRecord = _a.formatRecord, onValidateRecord = _a.onValidateRecord, onSubmit = _a.onSubmit, onClose = _a.onClose;
|
|
23
|
-
return (_jsx(ImporterContextProvider, __assign({ options: options, templateSlug: templateSlug, apiToken: apiToken, formatRecord: formatRecord, onValidateRecord: onValidateRecord, onClose: onClose, onSubmit: onSubmit }, { children: _jsx(ImporterWithContext, {}) })));
|
|
22
|
+
var templateSlug = _a.templateSlug, apiToken = _a.apiToken, options = _a.options, formatRecord = _a.formatRecord, onValidateRecord = _a.onValidateRecord, onSubmit = _a.onSubmit, onClose = _a.onClose, dynamicColumns = _a.dynamicColumns;
|
|
23
|
+
return (_jsx(ImporterContextProvider, __assign({ options: options, templateSlug: templateSlug, apiToken: apiToken, formatRecord: formatRecord, onValidateRecord: onValidateRecord, onClose: onClose, onSubmit: onSubmit, dynamicColumns: dynamicColumns }, { children: _jsx(ImporterWithContext, {}) })));
|
|
24
24
|
};
|
|
25
25
|
export * from "./common/Spreadsheet";
|
|
26
26
|
export * from "./common/utils";
|
|
@@ -19,28 +19,15 @@ import styled from "styled-components";
|
|
|
19
19
|
import { TooltipProvider } from "../../../common/TooltipProvider";
|
|
20
20
|
import { ConfirmationModal } from "../../../common/ConfirmationModal";
|
|
21
21
|
import { useSpreadsheetContext } from "../../../Importer";
|
|
22
|
-
import { useImporterContext } from "../../../Importer/contexts/ImporterContextProvider";
|
|
23
22
|
import { DeleteIcon, ConfirmationDeleteIcon } from "./icons";
|
|
24
|
-
import { addToast } from "../../../common/Toast";
|
|
25
23
|
import { Div } from "../../../styled/utils";
|
|
26
24
|
import { ActionButton } from "./TableActions.styles";
|
|
27
25
|
import { useTranslation } from "react-i18next";
|
|
28
26
|
var StyledTooltipProvider = styled(TooltipProvider)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: fit-content;\n"], ["\n width: fit-content;\n"])));
|
|
29
|
-
var filterByRecordsThatContainsValues = function (mainObject) {
|
|
30
|
-
return mainObject.filter(function (obj) {
|
|
31
|
-
for (var key in obj) {
|
|
32
|
-
if (key !== "_meta" && obj[key] !== null && obj[key] !== undefined) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
27
|
export var DeleteSelectedRows = function (_a) {
|
|
40
28
|
var _b = _a.testId, testId = _b === void 0 ? "ta-delete-rows" : _b;
|
|
41
29
|
var _c = useState(false), isConfirmationModalOpen = _c[0], setIsConfirmationModalOpen = _c[1];
|
|
42
|
-
var _d = useSpreadsheetContext(),
|
|
43
|
-
var _e = useImporterContext(), setCurrentStepIndex = _e.setCurrentStepIndex, isUsingManualImport = _e.isUsingManualImport;
|
|
30
|
+
var _d = useSpreadsheetContext(), deleteRecords = _d.deleteRecords, selectedRows = _d.selectedRows, setSelectedRows = _d.setSelectedRows, setFilteredInputValue = _d.setFilteredInputValue;
|
|
44
31
|
var t = useTranslation("review").t;
|
|
45
32
|
var toggleModalVisibility = function () {
|
|
46
33
|
setIsConfirmationModalOpen(function (oldValue) { return !oldValue; });
|
|
@@ -49,14 +36,6 @@ export var DeleteSelectedRows = function (_a) {
|
|
|
49
36
|
setSelectedRows([]);
|
|
50
37
|
toggleModalVisibility();
|
|
51
38
|
setFilteredInputValue("");
|
|
52
|
-
var validData = filterByRecordsThatContainsValues(data);
|
|
53
|
-
// If user is deleting every row, but not using the manual import option
|
|
54
|
-
if (!isUsingManualImport.current &&
|
|
55
|
-
!filteredInputValue &&
|
|
56
|
-
selectedRows.length === validData.length) {
|
|
57
|
-
setCurrentStepIndex(0);
|
|
58
|
-
return addToast(t("table_actions.delete_rows.delete_toast"), "success");
|
|
59
|
-
}
|
|
60
39
|
deleteRecords(selectedRows);
|
|
61
40
|
};
|
|
62
41
|
var DescriptionUI = function () { return (_jsx(_Fragment, { children: _jsxs(Div, { children: [t("table_actions.delete_rows.confirmation_modal", {
|
|
@@ -17,7 +17,9 @@ export var FilterByErrors = function () {
|
|
|
17
17
|
};
|
|
18
18
|
var onChange = function (selected) {
|
|
19
19
|
if (selected) {
|
|
20
|
-
|
|
20
|
+
var selectedField = fields.filter(function (field) { return field.name === selected; });
|
|
21
|
+
var label = selectedField[0].label || selected;
|
|
22
|
+
addToast("Showing only the rows with error on the ".concat(label, " column"), "success");
|
|
21
23
|
}
|
|
22
24
|
setSelectedErrorToFilter(selected || "");
|
|
23
25
|
};
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { BatchValidationErrors, Field, RecordDataSet } from "../../../types";
|
|
3
3
|
interface UseTableActionsProps {
|
|
4
|
-
setDataSet: React.Dispatch<React.SetStateAction<RecordDataSet>>;
|
|
5
4
|
setErrors: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
|
|
6
5
|
setWarnings: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
|
|
7
6
|
}
|
|
8
|
-
export type DeleteRecords = (
|
|
7
|
+
export type DeleteRecords = (setDataSet: React.Dispatch<React.SetStateAction<RecordDataSet>>, selectedRecords: string[], errors: BatchValidationErrors, warnings: BatchValidationErrors, isDeletingAllRows: boolean) => void;
|
|
9
8
|
export type FilterRecordsBySearchValue = (obj: RecordDataSet, value: string, fields: Field[]) => RecordDataSet;
|
|
10
9
|
export type FilterRecordsByError = (obj: RecordDataSet, keyToFilter: string, errors: BatchValidationErrors, fields: Field[]) => RecordDataSet;
|
|
11
10
|
interface UseTableActionsProps {
|
|
12
|
-
setDataSet: React.Dispatch<React.SetStateAction<RecordDataSet>>;
|
|
13
11
|
setErrors: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
|
|
14
12
|
setWarnings: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
|
|
13
|
+
fields: Field[];
|
|
15
14
|
}
|
|
16
|
-
export declare const useTableActions: ({
|
|
17
|
-
deleteRecords:
|
|
18
|
-
filterRecordsBySearchValue: (obj: RecordDataSet, value: string
|
|
15
|
+
export declare const useTableActions: ({ setErrors, setWarnings, fields, }: UseTableActionsProps) => {
|
|
16
|
+
deleteRecords: DeleteRecords;
|
|
17
|
+
filterRecordsBySearchValue: (obj: RecordDataSet, value: string) => RecordDataSet;
|
|
19
18
|
filterRecordsByError: (obj: RecordDataSet, keyToFilter: string, errors: BatchValidationErrors, fields: Field[]) => {};
|
|
20
19
|
};
|
|
21
20
|
export {};
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (var key in obj) {
|
|
7
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
8
|
-
var meta = (_a = obj[key]) === null || _a === void 0 ? void 0 : _a._meta;
|
|
9
|
-
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))) {
|
|
10
|
-
newObj[key] = obj[key];
|
|
11
|
-
}
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
12
6
|
}
|
|
13
7
|
}
|
|
14
|
-
return
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
15
9
|
};
|
|
10
|
+
import { useRef } from "react";
|
|
11
|
+
import { addEmptyRows, recordListToDataSet } from "../../../Importer/data";
|
|
16
12
|
var removeErrorsOrWarningsFromObject = function (obj, keysToRemove) {
|
|
17
13
|
var keysSet = new Set(keysToRemove);
|
|
18
14
|
var newObj = {};
|
|
@@ -35,18 +31,34 @@ var includesSearchValue = function (value, searchValue) {
|
|
|
35
31
|
return false;
|
|
36
32
|
};
|
|
37
33
|
export var useTableActions = function (_a) {
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
var setErrors = _a.setErrors, setWarnings = _a.setWarnings, fields = _a.fields;
|
|
35
|
+
var allRowsDeleted = useRef([]);
|
|
36
|
+
// Delete records from dataSet and from validations
|
|
37
|
+
var deleteRecords = function (setDataSet, selectedRecords, errors, warnings, isDeletingAllRows) {
|
|
38
|
+
var rowsToBeAddedIntoDeletedOnes = Array.from(new Set(__spreadArray(__spreadArray([], selectedRecords, true), allRowsDeleted.current, true)));
|
|
39
|
+
allRowsDeleted.current = rowsToBeAddedIntoDeletedOnes;
|
|
40
|
+
var newErrors = removeErrorsOrWarningsFromObject(errors, rowsToBeAddedIntoDeletedOnes);
|
|
41
|
+
var newWarnings = removeErrorsOrWarningsFromObject(warnings, rowsToBeAddedIntoDeletedOnes);
|
|
42
|
+
setDataSet(function (oldValues) {
|
|
43
|
+
if (!rowsToBeAddedIntoDeletedOnes)
|
|
44
|
+
return oldValues;
|
|
45
|
+
if (isDeletingAllRows) {
|
|
46
|
+
allRowsDeleted.current = [];
|
|
47
|
+
return recordListToDataSet(addEmptyRows([], fields), fields);
|
|
48
|
+
}
|
|
49
|
+
var dataSetWithoutDeletedRecords = {};
|
|
50
|
+
for (var objKey in oldValues) {
|
|
51
|
+
if (!selectedRecords.includes(objKey)) {
|
|
52
|
+
dataSetWithoutDeletedRecords[objKey] = oldValues[objKey];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return dataSetWithoutDeletedRecords;
|
|
56
|
+
});
|
|
45
57
|
setErrors(newErrors);
|
|
46
58
|
setWarnings(newWarnings);
|
|
47
59
|
};
|
|
48
|
-
//Filter records by search value
|
|
49
|
-
var filterRecordsBySearchValue = function (obj, value
|
|
60
|
+
// Filter records by search value
|
|
61
|
+
var filterRecordsBySearchValue = function (obj, value) {
|
|
50
62
|
var filteredObj = {};
|
|
51
63
|
for (var _i = 0, _a = Object.entries(obj); _i < _a.length; _i++) {
|
|
52
64
|
var _b = _a[_i], key = _b[0], currentObj = _b[1];
|
|
@@ -67,7 +79,7 @@ export var useTableActions = function (_a) {
|
|
|
67
79
|
}
|
|
68
80
|
return filteredObj;
|
|
69
81
|
};
|
|
70
|
-
//Filter records by selected column error
|
|
82
|
+
// Filter records by selected column error
|
|
71
83
|
var filterRecordsByError = function (obj, keyToFilter, errors, fields) {
|
|
72
84
|
var filteredObj = {};
|
|
73
85
|
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]; });
|
|
@@ -71,8 +71,10 @@ import { useTableContext } from "./TableDataProvider";
|
|
|
71
71
|
import { TableView as TableViewBase } from "./TableView";
|
|
72
72
|
import { useReorderRows } from "./useReorderRows";
|
|
73
73
|
import { addToast } from "../../common/Toast";
|
|
74
|
-
var
|
|
75
|
-
|
|
74
|
+
var TableContainer = styled(Div)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n overflow-x: auto;\n width: calc(100% + 2px);\n ", ";\n"], ["\n overflow-x: auto;\n width: calc(100% + 2px);\n ", ";\n"])), function (p) { return p.theme.css.scrollbarDark; });
|
|
75
|
+
var TableWrapper = styled(Div)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n min-width: 1000px;\n border: solid 1px ", ";\n"], ["\n min-width: 1000px;\n border: solid 1px ", ";\n"])), function (p) { return p.theme.colors.gray300; });
|
|
76
|
+
var TableView = styled(TableViewBase)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (p) {
|
|
77
|
+
return p.withPagination && css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n border-radius: 0px;\n "], ["\n border-radius: 0px;\n "])));
|
|
76
78
|
});
|
|
77
79
|
var Table = function (_a) {
|
|
78
80
|
var columns = _a.columns, _b = _a.onRowClick, onRowClick = _b === void 0 ? null : _b, _c = _a.blankState, blankState = _c === void 0 ? null : _c, templateSlug = _a.templateSlug, _d = _a.isDraggable, isDraggable = _d === void 0 ? false : _d, props = __rest(_a, ["columns", "onRowClick", "blankState", "templateSlug", "isDraggable"]);
|
|
@@ -122,15 +124,17 @@ var Table = function (_a) {
|
|
|
122
124
|
? [restrictToVerticalAxis, restrictToWindowEdges]
|
|
123
125
|
: undefined,
|
|
124
126
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
var Container = data.length > 0 ? TableContainer : Div;
|
|
128
|
+
var Wrapper = data.length > 0 ? TableWrapper : Div;
|
|
129
|
+
return (_jsx(Container, { children: _jsx(Wrapper, { children: _jsxs(Div, __assign({}, props, { children: [data.length ? (_jsx(DndContext, __assign({ sensors: dndContextValues.sensors, collisionDetection: dndContextValues.collisionDetection, onDragEnd: dndContextValues.onDragEnd, modifiers: dndContextValues.modifiers }, { children: _jsx(TableView, __assign({ pageSize: data.length, withPagination: withPagination, isDraggable: isDraggable }, {
|
|
130
|
+
isLoading: isLoading,
|
|
131
|
+
data: data,
|
|
132
|
+
columns: columns,
|
|
133
|
+
sortBy: sortBy,
|
|
134
|
+
setSortBy: setSortBy,
|
|
135
|
+
onRowClick: onRowClick,
|
|
136
|
+
})) }))) : (blankState), paginationUI] })) }) }));
|
|
133
137
|
};
|
|
134
138
|
export { Table };
|
|
135
139
|
export * from "./TableDataProvider";
|
|
136
|
-
var templateObject_1, templateObject_2;
|
|
140
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ColumnRequiredProps, ValidationOptionKeys, ValidationTypes } from "../types";
|
|
2
|
+
export type ValidationOption = {
|
|
3
|
+
type: "text" | "number" | "date";
|
|
4
|
+
key: ValidationOptionKeys;
|
|
5
|
+
tooltip: string;
|
|
6
|
+
};
|
|
7
|
+
export type Validation = {
|
|
8
|
+
value: ValidationTypes;
|
|
9
|
+
label: string;
|
|
10
|
+
isDefaultValidation?: boolean;
|
|
11
|
+
options?: ValidationOption[];
|
|
12
|
+
};
|
|
13
|
+
export declare const validationsByColumnType: {
|
|
14
|
+
[key: string]: Validation[];
|
|
15
|
+
};
|
|
16
|
+
export declare const validationsByType: {};
|
|
17
|
+
export declare const availableColumnTypes: string[];
|
|
18
|
+
export declare const datePatterns: {
|
|
19
|
+
value: string;
|
|
20
|
+
label: string;
|
|
21
|
+
}[];
|
|
22
|
+
export declare const dateTimePatterns: {
|
|
23
|
+
value: string;
|
|
24
|
+
label: string;
|
|
25
|
+
}[];
|
|
26
|
+
export declare const timePatterns: {
|
|
27
|
+
value: string;
|
|
28
|
+
label: string;
|
|
29
|
+
}[];
|
|
30
|
+
export declare const allowedPatterns: {
|
|
31
|
+
date: {
|
|
32
|
+
value: string;
|
|
33
|
+
label: string;
|
|
34
|
+
}[];
|
|
35
|
+
datetime: {
|
|
36
|
+
value: string;
|
|
37
|
+
label: string;
|
|
38
|
+
}[];
|
|
39
|
+
time: {
|
|
40
|
+
value: string;
|
|
41
|
+
label: string;
|
|
42
|
+
}[];
|
|
43
|
+
};
|
|
44
|
+
export declare const patternsColumnTypes: string[];
|
|
45
|
+
export declare const validateColumn: <T extends "string" | "boolean" | "time" | "integer" | "float" | "email" | "url" | "enum" | "date" | "datetime">(columnData: ColumnRequiredProps<T>) => Promise<void>;
|