fuse-importer 0.0.4-testing → 0.0.5-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.
@@ -67,7 +67,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
67
67
  };
68
68
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
69
69
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
70
- import { utils, writeFile } from "xlsx";
70
+ 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";
@@ -108,6 +108,15 @@ var filterAndMapWithBackendErrors = function (dataSet, errors) {
108
108
  return __assign(__assign({}, record), { _meta: __assign(__assign({}, meta), { isInvalid: true, backendErrors: errors[rId] }) });
109
109
  }, []);
110
110
  };
111
+ function downloadCsv(data, fileName) {
112
+ var blob = new Blob([data], { type: "text/csv;charset=utf-8;" });
113
+ var link = document.createElement("a");
114
+ link.href = URL.createObjectURL(blob);
115
+ link.download = fileName;
116
+ document.body.appendChild(link);
117
+ link.click();
118
+ document.body.removeChild(link);
119
+ }
111
120
  function csvExport(data) {
112
121
  var valuesWithQuotesWhenNecessary = data.map(function (obj) {
113
122
  var newObj = {};
@@ -118,11 +127,8 @@ function csvExport(data) {
118
127
  }
119
128
  return newObj;
120
129
  });
121
- var worksheet = utils.json_to_sheet(valuesWithQuotesWhenNecessary);
122
- var workbook = utils.book_new();
123
- utils.book_append_sheet(workbook, worksheet, "Data");
124
- utils.sheet_to_csv(worksheet);
125
- writeFile(workbook, "export.csv");
130
+ var csv = Papa.unparse(valuesWithQuotesWhenNecessary);
131
+ downloadCsv(csv, "export.csv");
126
132
  }
127
133
  export var ReviewContextProvider = function (_a) {
128
134
  var initialRecords = _a.initialRecords, children = _a.children;
@@ -25,6 +25,7 @@ import { Button } from "../../../common/buttons";
25
25
  import { DragAndDropSvg, UploadIndicatorSvg } from "./backgrounds";
26
26
  import { useTranslation } from "react-i18next";
27
27
  import Papa from "papaparse";
28
+ import * as XLSX from "xlsx";
28
29
  var DragAndDropCard = styled(Div)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n border-radius: 8px;\n margin-right: ", ";\n width: 100%;\n height: 100%;\n display: flex;\n background: ", ";\n border: 1px dashed ", ";\n\n @media (max-width: 1050px) {\n padding: 24px;\n width: auto;\n }\n\n ", "\n"], ["\n border-radius: 8px;\n margin-right: ", ";\n width: 100%;\n height: 100%;\n display: flex;\n background: ", ";\n border: 1px dashed ", ";\n\n @media (max-width: 1050px) {\n padding: 24px;\n width: auto;\n }\n\n ", "\n"])), function (props) { return (props.isDragActive ? "-10px" : "revert"); }, theme.colors.white, theme.colors.red50, function (props) {
29
30
  return props.isDragActive && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background: ", ";\n border: 1px solid ", ";\n justify-content: center;\n "], ["\n background: ", ";\n border: 1px solid ", ";\n justify-content: center;\n "])), function (p) { return p.theme.colors.blue100; }, function (p) { return p.theme.colors.blue500; });
30
31
  });
