fuse-importer 0.21.0 → 0.22.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/ImporterContextProvider.d.ts +31 -4
- package/lib/esm/Importer/ImporterContextProvider.js +40 -33
- package/lib/esm/Importer/Matcher/index.js +6 -5
- package/lib/esm/Importer/PreviewModeBanner.d.ts +2 -0
- package/lib/esm/Importer/PreviewModeBanner.js +20 -0
- package/lib/esm/Importer/Review/index.js +14 -18
- package/lib/esm/Importer/SpreadsheetReviewContextProvider.js +1 -1
- package/lib/esm/Importer/Stepper.js +10 -3
- package/lib/esm/Importer/Uploader/DragAndDropImporter/ImporterDropzone.js +4 -1
- package/lib/esm/Importer/Uploader/HeadersPreview.js +19 -17
- package/lib/esm/Importer/common/Spreadsheet/SpreadsheetContextProvider.js +7 -5
- package/lib/esm/Importer/common/Spreadsheet/common/FieldHeader.d.ts +7 -0
- package/lib/esm/Importer/common/Spreadsheet/common/FieldHeader.js +31 -0
- package/lib/esm/Importer/common/Spreadsheet/common/fields/SpeadsheetAutocomplete.d.ts +11 -6
- package/lib/esm/Importer/common/Spreadsheet/common/fields/SpeadsheetAutocomplete.js +6 -7
- package/lib/esm/Importer/common/Spreadsheet/common/fields/SpreadsheetInput.d.ts +4 -4
- package/lib/esm/Importer/common/Spreadsheet/common/fields/SpreadsheetInput.js +4 -5
- package/lib/esm/Importer/common/Spreadsheet/common/fields/index.d.ts +6 -5
- package/lib/esm/Importer/common/Spreadsheet/common/fields/index.js +14 -6
- package/lib/esm/Importer/common/Spreadsheet/common/index.d.ts +3 -0
- package/lib/esm/Importer/common/Spreadsheet/common/index.js +53 -9
- package/lib/esm/Importer/common/Spreadsheet/index.js +28 -57
- package/lib/esm/Importer/common/Spreadsheet/inputs/Boolean.d.ts +3 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/Boolean.js +18 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/EmailInput.d.ts +3 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/EmailInput.js +14 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/EnumInput.d.ts +6 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/EnumInput.js +30 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/FloatInput.d.ts +3 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/FloatInput.js +16 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/IntegerInput.d.ts +3 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/IntegerInput.js +16 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/StringInput.d.ts +3 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/StringInput.js +14 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/index.d.ts +13 -0
- package/lib/esm/Importer/common/Spreadsheet/inputs/index.js +20 -0
- package/lib/esm/Importer/common/index.d.ts +2 -2
- package/lib/esm/Importer/common/index.js +2 -2
- package/lib/esm/Importer/index.d.ts +1 -0
- package/lib/esm/Importer/index.js +3 -4
- package/lib/esm/Importer/theme.d.ts +225 -0
- package/lib/esm/Importer/theme.js +18 -0
- package/lib/esm/common/buttons.d.ts +15 -5
- package/lib/esm/common/buttons.js +13 -11
- package/lib/esm/common/index.js +1 -1
- package/lib/esm/common/inputs/Autocomplete.d.ts +2 -2
- package/lib/esm/common/inputs/TextInput.js +8 -1
- package/lib/esm/common/logo.js +1 -1
- package/lib/esm/styled/themeType.d.ts +1 -1
- package/lib/esm/styled/utils.d.ts +3 -0
- package/lib/esm/styled/utils.js +4 -3
- package/lib/esm/types.d.ts +7 -2
- package/lib/esm/types.js +4 -1
- package/lib/main.js +1 -1
- package/package.json +1 -1
- package/lib/esm/Importer/useCustomImporter.d.ts +0 -4
- package/lib/esm/Importer/useCustomImporter.js +0 -81
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Fuse from "fuse.js";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { ImporterOptions, OnValidateBatch, OnValidateRecord, FormatRecord } from "../types";
|
|
4
|
+
import { ImporterStylePreferences } from "./theme";
|
|
4
5
|
import { FuseApi } from "./FuseApi";
|
|
5
6
|
export declare const fusejsOptions: Fuse.IFuseOptions<string>;
|
|
6
7
|
export declare type HeaderMatchings = {
|
|
@@ -20,8 +21,28 @@ export declare type TemplateHeader = {
|
|
|
20
21
|
column_type: string;
|
|
21
22
|
internal_key: string;
|
|
22
23
|
values: string[];
|
|
24
|
+
pattern: string;
|
|
23
25
|
};
|
|
24
|
-
declare type
|
|
26
|
+
export declare type Organization = {
|
|
27
|
+
id: number;
|
|
28
|
+
name: string;
|
|
29
|
+
trial_mode: boolean;
|
|
30
|
+
plan: {
|
|
31
|
+
title: string;
|
|
32
|
+
allow_style_customization: boolean;
|
|
33
|
+
has_records_limit: boolean;
|
|
34
|
+
allowed_records: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare type Column = {
|
|
38
|
+
column_type: string;
|
|
39
|
+
internal_key: string;
|
|
40
|
+
label: string;
|
|
41
|
+
pattern: string;
|
|
42
|
+
required: boolean;
|
|
43
|
+
values: string[];
|
|
44
|
+
};
|
|
45
|
+
export declare type State = {
|
|
25
46
|
resetImport: () => void;
|
|
26
47
|
currentStepIndex: number;
|
|
27
48
|
setCurrentStepIndex: React.Dispatch<number>;
|
|
@@ -46,9 +67,10 @@ declare type State = {
|
|
|
46
67
|
fuseApi: FuseApi;
|
|
47
68
|
formatRecord: FormatRecord;
|
|
48
69
|
importerOptions: ImporterOptions;
|
|
49
|
-
|
|
70
|
+
theme: any;
|
|
71
|
+
logoURL: string;
|
|
50
72
|
};
|
|
51
|
-
declare type Props = {
|
|
73
|
+
export declare type Props = {
|
|
52
74
|
templateSlug: string;
|
|
53
75
|
apiToken: string;
|
|
54
76
|
options: ImporterOptions;
|
|
@@ -58,6 +80,11 @@ declare type Props = {
|
|
|
58
80
|
onValidateRecord?: OnValidateRecord;
|
|
59
81
|
onValidateBatch?: OnValidateBatch;
|
|
60
82
|
};
|
|
83
|
+
export declare type TemplateInfo = {
|
|
84
|
+
columns: Column[];
|
|
85
|
+
importer_style_preferences: ImporterStylePreferences;
|
|
86
|
+
organization: Organization;
|
|
87
|
+
name: string;
|
|
88
|
+
};
|
|
61
89
|
export declare const ImporterContextProvider: ({ templateSlug, apiToken, children, options, onClose, formatRecord, onValidateBatch, onValidateRecord, }: Props) => JSX.Element;
|
|
62
90
|
export declare const useImporterContext: () => State;
|
|
63
|
-
export {};
|
|
@@ -47,9 +47,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
};
|
|
48
48
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
49
49
|
import Fuse from "fuse.js";
|
|
50
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
50
|
+
import { createContext, useContext, useEffect, useMemo, useState, } from "react";
|
|
51
51
|
import { FieldTypes, } from "../types";
|
|
52
52
|
import { getColumnType } from "./common/utils";
|
|
53
|
+
import { theme, getCustomTheme, } from "./theme";
|
|
53
54
|
import { FuseApi } from "./FuseApi";
|
|
54
55
|
export var fusejsOptions = {
|
|
55
56
|
includeScore: true,
|
|
@@ -63,21 +64,24 @@ export var ImporterContextProvider = function (_a) {
|
|
|
63
64
|
var _d = useState(null), templateError = _d[0], setTemplateError = _d[1];
|
|
64
65
|
var _e = useState(null), templateHeaders = _e[0], setTemplateHeaders = _e[1];
|
|
65
66
|
var _f = useState(null), uploadedData = _f[0], setUploadedData = _f[1];
|
|
66
|
-
var _g = useState(
|
|
67
|
-
var _h = useState(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
var _g = useState(null), organization = _g[0], setOrganization = _g[1];
|
|
68
|
+
var _h = useState({
|
|
69
|
+
theme: theme,
|
|
70
|
+
logoURL: null,
|
|
71
|
+
}), style = _h[0], setStyle = _h[1];
|
|
72
|
+
var _j = useState(null), templateHeaderMatchings = _j[0], setTemplateHeaderMatchings = _j[1];
|
|
73
|
+
var _k = useState(null), enumFieldValueMatchings = _k[0], setEnumFieldValueMatchings = _k[1];
|
|
74
|
+
var _l = useState(null), uploadedDataEnumFieldValues = _l[0], setUploadedDataEnumFieldValues = _l[1];
|
|
75
|
+
var fuseApi = useMemo(function () { return new FuseApi(options.env, apiToken); }, [
|
|
76
|
+
options.env,
|
|
77
|
+
apiToken,
|
|
78
|
+
]);
|
|
79
|
+
var uploadedDataHeaders = useMemo(function () {
|
|
80
|
+
return uploadedData &&
|
|
81
|
+
uploadedData[0].map(function (ud) {
|
|
82
|
+
return typeof ud === "number" ? ud.toString() : ud;
|
|
83
|
+
});
|
|
84
|
+
}, [uploadedData]);
|
|
81
85
|
useEffect(function () {
|
|
82
86
|
if (!templateHeaderMatchings)
|
|
83
87
|
return;
|
|
@@ -102,25 +106,30 @@ export var ImporterContextProvider = function (_a) {
|
|
|
102
106
|
});
|
|
103
107
|
setUploadedDataEnumFieldValues(_uploadedDataEnumFieldValues);
|
|
104
108
|
}, [templateHeaderMatchings]);
|
|
109
|
+
useEffect(function () {
|
|
110
|
+
if (uploadedData)
|
|
111
|
+
setHeadersFromDataset();
|
|
112
|
+
}, [uploadedData]);
|
|
105
113
|
useEffect(function () {
|
|
106
114
|
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
-
var
|
|
108
|
-
var
|
|
109
|
-
return __generator(this, function (
|
|
110
|
-
switch (
|
|
115
|
+
var _a, organization_1, columns, importer_style_preferences, error_1, errorMsg;
|
|
116
|
+
var _b, _c;
|
|
117
|
+
return __generator(this, function (_d) {
|
|
118
|
+
switch (_d.label) {
|
|
111
119
|
case 0:
|
|
112
|
-
|
|
120
|
+
_d.trys.push([0, 2, , 3]);
|
|
113
121
|
return [4 /*yield*/, fuseApi.get("/api/v1/importer/templates/".concat(templateSlug))];
|
|
114
122
|
case 1:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
_a = (_d.sent()).data, organization_1 = _a.organization, columns = _a.columns, importer_style_preferences = _a.importer_style_preferences;
|
|
124
|
+
setOrganization(organization_1);
|
|
125
|
+
setTemplateHeaders(columns);
|
|
126
|
+
if (organization_1.plan && organization_1.plan.allow_style_customization) {
|
|
127
|
+
setStyle(getCustomTheme(importer_style_preferences));
|
|
128
|
+
}
|
|
120
129
|
return [3 /*break*/, 3];
|
|
121
130
|
case 2:
|
|
122
|
-
error_1 =
|
|
123
|
-
errorMsg = ((
|
|
131
|
+
error_1 = _d.sent();
|
|
132
|
+
errorMsg = ((_c = (_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) ||
|
|
124
133
|
"There was an error preventing the data importer from loading. Check your API Token and try again.";
|
|
125
134
|
setTemplateError(errorMsg);
|
|
126
135
|
return [3 /*break*/, 3];
|
|
@@ -129,10 +138,6 @@ export var ImporterContextProvider = function (_a) {
|
|
|
129
138
|
});
|
|
130
139
|
}); })();
|
|
131
140
|
}, []);
|
|
132
|
-
useEffect(function () {
|
|
133
|
-
if (uploadedData)
|
|
134
|
-
setHeadersFromDataset();
|
|
135
|
-
}, [uploadedData]);
|
|
136
141
|
var resetImport = function () {
|
|
137
142
|
setUploadedData(null);
|
|
138
143
|
setTemplateHeaderMatchings(null);
|
|
@@ -147,6 +152,7 @@ export var ImporterContextProvider = function (_a) {
|
|
|
147
152
|
});
|
|
148
153
|
setTemplateHeaderMatchings(_templateHeaderMatchings);
|
|
149
154
|
};
|
|
155
|
+
var inTrialMode = organization === null || organization === void 0 ? void 0 : organization.trial_mode;
|
|
150
156
|
var value = {
|
|
151
157
|
setUploadedData: setUploadedData,
|
|
152
158
|
currentStepIndex: currentStepIndex,
|
|
@@ -172,7 +178,8 @@ export var ImporterContextProvider = function (_a) {
|
|
|
172
178
|
inTrialMode: inTrialMode,
|
|
173
179
|
onClose: onClose,
|
|
174
180
|
fuseApi: fuseApi,
|
|
175
|
-
|
|
181
|
+
theme: style.theme,
|
|
182
|
+
logoURL: style.logoURL,
|
|
176
183
|
};
|
|
177
184
|
return (_jsx(ImporterContext.Provider, __assign({ value: value }, { children: children })));
|
|
178
185
|
};
|
|
@@ -14,6 +14,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
14
14
|
return __assign.apply(this, arguments);
|
|
15
15
|
};
|
|
16
16
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
import { useMemo } from "react";
|
|
17
18
|
import styled, { css } from "styled-components";
|
|
18
19
|
import { FieldTypes } from "../..";
|
|
19
20
|
import { Div } from "../../styled/utils";
|
|
@@ -26,11 +27,11 @@ var Dot = styled(Div)(function (_a) {
|
|
|
26
27
|
});
|
|
27
28
|
var Matcher = function () {
|
|
28
29
|
var _a = useImporterContext(), matcherSubstep = _a.matcherSubstep, templateHeaders = _a.templateHeaders;
|
|
29
|
-
var enumFieldsCount =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return (_jsxs(_Fragment, { children: [_jsx(Div, __assign({ centered: true }, { children: _jsx(Div, __assign({ w: 30, mt: 40, mb: 16, alignCenter: true, spaceBetween: true }, { children: enumFieldsCount > 0 &&
|
|
30
|
+
var enumFieldsCount = useMemo(function () {
|
|
31
|
+
return templateHeaders.filter(function (th) { return th.column_type === FieldTypes.enum; }).length;
|
|
32
|
+
}, [templateHeaders]);
|
|
33
|
+
var dotsUI = (_jsxs(_Fragment, { children: [_jsx(Dot, { isSelected: matcherSubstep === 0 }), _jsx(Dot, { isSelected: matcherSubstep === 1 })] }));
|
|
34
|
+
return (_jsxs(_Fragment, { children: [_jsx(Div, __assign({ centered: true }, { children: _jsx(Div, __assign({ w: 30, mt: 40, mb: 16, alignCenter: true, spaceBetween: true }, { children: enumFieldsCount > 0 && dotsUI })) })), matcherSubstep === 0 && _jsx(HeaderMatcher, {}), matcherSubstep === 1 && _jsx(EnumFieldsMatchers, {})] }));
|
|
34
35
|
};
|
|
35
36
|
export { Matcher };
|
|
36
37
|
var templateObject_1, templateObject_2;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { theme } from "../styled/theme";
|
|
14
|
+
import { Div, Span } from "../styled/utils";
|
|
15
|
+
import { useImporterContext } from "./ImporterContextProvider";
|
|
16
|
+
export var PreviewModeBanner = function () {
|
|
17
|
+
var previewMode = useImporterContext().importerOptions.previewMode;
|
|
18
|
+
return previewMode ? (_jsxs(Div, __assign({ bg: theme.colors.blue100, h: 80, alignCenter: true }, { children: [_jsx(Div, __assign({ ml: 33, mr: 8 }, { children: infoIcon })), _jsx(Span, __assign({ mr: 16 }, { children: "You’re currently in Preview mode." }))] }))) : null;
|
|
19
|
+
};
|
|
20
|
+
var infoIcon = (_jsxs("svg", __assign({ width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: [_jsx("circle", { cx: "14", cy: "2.5", r: "2.5", fill: "#0EBEBE" }), _jsx("path", { d: "M15.5075 8H6L5 10.5L10 11L6.57474 18.9354C6.57474 18.9354 6.40657 20.1663 6.57474 20.9247C6.76276 21.7725 6.97074 22.2838 7.56727 22.9139C8.6672 24.0757 9.95115 24.1037 11.5374 23.9085C14.2577 23.5737 17 19.5 17 19.5L15.5075 17.9408C15.5075 17.9408 13.5223 19.93 12.5298 19.93C11.5373 19.93 11.5374 18.9354 11.5374 18.9354L15.5075 8Z", fill: "#0EBEBE" })] })));
|
|
@@ -14,18 +14,11 @@ import { useMemo } from "react";
|
|
|
14
14
|
import { Div } from "../../styled/utils";
|
|
15
15
|
import { FieldTypes } from "../../types";
|
|
16
16
|
import { Spreadsheet } from "../common/Spreadsheet";
|
|
17
|
+
import { isFloat, isInteger, isTrue } from "../common/Spreadsheet/common/index";
|
|
17
18
|
import { getColumnType, getSpreadsheetRowWidth } from "../common/utils";
|
|
18
19
|
import { useImporterContext } from "../ImporterContextProvider";
|
|
19
20
|
import { useSpreadsheetReviewContext } from "../SpreadsheetReviewContextProvider";
|
|
20
21
|
import { AppResponseModal } from "./AppResponseModal";
|
|
21
|
-
var valueIsTrue = function (value) {
|
|
22
|
-
var _value = (value || "").toString().toLowerCase();
|
|
23
|
-
return ["true", "yes", "1", "y", "on", "t"].includes(_value);
|
|
24
|
-
};
|
|
25
|
-
var valueIsInteger = function (value) { return /^-?[0-9]+$/.test(value + ""); };
|
|
26
|
-
var valueIsNumber = function (value) {
|
|
27
|
-
return /^-?[0-9]+(?:\.[0-9]+)?$/.test(value + "");
|
|
28
|
-
};
|
|
29
22
|
var useInitialData = function () {
|
|
30
23
|
var _a = useImporterContext(), templateHeaderMatchings = _a.templateHeaderMatchings, enumFieldValueMatchings = _a.enumFieldValueMatchings, templateHeaders = _a.templateHeaders, uploadedDataHeaders = _a.uploadedDataHeaders, uploadedData = _a.uploadedData, formatRecord = _a.formatRecord;
|
|
31
24
|
return useMemo(function () {
|
|
@@ -50,11 +43,11 @@ var useInitialData = function () {
|
|
|
50
43
|
if (columnType === FieldTypes.enum)
|
|
51
44
|
record[key] = enumFieldValueMatchings[templateLabel][value];
|
|
52
45
|
if (columnType === FieldTypes.boolean)
|
|
53
|
-
record[key] =
|
|
46
|
+
record[key] = isTrue(value);
|
|
54
47
|
if (columnType === FieldTypes.float)
|
|
55
|
-
record[key] =
|
|
48
|
+
record[key] = isFloat(value) ? parseFloat(value) : value;
|
|
56
49
|
if (columnType === FieldTypes.integer)
|
|
57
|
-
record[key] =
|
|
50
|
+
record[key] = isInteger(value) ? parseInt(value) : value;
|
|
58
51
|
});
|
|
59
52
|
return formatRecord ? formatRecord(record) : record;
|
|
60
53
|
};
|
|
@@ -71,13 +64,16 @@ var Review = function () {
|
|
|
71
64
|
var _a = useImporterContext(), templateHeaders = _a.templateHeaders, onValidateRecord = _a.onValidateRecord, onValidateBatch = _a.onValidateBatch, _b = _a.importerOptions, batchValidationDelayMs = _b.batchValidationDelayMs, batchValidationSize = _b.batchValidationSize;
|
|
72
65
|
var initialData = useInitialData();
|
|
73
66
|
var _c = useSpreadsheetReviewContext(), submittedData = _c.submittedData, appResponse = _c.appResponse, setReviewedData = _c.setReviewedData;
|
|
74
|
-
var fields =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
var fields = useMemo(function () {
|
|
68
|
+
return templateHeaders.map(function (templateHeader) { return ({
|
|
69
|
+
label: templateHeader.label,
|
|
70
|
+
name: templateHeader.internal_key,
|
|
71
|
+
type: FieldTypes[templateHeader.column_type] || FieldTypes.string,
|
|
72
|
+
isRequired: templateHeader.required,
|
|
73
|
+
options: templateHeader.values,
|
|
74
|
+
pattern: templateHeader.pattern,
|
|
75
|
+
}); });
|
|
76
|
+
}, [templateHeaders]);
|
|
81
77
|
var spreadsheetUI = useMemo(function () { return (_jsx(Div, { children: _jsx(Spreadsheet, __assign({ rowWidth: getSpreadsheetRowWidth(fields, 6), options: {
|
|
82
78
|
batchValidationDelayMs: batchValidationDelayMs,
|
|
83
79
|
batchValidationSize: batchValidationSize || initialData.length,
|
|
@@ -47,8 +47,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
};
|
|
48
48
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
49
49
|
import { createContext, useContext, useState } from "react";
|
|
50
|
-
import { getUnsubmittedData } from ".";
|
|
51
50
|
import { AppLoading } from "./common/AppLoading";
|
|
51
|
+
import { getUnsubmittedData } from "./common/utils";
|
|
52
52
|
import { useImporterContext } from "./ImporterContextProvider";
|
|
53
53
|
var SpreadsheetReviewContext = createContext({});
|
|
54
54
|
export var SpreadsheetReviewContextProvider = function (_a) {
|
|
@@ -31,7 +31,7 @@ var StepIndexWrapper = styled(Div)(templateObject_2 || (templateObject_2 = __mak
|
|
|
31
31
|
return p.isSelected && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: 32px;\n width: 32px;\n border: solid 1px ", ";\n color: ", ";\n background-color: ", ";\n "], ["\n height: 32px;\n width: 32px;\n border: solid 1px ", ";\n color: ", ";\n background-color: ", ";\n "])), function (p) { return p.theme.colors.blue500; }, function (p) { return p.theme.colors.white; }, function (p) { return p.theme.colors.blue500; });
|
|
32
32
|
});
|
|
33
33
|
var StepperWrapper = styled(Div)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n background-color: ", ";\n user-select: none;\n border-bottom: 1px solid ", ";\n"], ["\n background-color: ", ";\n user-select: none;\n border-bottom: 1px solid ", ";\n"])), function (p) { return p.theme.colors.white; }, function (p) { return p.theme.colors.gray300; });
|
|
34
|
-
var Logo = styled.img(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n max-height: 70px;\n position: absolute;\n left: 41px;\n"], ["\n max-height: 70px;\n position: absolute;\n left: 41px;\n"])));
|
|
34
|
+
var Logo = styled.img(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n max-height: 70px;\n max-width: 300px;\n position: absolute;\n left: 41px;\n"], ["\n max-height: 70px;\n max-width: 300px;\n position: absolute;\n left: 41px;\n"])));
|
|
35
35
|
var StepIndex = function (_a) {
|
|
36
36
|
var index = _a.index, isSelected = _a.isSelected, isCompleted = _a.isCompleted;
|
|
37
37
|
return (_jsx(_Fragment, { children: isCompleted ? (_jsx(Div, __assign({ centered: true, body2: true, bold: true, mr: 8 }, { children: whiteCheckIcon }))) : (_jsx(StepIndexWrapper, __assign({ centered: true, body2: true, bold: true, mr: 8, isSelected: isSelected }, { children: index }))) }));
|
|
@@ -112,8 +112,15 @@ var Stepper = function (_a) {
|
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
var goBack = function () {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
var isMatchingColumnValues = matcherSubstep === 1;
|
|
116
|
+
var isInMachStep = currentStepIndex === 1;
|
|
117
|
+
var shouldBackOnlyMatcherSubStep = isMatchingColumnValues && isInMachStep;
|
|
118
|
+
if (shouldBackOnlyMatcherSubStep) {
|
|
119
|
+
setMatcherSubstep(matcherSubstep - 1);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
setCurrentStepIndex(currentStepIndex - 1);
|
|
123
|
+
}
|
|
117
124
|
};
|
|
118
125
|
var skipStep = function () {
|
|
119
126
|
setStep();
|
|
@@ -61,7 +61,10 @@ var ImporterDropzone = function () {
|
|
|
61
61
|
reader.onload = function (event) {
|
|
62
62
|
var results = event.target.result;
|
|
63
63
|
var getDataFromFile = function (fileResults) {
|
|
64
|
-
var workBook = XLSX.read(fileResults, {
|
|
64
|
+
var workBook = XLSX.read(fileResults, {
|
|
65
|
+
type: "array",
|
|
66
|
+
raw: true,
|
|
67
|
+
});
|
|
65
68
|
var workBookName = workBook.SheetNames[0];
|
|
66
69
|
var sheet = workBook.Sheets[workBookName];
|
|
67
70
|
return XLSX.utils.sheet_to_json(sheet, { header: 1 });
|
|
@@ -30,6 +30,7 @@ import { useImporterContext } from "../ImporterContextProvider";
|
|
|
30
30
|
import { FieldTypes } from "../../types";
|
|
31
31
|
import { Div } from "../../styled/utils";
|
|
32
32
|
import { getSpreadsheetRowWidth } from "../common/utils";
|
|
33
|
+
import { useMemo } from "react";
|
|
33
34
|
var HeaderButtonsWrapper = styled(Div)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n > div {\n margin-left: 8px;\n margin-right: 8px;\n }\n"], ["\n > div {\n margin-left: 8px;\n margin-right: 8px;\n }\n"])));
|
|
34
35
|
var HeaderButtons = function () {
|
|
35
36
|
var _a = useImporterContext(), setCurrentStepIndex = _a.setCurrentStepIndex, resetImport = _a.resetImport;
|
|
@@ -40,13 +41,14 @@ var HeaderButtons = function () {
|
|
|
40
41
|
};
|
|
41
42
|
var HeadersPreview = function () {
|
|
42
43
|
var uploadedData = useImporterContext().uploadedData;
|
|
43
|
-
var formattedData = (function () {
|
|
44
|
+
var formattedData = useMemo(function () {
|
|
44
45
|
var firstRowLen = 0;
|
|
45
|
-
if (uploadedData.length > 0 && Array.isArray(uploadedData[0]))
|
|
46
|
+
if (uploadedData.length > 0 && Array.isArray(uploadedData[0])) {
|
|
46
47
|
firstRowLen = uploadedData[0].length;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
}
|
|
49
|
+
var placeholderHeaders = new Array(firstRowLen)
|
|
50
|
+
.fill(null)
|
|
51
|
+
.map(function (_, i) { return String.fromCharCode(65 + i); });
|
|
50
52
|
var getDataRows = function () {
|
|
51
53
|
var emptyRows = [];
|
|
52
54
|
if (uploadedData.length < 20)
|
|
@@ -60,18 +62,18 @@ var HeadersPreview = function () {
|
|
|
60
62
|
return entry;
|
|
61
63
|
});
|
|
62
64
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
});
|
|
65
|
+
return getDataRows();
|
|
66
|
+
}, [uploadedData]);
|
|
67
|
+
var readonlyFields = useMemo(function () {
|
|
68
|
+
return Object.keys(formattedData[0]).map(function (key) {
|
|
69
|
+
return {
|
|
70
|
+
label: key,
|
|
71
|
+
name: key,
|
|
72
|
+
type: FieldTypes.string,
|
|
73
|
+
isRequired: false,
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}, []);
|
|
75
77
|
return (_jsx(_Fragment, { children: _jsxs(Div, __assign({ flexColumn: true, centered: true, pt: 40 }, { children: [_jsx(Div, __assign({ h2: true, mb: 16 }, { children: "Verify Your Column Headers" })), _jsx(Div, __assign({ body1: true, mb: 24, textAlignCenter: true }, { children: "File must contain column headers to proceed." })), _jsx(HeaderButtons, {}), _jsx(Div, __assign({ w100: true, centered: true, mb: 36 }, { children: _jsx(Spreadsheet, __assign({ rowWidth: getSpreadsheetRowWidth(readonlyFields, 6), isReadOnly: true, initialData: formattedData }, { fields: readonlyFields }, { highlightFirstRow: true })) }))] })) }));
|
|
76
78
|
};
|
|
77
79
|
export default HeadersPreview;
|
|
@@ -55,7 +55,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
55
55
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
56
|
};
|
|
57
57
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
58
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
58
|
+
import { createContext, useContext, useEffect, useState, useMemo, } from "react";
|
|
59
59
|
import { formatBatchErrors } from "../../..";
|
|
60
60
|
import { getRecordErrors, getRenderedRecordWithErrors, recordIsEmpty, } from "./common";
|
|
61
61
|
var MINIMUM_ROW_COUNT = 20;
|
|
@@ -102,10 +102,10 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
102
102
|
}), columnErrorCounts = _l.columnErrorCounts, totalErrors = _l.totalErrors, isValidationComplete = _l.isValidationComplete;
|
|
103
103
|
useEffect(function () {
|
|
104
104
|
var init = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
105
|
-
var batchValidationDelayMs, batchValidationSize,
|
|
105
|
+
var batchValidationDelayMs, batchValidationSize, addEmptyRows, validateInBatches;
|
|
106
106
|
return __generator(this, function (_a) {
|
|
107
107
|
batchValidationDelayMs = options.batchValidationDelayMs, batchValidationSize = options.batchValidationSize;
|
|
108
|
-
|
|
108
|
+
addEmptyRows = function () {
|
|
109
109
|
var newData = __spreadArray([], data, true);
|
|
110
110
|
var emptyRecord = fields.reduce(function (obj, f) {
|
|
111
111
|
var _a;
|
|
@@ -120,7 +120,7 @@ export var SpreadsheetContextProvider = function (_a) {
|
|
|
120
120
|
setData(newData);
|
|
121
121
|
};
|
|
122
122
|
if (data.length < MINIMUM_ROW_COUNT)
|
|
123
|
-
|
|
123
|
+
addEmptyRows();
|
|
124
124
|
validateInBatches = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
125
|
var validationErrors, batchSize, batchCount, batchIdx, idx, batch, errors, validationPercentage;
|
|
126
126
|
return __generator(this, function (_a) {
|
|
@@ -280,7 +280,9 @@ var useValidationState = function (_a) {
|
|
|
280
280
|
};
|
|
281
281
|
updateErrorCounts();
|
|
282
282
|
}, [data, batchValidationErrors]);
|
|
283
|
-
var totalErrors =
|
|
283
|
+
var totalErrors = useMemo(function () {
|
|
284
|
+
return Object.keys(columnErrorCounts).reduce(function (total, key) { return total + (columnErrorCounts[key] || 0); }, 0);
|
|
285
|
+
}, []);
|
|
284
286
|
var isValidationComplete = batchValidationErrors && totalErrors === 0;
|
|
285
287
|
return { columnErrorCounts: columnErrorCounts, totalErrors: totalErrors, isValidationComplete: isValidationComplete };
|
|
286
288
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
+
return cooked;
|
|
4
|
+
};
|
|
5
|
+
var __assign = (this && this.__assign) || function () {
|
|
6
|
+
__assign = Object.assign || function(t) {
|
|
7
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
8
|
+
s = arguments[i];
|
|
9
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
10
|
+
t[p] = s[p];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
};
|
|
16
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
import { TooltipProvider } from "../../../../common";
|
|
18
|
+
import { Div } from "../../../../styled/utils";
|
|
19
|
+
import { useSpreadsheetContext } from "../SpreadsheetContextProvider";
|
|
20
|
+
import styled, { css } from "styled-components";
|
|
21
|
+
var ErrorCount = styled(Div)(function (_a) {
|
|
22
|
+
var _b = _a.theme, colors = _b.colors, c = _b.css;
|
|
23
|
+
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n color: ", ";\n background: ", ";\n border: solid 1px ", ";\n padding: 4px 7px;\n border-radius: 56px;\n min-width: 24px;\n ", ";\n "], ["\n color: ", ";\n background: ", ";\n border: solid 1px ", ";\n padding: 4px 7px;\n border-radius: 56px;\n min-width: 24px;\n ", ";\n "])), colors.error, colors.red100, colors.error, c.centered);
|
|
24
|
+
});
|
|
25
|
+
export var FieldHeader = function (_a) {
|
|
26
|
+
var field = _a.field, sortByFieldErrors = _a.sortByFieldErrors;
|
|
27
|
+
var columnErrorCounts = useSpreadsheetContext().columnErrorCounts;
|
|
28
|
+
var fieldErrorCount = columnErrorCounts[field.name];
|
|
29
|
+
return (_jsxs(Div, __assign({ p: "0 16px", spaceBetween: true, w100: true, alignCenter: true }, { children: [_jsxs(Div, __assign({ truncateText: true }, { children: [field.label, field.isRequired && "*"] })), fieldErrorCount && (_jsx(TooltipProvider, __assign({ mr: 3, w: 35, tooltip: "Sort by ".concat(field.label, " errors") }, { children: _jsx(ErrorCount, __assign({ onClick: function () { return sortByFieldErrors(field.name); } }, { children: _jsx(Div, __assign({ centered: true }, { children: _jsx(Div, __assign({ w: 35, textAlignCenter: true, label3: true, truncateText: true }, { children: fieldErrorCount })) })) })) })))] })));
|
|
30
|
+
};
|
|
31
|
+
var templateObject_1;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Option } from "../../../../../common/inputs/Autocomplete";
|
|
3
|
+
import { Record, FieldTypes } from "../../../../../types";
|
|
4
|
+
export declare type AutoCompleteOption = Option;
|
|
5
|
+
export declare type SpreadsheetAutocompleteProps = {
|
|
6
|
+
name: string;
|
|
7
|
+
record: Record;
|
|
8
|
+
options: AutoCompleteOption[];
|
|
6
9
|
isInputDisabled?: boolean;
|
|
7
|
-
|
|
10
|
+
fieldType: FieldTypes;
|
|
11
|
+
};
|
|
12
|
+
export declare const SpreadsheetAutocomplete: React.FC<SpreadsheetAutocompleteProps>;
|
|
@@ -15,9 +15,9 @@ var __assign = (this && this.__assign) || function () {
|
|
|
15
15
|
};
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
import styled, { css } from "styled-components";
|
|
18
|
-
import { SpreadsheetField, useSpreadsheetField
|
|
18
|
+
import { SpreadsheetField, useSpreadsheetField } from ".";
|
|
19
19
|
import { spreadsheetRowHeightPx } from "..";
|
|
20
|
-
import { Autocomplete as AutocompleteBase } from "../../../../../common/inputs/Autocomplete";
|
|
20
|
+
import { Autocomplete as AutocompleteBase, } from "../../../../../common/inputs/Autocomplete";
|
|
21
21
|
import { SelectMenuDiv, SelectMenuScrollArea, } from "../../../../../common/inputs/SelectMenu";
|
|
22
22
|
import { HTMLInput, TextInputIcon, } from "../../../../../common/inputs/TextInput";
|
|
23
23
|
import { useSpreadsheetContext } from "../../SpreadsheetContextProvider";
|
|
@@ -26,12 +26,11 @@ var Autocomplete = styled(AutocompleteBase)(templateObject_3 || (templateObject_
|
|
|
26
26
|
}, function (p) {
|
|
27
27
|
return p.hasError && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n color: ", ";\n "], ["\n color: ", ";\n "])), function (p) { return p.theme.colors.error; });
|
|
28
28
|
}, TextInputIcon, SelectMenuDiv, SelectMenuScrollArea);
|
|
29
|
-
export var SpreadsheetAutocomplete = function (
|
|
30
|
-
var name =
|
|
31
|
-
var
|
|
32
|
-
var _c = useSpreadsheetField(name, record), value = _c.value, setValue = _c.setValue;
|
|
29
|
+
export var SpreadsheetAutocomplete = function (props) {
|
|
30
|
+
var name = props.name, record = props.record, options = props.options, fieldType = props.fieldType, _a = props.isInputDisabled, isInputDisabled = _a === void 0 ? false : _a;
|
|
31
|
+
var _b = useSpreadsheetField(name, record, fieldType), value = _b.value, setValue = _b.setValue, validationError = _b.validationError;
|
|
33
32
|
var setIsScrollingEnabled = useSpreadsheetContext().setIsScrollingEnabled;
|
|
34
|
-
return (_jsx(SpreadsheetField, __assign({
|
|
33
|
+
return (_jsx(SpreadsheetField, __assign({ validationError: validationError }, { children: _jsx(Autocomplete, { placement: "bottom", isInputDisabled: isInputDisabled, hasError: !!validationError, onToggle: function (isOpen) { return setIsScrollingEnabled(!isOpen); }, options: options, value: value, icon: chevronDownIcon, onChange: function (v) { return setValue(v); } }) })));
|
|
35
34
|
};
|
|
36
35
|
var chevronDownIcon = (_jsx("svg", __assign({ width: "10", height: "6", viewBox: "0 0 10 6", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, { children: _jsx("path", { d: "M8.46289 1L4.98131 4.48159L1.49972 1", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })));
|
|
37
36
|
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { HTMLInputCSSProps } from "../../../../../styled/utils";
|
|
3
|
-
import { Record } from "../../../../../types";
|
|
4
|
-
declare type SpreadsheetTextInputArgs = {
|
|
3
|
+
import { FieldTypes, Record } from "../../../../../types";
|
|
4
|
+
export declare type SpreadsheetTextInputArgs = {
|
|
5
5
|
name: string;
|
|
6
6
|
record: Record;
|
|
7
|
+
fieldType: FieldTypes;
|
|
7
8
|
} & HTMLInputCSSProps;
|
|
8
|
-
export declare const SpreadsheetInput: ({ name, record, ...props }: SpreadsheetTextInputArgs) => JSX.Element;
|
|
9
|
+
export declare const SpreadsheetInput: ({ name, record, fieldType, ...props }: SpreadsheetTextInputArgs) => JSX.Element;
|
|
9
10
|
export declare const Input: import("styled-components").StyledComponent<"input", import("styled-components").DefaultTheme, {
|
|
10
11
|
hasError: boolean;
|
|
11
12
|
} & import("../../../../../styled/utils").HTMLInputProps & import("../../../../../styled/utils").CSSProps, never>;
|
|
12
|
-
export {};
|
|
@@ -26,12 +26,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
26
26
|
};
|
|
27
27
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
28
|
import styled, { css } from "styled-components";
|
|
29
|
-
import { SpreadsheetField, useSpreadsheetField
|
|
29
|
+
import { SpreadsheetField, useSpreadsheetField } from ".";
|
|
30
30
|
export var SpreadsheetInput = function (_a) {
|
|
31
|
-
var name = _a.name, record = _a.record, props = __rest(_a, ["name", "record"]);
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
return (_jsx(SpreadsheetField, __assign({}, { name: name, record: record }, { children: _jsx(Input, __assign({ hasError: !!validationError, value: value || "", onChange: function (_a) {
|
|
31
|
+
var name = _a.name, record = _a.record, fieldType = _a.fieldType, props = __rest(_a, ["name", "record", "fieldType"]);
|
|
32
|
+
var _b = useSpreadsheetField(name, record, fieldType), value = _b.value, setValue = _b.setValue, validationError = _b.validationError;
|
|
33
|
+
return (_jsx(SpreadsheetField, __assign({ validationError: validationError }, { children: _jsx(Input, __assign({ hasError: !!validationError, value: value || "", onChange: function (_a) {
|
|
35
34
|
var value = _a.target.value;
|
|
36
35
|
return setValue(value);
|
|
37
36
|
} }, props)) })));
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Record } from "../../../../../types";
|
|
2
|
+
import { FieldTypes, Record } from "../../../../../types";
|
|
3
|
+
export declare const parseValue: (fieldType: FieldTypes, value: any) => any;
|
|
3
4
|
export declare const useValidationError: (fieldName: string, record: Record) => {
|
|
4
5
|
validationError: any;
|
|
5
6
|
};
|
|
6
|
-
export declare const useSpreadsheetField: (name: any, record: Record) => {
|
|
7
|
+
export declare const useSpreadsheetField: (name: any, record: Record, fieldType: FieldTypes) => {
|
|
7
8
|
value: any;
|
|
8
9
|
setValue: React.Dispatch<any>;
|
|
10
|
+
validationError: any;
|
|
9
11
|
};
|
|
10
|
-
export declare const SpreadsheetField: ({
|
|
11
|
-
|
|
12
|
-
record: any;
|
|
12
|
+
export declare const SpreadsheetField: ({ validationError, children }: {
|
|
13
|
+
validationError: any;
|
|
13
14
|
children: any;
|
|
14
15
|
}) => JSX.Element;
|