fuse-importer 0.26.6 → 0.26.7

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.
@@ -17,8 +17,9 @@ type State = {
17
17
  onDataSetChanged: OnDataSetChanged;
18
18
  onValidationStateChanged: OnValidationStateChanged;
19
19
  onSubmit: () => void;
20
- onExport: () => void;
20
+ onExport: (dataType: ExportDataType) => void;
21
21
  };
22
+ type ExportDataType = "csv" | "excel";
22
23
  type Props = {
23
24
  children: JSX.Element;
24
25
  };
@@ -45,6 +45,17 @@ 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 __rest = (this && this.__rest) || function (s, e) {
49
+ var t = {};
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
+ t[p] = s[p];
52
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
+ t[p[i]] = s[p[i]];
56
+ }
57
+ return t;
58
+ };
48
59
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
60
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
61
  if (ar || !(i in from)) {
@@ -56,6 +67,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
56
67
  };
57
68
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
58
69
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
70
+ import { utils, writeFile } from "xlsx";
59
71
  import { AppLoading } from "../common/AppLoading";
60
72
  import { isRecordEmpty } from "../common/Spreadsheet/common";
61
73
  import { sendRecordsToIntegrations } from "../common/utils";
@@ -94,18 +106,21 @@ var filterAndMapWithBackendErrors = function (dataSet, errors) {
94
106
  return __assign(__assign({}, record), { _meta: __assign(__assign({}, meta), { isInvalid: true, backendErrors: errors[rId] }) });
95
107
  }, []);
96
108
  };
