From 1eb0c7b11f819f1ce7cbb18cb7af6880a6115a53 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 16 Jul 2021 13:12:02 +0200 Subject: [PATCH] ui: Fix bug where we can't change tab from attack to another tab in configure --- .../cc/ui/src/components/pages/ConfigurePage.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 c7c84e327d9..2642a6c12d9 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -59,11 +59,15 @@ class ConfigurePageComponent extends AuthComponent { getSectionsOrder() { let islandMode = this.props.islandMode ? this.props.islandMode : 'advanced' + // TODO delete the following line before merging + islandMode = 'advanced' return CONFIGURATION_TABS_PER_MODE[islandMode]; } setInitialConfig(config) { // Sets a reference to know if config was changed + config['attack'] = {} + this.currentFormData = {} this.initialConfig = JSON.parse(JSON.stringify(config)); } @@ -228,12 +232,16 @@ class ConfigurePageComponent extends AuthComponent { onChange = ({formData}) => { let configuration = this.state.configuration; + if (this.state.selectedSection === 'attack'){ + formData = {}; + } configuration[this.state.selectedSection] = formData; this.setState({currentFormData: formData, configuration: configuration}); }; updateConfigSection = () => { let newConfig = this.state.configuration; + if (Object.keys(this.state.currentFormData).length > 0) { newConfig[this.currentSection] = this.state.currentFormData; } @@ -323,17 +331,21 @@ class ConfigurePageComponent extends AuthComponent { } setSelectedSection = (key) => { + if ((key === 'attack' && this.userChangedConfig()) || (this.currentSection === 'attack' && this.userChangedMatrix())) { this.setState({showAttackAlert: true}); return; } + this.updateConfigSection(); this.currentSection = key; + this.setState({ selectedSection: key, currentFormData: this.state.configuration[key] }); + }; resetConfig = () => { @@ -345,6 +357,7 @@ class ConfigurePageComponent extends AuthComponent { }) .then(res => res.json()) .then(res => { + res.configuration['attack'] = {} this.setState({ lastAction: 'reset', schema: res.schema,