mig-schema-table 3.0.99 → 3.0.101
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,7 +1,7 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from "react";
|
|
2
2
|
interface IColumnResizersProps {
|
|
3
3
|
columnWidths: number[];
|
|
4
|
-
setColumnWidths: Dispatch<SetStateAction<number[]>>;
|
|
4
|
+
setColumnWidths: Dispatch<SetStateAction<undefined | number[]>>;
|
|
5
5
|
tableBodyHeight: number;
|
|
6
6
|
}
|
|
7
7
|
declare const ColumnResizers: ({ columnWidths, setColumnWidths, tableBodyHeight, }: IColumnResizersProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,16 +5,14 @@ const ColumnResizers = ({ columnWidths, setColumnWidths, tableBodyHeight, }) =>
|
|
|
5
5
|
const [dragColumnIndex, setDragColumnIndex] = React.useState(-1);
|
|
6
6
|
const [dragStartX, setDragStartX] = React.useState(0);
|
|
7
7
|
const setColumnDelta = React.useCallback((columnDelta) => {
|
|
8
|
-
if (!columnWidths) {
|
|
9
|
-
throw new Error("Missing column widths?");
|
|
10
|
-
}
|
|
11
8
|
const newColumnWidths = columnWidths.map((columnWidth, columnWidthIndex) => {
|
|
12
9
|
if (columnWidthIndex === dragColumnIndex) {
|
|
13
10
|
return Math.max(columnWidth + columnDelta, MINIMUM_COLUMN_WIDTH);
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
// Do not allow oversized tables?
|
|
13
|
+
// if (columnWidthIndex - 1 === dragColumnIndex) {
|
|
14
|
+
// return Math.max(columnWidth - columnDelta, MINIMUM_COLUMN_WIDTH);
|
|
15
|
+
// }
|
|
18
16
|
return columnWidth;
|
|
19
17
|
});
|
|
20
18
|
setColumnWidths(newColumnWidths);
|
|
@@ -35,7 +33,7 @@ const ColumnResizers = ({ columnWidths, setColumnWidths, tableBodyHeight, }) =>
|
|
|
35
33
|
if (columnIndex === dragColumnIndex) {
|
|
36
34
|
classNames.push("schema-table__column_resizer--dragged");
|
|
37
35
|
}
|
|
38
|
-
return
|
|
36
|
+
return (_jsx("div", { style: { left: pointer, bottom: tableBodyHeight }, className: classNames.join(" "), draggable: "true", "data-column-index": columnIndex, onDragStart: onDragStart, onDragEnd: onDragEnd }, columnIndex));
|
|
39
37
|
}) }));
|
|
40
38
|
};
|
|
41
39
|
export default ColumnResizers;
|
|
@@ -23,6 +23,7 @@ import ThMenu from "./ThMenu";
|
|
|
23
23
|
import { saveAs } from "file-saver";
|
|
24
24
|
import { unparse } from "papaparse";
|
|
25
25
|
import ColumnResizers from "./ColumnResizers";
|
|
26
|
+
import { sum } from "lodash";
|
|
26
27
|
const startOfTheWorldDate = new Date("1000-01-01 00:00:00Z");
|
|
27
28
|
const numberFormatter = new Intl.NumberFormat("nl-NL");
|
|
28
29
|
const currencyFormatter = new Intl.NumberFormat("nl-NL", {
|
|
@@ -53,6 +54,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
53
54
|
const [thMenuConfig, setThMenuConfig] = React.useState();
|
|
54
55
|
const isDataFunction = data instanceof Function;
|
|
55
56
|
const [sourceData, setSourceData] = React.useState(isDataFunction ? undefined : data);
|
|
57
|
+
const [columnWidths, setColumnWidths] = React.useState();
|
|
56
58
|
const [locationHash, setLocationHash] = React.useState(useFilterStateHash ? parseLocationHash(window.location.hash) : {});
|
|
57
59
|
const [searchQuery, setSearchQuery] = React.useState(locationHash.searchQuery || "");
|
|
58
60
|
const [columnFilterMap, setColumnFilterMap] = React.useState(locationHash.columnFilterMap || defaultColumnFilters);
|
|
@@ -204,22 +206,30 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
204
206
|
}, 0);
|
|
205
207
|
return { dynamicWidthColumnCount, fixedWidthColumnsWidth };
|
|
206
208
|
}, [columnNames, config]);
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
roundingDifference
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
React.useEffect(() => {
|
|
210
|
+
const dynamicColumnWidth = Math.floor((width - fixedWidthColumnsWidth) / dynamicWidthColumnCount);
|
|
211
|
+
let roundingDifference = (width - fixedWidthColumnsWidth) % dynamicWidthColumnCount;
|
|
212
|
+
setColumnWidths(columnNames.map((propName) => {
|
|
213
|
+
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
214
|
+
return SELECT_ALL_COLUMN_WIDTH;
|
|
215
|
+
}
|
|
216
|
+
const propConfig = config ? config[propName] : undefined;
|
|
217
|
+
if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.width) {
|
|
218
|
+
return propConfig === null || propConfig === void 0 ? void 0 : propConfig.width;
|
|
219
|
+
}
|
|
220
|
+
if (roundingDifference) {
|
|
221
|
+
roundingDifference -= 1;
|
|
222
|
+
return dynamicColumnWidth + 1;
|
|
223
|
+
}
|
|
224
|
+
return dynamicColumnWidth;
|
|
225
|
+
}));
|
|
226
|
+
}, [
|
|
227
|
+
columnNames,
|
|
228
|
+
config,
|
|
229
|
+
dynamicWidthColumnCount,
|
|
230
|
+
fixedWidthColumnsWidth,
|
|
231
|
+
width,
|
|
232
|
+
]);
|
|
223
233
|
const getColumnWidth = React.useCallback((columnIndex) => (columnWidths ? columnWidths[columnIndex] : 1), [columnWidths]);
|
|
224
234
|
const filteredRenderData = React.useMemo(() => {
|
|
225
235
|
if (!renderData ||
|
|
@@ -498,7 +508,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
498
508
|
}
|
|
499
509
|
}, [isDirty, searchQuery, onSearchEnter, refreshData]);
|
|
500
510
|
const getRowHeight = React.useCallback(() => rowHeight, [rowHeight]);
|
|
501
|
-
const rowWidth =
|
|
511
|
+
const rowWidth = React.useMemo(() => sum(columnWidths), [columnWidths]);
|
|
502
512
|
const rowCount = React.useMemo(() => (sortedRenderData ? sortedRenderData.length : 0), [sortedRenderData]);
|
|
503
513
|
const tableBodyHeight = React.useMemo(() => {
|
|
504
514
|
const rowsHeight = rowHeight * rowCount;
|
|
@@ -586,7 +596,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
586
596
|
type: "text/csv;charset=utf-8",
|
|
587
597
|
}), "export.csv");
|
|
588
598
|
}, [sortedRenderData]);
|
|
589
|
-
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] })), _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 }, { children: SchemaTableTd }), `tbody_${tableBodyHeight}_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}_${columnWidths.join(" ")}`)) : (_jsx("div", Object.assign({ style: {
|
|
599
|
+
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 }, { children: SchemaTableTd }), `tbody_${tableBodyHeight}_${rowWidth}_${sortColumn}_${sortAsc}_${searchQuery}_${columnCount}_${columnWidths.join(" ")}`)) : (_jsx("div", Object.assign({ style: {
|
|
590
600
|
width: rowWidth,
|
|
591
601
|
height: Math.max(50, tableBodyHeight),
|
|
592
602
|
border: "1px solid #BBB",
|
|
@@ -595,6 +605,6 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
595
605
|
backgroundColor: "#CCC",
|
|
596
606
|
alignItems: "center",
|
|
597
607
|
justifyContent: "center",
|
|
598
|
-
} }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), isResizable ? (_jsx(ColumnResizers, { columnWidths: columnWidths, setColumnWidths: setColumnWidths, tableBodyHeight: tableBodyHeight })) : null] })), 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] })));
|
|
608
|
+
} }, { children: isDirty ? (_jsx("button", Object.assign({ onClick: refreshData, className: "btn border" }, { children: "Refresh data" }))) : (_jsx("div", { children: "\u231B Loading..." })) }))), isResizable ? (_jsx(ColumnResizers, { columnWidths: columnWidths, setColumnWidths: setColumnWidths, tableBodyHeight: tableBodyHeight })) : null] }))) : null, 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] })));
|
|
599
609
|
}
|
|
600
610
|
export default React.memo(SchemaTable);
|