pixelize-design-library 2.2.179 → 2.2.183
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/Components/Table/Components/Pagination.d.ts +2 -3
- package/dist/Components/Table/Components/Pagination.js +9 -11
- package/dist/Components/Table/Components/TableBody.js +63 -58
- package/dist/Components/Table/Components/useTable.d.ts +1 -2
- package/dist/Components/Table/Components/useTable.js +57 -71
- package/dist/Components/Table/Table.js +35 -16
- package/dist/Components/Table/TableProps.d.ts +1 -1
- package/dist/Hooks/usePreferences.js +3 -18
- package/dist/Utils/table.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { TableProps } from "../TableProps";
|
|
3
|
-
type PaginationProps = Pick<TableProps, "isVisiblity" | "columns"> & {
|
|
3
|
+
type PaginationProps = Pick<TableProps, "isVisiblity" | "columns" | "paginationSelectOptions"> & {
|
|
4
4
|
paginationText: string;
|
|
5
5
|
handlePageSizeChange: (event: React.ChangeEvent<HTMLSelectElement>) => void;
|
|
6
6
|
rowsPerPage: number;
|
|
@@ -9,7 +9,6 @@ type PaginationProps = Pick<TableProps, "isVisiblity" | "columns"> & {
|
|
|
9
9
|
setCurrentPage: React.Dispatch<React.SetStateAction<number>>;
|
|
10
10
|
dataLength: number;
|
|
11
11
|
isServerPagination: boolean;
|
|
12
|
-
pageSizeOptions?: (number | string)[];
|
|
13
12
|
};
|
|
14
|
-
declare const Pagination: ({ paginationText, handlePageSizeChange, rowsPerPage, currentPage, pages, setCurrentPage, dataLength, isServerPagination,
|
|
13
|
+
declare const Pagination: ({ paginationText, handlePageSizeChange, rowsPerPage, currentPage, pages, setCurrentPage, dataLength, isServerPagination, paginationSelectOptions, }: PaginationProps) => React.JSX.Element;
|
|
15
14
|
export default Pagination;
|
|
@@ -8,26 +8,24 @@ var react_2 = require("@chakra-ui/react");
|
|
|
8
8
|
var table_1 = require("../../../Utils/table");
|
|
9
9
|
var lucide_react_1 = require("lucide-react");
|
|
10
10
|
var Pagination = function (_a) {
|
|
11
|
-
var paginationText = _a.paginationText, handlePageSizeChange = _a.handlePageSizeChange, rowsPerPage = _a.rowsPerPage, currentPage = _a.currentPage, pages = _a.pages, setCurrentPage = _a.setCurrentPage, dataLength = _a.dataLength, isServerPagination = _a.isServerPagination,
|
|
12
|
-
var computedOptions =
|
|
13
|
-
?
|
|
11
|
+
var paginationText = _a.paginationText, handlePageSizeChange = _a.handlePageSizeChange, rowsPerPage = _a.rowsPerPage, currentPage = _a.currentPage, pages = _a.pages, setCurrentPage = _a.setCurrentPage, dataLength = _a.dataLength, isServerPagination = _a.isServerPagination, paginationSelectOptions = _a.paginationSelectOptions;
|
|
12
|
+
var computedOptions = paginationSelectOptions && paginationSelectOptions.length
|
|
13
|
+
? paginationSelectOptions
|
|
14
14
|
: (0, table_1.pageSizeCalculation)(dataLength);
|
|
15
15
|
// const isLeftDisabled = currentPage === 0;
|
|
16
16
|
// const isRightDisabled = currentPage >= pages - 1;
|
|
17
17
|
var isLeftDisabled = dataLength === 0 || currentPage === 0;
|
|
18
18
|
var isRightDisabled = dataLength === 0 || currentPage >= pages - 1;
|
|
19
|
-
return (react_1.default.createElement(react_2.Flex, { justify: "flex-end", align: "center",
|
|
20
|
-
!isServerPagination && (react_1.default.createElement(react_2.Select, { onChange: handlePageSizeChange, value: rowsPerPage, size: "xs", borderRadius: 3, width: 20, isDisabled: dataLength === 0 },
|
|
21
|
-
!
|
|
22
|
-
computedOptions.map(function (size, index) {
|
|
23
|
-
|
|
24
|
-
}))),
|
|
25
|
-
dataLength > 0 && (react_1.default.createElement(react_2.Flex, null,
|
|
19
|
+
return (react_1.default.createElement(react_2.Flex, { justify: "flex-end", align: "center", flexWrap: "nowrap" },
|
|
20
|
+
(!isServerPagination || paginationSelectOptions) && (react_1.default.createElement(react_2.Select, { onChange: handlePageSizeChange, value: rowsPerPage, size: "xs", borderRadius: 3, width: 20, isDisabled: dataLength === 0 },
|
|
21
|
+
!paginationSelectOptions && dataLength < 100 ? react_1.default.createElement("option", { value: 0 }) : null,
|
|
22
|
+
computedOptions.map(function (size, index) { return (react_1.default.createElement("option", { key: index, value: size }, String(size))); }))),
|
|
23
|
+
dataLength > 0 && (react_1.default.createElement(react_2.Flex, { w: "100%" },
|
|
26
24
|
react_1.default.createElement(react_2.IconButton, { "aria-label": "first-page", color: isLeftDisabled ? "gray" : "black", rounded: "full", variant: isLeftDisabled ? "plain" : "ghost", onClick: function () { return setCurrentPage(0); } },
|
|
27
25
|
react_1.default.createElement(lucide_react_1.ChevronsLeft, null)),
|
|
28
26
|
react_1.default.createElement(react_2.IconButton, { "aria-label": "previous-page", color: isLeftDisabled ? "gray" : "black", rounded: "full", variant: isLeftDisabled ? "plain" : "ghost", onClick: function () { return currentPage > 0 && setCurrentPage(currentPage - 1); } },
|
|
29
27
|
react_1.default.createElement(lucide_react_1.ChevronLeft, null)),
|
|
30
|
-
react_1.default.createElement(react_2.Text, { mt: 3, fontSize: 12 }, paginationText),
|
|
28
|
+
react_1.default.createElement(react_2.Text, { mt: 3, fontSize: 12, whiteSpace: "nowrap" }, paginationText),
|
|
31
29
|
react_1.default.createElement(react_2.IconButton, { "aria-label": "next-page", color: isRightDisabled ? "gray" : "black", rounded: "full", variant: isRightDisabled ? "plain" : "ghost", onClick: function () {
|
|
32
30
|
return currentPage < pages - 1 && setCurrentPage(currentPage + 1);
|
|
33
31
|
} },
|
|
@@ -45,10 +45,10 @@ var TableActions_1 = __importDefault(require("./TableActions"));
|
|
|
45
45
|
var lucide_react_1 = require("lucide-react");
|
|
46
46
|
var Checkbox_1 = __importDefault(require("../../Checkbox/Checkbox"));
|
|
47
47
|
var TableBody = function (_a) {
|
|
48
|
-
var _b, _c, _d;
|
|
48
|
+
var _b, _c, _d, _e, _f;
|
|
49
49
|
var data = _a.data, isCheckbox = _a.isCheckbox, columns = _a.columns, startRow = _a.startRow, columnWidths = _a.columnWidths, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, noBorders = _a.noBorders, handleCheckbox = _a.handleCheckbox, selections = _a.selections, isLoading = _a.isLoading, onRowClick = _a.onRowClick, isContent = _a.isContent, isLink = _a.isLink, isActionFreeze = _a.isActionFreeze, loadingSkeletonRows = _a.loadingSkeletonRows;
|
|
50
50
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
51
|
-
var
|
|
51
|
+
var _g = (0, react_2.useState)(new Set()), expandedRows = _g[0], setExpandedRows = _g[1];
|
|
52
52
|
var toggleRowExpansion = function (rowIndex) {
|
|
53
53
|
setExpandedRows(function (prev) {
|
|
54
54
|
var newSet = new Set(prev);
|
|
@@ -84,68 +84,73 @@ var TableBody = function (_a) {
|
|
|
84
84
|
(isCheckbox ? 1 : 0) +
|
|
85
85
|
(isContent ? 1 : 0) +
|
|
86
86
|
(isLink ? 1 : 0);
|
|
87
|
-
if (isLoading) {
|
|
87
|
+
if (isLoading && data.length === 0) {
|
|
88
88
|
return (react_2.default.createElement(TableLoading_1.TableBodyLoading, { noOfColumns: totalVisibleColumns, borderColor: theme.colors.gray[300], rowsCount: typeof loadingSkeletonRows === "number" ? loadingSkeletonRows : 4 }));
|
|
89
89
|
}
|
|
90
|
-
if (data.length === 0) {
|
|
90
|
+
if (!isLoading && data.length === 0) {
|
|
91
91
|
return (react_2.default.createElement(react_1.Tr, { backgroundColor: (_b = theme.colors.background) === null || _b === void 0 ? void 0 : _b[50] },
|
|
92
92
|
react_2.default.createElement(react_1.Td, { colSpan: totalVisibleColumns, textAlign: "center", py: 4 },
|
|
93
93
|
react_2.default.createElement(react_1.Box, { textAlign: "center", fontSize: 14, color: (_d = (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d[500] },
|
|
94
94
|
react_2.default.createElement("p", null, "No data found")))));
|
|
95
95
|
}
|
|
96
|
-
return (react_2.default.createElement(react_2.default.Fragment, null,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
96
|
+
return (react_2.default.createElement(react_2.default.Fragment, null,
|
|
97
|
+
isLoading && data.length > 0 && (react_2.default.createElement(react_1.Tr, null,
|
|
98
|
+
react_2.default.createElement(react_1.Td, { colSpan: totalVisibleColumns, p: 0, border: "none", position: "relative", height: 0 },
|
|
99
|
+
react_2.default.createElement(react_1.Box, { position: "absolute", top: 4, left: "50%", transform: "translateX(-50%)", zIndex: 10 },
|
|
100
|
+
react_2.default.createElement(react_1.Spinner, { size: "sm", color: ((_f = (_e = theme.colors) === null || _e === void 0 ? void 0 : _e.primary) === null || _f === void 0 ? void 0 : _f[500]) || "blue.500" }))))),
|
|
101
|
+
data.map(function (row, index) {
|
|
102
|
+
var rowIndex = startRow + index;
|
|
103
|
+
var isExpanded = expandedRows.has(rowIndex);
|
|
104
|
+
var isChecked = selections.includes(row.id);
|
|
105
|
+
return (react_2.default.createElement(react_2.default.Fragment, { key: rowIndex },
|
|
106
|
+
react_2.default.createElement(react_1.Tr, { key: index + 1, opacity: isLoading ? 0.4 : 1, pointerEvents: isLoading ? "none" : "auto", transition: "opacity 0.2s", sx: isChecked
|
|
107
|
+
? {
|
|
108
|
+
"& td": {
|
|
109
|
+
backgroundColor: theme.colors.disabled[100],
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
: {} },
|
|
113
|
+
isContent && (react_2.default.createElement(RenderContent, { rowIndex: rowIndex, isExpanded: isExpanded, isContent: !!(row === null || row === void 0 ? void 0 : row.content) })),
|
|
114
|
+
isCheckbox && react_2.default.createElement(RenderCheckbox, { row: row, isChecked: isChecked }),
|
|
115
|
+
columns.map(function (header, headerIndex) {
|
|
116
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
117
|
+
if (header.isHidden)
|
|
118
|
+
return null;
|
|
119
|
+
var isFrozen = header.isFreeze;
|
|
120
|
+
var leftOffset = (0, table_1.TableCellCalculation)({
|
|
121
|
+
isFrozen: isFrozen,
|
|
122
|
+
columnWidths: columnWidths,
|
|
123
|
+
headerIndex: headerIndex,
|
|
124
|
+
isCheckbox: isCheckbox,
|
|
125
|
+
header: header,
|
|
126
|
+
row: row,
|
|
127
|
+
freezedBgColor: freezedBgColor,
|
|
128
|
+
index: index,
|
|
129
|
+
theme: theme,
|
|
130
|
+
}).leftOffset;
|
|
131
|
+
return (react_2.default.createElement(react_1.Td, { maxWidth: 500, minWidth: 120, height: 45, key: headerIndex + 1, onClick: function () {
|
|
132
|
+
return !header.node
|
|
133
|
+
? handleRowClick(row, {
|
|
134
|
+
label: header.label,
|
|
135
|
+
id: header.id,
|
|
136
|
+
})
|
|
137
|
+
: null;
|
|
138
|
+
}, fontSize: 14, fontWeight: 400, position: isFrozen ? "sticky" : undefined, left: isFrozen ? leftOffset : undefined, zIndex: isFrozen ? 1 : 0, backgroundColor: (_a = theme.colors.background) === null || _a === void 0 ? void 0 : _a[50], textOverflow: "ellipsis", borderBottom: noBorders
|
|
139
|
+
? "none"
|
|
140
|
+
: "0.063rem solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[isFrozen || isChecked ? 300 : 200]), className: "columns ".concat(isFrozen ? "sticky-columns" : "scrollable-columns"), boxSizing: "border-box", color: (_d = (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d[500], _hover: ((_e = row.cellStyle) === null || _e === void 0 ? void 0 : _e[header.id]) || row.rowStyle
|
|
141
|
+
? {}
|
|
142
|
+
: {
|
|
143
|
+
backgroundColor: (_g = (_f = theme.colors.secondary) === null || _f === void 0 ? void 0 : _f.opacity) === null || _g === void 0 ? void 0 : _g[4],
|
|
144
|
+
} },
|
|
145
|
+
react_2.default.createElement(react_1.Box, { display: "block", overflow: "hidden", whiteSpace: "normal", overflowWrap: "break-word" }, (0, table_1.normalizeTableCellValue)(header.node ? header.node(row) : row[header.id]))));
|
|
146
|
+
}),
|
|
147
|
+
isLink && react_2.default.createElement(RenderView, { row: row })),
|
|
148
|
+
row.content && isExpanded && (react_2.default.createElement(react_1.Tr, null,
|
|
149
|
+
react_2.default.createElement(react_1.Td, { colSpan: columns.length +
|
|
150
|
+
(isCheckbox ? 1 : 0) +
|
|
151
|
+
(isContent ? 1 : 0) +
|
|
152
|
+
(isLink ? 1 : 0), p: 2 },
|
|
153
|
+
react_2.default.createElement(react_1.Box, { p: 2, bg: theme.colors.white, borderRadius: "md" }, row === null || row === void 0 ? void 0 : row.content(row)))))));
|
|
154
|
+
})));
|
|
150
155
|
};
|
|
151
156
|
exports.default = TableBody;
|
|
@@ -40,7 +40,6 @@ declare const useTable: ({ tableBorderColor, data, isPagination, selections, onS
|
|
|
40
40
|
rowsPerPage: number;
|
|
41
41
|
setCurrentPage: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
42
42
|
columnsList: TableHeaderProps[];
|
|
43
|
-
handleColumnPreferences: (
|
|
44
|
-
handleGlobalSearch: (query: string) => void;
|
|
43
|
+
handleColumnPreferences: (columns: any) => void;
|
|
45
44
|
};
|
|
46
45
|
export default useTable;
|
|
@@ -23,7 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
var react_1 = require("react");
|
|
24
24
|
var useCustomTheme_1 = require("../../../Theme/useCustomTheme");
|
|
25
25
|
var table_1 = require("../../../Utils/table");
|
|
26
|
-
var defaultPageSize =
|
|
26
|
+
var defaultPageSize = 20;
|
|
27
27
|
var mergeColumnWithPreference = function (pref, originalCol) {
|
|
28
28
|
if (!pref || typeof pref !== "object") {
|
|
29
29
|
return __assign({}, originalCol);
|
|
@@ -46,18 +46,17 @@ var useTable = function (_a) {
|
|
|
46
46
|
var _d = (0, react_1.useState)([]), columnsSort = _d[0], setColumnsSort = _d[1];
|
|
47
47
|
var _e = (0, react_1.useState)(0), currentPage = _e[0], setCurrentPage = _e[1];
|
|
48
48
|
var _f = (0, react_1.useState)(noOfRowsPerPage !== null && noOfRowsPerPage !== void 0 ? noOfRowsPerPage : defaultPageSize), rowsPerPage = _f[0], setRowsPerPage = _f[1];
|
|
49
|
+
var prevRowsPerPageProp = (0, react_1.useRef)(noOfRowsPerPage);
|
|
50
|
+
if (noOfRowsPerPage !== prevRowsPerPageProp.current) {
|
|
51
|
+
prevRowsPerPageProp.current = noOfRowsPerPage;
|
|
52
|
+
if (noOfRowsPerPage !== undefined && noOfRowsPerPage !== rowsPerPage) {
|
|
53
|
+
setRowsPerPage(noOfRowsPerPage);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
var tableData = data;
|
|
49
57
|
var _g = (0, react_1.useState)(function () {
|
|
50
58
|
return columns.map(function (col) { return (__assign({}, col)); });
|
|
51
59
|
}), columnsList = _g[0], setColumnsList = _g[1];
|
|
52
|
-
// Stable refs for callbacks that shouldn't appear in deps
|
|
53
|
-
var onSelectionRef = (0, react_1.useRef)(onSelection);
|
|
54
|
-
onSelectionRef.current = onSelection;
|
|
55
|
-
var dataRef = (0, react_1.useRef)(data);
|
|
56
|
-
dataRef.current = data;
|
|
57
|
-
var tablePreferencesRef = (0, react_1.useRef)(tablePreferences);
|
|
58
|
-
tablePreferencesRef.current = tablePreferences;
|
|
59
|
-
var savePreferencesRef = (0, react_1.useRef)(savePreferences);
|
|
60
|
-
savePreferencesRef.current = savePreferences;
|
|
61
60
|
(0, react_1.useEffect)(function () {
|
|
62
61
|
var _a;
|
|
63
62
|
var columnPreference = (_a = tablePreferences === null || tablePreferences === void 0 ? void 0 : tablePreferences.columns) !== null && _a !== void 0 ? _a : [];
|
|
@@ -85,99 +84,87 @@ var useTable = function (_a) {
|
|
|
85
84
|
overflowY: "auto",
|
|
86
85
|
});
|
|
87
86
|
}, [tableBorderColor, theme]);
|
|
88
|
-
var isContent = (0, react_1.useMemo)(function () { return
|
|
89
|
-
var isLink = (0, react_1.useMemo)(function () { return
|
|
87
|
+
var isContent = (0, react_1.useMemo)(function () { return tableData.some(function (o) { return o.content; }); }, [tableData]);
|
|
88
|
+
var isLink = (0, react_1.useMemo)(function () { return tableData.some(function (o) { return o.onLink || o.onDelete || o.onEdit; }); }, [tableData]);
|
|
90
89
|
(0, react_1.useEffect)(function () {
|
|
91
90
|
var widths = headerRefs.current.map(function (ref) { return (ref === null || ref === void 0 ? void 0 : ref.offsetWidth) || 0; });
|
|
92
91
|
setColumnWidths(widths);
|
|
93
92
|
}, []);
|
|
94
93
|
var pages = (0, react_1.useMemo)(function () {
|
|
95
94
|
if (isServerPagination) {
|
|
96
|
-
return Math.ceil(totalRecords / (
|
|
95
|
+
return Math.ceil(totalRecords / (rowsPerPage || 1));
|
|
97
96
|
}
|
|
98
|
-
return isPagination ? Math.ceil(
|
|
97
|
+
return isPagination ? Math.ceil(tableData.length / rowsPerPage) : 0;
|
|
99
98
|
}, [
|
|
100
99
|
isPagination,
|
|
101
100
|
rowsPerPage,
|
|
102
|
-
|
|
101
|
+
tableData.length,
|
|
103
102
|
totalRecords,
|
|
104
103
|
isServerPagination,
|
|
105
|
-
noOfRowsPerPage,
|
|
106
104
|
]);
|
|
107
105
|
var startRow = (0, react_1.useMemo)(function () { return (!isPagination ? 0 : currentPage * rowsPerPage); }, [currentPage, isPagination, rowsPerPage]);
|
|
108
|
-
var endRow = (0, react_1.useMemo)(function () { return (!isPagination ?
|
|
109
|
-
// Sort once (only re-runs when data or sort config changes, not on page change)
|
|
110
|
-
var sortedData = (0, react_1.useMemo)(function () {
|
|
111
|
-
if (isServerPagination)
|
|
112
|
-
return data;
|
|
113
|
-
return (0, table_1.SortMultiColumnData)(data, columnsSort);
|
|
114
|
-
}, [data, columnsSort, isServerPagination]);
|
|
115
|
-
// Paginate from the already-sorted data
|
|
106
|
+
var endRow = (0, react_1.useMemo)(function () { return (!isPagination ? tableData.length : startRow + rowsPerPage); }, [isPagination, rowsPerPage, startRow, tableData.length]);
|
|
116
107
|
var filteredData = (0, react_1.useMemo)(function () {
|
|
117
|
-
if (isServerPagination)
|
|
118
|
-
return
|
|
108
|
+
if (isServerPagination) {
|
|
109
|
+
return tableData;
|
|
110
|
+
}
|
|
111
|
+
var sortedData = (0, table_1.SortMultiColumnData)(tableData, columnsSort);
|
|
119
112
|
return sortedData.slice(startRow, endRow);
|
|
120
|
-
}, [
|
|
121
|
-
var handlePageSizeChange =
|
|
113
|
+
}, [columnsSort, startRow, endRow, tableData, isServerPagination]);
|
|
114
|
+
var handlePageSizeChange = function (event) {
|
|
122
115
|
var value = Number(event.target.value);
|
|
123
116
|
setRowsPerPage(value !== 0 ? value : defaultPageSize);
|
|
124
117
|
if (onNoOfRowsPerPageChange) {
|
|
125
118
|
onNoOfRowsPerPageChange(value !== 0 ? value : defaultPageSize);
|
|
126
119
|
}
|
|
127
120
|
setCurrentPage(0);
|
|
128
|
-
}
|
|
129
|
-
// Stable: uses functional updater so columnsSort is not a dependency
|
|
121
|
+
};
|
|
130
122
|
var handleSort = (0, react_1.useCallback)(function (field, sort) {
|
|
131
123
|
if (!sort)
|
|
132
124
|
return;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
125
|
+
var newSortState = __spreadArray([], columnsSort, true);
|
|
126
|
+
var existingIndex = newSortState.findIndex(function (sort) { return sort.column === field; });
|
|
127
|
+
if (existingIndex === -1) {
|
|
128
|
+
newSortState.push({
|
|
129
|
+
column: field,
|
|
130
|
+
direction: "asc", // Default to ascending when adding a column
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
var existingSort = newSortState[existingIndex];
|
|
135
|
+
existingSort.direction = sort;
|
|
136
|
+
}
|
|
137
|
+
setColumnsSort(newSortState);
|
|
138
|
+
}, [columnsSort]);
|
|
145
139
|
(0, react_1.useEffect)(function () {
|
|
146
140
|
setSelection(selections !== null && selections !== void 0 ? selections : []);
|
|
147
141
|
}, [selections]);
|
|
148
|
-
// Stable: uses functional updater + refs so selection/data are not dependencies
|
|
149
142
|
var handleCheckbox = (0, react_1.useCallback)(function (id) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (id === 0) {
|
|
155
|
-
selectedItems =
|
|
156
|
-
prev.length === currentData.length
|
|
157
|
-
? []
|
|
158
|
-
: currentData.map(function (item) { return item.id; });
|
|
159
|
-
}
|
|
160
|
-
else if (prev.includes(id)) {
|
|
161
|
-
selectedItems = prev.filter(function (item) { return item !== id; });
|
|
143
|
+
var selectedItems = [];
|
|
144
|
+
if (id === 0) {
|
|
145
|
+
if (selection.length === tableData.length) {
|
|
146
|
+
selectedItems = [];
|
|
162
147
|
}
|
|
163
148
|
else {
|
|
164
|
-
selectedItems =
|
|
149
|
+
selectedItems = tableData.map(function (item) { return item.id; });
|
|
165
150
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
151
|
+
}
|
|
152
|
+
else if (selection.includes(id)) {
|
|
153
|
+
selectedItems = selection.filter(function (item) { return item !== id; });
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
selectedItems = __spreadArray(__spreadArray([], selection, true), [id], false);
|
|
157
|
+
}
|
|
158
|
+
setSelection(selectedItems);
|
|
159
|
+
onSelection && onSelection(selectedItems);
|
|
160
|
+
}, [onSelection, selection, tableData]);
|
|
161
|
+
var handleColumnPreferences = function (columns) {
|
|
162
|
+
setColumnsList(columns);
|
|
163
|
+
savePreferences &&
|
|
164
|
+
savePreferences(__assign(__assign({}, tablePreferences), { columns: columns }));
|
|
165
|
+
};
|
|
179
166
|
return {
|
|
180
|
-
tableData:
|
|
167
|
+
tableData: tableData,
|
|
181
168
|
tableContainerStyles: tableContainerStyles,
|
|
182
169
|
isContent: isContent,
|
|
183
170
|
isLink: isLink,
|
|
@@ -197,7 +184,6 @@ var useTable = function (_a) {
|
|
|
197
184
|
setCurrentPage: setCurrentPage,
|
|
198
185
|
columnsList: columnsList,
|
|
199
186
|
handleColumnPreferences: handleColumnPreferences,
|
|
200
|
-
handleGlobalSearch: handleGlobalSearch,
|
|
201
187
|
};
|
|
202
188
|
};
|
|
203
189
|
exports.default = useTable;
|
|
@@ -56,17 +56,16 @@ var TableSearch_1 = __importDefault(require("./Components/TableSearch"));
|
|
|
56
56
|
var ActiveFilters_1 = __importDefault(require("./Components/ActiveFilters"));
|
|
57
57
|
var lucide_react_1 = require("lucide-react");
|
|
58
58
|
var MotionBox = (0, framer_motion_1.motion)(react_2.Box);
|
|
59
|
-
var DEFAULT_PREFERENCES = {
|
|
60
|
-
url: "",
|
|
61
|
-
token: "",
|
|
62
|
-
key: "",
|
|
63
|
-
name: "",
|
|
64
|
-
page: "",
|
|
65
|
-
orgId: "",
|
|
66
|
-
};
|
|
67
59
|
function Table(_a) {
|
|
68
60
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
69
|
-
var data = _a.data, columns = _a.columns, onSelection = _a.onSelection, isLoading = _a.isLoading, _0 = _a.isCheckbox, isCheckbox = _0 === void 0 ? false : _0, headerBgColor = _a.headerBgColor, freezedBgColor = _a.freezedBgColor, headerTextColor = _a.headerTextColor, freezedTextColor = _a.freezedTextColor, tableBorderColor = _a.tableBorderColor, _1 = _a.noBorders, noBorders = _1 === void 0 ? false : _1, _2 = _a.isPagination, isPagination = _2 === void 0 ? true : _2, onRowClick = _a.onRowClick, selections = _a.selections, _3 = _a.isActionFreeze, isActionFreeze = _3 === void 0 ? true : _3, _4 = _a.preferences, preferences = _4 === void 0 ?
|
|
61
|
+
var data = _a.data, columns = _a.columns, onSelection = _a.onSelection, isLoading = _a.isLoading, _0 = _a.isCheckbox, isCheckbox = _0 === void 0 ? false : _0, headerBgColor = _a.headerBgColor, freezedBgColor = _a.freezedBgColor, headerTextColor = _a.headerTextColor, freezedTextColor = _a.freezedTextColor, tableBorderColor = _a.tableBorderColor, _1 = _a.noBorders, noBorders = _1 === void 0 ? false : _1, _2 = _a.isPagination, isPagination = _2 === void 0 ? true : _2, onRowClick = _a.onRowClick, selections = _a.selections, _3 = _a.isActionFreeze, isActionFreeze = _3 === void 0 ? true : _3, _4 = _a.preferences, preferences = _4 === void 0 ? {
|
|
62
|
+
url: "",
|
|
63
|
+
token: "",
|
|
64
|
+
key: "",
|
|
65
|
+
name: "",
|
|
66
|
+
page: "",
|
|
67
|
+
orgId: "",
|
|
68
|
+
} : _4, _5 = _a.paginationMode, paginationMode = _5 === void 0 ? "client" : _5, _6 = _a.noOfRowsPerPage, noOfRowsPerPage = _6 === void 0 ? 50 : _6, _7 = _a.totalRecords, totalRecords = _7 === void 0 ? 0 : _7, onPagination = _a.onPagination, _8 = _a.isTableSettings, isTableSettings = _8 === void 0 ? false : _8, headerActions = _a.headerActions, onGlobalSearch = _a.onGlobalSearch, onNoOfRowsPerPageChange = _a.onNoOfRowsPerPageChange, paginationSelectOptions = _a.paginationSelectOptions, tableMaxHeight = _a.tableMaxHeight, minVisibleRows = _a.minVisibleRows, maxVisibleRows = _a.maxVisibleRows, autoFitViewport = _a.autoFitViewport, tableSettings = _a.tableSettings, filterSidebar = _a.filterSidebar, loadingSkeletonRows = _a.loadingSkeletonRows
|
|
70
69
|
// onColumnFilter
|
|
71
70
|
;
|
|
72
71
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
@@ -120,10 +119,30 @@ function Table(_a) {
|
|
|
120
119
|
}, [columnsSearch, filteredData]);
|
|
121
120
|
var onPaginationRef = (0, react_1.useRef)(onPagination);
|
|
122
121
|
onPaginationRef.current = onPagination;
|
|
122
|
+
var prevPageRef = (0, react_1.useRef)(currentPage);
|
|
123
123
|
(0, react_1.useEffect)(function () {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
if (onPaginationRef.current) {
|
|
125
|
+
var prevPage = prevPageRef.current;
|
|
126
|
+
var direction = void 0;
|
|
127
|
+
if (currentPage === 0) {
|
|
128
|
+
direction = "first";
|
|
129
|
+
}
|
|
130
|
+
else if (currentPage === pages - 1) {
|
|
131
|
+
direction = "last";
|
|
132
|
+
}
|
|
133
|
+
else if (currentPage > prevPage) {
|
|
134
|
+
direction = "next";
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
direction = "prev";
|
|
138
|
+
}
|
|
139
|
+
var record = direction === "next" || direction === "last"
|
|
140
|
+
? (tableData.length > 0 ? tableData[tableData.length - 1] : undefined)
|
|
141
|
+
: (tableData.length > 0 ? tableData[0] : undefined);
|
|
142
|
+
onPaginationRef.current(currentPage + 1, rowsPerPage, record, direction);
|
|
143
|
+
prevPageRef.current = currentPage;
|
|
144
|
+
}
|
|
145
|
+
}, [currentPage, rowsPerPage]);
|
|
127
146
|
var tablePaginationText = "".concat(startRow + 1, " - ").concat(endRow > tableData.length ? tableData.length : endRow, " of ").concat(isServerPagination ? totalRecords : tableData.length);
|
|
128
147
|
var controlsHeight = 45;
|
|
129
148
|
var estimatedRowHeight = 45;
|
|
@@ -204,14 +223,14 @@ function Table(_a) {
|
|
|
204
223
|
react_1.default.createElement(HeaderActions_1.default, { actions: headerActions, selections: selection }))) : null,
|
|
205
224
|
react_1.default.createElement(ActiveFilters_1.default, { columns: columnsList, columnsSearch: columnsSearch, setColumnsSearch: setColumnsSearch }),
|
|
206
225
|
react_1.default.createElement(react_2.Box, { ml: "auto", display: "flex", alignItems: "center", gap: 2 },
|
|
207
|
-
(isPagination || isServerPagination) && !isCompactHeader && (react_1.default.createElement(react_2.Box, { flex: "0
|
|
208
|
-
react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: tablePaginationText, handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, isServerPagination: isServerPagination,
|
|
226
|
+
(isPagination || isServerPagination) && !isCompactHeader && (react_1.default.createElement(react_2.Box, { flex: "0 0 auto" },
|
|
227
|
+
react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: tablePaginationText, handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, isServerPagination: isServerPagination, paginationSelectOptions: paginationSelectOptions, isVisiblity: true }))),
|
|
209
228
|
(isPagination || isServerPagination) && isCompactHeader && tableData.length > 0 && (react_1.default.createElement(react_2.Popover, { placement: "bottom-end" },
|
|
210
229
|
react_1.default.createElement(react_2.PopoverTrigger, null,
|
|
211
230
|
react_1.default.createElement(react_2.IconButton, { "aria-label": "More", size: "sm", variant: "ghost", icon: react_1.default.createElement(lucide_react_1.EllipsisVertical, { size: 18, color: (_w = (_v = theme.colors) === null || _v === void 0 ? void 0 : _v.text) === null || _w === void 0 ? void 0 : _w[500] }) })),
|
|
212
|
-
react_1.default.createElement(react_2.PopoverContent, { maxW: "
|
|
231
|
+
react_1.default.createElement(react_2.PopoverContent, { maxW: "22rem", p: 2, overflow: "hidden" },
|
|
213
232
|
react_1.default.createElement(react_2.PopoverBody, { p: 0 },
|
|
214
|
-
react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: tablePaginationText, handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, isServerPagination: isServerPagination,
|
|
233
|
+
react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: tablePaginationText, handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, isServerPagination: isServerPagination, paginationSelectOptions: paginationSelectOptions, isVisiblity: true }))))))),
|
|
215
234
|
react_1.default.createElement(react_2.TableContainer, { ref: tableContainerRef, position: "relative", h: isTableLoading ? tableMaxH : undefined, maxH: !isTableLoading ? tableMaxH : undefined, pb: isTableLoading ? 0 : compactScrollbarPadding, overflowY: isCompactRows ? "hidden" : "auto", overflowX: "auto", sx: {
|
|
216
235
|
'&::-webkit-scrollbar': {
|
|
217
236
|
width: '6px',
|
|
@@ -23,7 +23,7 @@ export type TableProps = {
|
|
|
23
23
|
paginationMode?: "client" | "server";
|
|
24
24
|
noOfRowsPerPage?: number;
|
|
25
25
|
totalRecords?: number;
|
|
26
|
-
onPagination?: (page: number, noOfRecords: number) => void;
|
|
26
|
+
onPagination?: (page: number, noOfRecords: number, record: DataObject | undefined, direction: "next" | "prev" | "first" | "last") => void;
|
|
27
27
|
onNoOfRowsPerPageChange?: (noOfRows: number) => void;
|
|
28
28
|
paginationSelectOptions?: (number | string)[];
|
|
29
29
|
tableMaxHeight?: number;
|
|
@@ -28,32 +28,17 @@ var useGetPreferences = function (_a) {
|
|
|
28
28
|
if (!baseUrl) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
var controller = new AbortController();
|
|
32
31
|
setLoading(true);
|
|
33
32
|
var url = constructUrl({ baseUrl: baseUrl, key: key, page: page, name: name, orgId: orgId });
|
|
34
33
|
fetch(url, {
|
|
35
34
|
headers: {
|
|
36
35
|
Authorization: authToken,
|
|
37
36
|
},
|
|
38
|
-
signal: controller.signal,
|
|
39
37
|
})
|
|
40
38
|
.then(function (response) { return response.json(); })
|
|
41
|
-
.then(function (data) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
.catch(function (error) {
|
|
47
|
-
if (!controller.signal.aborted) {
|
|
48
|
-
console.error(error);
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
.finally(function () {
|
|
52
|
-
if (!controller.signal.aborted) {
|
|
53
|
-
setLoading(false);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
return function () { return controller.abort(); };
|
|
39
|
+
.then(function (data) { return setPreferences(data); })
|
|
40
|
+
.catch(function (error) { return console.error(error); })
|
|
41
|
+
.finally(function () { return setLoading(false); });
|
|
57
42
|
/* eslint-disable */
|
|
58
43
|
}, [baseUrl]);
|
|
59
44
|
return { preferences: preferences, loading: loading };
|
package/dist/Utils/table.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ type TableCellCalculationProps = {
|
|
|
23
23
|
row: DataObject;
|
|
24
24
|
freezedBgColor?: string;
|
|
25
25
|
index: number;
|
|
26
|
-
theme:
|
|
26
|
+
theme: any;
|
|
27
27
|
};
|
|
28
28
|
export declare const TableCellCalculation: ({ isFrozen, columnWidths, headerIndex, isCheckbox, header, row, freezedBgColor, index, theme, }: TableCellCalculationProps) => {
|
|
29
29
|
leftOffset: number;
|