mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-05-05 09:40:54 +02:00
Compare commits
No commits in common. "7197813cc90795704f3bfbd784a945c321e4eecc" and "2f249ce3dcff7fceeedc625c968e84020931bb27" have entirely different histories.
7197813cc9
...
2f249ce3dc
@ -8,12 +8,6 @@ and this project adheres to
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [6.6.1] - 2025-02-17
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- Refactored RichTable component to use forwardRef
|
|
||||||
|
|
||||||
## [6.6.0] - 2025-02-07
|
## [6.6.0] - 2025-02-07
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@ -441,8 +435,7 @@ and this project adheres to
|
|||||||
## [0.0.7] - 2019-09-02
|
## [0.0.7] - 2019-09-02
|
||||||
|
|
||||||
[unreleased]:
|
[unreleased]:
|
||||||
https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.6.1...dev
|
https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.6.0...dev
|
||||||
[6.6.1]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.6.0...v6.6.1
|
|
||||||
[6.6.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.5.0...v6.6.0
|
[6.6.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.5.0...v6.6.0
|
||||||
[6.5.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.4.0...v6.5.0
|
[6.5.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.4.0...v6.5.0
|
||||||
[6.4.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.3.0...v6.4.0
|
[6.4.0]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.3.0...v6.4.0
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "foris",
|
"name": "foris",
|
||||||
"version": "6.6.1",
|
"version": "6.6.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "foris",
|
"name": "foris",
|
||||||
"version": "6.6.1",
|
"version": "6.6.0",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.6.0",
|
"@fortawesome/fontawesome-svg-core": "^6.6.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "foris",
|
"name": "foris",
|
||||||
"version": "6.6.1",
|
"version": "6.6.0",
|
||||||
"description": "Foris JS library is a set of components and utils for reForis application and plugins.",
|
"description": "Foris JS library is a set of components and utils for reForis application and plugins.",
|
||||||
"author": "CZ.NIC, z.s.p.o.",
|
"author": "CZ.NIC, z.s.p.o.",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -5,12 +5,7 @@
|
|||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, {
|
import React, { useMemo, useState } from "react";
|
||||||
useMemo,
|
|
||||||
useState,
|
|
||||||
useImperativeHandle,
|
|
||||||
forwardRef,
|
|
||||||
} from "react";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
flexRender,
|
flexRender,
|
||||||
@ -27,20 +22,34 @@ import RichTablePagination from "./RichTablePagination";
|
|||||||
|
|
||||||
const fallbackData = [];
|
const fallbackData = [];
|
||||||
|
|
||||||
const RichTable = forwardRef(
|
RichTable.propTypes = {
|
||||||
({ columns, data, withPagination, pageSize = 5, pageIndex = 0 }, ref) => {
|
/** Columns to be displayed in the table */
|
||||||
|
columns: PropTypes.array.isRequired,
|
||||||
|
/** Data to be displayed in the table */
|
||||||
|
data: PropTypes.array.isRequired,
|
||||||
|
/** Whether to display pagination */
|
||||||
|
withPagination: PropTypes.bool,
|
||||||
|
/** Number of rows per page */
|
||||||
|
pageSize: PropTypes.number,
|
||||||
|
/** Index of the current page */
|
||||||
|
pageIndex: PropTypes.number,
|
||||||
|
};
|
||||||
|
|
||||||
|
function RichTable({
|
||||||
|
columns,
|
||||||
|
data,
|
||||||
|
withPagination,
|
||||||
|
pageSize = 5,
|
||||||
|
pageIndex = 0,
|
||||||
|
}) {
|
||||||
const tableColumns = useMemo(() => columns, [columns]);
|
const tableColumns = useMemo(() => columns, [columns]);
|
||||||
const [tableData, setTableData] = useState(data ?? fallbackData);
|
const [tableData] = useState(data ?? fallbackData);
|
||||||
const [sorting, setSorting] = useState([]);
|
const [sorting, setSorting] = useState([]);
|
||||||
const [pagination, setPagination] = useState({
|
const [pagination, setPagination] = useState({
|
||||||
pageIndex,
|
pageIndex,
|
||||||
pageSize,
|
pageSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
|
||||||
setTableData,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: tableData,
|
data: tableData,
|
||||||
columns: tableColumns,
|
columns: tableColumns,
|
||||||
@ -55,8 +64,7 @@ const RichTable = forwardRef(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const paginationIsNeeded =
|
const paginationIsNeeded = tableData.length > pageSize && withPagination;
|
||||||
tableData.length > pageSize && withPagination;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="table-responsive">
|
<div className="table-responsive">
|
||||||
@ -73,22 +81,6 @@ const RichTable = forwardRef(
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
RichTable.propTypes = {
|
|
||||||
/** Columns to be displayed in the table */
|
|
||||||
columns: PropTypes.array.isRequired,
|
|
||||||
/** Data to be displayed in the table */
|
|
||||||
data: PropTypes.array.isRequired,
|
|
||||||
/** Whether to display pagination */
|
|
||||||
withPagination: PropTypes.bool,
|
|
||||||
/** Number of rows per page */
|
|
||||||
pageSize: PropTypes.number,
|
|
||||||
/** Index of the current page */
|
|
||||||
pageIndex: PropTypes.number,
|
|
||||||
};
|
|
||||||
|
|
||||||
RichTable.displayName = "RichTable";
|
|
||||||
|
|
||||||
export default RichTable;
|
export default RichTable;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user