From 2c71202c09df4b1be22f2ec2aebdbe5aaea67ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Sat, 11 Mar 2023 00:20:18 +0000 Subject: [PATCH] [web] Drop no longer needed TargetIpsPopup component Now that the Network section summarizes the available connections, this component is not that relevant. It is being dropped to reduce the confusion of having two slightly different network summaries in two different locations. --- web/src/components/core/Sidebar.jsx | 2 - web/src/components/core/Sidebar.test.jsx | 1 - web/src/components/network/TargetIpsPopup.jsx | 89 ------------------- .../network/TargetIpsPopup.test.jsx | 87 ------------------ web/src/components/network/index.js | 1 - 5 files changed, 180 deletions(-) delete mode 100644 web/src/components/network/TargetIpsPopup.jsx delete mode 100644 web/src/components/network/TargetIpsPopup.test.jsx diff --git a/web/src/components/core/Sidebar.jsx b/web/src/components/core/Sidebar.jsx index 249538de5a..9a54a6501e 100644 --- a/web/src/components/core/Sidebar.jsx +++ b/web/src/components/core/Sidebar.jsx @@ -22,7 +22,6 @@ import React, { useEffect, useRef, useState } from "react"; import { Icon, PageActions, PageOptionsSlot } from "~/components/layout"; import { About, Disclosure, LogsButton, ShowLogButton, ShowTerminalButton } from "~/components/core"; -import { TargetIpsPopup } from "~/components/network"; /** * Internal and memoized component for rendering links only once @@ -58,7 +57,6 @@ const FixedLinks = React.memo(() => ( - ), () => true); diff --git a/web/src/components/core/Sidebar.test.jsx b/web/src/components/core/Sidebar.test.jsx index ac9f0e6004..9b70a50b9a 100644 --- a/web/src/components/core/Sidebar.test.jsx +++ b/web/src/components/core/Sidebar.test.jsx @@ -28,7 +28,6 @@ jest.mock("~/components/layout/Layout", () => mockLayout()); jest.mock("~/components/core/About", () => mockComponent(About link mock)); jest.mock("~/components/core/LogsButton", () => mockComponent()); jest.mock("~/components/core/ShowLogButton", () => mockComponent()); -jest.mock("~/components/network/TargetIpsPopup", () => mockComponent("Host Ips Mock")); it("renders the sidebar initially hidden", async () => { plainRender(); diff --git a/web/src/components/network/TargetIpsPopup.jsx b/web/src/components/network/TargetIpsPopup.jsx deleted file mode 100644 index 6b11e5386d..0000000000 --- a/web/src/components/network/TargetIpsPopup.jsx +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) [2022] SUSE LLC - * - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, contact SUSE LLC. - * - * To contact SUSE LLC about this file by physical or electronic mail, you may - * find current contact information at www.suse.com. - */ - -import React, { useEffect, useState } from "react"; -import { Button, List, ListItem, Text } from "@patternfly/react-core"; - -import { useCancellablePromise } from "~/utils"; -import { useInstallerClient } from "~/context/installer"; -import { formatIp } from "~/client/network/utils"; - -import { Icon } from "~/components/layout"; -import { Popup } from "~/components/core"; - -export default function TargetIpsPopup() { - const client = useInstallerClient(); - const { cancellablePromise } = useCancellablePromise(); - const [addresses, setAddresses] = useState([]); - const [initialized, setInitialized] = useState(false); - const [hostname, setHostname] = useState(); - const [isOpen, setIsOpen] = useState(false); - - useEffect(() => { - cancellablePromise(client.network.setUp()).then(() => setInitialized(true)); - }, [client.network, cancellablePromise]); - - useEffect(() => { - if (!initialized) return; - - const refreshState = () => { - setAddresses(client.network.addresses()); - setHostname(client.network.settings().hostname); - }; - - refreshState(); - return client.network.onNetworkEvent(() => { - refreshState(); - }); - }, [client.network, initialized]); - - if (addresses.length === 0) return null; - const [firstIp] = addresses; - - const open = () => setIsOpen(true); - const close = () => setIsOpen(false); - - return ( - <> - - - - - {addresses.map((ip, index) => ( - {formatIp(ip)} - ))} - - - - Close - - - - - ); -} diff --git a/web/src/components/network/TargetIpsPopup.test.jsx b/web/src/components/network/TargetIpsPopup.test.jsx deleted file mode 100644 index a16bb2a2dd..0000000000 --- a/web/src/components/network/TargetIpsPopup.test.jsx +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) [2022] SUSE LLC - * - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, contact SUSE LLC. - * - * To contact SUSE LLC about this file by physical or electronic mail, you may - * find current contact information at www.suse.com. - */ - -import React from "react"; - -import { act, screen, waitFor, within } from "@testing-library/react"; -import { installerRender } from "~/test-utils"; -import { createClient } from "~/client"; - -import { TargetIpsPopup } from "~/components/network"; - -jest.mock("~/client"); - -const addresses = [ - { address: "1.2.3.4", prefix: 24 }, - { address: "5.6.7.8", prefix: 16 }, -]; -const addressFn = jest.fn().mockReturnValue(addresses); -const networkSettings = { wifiScanSupported: false, hostname: "example.net" }; -const settingsFn = jest.fn().mockReturnValue(networkSettings); - -describe("TargetIpsPopup", () => { - let callbacks; - beforeEach(() => { - callbacks = []; - const onNetworkEventFn = (cb) => { callbacks.push(cb) }; - createClient.mockImplementation(() => { - return { - network: { - onNetworkEvent: onNetworkEventFn, - addresses: addressFn, - settings: settingsFn, - setUp: jest.fn().mockResolvedValue() - } - }; - }); - }); - - it("lists target IPs in hostname labeled popup", async () => { - const { user } = installerRender(); - - const button = await screen.findByRole("button", { name: /1.2.3.4\/24 \(example.net\)/i }); - await user.click(button); - - const dialog = await screen.findByRole("dialog"); - - within(dialog).getByText(/IP Addresses/); - within(dialog).getByText("5.6.7.8/16"); - - const closeButton = within(dialog).getByRole("button", { name: /Close/i }); - await user.click(closeButton); - - await waitFor(() => { - expect(screen.queryByRole("dialog")).not.toBeInTheDocument(); - }); - }); - - it("updates address and hostname if they change", async () => { - installerRender(); - await screen.findByRole("button", { name: /1.2.3.4\/24 \(example.net\)/i }); - - addressFn.mockReturnValue([{ address: "5.6.7.8", prefix: 24 }]); - settingsFn.mockReturnValue({ wifiScanSupported: false, hostname: "localhost.localdomain" }); - act(() => { - callbacks.forEach(cb => cb()); - }); - await screen.findByRole("button", { name: /5.6.7.8\/24 \(localhost.localdomain\)/i }); - }); -}); diff --git a/web/src/components/network/index.js b/web/src/components/network/index.js index e8d3a15ecb..5cb1b445b2 100644 --- a/web/src/components/network/index.js +++ b/web/src/components/network/index.js @@ -26,7 +26,6 @@ export { default as DnsDataList } from "./DnsDataList"; export { default as IpAddressInput } from "./IpAddressInput"; export { default as IpPrefixInput } from "./IpPrefixInput"; export { default as IpSettingsForm } from "./IpSettingsForm"; -export { default as TargetIpsPopup } from "./TargetIpsPopup"; export { default as WifiConnectionForm } from "./WifiConnectionForm"; export { default as WifiHiddenNetworkForm } from "./WifiHiddenNetworkForm"; export { default as WifiNetworkListItem } from "./WifiNetworkListItem";