From 8ba6ccf939bc3d42b9a8fd118e271fe75a7e2db8 Mon Sep 17 00:00:00 2001 From: Itay Mizeretz Date: Sun, 8 Oct 2017 17:58:40 +0300 Subject: [PATCH] Add warning to reset environment --- .../ui/src/components/pages/StartOverPage.js | 73 +++++++++++++++++-- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/monkey_island/cc/ui/src/components/pages/StartOverPage.js b/monkey_island/cc/ui/src/components/pages/StartOverPage.js index 6ecb2cc69..0152c9b61 100644 --- a/monkey_island/cc/ui/src/components/pages/StartOverPage.js +++ b/monkey_island/cc/ui/src/components/pages/StartOverPage.js @@ -1,19 +1,71 @@ import React from 'react'; import {Col} from 'react-bootstrap'; import {Link} from 'react-router-dom'; +import {ModalContainer, ModalDialog} from 'react-modal-dialog'; class StartOverPageComponent extends React.Component { constructor(props) { super(props); this.state = { - cleaned: false + cleaned: false, + showCleanDialog: false, + allMonkeysAreDead: false }; } + updateMonkeysRunning = () => { + 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']) + }); + }); + }; + + renderCleanDialogModal = () => { + if (!this.state.showCleanDialog) { + return
+ } + + return ( + this.setState({showCleanDialog: false})}> + this.setState({showCleanDialog: false})}> +

Reset environment

+

+ Are you sure you want to reset the environment? +

+ { + !this.state.allMonkeysAreDead ? +
+ + Some monkeys are still running. It's advised to kill all monkeys before resetting. +
+ : +
+ } + + + + + ) + }; + render() { return ( + {this.renderCleanDialogModal()}

Start Over

@@ -23,19 +75,26 @@ class StartOverPageComponent extends React.Component {

After that you could go back to the Run Monkey page to start new infections.

-

- Reset Environment +

+

+
+ + You can continue and Run More Monkeys as you wish, + and see the results on the Infection Map without deleting anything. +
{ this.state.cleaned ?
Environment was reset successfully
: ''} -

- * BTW you can just continue and run more monkeys as you wish, - and see the results on the Infection Map without deleting anything. -

);