diff --git a/striker-ui/components/CPU.tsx b/striker-ui/components/CPU.tsx index 40c4f8fa..c8af3d71 100644 --- a/striker-ui/components/CPU.tsx +++ b/striker-ui/components/CPU.tsx @@ -1,10 +1,14 @@ +import { useContext } from 'react'; import { Box } from '@material-ui/core'; import Panel from './Panel'; import { AllocationBar } from './Bars'; import { HeaderText, BodyText } from './Text'; import PeriodicFetch from '../lib/fetchers/periodicFetch'; +import { AnvilContext } from './AnvilContext'; + +const CPU = (): JSX.Element => { + const { uuid } = useContext(AnvilContext); -const CPU = ({ uuid }: { uuid: string }): JSX.Element => { const { data, isLoading } = PeriodicFetch( `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_cpu?anvil_uuid=`, uuid, diff --git a/striker-ui/components/Memory.tsx b/striker-ui/components/Memory.tsx index 1e8ce240..d972bb34 100644 --- a/striker-ui/components/Memory.tsx +++ b/striker-ui/components/Memory.tsx @@ -1,11 +1,14 @@ +import { useContext } from 'react'; import { Box } from '@material-ui/core'; import * as prettyBytes from 'pretty-bytes'; import Panel from './Panel'; import { AllocationBar } from './Bars'; import { HeaderText, BodyText } from './Text'; import PeriodicFetch from '../lib/fetchers/periodicFetch'; +import { AnvilContext } from './AnvilContext'; -const Memory = ({ uuid }: { uuid: string }): JSX.Element => { +const Memory = (): JSX.Element => { + const { uuid } = useContext(AnvilContext); const { data, isLoading } = PeriodicFetch( `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_memory?anvil_uuid=`, uuid, diff --git a/striker-ui/components/Network.tsx b/striker-ui/components/Network.tsx index 2c7c5445..6efc6f5b 100644 --- a/striker-ui/components/Network.tsx +++ b/striker-ui/components/Network.tsx @@ -1,11 +1,13 @@ +import { useContext } from 'react'; import { Box, Divider } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import { ClassNameMap } from '@material-ui/styles'; import Panel from './Panel'; import { HeaderText, BodyText } from './Text'; import PeriodicFetch from '../lib/fetchers/periodicFetch'; -import { BLUE, PURPLE_OFF, GREY } from '../lib/consts/DEFAULT_THEME'; +import { BLUE, PURPLE_OFF, DIVIDER } from '../lib/consts/DEFAULT_THEME'; import processNetworkData from './processNetwork'; +import { AnvilContext } from './AnvilContext'; const useStyles = makeStyles(() => ({ container: { @@ -21,7 +23,7 @@ const useStyles = makeStyles(() => ({ paddingLeft: 0, }, divider: { - background: GREY, + background: DIVIDER, }, decorator: { width: '20px', @@ -49,12 +51,13 @@ const selectDecorator = ( } }; -const Network = ({ anvil }: { anvil: AnvilListItem }): JSX.Element => { +const Network = (): JSX.Element => { + const { uuid } = useContext(AnvilContext); const classes = useStyles(); const { data } = PeriodicFetch( `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_network?anvil_uuid=`, - anvil?.anvil_uuid, + uuid, ); const processed = processNetworkData(data); diff --git a/striker-ui/components/Nodes/index.tsx b/striker-ui/components/Nodes/index.tsx index 22ecbaa9..41d56054 100644 --- a/striker-ui/components/Nodes/index.tsx +++ b/striker-ui/components/Nodes/index.tsx @@ -1,22 +1,30 @@ +import { useContext } from 'react'; import Panel from '../Panel'; import Text from '../Text/HeaderText'; import AnvilNode from './AnvilNode'; import PeriodicFetch from '../../lib/fetchers/periodicFetch'; +import { AnvilContext } from '../AnvilContext'; + +const Nodes = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => { + const { uuid } = useContext(AnvilContext); -const Nodes = ({ anvil }: { anvil: AnvilListItem }): JSX.Element => { const { data } = PeriodicFetch( `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_status?anvil_uuid=`, - anvil?.anvil_uuid, + uuid, ); return ( - { - return { ...node, ...data?.nodes[index] }; - })} - /> + {anvil.findIndex((a) => a.anvil_uuid === uuid) !== -1 && ( + a.anvil_uuid === uuid)].nodes.map( + (node, index) => { + return { ...node, ...data?.nodes[index] }; + }, + )} + /> + )} ); }; diff --git a/striker-ui/components/SharedStorage.tsx b/striker-ui/components/SharedStorage.tsx index 115ff022..7bef0082 100644 --- a/striker-ui/components/SharedStorage.tsx +++ b/striker-ui/components/SharedStorage.tsx @@ -1,16 +1,19 @@ -import { Box } from '@material-ui/core'; +import { useContext } from 'react'; +import { Box } from '@material-ui/core'; import { BodyText, HeaderText } from './Text'; import Panel from './Panel'; import SharedStorageNode from './SharedStorageNode'; import InnerPanel from './InnerPanel'; import PanelHeader from './PanelHeader'; import PeriodicFetch from '../lib/fetchers/periodicFetch'; +import { AnvilContext } from './AnvilContext'; -const SharedStorage = ({ anvil }: { anvil: AnvilListItem }): JSX.Element => { +const SharedStorage = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => { + const { uuid } = useContext(AnvilContext); const { data } = PeriodicFetch( `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_shared_storage?anvil_uuid=`, - anvil?.anvil_uuid, + uuid, ); return ( @@ -33,8 +36,13 @@ const SharedStorage = ({ anvil }: { anvil: AnvilListItem }): JSX.Element => { index: number, ): JSX.Element => ( a.anvil_uuid === uuid)] + .nodes[index], + }} + key={fs.nodes[index].free} /> ), )}