Sort VM by groups in VM list
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
20e6d7931e
commit
8b16ce0c5d
@ -1,3 +1,5 @@
|
|||||||
|
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
|
||||||
|
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
|
||||||
import VisibilityIcon from "@mui/icons-material/Visibility";
|
import VisibilityIcon from "@mui/icons-material/Visibility";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@ -15,6 +17,7 @@ import {
|
|||||||
import { filesize } from "filesize";
|
import { filesize } from "filesize";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { GroupApi } from "../api/GroupApi";
|
||||||
import { VMApi, VMInfo, VMState } from "../api/VMApi";
|
import { VMApi, VMInfo, VMState } from "../api/VMApi";
|
||||||
import { AsyncWidget } from "../widgets/AsyncWidget";
|
import { AsyncWidget } from "../widgets/AsyncWidget";
|
||||||
import { RouterLink } from "../widgets/RouterLink";
|
import { RouterLink } from "../widgets/RouterLink";
|
||||||
@ -22,11 +25,13 @@ import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
|
|||||||
import { VMStatusWidget } from "../widgets/vms/VMStatusWidget";
|
import { VMStatusWidget } from "../widgets/vms/VMStatusWidget";
|
||||||
|
|
||||||
export function VMListRoute(): React.ReactElement {
|
export function VMListRoute(): React.ReactElement {
|
||||||
|
const [groups, setGroups] = React.useState<Array<string | undefined>>();
|
||||||
const [list, setList] = React.useState<VMInfo[] | undefined>();
|
const [list, setList] = React.useState<VMInfo[] | undefined>();
|
||||||
|
|
||||||
const loadKey = React.useRef(1);
|
const loadKey = React.useRef(1);
|
||||||
|
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
|
setGroups([undefined, ...(await GroupApi.GetList())]);
|
||||||
setList(await VMApi.GetList());
|
setList(await VMApi.GetList());
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -52,7 +57,7 @@ export function VMListRoute(): React.ReactElement {
|
|||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<VMListWidget list={list!} onReload={reload} />
|
<VMListWidget list={list!} groups={groups!} onReload={reload} />
|
||||||
</VirtWebRouteContainer>
|
</VirtWebRouteContainer>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@ -60,13 +65,25 @@ export function VMListRoute(): React.ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function VMListWidget(p: {
|
function VMListWidget(p: {
|
||||||
|
groups: Array<string | undefined>;
|
||||||
list: VMInfo[];
|
list: VMInfo[];
|
||||||
onReload: () => void;
|
onReload: () => void;
|
||||||
}): React.ReactElement {
|
}): React.ReactElement {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const [hiddenGroups, setHiddenGroups] = React.useState<
|
||||||
|
Set<string | undefined>
|
||||||
|
>(new Set());
|
||||||
|
|
||||||
const [runningVMs, setRunningVMs] = React.useState<Set<string>>(new Set());
|
const [runningVMs, setRunningVMs] = React.useState<Set<string>>(new Set());
|
||||||
|
|
||||||
|
const toggleHiddenGroup = (g: string | undefined) => {
|
||||||
|
if (hiddenGroups.has(g)) hiddenGroups.delete(g);
|
||||||
|
else hiddenGroups.add(g);
|
||||||
|
|
||||||
|
setHiddenGroups(new Set([...hiddenGroups]));
|
||||||
|
};
|
||||||
|
|
||||||
const updateVMState = (v: VMInfo, s: VMState) => {
|
const updateVMState = (v: VMInfo, s: VMState) => {
|
||||||
const running = s !== "Shutoff";
|
const running = s !== "Shutoff";
|
||||||
if (runningVMs.has(v.name) === running) {
|
if (runningVMs.has(v.name) === running) {
|
||||||
@ -93,7 +110,28 @@ function VMListWidget(p: {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{p.list.map((row) => (
|
{p.groups.map((g, num) => (
|
||||||
|
<React.Fragment key={num}>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell
|
||||||
|
style={{ paddingBottom: 2, paddingTop: 2 }}
|
||||||
|
colSpan={6}
|
||||||
|
>
|
||||||
|
<IconButton size="small" onClick={() => toggleHiddenGroup(g)}>
|
||||||
|
{!hiddenGroups?.has(g) ? (
|
||||||
|
<KeyboardArrowUpIcon />
|
||||||
|
) : (
|
||||||
|
<KeyboardArrowDownIcon />
|
||||||
|
)}
|
||||||
|
</IconButton>
|
||||||
|
{g ?? "default"}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
{!hiddenGroups.has(g) &&
|
||||||
|
p.list
|
||||||
|
.filter((row) => row.group === g)
|
||||||
|
.map((row) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
hover
|
hover
|
||||||
key={row.name}
|
key={row.name}
|
||||||
@ -123,6 +161,8 @@ function VMListWidget(p: {
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
</React.Fragment>
|
||||||
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
<TableFooter>
|
<TableFooter>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
Loading…
Reference in New Issue
Block a user