fuse-importer 0.26.3 → 0.26.5

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.
@@ -9,15 +9,117 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
12
23
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import React from "react";
24
+ import { get } from "lodash";
25
+ import { DateTime } from "luxon";
26
+ import React, { useEffect, useState } from "react";
14
27
  import { areEqual } from "react-window";
28
+ import { useImporterContext } from "../../contexts/ImporterContextProvider";
29
+ import { SpreadsheetContextProvider } from "./SpreadsheetContextProvider";
15
30
  import SpreadsheetData from "./components/SpreadsheetData";
16
- import { SpreadsheetContextProvider, } from "./SpreadsheetContextProvider";
17
- var Spreadsheet = function (_a) {
18
- var isReadOnly = _a.isReadOnly, initialDataSet = _a.initialDataSet, fields = _a.fields, _b = _a.options, options = _b === void 0 ? {} : _b, _c = _a.highlightFirstRow, highlightFirstRow = _c === void 0 ? false : _c, _d = _a.onValidateRecord, onValidateRecord = _d === void 0 ? null : _d, onDataSetChanged = _a.onDataSetChanged, onValidationStateChanged = _a.onValidationStateChanged, selectedRows = _a.selectedRows, setSelectedRows = _a.setSelectedRows;
19
- return (_jsx(SpreadsheetContextProvider, __assign({ isReadOnly: isReadOnly, fields: fields, initialDataSet: initialDataSet, highlightFirstRow: highlightFirstRow, options: options, onDataSetChanged: onDataSetChanged, onValidateRecord: onValidateRecord, onValidationStateChanged: onValidationStateChanged, selectedRows: selectedRows, setSelectedRows: setSelectedRows }, { children: _jsx(SpreadsheetData, {}) })));
31
+ var useFieldSorting = function () {
32
+ var templateHeaders = useImporterContext().templateHeaders;
33
+ var getDefaultSortCompareFn = function (sortBy) {
34
+ return function (a, b) {
35
+ var aField = get(a, sortBy.field);
36
+ var bField = get(b, sortBy.field);
37
+ var fieldTypes = templateHeaders.reduce(function (acc, header) {
38
+ var type = header.column_type;
39
+ var pattern = header.pattern || null;
40
+ acc[header.internal_key] = { type: type, pattern: pattern };
41
+ return acc;
42
+ }, {});
43
+ var fieldType = fieldTypes[sortBy.field];
44
+ var isAEmpty = aField === undefined || aField === null || aField === "";
45
+ var isBEmpty = bField === undefined || bField === null || bField === "";
46
+ // sort empty values to the end
47
+ if (isAEmpty && isBEmpty) {
48
+ if (a._meta.rowIndex === b._meta.rowIndex)
49
+ return 0;
50
+ return a._meta.rowIndex < b._meta.rowIndex ? -1 : 1;
51
+ }
52
+ if (isAEmpty)
53
+ return 1;
54
+ if (isBEmpty)
55
+ return -1;
56
+ if (fieldType && fieldType.type === "boolean") {
57
+ var aString = aField ? "true" : "false";
58
+ var bString = bField ? "true" : "false";
59
+ if (aString === bString) {
60
+ if (a._meta.rowIndex === b._meta.rowIndex)
61
+ return 0;
62
+ return a._meta.rowIndex < b._meta.rowIndex ? -1 : 1;
63
+ }
64
+ if (aString === "true")
65
+ return sortBy.direction === "asc" ? -1 : 1;
66
+ if (bString === "true")
67
+ return sortBy.direction === "asc" ? 1 : -1;
68
+ }
69
+ else if (fieldType &&
70
+ (fieldType.type === "date" ||
71
+ fieldType.type === "datetime" ||
72
+ fieldType.type === "time")) {
73
+ var aDateTime = aField
74
+ ? DateTime.fromFormat(aField, fieldType.pattern)
75
+ : null;
76
+ var bDateTime = bField
77
+ ? DateTime.fromFormat(bField, fieldType.pattern)
78
+ : null;
79
+ // sort invalid date values to the end before empty values
80
+ if (aDateTime && !aDateTime.isValid)
81
+ return 1;
82
+ if (bDateTime && !bDateTime.isValid)
83
+ return -1;
84
+ if (aDateTime && bDateTime && aDateTime.equals(bDateTime)) {
85
+ if (a._meta.rowIndex === b._meta.rowIndex)
86
+ return 0;
87
+ return a._meta.rowIndex < b._meta.rowIndex ? -1 : 1;
88
+ }
89
+ if (sortBy.direction === "asc") {
90
+ return (aDateTime === null || aDateTime === void 0 ? void 0 : aDateTime.valueOf()) - (bDateTime === null || bDateTime === void 0 ? void 0 : bDateTime.valueOf());
91
+ }
92
+ return (bDateTime === null || bDateTime === void 0 ? void 0 : bDateTime.valueOf()) - (aDateTime === null || aDateTime === void 0 ? void 0 : aDateTime.valueOf());
93
+ }
94
+ else {
95
+ if (aField === bField) {
96
+ if (a._meta.rowIndex === b._meta.rowIndex)
97
+ return 0;
98
+ return a._meta.rowIndex < b._meta.rowIndex ? -1 : 1;
99
+ }
100
+ if (sortBy.direction === "asc") {
101
+ return aField > bField ? 1 : -1;
102
+ }
103
+ return aField < bField ? 1 : -1;
104
+ }
105
+ };
106
+ };
107
+ return { getDefaultSortCompareFn: getDefaultSortCompareFn };
20
108
  };
21
- export default React.memo(Spreadsheet, areEqual);
22
- export * from "./hooks";
109
+ var SpreadsheetWrapper = function (_a) {
110
+ var initialDataSet = _a.initialDataSet, props = __rest(_a, ["initialDataSet"]);
111
+ var _b = useState(0), key = _b[0], setKey = _b[1];
112
+ useEffect(function () {
113
+ /* increment the key to force a re-mount of the Spreadsheet component
114
+ when the initialDataSet changes */
115
+ setKey(key + 1);
116
+ }, [initialDataSet]);
117
+ return _jsx(Spreadsheet, __assign({ initialDataSet: initialDataSet }, props), key);
118
+ };
119
+ var Spreadsheet = function (props) {
120
+ var getDefaultSortCompareFn = useFieldSorting().getDefaultSortCompareFn;
121
+ return (_jsx(SpreadsheetContextProvider, __assign({}, props, { getSortCompareFn: getDefaultSortCompareFn }, { children: _jsx(SpreadsheetData, {}) })));
122
+ };
123
+ export default React.memo(SpreadsheetWrapper, areEqual);
23
124
  export * from "./SpreadsheetContextProvider";
125
+ export * from "./hooks";
@@ -4,17 +4,17 @@ interface UseTableActionsProps {
4
4
  setErrors: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
5
5
  setWarnings: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
6
6
  }
7
- export type DeleteRecords = (setDataSet: React.Dispatch<React.SetStateAction<RecordDataSet>>, selectedRecords: string[], errors: BatchValidationErrors, warnings: BatchValidationErrors, isDeletingAllRows: boolean) => void;
7
+ export type DeleteRecords = (selectedRecords: string[], errors: BatchValidationErrors, warnings: BatchValidationErrors) => void;
8
8
  export type FilterRecordsBySearchValue = (obj: RecordDataSet, value: string, fields: Field[]) => RecordDataSet;
9
9
  export type FilterRecordsByError = (obj: RecordDataSet, keyToFilter: string, errors: BatchValidationErrors, fields: Field[]) => RecordDataSet;
10
10
  interface UseTableActionsProps {
11
11
  setErrors: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
12
12
  setWarnings: React.Dispatch<React.SetStateAction<BatchValidationErrors>>;
13
- fields: Field[];
13
+ setDataSet: React.Dispatch<React.SetStateAction<RecordDataSet>>;
14
14
  }
15
- export declare const useTableActions: ({ setErrors, setWarnings, fields, }: UseTableActionsProps) => {
16
- deleteRecords: DeleteRecords;
17
- filterRecordsBySearchValue: (obj: RecordDataSet, value: string) => RecordDataSet;
15
+ export declare const useTableActions: ({ setDataSet, setErrors, setWarnings, }: UseTableActionsProps) => {
16
+ deleteRecords: (selectedRecords: string[], errors: BatchValidationErrors, warnings: BatchValidationErrors) => void;
17
+ filterRecordsBySearchValue: (obj: RecordDataSet, value: string) => {};
18
18
  filterRecordsByError: (obj: RecordDataSet, keyToFilter: string, errors: BatchValidationErrors, fields: Field[]) => {};
19
19
  };
20
20
  export {};
@@ -1,14 +1,3 @@
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];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
- import { useRef } from "react";
11
- import { addEmptyRows, recordListToDataSet } from "../../../Importer/data";
12
1
  var removeErrorsOrWarningsFromObject = function (obj, keysToRemove) {
13
2
  var keysSet = new Set(keysToRemove);
14
3
  var newObj = {};
@@ -19,6 +8,20 @@ var removeErrorsOrWarningsFromObject = function (obj, keysToRemove) {
19
8
  }
20
9
  return newObj;
21
10
  };
11
+ var removeItemsFromObject = function (obj, idsToRemove) {
12
+ var _a;
13
+ var idSet = new Set(idsToRemove);
14
+ var newObj = {};
15
+ for (var key in obj) {
16
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
17
+ var meta = (_a = obj[key]) === null || _a === void 0 ? void 0 : _a._meta;
18
+ 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))) {
19
+ newObj[key] = obj[key];
20
+ }
21
+ }
22
+ }
23
+ return newObj;
24
+ };
22
25
  var isObject = function (value) {
23
26
  return typeof value === "object" && value !== null && !Array.isArray(value);
24
27
  };
