import { useTheme } from "@emotion/react"; import { Box, Button, Container, Stack, Table, TableBody, TableContainer, TableHead, TableRow, TableSortLabel, } from "@mui/material"; import { useQueryState } from "nuqs"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { getGroupList } from "../../../api/api"; import { GroupEnt } from "../../../api/dashboard"; import { useAppDispatch } from "../../../redux/hooks"; import { NoWrapTableCell, SecondaryButton, StyledTableContainerPaper } from "../../Common/StyledComponents"; import Add from "../../Icons/Add"; import ArrowSync from "../../Icons/ArrowSync"; import PageContainer from "../../Pages/PageContainer"; import PageHeader from "../../Pages/PageHeader"; import TablePagination from "../Common/TablePagination"; import { OrderByQuery, OrderDirectionQuery, PageQuery, PageSizeQuery } from "../StoragePolicy/StoragePolicySetting"; import GroupRow from "./GroupRow"; import NewGroupDialog from "./NewGroupDIalog"; const GroupSetting = () => { const { t } = useTranslation("dashboard"); const theme = useTheme(); const dispatch = useAppDispatch(); const [loading, setLoading] = useState(true); const [groups, setGroups] = useState([]); const [page, setPage] = useQueryState(PageQuery, { defaultValue: "1" }); const [pageSize, setPageSize] = useQueryState(PageSizeQuery, { defaultValue: "10", }); const [orderBy, setOrderBy] = useQueryState(OrderByQuery, { defaultValue: "", }); const [orderDirection, setOrderDirection] = useQueryState(OrderDirectionQuery, { defaultValue: "desc" }); const [count, setCount] = useState(0); const [createNewOpen, setCreateNewOpen] = useState(false); const pageInt = parseInt(page) ?? 1; const pageSizeInt = parseInt(pageSize) ?? 11; useEffect(() => { fetchGroups(); }, [page, pageSize, orderBy, orderDirection]); const fetchGroups = () => { setLoading(true); dispatch( getGroupList({ page: pageInt, page_size: pageSizeInt, order_by: orderBy ?? "", order_direction: orderDirection ?? "desc", }), ) .then((res) => { setGroups(res.groups); setPageSize(res.pagination.page_size.toString()); setCount(res.pagination.total_items ?? 0); setLoading(false); }) .finally(() => { setLoading(false); }); }; const orderById = orderBy === "id" || orderBy === ""; const direction = orderDirection as "asc" | "desc"; const onSortClick = (field: string) => () => { const alreadySorted = orderBy === field || (field === "id" && orderById); setOrderBy(field); setOrderDirection(alreadySorted ? (direction === "asc" ? "desc" : "asc") : "asc"); }; return ( setCreateNewOpen(false)} /> }> {t("node.refresh")} {t("group.#")} {t("group.name")} {t("group.type")} {t("group.count")} {t("group.size")} {!loading && groups.map((group) => )} {loading && groups.length > 0 && groups.map((group) => )} {loading && groups.length === 0 && Array.from(Array(5)).map((_, index) => )}
{count > 0 && ( setPageSize(value.toString())} onChange={(_, value) => setPage(value.toString())} /> )}
); }; export default GroupSetting;