diff --git a/src/dashboard/dashboard.js b/src/dashboard/dashboard.js index 8fbbdee..bb67b97 100644 --- a/src/dashboard/dashboard.js +++ b/src/dashboard/dashboard.js @@ -54,6 +54,7 @@ class Dashboard extends Component { if (prevState == null) { prevState = {}; } + const sessionToken = LoginStore.getState().token; let dashboard = DashboardStore.getState().find(d => d.id === parseInt(props.match.params.dashboard, 10)); @@ -96,7 +97,7 @@ class Dashboard extends Component { modalData: null, modalIndex: null, widgetChangeData: [], - widgetAddData:[], + widgetAddData:prevState.widgetAddData || [], maxWidgetHeight: maxHeight || null, dropZoneHeight: maxHeight +80 || null, @@ -167,6 +168,10 @@ class Dashboard extends Component { handleDrop(widget) { widget.dashboardID = this.state.dashboard.id; + let tempChanges = this.state.widgetAddData; + tempChanges.push(widget); + + this.setState({ widgetAddData: tempChanges}) AppDispatcher.dispatch({ type: 'widgets/start-add', @@ -174,10 +179,7 @@ class Dashboard extends Component { data: widget }); - let tempChanges = this.state.widgetAddData; - tempChanges.push(widget); - this.setState({ widgetAddData: tempChanges}) /*let widgets = []; widgets = this.state.dashboard.get('widgets'); @@ -297,15 +299,17 @@ class Dashboard extends Component { } cancelEditing() { - console.log("cancelEditing the add data: "); - console.log(this.state.widgetAddData); + //raw widget has no id -> cannot be deleted in its original form + /* this.state.widgetAddData.forEach( widget => { AppDispatcher.dispatch({ type: 'widgets/start-remove', data: widget, token: this.state.sessionToken }); - }); + }); */ + + AppDispatcher.dispatch({ type: 'widgets/start-load', token: this.state.sessionToken, diff --git a/src/dashboard/widget-context-menu.js b/src/dashboard/widget-context-menu.js index 9e3ca2f..dcf444f 100644 --- a/src/dashboard/widget-context-menu.js +++ b/src/dashboard/widget-context-menu.js @@ -113,7 +113,7 @@ class WidgetContextMenu extends React.Component { ); return
- + Image - this.props.handleChange(e)}> + this.props.handleChange(e)}> {this.props.files.length === 0 ? ( ) : ( @@ -96,8 +96,8 @@ class EditImageWidgetControl extends React.Component { this.setState({ fileList: e.target.files }) } /> - - + +
; } } diff --git a/src/widget/edit-widget.js b/src/widget/edit-widget.js index 621dc03..f039f48 100644 --- a/src/widget/edit-widget.js +++ b/src/widget/edit-widget.js @@ -28,22 +28,23 @@ 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: {}, }; } - + static getDerivedStateFromProps(props, state){ + return { + temporal: props.widget + }; + } + + onClose(canceled) { if (canceled === false) { @@ -67,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) => { @@ -78,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') { @@ -100,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() {