ui: Fix bug where we can't change tab from attack to another tab in configure

This commit is contained in:
Ilija Lazoroski 2021-07-16 13:12:02 +02:00 committed by VakarisZ
parent f574af4225
commit f376c12db1
1 changed files with 8 additions and 8 deletions

View File

@ -59,13 +59,13 @@ class ConfigurePageComponent extends AuthComponent {
getSectionsOrder() { getSectionsOrder() {
let islandMode = this.props.islandMode ? this.props.islandMode : 'advanced' let islandMode = this.props.islandMode ? this.props.islandMode : 'advanced'
// TODO delete the following line before merging
islandMode = 'advanced'
return CONFIGURATION_TABS_PER_MODE[islandMode]; return CONFIGURATION_TABS_PER_MODE[islandMode];
} }
setInitialConfig(config) { setInitialConfig(config) {
// Sets a reference to know if config was changed // Sets a reference to know if config was changed
config['attack'] = {}
this.currentFormData = {}
this.initialConfig = JSON.parse(JSON.stringify(config)); this.initialConfig = JSON.parse(JSON.stringify(config));
} }
@ -230,6 +230,9 @@ class ConfigurePageComponent extends AuthComponent {
onChange = ({formData}) => { onChange = ({formData}) => {
let configuration = this.state.configuration; let configuration = this.state.configuration;
if (this.state.selectedSection === 'attack'){
formData = {};
}
configuration[this.state.selectedSection] = formData; configuration[this.state.selectedSection] = formData;
this.setState({currentFormData: formData, configuration: configuration}); this.setState({currentFormData: formData, configuration: configuration});
}; };
@ -237,10 +240,7 @@ class ConfigurePageComponent extends AuthComponent {
updateConfigSection = () => { updateConfigSection = () => {
let newConfig = this.state.configuration; let newConfig = this.state.configuration;
if (this.currentSection === 'attack' && this.state.currentFormData === undefined) { if (Object.keys(this.state.currentFormData).length > 0) {
this.state.currentFormData = this.state.attackConfig;
}
else if (Object.keys(this.state.currentFormData).length > 0) {
newConfig[this.currentSection] = this.state.currentFormData; newConfig[this.currentSection] = this.state.currentFormData;
} }
this.setState({configuration: newConfig, lastAction: 'none'}); this.setState({configuration: newConfig, lastAction: 'none'});
@ -340,14 +340,13 @@ class ConfigurePageComponent extends AuthComponent {
this.setState({showAttackAlert: true}); this.setState({showAttackAlert: true});
return; return;
} }
this.updateConfigSection(); this.updateConfigSection();
this.currentSection = key; this.currentSection = key;
this.setState({ this.setState({
selectedSection: key, selectedSection: key,
currentFormData: this.state.configuration[key] currentFormData: this.state.configuration[key]
}); });
}; };
resetConfig = () => { resetConfig = () => {
@ -359,6 +358,7 @@ class ConfigurePageComponent extends AuthComponent {
}) })
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
res.configuration['attack'] = {}
this.setState({ this.setState({
lastAction: 'reset', lastAction: 'reset',
schema: res.schema, schema: res.schema,