style: add eslint configuration and fixed linter issues (#35)

* style: add eslint configuration as per bee-js

* chore: add `plugin:react/reocommended` in `.eslintrc`

Co-authored-by: nugaon <50576770+nugaon@users.noreply.github.com>

* chore: add `consistent` to `array-bracket-newline` as per review

* style: after automatic fixes with `npm run lint`

* style: fixed all linter errors

* refactor: fixed all linter warnings

* chore: added missing new line at end of `.prettierrc` file

Co-authored-by: nugaon <50576770+nugaon@users.noreply.github.com>
This commit is contained in:
Vojtech Simetka
2021-04-03 14:04:37 +02:00
committed by GitHub
parent 9838aa70c8
commit bc01d60728
54 changed files with 3454 additions and 2782 deletions
+126 -114
View File
@@ -1,13 +1,13 @@
import React, { useState } from 'react'
import { Link } from 'react-router-dom';
import { ReactElement, useState } from 'react'
import { Link } from 'react-router-dom'
import { Theme, createStyles, makeStyles } from '@material-ui/core/styles';
import { Card, CardContent, Typography, Chip, Button } from '@material-ui/core/';
import { CheckCircle, Error, ArrowRight, ArrowDropUp } from '@material-ui/icons/';
import { Skeleton } from '@material-ui/lab';
import type { Health, NodeAddresses, Topology } from '@ethersphere/bee-js';
import { createStyles, makeStyles } from '@material-ui/core/styles'
import { Card, CardContent, Typography, Chip, Button } from '@material-ui/core/'
import { CheckCircle, Error, ArrowRight, ArrowDropUp } from '@material-ui/icons/'
import { Skeleton } from '@material-ui/lab'
import type { Health, NodeAddresses, Topology } from '@ethersphere/bee-js'
const useStyles = makeStyles((theme: Theme) =>
const useStyles = makeStyles(() =>
createStyles({
root: {
display: 'flex',
@@ -22,120 +22,132 @@ const useStyles = makeStyles((theme: Theme) =>
flex: '1 0 auto',
},
status: {
color: '#2145a0',
backgroundColor: '#e1effe',
}
color: '#2145a0',
backgroundColor: '#e1effe',
},
}),
);
)
interface IProps{
nodeHealth: Health,
loadingNodeHealth: boolean,
beeRelease: any,
loadingBeeRelease: boolean,
nodeAddresses: NodeAddresses,
nodeTopology: Topology,
loadingNodeTopology: boolean,
setStatusChecksVisible: any,
interface Props {
nodeHealth: Health | null
loadingNodeHealth: boolean
beeRelease: LatestBeeRelease | null
loadingBeeRelease: boolean
nodeAddresses: NodeAddresses
nodeTopology: Topology
loadingNodeTopology: boolean
setStatusChecksVisible: (value: boolean) => void
}
function StatusCard(props: IProps) {
const classes = useStyles();
function StatusCard(props: Props): ReactElement {
const classes = useStyles()
const [underlayAddressesVisible, setUnderlayAddresessVisible] = useState<Boolean>(false)
const [underlayAddressesVisible, setUnderlayAddresessVisible] = useState<boolean>(false)
return (
<div>
<Card className={classes.root}>
{ !props.loadingNodeHealth && props.nodeHealth ?
<div className={classes.details}>
<CardContent className={classes.content}>
<Typography component="h5" variant="h5" style={{display:'flex', justifyContent:'space-between'}}>
{ props.nodeHealth.status === 'ok' ?
<div>
<CheckCircle style={{color:'#32c48d', marginRight: '7px'}} />
<span>Connected to Bee Node</span>
</div>
:
<div>
<Error style={{color:'#c9201f', marginRight: '7px'}} />
<span>Could not connect to Bee Node</span>
</div>
}
<Button variant='outlined' color='primary' size='small' style={{marginLeft:'12px'}} onClick={() => props.setStatusChecksVisible(true)}>View Status Checks</Button>
</Typography>
<div style={{marginBottom: '20px' }}>
<span style={{marginRight:'20px'}}>Discovered Nodes: { props.nodeTopology.population }</span>
<span style={{marginRight:'20px'}}>
<span>Connected Peers: </span>
<Link to='/peers/'>
{ props.nodeTopology.connected }
</Link>
</span>
</div>
return (
<div>
<Card className={classes.root}>
{!props.loadingNodeHealth && props.nodeHealth ? (
<div className={classes.details}>
<CardContent className={classes.content}>
<Typography component="h5" variant="h5" style={{ display: 'flex', justifyContent: 'space-between' }}>
{props.nodeHealth.status === 'ok' ? (
<div>
<CheckCircle style={{ color: '#32c48d', marginRight: '7px' }} />
<span>Connected to Bee Node</span>
</div>
) : (
<div>
<Error style={{ color: '#c9201f', marginRight: '7px' }} />
<span>Could not connect to Bee Node</span>
</div>
)}
<Button
variant="outlined"
color="primary"
size="small"
style={{ marginLeft: '12px' }}
onClick={() => props.setStatusChecksVisible(true)}
>
View Status Checks
</Button>
</Typography>
<div style={{ marginBottom: '20px' }}>
<span style={{ marginRight: '20px' }}>Discovered Nodes: {props.nodeTopology.population}</span>
<span style={{ marginRight: '20px' }}>
<span>Connected Peers: </span>
<Link to="/peers/">{props.nodeTopology.connected}</Link>
</span>
</div>
<div>
<Typography component="div" variant="subtitle2" gutterBottom>
<span>AGENT: </span>
<a href="https://github.com/ethersphere/bee" rel="noreferrer" target="_blank">
Bee
</a>
<span>{props.nodeHealth?.version ? ` v${props.nodeHealth.version}` : '-'}</span>
{
// FIXME: this should be broken up
/* eslint-disable no-nested-ternary */
props.beeRelease && props.beeRelease.name === `v${props.nodeHealth?.version?.split('-')[0]}` ? (
<Chip
style={{ marginLeft: '7px', color: '#2145a0' }}
size="small"
label="latest"
className={classes.status}
/>
) : props.loadingBeeRelease ? (
''
) : (
<Typography variant="button">update</Typography>
)
/* eslint-enable no-nested-ternary */
}
</Typography>
<Typography component="div" variant="subtitle2" gutterBottom>
<span>PUBLIC KEY: </span>
<span>{props.nodeAddresses.public_key ? props.nodeAddresses.public_key : '-'}</span>
</Typography>
<Typography component="div" variant="subtitle2" gutterBottom>
<span>PSS PUBLIC KEY: </span>
<span>{props.nodeAddresses.pss_public_key ? props.nodeAddresses.pss_public_key : '-'}</span>
</Typography>
<Typography component="div" variant="subtitle2" gutterBottom>
<Typography component="div" style={{ marginTop: '20px' }}>
<span>OVERLAY ADDRESS (PEER ID): </span>
<span>{props.nodeAddresses.overlay ? props.nodeAddresses.overlay : '-'}</span>
</Typography>
<Typography component="div" onClick={() => setUnderlayAddresessVisible(!underlayAddressesVisible)}>
<Button color="primary" style={{ padding: 0, marginTop: '6px' }}>
{underlayAddressesVisible ? (
<ArrowDropUp style={{ fontSize: '12px' }} />
) : (
<ArrowRight style={{ fontSize: '12px' }} />
)}
<span>Underlay Addresses</span>
</Button>
</Typography>
{underlayAddressesVisible ? (
<div>
<Typography component="div" variant="subtitle2" gutterBottom>
<span>AGENT: </span>
<a href='https://github.com/ethersphere/bee' rel='noreferrer' target='_blank'>Bee</a>
<span>{props.nodeHealth?.version ? ` v${props.nodeHealth.version}` : '-'}</span>
{props.beeRelease && props.beeRelease.name === `v${props.nodeHealth?.version?.split('-')[0]}` ?
<Chip
style={{ marginLeft: '7px', color: '#2145a0' }}
size="small"
label='latest'
className={classes.status}
/>
:
props.loadingBeeRelease ?
''
:
<Typography variant="button">update</Typography>
}
</Typography>
<Typography component="div" variant="subtitle2" gutterBottom>
<span>PUBLIC KEY: </span>
<span>{ props.nodeAddresses.public_key ? props.nodeAddresses.public_key : '-' }</span>
</Typography>
<Typography component="div" variant="subtitle2" gutterBottom>
<span>PSS PUBLIC KEY: </span>
<span>{ props.nodeAddresses.pss_public_key ? props.nodeAddresses.pss_public_key : '-' }</span>
</Typography>
<Typography component="div" variant="subtitle2" gutterBottom>
<Typography component="div" style={{marginTop:'20px'}}>
<span>OVERLAY ADDRESS (PEER ID): </span>
<span>{ props.nodeAddresses.overlay ? props.nodeAddresses.overlay : '-' }</span>
</Typography>
<Typography component="div" onClick={() => setUnderlayAddresessVisible(!underlayAddressesVisible)}>
<Button color="primary" style={{padding: 0, marginTop:'6px'}}>
{ underlayAddressesVisible ?
<ArrowDropUp style={{fontSize:'12px'}} /> :
<ArrowRight style={{fontSize:'12px'}} />
}
<span>Underlay Addresses</span>
</Button>
</Typography>
{underlayAddressesVisible ?
<div>
{ props.nodeAddresses.underlay ?
props.nodeAddresses.underlay.map(item => (<li>{item}</li>))
: '-' }
</div>
: null}
</Typography>
{props.nodeAddresses.underlay
? props.nodeAddresses.underlay.map(item => <li key={item}>{item}</li>)
: '-'}
</div>
</CardContent>
</div>
:
<div style={{padding: '16px'}}>
<Skeleton width={650} height={32} animation="wave" />
<Skeleton width={650} height={24} animation="wave" />
<Skeleton width={650} height={24} animation="wave" />
</div>
}
</Card>
</div>
)
) : null}
</Typography>
</div>
</CardContent>
</div>
) : (
<div style={{ padding: '16px' }}>
<Skeleton width={650} height={32} animation="wave" />
<Skeleton width={650} height={24} animation="wave" />
<Skeleton width={650} height={24} animation="wave" />
</div>
)}
</Card>
</div>
)
}
export default StatusCard