fuse-importer 0.1.3-testing → 0.1.4-testing

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.
@@ -1,22 +1,11 @@
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
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
6
2
  import React from "react";
7
- import styled, { css } from "styled-components";
8
- import { Div } from "../../styled/utils";
9
3
  import { useImporterContext } from "../contexts/ImporterContextProvider";
10
4
  import { HeaderMatcher } from "./HeaderMatcher";
11
5
  import { EnumFieldsMatchers } from "./EnumFieldsMatchers";
12
6
  import { areEqual } from "react-window";
13
- var Dot = styled(Div)(function (_a) {
14
- var colors = _a.theme.colors, isSelected = _a.isSelected;
15
- return css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n height: 8px;\n width: 8px;\n border-radius: 100%;\n background: ", ";\n ", "\n "], ["\n height: 8px;\n width: 8px;\n border-radius: 100%;\n background: ", ";\n ", "\n "])), colors.outlineInputs, isSelected && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n height: 12px;\n width: 12px;\n background: ", ";\n "], ["\n height: 12px;\n width: 12px;\n background: ", ";\n "])), colors.highlight01));
16
- });
17
7
  var Matcher = function () {
18
8
  var matcherSubstep = useImporterContext().matcherSubstep;
19
9
  return (_jsxs(_Fragment, { children: [matcherSubstep === 0 && _jsx(HeaderMatcher, {}), matcherSubstep === 1 && _jsx(EnumFieldsMatchers, {})] }));
20
10
  };
21
11
  export default React.memo(Matcher, areEqual);
22
- var templateObject_1, templateObject_2;
@@ -71,7 +71,7 @@ import Papa from "papaparse";
71
71
  import { AppLoading } from "../common/AppLoading";
72
72
  import { isRecordEmpty } from "../common/Spreadsheet/common";
73
73
  import { sendRecordsToIntegrations } from "../common/utils";
74
- import { useImporterContext } from "../contexts/ImporterContextProvider";
74
+ import { useImporterContext, } from "../contexts/ImporterContextProvider";
75
75
  import { transformToRecords } from "../data/index";
76
76
  import { getPreviewDataSet, getReviewDataSet, getTemplateFields, recordListToDataSet, } from "../data";
77
77
  import { useAppLoadingContext } from "../../common/AppLoadingContextProvider";
@@ -98,6 +98,41 @@ var trackImportedRowsCount = function (fuseApi, templateSlug, rowCount) { return
98
98
  }
99
99
  });
100
100
  }); };
101
+ var buildColumnMappingsFromHeaderMatchings = function (templateHeaders, templateHeaderMatchings, columnMappingsAttributes) {
102
+ return templateHeaders.map(function (column) {
103
+ var existingMatching = columnMappingsAttributes.find(function (matching) {
104
+ return matching.template_column_name === column.label &&
105
+ matching.matched_column_name === templateHeaderMatchings[column.label];
106
+ });
107
+ var mappedColumn = {
108
+ matched_column_name: templateHeaderMatchings[column.label],
109
+ template_column_name: column.label,
110
+ };
111
+ if (existingMatching) {
112
+ mappedColumn.id = existingMatching.id;
113
+ }
114
+ return mappedColumn;
115
+ });
116
+ };
117
+ var saveMappedColumns = function (columnMappings, fuseApi, templateSlug) { return __awaiter(void 0, void 0, void 0, function () {
118
+ var error_2;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ _a.trys.push([0, 2, , 3]);
123
+ return [4 /*yield*/, fuseApi.patch("/api/v1/templates/".concat(templateSlug), {
124
+ column_mappings_attributes: columnMappings,
125
+ })];
126
+ case 1:
127
+ _a.sent();
128
+ return [3 /*break*/, 3];
129
+ case 2:
130
+ error_2 = _a.sent();
131
+ throw new Error("There was an error trying to save column mappings");
132
+ case 3: return [2 /*return*/];
133
+ }
134
+ });
135
+ }); };
101
136
  var getImportWasSuccessful = function (response) {
102
137
  return !response.errors || !Object.keys(response.errors).length;
103
138
  };
@@ -132,7 +167,7 @@ function csvExport(data) {
132
167
  }
