mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-12-27 00:31:35 +01:00
Compare commits
No commits in common. "eafbc01c734b4a132bcb0d3c209b3c496342ac86" and "30fd6f91b4f02e5518822752f05f61c362a5aa70" have entirely different histories.
eafbc01c73
...
30fd6f91b4
|
@ -9,7 +9,7 @@ import React from "react";
|
||||||
|
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
import { HELP_TEXTS, HTMODES, BANDS, ENCRYPTIONMODES } from "./constants";
|
import { HELP_TEXTS, HTMODES, HWMODES, ENCRYPTIONMODES } from "./constants";
|
||||||
import WifiGuestForm from "./WiFiGuestForm";
|
import WifiGuestForm from "./WiFiGuestForm";
|
||||||
import WiFiQRCode from "./WiFiQRCode";
|
import WiFiQRCode from "./WiFiQRCode";
|
||||||
import PasswordInput from "../../bootstrap/PasswordInput";
|
import PasswordInput from "../../bootstrap/PasswordInput";
|
||||||
|
@ -60,7 +60,7 @@ DeviceForm.propTypes = {
|
||||||
SSID: PropTypes.string.isRequired,
|
SSID: PropTypes.string.isRequired,
|
||||||
password: PropTypes.string.isRequired,
|
password: PropTypes.string.isRequired,
|
||||||
hidden: PropTypes.bool.isRequired,
|
hidden: PropTypes.bool.isRequired,
|
||||||
band: PropTypes.string.isRequired,
|
hwmode: PropTypes.string.isRequired,
|
||||||
htmode: PropTypes.string.isRequired,
|
htmode: PropTypes.string.isRequired,
|
||||||
channel: PropTypes.string.isRequired,
|
channel: PropTypes.string.isRequired,
|
||||||
guest_wifi: PropTypes.object.isRequired,
|
guest_wifi: PropTypes.object.isRequired,
|
||||||
|
@ -155,26 +155,26 @@ function DeviceForm({
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<RadioSet
|
<RadioSet
|
||||||
name={`band-${deviceID}`}
|
name={`hwmode-${deviceID}`}
|
||||||
label={_("Band")}
|
label="GHz"
|
||||||
choices={getBandChoices(formData)}
|
choices={getHwmodeChoices(formData)}
|
||||||
value={formData.band}
|
value={formData.hwmode}
|
||||||
helpText={HELP_TEXTS.band}
|
helpText={HELP_TEXTS.hwmode}
|
||||||
inline
|
inline
|
||||||
onChange={setFormValue((value) => {
|
onChange={setFormValue((value) => {
|
||||||
// Find the selected band
|
// Get the last item in an array of available HT modes
|
||||||
const selectedBand = bnds.find(
|
const [best2] = bnds[0].available_htmodes.slice(-1);
|
||||||
(band) => band.band === value
|
const [best5] = bnds[1].available_htmodes.slice(-1);
|
||||||
);
|
|
||||||
// Get the last item in the available HT modes for the selected band
|
|
||||||
const bestHtmode =
|
|
||||||
selectedBand.available_htmodes.slice(-1)[0];
|
|
||||||
return {
|
return {
|
||||||
devices: {
|
devices: {
|
||||||
[deviceIndex]: {
|
[deviceIndex]: {
|
||||||
band: { $set: value },
|
hwmode: { $set: value },
|
||||||
channel: { $set: "0" },
|
channel: { $set: "0" },
|
||||||
htmode: { $set: bestHtmode },
|
htmode: {
|
||||||
|
$set:
|
||||||
|
// Set HT mode depending on checked frequency
|
||||||
|
value === "11a" ? best5 : best2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -263,7 +263,7 @@ function getChannelChoices(device) {
|
||||||
};
|
};
|
||||||
|
|
||||||
device.available_bands.forEach((availableBand) => {
|
device.available_bands.forEach((availableBand) => {
|
||||||
if (availableBand.band !== device.band) return;
|
if (availableBand.hwmode !== device.hwmode) return;
|
||||||
|
|
||||||
availableBand.available_channels.forEach((availableChannel) => {
|
availableBand.available_channels.forEach((availableChannel) => {
|
||||||
channelChoices[availableChannel.number.toString()] = `
|
channelChoices[availableChannel.number.toString()] = `
|
||||||
|
@ -282,7 +282,7 @@ function getHtmodeChoices(device) {
|
||||||
const htmodeChoices = {};
|
const htmodeChoices = {};
|
||||||
|
|
||||||
device.available_bands.forEach((availableBand) => {
|
device.available_bands.forEach((availableBand) => {
|
||||||
if (availableBand.band !== device.band) return;
|
if (availableBand.hwmode !== device.hwmode) return;
|
||||||
|
|
||||||
availableBand.available_htmodes.forEach((availableHtmod) => {
|
availableBand.available_htmodes.forEach((availableHtmod) => {
|
||||||
htmodeChoices[availableHtmod] = HTMODES[availableHtmod];
|
htmodeChoices[availableHtmod] = HTMODES[availableHtmod];
|
||||||
|
@ -291,10 +291,10 @@ function getHtmodeChoices(device) {
|
||||||
return htmodeChoices;
|
return htmodeChoices;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBandChoices(device) {
|
function getHwmodeChoices(device) {
|
||||||
return device.available_bands.map((availableBand) => ({
|
return device.available_bands.map((availableBand) => ({
|
||||||
label: `${BANDS[availableBand.band]} GHz`,
|
label: HWMODES[availableBand.hwmode],
|
||||||
value: availableBand.band,
|
value: availableBand.hwmode,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ describe("<WiFiSettings/>", () => {
|
||||||
it("Snapshot 2.4 GHz", () => {
|
it("Snapshot 2.4 GHz", () => {
|
||||||
fireEvent.click(getByText("Wi-Fi 1"));
|
fireEvent.click(getByText("Wi-Fi 1"));
|
||||||
const enabledRender = asFragment();
|
const enabledRender = asFragment();
|
||||||
fireEvent.click(getAllByText(/2.4/)[0]);
|
fireEvent.click(getAllByText("2.4")[0]);
|
||||||
expect(diffSnapshot(enabledRender, asFragment())).toMatchSnapshot();
|
expect(diffSnapshot(enabledRender, asFragment())).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ describe("<WiFiSettings/>", () => {
|
||||||
guest_wifi: { enabled: false },
|
guest_wifi: { enabled: false },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT80",
|
htmode: "HT80",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 0,
|
id: 0,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -135,7 +135,7 @@ describe("<WiFiSettings/>", () => {
|
||||||
|
|
||||||
it("Post form: 2.4 GHz", () => {
|
it("Post form: 2.4 GHz", () => {
|
||||||
fireEvent.click(getByText("Wi-Fi 1"));
|
fireEvent.click(getByText("Wi-Fi 1"));
|
||||||
fireEvent.click(getAllByText(/2.4/)[0]);
|
fireEvent.click(getAllByText("2.4")[0]);
|
||||||
|
|
||||||
fireEvent.click(getByText("Save"));
|
fireEvent.click(getByText("Save"));
|
||||||
expect(mockAxios.post).toBeCalled();
|
expect(mockAxios.post).toBeCalled();
|
||||||
|
@ -148,7 +148,7 @@ describe("<WiFiSettings/>", () => {
|
||||||
guest_wifi: { enabled: false },
|
guest_wifi: { enabled: false },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "VHT80",
|
htmode: "VHT80",
|
||||||
band: "2g",
|
hwmode: "11g",
|
||||||
id: 0,
|
id: 0,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -185,7 +185,7 @@ describe("<WiFiSettings/>", () => {
|
||||||
},
|
},
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT80",
|
htmode: "HT80",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 0,
|
id: 0,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
|
|
@ -77,7 +77,7 @@ export function wifiSettingsFixture() {
|
||||||
"VHT40",
|
"VHT40",
|
||||||
"VHT80",
|
"VHT80",
|
||||||
],
|
],
|
||||||
band: "2g",
|
hwmode: "11g",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
available_channels: [
|
available_channels: [
|
||||||
|
@ -215,7 +215,7 @@ export function wifiSettingsFixture() {
|
||||||
"VHT40",
|
"VHT40",
|
||||||
"VHT80",
|
"VHT80",
|
||||||
],
|
],
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
channel: 60,
|
channel: 60,
|
||||||
|
@ -227,7 +227,7 @@ export function wifiSettingsFixture() {
|
||||||
},
|
},
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT80",
|
htmode: "HT80",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 0,
|
id: 0,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -294,7 +294,7 @@ export function wifiSettingsFixture() {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
available_htmodes: ["NOHT", "HT20", "HT40"],
|
available_htmodes: ["NOHT", "HT20", "HT40"],
|
||||||
band: "2g",
|
hwmode: "11g",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
channel: 11,
|
channel: 11,
|
||||||
|
@ -306,7 +306,7 @@ export function wifiSettingsFixture() {
|
||||||
},
|
},
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT40",
|
htmode: "HT40",
|
||||||
band: "2g",
|
hwmode: "11g",
|
||||||
id: 1,
|
id: 1,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -323,7 +323,7 @@ const oneDevice = {
|
||||||
guest_wifi: { enabled: false },
|
guest_wifi: { enabled: false },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT40",
|
htmode: "HT40",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 0,
|
id: 0,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -340,7 +340,7 @@ const twoDevices = {
|
||||||
guest_wifi: { enabled: false },
|
guest_wifi: { enabled: false },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT40",
|
htmode: "HT40",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 0,
|
id: 0,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -352,7 +352,7 @@ const twoDevices = {
|
||||||
guest_wifi: { enabled: false },
|
guest_wifi: { enabled: false },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT40",
|
htmode: "HT40",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 1,
|
id: 1,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -369,7 +369,7 @@ const threeDevices = {
|
||||||
guest_wifi: { enabled: false },
|
guest_wifi: { enabled: false },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT40",
|
htmode: "HT40",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 0,
|
id: 0,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -381,7 +381,7 @@ const threeDevices = {
|
||||||
guest_wifi: { enabled: false },
|
guest_wifi: { enabled: false },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT40",
|
htmode: "HT40",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 1,
|
id: 1,
|
||||||
password: "TestPass",
|
password: "TestPass",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
@ -393,7 +393,7 @@ const threeDevices = {
|
||||||
guest_wifi: { enabled: false },
|
guest_wifi: { enabled: false },
|
||||||
hidden: false,
|
hidden: false,
|
||||||
htmode: "HT40",
|
htmode: "HT40",
|
||||||
band: "5g",
|
hwmode: "11a",
|
||||||
id: 2,
|
id: 2,
|
||||||
password: "",
|
password: "",
|
||||||
encryption: "WPA3",
|
encryption: "WPA3",
|
||||||
|
|
|
@ -555,23 +555,23 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||||
+ class="d-block"
|
+ class="d-block"
|
||||||
+ for="6"
|
+ for="6"
|
||||||
+ >
|
+ >
|
||||||
+ Band
|
+ GHz
|
||||||
+ </label>
|
+ </label>
|
||||||
+ <div
|
+ <div
|
||||||
+ class="mb-3 form-check form-check-inline"
|
+ class="mb-3 form-check form-check-inline"
|
||||||
+ >
|
+ >
|
||||||
+ <input
|
+ <input
|
||||||
+ class="form-check-input me-2"
|
+ class="form-check-input me-2"
|
||||||
+ id="band-0-0"
|
+ id="hwmode-0-0"
|
||||||
+ name="band-0"
|
+ name="hwmode-0"
|
||||||
+ type="radio"
|
+ type="radio"
|
||||||
+ value="2g"
|
+ value="11g"
|
||||||
+ />
|
+ />
|
||||||
+ <label
|
+ <label
|
||||||
+ class="form-check-label"
|
+ class="form-check-label"
|
||||||
+ for="band-0-0"
|
+ for="hwmode-0-0"
|
||||||
+ >
|
+ >
|
||||||
+ 2.4 GHz
|
+ 2.4
|
||||||
+ </label>
|
+ </label>
|
||||||
+ </div>
|
+ </div>
|
||||||
+ <div
|
+ <div
|
||||||
|
@ -580,16 +580,16 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||||
+ <input
|
+ <input
|
||||||
+ checked=""
|
+ checked=""
|
||||||
+ class="form-check-input me-2"
|
+ class="form-check-input me-2"
|
||||||
+ id="band-0-1"
|
+ id="hwmode-0-1"
|
||||||
+ name="band-0"
|
+ name="hwmode-0"
|
||||||
+ type="radio"
|
+ type="radio"
|
||||||
+ value="5g"
|
+ value="11a"
|
||||||
+ />
|
+ />
|
||||||
+ <label
|
+ <label
|
||||||
+ class="form-check-label"
|
+ class="form-check-label"
|
||||||
+ for="band-0-1"
|
+ for="hwmode-0-1"
|
||||||
+ >
|
+ >
|
||||||
+ 5 GHz
|
+ 5
|
||||||
+ </label>
|
+ </label>
|
||||||
+ </div>
|
+ </div>
|
||||||
+ <div
|
+ <div
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2024 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.
|
||||||
|
@ -18,10 +18,9 @@ export const HTMODES = {
|
||||||
HE80: _("802.11ax - 80 MHz wide channel"),
|
HE80: _("802.11ax - 80 MHz wide channel"),
|
||||||
HE160: _("802.11ax - 160 MHz wide channel"),
|
HE160: _("802.11ax - 160 MHz wide channel"),
|
||||||
};
|
};
|
||||||
export const BANDS = {
|
export const HWMODES = {
|
||||||
"2g": "2.4",
|
"11g": "2.4",
|
||||||
"5g": "5",
|
"11a": "5",
|
||||||
"6g": "6",
|
|
||||||
};
|
};
|
||||||
export const ENCRYPTIONMODES = {
|
export const ENCRYPTIONMODES = {
|
||||||
WPA3: _("WPA3 only"),
|
WPA3: _("WPA3 only"),
|
||||||
|
@ -38,7 +37,7 @@ export const HELP_TEXTS = {
|
||||||
hidden: _(
|
hidden: _(
|
||||||
"If set, network is not visible when scanning for available networks."
|
"If set, network is not visible when scanning for available networks."
|
||||||
),
|
),
|
||||||
band: _(
|
hwmode: _(
|
||||||
"The 2.4 GHz band is more widely supported by clients, but tends to have more interference. The 5 GHz band is a newer standard and may not be supported by all your devices. It usually has less interference, but the signal does not carry so well indoors."
|
"The 2.4 GHz band is more widely supported by clients, but tends to have more interference. The 5 GHz band is a newer standard and may not be supported by all your devices. It usually has less interference, but the signal does not carry so well indoors."
|
||||||
),
|
),
|
||||||
htmode: _(
|
htmode: _(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user