foris 6.6.1 → 6.6.2

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.
@@ -1,16 +1,11 @@
1
1
  /*
2
- * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/)
2
+ * Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
3
3
  *
4
4
  * This is free software, licensed under the GNU General Public License v3.
5
5
  * See /LICENSE for more information.
6
6
  */
7
7
 
8
- import React, {
9
- useMemo,
10
- useState,
11
- useImperativeHandle,
12
- forwardRef,
13
- } from "react";
8
+ import React, { useMemo, useState } from "react";
14
9
 
15
10
  import {
16
11
  flexRender,
@@ -25,70 +20,62 @@ import RichTableBody from "./RichTableBody";
25
20
  import RichTableHeader from "./RichTableHeader";
26
21
  import RichTablePagination from "./RichTablePagination";
27
22
 
28
- const fallbackData = [];
29
-
30
- const RichTable = forwardRef(
31
- ({ columns, data, withPagination, pageSize = 5, pageIndex = 0 }, ref) => {
32
- const tableColumns = useMemo(() => columns, [columns]);
33
- const [tableData, setTableData] = useState(data ?? fallbackData);
34
- const [sorting, setSorting] = useState([]);
35
- const [pagination, setPagination] = useState({
36
- pageIndex,
37
- pageSize,
38
- });
39
-
40
- useImperativeHandle(ref, () => ({
41
- setTableData,
42
- }));
43
-
44
- const table = useReactTable({
45
- data: tableData,
46
- columns: tableColumns,
47
- getCoreRowModel: getCoreRowModel(),
48
- getSortedRowModel: getSortedRowModel(),
49
- getPaginationRowModel: getPaginationRowModel(),
50
- onPaginationChange: setPagination,
51
- onSortingChange: setSorting,
52
- state: {
53
- sorting,
54
- pagination,
55
- },
56
- });
57
-
58
- const paginationIsNeeded =
59
- tableData.length > pageSize && withPagination;
60
-
61
- return (
62
- <div className="table-responsive">
63
- <table className="table table-hover text-nowrap">
64
- <RichTableHeader table={table} flexRender={flexRender} />
65
- <RichTableBody table={table} flexRender={flexRender} />
66
- </table>
67
- {paginationIsNeeded && (
68
- <RichTablePagination
69
- table={table}
70
- tablePageSize={pageSize}
71
- allRows={tableData.length}
72
- />
73
- )}
74
- </div>
75
- );
76
- }
77
- );
78
-
79
23
  RichTable.propTypes = {
80
24
  /** Columns to be displayed in the table */
81
25
  columns: PropTypes.array.isRequired,
82
- /** Data to be displayed in the table */
26
+ /** Data to be displayed in the table, must be passed as a stable reference, for example, useState */
83
27
  data: PropTypes.array.isRequired,
84
28
  /** Whether to display pagination */
85
29
  withPagination: PropTypes.bool,
86
- /** Number of rows per page */
30
+ /** Number of rows per page, the default is 5 */
87
31
  pageSize: PropTypes.number,
88
32
  /** Index of the current page */
89
33
  pageIndex: PropTypes.number,
90
34
  };
91
35
 
92
- RichTable.displayName = "RichTable";
36
+ export default function RichTable({
37
+ columns,
38
+ data,
39
+ withPagination,
40
+ pageSize = 5,
41
+ pageIndex = 0,
42
+ }) {
43
+ const tableColumns = useMemo(() => columns, [columns]);
44
+ const [sorting, setSorting] = useState([]);
45
+ const [pagination, setPagination] = useState({
46
+ pageIndex,
47
+ pageSize,
48
+ });
49
+
50
+ const table = useReactTable({
51
+ data,
52
+ columns: tableColumns,
53
+ getCoreRowModel: getCoreRowModel(),
54
+ getSortedRowModel: getSortedRowModel(),
55
+ getPaginationRowModel: getPaginationRowModel(),
56
+ onPaginationChange: setPagination,
57
+ onSortingChange: setSorting,
58
+ state: {
59
+ sorting,
60
+ pagination,
61
+ },
62
+ });
63
+
64
+ const paginationIsNeeded = data.length > pageSize && withPagination;
93
65
 
94
- export default RichTable;
66
+ return (
67
+ <div className="table-responsive">
68
+ <table className="table table-hover text-nowrap">
69
+ <RichTableHeader table={table} flexRender={flexRender} />
70
+ <RichTableBody table={table} flexRender={flexRender} />
71
+ </table>
72
+ {paginationIsNeeded && (
73
+ <RichTablePagination
74
+ table={table}
75
+ tablePageSize={pageSize}
76
+ allRows={data.length}
77
+ />
78
+ )}
79
+ </div>
80
+ );
81
+ }
Binary file
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
2
+ * Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
3
3
  *
4
4
  * This is free software, licensed under the GNU General Public License v3.
5
5
  * See /LICENSE for more information.
@@ -20,22 +20,25 @@ export const STATES = {
20
20
  SubmitButton.propTypes = {
21
21
  disabled: PropTypes.bool,
22
22
  state: PropTypes.oneOf(Object.keys(STATES).map((key) => STATES[key])),
23
+ label: PropTypes.string,
23
24
  };
24
25
 
25
- export function SubmitButton({ disabled, state, ...props }) {
26
+ export function SubmitButton({ disabled, state, label, ...props }) {
26
27
  const disableSubmitButton = disabled || state !== STATES.READY;
27
28
  const loadingSubmitButton = state !== STATES.READY;
28
29
 
29
- let labelSubmitButton;
30
- switch (state) {
31
- case STATES.SAVING:
32
- labelSubmitButton = _("Updating");
33
- break;
34
- case STATES.LOAD:
35
- labelSubmitButton = _("Load settings");
36
- break;
37
- default:
38
- labelSubmitButton = _("Save");
30
+ let labelSubmitButton = label;
31
+ if (!labelSubmitButton) {
32
+ switch (state) {
33
+ case STATES.SAVING:
34
+ labelSubmitButton = _("Updating");
35
+ break;
36
+ case STATES.LOAD:
37
+ labelSubmitButton = _("Load settings");
38
+ break;
39
+ default:
40
+ labelSubmitButton = _("Save");
41
+ }
39
42
  }
40
43
 
41
44
  return (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foris",
3
- "version": "6.6.1",
3
+ "version": "6.6.2",
4
4
  "description": "Foris JS library is a set of components and utils for reForis application and plugins.",
5
5
  "author": "CZ.NIC, z.s.p.o.",
6
6
  "repository": {
package/foris-6.6.1.tgz DELETED
Binary file