diff --git a/client/src/components/Settings/Clients/AutoClients.js b/client/src/components/Settings/Clients/AutoClients.js index f1ea86bc..4348c62b 100644 --- a/client/src/components/Settings/Clients/AutoClients.js +++ b/client/src/components/Settings/Clients/AutoClients.js @@ -11,15 +11,6 @@ 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'), @@ -47,11 +38,12 @@ class AutoClients extends Component { }, { Header: this.props.t('requests_count'), - accessor: 'statistics', + accessor: row => this.props.normalizedTopClients[row.ip] || 0, + sortMethod: (a, b) => b - a, + id: 'statistics', minWidth: COLUMN_MIN_WIDTH, Cell: (row) => { - const clientIP = row.original.ip; - const clientStats = clientIP && this.getStats(clientIP, this.props.topClients); + const { value: clientStats } = row; if (clientStats) { return ( @@ -80,6 +72,12 @@ class AutoClients extends Component { { - if (stats) { - const currentStats = stats.find(item => item.info && item.info.name === name); - return currentStats && currentStats.count; - } - - return ''; - }; - handleDelete = (data) => { // eslint-disable-next-line no-alert if (window.confirm(this.props.t('client_confirm_delete', { key: data.name }))) { @@ -138,13 +129,13 @@ class ClientsTable extends Component {
{value && value.length > 0 ? value.map(service => ( - - - + + + )) : '–'}
@@ -177,11 +168,12 @@ class ClientsTable extends Component { }, { Header: this.props.t('requests_count'), - accessor: 'statistics', + id: 'statistics', + accessor: row => this.props.normalizedTopClients[row.name] || 0, + sortMethod: (a, b) => b - a, minWidth: 120, Cell: (row) => { - const { name } = row.original; - const clientStats = this.getStats(name, this.props.topClients); + const { value: clientStats } = row; if (clientStats) { return ( @@ -265,6 +257,12 @@ class ClientsTable extends Component { )} diff --git a/client/src/helpers/helpers.js b/client/src/helpers/helpers.js index d7c78fc2..8d68794c 100644 --- a/client/src/helpers/helpers.js +++ b/client/src/helpers/helpers.js @@ -261,6 +261,13 @@ export const redirectToCurrentProtocol = (values, httpPort = 80) => { export const normalizeTextarea = text => text && text.replace(/[;, ]/g, '\n').split('\n').filter(n => n); +export const normalizeTopClients = clients => clients.reduce((accumulator, clientObj) => { + const { name, count } = clientObj; + const idToCountMap = accumulator; + idToCountMap[name] = count; + return idToCountMap; +}, {}); + export const getClientInfo = (clients, ip) => { const client = clients .find(item => item.ip_addrs && item.ip_addrs.find(clientIp => clientIp === ip)); diff --git a/client/src/reducers/stats.js b/client/src/reducers/stats.js index 88c33a12..9a74c1b1 100644 --- a/client/src/reducers/stats.js +++ b/client/src/reducers/stats.js @@ -1,4 +1,5 @@ import { handleActions } from 'redux-actions'; +import { normalizeTopClients } from '../helpers/helpers'; import * as actions from '../actions/stats'; @@ -64,6 +65,7 @@ const stats = handleActions( replacedSafebrowsing, topBlockedDomains, topClients, + normalizedTopClients: normalizeTopClients(topClients), topQueriedDomains, numBlockedFiltering, numDnsQueries,