import { Box, Divider, styled } from '@mui/material'; import { useContext, useState } from 'react'; import API_BASE_URL from '../../lib/consts/API_BASE_URL'; import { DIVIDER, LARGE_MOBILE_BREAKPOINT, } from '../../lib/consts/DEFAULT_THEME'; import { AnvilContext } from '../AnvilContext'; import Decorator, { Colours } from '../Decorator'; import { Panel } from '../Panels'; import periodicFetch from '../../lib/fetchers/periodicFetch'; import processNetworkData from './processNetwork'; import Spinner from '../Spinner'; import { HeaderText, BodyText } from '../Text'; const PREFIX = 'Network'; const classes = { container: `${PREFIX}-container`, root: `${PREFIX}-root`, noPaddingLeft: `${PREFIX}-noPaddingLeft`, divider: `${PREFIX}-divider`, verticalDivider: `${PREFIX}-verticalDivider`, }; const StyledDiv = styled('div')(({ theme }) => ({ [`& .${classes.container}`]: { width: '100%', overflow: 'auto', height: '32vh', paddingRight: '.3em', [theme.breakpoints.down(LARGE_MOBILE_BREAKPOINT)]: { height: '100%', overflow: 'hidden', }, }, [`& .${classes.root}`]: { paddingTop: '.7em', paddingBottom: '.7em', }, [`& .${classes.noPaddingLeft}`]: { paddingLeft: 0, }, [`& .${classes.divider}`]: { backgroundColor: DIVIDER, }, [`& .${classes.verticalDivider}`]: { height: '3.5em', }, })); const selectDecorator = (state: string): Colours => { switch (state) { case 'optimal': return 'ok'; case 'degraded': return 'warning'; case 'down': return 'error'; default: return 'warning'; } }; const Network = (): JSX.Element => { const { uuid } = useContext(AnvilContext); const [processed, setProcessed] = useState(); const { isLoading } = periodicFetch( `${API_BASE_URL}/anvil/${uuid}/network`, { onSuccess: (data) => { setProcessed(processNetworkData(data)); }, }, ); return ( {!isLoading ? ( {processed && processed.bonds.map((bond: ProcessedBond) => ( <> {bond.hosts.map( (host, index: number): JSX.Element => ( <> {index !== bond.hosts.length - 1 && ( )} ), )} ))} ) : ( )} ); }; export default Network;