@@ -3,14 +3,15 @@ import * as FlexLayout from 'geppetto-client/js/components/interface/flexLayout2
33import Actions from '@geppettoengine/geppetto-client/js/components/interface/flexLayout2/src/model/Actions' ;
44
55
6- import { WidgetStatus } from '../../constants' ;
6+ import { WidgetStatus , WIDGETS_IDS } from '../../constants' ;
77import { isEqual } from '../../Utils' ;
88import WidgetFactory from './WidgetFactory' ;
99import TabsetIconFactory from './TabsetIconFactory'
1010import defaultLayoutConfiguration from './layoutConf.json' ;
1111
1212import { withStyles } from '@material-ui/core/styles'
1313import onAction from './OnLayoutAction' ;
14+ import { getPythonDefaultConsoleWidget } from '../../redux/reducers/flexlayout' ;
1415
1516/**
1617 * Transforms a widget configutation into a flexlayout node descriptor
@@ -77,18 +78,18 @@ class LayoutManager extends Component {
7778
7879 const { widgets } = this . props ;
7980 const oldWidgets = prevProps . widgets ;
81+
8082 const newWidgets = this . findNewWidgets ( widgets , oldWidgets ) ;
8183 if ( newWidgets . length > 0 ) {
8284 this . addWidgets ( newWidgets ) ;
8385 }
8486
8587 const updatedWidgets = this . findUpdatedWidgets ( widgets , oldWidgets ) ;
8688 if ( updatedWidgets ) {
87- this . updateWidgets ( updatedWidgets ) ;
89+ this . updateWidgets ( updatedWidgets , oldWidgets ) ;
8890 }
8991
9092 const deletedWidgets = this . findDeletedWidgets ( widgets , oldWidgets ) ;
91-
9293 if ( deletedWidgets ) {
9394 this . deleteWidgets ( deletedWidgets ) ;
9495 }
@@ -170,19 +171,23 @@ class LayoutManager extends Component {
170171 }
171172 }
172173
173- updateWidgets ( widgets ) {
174+ updateWidgets ( widgets , oldWidgets ) {
174175 const model = this . getModel ( )
175176 for ( let widget of widgets ) {
176177
177178 this . updateWidget ( widget ) ;
178179
179- // This updates plotly.js plots to new panel sizes
180- if ( widget . status == WidgetStatus . ACTIVE ) {
181- model . doAction ( FlexLayout . Actions . selectTab ( widget . id ) ) ;
180+ if ( oldWidgets [ widget . id ] . status === WidgetStatus . BORDER && widget . status !== WidgetStatus . BORDER ) {
181+ this . restoreWidgetFromBottom ( widget )
182+ } else if ( oldWidgets [ widget . id ] . status !== WidgetStatus . BORDER && widget . status === WidgetStatus . BORDER ) {
183+ this . moveWidget ( widget )
184+ } else {
185+ // update plotly.js plots to new panel sizes
186+ if ( widget . status == WidgetStatus . ACTIVE ) {
187+ model . doAction ( FlexLayout . Actions . selectTab ( widget . id ) ) ;
188+ }
182189 }
183-
184190 }
185- // window.dispatchEvent(new Event('resize'));
186191 }
187192
188193 updateWidget ( widget ) {
@@ -228,31 +233,40 @@ class LayoutManager extends Component {
228233 }
229234
230235
231- clickOnBordersAction ( node ) {
236+ restoreWidgetFromBottom ( widget ) {
232237 const model = this . getModel ( )
233- let tabset = model . getNodeById ( 'consolePanel' )
238+ // We only allow python console to be send to the bottom
239+ const panelName = getPythonDefaultConsoleWidget ( this . props . editMode ) . panelName
240+ let tabset = model . getNodeById ( panelName )
234241 if ( tabset === undefined ) {
235- this . createTabSet ( 'consolePanel' )
242+ this . createTabSet ( panelName )
236243 }
237- model . doAction ( FlexLayout . Actions . moveNode ( node . getId ( ) , 'consolePanel' , FlexLayout . DockLocation . CENTER , 0 ) ) ;
244+ this . moveWidget ( widget )
238245 }
239246
247+
248+ moveWidget ( widget ) {
249+ const model = this . getModel ( )
250+ model . doAction ( FlexLayout . Actions . moveNode ( widget . id , widget . panelName , FlexLayout . DockLocation . CENTER , 0 ) ) ;
251+ // Resize of canvas and SVG images
252+ window . dispatchEvent ( new Event ( 'resize' ) ) ;
253+ }
254+
240255 onRenderTab ( node , renderValues ) {
241- console . log ( 'pepe' )
242256 }
243257 render ( ) {
244258 const { classes, widgets } = this . props
259+ const model = this . getModel ( )
245260 return (
246261 < div className = { classes . container } >
247262 < div className = { classes . spacer } />
248263 < div className = { classes . flexlayout } >
249264 < FlexLayout . Layout
250265 ref = "layout"
251- model = { this . getModel ( ) }
266+ model = { model }
252267 factory = { this . factory . bind ( this ) }
253268 iconFactory = { this . iconFactory . bind ( this ) }
254- onAction = { action => onAction ( action , widgets , this . getModel ( ) , this . props . updateWidget , this . activateWidget , this . destroyWidget , this . maximizeWidget , this . minimizeWidget ) }
255- clickOnBordersAction = { node => this . clickOnBordersAction ( node ) }
269+ onAction = { action => onAction ( action , widgets , model , this . props . updateWidget , this . activateWidget , this . destroyWidget , this . maximizeWidget , this . minimizeWidget ) }
256270 onRenderTab = { ( node , renderValues ) => this . onRenderTab ( node , renderValues ) }
257271 />
258272 </ div >
0 commit comments