From 6fa61d07f82b709a91e23fe146f4fcc7fa6b2811 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Tue, 28 Jan 2020 14:18:02 +0100 Subject: [PATCH] initialize temporal widget as empty before it is overwritten with props widget --- src/widget/edit-widget.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/widget/edit-widget.js b/src/widget/edit-widget.js index d56dae3..f039f48 100644 --- a/src/widget/edit-widget.js +++ b/src/widget/edit-widget.js @@ -28,18 +28,13 @@ import CreateControls from './edit-widget-control-creator'; class EditWidgetDialog extends React.Component { valid = true; - + constructor(props) { super(props); this.state = { - temporal: { - name: '', - simulationModel: '', - signal: 0 - - } + temporal: {}, }; } @@ -49,7 +44,7 @@ class EditWidgetDialog extends React.Component { }; } - + onClose(canceled) { if (canceled === false) { @@ -73,7 +68,7 @@ class EditWidgetDialog extends React.Component { } handleChange(e) { - + // TODO: check what we really need in this function. Can we reduce its complexity? if (e.constructor === Array) { // Every property in the array will be updated let changes = e.reduce( (changesObject, event) => { @@ -84,7 +79,7 @@ class EditWidgetDialog extends React.Component { this.setState({ temporal: Object.assign({}, this.state.temporal, changes ) }); } - + if(e.target.type !== 'text'){ let changeObject = {}; if (e.target.id === 'lockAspect') { @@ -106,28 +101,25 @@ class EditWidgetDialog extends React.Component { } else if (e.target.type === 'number') { changeObject[e.target.id] = Number(e.target.value); } - + else { changeObject[e.target.id] = e.target.value; } let finalChange = this.state.temporal; - + finalChange.customProperties[e.target.id] = changeObject[e.target.id]; this.setState({ temporal: finalChange}); } else{ if(this.state.temporal[e.target.id]){ let finalChange = this.state.temporal; - + finalChange[e.target.id] = e.target.value; this.setState({ temporal: finalChange}); - } } - - } resetState() {