diff --git a/striker-ui/components/Network/Network.tsx b/striker-ui/components/Network/Network.tsx index 868e4497..0376ee48 100644 --- a/striker-ui/components/Network/Network.tsx +++ b/striker-ui/components/Network/Network.tsx @@ -1,17 +1,20 @@ +import { Box, Divider, styled } from '@mui/material'; import { useContext } from 'react'; -import { Box, Divider } from '@mui/material'; -import { styled } from '@mui/material/styles'; -import { Panel } from '../Panels'; -import { HeaderText, BodyText } from '../Text'; -import periodicFetch from '../../lib/fetchers/periodicFetch'; + import { DIVIDER, LARGE_MOBILE_BREAKPOINT, } from '../../lib/consts/DEFAULT_THEME'; -import processNetworkData from './processNetwork'; + 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'; +import useProtect from '../../hooks/useProtect'; +import useProtectedState from '../../hooks/useProtectedState'; const PREFIX = 'Network'; @@ -68,26 +71,35 @@ const selectDecorator = (state: string): Colours => { const Network = (): JSX.Element => { const { uuid } = useContext(AnvilContext); + const { protect } = useProtect(); + + const [processed, setProcessed] = useProtectedState< + ProcessedNetwork | undefined + >(undefined, protect); - const { data, isLoading } = periodicFetch( + const { isLoading } = periodicFetch( `${process.env.NEXT_PUBLIC_API_URL}/get_networks?anvil_uuid=${uuid}`, + { + onSuccess: (data) => { + setProcessed(processNetworkData(data)); + }, + }, ); - const processed = processNetworkData(data); return ( {!isLoading ? ( - {data && + {processed && processed.bonds.map((bond: ProcessedBond) => ( <> diff --git a/striker-ui/components/Network/processNetwork.ts b/striker-ui/components/Network/processNetwork.ts index 0a321312..c08b11af 100644 --- a/striker-ui/components/Network/processNetwork.ts +++ b/striker-ui/components/Network/processNetwork.ts @@ -2,7 +2,7 @@ const processNetworkData = (data: AnvilNetwork): ProcessedNetwork => { const processedBonds: string[] = []; const displayBonds: ProcessedNetwork = { bonds: [] }; - data?.hosts.forEach((host) => { + data.hosts.forEach((host) => { host.bonds.forEach((bond) => { const index = processedBonds.findIndex( (processed: string) => processed === bond.bond_name, @@ -33,7 +33,6 @@ const processNetworkData = (data: AnvilNetwork): ProcessedNetwork => { }); }); - /* eslint-disable no-param-reassign */ displayBonds.bonds.forEach((bond) => { const hostIndex = bond.hosts[0].link.link_speed > bond.hosts[1].link.link_speed ? 1 : 0;