133
168
  export var ReviewContextProvider = function (_a) {
134
169
  var initialRecords = _a.initialRecords, children = _a.children;
135
- var _b = useImporterContext(), templateHeaderMatchings = _b.templateHeaderMatchings, enumFieldValueMatchings = _b.enumFieldValueMatchings, templateHeaders = _b.templateHeaders, uploadedDataHeaders = _b.uploadedDataHeaders, headerRowIndex = _b.headerRowIndex, uploadedData = _b.uploadedData, currentStepIndex = _b.currentStepIndex, integrations = _b.integrations, templateSlug = _b.templateSlug, fuseApi = _b.fuseApi, setSelectedRows = _b.setSelectedRows, _c = _b.importerOptions, disableSubmitIfInvalid = _c.disableSubmitIfInvalid, batchValidationDelayMs = _c.batchValidationDelayMs, batchValidationSize = _c.batchValidationSize, previewMode = _c.previewMode, loadingComponent = _c.loadingComponent, onSubmit = _b.onSubmit, onValidateRecord = _b.onValidateRecord, formatRecord = _b.formatRecord, selectedRows = _b.selectedRows;
170
+ var _b = useImporterContext(), templateHeaderMatchings = _b.templateHeaderMatchings, enumFieldValueMatchings = _b.enumFieldValueMatchings, templateHeaders = _b.templateHeaders, uploadedDataHeaders = _b.uploadedDataHeaders, headerRowIndex = _b.headerRowIndex, uploadedData = _b.uploadedData, currentStepIndex = _b.currentStepIndex, integrations = _b.integrations, templateSlug = _b.templateSlug, fuseApi = _b.fuseApi, setSelectedRows = _b.setSelectedRows, _c = _b.importerOptions, disableSubmitIfInvalid = _c.disableSubmitIfInvalid, batchValidationDelayMs = _c.batchValidationDelayMs, batchValidationSize = _c.batchValidationSize, previewMode = _c.previewMode, loadingComponent = _c.loadingComponent, onSubmit = _b.onSubmit, onValidateRecord = _b.onValidateRecord, formatRecord = _b.formatRecord, selectedRows = _b.selectedRows, columnMappingsAttributes = _b.columnMappingsAttributes;
136
171
  var setIsLoadingApp = useAppLoadingContext().setIsLoadingApp;
137
172
  var _d = useState(false), isSubmitting = _d[0], setIsSubmitting = _d[1];
138
173
  var _e = useState(false), isSubmitDisabled = _e[0], setIsSubmitDisabled = _e[1];
@@ -166,11 +201,11 @@ export var ReviewContextProvider = function (_a) {
166
201
  }
167
202
  }, [reviewFields, selectedRows]);
168
203
  var onSubmitData = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
169
- var dataSet, dataSetValues, validDataSetValues, validDataSetLength, invalidRecords_1, applicationResponse, isAppResponseSuccessful, _a, errors, isDataValid, recordsToDisplayFiltered, invalidDataSet, error_2;
204
+ var dataSet, dataSetValues, validDataSetValues, validDataSetLength, invalidRecords_1, applicationResponse, isAppResponseSuccessful, _a, errors, isDataValid, recordsToDisplayFiltered, invalidDataSet, columnMappings, error_3;
170
205
  return __generator(this, function (_b) {
171
206
  switch (_b.label) {
172
207
  case 0:
173
- _b.trys.push([0, 5, 6, 7]);
208
+ _b.trys.push([0, 6, 7, 8]);
174
209
  if (!reviewDataSetRef.current)
175
210
  return [2 /*return*/];
176
211
  setIsSubmitting(true);
@@ -202,23 +237,27 @@ export var ReviewContextProvider = function (_a) {
202
237
  invalidDataSet = recordListToDataSet(invalidRecords_1, reviewFields);
203
238
  setReviewInitialDataSet(invalidDataSet);
204
239
  setInitialDataSetUpdatedAt(Date.now());
205
- if (!!previewMode) return [3 /*break*/, 4];
240
+ if (!!previewMode) return [3 /*break*/, 5];
206
241
  return [4 /*yield*/, trackImportedRowsCount(fuseApi, templateSlug, validDataSetLength)];
207
242
  case 2:
208
243
  _b.sent();
209
244
  return [4 /*yield*/, sendRecordsToIntegrations(dataSetValues, integrations)];
210
245
  case 3:
211
246
  _b.sent();
212
- _b.label = 4;
213
- case 4: return [3 /*break*/, 7];
214
- case 5:
215
- error_2 = _b.sent();
216
- console.error(error_2);
217
- return [3 /*break*/, 7];
247
+ columnMappings = buildColumnMappingsFromHeaderMatchings(templateHeaders, templateHeaderMatchings, columnMappingsAttributes);
248
+ return [4 /*yield*/, saveMappedColumns(columnMappings, fuseApi, templateSlug)];
249
+ case 4:
250
+ _b.sent();
251
+ _b.label = 5;
252
+ case 5: return [3 /*break*/, 8];
218
253
  case 6:
254
+ error_3 = _b.sent();
255
+ console.error(error_3);
256
+ return [3 /*break*/, 8];
257
+ case 7:
219
258
  setIsSubmitting(false);
220
259
  return [7 /*endfinally*/];
221
- case 7: return [2 /*return*/];
260
+ case 8: return [2 /*return*/];
222
261
  }
223
262
  });
224
263
  }); }, [reviewFields, onSubmit]);
