refactor: translate and display node state messages

main
Josue 4 years ago committed by Tsu-ba-me
parent e775b4ac16
commit 1255ca2599
  1. 28
      striker-ui/components/Nodes/AnvilNode.tsx
  2. 23
      striker-ui/lib/consts/NODES.ts

@ -4,6 +4,7 @@ import { InnerPanel, PanelHeader } from '../Panels';
import { ProgressBar } from '../Bars'; import { ProgressBar } from '../Bars';
import { BodyText } from '../Text'; import { BodyText } from '../Text';
import Decorator, { Colours } from '../Decorator'; import Decorator, { Colours } from '../Decorator';
import NODE_STATUS from '../../lib/consts/NODES';
import putJSON from '../../lib/fetchers/putJSON'; import putJSON from '../../lib/fetchers/putJSON';
@ -38,6 +39,15 @@ const useStyles = makeStyles((theme) => ({
}, },
})); }));
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 => { const selectDecorator = (state: string): Colours => {
switch (state) { switch (state) {
case 'ready': case 'ready':
@ -58,7 +68,8 @@ const AnvilNode = ({
nodes: Array<AnvilStatusNode & AnvilListItemNode>; nodes: Array<AnvilStatusNode & AnvilListItemNode>;
}): JSX.Element => { }): JSX.Element => {
const classes = useStyles(); const classes = useStyles();
const regex = /(^|| )+[a-zA-Z0-9]/; const stateRegex = /^[a-zA-Z]/;
const messageRegex = /^(message_[0-9]+)/;
return ( return (
<Box className={classes.root}> <Box className={classes.root}>
@ -78,8 +89,9 @@ const AnvilNode = ({
<Box> <Box>
<BodyText <BodyText
text={ text={
node?.state?.replace(regex, (c) => c.toUpperCase()) || node?.state?.replace(stateRegex, (c) =>
'Not Available' c.toUpperCase(),
) || 'Not Available'
} }
/> />
</Box> </Box>
@ -119,11 +131,13 @@ const AnvilNode = ({
{node.state !== 'ready' && ( {node.state !== 'ready' && (
<> <>
<Box display="flex" width="100%" className={classes.state}> <Box display="flex" width="100%" className={classes.state}>
<Box flexGrow={1}>
<BodyText text={`State: ${node.state}`} />
</Box>
<Box> <Box>
<BodyText text={node.state_message} /> <BodyText
text={selectStateMessage(
messageRegex,
node.state_message,
)}
/>
</Box> </Box>
</Box> </Box>
<Box display="flex" width="100%" className={classes.bar}> <Box display="flex" width="100%" className={classes.bar}>

@ -1,9 +1,18 @@
const nodeState: ReadonlyMap<string, string> = new Map([ const NODE_STATUS_MESSAGE_MAP: ReadonlyMap<string, string> = new Map([
['unknown', 'Unknown'], ['message_0222', 'The node is in an unknown state.'],
['off', 'Off'], ['message_0223', 'The node is a full cluster member.'],
['on', 'On'], [
['accessible', 'Accessible'], 'message_0224',
['ready', 'Ready'], 'The node is coming online; the cluster resource manager is running (step 2/3).',
],
[
'message_0225',
'The node is coming online; the node is a consensus cluster member (step 1/3).',
],
[
'message_0226',
'The node has booted, but it is not (yet) joining the cluster.',
],
]); ]);
export default nodeState; export default NODE_STATUS_MESSAGE_MAP;

Loading…
Cancel
Save