import DeleteIcon from "@mui/icons-material/Delete"; import VisibilityIcon from "@mui/icons-material/Visibility"; import { Button, IconButton, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip, } from "@mui/material"; import { filesize } from "filesize"; import React from "react"; import { VMApi, VMInfo } from "../api/VMApi"; import { AsyncWidget } from "../widgets/AsyncWidget"; import { RouterLink } from "../widgets/RouterLink"; import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer"; import { VMStatusWidget } from "../widgets/vms/VMStatusWidget"; import { useSnackbar } from "../hooks/providers/SnackbarProvider"; import { useConfirm } from "../hooks/providers/ConfirmDialogProvider"; export function VirtualMachinesRoute(): React.ReactElement { const [list, setList] = React.useState(); const loadKey = React.useRef(1); const load = async () => { setList(await VMApi.GetList()); }; const reload = () => { loadKey.current += 1; setList(undefined); }; return ( ( } > )} /> ); } function VMListWidget(p: { list: VMInfo[]; onReload: () => void; }): React.ReactElement { const confirm = useConfirm(); const snackbar = useSnackbar(); const deleteVM = async (v: VMInfo) => { try { if ( !(await confirm( `Do you really want to delete the vm ${v.name}? The operation CANNOT be undone!`, "Delete a VM", "DELETE" )) ) return; const keepData = !(await confirm( "Do you want to delete the files of the VM?", "Delete a VM", "Delete the data", "keep the data" )); await VMApi.Delete(v, keepData); snackbar("The VM was successfully deleted!"); p.onReload(); } catch (e) { console.error(e); snackbar("Failed to delete VM!"); } }; return ( Name Description Memory Status Actions {p.list.map((row) => ( {row.name} {row.description ?? ""} {filesize(row.memory * 1000 * 1000)} deleteVM(row)}> ))}
); }