@@ -242,7 +281,9 @@ export var ReviewContextProvider = function (_a) {
242
281
  reviewDataSetRef.current = null;
243
282
  return;
244
283
  }
245
- var sleep = function (n) { return new Promise(function (resolve) { return setTimeout(resolve, n); }); };
284
+ var sleep = function (n) {
285
+ return new Promise(function (resolve) { return setTimeout(resolve, n); });
286
+ };
246
287
  if (currentStepIndex === 0) {
247
288
  if (!previewInitialDataSet) {
248
289
  //Uploader spreadsheet data
@@ -10,7 +10,10 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import Fuse from "fuse.js";
13
- import { fusejsOptions, } from "../../contexts/ImporterContextProvider";
13
+ var fusejsOptions = {
14
+ includeScore: true,
15
+ threshold: 0.35,
16
+ };
14
17
  export var getEnumFieldValueMatchingsInitialValue = function (_a) {
15
18
  var uploadedDataEnumFieldValues = _a.uploadedDataEnumFieldValues, templateHeaders = _a.templateHeaders;
16
19
  var res = {};
@@ -18,11 +21,11 @@ export var getEnumFieldValueMatchingsInitialValue = function (_a) {
18
21
  uploadedDataEnumFieldValues[templateLabel].forEach(function (uploadedValue, _index) {
19
22
  var _a, _b;
20
23
  var templateOptions = (_a = templateHeaders.find(function (th) { return th.label === templateLabel; })) === null || _a === void 0 ? void 0 : _a.values;
21
- var fuse = new Fuse(templateOptions, fusejsOptions);
22
- var fuseResults = fuse.search(uploadedValue);
24
+ var fuzzySearch = new Fuse(templateOptions, fusejsOptions);
25
+ var fuzzySearchResults = fuzzySearch.search(uploadedValue);
23
26
  var previousRes = __assign({}, (res[templateLabel] || {}));
24
27
  res[templateLabel] = previousRes;
25
- res[templateLabel][uploadedValue] = (_b = fuseResults[0]) === null || _b === void 0 ? void 0 : _b.item;
28
+ res[templateLabel][uploadedValue] = (_b = fuzzySearchResults[0]) === null || _b === void 0 ? void 0 : _b.item;
26
29
  });
27
30
  };
28
31
  var templateLabels = Object.keys(uploadedDataEnumFieldValues);
@@ -13,8 +13,44 @@ var __assign = (this && this.__assign) || function () {
13
13
  };
14
14
  return __assign.apply(this, arguments);
15
15
  };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
16
52
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
17
- import { useState } from "react";
53
+ import { useState, useEffect } from "react";
18
54
  import { useTranslation } from "react-i18next";
19
55
  import styled, { css } from "styled-components";
20
56
  import { Button, ChevronRightIcon, closeIconCondensed } from "../../common";
@@ -27,6 +63,7 @@ import { Step } from "./Step";
27
63
  import { StepperSubmitModal } from "./StepperSubmitModal";
28
64
  import { UnmatchedHeadersModal } from "./UnmatchedHeadersModal";
29
65
  import { getEnumFieldValueMatchingsInitialValue } from "./common/getEnumFieldValueMatchingsInitialValue";
66
+ import { useAppLoadingContext } from "../../common/AppLoadingContextProvider";
30
67
  var StepperWrapper = styled(Div)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background-color: ", ";\n border-bottom: 1px solid ", ";\n user-select: none;\n"], ["\n background-color: ", ";\n border-bottom: 1px solid ", ";\n user-select: none;\n"])), function (p) { return p.theme.colors.white; }, function (p) { return p.theme.colors.gray300; });
31
68
  var StepperContainer = styled(Div)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n align-items: center;\n display: flex;\n gap: 16px;\n justify-content: space-between;\n padding-left: 32px;\n padding-right: 32px;\n width: 100%;\n"], ["\n align-items: center;\n display: flex;\n gap: 16px;\n justify-content: space-between;\n padding-left: 32px;\n padding-right: 32px;\n width: 100%;\n"])));
32
69
  var Steps = styled(Div)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n @media (max-width: 630px) {\n display: none;\n }\n"], ["\n @media (max-width: 630px) {\n display: none;\n }\n"])));
@@ -43,8 +80,30 @@ export var Stepper = function (_a) {
43
80
  var t = useTranslation("general").t;
44
81
  var _c = useState(false), isSubmitModalOpen = _c[0], setIsSubmitModalOpen = _c[1];
45
82
  var _d = useState(false), isConfirmCloseModalOpen = _d[0], setIsConfirmCloseModalOpen = _d[1];
83
+ var setIsLoadingApp = useAppLoadingContext().setIsLoadingApp;
46
84
  var _e = useReviewContext(), appResponse = _e.appResponse, isSubmitDisabled = _e.isSubmitDisabled, onSubmit = _e.onSubmit;
47
- var _f = useImporterContext(), initialRecords = _f.initialRecords, currentStepIndex = _f.currentStepIndex, templateHeaderMatchings = _f.templateHeaderMatchings, matcherSubstep = _f.matcherSubstep, templateHeaders = _f.templateHeaders, uploadedDataEnumFieldValues = _f.uploadedDataEnumFieldValues, setEnumFieldValueMatchings = _f.setEnumFieldValueMatchings, setMatcherSubstep = _f.setMatcherSubstep, setCurrentStepIndex = _f.setCurrentStepIndex, onClose = _f.onClose, isUsingManualImport = _f.isUsingManualImport, resetImporterWhenUsingManualImport = _f.resetImporterWhenUsingManualImport, uploadedData = _f.uploadedData;
85
+ var _f = useImporterContext(), initialRecords = _f.initialRecords, currentStepIndex = _f.currentStepIndex, templateHeaderMatchings = _f.templateHeaderMatchings, matcherSubstep = _f.matcherSubstep, templateHeaders = _f.templateHeaders, uploadedDataEnumFieldValues = _f.uploadedDataEnumFieldValues, setEnumFieldValueMatchings = _f.setEnumFieldValueMatchings, setMatcherSubstep = _f.setMatcherSubstep, setCurrentStepIndex = _f.setCurrentStepIndex, onClose = _f.onClose, isUsingManualImport = _f.isUsingManualImport, resetImporterWhenUsingManualImport = _f.resetImporterWhenUsingManualImport, uploadedData = _f.uploadedData, setHeadersMappings = _f.setHeadersMappings, uploadedDataHeaders = _f.uploadedDataHeaders, fuseApi = _f.fuseApi, templateSlug = _f.templateSlug;
86
+ useEffect(function () {
87
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
88
+ var mappings;
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0:
92
+ if (!uploadedDataHeaders) return [3 /*break*/, 2];
93
+ setIsLoadingApp(true);
94
+ return [4 /*yield*/, fuseApi.post("/api/v1/importer/templates/".concat(templateSlug, "/mappings"), {
95
+ file_headers: uploadedDataHeaders,
96
+ })];
97
+ case 1:
98
+ mappings = (_a.sent()).data.mappings;
99
+ setIsLoadingApp(false);
100
+ setHeadersMappings(mappings);
101
+ _a.label = 2;
102
+ case 2: return [2 /*return*/];
103
+ }
104
+ });
105
+ }); })();
106
+ }, [uploadedDataHeaders]);
48
107
  var templateHeaderLabels = Object.keys(templateHeaderMatchings || []);
