Merge branch 'dev' into 'master'

Dev

See merge request turris/reforis/foris-js!210
feature/ws-included v5.6.0
Aleksandr Gumroian 1 year ago
commit efb3fa80ce
  1. 1
      .gitignore
  2. 747
      package-lock.json
  3. 2
      package.json
  4. 2
      src/common/RebootButton.js
  5. 2
      src/common/WiFiSettings/ResetWiFiSettings.js
  6. 4
      src/common/WiFiSettings/WiFiForm.js
  7. 4
      src/context/alertContext/AlertContext.js
  8. 0
      src/context/alertContext/AlertContext.md
  9. 0
      src/context/alertContext/__tests__/AlertContext.test.js
  10. 0
      src/context/alertContext/__tests__/__snapshots__/AlertContext.test.js.snap
  11. 57
      src/context/customizationContext/CustomizationContext.js
  12. 3
      src/context/customizationContext/CustomizationContext.md
  13. 53
      src/context/customizationContext/__tests__/CustomizationContext.test.js
  14. 17
      src/context/customizationContext/__tests__/__snapshots__/CustomizationContext.test.js.snap
  15. 2
      src/form/components/ForisForm.js
  16. 13
      src/index.js
  17. 13
      src/testUtils/customTestRender.js
  18. 34
      src/testUtils/cutomizationContextMock.js
  19. 1
      src/utils/forisUrls.js
  20. 10
      styleguide.config.js
  21. 16
      translations/ru/LC_MESSAGES/forisjs.po
  22. 14
      translations/sk/LC_MESSAGES/forisjs.po

1
.gitignore vendored

@ -51,4 +51,3 @@ coverage.xml
dist/
foris-*.tgz
styleguide/
testUtils

747
package-lock.json generated

File diff suppressed because it is too large Load Diff

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