@@ -31,31 +34,17 @@ var includesSearchValue = function (value, searchValue) {
31
34
  return false;
32
35
  };
33
36
  export var useTableActions = function (_a) {
34
- var setErrors = _a.setErrors, setWarnings = _a.setWarnings, fields = _a.fields;
35
- var allRowsDeleted = useRef([]);
37
+ var setDataSet = _a.setDataSet, setErrors = _a.setErrors, setWarnings = _a.setWarnings;
36
38
  // 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
- });
39
+ var deleteRecords = function (selectedRecords, errors, warnings) {
40
+ var newErrors = removeErrorsOrWarningsFromObject(errors, selectedRecords);
41
+ var newWarnings = removeErrorsOrWarningsFromObject(warnings, selectedRecords);
57
42
  setErrors(newErrors);
58
43
  setWarnings(newWarnings);
44
+ setDataSet(function (prev) {
45
+ var newDataSet = removeItemsFromObject(prev, selectedRecords);
46
+ return newDataSet;
47
+ });
59
48
  };
60
49
  // Filter records by search value
61
50
  var filterRecordsBySearchValue = function (obj, value) {
@@ -72,11 +61,6 @@ export var useTableActions = function (_a) {
72
61
  filteredObj[key] = currentObj;
73
62
  }
74
63
  }
