mig-schema-table 3.0.112 → 3.0.114
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,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React from "react";
|
|
3
|
-
|
|
3
|
+
import { MINIMUM_COLUMN_WIDTH } from "../../inc/constant";
|
|
4
4
|
const ColumnResizers = ({ columnWidths, setColumnWidths, tableBodyHeight, }) => {
|
|
5
5
|
const [dragColumnIndex, setDragColumnIndex] = React.useState(-1);
|
|
6
6
|
const [dragStartX, setDragStartX] = React.useState(0);
|
|
@@ -17,14 +17,14 @@ import { localeFormat } from "../inc/date";
|
|
|
17
17
|
import { defaultTranslate } from "../inc/string";
|
|
18
18
|
import { SELECT_ALL_COLUMN_NAME, SELECT_ALL_COLUMN_WIDTH } from "./constants";
|
|
19
19
|
import Td from "./Td";
|
|
20
|
-
import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, ENumberColumnFilterOperation, } from "../inc/constant";
|
|
20
|
+
import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_TIME_FORMAT, ENumberColumnFilterOperation, MINIMUM_COLUMN_WIDTH, } from "../inc/constant";
|
|
21
21
|
import { parseLocationHash, serializeLocationHash } from "../inc/data";
|
|
22
22
|
import Th, { EColumnFilterStatus } from "./Th";
|
|
23
23
|
import ThMenu from "./ThMenu";
|
|
24
24
|
import { saveAs } from "file-saver";
|
|
25
|
-
import { unparse } from "papaparse";
|
|
26
25
|
import ColumnResizers from "./ColumnResizers";
|
|
27
|
-
import { sum } from "lodash";
|
|
26
|
+
import { difference, sum } from "lodash";
|
|
27
|
+
import * as ExcelJS from "exceljs";
|
|
28
28
|
const startOfTheWorldDate = new Date("1000-01-01 00:00:00Z");
|
|
29
29
|
const numberFormatter = new Intl.NumberFormat("nl-NL");
|
|
30
30
|
const currencyFormatter = new Intl.NumberFormat("nl-NL", {
|
|
@@ -220,7 +220,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
220
220
|
return { dynamicWidthColumnCount, fixedWidthColumnsWidth };
|
|
221
221
|
}, [columnNames, config]);
|
|
222
222
|
React.useEffect(() => {
|
|
223
|
-
const dynamicColumnWidth = Math.floor((width - fixedWidthColumnsWidth) / dynamicWidthColumnCount);
|
|
223
|
+
const dynamicColumnWidth = Math.max(Math.floor((width - fixedWidthColumnsWidth) / dynamicWidthColumnCount), MINIMUM_COLUMN_WIDTH);
|
|
224
224
|
let roundingDifference = (width - fixedWidthColumnsWidth) % dynamicWidthColumnCount;
|
|
225
225
|
setColumnWidths(columnNames.map((propName) => {
|
|
226
226
|
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
@@ -608,14 +608,31 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
608
608
|
if (!sortedRenderData) {
|
|
609
609
|
return;
|
|
610
610
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
],
|
|
617
|
-
|
|
618
|
-
|
|
611
|
+
const workbook = new ExcelJS.Workbook();
|
|
612
|
+
const worksheet = workbook.addWorksheet("Data");
|
|
613
|
+
if (!sortedRenderData.length) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
worksheet.addRow(difference(Object.keys(sortedRenderData[0]), [
|
|
617
|
+
"_index",
|
|
618
|
+
"SELECT_ALL_COLUMN_NAME",
|
|
619
|
+
]));
|
|
620
|
+
worksheet.addRows(sortedRenderData.map((row) => {
|
|
621
|
+
const { _index, SELECT_ALL_COLUMN_NAME } = row, data = __rest(row, ["_index", "SELECT_ALL_COLUMN_NAME"]);
|
|
622
|
+
return Object.values(data);
|
|
623
|
+
}));
|
|
624
|
+
// Save the workbook to a Blob
|
|
625
|
+
workbook.xlsx
|
|
626
|
+
.writeBuffer()
|
|
627
|
+
.then((buffer) => {
|
|
628
|
+
const blob = new Blob([buffer], {
|
|
629
|
+
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
630
|
+
});
|
|
631
|
+
saveAs(blob, "export.xlsx");
|
|
632
|
+
})
|
|
633
|
+
.catch((error) => {
|
|
634
|
+
console.error("Error generating Excel file:", error);
|
|
635
|
+
});
|
|
619
636
|
}, [sortedRenderData]);
|
|
620
637
|
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: rowWidth }), role: "table" }, { children: [_jsxs("div", Object.assign({ className: "schema-table__action-container" }, { children: [_jsx("div", { children: isSearchable ? (_jsx("input", { className: "schema-table__search", type: "text", placeholder: searchPlaceholder || "Search...", value: searchQuery, onChange: onSearchChange, onKeyDown: onInputKeyDown, autoFocus: enableAutoFocus, onBlur: onSearchBlur })) : null }), customElement || (_jsx("div", { className: "schema-table__custom_element_placeholder" })), enableRowCounter ? (_jsx("span", Object.assign({ className: "schema-table__row_counter" }, { children: translate("showingFilteredCountOfTotalCount", (sortedRenderData === null || sortedRenderData === void 0 ? void 0 : sortedRenderData.length) || 0, data.length) }))) : null, isExportable ? (_jsx("button", Object.assign({ onClick: onExportDataClick, style: { marginLeft: 8 }, disabled: !(sortedRenderData === null || sortedRenderData === void 0 ? void 0 : sortedRenderData.length) }, { children: translate("exportData") }))) : null, isSearchable || isColumnFilterable ? (_jsx("button", Object.assign({ onClick: onClearFiltersButtonClick, style: { marginLeft: 8 }, disabled: Object.keys(columnFilterMap).length + searchQuery.length === 0 }, { children: translate("clearFilters") }))) : null] })), columnWidths ? (_jsxs("div", Object.assign({ className: "schema-table__column_resize_container" }, { children: [_jsx(Heading, Object.assign({ height: 50, itemCount: columnCount, itemSize: getColumnWidth, layout: "horizontal", width: rowWidth, sortAsc: sortAsc, setSortAsc: onSetSortAsc, setSortColumn: onSetSortColumn, sortColumn: sortColumn, sortedRenderData: sortedRenderData, className: "schema-table__th-row" }, { children: ConfiguredTh }), `thead_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnWidths.join(" ")}`), sourceData && !isDirty ? (_jsx(VariableSizeGrid, Object.assign({ className: "schema-table__tbody", height: tableBodyHeight, width: rowWidth, columnWidth: getColumnWidth, rowHeight: getRowHeight, columnCount: columnCount, rowCount: rowCount, ref: tableRef }, { children: SchemaTableTd }), `tbody_${tableBodyHeight}_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}_${columnWidths.join(" ")}`)) : (_jsx("div", Object.assign({ style: {
|
|
621
638
|
width: rowWidth,
|
package/dist/inc/constant.d.ts
CHANGED
package/dist/inc/constant.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const DEFAULT_DATE_FORMAT = "dd MMM yyyy";
|
|
2
2
|
export const DEFAULT_DATE_TIME_FORMAT = "dd MMM yyyy HH:mm";
|
|
3
|
+
export const MINIMUM_COLUMN_WIDTH = 25;
|
|
3
4
|
export var ENumberColumnFilterOperation;
|
|
4
5
|
(function (ENumberColumnFilterOperation) {
|
|
5
6
|
ENumberColumnFilterOperation["GT"] = "GT";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mig-schema-table",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.114",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/"
|
|
@@ -10,16 +10,15 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@types/file-saver": "^2.0.7",
|
|
12
12
|
"@types/jest": "^27.5.2",
|
|
13
|
-
"@types/papaparse": "^5.3.14",
|
|
14
13
|
"@types/react": "^18.2.6",
|
|
15
14
|
"@types/react-datepicker": "^4.11.2",
|
|
16
15
|
"@types/react-dom": "^18.2.4",
|
|
17
16
|
"date-fns": "^2.30.0",
|
|
18
17
|
"date-fns-tz": "^2.0.0",
|
|
18
|
+
"exceljs": "^4.4.0",
|
|
19
19
|
"file-saver": "^2.0.5",
|
|
20
20
|
"lodash": "^4.17.21",
|
|
21
21
|
"openapi3-ts": "^4.1.2",
|
|
22
|
-
"papaparse": "^5.4.1",
|
|
23
22
|
"react": "^18.2.0",
|
|
24
23
|
"react-datepicker": "^6.2.0",
|
|
25
24
|
"react-dom": "^18.2.0",
|
|
@@ -52,11 +51,11 @@
|
|
|
52
51
|
]
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
|
-
"@types/node": "^20.12.5",
|
|
56
54
|
"@testing-library/jest-dom": "^5.16.5",
|
|
57
55
|
"@testing-library/react": "^13.4.0",
|
|
58
56
|
"@types/date-fns": "^2.6.0",
|
|
59
57
|
"@types/lodash": "^4.14.194",
|
|
58
|
+
"@types/node": "^20.12.5",
|
|
60
59
|
"@types/react-window": "^1.8.5",
|
|
61
60
|
"axios": "^1.4.0",
|
|
62
61
|
"prettier": "^2.8.8",
|