From fedafa6583c205f3ca11e91cf8d0aa7e1a1b6d62 Mon Sep 17 00:00:00 2001 From: Itay Mizeretz Date: Tue, 19 Sep 2017 19:08:27 +0300 Subject: [PATCH] Fix config bug that only subset of config was sent --- .../ui/src/components/pages/ConfigurePage.js | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index 3383ee336..dbd8f3991 100644 --- a/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -6,6 +6,9 @@ class ConfigurePageComponent extends React.Component { constructor(props) { super(props); + this.currentSection = 'basic'; + this.currentFormData = {}; + // set schema from server this.state = { schema: {}, @@ -31,11 +34,18 @@ class ConfigurePageComponent extends React.Component { } onSubmit = ({formData}) => { + this.currentFormData = formData; + let newConfig = this.state.configuration; + if (this.currentFormData != {}) { + newConfig[this.currentSection] = this.currentFormData; + this.currentFormData = {}; + } + this.setState({configuration: newConfig}); fetch('/api/configuration', { method: 'POST', headers: {'Content-Type': 'application/json'}, - body: JSON.stringify(formData) + body: JSON.stringify(this.state.configuration) }) .then(res => res.json()) .then(res => { @@ -48,9 +58,21 @@ class ConfigurePageComponent extends React.Component { }); }; + onChange = ({formData}) => { + this.currentFormData = formData; + }; + + // TODO: remove code duplication setSelectedSection = (key) => { + let newConfig = this.state.configuration; + if (Object.keys(this.currentFormData).length > 0) { + newConfig[this.currentSection] = this.currentFormData; + this.currentFormData = {}; + } + this.currentSection = key; this.setState({ - selectedSection: key + selectedSection: key, + configuration: newConfig }); }; @@ -76,8 +98,9 @@ class ConfigurePageComponent extends React.Component { { this.state.selectedSection ?
+ formData={this.state.configuration[this.state.selectedSection]} + onSubmit={this.onSubmit} + onChange={this.onChange} /> : ''}