diff --git a/monkey_island/cc/ui/src/components/pages/ReportPage.js b/monkey_island/cc/ui/src/components/pages/ReportPage.js index 82787f5f0..a058ce516 100644 --- a/monkey_island/cc/ui/src/components/pages/ReportPage.js +++ b/monkey_island/cc/ui/src/components/pages/ReportPage.js @@ -31,25 +31,27 @@ class ReportPageComponent extends React.Component { this.state = { report: {}, graph: {nodes: [], edges: []}, - allMonkeysAreDead: false + allMonkeysAreDead: false, + runStarted: true }; } componentDidMount() { - this.getReportFromServer(); + this.updateMonkeysRunning().then(res => this.getReportFromServer(res)); this.updateMapFromServer(); - this.updateMonkeysRunning(); this.interval = setInterval(this.updateMapFromServer, 1000); } updateMonkeysRunning = () => { - fetch('/api') + return fetch('/api') .then(res => res.json()) .then(res => { // This check is used to prevent unnecessary re-rendering this.setState({ - allMonkeysAreDead: (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']) + allMonkeysAreDead: (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']), + runStarted: res['completed_steps']['run_monkey'] }); + return res; }); }; @@ -69,14 +71,16 @@ class ReportPageComponent extends React.Component { }); }; - getReportFromServer() { - fetch('/api/report') - .then(res => res.json()) - .then(res => { - this.setState({ - report: res + getReportFromServer(res) { + if (res['completed_steps']['run_monkey']) { + fetch('/api/report') + .then(res => res.json()) + .then(res => { + this.setState({ + report: res + }); }); - }); + } } generateInfoBadges(data_array) { @@ -353,11 +357,18 @@ class ReportPageComponent extends React.Component { }; - render() { let content; if (Object.keys(this.state.report).length === 0) { - content = (

Generating Report...

); + if (this.state.runStarted) { + content = (

Generating Report...

); + } else { + content = +

+ + You have to run a monkey before generating a report! +

; + } } else { let exploitPercentage = (100 * this.state.report.glance.exploited.length) / this.state.report.glance.scanned.length;