49
108
  var unmatchedHeadersCount = templateHeaderLabels.filter(function (templateHeaderLabel) { return !templateHeaderMatchings[templateHeaderLabel]; }).length;
50
109
  var isLastSubMatchStep = matcherSubstep === 1;
@@ -87,29 +87,34 @@ export var useSpreadsheetField = function (name, record, fieldType) {
87
87
  validationWarning: validationWarning,
88
88
  };
89
89
  };
90
- var ContentContainer = styled(Div)(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n height: calc(100% - 1px);\n width: ", ";\n overflow: hidden;\n\n ", "\n\n &:focus-within, \n &:hover {\n ", "\n }\n\n ", ";\n ", "\n ", "\n ", "\n ", "\n"], ["\n height: calc(100% - 1px);\n width: ", ";\n overflow: hidden;\n\n ", "\n\n &:focus-within, \n &:hover {\n ", "\n }\n\n ", ";\n ", "\n ", "\n ", "\n ", "\n"])), function (_a) {
90
+ var ContentContainer = styled(Div)(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n height: calc(100% - 1px);\n width: ", ";\n overflow: hidden;\n\n ", "\n\n &:focus-within, \n &:hover {\n ", "\n }\n\n &:focus-within, \n &:hover {\n ", "\n }\n\n ", ";\n ", "\n ", "\n ", "\n ", "\n"], ["\n height: calc(100% - 1px);\n width: ", ";\n overflow: hidden;\n\n ", "\n\n &:focus-within, \n &:hover {\n ", "\n }\n\n &:focus-within, \n &:hover {\n ", "\n }\n\n ", ";\n ", "\n ", "\n ", "\n ", "\n"])), function (_a) {
91
91
  var defaultFieldWidth = _a.defaultFieldWidth;
92
92
  return defaultFieldWidth ? "".concat(defaultFieldWidth, "px") : "100%";
93
93
  }, function (_a) {
94
94
  var expandedFieldWidth = _a.expandedFieldWidth;
95
95
  return expandedFieldWidth && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: absolute;\n "], ["\n position: absolute;\n "])));
96
96
  }, function (_a) {
97
- var expandedFieldWidth = _a.expandedFieldWidth, isHighlighted = _a.isHighlighted, theme = _a.theme, shouldExpandInput = _a.shouldExpandInput;
98
- return shouldExpandInput && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background: ", ";\n box-shadow: 0px 0px 0px 2px ", " inset;\n width: ", ";\n z-index: 1;\n\n .suffix {\n right: 12px;\n }\n "], ["\n background: ", ";\n box-shadow: 0px 0px 0px 2px ", " inset;\n width: ", ";\n z-index: 1;\n\n .suffix {\n right: 12px;\n }\n "])), !isHighlighted
97
+ var hasError = _a.hasError, hasWarning = _a.hasWarning, isHighlighted = _a.isHighlighted, theme = _a.theme, shouldExpandInput = _a.shouldExpandInput;
98
+ return shouldExpandInput &&
99
+ !hasError &&
100
+ !hasWarning && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n background: ", ";\n box-shadow: 0px 0px 0px 2px ", " inset;\n "], ["\n background: ", ";\n box-shadow: 0px 0px 0px 2px ", " inset;\n "])), !isHighlighted
99
101
  ? theme.colors.white
100
- : theme.colors.blue100, function (p) { return p.theme.colors.blue500; }, expandedFieldWidth || "auto");
102
+ : theme.colors.blue100, function (p) { return p.theme.colors.blue500; });
103
+ }, function (_a) {
104
+ var expandedFieldWidth = _a.expandedFieldWidth, shouldExpandInput = _a.shouldExpandInput;
105
+ return shouldExpandInput && css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: ", ";\n z-index: 1;\n\n .suffix {\n right: 12px;\n }\n "], ["\n width: ", ";\n z-index: 1;\n\n .suffix {\n right: 12px;\n }\n "])), expandedFieldWidth || "auto");
101
106
  }, function (p) { return p.theme.css.alignCenter; }, function (p) {
102
- return p.isHighlighted && css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 2px ", " inset;\n "], ["\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 2px ", " inset;\n "])), function (p) { return p.theme.colors.blue100; }, function (p) { return p.theme.colors.blue500; });
107
+ return p.isHighlighted && css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 2px ", " inset;\n "], ["\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 2px ", " inset;\n "])), function (p) { return p.theme.colors.blue100; }, function (p) { return p.theme.colors.blue500; });
103
108
  }, function (p) {
104
- return p.hasWarning && css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n color: ", ";\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 1px ", " inset;\n "], ["\n color: ", ";\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 1px ", " inset;\n "])), function (p) { return p.theme.colors.orange1200; }, function (p) { return p.theme.colors.orange1100; }, function (p) { return p.theme.colors.orange500; });
109
+ return p.hasWarning && css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n color: ", ";\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 1px ", " inset;\n "], ["\n color: ", ";\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 1px ", " inset;\n "])), function (p) { return p.theme.colors.orange1200; }, function (p) { return p.theme.colors.orange1100; }, function (p) { return p.theme.colors.orange500; });
105
110
  }, function (p) {
106
- return p.hasError && css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n color: ", ";\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 1px ", " inset;\n "], ["\n color: ", ";\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 1px ", " inset;\n "])), function (p) { return p.theme.colors.error; }, function (p) { return p.theme.colors.red100; }, function (p) { return p.theme.colors.error; });
111
+ return p.hasError && css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n color: ", ";\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 1px ", " inset;\n "], ["\n color: ", ";\n background: ", ";\n /* internal border */\n box-shadow: 0px 0px 0px 1px ", " inset;\n "])), function (p) { return p.theme.colors.error; }, function (p) { return p.theme.colors.red100; }, function (p) { return p.theme.colors.error; });
107
112
  }, function (p) {
108
- return p.isReadOnly && css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n pointer-events: none;\n "], ["\n pointer-events: none;\n "])));
113
+ return p.isReadOnly && css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n pointer-events: none;\n "], ["\n pointer-events: none;\n "])));
109
114
  });
