mig-schema-table 3.0.100 → 3.0.102
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;
|
|
@@ -46,6 +46,7 @@ function getSortByValue(propSchema, propConfig) {
|
|
|
46
46
|
}
|
|
47
47
|
function getIsColumnSortable(isTableSortable, propSchema, propConfig) {
|
|
48
48
|
return !!(isTableSortable &&
|
|
49
|
+
(propConfig === null || propConfig === void 0 ? void 0 : propConfig.isSortable) !== false &&
|
|
49
50
|
(propSchema || (propConfig === null || propConfig === void 0 ? void 0 : propConfig.renderData) || (propConfig === null || propConfig === void 0 ? void 0 : propConfig.sort)));
|
|
50
51
|
}
|
|
51
52
|
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, }) {
|
|
@@ -54,6 +55,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
54
55
|
const [thMenuConfig, setThMenuConfig] = React.useState();
|
|
55
56
|
const isDataFunction = data instanceof Function;
|
|
56
57
|
const [sourceData, setSourceData] = React.useState(isDataFunction ? undefined : data);
|
|
58
|
+
const [columnWidths, setColumnWidths] = React.useState();
|
|
57
59
|
const [locationHash, setLocationHash] = React.useState(useFilterStateHash ? parseLocationHash(window.location.hash) : {});
|
|
58
60
|
const [searchQuery, setSearchQuery] = React.useState(locationHash.searchQuery || "");
|
|
59
61
|
const [columnFilterMap, setColumnFilterMap] = React.useState(locationHash.columnFilterMap || defaultColumnFilters);
|
|
@@ -205,22 +207,30 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
205
207
|
}, 0);
|
|
206
208
|
return { dynamicWidthColumnCount, fixedWidthColumnsWidth };
|
|
207
209
|
}, [columnNames, config]);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
roundingDifference
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
210
|
+
React.useEffect(() => {
|
|
211
|
+
const dynamicColumnWidth = Math.floor((width - fixedWidthColumnsWidth) / dynamicWidthColumnCount);
|
|
212
|
+
let roundingDifference = (width - fixedWidthColumnsWidth) % dynamicWidthColumnCount;
|
|
213
|
+
setColumnWidths(columnNames.map((propName) => {
|
|
214
|
+
if (propName === SELECT_ALL_COLUMN_NAME) {
|
|
215
|
+
return SELECT_ALL_COLUMN_WIDTH;
|
|
216
|
+
}
|
|
217
|
+
const propConfig = config ? config[propName] : undefined;
|
|
218
|
+
if (propConfig === null || propConfig === void 0 ? void 0 : propConfig.width) {
|
|
219
|
+
return propConfig === null || propConfig === void 0 ? void 0 : propConfig.width;
|
|
220
|
+
}
|
|
221
|
+
if (roundingDifference) {
|
|
222
|
+
roundingDifference -= 1;
|
|
223
|
+
return dynamicColumnWidth + 1;
|
|
224
|
+
}
|
|
225
|
+
return dynamicColumnWidth;
|
|
226
|
+
}));
|
|
227
|
+
}, [
|
|
228
|
+
columnNames,
|
|
229
|
+
config,
|
|
230
|
+
dynamicWidthColumnCount,
|
|
231
|
+
fixedWidthColumnsWidth,
|
|
232
|
+
width,
|
|
233
|
+
]);
|
|
224
234
|
const getColumnWidth = React.useCallback((columnIndex) => (columnWidths ? columnWidths[columnIndex] : 1), [columnWidths]);
|
|
225
235
|
const filteredRenderData = React.useMemo(() => {
|
|
226
236
|
if (!renderData ||
|
|
@@ -303,6 +313,10 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
303
313
|
// fall through
|
|
304
314
|
default:
|
|
305
315
|
// fallback by looking at the render value
|
|
316
|
+
if (propSchema === null || propSchema === void 0 ? void 0 : propSchema.enum) {
|
|
317
|
+
result = rawValue === columnFilterValue;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
306
320
|
result = `${item[propName]}`
|
|
307
321
|
.toLowerCase()
|
|
308
322
|
.includes(`${columnFilterValue}`.toLowerCase());
|
|
@@ -587,7 +601,7 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
587
601
|
type: "text/csv;charset=utf-8",
|
|
588
602
|
}), "export.csv");
|
|
589
603
|
}, [sortedRenderData]);
|
|
590
|
-
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: {
|
|
604
|
+
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: {
|
|
591
605
|
width: rowWidth,
|
|
592
606
|
height: Math.max(50, tableBodyHeight),
|
|
593
607
|
border: "1px solid #BBB",
|
|
@@ -596,6 +610,6 @@ function SchemaTable({ Heading = VariableSizeList, checkedIndexes, config, custo
|
|
|
596
610
|
backgroundColor: "#CCC",
|
|
597
611
|
alignItems: "center",
|
|
598
612
|
justifyContent: "center",
|
|
599
|
-
} }, { 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] })));
|
|
613
|
+
} }, { 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] })));
|
|
600
614
|
}
|
|
601
615
|
export default React.memo(SchemaTable);
|
package/dist/types.d.ts
CHANGED