2018-10-12 13:02:01 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-08-30 14:25:33 +00:00
|
|
|
import ReactTable from 'react-table';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import map from 'lodash/map';
|
|
|
|
|
|
|
|
import Card from '../ui/Card';
|
2018-10-12 13:02:01 +00:00
|
|
|
import Cell from '../ui/Cell';
|
2018-08-30 14:25:33 +00:00
|
|
|
|
2018-10-12 13:02:01 +00:00
|
|
|
import { getPercent } from '../../helpers/helpers';
|
|
|
|
import { STATUS_COLORS } from '../../helpers/constants';
|
|
|
|
|
|
|
|
class Clients extends Component {
|
|
|
|
getPercentColor = (percent) => {
|
|
|
|
if (percent > 50) {
|
|
|
|
return STATUS_COLORS.green;
|
|
|
|
} else if (percent > 10) {
|
|
|
|
return STATUS_COLORS.yellow;
|
|
|
|
}
|
|
|
|
return STATUS_COLORS.red;
|
|
|
|
}
|
|
|
|
|
|
|
|
columns = [{
|
|
|
|
Header: 'IP',
|
|
|
|
accessor: 'ip',
|
|
|
|
}, {
|
|
|
|
Header: 'Requests count',
|
|
|
|
accessor: 'count',
|
|
|
|
Cell: ({ value }) => {
|
|
|
|
const percent = getPercent(this.props.dnsQueries, value);
|
|
|
|
const percentColor = this.getPercentColor(percent);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Cell value={value} percent={percent} color={percentColor} />
|
|
|
|
);
|
|
|
|
},
|
|
|
|
}];
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Card title="Top clients" subtitle="for the last 24 hours" bodyType="card-table" refresh={this.props.refreshButton}>
|
|
|
|
<ReactTable
|
|
|
|
data={map(this.props.topClients, (value, prop) => (
|
|
|
|
{ ip: prop, count: value }
|
|
|
|
))}
|
|
|
|
columns={this.columns}
|
|
|
|
showPagination={false}
|
|
|
|
noDataText="No clients found"
|
|
|
|
minRows={6}
|
|
|
|
className="-striped -highlight card-table-overflow"
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-08-30 14:25:33 +00:00
|
|
|
|
|
|
|
Clients.propTypes = {
|
|
|
|
topClients: PropTypes.object.isRequired,
|
2018-10-12 13:02:01 +00:00
|
|
|
dnsQueries: PropTypes.number.isRequired,
|
|
|
|
refreshButton: PropTypes.node.isRequired,
|
2018-08-30 14:25:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Clients;
|