|
| 1 | +import cn from 'bem-cn-lite'; |
| 2 | + |
| 3 | +import type {TSystemStateInfo} from '../../types/api/nodes'; |
| 4 | + |
| 5 | +import {LOAD_AVERAGE_TIME_INTERVALS} from '../../utils/constants'; |
| 6 | +import {calcUptime} from '../../utils'; |
| 7 | + |
| 8 | +import InfoViewer from '../InfoViewer/InfoViewer'; |
| 9 | +import ProgressViewer from '../ProgressViewer/ProgressViewer'; |
| 10 | +import {PoolUsage} from '../PoolUsage/PoolUsage'; |
| 11 | + |
| 12 | +import './FullNodeViewer.scss'; |
| 13 | + |
| 14 | +const b = cn('full-node-viewer'); |
| 15 | + |
| 16 | +interface FullNodeViewerProps { |
| 17 | + node: TSystemStateInfo | undefined; |
| 18 | + className?: string; |
| 19 | +} |
| 20 | + |
| 21 | +export const FullNodeViewer = ({node, className}: FullNodeViewerProps) => { |
| 22 | + const endpointsInfo = node?.Endpoints?.map(({Name, Address}) => ({ |
| 23 | + label: Name, |
| 24 | + value: Address, |
| 25 | + })); |
| 26 | + |
| 27 | + const commonInfo = [ |
| 28 | + {label: 'Version', value: node?.Version}, |
| 29 | + {label: 'Uptime', value: calcUptime(node?.StartTime)}, |
| 30 | + {label: 'DC', value: node?.DataCenterDescription}, |
| 31 | + {label: 'Rack', value: node?.Rack}, |
| 32 | + ]; |
| 33 | + |
| 34 | + const averageInfo = node?.LoadAverage?.map((load, loadIndex) => ({ |
| 35 | + label: LOAD_AVERAGE_TIME_INTERVALS[loadIndex], |
| 36 | + value: <ProgressViewer value={load} percents={true} colorizeProgress={true} />, |
| 37 | + })); |
| 38 | + |
| 39 | + return ( |
| 40 | + <div className={`${b()} ${className}`}> |
| 41 | + {node ? ( |
| 42 | + <div className={b('common-info')}> |
| 43 | + <div> |
| 44 | + <div className={b('section-title')}>Pools</div> |
| 45 | + <div className={b('section', {pools: true})}> |
| 46 | + {node?.PoolStats?.map((pool, poolIndex) => ( |
| 47 | + <PoolUsage key={poolIndex} data={pool} /> |
| 48 | + ))} |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + |
| 52 | + {endpointsInfo && endpointsInfo.length && ( |
| 53 | + <InfoViewer |
| 54 | + title="Endpoints" |
| 55 | + className={b('section')} |
| 56 | + info={endpointsInfo} |
| 57 | + /> |
| 58 | + )} |
| 59 | + |
| 60 | + <InfoViewer title="Common info" className={b('section')} info={commonInfo} /> |
| 61 | + |
| 62 | + <InfoViewer |
| 63 | + title="Load average" |
| 64 | + className={b('section', {average: true})} |
| 65 | + info={averageInfo} |
| 66 | + /> |
| 67 | + </div> |
| 68 | + ) : ( |
| 69 | + <div className="error">no data</div> |
| 70 | + )} |
| 71 | + </div> |
| 72 | + ); |
| 73 | +}; |
0 commit comments