mig-schema-table 3.0.115 → 3.0.116
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,8 +1,7 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from "react";
|
|
2
1
|
interface IColumnResizersProps {
|
|
3
2
|
columnWidths: number[];
|
|
4
|
-
|
|
3
|
+
onColumnWidthsChange: (newColumnWidths: number[]) => void;
|
|
5
4
|
tableBodyHeight: number;
|
|
6
5
|
}
|
|
7
|
-
declare const ColumnResizers: ({ columnWidths,
|
|
6
|
+
declare const ColumnResizers: ({ columnWidths, onColumnWidthsChange, tableBodyHeight, }: IColumnResizersProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
7
|
export default ColumnResizers;
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
const ColumnResizers = ({ columnWidths,
|
|
4
|
+
const ColumnResizers = ({ columnWidths, onColumnWidthsChange, tableBodyHeight, }) => {
|
|
5
5
|
const [dragColumnIndex, setDragColumnIndex] = React.useState(-1);
|
|
6
6
|
const [dragStartX, setDragStartX] = React.useState(0);
|
|
7
7
|
const setColumnDelta = React.useCallback((columnDelta) => {
|
|
@@ -9,14 +9,10 @@ const ColumnResizers = ({ columnWidths, setColumnWidths, tableBodyHeight, }) =>
|
|
|
9
9
|
if (columnWidthIndex === dragColumnIndex) {
|
|
10
10
|
return Math.max(columnWidth + columnDelta, MINIMUM_COLUMN_WIDTH);
|
|
11
11
|
}
|
|
12
|
-
// Do not allow oversized tables?
|
|
13
|
-
// if (columnWidthIndex - 1 === dragColumnIndex) {
|
|
14
|
-
// return Math.max(columnWidth - columnDelta, MINIMUM_COLUMN_WIDTH);
|
|
15
|
-
// }
|
|
16
12
|
return columnWidth;
|
|
17
13
|
});
|
|
18
|
-
|
|
19
|
-
}, [columnWidths, dragColumnIndex,
|
|
14
|
+
onColumnWidthsChange(newColumnWidths);
|
|
15
|
+
}, [columnWidths, dragColumnIndex, onColumnWidthsChange]);
|
|
20
16
|
let pointer = 0;
|
|
21
17
|
const onDragStart = React.useCallback((e) => {
|
|
22
18
|
setDragColumnIndex(parseInt(e.currentTarget.dataset.columnIndex));
|
|
@@ -43,6 +43,7 @@ export interface ISchemaTableProps<T> {
|
|
|
43
43
|
rowHeight?: number;
|
|
44
44
|
schema: oas31.SchemaObject;
|
|
45
45
|
searchPlaceholder?: string;
|
|
46
|
+
settingsStorageKey: string;
|
|
46
47
|
style?: React.CSSProperties;
|
|
47
48
|
translate?: (key: string, ...args: Array<string | number>) => string;
|
|
48
49
|
useFilterStateHash?: boolean;
|
|
@@ -61,6 +62,6 @@ export interface INumberColumnFilterValue {
|
|
|
61
62
|
filterEmpty?: true;
|
|
62
63
|
}
|
|
63
64
|
export type TColumnFilterValue = string | boolean | number | IDateColumnFilterValue | INumberColumnFilterValue;
|
|
64
|
-
declare function SchemaTable<T>({ Heading, checkedIndexes, config, customElement, data, defaultColumnFilters, defaultSortAsc, defaultSortColumn, disabledCheckedIndexes, enableAutoFocus, enableRowCounter, getRowClassName, getRowSelected, isColumnFilterable, isExportable, isResizable, isSearchable, isSortable, maxHeight, onCheckedIndexesChange, onRowClick, onRowDoubleClick, onSearchEnter, rowHeight, schema, searchPlaceholder, style, translate, useFilterStateHash, width, tableRef, }: ISchemaTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
65
|
+
declare function SchemaTable<T>({ Heading, checkedIndexes, config, customElement, data, defaultColumnFilters, defaultSortAsc, defaultSortColumn, disabledCheckedIndexes, enableAutoFocus, enableRowCounter, getRowClassName, getRowSelected, isColumnFilterable, isExportable, isResizable, isSearchable, isSortable, maxHeight, onCheckedIndexesChange, onRowClick, onRowDoubleClick, onSearchEnter, rowHeight, schema, searchPlaceholder, settingsStorageKey, style, translate, useFilterStateHash, width, tableRef, }: ISchemaTableProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
65
66
|
declare const _default: typeof SchemaTable;
|
|
66
67
|
export default _default;
|
|
@@ -24,7 +24,7 @@ import ThMenu from "./ThMenu";
|
|
|
24
24
|
import { saveAs } from "file-saver";
|
|
25
25
|
import ColumnResizers from "./ColumnResizers";
|
|
26
26
|
import { difference, sum } from "lodash";
|
|
27
|
-
import
|
|
27
|
+
import { Workbook } 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", {
|
|
@@ -50,7 +50,7 @@ function getIsColumnSortable(isTableSortable, propSchema, propConfig) {
|
|
|
50
50
|
(propConfig === null || propConfig === void 0 ? void 0 : propConfig.isSortable) !== false &&
|
|
51
51
|
(propSchema || (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderData) || (propConfig === null || propConfig === void 0 ? void 0 : propConfig.sort)));
|
|
52
52
|
}
|
|
53
|
-
function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, customElement, data, defaultColumnFilters, defaultSortAsc = false, defaultSortColumn, disabledCheckedIndexes, enableAutoFocus = true, enableRowCounter = true, getRowClassName, getRowSelected, isColumnFilterable = true, isExportable = true, isResizable = true, isSearchable = true, isSortable = true, maxHeight, onCheckedIndexesChange, onRowClick, onRowDoubleClick, onSearchEnter, rowHeight = 36, schema, searchPlaceholder, style, translate = defaultTranslate, useFilterStateHash, width, tableRef, }) {
|
|
53
|
+
function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, customElement, data, defaultColumnFilters, defaultSortAsc = false, defaultSortColumn, disabledCheckedIndexes, enableAutoFocus = true, enableRowCounter = true, getRowClassName, getRowSelected, isColumnFilterable = true, isExportable = true, isResizable = true, isSearchable = true, isSortable = true, maxHeight, onCheckedIndexesChange, onRowClick, onRowDoubleClick, onSearchEnter, rowHeight = 36, schema, searchPlaceholder, settingsStorageKey, style, translate = defaultTranslate, useFilterStateHash, width, tableRef, }) {
|
|
54
54
|
const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
|
|
55
55
|
const [sortAsc, setSortAsc] = React.useState(defaultSortAsc);
|
|
56
56
|
const [thMenuConfig, setThMenuConfig] = React.useState();
|
|
@@ -219,10 +219,17 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
219
219
|
}, 0);
|
|
220
220
|
return { dynamicWidthColumnCount, fixedWidthColumnsWidth };
|
|
221
221
|
}, [columnNames, config]);
|
|
222
|
+
const serializedStoredSettings = settingsStorageKey
|
|
223
|
+
? localStorage.getItem(settingsStorageKey)
|
|
224
|
+
: null;
|
|
222
225
|
React.useEffect(() => {
|
|
226
|
+
var _a;
|
|
227
|
+
const storedSettings = serializedStoredSettings
|
|
228
|
+
? JSON.parse(serializedStoredSettings)
|
|
229
|
+
: {};
|
|
223
230
|
const dynamicColumnWidth = Math.max(Math.floor((width - fixedWidthColumnsWidth) / dynamicWidthColumnCount), MINIMUM_COLUMN_WIDTH);
|
|
224
231
|
let roundingDifference = (width - fixedWidthColumnsWidth) % dynamicWidthColumnCount;
|
|
225
|
-
|
|
232
|
+
const newColumnWidths = columnNames.map((propName) => {
|
|
226
233
|
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
227
234
|
return SELECT_ALL_COLUMN_WIDTH;
|
|
228
235
|
}
|
|
@@ -235,12 +242,17 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
235
242
|
return dynamicColumnWidth + 1;
|
|
236
243
|
}
|
|
237
244
|
return dynamicColumnWidth;
|
|
238
|
-
})
|
|
245
|
+
});
|
|
246
|
+
setColumnWidths(((_a = storedSettings === null || storedSettings === void 0 ? void 0 : storedSettings.columnWidths) === null || _a === void 0 ? void 0 : _a.length) === newColumnWidths.length
|
|
247
|
+
? storedSettings.columnWidths
|
|
248
|
+
: newColumnWidths);
|
|
239
249
|
}, [
|
|
240
250
|
columnNames,
|
|
241
251
|
config,
|
|
242
252
|
dynamicWidthColumnCount,
|
|
243
253
|
fixedWidthColumnsWidth,
|
|
254
|
+
serializedStoredSettings,
|
|
255
|
+
settingsStorageKey,
|
|
244
256
|
width,
|
|
245
257
|
]);
|
|
246
258
|
const getColumnWidth = React.useCallback((columnIndex) => (columnWidths ? columnWidths[columnIndex] : 1), [columnWidths]);
|
|
@@ -608,7 +620,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
608
620
|
if (!sortedRenderData) {
|
|
609
621
|
return;
|
|
610
622
|
}
|
|
611
|
-
const workbook = new
|
|
623
|
+
const workbook = new Workbook();
|
|
612
624
|
const worksheet = workbook.addWorksheet("Data");
|
|
613
625
|
if (!sortedRenderData.length) {
|
|
614
626
|
return;
|
|
@@ -617,6 +629,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
617
629
|
"_index",
|
|
618
630
|
"SELECT_ALL_COLUMN_NAME",
|
|
619
631
|
]));
|
|
632
|
+
worksheet.getRow(1).font = { bold: true };
|
|
620
633
|
worksheet.addRows(sortedRenderData.map((row) => {
|
|
621
634
|
const { _index, SELECT_ALL_COLUMN_NAME } = row, data = __rest(row, ["_index", "SELECT_ALL_COLUMN_NAME"]);
|
|
622
635
|
return Object.values(data);
|
|
@@ -634,7 +647,17 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
634
647
|
console.error("Error generating Excel file:", error);
|
|
635
648
|
});
|
|
636
649
|
}, [sortedRenderData]);
|
|
637
|
-
|
|
650
|
+
const onColumnWidthsChange = React.useCallback((newColumnWidths) => {
|
|
651
|
+
if (settingsStorageKey) {
|
|
652
|
+
localStorage.setItem(settingsStorageKey, JSON.stringify({ columnWidths: newColumnWidths }));
|
|
653
|
+
}
|
|
654
|
+
setColumnWidths(newColumnWidths);
|
|
655
|
+
}, [settingsStorageKey]);
|
|
656
|
+
const onClearSettingsButtonClick = React.useCallback(() => {
|
|
657
|
+
localStorage.removeItem(settingsStorageKey);
|
|
658
|
+
setColumnWidths(undefined);
|
|
659
|
+
}, [settingsStorageKey]);
|
|
660
|
+
return (_jsxs("div", Object.assign({ className: `schema-table${onRowClick ? " schema-table--clickable-rows" : ""}`, style: Object.assign(Object.assign({}, style), { width: Math.min(rowWidth, width) }), 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, settingsStorageKey ? (_jsx("button", Object.assign({ onClick: onClearSettingsButtonClick, style: { marginLeft: 8 }, disabled: !serializedStoredSettings }, { children: translate("clearSettings") }))) : 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: {
|
|
638
661
|
width: rowWidth,
|
|
639
662
|
height: Math.max(50, tableBodyHeight),
|
|
640
663
|
border: "1px solid #BBB",
|
|
@@ -643,6 +666,6 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
643
666
|
backgroundColor: "#CCC",
|
|
644
667
|
alignItems: "center",
|
|
645
668
|
justifyContent: "center",
|
|
646
|
-
} }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), isResizable ? (_jsx(ColumnResizers, { columnWidths: columnWidths,
|
|
669
|
+
} }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), isResizable ? (_jsx(ColumnResizers, { columnWidths: columnWidths, onColumnWidthsChange: onColumnWidthsChange, tableBodyHeight: tableBodyHeight })) : null] }))) : null, createPortal(thMenuConfig ? (_jsx(ThMenu, { isFilterable: !!isColumnFilterable, isSortable: getIsColumnSortable(!!isSortable, schema.properties[thMenuConfig.propName], thMenuConfig.propConfig), onChange: onSchemaColumnFilterChange, onClose: onPopoverClose, onInputKeyDown: onInputKeyDown, propConfig: thMenuConfig.propConfig, propIsRequired: thMenuConfig.propIsRequired, propName: thMenuConfig.propName, propSchema: schema.properties[thMenuConfig.propName], referenceElement: thMenuConfig.referenceElement, setSortAsc: setSortAsc, setSortColumn: setSortColumn, translate: translate, value: columnFilterMap[thMenuConfig.propName] })) : null, document.body)] })));
|
|
647
670
|
}
|
|
648
671
|
export default React.memo(SchemaTable);
|