|
|
@ -1,5 +1,45 @@ |
|
|
|
import { NextPage } from 'next'; |
|
|
|
import { NextPage } from 'next'; |
|
|
|
|
|
|
|
import styled from 'styled-components'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import DEFAULT_THEME from '../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Header from '../components/organisms/Header'; |
|
|
|
|
|
|
|
import List from '../components/molecules/List'; |
|
|
|
|
|
|
|
import PageCenterContainer from '../components/organisms/PageCenterContainer'; |
|
|
|
|
|
|
|
import PageContainer from '../components/organisms/PageContainer'; |
|
|
|
|
|
|
|
import ToggleSwitch from '../components/atoms/ToggleSwitch'; |
|
|
|
|
|
|
|
|
|
|
|
import useOneAnvil from '../lib/anvil/useOneAnvil'; |
|
|
|
import useOneAnvil from '../lib/anvil/useOneAnvil'; |
|
|
|
|
|
|
|
import Label from '../components/atoms/Label'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const StyledAnvilNodeStatus = styled.div` |
|
|
|
|
|
|
|
display: flex; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flex-direction: column; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
width: 100%; |
|
|
|
|
|
|
|
height: 100%; |
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const StyledAnvilNodePower = styled.div` |
|
|
|
|
|
|
|
display: flex; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flex-direction: row; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
justify-content: space-around; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
width: 100%; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
margin-top: 1em; |
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StyledAnvilNodeStatus.defaultProps = { |
|
|
|
|
|
|
|
theme: DEFAULT_THEME, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StyledAnvilNodePower.defaultProps = { |
|
|
|
|
|
|
|
theme: DEFAULT_THEME, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const DemoAnvilStatus: NextPage = (): JSX.Element => { |
|
|
|
const DemoAnvilStatus: NextPage = (): JSX.Element => { |
|
|
|
const { |
|
|
|
const { |
|
|
@ -8,18 +48,58 @@ const DemoAnvilStatus: NextPage = (): JSX.Element => { |
|
|
|
isLoading, |
|
|
|
isLoading, |
|
|
|
} = useOneAnvil(`d61c0383-5d82-4d9f-a193-b4a31cff1ceb`); |
|
|
|
} = useOneAnvil(`d61c0383-5d82-4d9f-a193-b4a31cff1ceb`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lastUpdatedDatetime: string = new Date(timestamp * 1000).toLocaleString( |
|
|
|
|
|
|
|
'en-US', |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
timeZoneName: 'short', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div> |
|
|
|
<PageContainer> |
|
|
|
<h1>Demo Anvil Status</h1> |
|
|
|
<Header /> |
|
|
|
<h2>nodes</h2> |
|
|
|
<PageCenterContainer> |
|
|
|
<pre>{JSON.stringify(nodes, null, 4)}</pre> |
|
|
|
<List labelText="Anvil Status" isAlignHorizontal> |
|
|
|
<h2>timestamp</h2> |
|
|
|
{(() => { |
|
|
|
<pre>{timestamp}</pre> |
|
|
|
let resultElement: JSX.Element[]; |
|
|
|
<h2>isLoading</h2> |
|
|
|
|
|
|
|
<pre>{isLoading}</pre> |
|
|
|
if (isLoading) { |
|
|
|
<h2>error</h2> |
|
|
|
resultElement = [ |
|
|
|
<pre>{error?.message}</pre> |
|
|
|
<Label key="loading" text="Loading Anvil status..." />, |
|
|
|
</div> |
|
|
|
]; |
|
|
|
|
|
|
|
} else if (error !== null) { |
|
|
|
|
|
|
|
resultElement = [ |
|
|
|
|
|
|
|
<Label |
|
|
|
|
|
|
|
key="error" |
|
|
|
|
|
|
|
text={`Failed to get Anvil status; CAUSE: ${error}`} |
|
|
|
|
|
|
|
/>, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
resultElement = nodes.map( |
|
|
|
|
|
|
|
({ on }: AnvilNodeStatus, nodeIndex: number) => { |
|
|
|
|
|
|
|
const nodeName = `Node ${nodeIndex + 1}`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
<StyledAnvilNodeStatus key={nodeName}> |
|
|
|
|
|
|
|
<Label text={nodeName} /> |
|
|
|
|
|
|
|
<StyledAnvilNodePower> |
|
|
|
|
|
|
|
<Label text="Power" /> |
|
|
|
|
|
|
|
<ToggleSwitch checked={on === 1} /> |
|
|
|
|
|
|
|
</StyledAnvilNodePower> |
|
|
|
|
|
|
|
</StyledAnvilNodeStatus> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resultElement; |
|
|
|
|
|
|
|
})()} |
|
|
|
|
|
|
|
</List> |
|
|
|
|
|
|
|
<List labelText="Last Updated"> |
|
|
|
|
|
|
|
<Label text={lastUpdatedDatetime} /> |
|
|
|
|
|
|
|
</List> |
|
|
|
|
|
|
|
</PageCenterContainer> |
|
|
|
|
|
|
|
</PageContainer> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|