Skip to content

Commit

Permalink
(feat) Fix network issues (#1320)
Browse files Browse the repository at this point in the history
## Fixed some network issues

### Frontend

- Fixed disconnect and connect urls.
- Fixed network client variable
- Allow to connect to and disconnect from an specific wireless network.

#### Screenshots

![Screenshot from 2024-06-12
14-56-00](https://github.com/openSUSE/agama/assets/7056681/773ad8aa-ba9d-4484-be9f-39bf1cc112aa)
![Screenshot from 2024-06-12
14-55-58](https://github.com/openSUSE/agama/assets/7056681/c01e4710-d63c-412f-9589-8f76c5cc9d80)
![Screenshot from 2024-06-12
14-55-30](https://github.com/openSUSE/agama/assets/7056681/bf52dbf2-40fc-47a7-946d-a2cf5e79bd66)
![Screenshot from 2024-06-12
14-55-25](https://github.com/openSUSE/agama/assets/7056681/b7c4e60d-d2b2-4fef-b085-de2cf7ea859d)

### Backend

- Apply changes immediately when disconnection and connection
  • Loading branch information
teclator authored Jun 12, 2024
2 parents 5fcd29d + e4172e5 commit 372d94a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
12 changes: 12 additions & 0 deletions rust/agama-server/src/network/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ async fn connect(
.await
.map_err(|_| NetworkError::CannotApplyConfig)?;

state
.network
.apply()
.await
.map_err(|_| NetworkError::CannotApplyConfig)?;

Ok(StatusCode::NO_CONTENT)
}

Expand All @@ -341,6 +347,12 @@ async fn disconnect(
.await
.map_err(|_| NetworkError::CannotApplyConfig)?;

state
.network
.apply()
.await
.map_err(|_| NetworkError::CannotApplyConfig)?;

Ok(StatusCode::NO_CONTENT)
}

Expand Down
4 changes: 2 additions & 2 deletions web/src/client/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class NetworkClient {
* @param {Connection} connection - connection to be activated
*/
async connectTo(connection) {
return this.client.get(`/network/${connection.id}/connect`);
return this.client.get(`/network/connections/${connection.id}/connect`);
}

/**
Expand All @@ -234,7 +234,7 @@ class NetworkClient {
* @param {Connection} connection - connection to be activated
*/
async disconnect(connection) {
return this.client.get(`/network/${connection.id}/disconnect`);
return this.client.get(`/network/connections/${connection.id}/disconnect`);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/network/WifiNetworkListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function WifiNetworkListItem({ network, isSelected, isActive, onSelect, onCancel
{networkState(network.device?.state)}
</Text>
{network.settings &&
<WifiNetworkMenu settings={network.settings} />}
<WifiNetworkMenu settings={network.settings} device={network.device} onConnect={onSelect} />}
</Split>
</Flex>
{isSelected && (!network.settings || network.error) &&
Expand Down
23 changes: 22 additions & 1 deletion web/src/components/network/WifiNetworkMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const KebabToggle = ({ toggleRef, onClick }) => (
</MenuToggle>
);

export default function WifiNetworkMenu({ settings, position = "right" }) {
export default function WifiNetworkMenu({ settings, position = "right", device, onConnect }) {
const client = useInstallerClient();
const [isOpen, setIsOpen] = useState(false);
const toggle = () => setIsOpen(!isOpen);
Expand All @@ -45,6 +45,27 @@ export default function WifiNetworkMenu({ settings, position = "right" }) {
position={position}
>
<DropdownList>
{!device &&
<DropdownItem
key="connect"
onClick={async () => {
await client.network.connectTo(settings);
onConnect();
}}
icon={<Icon name="delete" size="s" />}
>
{/* TRANSLATORS: menu label, connect to the selected WiFi network */}
{_("Connect")}
</DropdownItem>}
{device &&
<DropdownItem
key="discconnect"
onClick={async () => await client.network.disconnect(settings)}
icon={<Icon name="delete" size="s" />}
>
{/* TRANSLATORS: menu label, disconnect from the selected WiFi network */}
{_("Disconnect")}
</DropdownItem>}
<DropdownItem
isDanger
key="forget-network"
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/network/WifiSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function WifiSelector({ isOpen = false, onClose }) {

case NetworkEventTypes.DEVICE_UPDATED: {
const [name, data] = payload;
if (data.state === "failed") {
if (data.state === "failed" && selectedNetwork) {
selectedNetwork.error = "Failed";
}
setDevices(devs => {
Expand Down Expand Up @@ -139,7 +139,7 @@ function WifiSelector({ isOpen = false, onClose }) {
onSelectionCallback={(network) => {
switchSelectedNetwork(network);
if (network.settings && !network.device) {
client.network.connectTo(network.settings);
client.connectTo(network.settings);
}
}}
onCancelSelectionCallback={() => switchSelectedNetwork(activeNetwork)}
Expand Down

0 comments on commit 372d94a

Please sign in to comment.