@@ -16,6 +16,8 @@ import {
1616// and ensured that plot data doesn't lead to performance issues due to possible deep-copy in reducers.
1717window . plotCache = { } ;
1818
19+ const isDisabled = ( widget , plots ) => ! plots [ widget . method . plotKey ] ?? true ;
20+
1921export default ( store ) => ( next ) => ( action ) => {
2022 async function setWidget ( widget ) {
2123 const {
@@ -28,11 +30,9 @@ export default (store) => (next) => (action) => {
2830 widget . initialized = true ;
2931 if ( data ) {
3032 console . debug ( 'Plot retrieved:' , widget . id ) ;
31- widget . disabled = false ;
3233 return widget ;
3334 }
3435 console . warn ( 'Plot not retrieved:' , widget . id ) ;
35- widget . disabled = true ;
3636 return widget ;
3737 } ) ;
3838 }
@@ -54,37 +54,37 @@ export default (store) => (next) => (action) => {
5454 case SET_WIDGETS : {
5555 // This is triggered once when we change the layout from Edit > Explore.
5656 // We add the widgets (back) to the sidebar but without fetching any data.
57- for ( const widget of Object . values ( action . data ) ) {
58- if ( widget . id in PLOT_WIDGETS ) {
59- next ( addWidget ( widget ) ) ;
60- }
61- }
57+ Object . values ( action . data )
58+ . filter ( ( widget ) => widget . id in PLOT_WIDGETS )
59+ . forEach ( ( widget ) => next ( addWidget ( widget ) ) ) ;
6260 next ( action ) ;
6361 break ;
6462 }
6563 case CREATE_NETWORK : {
66- // Reset network plots
67- for ( const widget of Object . values ( NETWORK_PLOT_WIDGETS ) ) {
68- delete window . plotCache [ widget . id ] ;
69- widget . initialized = false ;
70- next ( addWidget ( widget ) ) ;
71- }
64+ Utils . evalPythonMessage ( NETPYNE_COMMANDS . checkAvailablePlots , [ ] )
65+ . then ( ( plots ) => {
66+ // Only reset network plots
67+ Object . values ( NETWORK_PLOT_WIDGETS )
68+ . forEach ( ( widget ) => {
69+ delete window . plotCache [ widget . id ] ;
70+ widget . initialized = false ;
71+ widget . disabled = isDisabled ( widget , plots ) ;
72+ next ( addWidget ( widget ) ) ;
73+ } ) ;
74+ } ) ;
75+
7276 next ( action ) ;
7377 break ;
7478 }
7579 case SIMULATE_NETWORK :
7680 case CREATE_SIMULATE_NETWORK : {
77- window . plotCache = { } ;
78-
7981 Utils . evalPythonMessage ( NETPYNE_COMMANDS . checkAvailablePlots , [ ] )
8082 . then ( ( plots ) => {
83+ window . plotCache = { } ;
8184 Object . values ( PLOT_WIDGETS )
8285 . forEach ( ( widget ) => {
8386 widget . initialized = false ;
84- widget . disabled = true ;
85- if ( widget . method . plotKey in plots ) {
86- widget . disabled = ! plots [ widget . method . plotKey ] ;
87- }
87+ widget . disabled = isDisabled ( widget , plots ) ;
8888 next ( addWidget ( widget ) ) ;
8989 } ) ;
9090 } ) ;
0 commit comments