diff --git a/src/components/TopBlocked.js b/src/components/TopBlocked.js index a4b8ec7..cd6131f 100644 --- a/src/components/TopBlocked.js +++ b/src/components/TopBlocked.js @@ -14,6 +14,7 @@ import { api, ignoreCancel, makeCancelable } from '../utils'; class TopBlocked extends Component { state = { + loading: true, total_blocked: 0, top_blocked: [] }; @@ -27,12 +28,59 @@ class TopBlocked extends Component { this.updateHandler = makeCancelable(api.getTopBlocked(), { repeat: this.updateChart, interval: 10 * 1000 }); this.updateHandler.promise.then(res => { this.setState({ + loading: false, total_blocked: res.blocked_queries, top_blocked: res.top_blocked }); }).catch(ignoreCancel); } + generateTable = t => { + if(this.state.top_blocked.length === 0) { + return t("No Domains Found"); + } + + return ( + + + + + + + + {this.generateRows(t)} + +
{t("Domain")}{t("Hits")}{t("Frequency")}
+ ); + }; + + generateRows = t => { + return this.state.top_blocked.map(item => { + const percentage = item.count / this.state.total_blocked * 100; + return ( + + + {item.domain} + + + {item.count.toLocaleString()} + + +
+
+
+ + + ); + }); + }; + componentDidMount() { this.updateChart(); } @@ -52,45 +100,11 @@ class TopBlocked extends Component {
- - - - - - - - { - this.state.top_blocked.map(item => { - const percentage = item.count / this.state.total_blocked * 100; - return ( - - - - - - ); - }) - } - -
{t("Domain")}{t("Hits")}{t("Frequency")}
- {item.domain} - - {item.count.toLocaleString()} - -
-
-
-
+ {this.generateTable(t)}
{ - this.state.total_blocked === 0 + this.state.loading ?
diff --git a/src/components/TopClients.js b/src/components/TopClients.js index 5065a13..99e093f 100644 --- a/src/components/TopClients.js +++ b/src/components/TopClients.js @@ -14,6 +14,7 @@ import { api, ignoreCancel, makeCancelable } from '../utils'; class TopClients extends Component { state = { + loading: true, total_queries: 0, top_clients: [] }; @@ -27,12 +28,60 @@ class TopClients extends Component { this.updateHandler = makeCancelable(api.getTopClients(), { repeat: this.updateChart, interval: 10 * 1000 }); this.updateHandler.promise.then(res => { this.setState({ + loading: false, total_queries: res.total_queries, top_clients: res.top_clients }); }).catch(ignoreCancel); } + generateTable = t => { + if(this.state.top_clients.length === 0) { + return t("No Clients Found"); + } + + return ( + + + + + + + + {this.generateRows(t)} + +
{t("Client")}{t("Requests")}{t("Frequency")}
+ ); + }; + + generateRows = t => { + return this.state.top_clients.map(item => { + const percentage = item.count / this.state.total_queries * 100; + + return ( + + + {item.name !== "" ? item.name : item.ip} + + + {item.count.toLocaleString()} + + +
+
+
+ + + ); + }); + }; + componentDidMount() { this.updateChart(); } @@ -52,46 +101,11 @@ class TopClients extends Component {
- - - - - - - - { - this.state.top_clients.map(item => { - const percentage = item.count / this.state.total_queries * 100; - - return ( - - - - - - ); - }) - } - -
{t("Client")}{t("Requests")}{t("Frequency")}
- {item.name !== "" ? item.name : item.ip} - - {item.count.toLocaleString()} - -
-
-
-
+ {this.generateTable(t)}
{ - this.state.total_queries === 0 + this.state.loading ?
diff --git a/src/components/TopDomains.js b/src/components/TopDomains.js index 6982050..0850829 100644 --- a/src/components/TopDomains.js +++ b/src/components/TopDomains.js @@ -14,6 +14,7 @@ import { api, ignoreCancel, makeCancelable } from '../utils'; class TopDomains extends Component { state = { + loading: true, total_queries: 0, top_domains: [] }; @@ -27,12 +28,61 @@ class TopDomains extends Component { this.updateHandler = makeCancelable(api.getTopDomains(), { repeat: this.updateChart, interval: 10 * 1000 }); this.updateHandler.promise.then(res => { this.setState({ + loading: false, total_queries: res.total_queries, top_domains: res.top_domains }); }).catch(ignoreCancel); } + generateTable = t => { + if(this.state.top_domains.length === 0) { + return t("No Domains Found"); + } + + return ( + + + + + + + + { + this.generateRows(t) + } + +
{t("Domain")}{t("Hits")}{t("Frequency")}
+ ); + }; + + generateRows = t => { + return this.state.top_domains.map(item => { + const percentage = item.count / this.state.total_queries * 100; + return ( + + + {item.domain} + + + {item.count.toLocaleString()} + + +
+
+
+ + + ); + }); + }; + componentDidMount() { this.updateChart(); } @@ -52,45 +102,11 @@ class TopDomains extends Component {
- - - - - - - - { - this.state.top_domains.map(item => { - const percentage = item.count / this.state.total_queries * 100; - return ( - - - - - - ); - }) - } - -
{t("Domain")}{t("Hits")}{t("Frequency")}
- {item.domain} - - {item.count.toLocaleString()} - -
-
-
-
+ {this.generateTable(t)}
{ - this.state.total_queries === 0 + this.state.loading ?