From d954941d9f6de7c39643dd9b768a42999a8ed160 Mon Sep 17 00:00:00 2001 From: Laura Fuentes Grau Date: Tue, 28 Jan 2020 12:31:36 +0100 Subject: [PATCH] most widgets now editable again --- src/dashboard/dashboard.js | 23 +++++++++++++++-------- src/dashboard/widget-context-menu.js | 2 +- src/widget/edit-widget-color-control.js | 2 +- src/widget/edit-widget-image-control.js | 6 +++--- src/widget/edit-widget.js | 6 ++++++ 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/dashboard/dashboard.js b/src/dashboard/dashboard.js index 7180a81..b0e0f6f 100644 --- a/src/dashboard/dashboard.js +++ b/src/dashboard/dashboard.js @@ -56,6 +56,7 @@ class Dashboard extends Component { if (prevState == null) { prevState = {}; } + const sessionToken = LoginStore.getState().token; let maxHeight = null; let dashboard = Map(); @@ -163,7 +164,7 @@ class Dashboard extends Component { modalData: null, modalIndex: null, widgetChangeData: [], - widgetAddData:[], + widgetAddData:prevState.widgetAddData || [], maxWidgetHeight: maxHeight || null, dropZoneHeight: maxHeight +80 || null, @@ -298,6 +299,12 @@ class Dashboard extends Component { handleDrop(widget) { widget.dashboardID = this.state.dashboard.get('id'); console.log(widget); + let tempChanges = this.state.widgetAddData; + tempChanges.push(widget); + console.log("handle drop. the temp changes: "); + console.log(tempChanges); + + this.setState({ widgetAddData: tempChanges}) AppDispatcher.dispatch({ type: 'widgets/start-add', @@ -305,10 +312,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'); @@ -428,15 +432,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, @@ -462,6 +468,7 @@ class Dashboard extends Component { render() { + const widgets = this.state.dashboard.get('widgets'); const grid = this.state.dashboard.get('grid'); const boxClasses = classNames('section', 'box', { 'fullscreen-padding': this.props.isFullscreen }); diff --git a/src/dashboard/widget-context-menu.js b/src/dashboard/widget-context-menu.js index ae8c40f..1fa0967 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..d56dae3 100644 --- a/src/widget/edit-widget.js +++ b/src/widget/edit-widget.js @@ -43,6 +43,12 @@ class EditWidgetDialog extends React.Component { }; } + static getDerivedStateFromProps(props, state){ + return { + temporal: props.widget + }; + } + onClose(canceled) {