110
115
  export var SpreadsheetField = function (_a) {
111
116
  var validationError = _a.validationError, validationWarning = _a.validationWarning, children = _a.children, isHighlighted = _a.isHighlighted, expandedFieldWidth = _a.expandedFieldWidth, shouldExpandInput = _a.shouldExpandInput, defaultFieldWidth = _a.defaultFieldWidth;
112
117
  var isReadOnly = useSpreadsheetContext().isReadOnly;
113
118
  return (_jsx(Div, __assign({ dim: "100%" }, { children: _jsx(TooltipProvider, __assign({ tooltip: validationError || validationWarning }, { children: _jsx(Div, __assign({ dim: "100%" }, { children: _jsx(ContentContainer, __assign({ hasError: !!validationError, hasWarning: !!validationWarning, isHighlighted: isHighlighted, expandedFieldWidth: expandedFieldWidth, defaultFieldWidth: defaultFieldWidth, shouldExpandInput: shouldExpandInput, isReadOnly: isReadOnly, className: "input-content" }, { children: children })) })) })) })));
114
119
  };
115
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
120
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
@@ -1,8 +1,6 @@
1
- import Fuse from "fuse.js";
2
1
  import React from "react";
3
- import { CustomAction, FormatRecord, ImporterOptions, Integration, OnSubmit, OnValidateRecord, Record, TemplateHeader } from "../../types";
2
+ import { ColumnMapping, CustomAction, FormatRecord, ImporterOptions, Integration, OnSubmit, OnValidateRecord, Record, TemplateHeader } from "../../types";
4
3
  import { FuseApi } from "../common/FuseApi";
