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 Channels extends React.Component { constructor() { super(); this.state = { channels: [], }; this.loadChannels() } loadChannels = () => { AMQPAPI.get('/channels') .then(response => this.setState({channels: response.data.items ? response.data.items : []})) }; tableItems = () => { const {classes} = this.props; let rowId = 0; return ( Channel Virtual host User name QOS Unacked Publish Confirm Deliver Get Ack {this.state.channels.map(row => { return ( {row.channel} {row.vhost} {row.user} {row.qos} {row.counters.unacked.value} {this.transformRate(row.counters.publish)} {this.transformRate(row.counters.confirm)} {this.transformRate(row.counters.deliver)} {this.transformRate(row.counters.get)} {this.transformRate(row.counters.ack)} ); })}
) }; transformRate = (trackValue) => { if (!trackValue || !trackValue.value) { return '0/s' } return trackValue.value + '/s' }; render() { setTimeout(this.loadChannels, 5000); const {classes} = this.props; return ( {this.tableItems()} ) } } export default withStyles(styles)(Channels);