75
- // To ensure that rows are always displayed, even when the search query is empty,
76
- // we return an empty record list when the search yields no results.
77
- if (Object.keys(filteredObj).length === 0) {
78
- return recordListToDataSet(addEmptyRows([], fields), fields);
79
- }
80
64
  return filteredObj;
81
65
  };
82
66
  // Filter records by selected column error
@@ -38,15 +38,17 @@ import { defaultTableHeaderHeightPx, defaultTableRowHeightPx } from "./common";
38
38
  export * from "./TableHeaders";
39
39
  export * from "./TableRows/TableRow";
40
40
  export * from "./common";
41
- export var TableViewWrapper = styled(Div)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n ", "\n box-shadow: 0 0 0 1px ", ";\n overflow: hidden;\n\n ", "\n\n // prevents clipped dropdowns\n .ReactVirtualized__Grid__innerScrollContainer {\n overflow: visible !important;\n }\n .ReactVirtualized__Table__row {\n overflow: visible !important;\n }\n\n"], ["\n ", "\n box-shadow: 0 0 0 1px ", ";\n overflow: hidden;\n\n ", "\n\n // prevents clipped dropdowns\n .ReactVirtualized__Grid__innerScrollContainer {\n overflow: visible !important;\n }\n .ReactVirtualized__Table__row {\n overflow: visible !important;\n }\n\n"])), function (p) {
41
+ export var TableViewWrapper = styled(Div)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", "\n ", "\n overflow: hidden;\n\n ", "\n\n // prevents clipped dropdowns\n .ReactVirtualized__Grid__innerScrollContainer {\n overflow: visible !important;\n }\n .ReactVirtualized__Table__row {\n overflow: visible !important;\n }\n"], ["\n ", "\n ", "\n overflow: hidden;\n\n ", "\n\n // prevents clipped dropdowns\n .ReactVirtualized__Grid__innerScrollContainer {\n overflow: visible !important;\n }\n .ReactVirtualized__Table__row {\n overflow: visible !important;\n }\n"])), function (p) {
42
42
  return p.isLoading && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n opacity: 0.5;\n "], ["\n opacity: 0.5;\n "])));
