From 6c21d01df0906a77e64c9ca2df144c43fefae23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Tue, 23 Jul 2024 16:50:19 +0100 Subject: [PATCH] refactor(web) move and improve network routes file Related to 1555cc4c0144c2043cc4924cb5f34fb4c0a17933 --- .../components/network/ConnectionsTable.jsx | 8 +++--- web/src/components/network/NetworkPage.jsx | 11 ++++---- .../network/WifiNetworksListPage.jsx | 24 +++++++++-------- web/src/router.js | 4 +-- .../network/routes.js => routes/network.tsx} | 27 +++++++++++-------- 5 files changed, 41 insertions(+), 33 deletions(-) rename web/src/{components/network/routes.js => routes/network.tsx} (73%) diff --git a/web/src/components/network/ConnectionsTable.jsx b/web/src/components/network/ConnectionsTable.jsx index 22616074d7..4dd892758e 100644 --- a/web/src/components/network/ConnectionsTable.jsx +++ b/web/src/components/network/ConnectionsTable.jsx @@ -20,13 +20,13 @@ */ import React from "react"; -import { useNavigate } from "react-router-dom"; +import { useNavigate, generatePath } from "react-router-dom"; import { Table, Thead, Tr, Th, Tbody, Td } from "@patternfly/react-table"; -import { sprintf } from "sprintf-js"; - import { RowActions } from "~/components/core"; import { Icon } from "~/components/layout"; import { formatIp } from "~/client/network/utils"; +import { PATHS } from "~/routes/network"; +import { sprintf } from "sprintf-js"; import { _ } from "~/i18n"; /** @@ -76,7 +76,7 @@ export default function ConnectionsTable({ connections, devices, onForget }) { role: "link", // TRANSLATORS: %s is replaced by a network connection name "aria-label": sprintf(_("Edit connection %s"), connection.id), - onClick: () => navigate(`connections/${connection.id}/edit`), + onClick: () => navigate(generatePath(PATHS.editConnection, { id: connection.id })), }, typeof onForget === "function" && { title: _("Forget"), diff --git a/web/src/components/network/NetworkPage.jsx b/web/src/components/network/NetworkPage.jsx index 3de10cd297..dd1216d346 100644 --- a/web/src/components/network/NetworkPage.jsx +++ b/web/src/components/network/NetworkPage.jsx @@ -25,10 +25,11 @@ import React from "react"; import { CardBody, Grid, GridItem } from "@patternfly/react-core"; import { ButtonLink, CardField, EmptyState, Page } from "~/components/core"; import { ConnectionsTable } from "~/components/network"; -import { _ } from "~/i18n"; import { formatIp } from "~/client/network/utils"; -import { sprintf } from "sprintf-js"; import { useNetwork, useNetworkConfigChanges } from "~/queries/network"; +import { PATHS } from "~/routes/network"; +import { sprintf } from "sprintf-js"; +import { _ } from "~/i18n"; /** * Page component holding Network settings @@ -70,7 +71,7 @@ export default function NetworkPage() { + {activeConnection ? _("Change") : _("Connect")} } @@ -101,8 +102,8 @@ export default function NetworkPage() { return ( 0 && _("Wired")}> - {total === 0 && ()} - {total !== 0 && ()} + {total === 0 && } + {total !== 0 && } ); diff --git a/web/src/components/network/WifiNetworksListPage.jsx b/web/src/components/network/WifiNetworksListPage.jsx index d00b4cd2b9..12e362a298 100644 --- a/web/src/components/network/WifiNetworksListPage.jsx +++ b/web/src/components/network/WifiNetworksListPage.jsx @@ -43,15 +43,17 @@ import { Split, Stack, } from "@patternfly/react-core"; +import { generatePath } from "react-router-dom"; +import { useQueryClient } from "@tanstack/react-query"; import { Icon } from "~/components/layout"; import { WifiConnectionForm } from "~/components/network"; import { ButtonLink } from "~/components/core"; import { DeviceState } from "~/client/network/model"; -import { useInstallerClient } from "~/context/installer"; -import { _ } from "~/i18n"; import { formatIp } from "~/client/network/utils"; -import { useQueryClient } from "@tanstack/react-query"; +import { useInstallerClient } from "~/context/installer"; import { useSelectedWifi, useSelectedWifiChange } from "~/queries/network"; +import { PATHS } from "~/routes/network"; +import { _ } from "~/i18n"; const HIDDEN_NETWORK = Object.freeze({ hidden: true }); @@ -92,7 +94,7 @@ const WifiDrawerPanelBody = ({ network, onCancel }) => { const { data } = useSelectedWifi(); const forgetNetwork = async () => { await client.network.deleteConnection(network.settings.id); - queryClient.invalidateQueries({ queryKey: ["network", "connections"] }) + queryClient.invalidateQueries({ queryKey: ["network", "connections"] }); }; if (!network) return; @@ -109,7 +111,9 @@ const WifiDrawerPanelBody = ({ network, onCancel }) => { await client.network.connectTo(network.settings)}> {_("Connect")} - {_("Edit")} + + {_("Edit")} + @@ -131,7 +135,7 @@ const WifiDrawerPanelBody = ({ network, onCancel }) => { await client.network.disconnect(network.settings)}> {_("Disconnect")} - + {_("Edit")}