Start to implement action buttons for group VMs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Pierre HUBERT 2024-12-05 23:06:22 +01:00
parent 2a50e41894
commit 0c2cce397e
2 changed files with 82 additions and 8 deletions

View File

@ -0,0 +1,62 @@
import { Button, Toolbar, Tooltip } from "@fluentui/react-components";
import { PlayRegular } from "@fluentui/react-icons";
import { VMGroup } from "../api/ServerApi";
import { VMInfo, VMState } from "../api/VMApi";
export function GroupVMAction(p: {
group: VMGroup;
state?: VMState;
vm?: VMInfo;
}): React.ReactElement {
return (
<Toolbar>
<GroupVMButton
enabled={p.group.can_start}
icon={<PlayRegular />}
tooltip="Start"
group={p.group}
vm={p.vm}
allowedStates={["Shutdown", "Shutoff", "Crashed"]}
currState={p.state}
needConfirm={false}
action={async () => {}}
/>
</Toolbar>
);
}
function GroupVMButton(p: {
enabled: boolean;
icon: React.ReactElement;
action: (group: VMGroup, vm?: VMGroup) => Promise<void>;
tooltip: string;
currState?: VMState;
allowedStates: VMState[];
group: VMGroup;
vm?: VMInfo;
needConfirm: boolean;
}): React.ReactElement {
const process = () => {};
const allowed =
!p.vm || (p.currState && p.allowedStates.includes(p.currState));
if (!p.enabled) return <></>;
return (
<Tooltip
content={`${p.tooltip} ${
p.vm ? `the VM ${p.vm.name}` : `all the VM of the group ${p.group.id}`
}`}
relationship="description"
withArrow
>
<Button
icon={p.icon}
onClick={process}
disabled={!allowed}
appearance="subtle"
/>
</Tooltip>
);
}

View File

@ -11,11 +11,11 @@ import {
} from "@fluentui/react-components"; } from "@fluentui/react-components";
import { Desktop24Regular } from "@fluentui/react-icons"; import { Desktop24Regular } from "@fluentui/react-icons";
import { filesize } from "filesize"; import { filesize } from "filesize";
import { Rights, VMGroup } from "../api/ServerApi";
import { VMState } from "../api/VMApi";
import React from "react"; import React from "react";
import { GroupApi, GroupVMState } from "../api/GroupApi"; import { GroupApi, GroupVMState } from "../api/GroupApi";
import { Rights, VMGroup } from "../api/ServerApi";
import { useToast } from "../hooks/providers/ToastProvider"; import { useToast } from "../hooks/providers/ToastProvider";
import { GroupVMAction } from "./GroupVMAction";
export function GroupsWidget(p: { rights: Rights }): React.ReactElement { export function GroupsWidget(p: { rights: Rights }): React.ReactElement {
return ( return (
@ -61,12 +61,14 @@ function GroupInfo(p: { group: VMGroup }): React.ReactElement {
flexDirection: "column", flexDirection: "column",
}} }}
> >
<div style={{ display: "flex", justifyContent: "space-between" }}>
<Title3 style={{ marginLeft: "10px" }}>{p.group.id}</Title3> <Title3 style={{ marginLeft: "10px" }}>{p.group.id}</Title3>
<Table arial-label="Default table" style={{ minWidth: "510px" }}> <GroupVMAction group={p.group} />
</div>
<Table sortable>
<TableHeader> <TableHeader>
<TableRow> <TableRow>
<TableHeaderCell>Name</TableHeaderCell> <TableHeaderCell>VM</TableHeaderCell>
<TableHeaderCell>Description</TableHeaderCell>
<TableHeaderCell>Resources</TableHeaderCell> <TableHeaderCell>Resources</TableHeaderCell>
<TableHeaderCell>State</TableHeaderCell> <TableHeaderCell>State</TableHeaderCell>
<TableHeaderCell>Actions</TableHeaderCell> <TableHeaderCell>Actions</TableHeaderCell>
@ -76,17 +78,27 @@ function GroupInfo(p: { group: VMGroup }): React.ReactElement {
{p.group.vms.map((item) => ( {p.group.vms.map((item) => (
<TableRow key={item.uuid}> <TableRow key={item.uuid}>
<TableCell> <TableCell>
<TableCellLayout media={<Desktop24Regular />}> <TableCellLayout
media={<Desktop24Regular />}
appearance="primary"
description={item.description}
>
{item.name} {item.name}
</TableCellLayout> </TableCellLayout>
</TableCell> </TableCell>
<TableCell>{item.description}</TableCell>
<TableCell> <TableCell>
{item.architecture} &bull; RAM :{" "} {item.architecture} &bull; RAM :{" "}
{filesize(item.memory * 1000 * 1000)} &bull; {item.number_vcpu}{" "} {filesize(item.memory * 1000 * 1000)} &bull; {item.number_vcpu}{" "}
vCPU vCPU
</TableCell> </TableCell>
<TableCell>{state?.[item.uuid] ?? ""}</TableCell> <TableCell>{state?.[item.uuid] ?? ""}</TableCell>
<TableCell>
<GroupVMAction
group={p.group}
state={state?.[item.uuid]}
vm={item}
/>
</TableCell>
</TableRow> </TableRow>
))} ))}
</TableBody> </TableBody>