5
- export declare const fusejsOptions: Fuse.IFuseOptions<string>;
6
4
  export type HeaderMatchings = {
7
5
  [templateHeaderLabel: string]: string;
8
6
  };
@@ -46,6 +44,7 @@ export type State = {
46
44
  setCurrentStepIndex: React.Dispatch<number>;
47
45
  setEnumFieldValueMatchings: React.Dispatch<React.SetStateAction<EnumFieldValueMatchings>>;
48
46
  setUploadedData: React.Dispatch<any[]>;
47
+ setHeadersMappings: React.Dispatch<any[]>;
49
48
  setTemplateHeaderMatchings: React.Dispatch<React.SetStateAction<HeaderMatchings>>;
50
49
  setPreviewFirstTime: React.Dispatch<boolean>;
51
50
  formatRecord: FormatRecord;
@@ -56,6 +55,7 @@ export type State = {
56
55
  isUsingManualImport: React.MutableRefObject<boolean>;
57
56
  resetImporterWhenUsingManualImport: () => void;
58
57
  manualDataImportSelected: () => void;
58
+ columnMappingsAttributes: ColumnMapping[];
59
59
  customActions: CustomAction[];
60
60
  };
61
61
  export type Props = {
@@ -55,16 +55,11 @@ 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 Fuse from "fuse.js";
59
58
  import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
60
59
  import { FieldTypes, } from "../../types";
61
60
  import { FuseApi } from "../common/FuseApi";
62
61
  import { getCustomTheme, theme } from "../common/theme";
63
62
  import { getColumnType, verifyDuplicateValue } from "../common/utils";
64
- export var fusejsOptions = {
65
- includeScore: true,
66
- threshold: 0.35,
67
- };
68
63
  var ImporterContext = createContext({});
69
64
  export var ImporterContextProvider = function (_a) {
70
65
  var templateSlug = _a.templateSlug, initialRecords = _a.initialRecords, apiToken = _a.apiToken, children = _a.children, options = _a.options, onSubmit = _a.onSubmit, onClose = _a.onClose, formatRecord = _a.formatRecord, onValidateRecord = _a.onValidateRecord, dynamicColumns = _a.dynamicColumns, customActions = _a.customActions;
@@ -76,16 +71,18 @@ export var ImporterContextProvider = function (_a) {
76
71
  var _g = useState(null), uploadedData = _g[0], setUploadedData = _g[1];
77
72
  var _h = useState(null), organization = _h[0], setOrganization = _h[1];
78
73
  var _j = useState(null), previewFirstTime = _j[0], setPreviewFirstTime = _j[1];
79
- var _k = useState({
74
+ var _k = useState(null), columnMappingsAttributes = _k[0], setColumnMappingsAttributes = _k[1];
75
+ var _l = useState(null), headersMappings = _l[0], setHeadersMappings = _l[1];
76
+ var _m = useState({
80
77
  theme: theme,
81
78
  logoURL: null,
82
- }), style = _k[0], setStyle = _k[1];
83
- var _l = useState(null), templateHeaderMatchings = _l[0], setTemplateHeaderMatchings = _l[1];
84
- var _m = useState(null), enumFieldValueMatchings = _m[0], setEnumFieldValueMatchings = _m[1];
85
- var _o = useState(null), uploadedDataEnumFieldValues = _o[0], setUploadedDataEnumFieldValues = _o[1];
86
- var _p = useState([]), selectedRows = _p[0], setSelectedRows = _p[1];
79
+ }), style = _m[0], setStyle = _m[1];
80
+ var _o = useState(null), templateHeaderMatchings = _o[0], setTemplateHeaderMatchings = _o[1];
81
+ var _p = useState(null), enumFieldValueMatchings = _p[0], setEnumFieldValueMatchings = _p[1];
82
+ var _q = useState(null), uploadedDataEnumFieldValues = _q[0], setUploadedDataEnumFieldValues = _q[1];
83
+ var _r = useState([]), selectedRows = _r[0], setSelectedRows = _r[1];
87
84
  var isUsingManualImport = useRef(false);
88
- var _q = useState(0), headerRowIndex = _q[0], setHeaderRowIndex = _q[1];
85
+ var _s = useState(0), headerRowIndex = _s[0], setHeaderRowIndex = _s[1];
89
86
  var fuseApi = useMemo(function () { return new FuseApi(options.env, apiToken); }, [
90
87
  options.env,
91
88
  apiToken,
@@ -107,18 +104,29 @@ export var ImporterContextProvider = function (_a) {
107
104
  useEffect(function () {
108
105
  var setHeadersFromDataset = function () {
109
106
  var _templateHeaderMatchings = {};
110
- var fuse = new Fuse(uploadedDataHeaders, fusejsOptions);
111
107
  templateHeaders.forEach(function (templateHeader, _index) {
112
- var _a;
113
- var fuseResults = fuse.search(templateHeader.label);
114
- _templateHeaderMatchings[templateHeader.label] = (_a = fuseResults[0]) === null || _a === void 0 ? void 0 : _a.item;
108
+ var mappedHeader = headersMappings.find(function (headerMapping) {
109
+ var matchedColumn = Object.values(headerMapping)[0];
110
+ if (matchedColumn) {
111
+ return (matchedColumn.toLowerCase() === templateHeader.label.toLowerCase());
112
+ }
113
+ else {
114
+ return false;
115
+ }
116
+ });
117
+ if (mappedHeader) {
118
+ _templateHeaderMatchings[templateHeader.label] = Object.keys(mappedHeader)[0];
119
+ }
120
+ else {
121
+ _templateHeaderMatchings[templateHeader.label] = null;
122
+ }
115
123
  });
116
124
  setTemplateHeaderMatchings(_templateHeaderMatchings);
117
125
  };
118
- if (uploadedDataHeaders) {
126
+ if (uploadedDataHeaders && headersMappings) {
119
127
  setHeadersFromDataset();
120
128
  }
121
- }, [uploadedDataHeaders]);
129
+ }, [uploadedDataHeaders, headersMappings]);
122
130
  useEffect(function () {
123
131
  if (!templateHeaderMatchings || !uploadedDataHeaders)
124
132
  return;
@@ -145,7 +153,7 @@ export var ImporterContextProvider = function (_a) {
145
153
  }, [templateHeaderMatchings, uploadedDataHeaders]);
146
154
  useEffect(function () {
147
155
  (function () { return __awaiter(void 0, void 0, void 0, function () {
148
- var _a, organization_1, columns_1, importer_style_preferences, integrations_1, preview_first_time, error_1, errorMsg;
156
+ var _a, organization_1, columns_1, importer_style_preferences, integrations_1, preview_first_time, column_mappings_attributes, error_1, errorMsg;
149
157
  var _b, _c;
150
158
  return __generator(this, function (_d) {
151
159
  switch (_d.label) {
@@ -153,7 +161,7 @@ export var ImporterContextProvider = function (_a) {
153
161
  _d.trys.push([0, 2, , 3]);
154
162
  return [4 /*yield*/, fuseApi.get("/api/v1/importer/templates/".concat(templateSlug))];
155
163
  case 1:
156
- _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;
164
+ _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, column_mappings_attributes = _a.column_mappings_attributes;
157
165
  setOrganization(organization_1);
158
166
  setTemplateHeaders(function () {
159
167
  // user has created dynamic columns
@@ -170,6 +178,7 @@ export var ImporterContextProvider = function (_a) {
170
178
  });
171
179
  setIntegrations(integrations_1);
172
180
  setPreviewFirstTime(preview_first_time);
181
+ setColumnMappingsAttributes(column_mappings_attributes);
173
182
  if (organization_1.plan && organization_1.plan.allow_style_customization) {
174
183
  setStyle(getCustomTheme(importer_style_preferences));
175
184
  }
@@ -222,10 +231,12 @@ export var ImporterContextProvider = function (_a) {
222
231
  theme: style.theme,
223
232
  logoURL: style.logoURL,
224
233
  integrations: integrations,
234
+ columnMappingsAttributes: columnMappingsAttributes,
225
235
  previewFirstTime: previewFirstTime,
226
236
  headerRowIndex: headerRowIndex,
227
237
  setHeaderRowIndex: setHeaderRowIndex,
228
238
  setUploadedData: setUploadedData,
239
+ setHeadersMappings: setHeadersMappings,
229
240
  formatRecord: formatRecord,
230
241
  setCurrentStepIndex: setCurrentStepIndex,
231
242
  setEnumFieldValueMatchings: setEnumFieldValueMatchings,
@@ -43,14 +43,6 @@ export var datePatterns = [
43
43
  value: "yy/MM/dd",
44
44
  label: "yy/MM/dd (e.g. 23/08/31)",
45
45
  },
46
- {
47
- value: "EEEE MMMM yyyy",
48
- label: "Day MMMM Year (e.g. Tuesday August 2023)",
49
- },
50
- {
51
- value: "EEEE dd MMMM yyyy",
52
- label: "Day Day-of-Month Month Year (e.g. Tuesday 08 August 2023)",
53
- },
54
46
  {
55
47
  value: "MM-dd-yy",
56
48
  label: "MM-dd-yy (e.g. 01-15-90)",
@@ -61,7 +53,7 @@ export var datePatterns = [
61
53
  },
62
54
  {
63
55
  value: "dd-MM-yy",
64
- label: "dd-MM-yy (e.g. 15-01-90)",
56
+ label: "dd-MM-yy (e.g. 15-01-90)",
65
57
  },
66
58
  {
67
59
  value: "dd-MM-yyyy",
@@ -167,6 +159,14 @@ export var datePatterns = [
167
159
  value: "EEE, MMM dd, yyyy",
168
160
  label: "EEE, MMM dd, yyyy (e.g. Mon, Jan 15, 1990)",
169
161
  },
162
+ {
163
+ value: "EEEE MMMM yyyy",
164
+ label: "Day MMMM Year (e.g. Tuesday August 2023)",
165
+ },
166
+ {
167
+ value: "EEEE dd MMMM yyyy",
168
+ label: "Day Day-of-Month Month Year (e.g. Tuesday 08 August 2023)",
169
+ },
170
170
  ];
171
171
  export var dateTimePatterns = [
172
172
  {
@@ -317,7 +317,7 @@ export var timePatterns = [
317
317
  },
318
318
  {
319
319
  value: "hh:mm:ss a",
320
- label: "hh:mm:ss a (e.g. 01:30:45 PM)",
320
+ label: "hh:mm:ss a (e.g. 01:30:45 PM)",
321
321
  },
322
322
  ];
323
323
  export var allowedPatterns = {
@@ -114,6 +114,8 @@ export type TemplateHeader = {
114
114
  validations: FieldValidation[];
115
115
  transformations: FieldTransformation[];
116
116
  position: number;
117
+ id?: number;
118
+ archived?: boolean;
117
119
  };
118
120
  type CARecordFn = (record: Record) => Promise<Record> | Record;
119
121
  export type CustomActionTypes = "record";
@@ -140,6 +142,11 @@ export type Integration = {
140
142
  active: boolean;
141
143
  provider: string;
142
144
  };
145
+ export type ColumnMapping = {
146
+ matched_column_name: string;
147
+ template_column_name: string;
148
+ id?: number;
149
+ };
143
150
  export type TemplateInfo = {
144
151
  columns: TemplateHeader[];
145
152
  integrations: Integration[];
@@ -147,6 +154,7 @@ export type TemplateInfo = {
147
154
  organization: Organization;
148
155
  name: string;
149
156
  preview_first_time: boolean;
157
+ column_mappings_attributes?: ColumnMapping[];
150
158
  };
151
159
  export type Field = {
152
160
  name: string;