Skip to content

Commit

Permalink
ui: Fix bug where we can't change tab from attack to another tab in c…
Browse files Browse the repository at this point in the history
…onfigure
  • Loading branch information
ilija-lazoroski committed Jul 19, 2021
1 parent ed2ebc7 commit 1eb0c7b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 = () => {
Expand All @@ -345,6 +357,7 @@ class ConfigurePageComponent extends AuthComponent {
})
.then(res => res.json())
.then(res => {
res.configuration['attack'] = {}
this.setState({
lastAction: 'reset',
schema: res.schema,
Expand Down

0 comments on commit 1eb0c7b

Please sign in to comment.