import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { Trans, withNamespaces } 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 './Dashboard.css'; class Dashboard extends Component { componentDidMount() { this.getAllStats(); } getAllStats = () => { this.props.getStats(); this.props.getStatsHistory(); this.props.getTopStats(); } getToggleFilteringButton = () => { const { protectionEnabled, processingProtection } = this.props.dashboard; const buttonText = protectionEnabled ? 'disable_protection' : 'enable_protection'; const buttonClass = protectionEnabled ? 'btn-gray' : 'btn-success'; return ( this.props.toggleProtection(protectionEnabled)} disabled={processingProtection} > {buttonText} ); } render() { const { dashboard, t } = this.props; const dashboardProcessing = dashboard.processing || dashboard.processingStats || dashboard.processingStatsHistory || dashboard.processingTopStats; const refreshFullButton = this.getAllStats()}>refresh_statics; const refreshButton = this.getAllStats()} />; return ( {this.getToggleFilteringButton()} {refreshFullButton} {dashboardProcessing && } {!dashboardProcessing && {dashboard.statsHistory && } {dashboard.stats && } {dashboard.topStats && } } ); } } Dashboard.propTypes = { getStats: PropTypes.func, getStatsHistory: PropTypes.func, getTopStats: PropTypes.func, dashboard: PropTypes.object, isCoreRunning: PropTypes.bool, getFiltering: PropTypes.func, toggleProtection: PropTypes.func, processingProtection: PropTypes.bool, t: PropTypes.func, }; export default withNamespaces()(Dashboard);