Skip to content

Commit

Permalink
Merge pull request #1331 from guardicore/1293/attack-no-change-tabs
Browse files Browse the repository at this point in the history
Fix bug where we can't change tab from attack to another tab in Configure
  • Loading branch information
VakarisZ authored Jul 19, 2021
2 parents c760e06 + 491c44a commit b798e67
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ConfigurePageComponent extends AuthComponent {

setInitialConfig(config) {
// Sets a reference to know if config was changed
config['attack'] = {}
this.initialConfig = JSON.parse(JSON.stringify(config));
}

Expand Down Expand Up @@ -228,12 +229,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 @@ -309,10 +314,16 @@ class ConfigurePageComponent extends AuthComponent {
}

userChangedConfig() {
if (JSON.stringify(this.state.configuration) === JSON.stringify(this.initialConfig)) {
if (Object.keys(this.state.currentFormData).length === 0 ||
JSON.stringify(this.initialConfig[this.currentSection]) === JSON.stringify(this.state.currentFormData)) {
return false;
try {
if (JSON.stringify(this.state.configuration) === JSON.stringify(this.initialConfig)) {
if (Object.keys(this.state.currentFormData).length === 0 ||
JSON.stringify(this.initialConfig[this.currentSection]) === JSON.stringify(this.state.currentFormData)) {
return false;
}
}
} catch (TypeError) {
if (JSON.stringify(this.initialConfig[this.currentSection]) === JSON.stringify(this.state.currentFormData)){
return false;
}
}
return true;
Expand All @@ -328,6 +339,7 @@ class ConfigurePageComponent extends AuthComponent {
this.setState({showAttackAlert: true});
return;
}

this.updateConfigSection();
this.currentSection = key;
this.setState({
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 b798e67

Please sign in to comment.