Merge pull request #1331 from guardicore/1293/attack-no-change-tabs

Fix bug where we can't change tab from attack to another tab in Configure
This commit is contained in:
VakarisZ 2021-07-19 13:59:33 +03:00 committed by GitHub
commit b798e67163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -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));
}
@ -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;
}
@ -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;
@ -328,6 +339,7 @@ class ConfigurePageComponent extends AuthComponent {
this.setState({showAttackAlert: true});
return;
}
this.updateConfigSection();
this.currentSection = key;
this.setState({
@ -345,6 +357,7 @@ class ConfigurePageComponent extends AuthComponent {
})
.then(res => res.json())
.then(res => {
res.configuration['attack'] = {}
this.setState({
lastAction: 'reset',
schema: res.schema,