import { Box, Switch } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import { InnerPanel, PanelHeader } from '../Panels'; import { ProgressBar } from '../Bars'; import { BodyText } from '../Text'; import Decorator, { Colours } from '../Decorator'; import NODE_STATUS from '../../lib/consts/NODES'; import putJSON from '../../lib/fetchers/putJSON'; const useStyles = makeStyles((theme) => ({ root: { overflow: 'auto', height: '28vh', paddingLeft: '.3em', [theme.breakpoints.down('md')]: { height: '100%', overflow: 'hidden', }, }, state: { paddingLeft: '.7em', paddingRight: '.7em', paddingTop: '1em', }, bar: { paddingLeft: '.7em', paddingRight: '.7em', }, header: { paddingTop: '.3em', paddingRight: '.7em', }, label: { paddingTop: '.3em', }, decoratorBox: { paddingRight: '.3em', }, })); const selectStateMessage = (regex: RegExp, message: string): string => { const msg = regex.exec(message); if (msg) { return NODE_STATUS.get(msg[0]) || 'Error code not recognized'; } return 'Error code not found'; }; const selectDecorator = (state: string): Colours => { switch (state) { case 'ready': return 'ok'; case 'off': return 'off'; case 'accessible': case 'on': return 'warning'; default: return 'error'; } }; const AnvilNode = ({ nodes, }: { nodes: Array; }): JSX.Element => { const classes = useStyles(); const stateRegex = /^[a-zA-Z]/; const messageRegex = /^(message_[0-9]+)/; return ( {nodes && nodes.map( (node): JSX.Element => { return ( c.toUpperCase(), ) || 'Not Available' } /> putJSON('/anvils/set_power', { host_uuid: node.node_uuid, is_on: !(node.state === 'ready'), }) } /> putJSON('/anvils/set_membership', { host_uuid: node.node_uuid, is_member: !(node.state === 'ready'), }) } /> {node.state !== 'ready' && ( <> )} ); }, )} ); }; export default AnvilNode;