diff --git a/frontend_reactjs/src/components/ServerHardware.tsx b/frontend_reactjs/src/components/ServerHardware.tsx index 9aebcf3..718cc21 100644 --- a/frontend_reactjs/src/components/ServerHardware.tsx +++ b/frontend_reactjs/src/components/ServerHardware.tsx @@ -1,5 +1,5 @@ import { AppBar, Autocomplete, CircularProgress, Dialog, IconButton, TextField, Toolbar } from '@mui/material' -import { Fragment, useEffect, useState } from 'react' +import { Fragment, useState } from 'react' import { IRegion } from '../interfaces/fuel' import { useHardwares, useServers } from '../hooks/swrHooks' import FullFeaturedCrudGrid from './TableEditable' @@ -10,19 +10,12 @@ import ServerData from './ServerData' export default function ServerHardware() { const [open, setOpen] = useState(false) - const [options, setOptions] = useState([]) const [selectedOption, setSelectedOption] = useState(null) const { servers, isLoading } = useServers() const [serverDataOpen, setServerDataOpen] = useState(false) const [currentServerData, setCurrentServerData] = useState(null) - useEffect(() => { - if (servers) { - setOptions([...servers]) - } - }, [servers]) - const handleInputChange = (value: string) => { return value } @@ -81,43 +74,43 @@ export default function ServerHardware() { {serversLoading ? : - hardwares && { - setOpen(true) - }} - onClose={() => { - setOpen(false) - }} - onInputChange={(_, value) => handleInputChange(value)} - onChange={(_, value) => handleOptionChange(value)} - filterOptions={(x) => x} - isOptionEqualToValue={(option: IRegion, value: IRegion) => option.name === value.name} - getOptionLabel={(option: IRegion) => option.name ? option.name : ""} - options={options} - loading={isLoading} - value={selectedOption} - renderInput={(params) => ( - - {isLoading ? : null} - {params.InputProps.endAdornment} - - ) - }} /> - )} />} + autoComplete={ + { + setOpen(true) + }} + onClose={() => { + setOpen(false) + }} + onInputChange={(_, value) => handleInputChange(value)} + onChange={(_, value) => handleOptionChange(value)} + filterOptions={(x) => x} + isOptionEqualToValue={(option: IRegion, value: IRegion) => option.name === value.name} + getOptionLabel={(option: IRegion) => option.name ? option.name : ""} + options={servers || []} + loading={isLoading} + value={selectedOption} + renderInput={(params) => ( + + {isLoading ? : null} + {params.InputProps.endAdornment} + + ) + }} /> + )} />} onSave={() => { }} onDelete={ServerService.removeServer} - initialRows={hardwares} + initialRows={hardwares || []} columns={hardwareColumns} actions onRowClick={(params) => { diff --git a/frontend_reactjs/src/components/ServerIpsView.tsx b/frontend_reactjs/src/components/ServerIpsView.tsx index 127b61c..6d1ccd4 100644 --- a/frontend_reactjs/src/components/ServerIpsView.tsx +++ b/frontend_reactjs/src/components/ServerIpsView.tsx @@ -1,5 +1,5 @@ import { AppBar, Autocomplete, CircularProgress, Dialog, IconButton, TextField, Toolbar } from '@mui/material' -import { Fragment, useEffect, useState } from 'react' +import { Fragment, useState } from 'react' import { IRegion } from '../interfaces/fuel' import { useServerIps, useServers } from '../hooks/swrHooks' import FullFeaturedCrudGrid from './TableEditable' @@ -10,19 +10,12 @@ import ServerData from './ServerData' export default function ServerIpsView() { const [open, setOpen] = useState(false) - const [options, setOptions] = useState([]) const [selectedOption, setSelectedOption] = useState(null) const { servers, isLoading } = useServers() const [serverDataOpen, setServerDataOpen] = useState(false) const [currentServerData, setCurrentServerData] = useState(null) - useEffect(() => { - if (servers) { - setOptions([...servers]) - } - }, [servers]) - const handleInputChange = (value: string) => { return value } @@ -79,43 +72,43 @@ export default function ServerIpsView() { {serversLoading ? : - serverIps && { - setOpen(true) - }} - onClose={() => { - setOpen(false) - }} - onInputChange={(_, value) => handleInputChange(value)} - onChange={(_, value) => handleOptionChange(value)} - filterOptions={(x) => x} - isOptionEqualToValue={(option: IRegion, value: IRegion) => option.name === value.name} - getOptionLabel={(option: IRegion) => option.name ? option.name : ""} - options={options} - loading={isLoading} - value={selectedOption} - renderInput={(params) => ( - - {isLoading ? : null} - {params.InputProps.endAdornment} - - ) - }} /> - )} />} + autoComplete={ + { + setOpen(true) + }} + onClose={() => { + setOpen(false) + }} + onInputChange={(_, value) => handleInputChange(value)} + onChange={(_, value) => handleOptionChange(value)} + filterOptions={(x) => x} + isOptionEqualToValue={(option: IRegion, value: IRegion) => option.name === value.name} + getOptionLabel={(option: IRegion) => option.name ? option.name : ""} + options={servers || []} + loading={isLoading} + value={selectedOption} + renderInput={(params) => ( + + {isLoading ? : null} + {params.InputProps.endAdornment} + + ) + }} /> + )} />} onSave={() => { }} onDelete={ServerService.removeServer} - initialRows={serverIps} + initialRows={serverIps || []} columns={serverIpsColumns} actions onRowClick={(params) => { diff --git a/frontend_reactjs/src/components/ServerStorages.tsx b/frontend_reactjs/src/components/ServerStorages.tsx index 9369f88..2913a51 100644 --- a/frontend_reactjs/src/components/ServerStorages.tsx +++ b/frontend_reactjs/src/components/ServerStorages.tsx @@ -1,5 +1,5 @@ import { AppBar, Autocomplete, CircularProgress, Dialog, IconButton, TextField, Toolbar } from '@mui/material' -import { Fragment, useEffect, useState } from 'react' +import { Fragment, useState } from 'react' import { IRegion } from '../interfaces/fuel' import { useHardwares, useStorages } from '../hooks/swrHooks' import FullFeaturedCrudGrid from './TableEditable' @@ -10,19 +10,12 @@ import ServerData from './ServerData' export default function ServerStorage() { const [open, setOpen] = useState(false) - const [options, setOptions] = useState([]) const [selectedOption, setSelectedOption] = useState(null) const { hardwares, isLoading } = useHardwares() const [serverDataOpen, setServerDataOpen] = useState(false) const [currentServerData, setCurrentServerData] = useState(null) - useEffect(() => { - if (hardwares) { - setOptions([...hardwares]) - } - }, [hardwares]) - const handleInputChange = (value: string) => { return value } @@ -78,43 +71,43 @@ export default function ServerStorage() { {serversLoading ? : - storages && { - setOpen(true) - }} - onClose={() => { - setOpen(false) - }} - onInputChange={(_, value) => handleInputChange(value)} - onChange={(_, value) => handleOptionChange(value)} - filterOptions={(x) => x} - isOptionEqualToValue={(option: IRegion, value: IRegion) => option.name === value.name} - getOptionLabel={(option: IRegion) => option.name ? option.name : ""} - options={options} - loading={isLoading} - value={selectedOption} - renderInput={(params) => ( - - {isLoading ? : null} - {params.InputProps.endAdornment} - - ) - }} /> - )} />} + autoComplete={ + { + setOpen(true) + }} + onClose={() => { + setOpen(false) + }} + onInputChange={(_, value) => handleInputChange(value)} + onChange={(_, value) => handleOptionChange(value)} + filterOptions={(x) => x} + isOptionEqualToValue={(option: IRegion, value: IRegion) => option.name === value.name} + getOptionLabel={(option: IRegion) => option.name ? option.name : ""} + options={hardwares || []} + loading={isLoading} + value={selectedOption} + renderInput={(params) => ( + + {isLoading ? : null} + {params.InputProps.endAdornment} + + ) + }} /> + )} />} onSave={() => { }} onDelete={ServerService.removeServer} - initialRows={storages} + initialRows={storages || []} columns={storageColumns} actions onRowClick={(params) => { diff --git a/frontend_reactjs/src/components/ServersView.tsx b/frontend_reactjs/src/components/ServersView.tsx index 9cb3d56..d1f21df 100644 --- a/frontend_reactjs/src/components/ServersView.tsx +++ b/frontend_reactjs/src/components/ServersView.tsx @@ -1,5 +1,5 @@ import { AppBar, Autocomplete, Box, CircularProgress, Dialog, Grid, IconButton, TextField, Toolbar } from '@mui/material' -import { Fragment, useEffect, useState } from 'react' +import { Fragment, useState } from 'react' import { IRegion } from '../interfaces/fuel' import { useRegions, useServers, useServersInfo } from '../hooks/swrHooks' import FullFeaturedCrudGrid from './TableEditable' @@ -14,7 +14,6 @@ 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) @@ -28,12 +27,6 @@ export default function ServersView() { 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[] = [ @@ -58,7 +51,7 @@ export default function ServersView() { }} isOptionEqualToValue={(option: IRegion, value: IRegion) => option.name === value.name} getOptionLabel={(option: IRegion) => option.name ? option.name : ""} - options={options} + options={regions || []} loading={isLoading} value={params.value} renderInput={(params) => ( @@ -147,7 +140,7 @@ export default function ServersView() { onChange={(_, value) => setSelectedOption(value)} isOptionEqualToValue={(option: IRegion, value: IRegion) => option.id === value.id} getOptionLabel={(option: IRegion) => option.name ? option.name : ""} - options={options} + options={regions || []} loading={isLoading} value={selectedOption} renderInput={(params) => ( diff --git a/frontend_reactjs/src/pages/Reports.tsx b/frontend_reactjs/src/pages/Reports.tsx index 877d524..aeb5003 100644 --- a/frontend_reactjs/src/pages/Reports.tsx +++ b/frontend_reactjs/src/pages/Reports.tsx @@ -10,7 +10,6 @@ import { mutate } from "swr" export default function Reports() { const [download, setDownload] = useState(false) - const [options, setOptions] = useState([]) const [search, setSearch] = useState("") const debouncedSearch = useDebounce(search, 500) const [selectedOption, setSelectedOption] = useState(null) @@ -20,12 +19,6 @@ export default function Reports() { const { reportExported } = useReportExport(selectedOption?.id, download) - useEffect(() => { - if (cities) { - setOptions([...cities]) - } - }, [cities]) - const refreshReport = async () => { mutate(`/info/reports/${selectedOption?.id}?to_export=false`) } @@ -57,7 +50,7 @@ export default function Reports() { onChange={(_, value) => setSelectedOption(value)} isOptionEqualToValue={(option: ICity, value: ICity) => option.id === value.id} getOptionLabel={(option: ICity) => option.name ? option.name : ""} - options={options} + options={cities || []} loading={isLoading} value={selectedOption} renderInput={(params) => (