1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-12-18 04:43:36 +01:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Aleksandr Gumroian
7197813cc9 Merge branch 'dev' into 'master'
Dev

See merge request turris/reforis/foris-js!268
2025-02-17 16:16:10 +01:00
Aleksandr Gumroian
2f249ce3dc Merge branch 'dev' into 'master'
Dev

See merge request turris/reforis/foris-js!265
2025-02-07 14:46:24 +01:00
14 changed files with 3652 additions and 3399 deletions

View File

@@ -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

View File

@@ -21,7 +21,10 @@ module.exports = {
testPathIgnorePatterns: ["/node_modules/", "/__fixtures__/", "/dist/"], testPathIgnorePatterns: ["/node_modules/", "/__fixtures__/", "/dist/"],
testEnvironment: "jsdom", testEnvironment: "jsdom",
verbose: false, verbose: false,
setupFilesAfterEnv: ["<rootDir>/src/testUtils/setup"], setupFilesAfterEnv: [
"@testing-library/react/cleanup-after-each",
"<rootDir>/src/testUtils/setup",
],
globals: { globals: {
TZ: "utc", TZ: "utc",
}, },

6415
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -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": {
@@ -14,17 +14,17 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"main": "./src/index.js", "main": "./src/index.js",
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.7.2", "@fortawesome/fontawesome-svg-core": "^6.6.0",
"@fortawesome/free-regular-svg-icons": "^6.7.2", "@fortawesome/free-regular-svg-icons": "^6.6.0",
"@fortawesome/free-solid-svg-icons": "^6.7.2", "@fortawesome/free-solid-svg-icons": "^6.6.0",
"@fortawesome/react-fontawesome": "^0.2.2", "@fortawesome/react-fontawesome": "^0.2.2",
"@tanstack/react-table": "^8.21.2", "@tanstack/react-table": "^8.20.5",
"axios": "^1.7.9", "axios": "^1.7.2",
"immutability-helper": "^3.1.1", "immutability-helper": "^3.1.1",
"moment": "^2.30.1", "moment": "^2.30.1",
"qrcode.react": "^4.2.0", "qrcode.react": "^3.1.0",
"react-datetime": "^3.3.1", "react-datetime": "^3.2.0",
"react-uid": "^2.4.0" "react-uid": "^2.3.3"
}, },
"peerDependencies": { "peerDependencies": {
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
@@ -34,32 +34,32 @@
"react-router-dom": "^5.1.2" "react-router-dom": "^5.1.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.26.4", "@babel/cli": "^7.24.7",
"@babel/core": "^7.26.9", "@babel/core": "^7.24.7",
"@babel/plugin-transform-runtime": "^7.26.9", "@babel/plugin-transform-runtime": "^7.24.7",
"@babel/preset-env": "^7.26.9", "@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.26.3", "@babel/preset-react": "^7.24.7",
"@testing-library/react": "^12.1.5", "@testing-library/react": "^8.0.9",
"babel-loader": "^9.2.1", "babel-loader": "^8.1.0",
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",
"bootstrap": "^5.3.3", "bootstrap": "^5.3.3",
"css-loader": "^7.1.2", "css-loader": "^5.2.4",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-config-reforis": "^2.1.1", "eslint-config-reforis": "^2.1.1",
"file-loader": "^6.0.0", "file-loader": "^6.0.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0", "jest-environment-jsdom": "^29.7.0",
"jest-mock-axios": "^4.8.0", "jest-mock-axios": "^4.7.3",
"moment-timezone": "^0.5.47", "moment-timezone": "^0.5.45",
"prettier": "^3.5.2", "prettier": "^3.3.2",
"prop-types": "15.8.1", "prop-types": "15.8.1",
"react": "16.9.0", "react": "16.9.0",
"react-dom": "16.9.0", "react-dom": "16.9.0",
"react-router-dom": "^5.1.2", "react-router-dom": "^5.1.2",
"react-styleguidist": "^12.0.1", "react-styleguidist": "^12.0.1",
"snapshot-diff": "^0.10.0", "snapshot-diff": "^0.10.0",
"style-loader": "^4.0.0", "style-loader": "^1.2.1",
"webpack": "^5.98.0" "webpack": "^5.92.1"
}, },
"scripts": { "scripts": {
"lint": "eslint src", "lint": "eslint src",

View File

@@ -1,5 +1,5 @@
/* /*
* 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.
@@ -7,7 +7,7 @@
import React from "react"; import React from "react";
import { render, fireEvent, getByLabelText, waitFor } from "customTestRender"; import { render, fireEvent, getByLabelText, wait } from "customTestRender";
import NumberInput from "../NumberInput"; import NumberInput from "../NumberInput";
@@ -34,7 +34,7 @@ describe("<NumberInput/>", () => {
it("Increase number with button", async () => { it("Increase number with button", async () => {
const increaseButton = getByLabelText(componentContainer, /Increase/); const increaseButton = getByLabelText(componentContainer, /Increase/);
fireEvent.mouseDown(increaseButton); fireEvent.mouseDown(increaseButton);
await waitFor(() => await wait(() =>
expect(onChangeMock).toHaveBeenCalledWith({ target: { value: 2 } }) expect(onChangeMock).toHaveBeenCalledWith({ target: { value: 2 } })
); );
}); });
@@ -42,7 +42,7 @@ describe("<NumberInput/>", () => {
it("Decrease number with button", async () => { it("Decrease number with button", async () => {
const decreaseButton = getByLabelText(componentContainer, /Decrease/); const decreaseButton = getByLabelText(componentContainer, /Decrease/);
fireEvent.mouseDown(decreaseButton); fireEvent.mouseDown(decreaseButton);
await waitFor(() => await wait(() =>
expect(onChangeMock).toHaveBeenCalledWith({ target: { value: 0 } }) expect(onChangeMock).toHaveBeenCalledWith({ target: { value: 0 } })
); );
}); });

View File

@@ -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;

View File

@@ -1,5 +1,5 @@
/* /*
* 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.
@@ -32,7 +32,7 @@ function RichTableHeader({ table, flexRender }) {
}; };
return ( return (
<thead className="table-light"> <thead className="thead-light">
{table.getHeaderGroups().map((headerGroup) => ( {table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id} role="row"> <tr key={headerGroup.id} role="row">
{headerGroup.headers.map((header) => ( {headerGroup.headers.map((header) => (

View File

@@ -1,12 +1,12 @@
/* /*
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/) * Copyright (C) 2019-2021 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.
*/ */
import React from "react"; import React from "react";
import { render, fireEvent, waitFor } from "customTestRender"; import { render, fireEvent, wait } from "customTestRender";
import mockAxios from "jest-mock-axios"; import mockAxios from "jest-mock-axios";
import WebSockets from "webSockets/WebSockets"; import WebSockets from "webSockets/WebSockets";
@@ -35,7 +35,7 @@ describe("<ResetWiFiSettings/>", () => {
expect.anything() expect.anything()
); );
mockAxios.mockResponse({ data: { foo: "bar" } }); mockAxios.mockResponse({ data: { foo: "bar" } });
await waitFor(() => await wait(() =>
expect(mockSetAlert).toBeCalledWith( expect(mockSetAlert).toBeCalledWith(
"Wi-Fi settings are set to defaults.", "Wi-Fi settings are set to defaults.",
ALERT_TYPES.SUCCESS ALERT_TYPES.SUCCESS
@@ -46,7 +46,7 @@ describe("<ResetWiFiSettings/>", () => {
it("should display alert on open ports - failure", async () => { it("should display alert on open ports - failure", async () => {
fireEvent.click(getAllByText("Reset Wi-Fi Settings")[1]); fireEvent.click(getAllByText("Reset Wi-Fi Settings")[1]);
mockJSONError(); mockJSONError();
await waitFor(() => await wait(() =>
expect(mockSetAlert).toBeCalledWith( expect(mockSetAlert).toBeCalledWith(
"An error occurred during resetting Wi-Fi settings." "An error occurred during resetting Wi-Fi settings."
) )

View File

@@ -1,16 +1,15 @@
/* /*
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/) * Copyright (C) 2019-2021 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.
*/ */
import React from "react"; import React from "react";
import diffSnapshot from "snapshot-diff"; import diffSnapshot from "snapshot-diff";
import mockAxios from "jest-mock-axios"; import mockAxios from "jest-mock-axios";
import { fireEvent, render, waitFor } from "customTestRender"; import { fireEvent, render, wait } from "customTestRender";
import WebSockets from "webSockets/WebSockets"; import WebSockets from "webSockets/WebSockets";
import { mockJSONError } from "testUtils/network"; import { mockJSONError } from "testUtils/network";
@@ -46,7 +45,7 @@ describe("<WiFiSettings/>", () => {
getByLabelText = renderRes.getByLabelText; getByLabelText = renderRes.getByLabelText;
getByText = renderRes.getByText; getByText = renderRes.getByText;
mockAxios.mockResponse({ data: wifiSettingsFixture() }); mockAxios.mockResponse({ data: wifiSettingsFixture() });
await waitFor(() => renderRes.getByText("Wi-Fi 1")); await wait(() => renderRes.getByText("Wi-Fi 1"));
firstRender = renderRes.asFragment(); firstRender = renderRes.asFragment();
}); });
@@ -61,7 +60,7 @@ describe("<WiFiSettings/>", () => {
); );
const errorMessage = "An API error occurred."; const errorMessage = "An API error occurred.";
mockJSONError(errorMessage); mockJSONError(errorMessage);
await waitFor(() => { await wait(() => {
expect(getByText(errorMessage)).toBeTruthy(); expect(getByText(errorMessage)).toBeTruthy();
}); });
}); });
@@ -182,7 +181,6 @@ describe("<WiFiSettings/>", () => {
guest_wifi: { guest_wifi: {
SSID: "TestGuestSSID", SSID: "TestGuestSSID",
enabled: true, enabled: true,
encryption: "WPA2",
password: "test_password", password: "test_password",
}, },
hidden: false, hidden: false,

View File

@@ -223,7 +223,6 @@ export function wifiSettingsFixture() {
guest_wifi: { guest_wifi: {
SSID: "TestGuestSSID", SSID: "TestGuestSSID",
enabled: false, enabled: false,
encryption: "WPA2",
password: "", password: "",
}, },
hidden: false, hidden: false,

View File

@@ -1,5 +1,5 @@
/* /*
* 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.
@@ -9,7 +9,13 @@ import React from "react";
import Button from "bootstrap/Button"; import Button from "bootstrap/Button";
import { fireEvent, getByText, render, waitFor } from "customTestRender"; import {
fireEvent,
getByText,
queryByText,
render,
wait,
} from "customTestRender";
import mockAxios from "jest-mock-axios"; import mockAxios from "jest-mock-axios";
import { mockJSONError } from "testUtils/network"; import { mockJSONError } from "testUtils/network";
import { mockSetAlert } from "testUtils/alertContextMock"; import { mockSetAlert } from "testUtils/alertContextMock";
@@ -67,7 +73,7 @@ describe("<ActionButtonWithModal/>", () => {
fireEvent.click(getByText(componentContainer, "Action")); fireEvent.click(getByText(componentContainer, "Action"));
fireEvent.click(getByText(componentContainer, "Confirm action")); fireEvent.click(getByText(componentContainer, "Confirm action"));
mockJSONError(); mockJSONError();
await waitFor(() => await wait(() =>
expect(mockSetAlert).toBeCalledWith("Action request failed.") expect(mockSetAlert).toBeCalledWith("Action request failed.")
); );
}); });
@@ -76,7 +82,7 @@ describe("<ActionButtonWithModal/>", () => {
fireEvent.click(getByText(componentContainer, "Action")); fireEvent.click(getByText(componentContainer, "Action"));
fireEvent.click(getByText(componentContainer, "Confirm action")); fireEvent.click(getByText(componentContainer, "Confirm action"));
mockAxios.mockResponse({ status: 200 }); mockAxios.mockResponse({ status: 200 });
await waitFor(() => await wait(() =>
expect(mockSetAlert).toBeCalledWith( expect(mockSetAlert).toBeCalledWith(
"Action request succeeded.", "Action request succeeded.",
"success" "success"

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/) * Copyright (C) 2019-2022 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.
@@ -7,7 +7,7 @@
import React from "react"; import React from "react";
import { render, waitFor, getByText } from "customTestRender"; import { render, wait, getByText } from "customTestRender";
import mockAxios from "jest-mock-axios"; import mockAxios from "jest-mock-axios";
import { import {
@@ -38,7 +38,7 @@ describe("CustomizationContext", () => {
it("should render component without customization", async () => { it("should render component without customization", async () => {
mockAxios.mockResponse({ data: {} }); mockAxios.mockResponse({ data: {} });
await waitFor(() => getByText(componentContainer, ORIGINAL)); await wait(() => getByText(componentContainer, ORIGINAL));
expect(componentContainer).toMatchSnapshot(); expect(componentContainer).toMatchSnapshot();
}); });
@@ -46,7 +46,7 @@ describe("CustomizationContext", () => {
it("should render customized component", async () => { it("should render customized component", async () => {
mockAxios.mockResponse({ data: { customization: "shield" } }); mockAxios.mockResponse({ data: { customization: "shield" } });
await waitFor(() => getByText(componentContainer, CUSTOM)); await wait(() => getByText(componentContainer, CUSTOM));
expect(componentContainer).toMatchSnapshot(); expect(componentContainer).toMatchSnapshot();
}); });

View File

@@ -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.
@@ -7,7 +7,7 @@
import React from "react"; import React from "react";
import { act, fireEvent, render, waitFor } from "customTestRender"; import { act, fireEvent, render, waitForElement } from "customTestRender";
import mockAxios from "jest-mock-axios"; import mockAxios from "jest-mock-axios";
import WebSockets from "webSockets/WebSockets"; import WebSockets from "webSockets/WebSockets";
import ForisForm from "../components/ForisForm"; import ForisForm from "../components/ForisForm";
@@ -59,7 +59,7 @@ describe("useForm hook.", () => {
); );
mockAxios.mockResponse({ field: "fetchedData" }); mockAxios.mockResponse({ field: "fetchedData" });
input = await waitFor(() => getByTestId("test-input")); input = await waitForElement(() => getByTestId("test-input"));
form = container.firstChild.firstChild; form = container.firstChild.firstChild;
}); });

View File

@@ -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