43
- }, function (p) { return p.theme.colors.gray300; }, function (_a) {
43
+ }, function (p) {
44
+ return !p.isLoading && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n box-shadow: 0 0 0 1px ", ";\n "], ["\n box-shadow: 0 0 0 1px ", ";\n "])), function (p) { return p.theme.colors.gray300; });
45
+ }, function (_a) {
44
46
  var checkboxColumnWidth = _a.checkboxColumnWidth;
45
- return checkboxColumnWidth && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n max-width: calc(100vw - ", "px);\n "], ["\n max-width: calc(100vw - ", "px);\n "])), checkboxColumnWidth);
47
+ return checkboxColumnWidth && css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n max-width: calc(100vw - ", "px);\n "], ["\n max-width: calc(100vw - ", "px);\n "])), checkboxColumnWidth);
46
48
  });
47
- var SpinnerWrapper = styled(Div)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n pointer-events: none;\n z-index: 100;\n"], ["\n pointer-events: none;\n z-index: 100;\n"])));
49
+ var SpinnerWrapper = styled(Div)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n pointer-events: none;\n z-index: 100;\n"], ["\n pointer-events: none;\n z-index: 100;\n"])));
48
50
  var tableHeaderId = "tableHeaderId";
49
- var VirtualizedGrid = styled(Grid)(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n ", ";\n"], ["\n ", ";\n"])), function (p) { return p.theme.css.scrollbarDark; });
51
+ var VirtualizedGrid = styled(Grid)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n ", ";\n"], ["\n ", ";\n"])), function (p) { return p.theme.css.scrollbarDark; });
50
52
  var loadingUI = (_jsx(SpinnerWrapper, __assign({ pRelative: true }, { children: _jsx(Div, __assign({ w100: true, h100: true, centered: true, h: 400, pAbsolute: true }, { children: _jsx(Spinner, {}) })) })));
51
53
  var buildGridStyles = function (rowWidthScalingFactor) {
52
54
  /* using style={{ willChange: "unset" }} is important for having items
@@ -70,7 +72,8 @@ export var TableView = React.memo(function (_a) {
70
72
  var scrollTop = _a.scrollTop, scrollLeft = _a.scrollLeft;
71
73
  if (headerContainerRef.current && headerContainerRef.current.scrollTo) {
72
74
  requestAnimationFrame(function () {
73
- headerContainerRef.current.scrollTo({
75
+ var _a;
76
+ (_a = headerContainerRef === null || headerContainerRef === void 0 ? void 0 : headerContainerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
74
77
  left: scrollLeft,
75
78
  });
76
79
  });
@@ -127,4 +130,4 @@ export var TableView = React.memo(function (_a) {
127
130
  return (_jsxs(_Fragment, { children: [canRenderTableHeaders && (_jsx(TableHeaders, { rowWidth: rowWidth, containerWidth: autosizerWidth, id: tableHeaderId, containerRef: headerContainerRef, height: tableHeadersHeight, rowHeight: rowHeight, scrollLeft: 0, columns: columns, sortBy: sortBy, setSortBy: setSortBy })), _jsx(GridContainer, __assign({}, gridContainerProps, { children: _jsx(VirtualizedGrid, __assign({}, gridProps, { children: Row })) }))] }));
128
131
  } })] })));
129
132
  }, areEqual);
130
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
133
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
@@ -126,7 +126,7 @@ var Table = function (_a) {
126
126
  };
127
127
  var Container = data.length > 0 ? TableContainer : Div;
128
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 }, {
129
+ return (_jsx(Container, { children: _jsx(Wrapper, { children: _jsxs(Div, __assign({}, props, { children: [data.length || isLoading ? (_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
130
  isLoading: isLoading,
131
131
  data: data,
132
132
  columns: columns,
@@ -64,6 +64,7 @@ export type BatchValidationErrors = {
64
64
  [rowId: string]: ValidationErrors;
65
65
  };
66
66
  export type AppResponse = {
67
+ recordsToDisplay?: Record[];
67
68
  errors?: SpreadsheetValidationErrors;
68
69
  message?: string;
69
70
  };