97
- function convertToCSV(data) {
98
- var headers = Object.keys(data[0]).filter(function (header) { return header !== "_meta"; });
99
- var csvRows = [];
100
- csvRows.push(headers.join(","));
101
- data.forEach(function (item) {
102
- var row = [];
103
- headers.forEach(function (header) {
104
- row.push(item[header]);
105
- });
106
- csvRows.push(row.join(","));
109
+ function csvExport(data) {
110
+ var valuesWithQuotesWhenNecessary = data.map(function (obj) {
111
+ var newObj = {};
112
+ for (var key in obj) {
113
+ var value = obj[key];
114
+ newObj[key] =
115
+ typeof value === "string" && value.includes(",") ? "\"".concat(value, "\"") : value;
116
+ }
117
+ return newObj;
107
118
  });
108
- return csvRows.join("\n");
119
+ var worksheet = utils.json_to_sheet(valuesWithQuotesWhenNecessary);
120
+ var workbook = utils.book_new();
121
+ utils.book_append_sheet(workbook, worksheet, "Data");
122
+ utils.sheet_to_csv(worksheet);
123
+ writeFile(workbook, "export.csv");
109
124
  }
110
125
  export var ReviewContextProvider = function (_a) {
111
126
  var children = _a.children;
@@ -127,18 +142,18 @@ export var ReviewContextProvider = function (_a) {
127
142
  batchValidationDelayMs: batchValidationDelayMs,
128
143
  batchValidationSize: batchValidationSize,
129
144
  }); }, [batchValidationDelayMs, batchValidationSize]);
130
- var onExport = useCallback(function () {
145
+ var onExport = useCallback(function (dataType) {
131
146
  if (!reviewDataSetRef.current)
132
147
  return;
133
148
  var dataSet = reviewDataSetRef.current;
134
149
  var dataSetValues = Object.values(dataSet);
135
- var csv = convertToCSV(dataSetValues);
136
- var blob = new Blob([csv], { type: "text/csv" });
137
- var url = URL.createObjectURL(blob);
138
- var link = document.createElement("a");
139
- link.setAttribute("href", url);
140
- link.setAttribute("download", "export.csv");
141
- link.click();
150
+ if (dataType === "csv") {
151
+ var valuesWithoutMeta = dataSetValues.map(function (_a) {
152
+ var _meta = _a._meta, rest = __rest(_a, ["_meta"]);
153
+ return rest;
154
+ });
155
+ csvExport(valuesWithoutMeta);
156
+ }
142
157
  }, [reviewFields, selectedRows]);
143
158
  var onSubmitData = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
144
159
  var dataSet, dataSetValues, validDataSetValues, validDataSetLength, invalidRecords_1, applicationResponse, isAppResponseSuccessful, _a, errors, isDataValid, recordsToDisplayFiltered, invalidDataSet, error_2;
@@ -19,5 +19,5 @@ export var ExportData = function (_a) {
19
19
  var _b = _a.testId, testId = _b === void 0 ? "ta-export-data" : _b;
20
20
  var onExport = useReviewContext().onExport;
21
21
  var t = useTranslation("review").t;
22
- return (_jsx(TooltipProvider, __assign({ tooltip: t("table_actions.export_your_data.tooltip"), placement: "right", flip: false, centered: true, "data-testid": testId }, { children: _jsx(ActionButton, __assign({ onClick: onExport }, { children: _jsx(DownloadIcon, {}) })) })));
22
+ return (_jsx(TooltipProvider, __assign({ tooltip: t("table_actions.export_your_data.tooltip"), placement: "right", flip: false, centered: true, "data-testid": testId }, { children: _jsx(ActionButton, __assign({ onClick: function () { return onExport("csv"); } }, { children: _jsx(DownloadIcon, {}) })) })));
23
23
  };
@@ -4,11 +4,13 @@ import { useSpreadsheetContext } from "../../../../Importer";
4
4
  import { formatErrors, getUniqueErrors } from "./functions";
5
5
  import { useTranslation } from "react-i18next";
6
6
  import { addToast } from "../../../../common/Toast";
7
+ import { useState } from "react";
7
8
  export var FilterByErrors = function () {
8
9
  var _a;
9
10
  var _b = useSpreadsheetContext(), errors = _b.errors, fields = _b.fields, selectedErrorToFilter = _b.selectedErrorToFilter, setSelectedErrorToFilter = _b.setSelectedErrorToFilter;
10
11
  var t = useTranslation("review").t;
11
- var prefix = "".concat(t("table_actions.filter_by_errors.filter_by_errors"), ": ");
12
+ var _c = useState(false), isMenuOpened = _c[0], setIsMenuOpened = _c[1];
13
+ var prefix = t("table_actions.filter_by_errors.filter_by_errors");
12
14
  var search_or_select = t("table_actions.filter_by_errors.search_or_select");
13
15
  var getSelectedErrorLabel = function (selectedFieldName) {
14
16
  var _a;
@@ -26,11 +28,15 @@ export var FilterByErrors = function () {
26
28
  var uniqueErrors = getUniqueErrors(fields, errors);
27
29
  var errorArray = formatErrors(fields, uniqueErrors);
28
30
  // the average size of each character in the input (in px)
29
- var widthPerCharacter = 5.3;
30
- var amountOfCharacters = prefix.length + ((_a = getSelectedErrorLabel(selectedErrorToFilter)) === null || _a === void 0 ? void 0 : _a.length) || 0;
31
+ var widthPerCharacter = 5.8;
32
+ var amountOfCharacters = prefix.length + ((_a = getSelectedErrorLabel(selectedErrorToFilter)) === null || _a === void 0 ? void 0 : _a.length);
31
33
  // 24 -> padding + 64px of the X icon area
32
34
  var totalWidth = widthPerCharacter * amountOfCharacters + 24 + 64;
33
35
  var inputWidth = selectedErrorToFilter ? "".concat(totalWidth, "px") : "fit-content";
34
- var inputText = selectedErrorToFilter ? prefix : search_or_select;
35
- return (_jsx(S.StyledAutocomplete, { placement: "bottom", placeholder: inputText, onChange: onChange, value: selectedErrorToFilter, options: errorArray, isDisabled: errorArray.length === 0, isInputDisabled: errorArray.length === 0, inputWidth: inputWidth, "data-testid": "ta-filter-by-errors", prefix: inputText }));
36
+ var inputText = selectedErrorToFilter
37
+ ? "".concat(prefix, ": ")
38
+ : isMenuOpened
39
+ ? search_or_select
40
+ : prefix;
41
+ return (_jsx(S.StyledAutocomplete, { placement: "bottom", placeholder: inputText, onToggle: function (v) { return setIsMenuOpened(v); }, onChange: onChange, value: selectedErrorToFilter, options: errorArray, isDisabled: errorArray.length === 0, isInputDisabled: errorArray.length === 0, inputWidth: inputWidth, "data-testid": "ta-filter-by-errors", prefix: inputText }));
36
42
  };