mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-05-07 09:40:54 +02:00
Compare commits
No commits in common. "ede4fb02125f0fa0393af086cd4fdbdbf8f4f2fd" and "7197813cc90795704f3bfbd784a945c321e4eecc" have entirely different histories.
ede4fb0212
...
7197813cc9
10
CHANGELOG.md
10
CHANGELOG.md
@ -8,13 +8,6 @@ and this project adheres to
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [6.6.2] - 2025-02-20
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
- Enhanced SubmitButton component to accept a custom label prop
|
|
||||||
- Refactored RichTable component to remove forwardRef and simplify data handling
|
|
||||||
|
|
||||||
## [6.6.1] - 2025-02-17
|
## [6.6.1] - 2025-02-17
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
@ -448,8 +441,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.2...dev
|
https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.6.1...dev
|
||||||
[6.6.2]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.6.1...v6.6.2
|
|
||||||
[6.6.1]: https://gitlab.nic.cz/turris/reforis/foris-js/-/compare/v6.6.0...v6.6.1
|
[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
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "foris",
|
"name": "foris",
|
||||||
"version": "6.6.2",
|
"version": "6.6.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "foris",
|
"name": "foris",
|
||||||
"version": "6.6.2",
|
"version": "6.6.1",
|
||||||
"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.2",
|
"version": "6.6.1",
|
||||||
"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": {
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
* Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||||
*
|
*
|
||||||
* This is free software, licensed under the GNU General Public License v3.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useMemo, useState } from "react";
|
import React, {
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
useImperativeHandle,
|
||||||
|
forwardRef,
|
||||||
|
} from "react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
flexRender,
|
flexRender,
|
||||||
@ -20,35 +25,24 @@ import RichTableBody from "./RichTableBody";
|
|||||||
import RichTableHeader from "./RichTableHeader";
|
import RichTableHeader from "./RichTableHeader";
|
||||||
import RichTablePagination from "./RichTablePagination";
|
import RichTablePagination from "./RichTablePagination";
|
||||||
|
|
||||||
RichTable.propTypes = {
|
const fallbackData = [];
|
||||||
/** Columns to be displayed in the table */
|
|
||||||
columns: PropTypes.array.isRequired,
|
|
||||||
/** Data to be displayed in the table, must be passed as a stable reference, for example, useState */
|
|
||||||
data: PropTypes.array.isRequired,
|
|
||||||
/** Whether to display pagination */
|
|
||||||
withPagination: PropTypes.bool,
|
|
||||||
/** Number of rows per page, the default is 5 */
|
|
||||||
pageSize: PropTypes.number,
|
|
||||||
/** Index of the current page */
|
|
||||||
pageIndex: PropTypes.number,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function RichTable({
|
const RichTable = forwardRef(
|
||||||
columns,
|
({ columns, data, withPagination, pageSize = 5, pageIndex = 0 }, ref) => {
|
||||||
data,
|
|
||||||
withPagination,
|
|
||||||
pageSize = 5,
|
|
||||||
pageIndex = 0,
|
|
||||||
}) {
|
|
||||||
const tableColumns = useMemo(() => columns, [columns]);
|
const tableColumns = useMemo(() => columns, [columns]);
|
||||||
|
const [tableData, setTableData] = 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,
|
data: tableData,
|
||||||
columns: tableColumns,
|
columns: tableColumns,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
getSortedRowModel: getSortedRowModel(),
|
getSortedRowModel: getSortedRowModel(),
|
||||||
@ -61,7 +55,8 @@ export default function RichTable({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const paginationIsNeeded = data.length > pageSize && withPagination;
|
const paginationIsNeeded =
|
||||||
|
tableData.length > pageSize && withPagination;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="table-responsive">
|
<div className="table-responsive">
|
||||||
@ -73,9 +68,27 @@ export default function RichTable({
|
|||||||
<RichTablePagination
|
<RichTablePagination
|
||||||
table={table}
|
table={table}
|
||||||
tablePageSize={pageSize}
|
tablePageSize={pageSize}
|
||||||
allRows={data.length}
|
allRows={tableData.length}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</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;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||||
*
|
*
|
||||||
* This is free software, licensed under the GNU General Public License v3.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
@ -20,15 +20,13 @@ export const STATES = {
|
|||||||
SubmitButton.propTypes = {
|
SubmitButton.propTypes = {
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
state: PropTypes.oneOf(Object.keys(STATES).map((key) => STATES[key])),
|
state: PropTypes.oneOf(Object.keys(STATES).map((key) => STATES[key])),
|
||||||
label: PropTypes.string,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function SubmitButton({ disabled, state, label, ...props }) {
|
export function SubmitButton({ disabled, state, ...props }) {
|
||||||
const disableSubmitButton = disabled || state !== STATES.READY;
|
const disableSubmitButton = disabled || state !== STATES.READY;
|
||||||
const loadingSubmitButton = state !== STATES.READY;
|
const loadingSubmitButton = state !== STATES.READY;
|
||||||
|
|
||||||
let labelSubmitButton = label;
|
let labelSubmitButton;
|
||||||
if (!labelSubmitButton) {
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case STATES.SAVING:
|
case STATES.SAVING:
|
||||||
labelSubmitButton = _("Updating");
|
labelSubmitButton = _("Updating");
|
||||||
@ -39,7 +37,6 @@ export function SubmitButton({ disabled, state, label, ...props }) {
|
|||||||
default:
|
default:
|
||||||
labelSubmitButton = _("Save");
|
labelSubmitButton = _("Save");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
|
Loading…
x
Reference in New Issue
Block a user