mig-schema-table 3.0.117 → 3.0.119
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.
- package/dist/SchemaTable/ColumnResizers/index.d.ts +3 -1
- package/dist/SchemaTable/ColumnResizers/index.js +8 -9
- package/dist/SchemaTable/Th/index.d.ts +2 -1
- package/dist/SchemaTable/Th/index.js +49 -3
- package/dist/SchemaTable/index.js +107 -66
- package/dist/index.css +12 -0
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
interface IColumnResizersProps {
|
|
2
2
|
columnWidths: number[];
|
|
3
3
|
onColumnWidthsChange: (newColumnWidths: number[]) => void;
|
|
4
|
+
resizeColumnIndex: number;
|
|
5
|
+
setResizeColumnIndex: (newResizeColumnIndex: number) => void;
|
|
4
6
|
tableBodyHeight: number;
|
|
5
7
|
}
|
|
6
|
-
declare const ColumnResizers: ({ columnWidths, onColumnWidthsChange, tableBodyHeight, }: IColumnResizersProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
declare const ColumnResizers: ({ columnWidths, onColumnWidthsChange, resizeColumnIndex, setResizeColumnIndex, tableBodyHeight, }: IColumnResizersProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
9
|
export default ColumnResizers;
|
|
@@ -1,32 +1,31 @@
|
|
|
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, onColumnWidthsChange, tableBodyHeight, }) => {
|
|
5
|
-
const [dragColumnIndex, setDragColumnIndex] = React.useState(-1);
|
|
4
|
+
const ColumnResizers = ({ columnWidths, onColumnWidthsChange, resizeColumnIndex, setResizeColumnIndex, tableBodyHeight, }) => {
|
|
6
5
|
const [dragStartX, setDragStartX] = React.useState(0);
|
|
7
6
|
const setColumnDelta = React.useCallback((columnDelta) => {
|
|
8
7
|
const newColumnWidths = columnWidths.map((columnWidth, columnWidthIndex) => {
|
|
9
|
-
if (columnWidthIndex ===
|
|
8
|
+
if (columnWidthIndex === resizeColumnIndex) {
|
|
10
9
|
return Math.max(columnWidth + columnDelta, MINIMUM_COLUMN_WIDTH);
|
|
11
10
|
}
|
|
12
11
|
return columnWidth;
|
|
13
12
|
});
|
|
14
13
|
onColumnWidthsChange(newColumnWidths);
|
|
15
|
-
}, [columnWidths,
|
|
14
|
+
}, [columnWidths, resizeColumnIndex, onColumnWidthsChange]);
|
|
16
15
|
let pointer = 0;
|
|
17
16
|
const onDragStart = React.useCallback((e) => {
|
|
18
|
-
|
|
17
|
+
setResizeColumnIndex(parseInt(e.currentTarget.dataset.columnIndex));
|
|
19
18
|
setDragStartX(e.clientX);
|
|
20
|
-
}, []);
|
|
19
|
+
}, [setResizeColumnIndex]);
|
|
21
20
|
const onDragEnd = React.useCallback((e) => {
|
|
22
21
|
setColumnDelta(e.clientX - dragStartX);
|
|
23
22
|
setDragStartX(0);
|
|
24
|
-
|
|
25
|
-
}, [dragStartX, setColumnDelta]);
|
|
23
|
+
setResizeColumnIndex(-1);
|
|
24
|
+
}, [dragStartX, setColumnDelta, setResizeColumnIndex]);
|
|
26
25
|
return (_jsx("div", { children: columnWidths.map((columnWidth, columnIndex) => {
|
|
27
26
|
pointer += columnWidth;
|
|
28
27
|
const classNames = ["schema-table__column_resizer"];
|
|
29
|
-
if (columnIndex ===
|
|
28
|
+
if (columnIndex === resizeColumnIndex) {
|
|
30
29
|
classNames.push("schema-table__column_resizer--dragged");
|
|
31
30
|
}
|
|
32
31
|
return (_jsx("div", { style: { left: pointer, bottom: tableBodyHeight }, className: classNames.join(" "), draggable: "true", "data-column-index": columnIndex, onDragStart: onDragStart, onDragEnd: onDragEnd }, columnIndex));
|
|
@@ -12,6 +12,7 @@ interface IThProps {
|
|
|
12
12
|
isAllChecked?: boolean;
|
|
13
13
|
isSortable: boolean;
|
|
14
14
|
numberOfSelectedRows?: number;
|
|
15
|
+
onColumnPositionChange?: (sourceColumnName: string, destinationColumnName: string) => void;
|
|
15
16
|
onSelectAllIndexesHandler?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
16
17
|
propConfig?: IColumnConfig<any>;
|
|
17
18
|
propIsRequired: boolean;
|
|
@@ -24,5 +25,5 @@ interface IThProps {
|
|
|
24
25
|
style: CSSProperties;
|
|
25
26
|
translate: (key: string, ...args: Array<string | number>) => string;
|
|
26
27
|
}
|
|
27
|
-
declare const _default: ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, translate, }: IThProps) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
declare const _default: ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onColumnPositionChange, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, translate, }: IThProps) => import("react/jsx-runtime").JSX.Element;
|
|
28
29
|
export default _default;
|
|
@@ -8,7 +8,9 @@ export var EColumnFilterStatus;
|
|
|
8
8
|
EColumnFilterStatus["AVAILABLE"] = "AVAILABLE";
|
|
9
9
|
EColumnFilterStatus["ACTIVE"] = "ACTIVE";
|
|
10
10
|
})(EColumnFilterStatus || (EColumnFilterStatus = {}));
|
|
11
|
-
const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, translate, }) => {
|
|
11
|
+
const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows, onColumnPositionChange, onSelectAllIndexesHandler, propConfig, propIsRequired, propName, schema, setMenuConfig, setSortAsc, setSortColumn, sortAsc, style, translate, }) => {
|
|
12
|
+
const [isDragging, setIsDragging] = React.useState(false);
|
|
13
|
+
const [isDropTarget, setIsDropTarget] = React.useState(false);
|
|
12
14
|
const classNames = [
|
|
13
15
|
`schema-table__th`,
|
|
14
16
|
`schema-table__th--filter-${columnFilterStatus}`,
|
|
@@ -18,6 +20,12 @@ const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows
|
|
|
18
20
|
if (sortAsc !== undefined) {
|
|
19
21
|
classNames.push("schema-table__th--sorted");
|
|
20
22
|
}
|
|
23
|
+
if (isDragging) {
|
|
24
|
+
classNames.push(`schema-table__th--dragging`);
|
|
25
|
+
}
|
|
26
|
+
if (isDropTarget) {
|
|
27
|
+
classNames.push(`schema-table__th--drop-target`);
|
|
28
|
+
}
|
|
21
29
|
const onLabelClick = React.useCallback(() => {
|
|
22
30
|
if (!isSortable) {
|
|
23
31
|
return;
|
|
@@ -67,11 +75,49 @@ const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows
|
|
|
67
75
|
schema === null || schema === void 0 ? void 0 : schema.format,
|
|
68
76
|
translate,
|
|
69
77
|
]);
|
|
78
|
+
const onDragStart = React.useCallback((e) => {
|
|
79
|
+
if (!onColumnPositionChange) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
setIsDragging(true);
|
|
83
|
+
e.dataTransfer.effectAllowed = "move";
|
|
84
|
+
e.dataTransfer.dropEffect = "move";
|
|
85
|
+
e.dataTransfer.setData("text/plain", propName);
|
|
86
|
+
}, [onColumnPositionChange, propName]);
|
|
87
|
+
const onDragEnd = React.useCallback((e) => {
|
|
88
|
+
if (!onColumnPositionChange) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setIsDragging(false);
|
|
92
|
+
}, [onColumnPositionChange]);
|
|
93
|
+
const onDragOver = React.useCallback((e) => {
|
|
94
|
+
if (!onColumnPositionChange) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
setIsDropTarget(true);
|
|
99
|
+
}, [onColumnPositionChange]);
|
|
100
|
+
const onDragLeave = React.useCallback(() => {
|
|
101
|
+
if (!onColumnPositionChange) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
setIsDropTarget(false);
|
|
105
|
+
}, [onColumnPositionChange]);
|
|
106
|
+
const onDrop = React.useCallback((e) => {
|
|
107
|
+
if (!onColumnPositionChange || !propName) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const sourcePropName = e.dataTransfer.getData("text/plain");
|
|
111
|
+
if (!sourcePropName) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
onColumnPositionChange(sourcePropName, propName);
|
|
115
|
+
}, [onColumnPositionChange, propName]);
|
|
70
116
|
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
71
117
|
return (_jsx("div", Object.assign({ style: style, className: classNames.join(" ") }, { children: _jsx("div", Object.assign({ style: {
|
|
72
118
|
width: "100%",
|
|
73
119
|
textAlign: "center",
|
|
74
|
-
}, title: `${numberOfSelectedRows || 0} selected` }, { children: _jsx("input", { type: "checkbox", checked: isAllChecked, onChange: onSelectAllIndexesHandler }) })) })));
|
|
120
|
+
}, title: `${numberOfSelectedRows || 0} selected` }, { children: _jsx("input", { type: "checkbox", name: "selectAll", checked: isAllChecked, onChange: onSelectAllIndexesHandler }) })) })));
|
|
75
121
|
}
|
|
76
122
|
const title = typeof labelBody === "string" ? labelBody : undefined;
|
|
77
123
|
if (!schema && !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderData) && !(propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderCell)) {
|
|
@@ -90,6 +136,6 @@ const Th = ({ columnFilterStatus, isAllChecked, isSortable, numberOfSelectedRows
|
|
|
90
136
|
classNames.push(`text-${propConfig.align}`);
|
|
91
137
|
}
|
|
92
138
|
}
|
|
93
|
-
return (_jsxs("div", Object.assign({ style: style, className: classNames.join(" "), title: title }, { children: [_jsxs("div", Object.assign({ className: "schema-table__th__label-body", style: { lineHeight: "44px" }, onClick: onLabelClick }, { children: [_jsx("span", Object.assign({ className: "schema-table__th__label-body-text" }, { children: labelBody })), sortAsc === undefined ? null : (_jsx("span", Object.assign({ className: "schema-table__th__sort-icon" }, { children: sortAsc ? "↓" : "↑" })))] })), isSortable || columnFilterStatus !== EColumnFilterStatus.UNAVAILABLE ? (_jsx("button", Object.assign({ className: "schema-table__th__trigger-el", onClick: onTriggerClick }, { children: _jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "#404040", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, { children: _jsx("polyline", { points: "6 9 12 15 18 9" }) })) }))) : null] })));
|
|
139
|
+
return (_jsxs("div", Object.assign({ style: style, className: classNames.join(" "), title: title }, { children: [_jsxs("div", Object.assign({ className: "schema-table__th__label-body", style: { lineHeight: "44px" }, onClick: onLabelClick, draggable: true, onDragStart: onDragStart, onDragEnd: onDragEnd, onDragOver: onDragOver, onDragLeave: onDragLeave, onDrop: onDrop }, { children: [_jsx("span", Object.assign({ className: "schema-table__th__label-body-text" }, { children: labelBody })), sortAsc === undefined ? null : (_jsx("span", Object.assign({ className: "schema-table__th__sort-icon" }, { children: sortAsc ? "↓" : "↑" })))] })), isSortable || columnFilterStatus !== EColumnFilterStatus.UNAVAILABLE ? (_jsx("button", Object.assign({ className: "schema-table__th__trigger-el", onClick: onTriggerClick }, { children: _jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "#404040", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, { children: _jsx("polyline", { points: "6 9 12 15 18 9" }) })) }))) : null] })));
|
|
94
140
|
};
|
|
95
141
|
export default React.memo(Th);
|
|
@@ -23,7 +23,7 @@ import Th, { EColumnFilterStatus } from "./Th";
|
|
|
23
23
|
import ThMenu from "./ThMenu";
|
|
24
24
|
import { saveAs } from "file-saver";
|
|
25
25
|
import ColumnResizers from "./ColumnResizers";
|
|
26
|
-
import { difference, sum } from "lodash";
|
|
26
|
+
import { difference, isFinite, sum } from "lodash";
|
|
27
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");
|
|
@@ -51,6 +51,8 @@ function getIsColumnSortable(isTableSortable, propSchema, propConfig) {
|
|
|
51
51
|
(propSchema || (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderData) || (propConfig === null || propConfig === void 0 ? void 0 : propConfig.sort)));
|
|
52
52
|
}
|
|
53
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
|
+
const [columnNames, setColumnNames] = React.useState();
|
|
55
|
+
const [resizeColumnIndex, setResizeColumnIndex] = React.useState(-1);
|
|
54
56
|
const [sortColumn, setSortColumn] = React.useState(defaultSortColumn);
|
|
55
57
|
const [sortAsc, setSortAsc] = React.useState(defaultSortAsc);
|
|
56
58
|
const [thMenuConfig, setThMenuConfig] = React.useState();
|
|
@@ -98,50 +100,61 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
98
100
|
sourceData,
|
|
99
101
|
]);
|
|
100
102
|
const { properties = {}, required = [] } = schema;
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
+
const serializedStoredColumnNames = settingsStorageKey
|
|
104
|
+
? localStorage.getItem(`${settingsStorageKey}.columnNames`)
|
|
105
|
+
: null;
|
|
106
|
+
const serializedStoredColumnWidths = settingsStorageKey
|
|
107
|
+
? localStorage.getItem(`${settingsStorageKey}.columnWidths`)
|
|
108
|
+
: null;
|
|
109
|
+
React.useEffect(() => {
|
|
110
|
+
const storedColumnNames = serializedStoredColumnNames
|
|
111
|
+
? JSON.parse(serializedStoredColumnNames)
|
|
112
|
+
: undefined;
|
|
113
|
+
let freshColumnNames = Object.keys(properties);
|
|
103
114
|
if (onCheckedIndexesChange) {
|
|
104
|
-
|
|
115
|
+
freshColumnNames.unshift(SELECT_ALL_COLUMN_NAME);
|
|
105
116
|
}
|
|
106
|
-
if (
|
|
107
|
-
|
|
117
|
+
if (config) {
|
|
118
|
+
Object.keys(config).forEach((configKey) => {
|
|
119
|
+
if (!freshColumnNames.includes(configKey)) {
|
|
120
|
+
freshColumnNames.push(configKey);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const invisibleColumns = Object.entries(config).reduce((prev, [propName, propConfig]) => {
|
|
124
|
+
if (propConfig.hidden) {
|
|
125
|
+
prev.push(propName);
|
|
126
|
+
}
|
|
127
|
+
return prev;
|
|
128
|
+
}, []);
|
|
129
|
+
freshColumnNames = freshColumnNames
|
|
130
|
+
.filter((key) => !invisibleColumns.includes(key))
|
|
131
|
+
.sort((columnA, columnB) => {
|
|
132
|
+
let orderA = config[columnA] ? config[columnA].order : undefined;
|
|
133
|
+
if (orderA === undefined) {
|
|
134
|
+
orderA = Object.keys(properties).findIndex((propName) => propName === columnA);
|
|
135
|
+
}
|
|
136
|
+
let orderB = config[columnB] ? config[columnB].order : undefined;
|
|
137
|
+
if (orderB === undefined) {
|
|
138
|
+
orderB = Object.keys(properties).findIndex((propName) => propName === columnB);
|
|
139
|
+
}
|
|
140
|
+
if (columnB === SELECT_ALL_COLUMN_NAME ||
|
|
141
|
+
columnA === SELECT_ALL_COLUMN_NAME) {
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
if (orderA === -1) {
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
if (orderB === -1) {
|
|
148
|
+
return -1;
|
|
149
|
+
}
|
|
150
|
+
return orderA - orderB;
|
|
151
|
+
});
|
|
108
152
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const invisibleColumns = Object.entries(config).reduce((prev, [propName, propConfig]) => {
|
|
115
|
-
if (propConfig.hidden) {
|
|
116
|
-
prev.push(propName);
|
|
117
|
-
}
|
|
118
|
-
return prev;
|
|
119
|
-
}, []);
|
|
120
|
-
return columns
|
|
121
|
-
.filter((key) => !invisibleColumns.includes(key))
|
|
122
|
-
.sort((columnA, columnB) => {
|
|
123
|
-
let orderA = config[columnA] ? config[columnA].order : undefined;
|
|
124
|
-
if (orderA === undefined) {
|
|
125
|
-
orderA = Object.keys(properties).findIndex((propName) => propName === columnA);
|
|
126
|
-
}
|
|
127
|
-
let orderB = config[columnB] ? config[columnB].order : undefined;
|
|
128
|
-
if (orderB === undefined) {
|
|
129
|
-
orderB = Object.keys(properties).findIndex((propName) => propName === columnB);
|
|
130
|
-
}
|
|
131
|
-
if (columnB === SELECT_ALL_COLUMN_NAME ||
|
|
132
|
-
columnA === SELECT_ALL_COLUMN_NAME) {
|
|
133
|
-
return 0;
|
|
134
|
-
}
|
|
135
|
-
if (orderA === -1) {
|
|
136
|
-
return 1;
|
|
137
|
-
}
|
|
138
|
-
if (orderB === -1) {
|
|
139
|
-
return -1;
|
|
140
|
-
}
|
|
141
|
-
return orderA - orderB;
|
|
142
|
-
});
|
|
143
|
-
}, [config, onCheckedIndexesChange, properties]);
|
|
144
|
-
const renderData = React.useMemo(() => sourceData
|
|
153
|
+
setColumnNames((storedColumnNames === null || storedColumnNames === void 0 ? void 0 : storedColumnNames.length) === freshColumnNames.length
|
|
154
|
+
? storedColumnNames
|
|
155
|
+
: freshColumnNames);
|
|
156
|
+
}, [config, onCheckedIndexesChange, properties, serializedStoredColumnNames]);
|
|
157
|
+
const renderData = React.useMemo(() => sourceData && columnNames
|
|
145
158
|
? sourceData.map((object, rowIndex) => columnNames.reduce((prev, propName) => {
|
|
146
159
|
var _a;
|
|
147
160
|
const schema = properties[propName];
|
|
@@ -200,11 +213,11 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
200
213
|
}
|
|
201
214
|
}, { _index: rowIndex }))
|
|
202
215
|
: undefined, [sourceData, columnNames, properties, config, translate]);
|
|
203
|
-
const columnCount = columnNames.length;
|
|
216
|
+
const columnCount = columnNames ? columnNames.length : 0;
|
|
204
217
|
const { dynamicWidthColumnCount, fixedWidthColumnsWidth } = React.useMemo(() => {
|
|
205
218
|
let fixedWidthColumnsWidth = 0;
|
|
206
219
|
let dynamicWidthColumnCount = 0;
|
|
207
|
-
columnNames.forEach((propName) => {
|
|
220
|
+
(columnNames || []).forEach((propName) => {
|
|
208
221
|
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
209
222
|
fixedWidthColumnsWidth += SELECT_ALL_COLUMN_WIDTH;
|
|
210
223
|
return;
|
|
@@ -219,17 +232,16 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
219
232
|
}, 0);
|
|
220
233
|
return { dynamicWidthColumnCount, fixedWidthColumnsWidth };
|
|
221
234
|
}, [columnNames, config]);
|
|
222
|
-
const serializedStoredSettings = settingsStorageKey
|
|
223
|
-
? localStorage.getItem(settingsStorageKey)
|
|
224
|
-
: null;
|
|
225
235
|
React.useEffect(() => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
236
|
+
if (!columnNames) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const storedColumnWidths = serializedStoredColumnWidths
|
|
240
|
+
? JSON.parse(serializedStoredColumnWidths)
|
|
241
|
+
: undefined;
|
|
230
242
|
const dynamicColumnWidth = Math.max(Math.floor((width - fixedWidthColumnsWidth) / dynamicWidthColumnCount), MINIMUM_COLUMN_WIDTH);
|
|
231
243
|
let roundingDifference = (width - fixedWidthColumnsWidth) % dynamicWidthColumnCount;
|
|
232
|
-
const
|
|
244
|
+
const freshColumnWidths = columnNames.map((propName) => {
|
|
233
245
|
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
234
246
|
return SELECT_ALL_COLUMN_WIDTH;
|
|
235
247
|
}
|
|
@@ -243,15 +255,15 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
243
255
|
}
|
|
244
256
|
return dynamicColumnWidth;
|
|
245
257
|
});
|
|
246
|
-
setColumnWidths((
|
|
247
|
-
?
|
|
248
|
-
:
|
|
258
|
+
setColumnWidths((storedColumnWidths === null || storedColumnWidths === void 0 ? void 0 : storedColumnWidths.length) === freshColumnWidths.length
|
|
259
|
+
? storedColumnWidths
|
|
260
|
+
: freshColumnWidths);
|
|
249
261
|
}, [
|
|
250
262
|
columnNames,
|
|
251
263
|
config,
|
|
252
264
|
dynamicWidthColumnCount,
|
|
253
265
|
fixedWidthColumnsWidth,
|
|
254
|
-
|
|
266
|
+
serializedStoredColumnWidths,
|
|
255
267
|
settingsStorageKey,
|
|
256
268
|
width,
|
|
257
269
|
]);
|
|
@@ -265,6 +277,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
265
277
|
return renderData.filter((item) => {
|
|
266
278
|
const lcSearchQuery = searchQuery.toLowerCase();
|
|
267
279
|
if (searchQuery &&
|
|
280
|
+
columnNames &&
|
|
268
281
|
!columnNames.find((columnName) => `${item[columnName]}`.toLowerCase().includes(lcSearchQuery))) {
|
|
269
282
|
return false;
|
|
270
283
|
}
|
|
@@ -459,7 +472,35 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
459
472
|
}
|
|
460
473
|
setSortAsc(x);
|
|
461
474
|
}, [isDataFunction]);
|
|
475
|
+
const onColumnWidthsChange = React.useCallback((newColumnWidths) => {
|
|
476
|
+
if (settingsStorageKey) {
|
|
477
|
+
localStorage.setItem(`${settingsStorageKey}.columnWidths`, JSON.stringify(newColumnWidths));
|
|
478
|
+
}
|
|
479
|
+
setColumnWidths(newColumnWidths);
|
|
480
|
+
}, [settingsStorageKey]);
|
|
481
|
+
const onColumnPositionChange = React.useCallback((dragColumnName, dropColumnName) => {
|
|
482
|
+
if (!columnNames || !columnWidths) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
// First move the actual name...
|
|
486
|
+
const dragColumnIndex = columnNames.indexOf(dragColumnName);
|
|
487
|
+
let newColumnNames = [...columnNames];
|
|
488
|
+
newColumnNames.splice(dragColumnIndex, 1);
|
|
489
|
+
const dropColumnIndex = newColumnNames.indexOf(dropColumnName);
|
|
490
|
+
newColumnNames.splice(dropColumnIndex + 1, 0, dragColumnName);
|
|
491
|
+
localStorage.setItem(`${settingsStorageKey}.columnNames`, JSON.stringify(newColumnNames));
|
|
492
|
+
setColumnNames(newColumnNames);
|
|
493
|
+
// ...then make sure the width of column is moved as well
|
|
494
|
+
let newColumnWidths = [...columnWidths];
|
|
495
|
+
const draggedColumnWidth = newColumnWidths[dragColumnIndex];
|
|
496
|
+
newColumnWidths.splice(dragColumnIndex, 1);
|
|
497
|
+
newColumnWidths.splice(dropColumnIndex + 1, 0, draggedColumnWidth);
|
|
498
|
+
onColumnWidthsChange(newColumnWidths);
|
|
499
|
+
}, [columnNames, columnWidths, onColumnWidthsChange, settingsStorageKey]);
|
|
462
500
|
const ConfiguredTh = React.useCallback(({ style, index }) => {
|
|
501
|
+
if (!columnNames || !isFinite(style.left)) {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
463
504
|
const propName = columnNames[index];
|
|
464
505
|
const propSchema = (propName === SELECT_ALL_COLUMN_NAME
|
|
465
506
|
? { type: "boolean" }
|
|
@@ -475,7 +516,9 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
475
516
|
}
|
|
476
517
|
return (_jsx(Th, { columnFilterStatus: columnFilterStatus,
|
|
477
518
|
// disableColumnFilter={disableColumnFilter}
|
|
478
|
-
isAllChecked: isAllRowsChecked, isSortable: getIsColumnSortable(!!isSortable, propSchema, propConfig), numberOfSelectedRows: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length, onSelectAllIndexesHandler: onSelectAllIndexesHandler,
|
|
519
|
+
isAllChecked: isAllRowsChecked, isSortable: getIsColumnSortable(!!isSortable, propSchema, propConfig), numberOfSelectedRows: checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length, onSelectAllIndexesHandler: onSelectAllIndexesHandler, onColumnPositionChange: resizeColumnIndex === -1 && settingsStorageKey
|
|
520
|
+
? onColumnPositionChange
|
|
521
|
+
: undefined, propConfig: propConfig, propIsRequired: required.includes(propName), propName: propName, schema: propSchema, setMenuConfig: setThMenuConfig, setSortAsc: onSetSortAsc, setSortColumn: onSetSortColumn, sortAsc: sortColumn === propName ? sortAsc : undefined, style: style, translate: translate }));
|
|
479
522
|
}, [
|
|
480
523
|
checkedIndexes === null || checkedIndexes === void 0 ? void 0 : checkedIndexes.length,
|
|
481
524
|
columnFilterMap,
|
|
@@ -484,11 +527,14 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
484
527
|
isAllRowsChecked,
|
|
485
528
|
isColumnFilterable,
|
|
486
529
|
isSortable,
|
|
530
|
+
onColumnPositionChange,
|
|
487
531
|
onSelectAllIndexesHandler,
|
|
488
532
|
onSetSortAsc,
|
|
489
533
|
onSetSortColumn,
|
|
490
534
|
properties,
|
|
491
535
|
required,
|
|
536
|
+
resizeColumnIndex,
|
|
537
|
+
settingsStorageKey,
|
|
492
538
|
sortAsc,
|
|
493
539
|
sortColumn,
|
|
494
540
|
translate,
|
|
@@ -647,20 +693,15 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
647
693
|
console.error("Error generating Excel file:", error);
|
|
648
694
|
});
|
|
649
695
|
}, [sortedRenderData]);
|
|
650
|
-
const onColumnWidthsChange = React.useCallback((newColumnWidths) => {
|
|
651
|
-
if (settingsStorageKey) {
|
|
652
|
-
localStorage.setItem(settingsStorageKey, JSON.stringify({ columnWidths: newColumnWidths }));
|
|
653
|
-
}
|
|
654
|
-
setColumnWidths(newColumnWidths);
|
|
655
|
-
}, [settingsStorageKey]);
|
|
656
696
|
const onClearSettingsButtonClick = React.useCallback(() => {
|
|
657
697
|
if (!settingsStorageKey) {
|
|
658
698
|
return;
|
|
659
699
|
}
|
|
660
|
-
localStorage.removeItem(settingsStorageKey);
|
|
700
|
+
localStorage.removeItem(`${settingsStorageKey}.columnNames`);
|
|
701
|
+
localStorage.removeItem(`${settingsStorageKey}.columnWidths`);
|
|
661
702
|
setColumnWidths(undefined);
|
|
662
703
|
}, [settingsStorageKey]);
|
|
663
|
-
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: !
|
|
704
|
+
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", name: "search", autoComplete: "off", 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: !serializedStoredColumnNames && !serializedStoredColumnWidths }, { children: translate("clearSettings") }))) : null] })), columnNames && 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: {
|
|
664
705
|
width: rowWidth,
|
|
665
706
|
height: Math.max(50, tableBodyHeight),
|
|
666
707
|
border: "1px solid #BBB",
|
|
@@ -669,6 +710,6 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
669
710
|
backgroundColor: "#CCC",
|
|
670
711
|
alignItems: "center",
|
|
671
712
|
justifyContent: "center",
|
|
672
|
-
} }, { 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)] })));
|
|
713
|
+
} }, { 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, resizeColumnIndex: resizeColumnIndex, setResizeColumnIndex: setResizeColumnIndex, 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)] })));
|
|
673
714
|
}
|
|
674
715
|
export default React.memo(SchemaTable);
|
package/dist/index.css
CHANGED
|
@@ -74,6 +74,18 @@
|
|
|
74
74
|
.schema-table__th--sorted {
|
|
75
75
|
background-color: #eff6fb;
|
|
76
76
|
}
|
|
77
|
+
.schema-table__th--dragging {
|
|
78
|
+
opacity: 0.5;
|
|
79
|
+
}
|
|
80
|
+
.schema-table__th--dragging .schema-table__th__trigger-el {
|
|
81
|
+
display: none !important;
|
|
82
|
+
}
|
|
83
|
+
.schema-table__th--drop-target {
|
|
84
|
+
border-right: 3px dashed green;
|
|
85
|
+
}
|
|
86
|
+
.schema-table__th--drop-target .schema-table__th__trigger-el {
|
|
87
|
+
display: none !important;
|
|
88
|
+
}
|
|
77
89
|
.schema-table__th--filter-ACTIVE .schema-table__th__label-body-text {
|
|
78
90
|
text-decoration: underline;
|
|
79
91
|
font-style: italic;
|