badguardhome/client/src/components/Dashboard/QueriedDomains.js

82 lines
2.5 KiB
JavaScript
Raw Normal View History

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 { withNamespaces, Trans } from 'react-i18next';
2018-08-30 14:25:33 +00:00
import Card from '../ui/Card';
2018-10-12 13:02:01 +00:00
import Cell from '../ui/Cell';
import Popover from '../ui/Popover';
2018-08-30 14:25:33 +00:00
2018-10-14 20:24:11 +00:00
import { getTrackerData } from '../../helpers/trackers/trackers';
2018-10-12 13:02:01 +00:00
import { getPercent } from '../../helpers/helpers';
import { STATUS_COLORS } from '../../helpers/constants';
class QueriedDomains extends Component {
getPercentColor = (percent) => {
if (percent > 10) {
return STATUS_COLORS.red;
} else if (percent > 5) {
return STATUS_COLORS.yellow;
}
return STATUS_COLORS.green;
}
columns = [{
Header: 'IP',
accessor: 'ip',
Cell: (row) => {
const { value } = row;
const trackerData = getTrackerData(value);
return (
2018-10-29 10:13:32 +00:00
<div className="logs__row">
<div className="logs__text" title={value}>
{value}
</div>
{trackerData && <Popover data={trackerData} />}
</div>
);
},
2018-10-12 13:02:01 +00:00
}, {
2018-11-09 06:51:28 +00:00
Header: <Trans>requests_count</Trans>,
2018-10-12 13:02:01 +00:00
accessor: 'count',
2018-10-15 11:57:36 +00:00
maxWidth: 190,
2018-10-12 13:02:01 +00:00
Cell: ({ value }) => {
const percent = getPercent(this.props.dnsQueries, value);
const percentColor = this.getPercentColor(percent);
return (
<Cell value={value} percent={percent} color={percentColor} />
);
},
}];
render() {
const { t } = this.props;
2018-10-12 13:02:01 +00:00
return (
2018-11-09 06:51:28 +00:00
<Card title={ t('stats_query_domain') } subtitle={ t('for_last_24_hours') } bodyType="card-table" refresh={this.props.refreshButton}>
2018-10-12 13:02:01 +00:00
<ReactTable
data={map(this.props.topQueriedDomains, (value, prop) => (
{ ip: prop, count: value }
))}
columns={this.columns}
showPagination={false}
2018-11-09 06:51:28 +00:00
noDataText={ t('no_domains_found') }
2018-10-12 13:02:01 +00:00
minRows={6}
className="-striped -highlight card-table-overflow stats__table"
2018-10-12 13:02:01 +00:00
/>
</Card>
);
}
}
2018-08-30 14:25:33 +00:00
QueriedDomains.propTypes = {
topQueriedDomains: PropTypes.object.isRequired,
2018-10-12 13:02:01 +00:00
dnsQueries: PropTypes.number.isRequired,
refreshButton: PropTypes.node.isRequired,
t: PropTypes.func,
2018-08-30 14:25:33 +00:00
};
export default withNamespaces()(QueriedDomains);