Reorganize network tab

This commit is contained in:
Pierre HUBERT 2024-01-02 20:09:42 +01:00
parent 0175726696
commit 085deff4f7
3 changed files with 98 additions and 91 deletions

View File

@ -2,11 +2,12 @@ import { Grid, Paper, Typography } from "@mui/material";
import React, { PropsWithChildren } from "react"; import React, { PropsWithChildren } from "react";
export function EditSection( export function EditSection(
p: { title: string; actions?: React.ReactElement } & PropsWithChildren p: { title?: string; actions?: React.ReactElement } & PropsWithChildren
): React.ReactElement { ): React.ReactElement {
return ( return (
<Grid item sm={12} md={6}> <Grid item sm={12} md={6}>
<Paper style={{ margin: "10px", padding: "10px" }}> <Paper style={{ margin: "10px", padding: "10px" }}>
{(p.title || p.actions) && (
<span <span
style={{ style={{
display: "flex", display: "flex",
@ -14,11 +15,14 @@ export function EditSection(
alignItems: "center", alignItems: "center",
}} }}
> >
{p.title && (
<Typography variant="h5" style={{ marginBottom: "15px" }}> <Typography variant="h5" style={{ marginBottom: "15px" }}>
{p.title} {p.title}
</Typography> </Typography>
)}
{p.actions} {p.actions}
</span> </span>
)}
{p.children} {p.children}
</Paper> </Paper>
</Grid> </Grid>

View File

@ -4,6 +4,7 @@ import DeleteIcon from "@mui/icons-material/Delete";
import { import {
Avatar, Avatar,
Button, Button,
Grid,
IconButton, IconButton,
ListItem, ListItem,
ListItemAvatar, ListItemAvatar,
@ -19,6 +20,7 @@ import { randomMacAddress } from "../../utils/RandUtils";
import { MACInput } from "./MACInput"; import { MACInput } from "./MACInput";
import { SelectInput } from "./SelectInput"; import { SelectInput } from "./SelectInput";
import { VMNetworkFilterParameters } from "./VMNetworkFilterParameters"; import { VMNetworkFilterParameters } from "./VMNetworkFilterParameters";
import { EditSection } from "./EditSection";
export function VMNetworksList(p: { export function VMNetworksList(p: {
vm: VMInfo; vm: VMInfo;
@ -37,8 +39,16 @@ export function VMNetworksList(p: {
return ( return (
<> <>
{p.editable && (
<div style={{ textAlign: "right", marginTop: "5px" }}>
<Button onClick={addNew}>Add a new network interface</Button>
</div>
)}
<Grid container spacing={2}>
{/* networks list */} {/* networks list */}
{p.vm.networks.map((n, num) => ( {p.vm.networks.map((n, num) => (
<EditSection key={num}>
<NetworkInfoWidget <NetworkInfoWidget
key={num} key={num}
network={n} network={n}
@ -48,11 +58,9 @@ export function VMNetworksList(p: {
}} }}
{...p} {...p}
/> />
</EditSection>
))} ))}
</Grid>
{p.editable && (
<Button onClick={addNew}>Add a new network interface</Button>
)}
</> </>
); );
} }
@ -141,6 +149,7 @@ function NetworkInfoWidget(p: {
/> />
{p.network.type === "DefinedNetwork" && ( {p.network.type === "DefinedNetwork" && (
<>
<SelectInput <SelectInput
editable={p.editable} editable={p.editable}
label="Defined network" label="Defined network"
@ -163,7 +172,6 @@ function NetworkInfoWidget(p: {
p.onChange?.(); p.onChange?.();
}} }}
/> />
)}
{/* Network Filter */} {/* Network Filter */}
<SelectInput <SelectInput
@ -200,6 +208,8 @@ function NetworkInfoWidget(p: {
/> />
</div> </div>
)} )}
</>
)}
</div> </div>
</> </>
); );

View File

@ -288,14 +288,7 @@ function VMDetailsTabStorage(p: DetailsInnerProps): React.ReactElement {
} }
function VMDetailsTabNetwork(p: DetailsInnerProps): React.ReactElement { function VMDetailsTabNetwork(p: DetailsInnerProps): React.ReactElement {
return ( return <VMNetworksList {...p} />;
<Grid container spacing={2}>
{/* Networks section */}
<EditSection title="Networks">
<VMNetworksList {...p} />
</EditSection>
</Grid>
);
} }
function VMDetailsTabDanger(p: DetailsInnerProps): React.ReactElement { function VMDetailsTabDanger(p: DetailsInnerProps): React.ReactElement {