import React from 'react'; import Table from '@material-ui/core/Table'; import TableBody from '@material-ui/core/TableBody'; import TableCell from '@material-ui/core/TableCell'; import TableHead from '@material-ui/core/TableHead'; import TableRow from '@material-ui/core/TableRow'; import {withStyles} from '@material-ui/core/styles'; import Grid from '@material-ui/core/Grid'; import AMQPAPI from '../../AMQPApi' import Paper from '@material-ui/core/Paper'; const styles = theme => ({ tableContainer: { width: '100%', }, table: { width: '100%', }, formContainer: { width: 300, }, form: { marginLeft: theme.spacing.unit * 1, }, submit: { marginTop: theme.spacing.unit * 3, }, tableHead: { fontWeight: 'bold', } }); class Connections extends React.Component { constructor() { super(); this.state = { connections: [], }; this.loadConnections() } loadConnections = () => { AMQPAPI.get('/connections') .then(response => this.setState({connections: response.data.items ? response.data.items : []})) }; tableItems = () => { const {classes} = this.props; let rowId = 0; return ( ID Virtual Host Name User name Protocol Channels From client To client {this.state.connections.map(row => { return ( {row.id} {row.vhost} {row.addr} {row.user} {row.protocol} {row.channels_count} {this.transformTraffic(row.from_client)} {this.transformTraffic(row.to_client)} ); })}
) }; transformTraffic = (trackValue) => { let value = 0; if (trackValue) { value = trackValue.value; } if (value > 1024 * 1024) { value = Math.round(value * 100 / 1024 / 1024) / 100; return value + ' MB/s'; } else if (value > 1024) { value = Math.round(value * 100 / 1024) / 100; return value + ' KB/s'; } else { return value + ' B/s'; } }; render() { setTimeout(this.loadConnections, 5000); const {classes} = this.props; return ( {this.tableItems()} ) } } export default withStyles(styles)(Connections);