refactor: use context to display anvil info in CPU, Memory, Network, Storage and Nodes components

main
Josue 4 years ago committed by Tsu-ba-me
parent 2c795383d2
commit bfbefa74c6
  1. 6
      striker-ui/components/CPU.tsx
  2. 5
      striker-ui/components/Memory.tsx
  3. 11
      striker-ui/components/Network.tsx
  4. 22
      striker-ui/components/Nodes/index.tsx
  5. 18
      striker-ui/components/SharedStorage.tsx

@ -1,10 +1,14 @@
import { useContext } from 'react';
import { Box } from '@material-ui/core'; import { Box } from '@material-ui/core';
import Panel from './Panel'; import Panel from './Panel';
import { AllocationBar } from './Bars'; import { AllocationBar } from './Bars';
import { HeaderText, BodyText } from './Text'; import { HeaderText, BodyText } from './Text';
import PeriodicFetch from '../lib/fetchers/periodicFetch'; 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<AnvilCPU>( const { data, isLoading } = PeriodicFetch<AnvilCPU>(
`${process.env.NEXT_PUBLIC_API_URL}/anvils/get_cpu?anvil_uuid=`, `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_cpu?anvil_uuid=`,
uuid, uuid,

@ -1,11 +1,14 @@
import { useContext } from 'react';
import { Box } from '@material-ui/core'; import { Box } from '@material-ui/core';
import * as prettyBytes from 'pretty-bytes'; import * as prettyBytes from 'pretty-bytes';
import Panel from './Panel'; import Panel from './Panel';
import { AllocationBar } from './Bars'; import { AllocationBar } from './Bars';
import { HeaderText, BodyText } from './Text'; import { HeaderText, BodyText } from './Text';
import PeriodicFetch from '../lib/fetchers/periodicFetch'; 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<AnvilMemory>( const { data, isLoading } = PeriodicFetch<AnvilMemory>(
`${process.env.NEXT_PUBLIC_API_URL}/anvils/get_memory?anvil_uuid=`, `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_memory?anvil_uuid=`,
uuid, uuid,

@ -1,11 +1,13 @@
import { useContext } from 'react';
import { Box, Divider } from '@material-ui/core'; import { Box, Divider } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles'; import { makeStyles } from '@material-ui/core/styles';
import { ClassNameMap } from '@material-ui/styles'; import { ClassNameMap } from '@material-ui/styles';
import Panel from './Panel'; import Panel from './Panel';
import { HeaderText, BodyText } from './Text'; import { HeaderText, BodyText } from './Text';
import PeriodicFetch from '../lib/fetchers/periodicFetch'; 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 processNetworkData from './processNetwork';
import { AnvilContext } from './AnvilContext';
const useStyles = makeStyles(() => ({ const useStyles = makeStyles(() => ({
container: { container: {
@ -21,7 +23,7 @@ const useStyles = makeStyles(() => ({
paddingLeft: 0, paddingLeft: 0,
}, },
divider: { divider: {
background: GREY, background: DIVIDER,
}, },
decorator: { decorator: {
width: '20px', 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 classes = useStyles();
const { data } = PeriodicFetch<AnvilNetwork>( const { data } = PeriodicFetch<AnvilNetwork>(
`${process.env.NEXT_PUBLIC_API_URL}/anvils/get_network?anvil_uuid=`, `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_network?anvil_uuid=`,
anvil?.anvil_uuid, uuid,
); );
const processed = processNetworkData(data); const processed = processNetworkData(data);

@ -1,22 +1,30 @@
import { useContext } from 'react';
import Panel from '../Panel'; import Panel from '../Panel';
import Text from '../Text/HeaderText'; import Text from '../Text/HeaderText';
import AnvilNode from './AnvilNode'; import AnvilNode from './AnvilNode';
import PeriodicFetch from '../../lib/fetchers/periodicFetch'; 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<AnvilStatus>( const { data } = PeriodicFetch<AnvilStatus>(
`${process.env.NEXT_PUBLIC_API_URL}/anvils/get_status?anvil_uuid=`, `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_status?anvil_uuid=`,
anvil?.anvil_uuid, uuid,
); );
return ( return (
<Panel> <Panel>
<Text text="Nodes" /> <Text text="Nodes" />
<AnvilNode {anvil.findIndex((a) => a.anvil_uuid === uuid) !== -1 && (
nodes={anvil?.nodes.map((node, index) => { <AnvilNode
return { ...node, ...data?.nodes[index] }; nodes={anvil[anvil.findIndex((a) => a.anvil_uuid === uuid)].nodes.map(
})} (node, index) => {
/> return { ...node, ...data?.nodes[index] };
},
)}
/>
)}
</Panel> </Panel>
); );
}; };

@ -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 { BodyText, HeaderText } from './Text';
import Panel from './Panel'; import Panel from './Panel';
import SharedStorageNode from './SharedStorageNode'; import SharedStorageNode from './SharedStorageNode';
import InnerPanel from './InnerPanel'; import InnerPanel from './InnerPanel';
import PanelHeader from './PanelHeader'; import PanelHeader from './PanelHeader';
import PeriodicFetch from '../lib/fetchers/periodicFetch'; 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<AnvilSharedStorage>( const { data } = PeriodicFetch<AnvilSharedStorage>(
`${process.env.NEXT_PUBLIC_API_URL}/anvils/get_shared_storage?anvil_uuid=`, `${process.env.NEXT_PUBLIC_API_URL}/anvils/get_shared_storage?anvil_uuid=`,
anvil?.anvil_uuid, uuid,
); );
return ( return (
<Panel> <Panel>
@ -33,8 +36,13 @@ const SharedStorage = ({ anvil }: { anvil: AnvilListItem }): JSX.Element => {
index: number, index: number,
): JSX.Element => ( ): JSX.Element => (
<SharedStorageNode <SharedStorageNode
node={{ ...node, nodeInfo: anvil.nodes[index] }} node={{
key={anvil.nodes[index].node_uuid} ...node,
nodeInfo:
anvil[anvil.findIndex((a) => a.anvil_uuid === uuid)]
.nodes[index],
}}
key={fs.nodes[index].free}
/> />
), ),
)} )}

Loading…
Cancel
Save