import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { withNamespaces } from 'react-i18next'; import ReactTable from 'react-table'; import Card from '../../ui/Card'; import WrapCell from './WrapCell'; import whoisCell from './whoisCell'; const COLUMN_MIN_WIDTH = 200; class AutoClients extends Component { getStats = (ip, stats) => { if (stats) { const statsForCurrentIP = stats.find(item => item.name === ip); return statsForCurrentIP && statsForCurrentIP.count; } return ''; }; columns = [ { Header: this.props.t('table_client'), accessor: 'ip', minWidth: COLUMN_MIN_WIDTH, Cell: WrapCell, }, { Header: this.props.t('table_name'), accessor: 'name', minWidth: COLUMN_MIN_WIDTH, Cell: WrapCell, }, { Header: this.props.t('source_label'), accessor: 'source', minWidth: COLUMN_MIN_WIDTH, Cell: WrapCell, }, { Header: this.props.t('whois'), accessor: 'whois_info', minWidth: COLUMN_MIN_WIDTH, Cell: whoisCell(this.props.t), }, { Header: this.props.t('requests_count'), accessor: 'statistics', minWidth: COLUMN_MIN_WIDTH, Cell: (row) => { const clientIP = row.original.ip; const clientStats = clientIP && this.getStats(clientIP, this.props.topClients); if (clientStats) { return (
{clientStats}
); } return '–'; }, }, ]; render() { const { t, autoClients } = this.props; return ( ); } } AutoClients.propTypes = { t: PropTypes.func.isRequired, autoClients: PropTypes.array.isRequired, topClients: PropTypes.array.isRequired, }; export default withNamespaces()(AutoClients);