@@ -62,12 +63,26 @@ var ImporterDropzone = function () {
62
63
  reader.onload = function (event) {
63
64
  var _a;
64
65
  var results = event.target.result;
66
+ var isCsvFile = file.type === "text/csv";
67
+ // rounded value to 20MB
68
+ var isLargeFile = file.size > 20000000;
65
69
  var getDataFromFile = function (fileResults) {
66
- var csvString = new TextDecoder().decode(fileResults instanceof ArrayBuffer
67
- ? fileResults
68
- : new TextEncoder().encode(fileResults));
69
- var data = Papa.parse(csvString).data;
70
- return data;
70
+ if (isCsvFile) {
71
+ var csvString = new TextDecoder().decode(fileResults instanceof ArrayBuffer
72
+ ? fileResults
73
+ : new TextEncoder().encode(fileResults));
74
+ var data = Papa.parse(csvString).data;
75
+ return data;
76
+ }
77
+ var workBook = XLSX.read(fileResults, {
78
+ type: "array",
79
+ codepage: 65001,
80
+ raw: true,
81
+ dense: isLargeFile,
82
+ });
83
+ var workBookName = workBook.SheetNames[0];
84
+ var sheet = workBook.Sheets[workBookName];
85
+ return XLSX.utils.sheet_to_json(sheet, { header: 1, raw: false });
71
86
  };
72
87
  var fileData = getDataFromFile(results);
73
88
  var headersCount = (_a = fileData[0]) === null || _a === void 0 ? void 0 : _a.length;
@@ -98,7 +113,7 @@ var ImporterDropzone = function () {
98
113
  onDropRejected: onDropRejected,
99
114
  noClick: true,
100
115
  noKeyboard: true,
101
- accept: ".csv, .tsv, .xls, .xlsx",
116
+ accept: ".csv, .xls, .xlsx",
102
117
  maxFiles: 1,
103
118
  maxSize: 200000000, // 200MB
104
119
  }), getRootProps = _b.getRootProps, getInputProps = _b.getInputProps, open = _b.open, isDragActive = _b.isDragActive;
@@ -102,11 +102,11 @@ function mergeErrorsAndWarnings(currentErrors, errors) {
102
102
  return __assign(__assign({}, currentErrors), { errors: __assign(__assign({}, (currentErrors.errors || {})), errors), warnings: __assign({}, (currentErrors.warnings || {})) });
103
103
  }
104
104
  function runValidatorsFor(_a) {
105
- var record = _a.record, data = _a.data, validators = _a.validators, isTouched = _a.isTouched;
105
+ var record = _a.record, data = _a.data, validators = _a.validators;
106
106
  return validators.reduce(function (currentErrors, _a) {
107
107
  var field = _a.field, validators = _a.validators;
108
108
  var errors = {};
109
- if (isTouched && !field.isRequired && isEmpty(record[field.name])) {
109
+ if (!field.isRequired && isEmpty(record[field.name])) {
110
110
  return mergeErrorsAndWarnings(currentErrors, errors);
111
111
  }
112
112
  for (var index = 0; index < validators.length; index++) {
@@ -181,7 +181,6 @@ export function validateRecord(_a) {
181
181
  record: record,
182
182
  data: data,
183
183
  validators: validators,
184
- isTouched: isTouched,
185
184
  }), validatorErrors = _d.errors, validatorWarnings = _d.warnings;
186
185
  errors = ignoreNullOrUndefinedKeyValues(validatorErrors);
187
186
  warnings = ignoreNullOrUndefinedKeyValues(validatorWarnings);
@@ -25,7 +25,7 @@ export default {
25
25
  optional_headers: "Optionale Überschriften",
26
26
  },
27
27
  title: "Laden Sie eine Datei hoch, um Ihre Daten zu importieren",
28
- description: "\n Laden Sie eine beliebige .csv, .tsv, .xls, .xlsx-Tabellenkalkulationsdatei mit einem beliebigen Satz von\n Spalten hoch, solange es einen Datensatz pro Zeile enth\u00E4lt.\n ",
28
+ description: "\n Laden Sie eine beliebige .csv, .xls, .xlsx-Tabellenkalkulationsdatei\n mit einem beliebigen Satz von Spalten hoch, solange es einen Datensatz pro Zeile enth\u00E4lt.\n ",
29
29
  loading: {
30
30
  title: "Hochladen...",
31
31
  },
@@ -25,7 +25,7 @@ export default {
25
25
  optional_headers: "Optional Headers",
26
26
  },
27
27
  title: "Upload a File to Import your Data",
28
- description: "\n Upload any .csv, .tsv, .xls, .xlsx spreadsheet file with any set of\n columns as long as it has one record per row.\n ",
28
+ description: "\n Upload any .csv, .xls, .xlsx file with any set of\n columns as long as it has one record per row.\n ",
29
29
  loading: {
30
30
  title: "Uploading...",
31
31
  },
@@ -25,7 +25,7 @@ export default {
25
25
  optional_headers: "Encabezados opcionales",
26
26
  },
27
27
  title: "Cargue un archivo para importar sus datos",
28
- description: "\n Cargue cualquier archivo de hoja de c\u00E1lculo .csv, .tsv, .xls, .xlsx con cualquier conjunto de\n columnas siempre y cuando tenga un registro por fila.\n ",
28
+ description: "\n Cargue cualquier archivo de hoja de c\u00E1lculo .csv, .xls, .xlsx con cualquier conjunto de\n columnas siempre y cuando tenga un registro por fila.\n ",
29
29
  loading: {
30
30
  title: "Cargando...",
31
31
  },
@@ -25,7 +25,7 @@ export default {
25
25
  optional_headers: "En-têtes facultatifs",
26
26
  },
27
27
  title: "Téléchargez un fichier pour importer vos données",
28
- description: "\n T\u00E9l\u00E9chargez tout fichier de tableur .csv, .tsv, .xls, .xlsx avec n'importe quel ensemble de\n colonnes tant qu'il a une seule ligne par ligne.\n ",
28
+ description: "\n T\u00E9l\u00E9chargez tout fichier de tableur .csv, .xls, .xlsx avec n'importe quel ensemble de\n colonnes tant qu'il a une seule ligne par ligne.\n ",
29
29
  loading: {
30
30
  title: "Téléchargement en cours...",
31
31
  },