From d67cb18cae292a070e2d34b80a9ee7429f8b0be4 Mon Sep 17 00:00:00 2001 From: itay Date: Thu, 14 Feb 2019 19:07:12 +0200 Subject: [PATCH] Some unecessary set states removed to prevent refreshing of config page --- monkey/monkey_island/cc/ui/src/components/Main.js | 8 +++++--- .../cc/ui/src/components/pages/ConfigurePage.js | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/Main.js b/monkey/monkey_island/cc/ui/src/components/Main.js index 69eeb8500..02cf9fdee 100644 --- a/monkey/monkey_island/cc/ui/src/components/Main.js +++ b/monkey/monkey_island/cc/ui/src/components/Main.js @@ -29,9 +29,11 @@ class AppComponent extends AuthComponent { updateStatus = () => { this.auth.loggedIn() .then(res => { - this.setState({ - isLoggedIn: res - }); + if (this.state.isLoggedIn !== res) { + this.setState({ + isLoggedIn: res + }); + } if (res) { this.authFetch('/api') diff --git a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index ed8258197..a4d143c5e 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -141,9 +141,12 @@ class ConfigurePageComponent extends AuthComponent { .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']) - }); + let allMonkeysAreDead = (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']); + if (allMonkeysAreDead !== this.state.allMonkeysAreDead) { + this.setState({ + allMonkeysAreDead: allMonkeysAreDead + }); + } }); };