@ -14,7 +14,7 @@ import { ForisURLs } from "../utils/forisUrls";
import { Button } from "../bootstrap/Button";
import { Modal, ModalHeader, ModalBody, ModalFooter } from "../bootstrap/Modal";
import { useAlert } from "../alertContext/AlertContext";
import { useAlert } from "../context/alertContext/AlertContext";
export function RebootButton(props) {
const [triggered, setTriggered] = useState(false);

@ -9,7 +9,7 @@ import React, { useEffect, useState } from "react";
import PropTypes from "prop-types";
import { Button } from "../../bootstrap/Button";
import { useAlert } from "../../alertContext/AlertContext";
import { useAlert } from "../../context/alertContext/AlertContext";
import { ALERT_TYPES } from "../../bootstrap/Alert";
import { useAPIPost } from "../../api/hooks";
import { API_STATE } from "../../api/utils";

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 CZ.NIC z.s.p.o. (http://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.
* See /LICENSE for more information.
@ -64,7 +64,7 @@ DeviceForm.propTypes = {
guest_wifi: PropTypes.object.isRequired,
encryption: PropTypes.string.isRequired,
available_bands: PropTypes.array.isRequired,
ieee80211w_disabled: PropTypes.bool.isRequired,
ieee80211w_disabled: PropTypes.bool,
}),
formErrors: PropTypes.object.isRequired,
setFormValue: PropTypes.func.isRequired,

@ -8,8 +8,8 @@
import React, { useState, useContext, useCallback } from "react";
import PropTypes from "prop-types";
import { Alert, ALERT_TYPES } from "../bootstrap/Alert";
import { Portal } from "../utils/Portal";
import { Alert, ALERT_TYPES } from "../../bootstrap/Alert";
import { Portal } from "../../utils/Portal";
AlertContextProvider.propTypes = {
children: PropTypes.oneOfType([

@ -0,0 +1,57 @@
/*
* 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.
* See /LICENSE for more information.
*/
import React, { useContext, useEffect } from "react";
import PropTypes from "prop-types";
import { useAPIGet } from "../../api/hooks";
import { ForisURLs } from "../../utils/forisUrls";
import { Spinner } from "../../bootstrap/Spinner";
CustomizationContextProvider.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
};
function CustomizationContextProvider({ children }) {
const { CustomizationContext } = window;
const [getCustomizationResponse, getCustomization] = useAPIGet(
ForisURLs.about
);
useEffect(() => {
getCustomization();
}, [getCustomization]);
if (getCustomizationResponse.state !== "success") {
return <Spinner fullScreen />;
}
const deviceDetails = getCustomizationResponse.data || {};
const isCustomized = !!(
deviceDetails &&
deviceDetails.customization !== undefined &&
deviceDetails.customization === "shield"
);
return (
<CustomizationContext.Provider value={{ deviceDetails, isCustomized }}>
{children}
</CustomizationContext.Provider>
);
}
function useCustomizationContext() {
const { CustomizationContext } = window;
return useContext(CustomizationContext);
}
export { CustomizationContextProvider, useCustomizationContext };

@ -0,0 +1,3 @@
It provides customization context to the children. `CustomizationContext` allows
using `useCustomizationContext` in components to check if the reForis UI is
customized or not for specific devices.

@ -0,0 +1,53 @@
/*
* 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.
* See /LICENSE for more information.
*/
import React from "react";
import { render, wait, getByText } from "customTestRender";
import mockAxios from "jest-mock-axios";
import {
useCustomizationContext,
CustomizationContextProvider,
} from "../CustomizationContext";
const CUSTOM = "Description / component for customized reForis (Shield)";
const ORIGINAL = "Description / component for original reForis (other devices)";
const CustomizationTest = () => {
const { isCustomized } = useCustomizationContext();
return <p>{isCustomized ? CUSTOM : ORIGINAL}</p>;
};
describe("CustomizationContext", () => {
let componentContainer;
beforeEach(() => {
const { container } = render(
<CustomizationContextProvider>
<CustomizationTest />
</CustomizationContextProvider>
);
componentContainer = container;
});
it("should render component without customization", async () => {
mockAxios.mockResponse({ data: {} });
await wait(() => getByText(componentContainer, ORIGINAL));
expect(componentContainer).toMatchSnapshot();
});
it("should render customized component", async () => {
mockAxios.mockResponse({ data: { customization: "shield" } });
await wait(() => getByText(componentContainer, CUSTOM));
expect(componentContainer).toMatchSnapshot();
});
});

@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`CustomizationContext should render component without customization 1`] = `
<div>
<p>
Description / component for original reForis (other devices)
</p>
</div>
`;
exports[`CustomizationContext should render customized component 1`] = `
<div>
<p>
Description / component for customized reForis (Shield)
</p>
</div>
`;

@ -13,7 +13,7 @@ import { ALERT_TYPES } from "../../bootstrap/Alert";
import { API_STATE } from "../../api/utils";
import { formFieldsSize } from "../../bootstrap/constants";
import { Spinner } from "../../bootstrap/Spinner";
import { useAlert } from "../../alertContext/AlertContext";
import { useAlert } from "../../context/alertContext/AlertContext";
import { useAPIPost } from "../../api/hooks";
import { useForisModule, useForm } from "../hooks";

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 CZ.NIC z.s.p.o. (http://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.
* See /LICENSE for more information.
@ -90,4 +90,13 @@ export {
} from "./utils/validations";
// Alert context
export { AlertContextProvider, useAlert } from "./alertContext/AlertContext";
export {
AlertContextProvider,
useAlert,
} from "./context/alertContext/AlertContext";
// Customization context
export {
CustomizationContextProvider,
useCustomizationContext,
} from "./context/customizationContext/CustomizationContext";

@ -14,6 +14,7 @@ import { render } from "@testing-library/react";
import PropTypes from "prop-types";
import { AlertContextMock } from "./alertContextMock";
import { CustomizationContextMock } from "./cutomizationContextMock";
Wrapper.propTypes = {
children: PropTypes.oneOfType([
@ -24,11 +25,13 @@ Wrapper.propTypes = {
function Wrapper({ children }) {
return (
<AlertContextMock>
<StaticRouter>
<UIDReset>{children}</UIDReset>
</StaticRouter>
</AlertContextMock>
<CustomizationContextMock>
<AlertContextMock>
<StaticRouter>
<UIDReset>{children}</UIDReset>
</StaticRouter>
</AlertContextMock>
</CustomizationContextMock>
);
}

@ -0,0 +1,34 @@
/*
* 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.
* See /LICENSE for more information.
*/
import React from "react";
window.CustomizationContext = React.createContext();
const deviceDetails = {
kernel: "5.x.x",
model: "Turris Omnia",
os_branch: {
mode: "branch",
value: "hbs",
},
os_version: "6.x.x",
reforis_version: "1.x.x",
serial: 123456789,
};
const isCustomized = false;
function CustomizationContextMock({ children }) {
return (
<CustomizationContext.Provider value={{ deviceDetails, isCustomized }}>
{children}
</CustomizationContext.Provider>
);
}
export { CustomizationContextMock };

@ -36,5 +36,6 @@ export const ForisURLs = {
luci: "/cgi-bin/luci",
// API
about: `${REFORIS_API_URL_PREFIX}/about`,
reboot: `${REFORIS_API_URL_PREFIX}/reboot`,
};

@ -43,7 +43,7 @@ module.exports = {
},
{
name: "Alert Context",
components: ["src/alertContext/AlertContext.js"],
components: ["src/context/alertContext/AlertContext.js"],
exampleMode: "expand",
usageMode: "expand",
},
@ -51,6 +51,14 @@ module.exports = {
sectionDepth: 1,
},
{
name: "Customization Context",
components: [
"src/context/customizationContext/CustomizationContext.js",
],
exampleMode: "expand",
usageMode: "expand",
},
{
name: "Bootstrap components",
description: "Set of bootstrap components.",

@ -8,16 +8,17 @@ msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-12-02 15:54+0100\n"
"PO-Revision-Date: 2022-05-28 09:19+0000\n"
"PO-Revision-Date: 2022-12-07 12:47+0000\n"
"Last-Translator: Алексей Леньшин <alenshin@gmail.com>\n"
"Language-Team: Russian <https://hosted.weblate.org/projects/turris/foris-js/"
"ru/>\n"
"Language: ru\n"
"Language-Team: Russian <https://hosted.weblate.org/projects/turris/foris-"
"js/ru/>\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 4.15-dev\n"
"Generated-By: Babel 2.11.0\n"
#: src/api/utils.js:61
@ -118,13 +119,15 @@ msgstr "Шифрование"
#: src/common/WiFiSettings/WiFiForm.js:226
msgid "Disable Management Frame Protection"
msgstr ""
msgstr "Отключить защиту кадров управления"
#: src/common/WiFiSettings/WiFiForm.js:227
msgid ""
"In case you have trouble connecting to WiFi Access Point, try disabling "
"Management Frame Protection."
msgstr ""
"Если у вас возникли проблемы с подключением к точке доступа Wi-Fi, "
"попробуйте отключить защиту кадров управления."
#: src/common/WiFiSettings/WiFiForm.js:262
msgid "auto"
@ -381,4 +384,3 @@ msgstr "Не содержит списка электронных адресов
#~ "конфигурации Wi-Fi и восстановлению "
#~ "значений по умолчанию.\n"
#~ " "

@ -8,15 +8,16 @@ msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-12-02 15:54+0100\n"
"PO-Revision-Date: 2022-05-30 06:14+0000\n"
"PO-Revision-Date: 2022-12-05 16:48+0000\n"
"Last-Translator: Atec <dr.atec@gmail.com>\n"
"Language-Team: Slovak <https://hosted.weblate.org/projects/turris/foris-js/"
"sk/>\n"
"Language: sk\n"
"Language-Team: Slovak <https://hosted.weblate.org/projects/turris/foris-"
"js/sk/>\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
"X-Generator: Weblate 4.15-dev\n"
"Generated-By: Babel 2.11.0\n"
#: src/api/utils.js:61
@ -117,13 +118,15 @@ msgstr "Šifrovanie"
#: src/common/WiFiSettings/WiFiForm.js:226
msgid "Disable Management Frame Protection"
msgstr ""
msgstr "Zakázať Management Frame Protection"
#: src/common/WiFiSettings/WiFiForm.js:227
msgid ""
"In case you have trouble connecting to WiFi Access Point, try disabling "
"Management Frame Protection."
msgstr ""
"Ak máte problémy s pripojením k prístupovému bodu WiFi, skúste zakázať "
"Management Frame Protection."
#: src/common/WiFiSettings/WiFiForm.js:262
msgid "auto"
@ -377,4 +380,3 @@ msgstr "Neobsahuje zoznam e-mailov oddelených čiarkami."
#~ "že sa tým odstráni aktuálna konfigurácia"
#~ " a obnovia sa východiskové hodnoty.\n"
#~ " "

Loading…
Cancel
Save