From 085deff4f7d9c536661780d4b4e0c77446b84a12 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 2 Jan 2024 20:09:42 +0100 Subject: [PATCH] Reorganize network tab --- .../src/widgets/forms/EditSection.tsx | 30 ++-- .../src/widgets/forms/VMNetworksList.tsx | 150 ++++++++++-------- .../src/widgets/vms/VMDetails.tsx | 9 +- 3 files changed, 98 insertions(+), 91 deletions(-) diff --git a/virtweb_frontend/src/widgets/forms/EditSection.tsx b/virtweb_frontend/src/widgets/forms/EditSection.tsx index 0dd3b8c..03ead13 100644 --- a/virtweb_frontend/src/widgets/forms/EditSection.tsx +++ b/virtweb_frontend/src/widgets/forms/EditSection.tsx @@ -2,23 +2,27 @@ import { Grid, Paper, Typography } from "@mui/material"; import React, { PropsWithChildren } from "react"; export function EditSection( - p: { title: string; actions?: React.ReactElement } & PropsWithChildren + p: { title?: string; actions?: React.ReactElement } & PropsWithChildren ): React.ReactElement { return ( - - - {p.title} - - {p.actions} - + {(p.title || p.actions) && ( + + {p.title && ( + + {p.title} + + )} + {p.actions} + + )} {p.children} diff --git a/virtweb_frontend/src/widgets/forms/VMNetworksList.tsx b/virtweb_frontend/src/widgets/forms/VMNetworksList.tsx index d3bfbe6..98433ae 100644 --- a/virtweb_frontend/src/widgets/forms/VMNetworksList.tsx +++ b/virtweb_frontend/src/widgets/forms/VMNetworksList.tsx @@ -4,6 +4,7 @@ import DeleteIcon from "@mui/icons-material/Delete"; import { Avatar, Button, + Grid, IconButton, ListItem, ListItemAvatar, @@ -19,6 +20,7 @@ import { randomMacAddress } from "../../utils/RandUtils"; import { MACInput } from "./MACInput"; import { SelectInput } from "./SelectInput"; import { VMNetworkFilterParameters } from "./VMNetworkFilterParameters"; +import { EditSection } from "./EditSection"; export function VMNetworksList(p: { vm: VMInfo; @@ -37,22 +39,28 @@ export function VMNetworksList(p: { return ( <> - {/* networks list */} - {p.vm.networks.map((n, num) => ( - { - p.vm.networks.splice(num, 1); - p.onChange?.(); - }} - {...p} - /> - ))} - {p.editable && ( - +
+ +
)} + + + {/* networks list */} + {p.vm.networks.map((n, num) => ( + + { + p.vm.networks.splice(num, 1); + p.onChange?.(); + }} + {...p} + /> + + ))} + ); } @@ -141,64 +149,66 @@ function NetworkInfoWidget(p: { /> {p.network.type === "DefinedNetwork" && ( - { - const chars = [n.forward_mode.toString()]; - if (n.ip_v4) chars.push("IPv4"); - if (n.ip_v6) chars.push("IPv6"); - if (n.description) chars.push(n.description); + <> + { + const chars = [n.forward_mode.toString()]; + if (n.ip_v4) chars.push("IPv4"); + if (n.ip_v6) chars.push("IPv6"); + if (n.description) chars.push(n.description); - return { - label: n.name, - value: n.name, - description: chars.join(" - "), - }; - })} - value={p.network.network} - onValueChange={(v) => { - if (p.network.type === "DefinedNetwork") - p.network.network = v as any; - p.onChange?.(); - }} - /> - )} - - {/* Network Filter */} - { - if (v && !p.network.nwfilterref) { - p.network.nwfilterref = { name: v, parameters: [] }; - } else if (v) { - p.network.nwfilterref!.name = v; - } else { - p.network.nwfilterref = undefined; - } - p.onChange?.(); - }} - options={[ - { label: "No network filer", value: undefined }, - ...p.networkFiltersList.map((v) => { - return { - value: v.name, - label: `${v.name} (${v.chain?.protocol ?? "unspecified"})`, - description: `${v.rules.length} rules - ${v.join_filters.length} joint filters`, - }; - }), - ]} - /> - - {p.network.nwfilterref && ( -
- { + if (p.network.type === "DefinedNetwork") + p.network.network = v as any; + p.onChange?.(); + }} /> -
+ + {/* Network Filter */} + { + if (v && !p.network.nwfilterref) { + p.network.nwfilterref = { name: v, parameters: [] }; + } else if (v) { + p.network.nwfilterref!.name = v; + } else { + p.network.nwfilterref = undefined; + } + p.onChange?.(); + }} + options={[ + { label: "No network filer", value: undefined }, + ...p.networkFiltersList.map((v) => { + return { + value: v.name, + label: `${v.name} (${v.chain?.protocol ?? "unspecified"})`, + description: `${v.rules.length} rules - ${v.join_filters.length} joint filters`, + }; + }), + ]} + /> + + {p.network.nwfilterref && ( +
+ +
+ )} + )} diff --git a/virtweb_frontend/src/widgets/vms/VMDetails.tsx b/virtweb_frontend/src/widgets/vms/VMDetails.tsx index 4342314..7f05c72 100644 --- a/virtweb_frontend/src/widgets/vms/VMDetails.tsx +++ b/virtweb_frontend/src/widgets/vms/VMDetails.tsx @@ -288,14 +288,7 @@ function VMDetailsTabStorage(p: DetailsInnerProps): React.ReactElement { } function VMDetailsTabNetwork(p: DetailsInnerProps): React.ReactElement { - return ( - - {/* Networks section */} - - - - - ); + return ; } function VMDetailsTabDanger(p: DetailsInnerProps): React.ReactElement {