@@ -39,6 +39,7 @@ import {
3939 PanelEvent ,
4040 setDashboardData as setDashboardDataAction ,
4141 setDashboardPluginData as setDashboardPluginDataAction ,
42+ stopListenForCreateDashboard ,
4243 updateDashboardData as updateDashboardDataAction ,
4344} from '@deephaven/dashboard' ;
4445import {
@@ -203,6 +204,8 @@ export class AppMainContainer extends Component<
203204
204205 const { allDashboardData } = this . props ;
205206
207+ this . dashboardLayouts = new Map ( ) ;
208+
206209 this . state = {
207210 contextActions : [
208211 {
@@ -261,6 +264,7 @@ export class AppMainContainer extends Component<
261264
262265 componentDidMount ( ) : void {
263266 this . initWidgets ( ) ;
267+ this . initDashboardData ( ) ;
264268 this . startListeningForDisconnect ( ) ;
265269
266270 window . addEventListener (
@@ -283,13 +287,18 @@ export class AppMainContainer extends Component<
283287 this . deinitWidgets ( ) ;
284288 this . stopListeningForDisconnect ( ) ;
285289
290+ this . dashboardLayouts . forEach ( layout => {
291+ stopListenForCreateDashboard ( layout . eventHub , this . handleCreateDashboard ) ;
292+ } ) ;
293+
286294 window . removeEventListener (
287295 'beforeunload' ,
288296 AppMainContainer . handleWindowBeforeUnload
289297 ) ;
290298 }
291299
292- goldenLayout ?: GoldenLayout ;
300+ /** Map from the dashboard ID to the GoldenLayout instance for that dashboard */
301+ dashboardLayouts : Map < string , GoldenLayout > ;
293302
294303 importElement : RefObject < HTMLInputElement > ;
295304
@@ -337,6 +346,28 @@ export class AppMainContainer extends Component<
337346 this . widgetListenerRemover ?.( ) ;
338347 }
339348
349+ initDashboardData ( ) : void {
350+ // TODO: #1746 We should be loading data from a dashboard storage store
351+ // For now only the default dashboard data is stored with the workspace and set on the default dashboard
352+ const { setDashboardPluginData, updateDashboardData, workspace } =
353+ this . props ;
354+ const { data : workspaceData } = workspace ;
355+ const { filterSets, links, pluginDataMap } = workspaceData ;
356+ updateDashboardData ( DEFAULT_DASHBOARD_ID , {
357+ filterSets,
358+ links,
359+ } ) ;
360+ if ( pluginDataMap != null ) {
361+ const pluginKeys = Object . keys ( pluginDataMap ) ;
362+ for ( let i = 0 ; i < pluginKeys . length ; i += 1 ) {
363+ const pluginId = pluginKeys [ i ] ;
364+ const pluginData = pluginDataMap [ pluginId ] ;
365+ log . debug ( 'initDashboardData plugin data' , pluginId , pluginData ) ;
366+ setDashboardPluginData ( DEFAULT_DASHBOARD_ID , pluginId , pluginData ) ;
367+ }
368+ }
369+ }
370+
340371 openNotebookFromURL ( ) : void {
341372 const { match } = this . props ;
342373 const { notebookPath } = match . params ;
@@ -374,7 +405,9 @@ export class AppMainContainer extends Component<
374405 }
375406
376407 emitLayoutEvent ( event : string , ...args : unknown [ ] ) : void {
377- this . goldenLayout ?. eventHub . emit ( event , ...args ) ;
408+ const { activeTabKey } = this . state ;
409+ const layout = this . dashboardLayouts . get ( activeTabKey ) ;
410+ layout ?. eventHub . emit ( event , ...args ) ;
378411 }
379412
380413 handleCancelResetLayoutPrompt ( ) : void {
@@ -465,16 +498,25 @@ export class AppMainContainer extends Component<
465498 const { updateWorkspaceData } = this . props ;
466499
467500 // Only save the data that is serializable/we want to persist to the workspace
468- const { closed, filterSets, links } = data ;
469- updateWorkspaceData ( { closed, filterSets, links } ) ;
501+ const { closed, filterSets, links, pluginDataMap } = data ;
502+ updateWorkspaceData ( { closed, filterSets, links, pluginDataMap } ) ;
470503 }
471504
472- handleGoldenLayoutChange ( goldenLayout : GoldenLayout ) : void {
473- this . goldenLayout = goldenLayout ;
474- listenForCreateDashboard (
475- this . goldenLayout . eventHub ,
476- this . handleCreateDashboard
477- ) ;
505+ handleGoldenLayoutChange ( newLayout : GoldenLayout ) : void {
506+ const { activeTabKey } = this . state ;
507+ const oldLayout = this . dashboardLayouts . get ( activeTabKey ) ;
508+ if ( oldLayout === newLayout ) return ;
509+
510+ if ( oldLayout != null ) {
511+ stopListenForCreateDashboard (
512+ oldLayout . eventHub ,
513+ this . handleCreateDashboard
514+ ) ;
515+ }
516+
517+ this . dashboardLayouts . set ( activeTabKey , newLayout ) ;
518+
519+ listenForCreateDashboard ( newLayout . eventHub , this . handleCreateDashboard ) ;
478520 }
479521
480522 handleCreateDashboard ( {
0 commit comments