Skip to content

Commit

Permalink
Merge pull request #477 from yast/wifi_page_options
Browse files Browse the repository at this point in the history
Wifi page options
  • Loading branch information
teclator authored Mar 21, 2023
2 parents ea0f796 + 075450b commit 86f9ad5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
4 changes: 3 additions & 1 deletion web/src/components/layout/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import Terminal from "@icons/terminal.svg?component";
import Translate from "@icons/translate.svg?component";
import Warning from "@icons/warning.svg?component";
import Wifi from "@icons/wifi.svg?component";
import WifiFind from "@icons/wifi_find.svg?component";

import Loading from "./three-dots-loader-icon.svg?component";

Expand Down Expand Up @@ -95,7 +96,8 @@ const icons = {
terminal: Terminal,
translate: Translate,
warning: Warning,
wifi: Wifi
wifi: Wifi,
wifi_find: WifiFind
};

/**
Expand Down
15 changes: 12 additions & 3 deletions web/src/components/network/ConnectionsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ const RowActions = ({ actions, connection, ...props }) => {
* @param {object} props
* @param {Connection[]} props.connections - Connections to be shown
* @param {function} props.onEdit - function to be called for editing a connection
* @param {function} props.onForget - function to be called for forgetting a connection
*/
export default function ConnectionsTable ({
connections,
onEdit
onEdit,
onForget
}) {
if (connections.length === 0) return null;

Expand All @@ -83,8 +85,15 @@ export default function ConnectionsTable ({
title: "Edit",
"aria-label": `Edit connection ${connection.name}`,
onClick: () => onEdit(connection)
}
];
},
typeof onForget === 'function' && {
title: "Forget",
"aria-label": `Forget connection ${connection.name}`,
className: "danger-action",
icon: <Icon name="delete" size="24" />,
onClick: () => onForget(connection)
},
].filter(Boolean);

return (
<Tr key={connection.id}>
Expand Down
28 changes: 20 additions & 8 deletions web/src/components/network/NetworkPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import React, { useEffect, useState } from "react";
import { Button, Skeleton } from "@patternfly/react-core";

import { Icon } from "~/components/layout";
import { useInstallerClient } from "~/context/installer";
import { ConnectionTypes, NetworkEventTypes } from "~/client/network";
import { Page, Section } from "~/components/core";
import { Page, PageOptions, Section } from "~/components/core";
import { ConnectionsTable, IpSettingsForm, WifiSelector } from "~/components/network";

/**
Expand All @@ -42,7 +42,13 @@ const WifiScan = ({ supported, actionVariant = "link" }) => {

return (
<>
<Button variant={actionVariant} onClick={() => setWifiSelectorOpen(true)}>Connect to a Wi-Fi network</Button>
<Button
variant={actionVariant}
onClick={() => setWifiSelectorOpen(true)}
icon={<Icon name="wifi_find" size="24" />}
>
Connect to a Wi-Fi network
</Button>
<WifiSelector isOpen={wifiSelectorOpen} onClose={() => setWifiSelectorOpen(false)} />
</>
);
Expand Down Expand Up @@ -76,7 +82,7 @@ const NoWifiConnections = ({ wifiScanSupported }) => {
<div className="stack">
<div className="bold">No WiFi connections found</div>
<div>{message}</div>
<WifiScan supported={wifiScanSupported} buttonVariant="primary" />
<WifiScan supported={wifiScanSupported} actionVariant="primary" />
</div>
);
};
Expand Down Expand Up @@ -140,6 +146,11 @@ export default function NetworkPage() {
client.getConnection(id).then(setSelectedConnection);
};

const forgetConnection = async ({ id }) => {
const connection = await client.getConnection(id);
client.deleteConnection(connection);
};

const activeWiredConnections = connections.filter(c => c.type === ConnectionTypes.ETHERNET);
const activeWifiConnections = connections.filter(c => c.type === ConnectionTypes.WIFI);

Expand All @@ -150,10 +161,7 @@ export default function NetworkPage() {

return (
<>
<ConnectionsTable connections={activeWifiConnections} onEdit={selectConnection} />
<div className="horizontally-centered">
<WifiScan supported={wifiScanSupported} />
</div>
<ConnectionsTable connections={activeWifiConnections} onEdit={selectConnection} onForget={forgetConnection} />
</>
);
};
Expand All @@ -176,6 +184,10 @@ export default function NetworkPage() {

{ /* TODO: improve the connections edition */ }
{ selectedConnection && <IpSettingsForm connection={selectedConnection} onClose={() => setSelectedConnection(null)} /> }
{ wifiScanSupported &&
<PageOptions title="Network">
<WifiScan supported={wifiScanSupported} />
</PageOptions> }
</Page>
);
}
23 changes: 0 additions & 23 deletions web/src/components/network/NetworkPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,6 @@ describe("NetworkPage", () => {
within(section).getByText("192.168.69.200/24");
});

describe("when WiFi scan is supported", () => {
beforeEach(() => {
settingsFn.mockReturnValue({ ...networkSettings, wifiScanSupported: true });
});

it("displays a link for scanning other WiFi networks", async () => {
installerRender(<NetworkPage />);

const heading = await screen.findByRole("heading", { name: "WiFi networks" });
const section = heading.closest("section");
const scanWifiButton = within(section).getByRole("button", { name: "Connect to a Wi-Fi network" });
expect(scanWifiButton.classList.contains("pf-m-link")).toBe(true);
});

it("opens the WiFi selector dialog when user clicks for scanning WiFi networks", async () => {
const { user } = installerRender(<NetworkPage />);
const link = await screen.findByRole("button", { name: "Connect to a Wi-Fi network" });
await user.click(link);
const wifiDialog = await screen.findByRole("dialog");
within(wifiDialog).getByText("Connect to a Wi-Fi network");
});
});

describe("when no wired connection is detected", () => {
beforeEach(() => {
activeConnectionsFn.mockReturnValue([wiFiConnection]);
Expand Down

0 comments on commit 86f9ad5

Please sign in to comment.