import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { Trans, withTranslation } from 'react-i18next'; import Statistics from './Statistics'; import Counters from './Counters'; import Clients from './Clients'; import QueriedDomains from './QueriedDomains'; import BlockedDomains from './BlockedDomains'; import PageTitle from '../ui/PageTitle'; import Loading from '../ui/Loading'; import { BLOCK_ACTIONS } from '../../helpers/constants'; import './Dashboard.css'; class Dashboard extends Component { componentDidMount() { this.getAllStats(); } getAllStats = () => { this.props.getAccessList(); this.props.getStats(); this.props.getStatsConfig(); }; getToggleFilteringButton = () => { const { protectionEnabled, processingProtection } = this.props.dashboard; const buttonText = protectionEnabled ? 'disable_protection' : 'enable_protection'; const buttonClass = protectionEnabled ? 'btn-gray' : 'btn-success'; return ( ); }; toggleClientStatus = (type, ip) => { const confirmMessage = type === BLOCK_ACTIONS.BLOCK ? 'client_confirm_block' : 'client_confirm_unblock'; if (window.confirm(this.props.t(confirmMessage, { ip }))) { this.props.toggleClientBlock(type, ip); } }; render() { const { dashboard, stats, access, t, } = this.props; const statsProcessing = stats.processingStats || stats.processingGetConfig || access.processing; const subtitle = stats.interval === 1 ? t('for_last_24_hours') : t('for_last_days', { count: stats.interval }); const refreshFullButton = ( ); const refreshButton = ( ); return (
{this.getToggleFilteringButton()} {refreshFullButton}
{statsProcessing && } {!statsProcessing && (
)}
); } } Dashboard.propTypes = { dashboard: PropTypes.object.isRequired, stats: PropTypes.object.isRequired, access: PropTypes.object.isRequired, getStats: PropTypes.func.isRequired, getStatsConfig: PropTypes.func.isRequired, toggleProtection: PropTypes.func.isRequired, getClients: PropTypes.func.isRequired, t: PropTypes.func.isRequired, toggleClientBlock: PropTypes.func.isRequired, getAccessList: PropTypes.func.isRequired, }; export default withTranslation()(Dashboard);