forked from p15670423/monkey
Fix config bug that only subset of config was sent
This commit is contained in:
parent
61f4a08ef3
commit
fedafa6583
|
@ -6,6 +6,9 @@ class ConfigurePageComponent extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.currentSection = 'basic';
|
||||||
|
this.currentFormData = {};
|
||||||
|
|
||||||
// set schema from server
|
// set schema from server
|
||||||
this.state = {
|
this.state = {
|
||||||
schema: {},
|
schema: {},
|
||||||
|
@ -31,11 +34,18 @@ class ConfigurePageComponent extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit = ({formData}) => {
|
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',
|
fetch('/api/configuration',
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify(formData)
|
body: JSON.stringify(this.state.configuration)
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
@ -48,9 +58,21 @@ class ConfigurePageComponent extends React.Component {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onChange = ({formData}) => {
|
||||||
|
this.currentFormData = formData;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: remove code duplication
|
||||||
setSelectedSection = (key) => {
|
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({
|
this.setState({
|
||||||
selectedSection: key
|
selectedSection: key,
|
||||||
|
configuration: newConfig
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -76,8 +98,9 @@ class ConfigurePageComponent extends React.Component {
|
||||||
|
|
||||||
{ this.state.selectedSection ?
|
{ this.state.selectedSection ?
|
||||||
<Form schema={displayedSchema}
|
<Form schema={displayedSchema}
|
||||||
formData={this.state.configuration}
|
formData={this.state.configuration[this.state.selectedSection]}
|
||||||
onSubmit={this.onSubmit}/>
|
onSubmit={this.onSubmit}
|
||||||
|
onChange={this.onChange} />
|
||||||
: ''}
|
: ''}
|
||||||
|
|
||||||
<div className="alert alert-info">
|
<div className="alert alert-info">
|
||||||
|
|
Loading…
Reference in New Issue