1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-02-22 09:44:18 +01:00

Merge branch 'dev' into 'master'

Dev

See merge request turris/reforis/foris-js!271
This commit is contained in:
Aleksandr Gumroian 2025-02-20 12:56:13 +01:00
commit ede4fb0212
5 changed files with 266 additions and 268 deletions

View File

@ -8,6 +8,13 @@ and this project adheres to
## [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
### Changed
@ -441,7 +448,8 @@ and this project adheres to
## [0.0.7] - 2019-09-02
[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.2...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.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

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "foris",
"version": "6.6.1",
"version": "6.6.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "foris",
"version": "6.6.1",
"version": "6.6.2",
"license": "GPL-3.0",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.6.0",

View File

@ -1,6 +1,6 @@
{
"name": "foris",
"version": "6.6.1",
"version": "6.6.2",
"description": "Foris JS library is a set of components and utils for reForis application and plugins.",
"author": "CZ.NIC, z.s.p.o.",
"repository": {

View File

@ -1,16 +1,11 @@
/*
* Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/)
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
*
* This is free software, licensed under the GNU General Public License v3.
* See /LICENSE for more information.
*/
import React, {
useMemo,
useState,
useImperativeHandle,
forwardRef,
} from "react";
import React, { useMemo, useState } from "react";
import {
flexRender,
@ -25,24 +20,35 @@ import RichTableBody from "./RichTableBody";
import RichTableHeader from "./RichTableHeader";
import RichTablePagination from "./RichTablePagination";
const fallbackData = [];
RichTable.propTypes = {
/** 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,
};
const RichTable = forwardRef(
({ columns, data, withPagination, pageSize = 5, pageIndex = 0 }, ref) => {
export default function RichTable({
columns,
data,
withPagination,
pageSize = 5,
pageIndex = 0,
}) {
const tableColumns = useMemo(() => columns, [columns]);
const [tableData, setTableData] = useState(data ?? fallbackData);
const [sorting, setSorting] = useState([]);
const [pagination, setPagination] = useState({
pageIndex,
pageSize,
});
useImperativeHandle(ref, () => ({
setTableData,
}));
const table = useReactTable({
data: tableData,
data,
columns: tableColumns,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
@ -55,8 +61,7 @@ const RichTable = forwardRef(
},
});
const paginationIsNeeded =
tableData.length > pageSize && withPagination;
const paginationIsNeeded = data.length > pageSize && withPagination;
return (
<div className="table-responsive">
@ -68,27 +73,9 @@ const RichTable = forwardRef(
<RichTablePagination
table={table}
tablePageSize={pageSize}
allRows={tableData.length}
allRows={data.length}
/>
)}
</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;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
*
* This is free software, licensed under the GNU General Public License v3.
* See /LICENSE for more information.
@ -20,13 +20,15 @@ export const STATES = {
SubmitButton.propTypes = {
disabled: PropTypes.bool,
state: PropTypes.oneOf(Object.keys(STATES).map((key) => STATES[key])),
label: PropTypes.string,
};
export function SubmitButton({ disabled, state, ...props }) {
export function SubmitButton({ disabled, state, label, ...props }) {
const disableSubmitButton = disabled || state !== STATES.READY;
const loadingSubmitButton = state !== STATES.READY;
let labelSubmitButton;
let labelSubmitButton = label;
if (!labelSubmitButton) {
switch (state) {
case STATES.SAVING:
labelSubmitButton = _("Updating");
@ -37,6 +39,7 @@ export function SubmitButton({ disabled, state, ...props }) {
default:
labelSubmitButton = _("Save");
}
}
return (
<Button