import { AppBar, Autocomplete, Box, CircularProgress, Dialog, Grid, IconButton, TextField, Toolbar } from '@mui/material' import { Fragment, useEffect, useState } from 'react' import { IRegion } from '../interfaces/fuel' import { useRegions, useServers, useServersInfo } from '../hooks/swrHooks' import FullFeaturedCrudGrid from './TableEditable' import ServerService from '../services/ServersService' import { GridColDef, GridRenderCellParams } from '@mui/x-data-grid' import { Close, Cloud, CloudOff } from '@mui/icons-material' import ServerData from './ServerData' import { IServersInfo } from '../interfaces/servers' import CardInfo from './CardInfo/CardInfo' import CardInfoLabel from './CardInfo/CardInfoLabel' import CardInfoChip from './CardInfo/CardInfoChip' import { useDebounce } from '@uidotdev/usehooks' export default function ServersView() { const [options, setOptions] = useState([]) const [search, setSearch] = useState("") const debouncedSearch = useDebounce(search, 500) const [selectedOption, setSelectedOption] = useState(null) const { regions, isLoading } = useRegions(10, 1, debouncedSearch) const { serversInfo } = useServersInfo(selectedOption?.id) const [serverDataOpen, setServerDataOpen] = useState(false) const [currentServerData, setCurrentServerData] = useState(null) useEffect(() => { if (regions) { setOptions([...regions]) } }, [regions]) const { servers, isLoading: serversLoading } = useServers(selectedOption?.id, 0, 10) const serversColumns: GridColDef[] = [ //{ field: 'id', headerName: 'ID', type: "number" }, { field: 'name', headerName: 'Название', type: "string", editable: true, }, { field: 'region_id', editable: true, renderCell: (params) => (
{params.value}
), renderEditCell: (params: GridRenderCellParams) => ( setSearch(value)} onChange={(_, value) => { params.value = value }} isOptionEqualToValue={(option: IRegion, value: IRegion) => option.name === value.name} getOptionLabel={(option: IRegion) => option.name ? option.name : ""} options={options} loading={isLoading} value={params.value} renderInput={(params) => ( {isLoading ? : null} {params.InputProps.endAdornment} ) }} /> )} /> ), width: 200 } ] return ( <> { setServerDataOpen(false) }} aria-labelledby="modal-modal-title" aria-describedby="modal-modal-description"> { setServerDataOpen(false) }} aria-label="close" > {currentServerData && } {serversInfo && {serversInfo.map((serverInfo: IServersInfo) => ( } iconOff={} /> ))} } setSearch(value)} onChange={(_, value) => setSelectedOption(value)} isOptionEqualToValue={(option: IRegion, value: IRegion) => option.id === value.id} getOptionLabel={(option: IRegion) => option.name ? option.name : ""} options={options} loading={isLoading} value={selectedOption} renderInput={(params) => ( {isLoading ? : null} {params.InputProps.endAdornment} ) }} /> )} /> } onSave={() => { }} onDelete={ServerService.removeServer} initialRows={servers} columns={serversColumns} actions onRowClick={(params) => { setCurrentServerData(params.row) setServerDataOpen(true) }} /> ) }