ar-design 0.2.22 → 0.2.24
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.
|
@@ -4,7 +4,7 @@ import { ARIcon } from "../../icons";
|
|
|
4
4
|
import Button from "../../form/button";
|
|
5
5
|
import Checkbox from "../../form/checkbox";
|
|
6
6
|
import Pagination from "../../navigation/pagination";
|
|
7
|
-
import React, { forwardRef, memo, useCallback, useEffect, useRef, useState } from "react";
|
|
7
|
+
import React, { forwardRef, memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
8
|
import Input from "../../form/input";
|
|
9
9
|
import Popover from "../../feedback/popover";
|
|
10
10
|
const Table = forwardRef(({ children, title, description, data, columns, actions, selections, previousSelections, searchedParams, pagination, config = { isSearchable: false }, }, ref) => {
|
|
@@ -26,6 +26,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
|
|
|
26
26
|
const [_searchedParams, setSearchedParams] = useState(undefined);
|
|
27
27
|
const [checkboxSelectedParams, setCheckboxSelectedParams] = useState(undefined);
|
|
28
28
|
// states -> Pagination
|
|
29
|
+
const [totalRecords, setTotalRecords] = useState(0);
|
|
29
30
|
const [currentPage, setCurrentPage] = useState(1);
|
|
30
31
|
if (config && Object.keys(config.scroll || {}).length > 0) {
|
|
31
32
|
if (_tableContent.current && config.scroll) {
|
|
@@ -104,12 +105,10 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
|
|
|
104
105
|
clearTimeout(_searchTimeOut.current);
|
|
105
106
|
_searchTimeOut.current = setTimeout(() => {
|
|
106
107
|
setSearchedParams((prev) => ({ ...prev, [event.target.name]: event.target.value }));
|
|
107
|
-
setCurrentPage(1);
|
|
108
108
|
pagination && pagination.onChange(1);
|
|
109
109
|
}, 750);
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
|
-
setCurrentPage(1);
|
|
113
112
|
setSearchedText((prev) => ({ ...prev, [event.target.name]: event.target.value }));
|
|
114
113
|
}
|
|
115
114
|
};
|
|
@@ -158,10 +157,16 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
|
|
|
158
157
|
return false;
|
|
159
158
|
});
|
|
160
159
|
};
|
|
161
|
-
const getData =
|
|
160
|
+
const getData = useMemo(() => {
|
|
162
161
|
let _data = [...data];
|
|
163
|
-
if (searchedText)
|
|
162
|
+
if (searchedText) {
|
|
164
163
|
_data = _data.filter((item) => deepSearch(item, searchedText));
|
|
164
|
+
setTotalRecords(_data.length);
|
|
165
|
+
setCurrentPage(1);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
setTotalRecords(data.length);
|
|
169
|
+
}
|
|
165
170
|
if (pagination && !config.isServerSide) {
|
|
166
171
|
const indexOfLastRow = currentPage * pagination.perPage;
|
|
167
172
|
const indexOfFirstRow = indexOfLastRow - pagination.perPage;
|
|
@@ -215,7 +220,10 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
|
|
|
215
220
|
React.createElement("div", { className: "title" },
|
|
216
221
|
React.createElement("h3", null, title),
|
|
217
222
|
React.createElement("h5", null, description)),
|
|
218
|
-
React.createElement("div", null
|
|
223
|
+
React.createElement("div", { className: "actions" }, actions && (React.createElement(React.Fragment, null,
|
|
224
|
+
actions.create && (React.createElement(Button, { variant: "outlined", status: "dark", icon: { element: React.createElement(ARIcon, { icon: "Add", size: 16 }) }, tooltip: { text: actions.create.tooltip, direction: "top" }, onClick: actions.create.onClick })),
|
|
225
|
+
actions.import && (React.createElement(Button, { variant: "outlined", status: "dark", icon: { element: React.createElement(ARIcon, { icon: "Import", size: 16 }) }, tooltip: { text: actions.import.tooltip, direction: "top" }, onClick: actions.import.onClick })),
|
|
226
|
+
actions.filterClear && (React.createElement(Button, { variant: "outlined", status: "dark", icon: { element: React.createElement(ARIcon, { icon: "Trash", size: 16 }) }, tooltip: { text: actions.filterClear.tooltip, direction: "top" }, onClick: actions.filterClear.onClick }))))))),
|
|
219
227
|
React.createElement("div", { ref: _tableContent, className: "content", onScroll: handleScroll },
|
|
220
228
|
React.createElement("table", { ref: ref },
|
|
221
229
|
React.createElement("thead", null,
|
|
@@ -274,7 +282,7 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
|
|
|
274
282
|
})), windowBlur: true },
|
|
275
283
|
React.createElement(Button, { variant: "borderless", icon: { element: React.createElement(ARIcon, { icon: "Filter", stroke: "var(--primary)", size: 16 }) } })))))));
|
|
276
284
|
})))),
|
|
277
|
-
React.createElement("tbody", null, getData
|
|
285
|
+
React.createElement("tbody", null, getData.map((item, index) => (React.createElement("tr", { key: `row-${index}-${Math.random()}` },
|
|
278
286
|
selections && (React.createElement("td", { key: `selection-${index}`, className: "sticky-left", "data-sticky-position": "left" },
|
|
279
287
|
React.createElement(Checkbox, { ref: (element) => (_checkboxItems.current[index] = element), status: "primary", checked: selectionItems.some((selectionItem) => JSON.stringify(selectionItem) === JSON.stringify(item)), onChange: (event) => {
|
|
280
288
|
if (event.target.checked)
|
|
@@ -325,13 +333,13 @@ const Table = forwardRef(({ children, title, description, data, columns, actions
|
|
|
325
333
|
React.createElement("span", null,
|
|
326
334
|
React.createElement("strong", null,
|
|
327
335
|
"Showing ",
|
|
328
|
-
getData
|
|
336
|
+
getData.length),
|
|
329
337
|
" ",
|
|
330
338
|
React.createElement("span", null,
|
|
331
339
|
"of ",
|
|
332
|
-
pagination?.perPage ?? getData
|
|
340
|
+
pagination?.perPage ?? getData.length,
|
|
333
341
|
" agreement")),
|
|
334
|
-
React.createElement(Pagination, { totalRecords: pagination.totalRecords, currentPage: currentPage, perPage: pagination.perPage, onChange: (currentPage) => {
|
|
342
|
+
React.createElement(Pagination, { totalRecords: config.isServerSide ? pagination.totalRecords : totalRecords ?? 0, currentPage: currentPage, perPage: pagination.perPage, onChange: (currentPage) => {
|
|
335
343
|
config.isServerSide && pagination.onChange(currentPage);
|
|
336
344
|
setCurrentPage(currentPage);
|
|
337
345
|
} })))));
|