@@ -8,6 +8,7 @@ import { isEqual } from '../../Utils';
88import WidgetFactory from './WidgetFactory' ;
99import TabsetIconFactory from './TabsetIconFactory'
1010import defaultLayoutConfiguration from './layoutConf.json' ;
11+ import simulateLayoutConfiguration from './simulateLayoutConf.json' ;
1112
1213/**
1314 * Transforms a widget configutation into a flexlayout node descriptor
@@ -33,7 +34,6 @@ export default class LayoutManager extends Component {
3334 constructor ( props ) {
3435 super ( props ) ;
3536 const layout = this . props . layout ? this . props . layout : defaultLayoutConfiguration ;
36- this . model = FlexLayout . Model . fromJson ( layout ) ;
3737 this . destroyWidget = this . props . destroyWidget ? this . props . destroyWidget : ( ) => console . debug ( 'destroyWidget not defined' ) ;
3838 this . activateWidget = this . props . activateWidget ? this . props . activateWidget : ( ) => console . debug ( 'activateWidget not defined' ) ;
3939 this . maximizeWidget = this . props . maximizeWidget ? this . props . maximizeWidget : ( ) => console . debug ( 'maximizeWidget not defined' ) ;
@@ -42,19 +42,34 @@ export default class LayoutManager extends Component {
4242
4343 this . widgetFactory = this . props . widgetFactory ? this . props . widgetFactory : new WidgetFactory ( ) ;
4444 this . tabsetIconFactory = this . props . TabsetIconFactory ? this . props . TabsetIconFactory : new TabsetIconFactory ( ) ;
45+
46+ this . cacheModels = {
47+ edit : FlexLayout . Model . fromJson ( layout ) ,
48+ simulate : FlexLayout . Model . fromJson ( simulateLayoutConfiguration )
49+ }
4550 }
51+
52+
4653 componentDidMount ( ) {
4754 const { widgets } = this . props ;
4855 this . addWidgets ( Object . values ( widgets ) ) ;
4956 }
5057
5158 componentDidUpdate ( prevProps , prevState ) {
59+ if ( prevProps . editMode !== this . props . editMode ) {
60+ return
61+ }
62+
5263 const { widgets } = this . props ;
5364 const oldWidgets = prevProps . widgets ;
5465 const newWidgets = this . findNewWidgets ( widgets , oldWidgets ) ;
55- if ( newWidgets ) {
66+ if ( newWidgets . length > 0 ) {
5667 this . addWidgets ( newWidgets ) ;
5768 }
69+
70+ if ( ! this . props . editMode && ! this . cacheModels . simulate . getNodeById ( widgets . python . id ) ) {
71+ this . addWidgets ( [ widgets . python ] ) ;
72+ }
5873
5974 const updatedWidgets = this . findUpdatedWidgets ( widgets , oldWidgets ) ;
6075 if ( updatedWidgets ) {
@@ -68,8 +83,15 @@ export default class LayoutManager extends Component {
6883 }
6984 }
7085
86+ getModel ( ) {
87+ if ( this . props . editMode ) {
88+ return this . cacheModels . edit
89+ }
90+ return this . cacheModels . simulate
91+ }
92+
7193 addWidgets ( widgets ) {
72- const { model } = this ;
94+ const model = this . getModel ( )
7395 for ( let newWidgetDescriptor of widgets ) {
7496
7597 if ( ! model . getNodeById ( newWidgetDescriptor . id ) ) {
@@ -82,16 +104,17 @@ export default class LayoutManager extends Component {
82104 for ( let widget of widgets ) {
83105
84106 if ( widget . status == WidgetStatus . ACTIVE ) {
85- this . model . doAction ( FlexLayout . Actions . selectTab ( widget . id ) ) ;
107+ model . doAction ( FlexLayout . Actions . selectTab ( widget . id ) ) ;
86108 }
87109
88110 }
89111 // window.dispatchEvent(new Event('resize'));
90112 }
91113
92114 deleteWidgets ( widgets ) {
115+ const model = this . getModel ( )
93116 for ( let widget of widgets ) {
94- this . model . doAction ( FlexLayout . Actions . deleteTab ( widget . id ) ) ;
117+ model . doAction ( FlexLayout . Actions . deleteTab ( widget . id ) ) ;
95118 }
96119 }
97120
@@ -100,24 +123,25 @@ export default class LayoutManager extends Component {
100123 }
101124
102125 updateWidgets ( widgets ) {
103-
126+ const model = this . getModel ( )
104127 for ( let widget of widgets ) {
105128
106129 this . updateWidget ( widget ) ;
107130
108131 // This updates plotly.js plots to new panel sizes
109132 if ( widget . status == WidgetStatus . ACTIVE ) {
110- this . model . doAction ( FlexLayout . Actions . selectTab ( widget . id ) ) ;
133+ model . doAction ( FlexLayout . Actions . selectTab ( widget . id ) ) ;
111134 }
112135
113136 }
114137 // window.dispatchEvent(new Event('resize'));
115138 }
116139
117140 updateWidget ( widget ) {
141+ const model = this . getModel ( )
118142 if ( widget ) {
119143 this . widgetFactory . updateWidget ( widget ) ;
120- this . model . doAction ( Actions . updateNodeAttributes ( widget . id , widget2Node ( widget ) ) ) ;
144+ model . doAction ( Actions . updateNodeAttributes ( widget . id , widget2Node ( widget ) ) ) ;
121145 }
122146
123147 }
@@ -128,6 +152,7 @@ export default class LayoutManager extends Component {
128152 }
129153
130154 iconFactory ( node ) {
155+ // TODO move to newest flexlayout-react to add this functionality
131156 return this . tabsetIconFactory . factory ( node . getConfig ( ) ) ;
132157 }
133158
@@ -152,6 +177,7 @@ export default class LayoutManager extends Component {
152177
153178
154179 onAction ( action ) {
180+ const model = this . getModel ( )
155181 switch ( action . type ) {
156182 case Actions . SET_ACTIVE_TABSET :
157183 break ;
@@ -173,11 +199,11 @@ export default class LayoutManager extends Component {
173199 break ;
174200 }
175201
176- this . model . doAction ( action ) ;
202+ model . doAction ( action ) ;
177203 }
178204
179205 onActionMaximizeWidget ( action ) {
180- const { model } = this ;
206+ const model = this . getModel ( )
181207 const { widgets } = this . props ;
182208 const { maximizeWidget, activateWidget } = this ;
183209 const panel2maximize = model . getNodeById ( action . data . node ) ;
@@ -203,7 +229,7 @@ export default class LayoutManager extends Component {
203229 }
204230
205231 onActionDeleteWidget ( action ) {
206- const { model } = this ;
232+ const model = this . getModel ( )
207233 const { widgets } = this . props ;
208234 const maximizedWidget = this . findMaximizedWidget ( widgets ) ;
209235 // change widget status
@@ -226,14 +252,16 @@ export default class LayoutManager extends Component {
226252
227253
228254 clickOnBordersAction ( node ) {
229- this . model . doAction ( FlexLayout . Actions . moveNode ( node . getId ( ) , 'bottomPanel' , FlexLayout . DockLocation . CENTER , 0 ) ) ;
255+ const model = this . getModel ( )
256+ model . doAction ( FlexLayout . Actions . moveNode ( node . getId ( ) , 'bottomPanel' , FlexLayout . DockLocation . CENTER , 0 ) ) ;
230257 }
231258
232259 onRenderTabSet ( panel , renderValues ) {
260+ const model = this . getModel ( )
233261 if ( panel . getType ( ) === "tabset" ) {
234262 if ( panel . getId ( ) != 'leftPanel' && panel . getChildren ( ) . length > 0 ) {
235263 renderValues . buttons . push ( < div key = { panel . getId ( ) } className = "fa fa-window-minimize customIconFlexLayout" onClick = { ( ) => {
236- this . model . doAction ( FlexLayout . Actions . moveNode ( panel . getSelectedNode ( ) . getId ( ) , "border_bottom" , FlexLayout . DockLocation . CENTER , 0 ) ) ;
264+ model . doAction ( FlexLayout . Actions . moveNode ( panel . getSelectedNode ( ) . getId ( ) , "border_bottom" , FlexLayout . DockLocation . CENTER , 0 ) ) ;
237265 } } /> ) ;
238266 }
239267 }
@@ -244,7 +272,7 @@ export default class LayoutManager extends Component {
244272 < div style = { { position : 'relative' , flexGrow : 1 } } >
245273 < FlexLayout . Layout
246274 ref = "layout"
247- model = { this . model }
275+ model = { this . getModel ( ) }
248276 factory = { this . factory . bind ( this ) }
249277 iconFactory = { this . iconFactory . bind ( this ) }
250278 onAction = { action => this . onAction ( action ) }
0 commit comments