@@ -40,14 +40,16 @@ export function* lcManager() {
40
40
] ) ;
41
41
42
42
/**
43
- * This is the current state of the application. Depending on what action is yielded, modify
44
- * this object accordingly then update it via dispatch .
43
+ * This is the current state of the application. Action handlers should return newLayoutInfo if state changes
44
+ * If state has changed, it will be dispacthed into the flux .
45
45
* @type {LayoutInfo }
46
46
* @prop {boolean } layoutInfo.showForm show form panel
47
47
* @prop {boolean } layoutInfo.showTables show tables panel
48
48
* @prop {boolean } layoutInfo.showCharts show charts panel
49
49
* @prop {boolean } layoutInfo.showImages show images panel
50
50
* @prop {string } layoutInfo.searchDesc optional string describing search criteria used to generate this result.
51
+ * @prop {Object } layoutInfo.images images specific states
52
+ * @prop {string } layoutInfo.images.activeTableId last active table id that images responded to
51
53
*/
52
54
var layoutInfo = getLayouInfo ( ) ;
53
55
var newLayoutInfo = layoutInfo ;
@@ -59,10 +61,10 @@ export function* lcManager() {
59
61
newLayoutInfo = handleTableLoad ( newLayoutInfo , action ) ;
60
62
break ;
61
63
case TABLE_HIGHLIGHT :
62
- handleTableHighlight ( PHASE_FOLDED , action ) ;
64
+ newLayoutInfo = handleTableHighlight ( newLayoutInfo , action ) ;
63
65
break ;
64
66
case CHANGE_VIEWER_LAYOUT :
65
- handleChangeMultiViewLayout ( PHASE_FOLDED ) ;
67
+ newLayoutInfo = handleChangeMultiViewLayout ( newLayoutInfo , action ) ;
66
68
break ;
67
69
case TBL_RESULTS_ACTIVE :
68
70
newLayoutInfo = handleTableActive ( newLayoutInfo , action ) ;
@@ -79,47 +81,42 @@ export function* lcManager() {
79
81
80
82
function handleTableLoad ( layoutInfo , action ) {
81
83
const { tbl_id} = action . payload ;
82
- layoutInfo = updateSet ( layoutInfo , 'showTables' , true ) ;
83
- if ( [ RAW_TABLE , PEAK_TABLE , PHASE_FOLDED , PERIODOGRAM ] . includes ( tbl_id ) ) {
84
- layoutInfo = updateSet ( layoutInfo , 'showXyPlots' , true ) ;
85
- }
86
- if ( [ PHASE_FOLDED ] . includes ( tbl_id ) ) {
84
+ layoutInfo = Object . assign ( { } , layoutInfo , { showTables : true , showXyPlots : true } ) ;
85
+ if ( isImageEnabledTable ( tbl_id ) ) {
87
86
layoutInfo = updateSet ( layoutInfo , 'showImages' , true ) ;
88
- handleTableHighlight ( PHASE_FOLDED , action ) ;
87
+ layoutInfo = updateSet ( layoutInfo , 'images.activeTableId' , tbl_id ) ;
88
+ exec ( setupImages , tbl_id ) ;
89
89
}
90
90
return layoutInfo ;
91
91
}
92
92
93
93
94
94
95
95
function handleTableActive ( layoutInfo , action ) {
96
+ const { tbl_id} = action . payload ;
97
+ if ( isImageEnabledTable ( tbl_id ) ) {
98
+ layoutInfo = updateSet ( layoutInfo , 'images.activeTableId' , tbl_id ) ;
99
+ exec ( setupImages , tbl_id ) ;
100
+ }
96
101
return layoutInfo ;
97
102
}
98
103
99
- /**
100
- *
101
- * @param {string } activePhaseFoldedTableId last active phase folded table id
102
- * @param {Action } action
103
- */
104
- function handleTableHighlight ( activePhaseFoldedTableId , action ) {
104
+ function handleTableHighlight ( layoutInfo , action ) {
105
105
const { tbl_id} = action . payload ;
106
- if ( tbl_id === activePhaseFoldedTableId ) {
107
- try {
108
- setupImages ( tbl_id ) ;
109
- } catch ( E ) {
110
- console . log ( E . toString ( ) ) ;
111
- }
112
-
106
+ if ( isImageEnabledTable ( tbl_id ) ) {
107
+ exec ( setupImages , tbl_id ) ;
113
108
}
114
109
}
115
110
116
- /**
117
- *
118
- * @param {string } activePhaseFoldedTableId last active phase folded table id
119
- */
120
- function handleChangeMultiViewLayout ( activePhaseFoldedTableId ) {
121
- const tbl = getTblById ( activePhaseFoldedTableId ) ;
122
- if ( get ( tbl , 'totalRows' , 0 ) > 0 ) setupImages ( activePhaseFoldedTableId ) ;
111
+ function isImageEnabledTable ( tbl_id ) {
112
+ return [ PHASE_FOLDED , RAW_TABLE ] . includes ( tbl_id ) ;
113
+ }
114
+
115
+ function handleChangeMultiViewLayout ( layoutInfo , action ) {
116
+ const activeTableId = get ( layoutInfo , 'images.activeTableId' ) ;
117
+ const tbl = getTblById ( activeTableId ) ;
118
+ if ( get ( tbl , 'totalRows' , 0 ) > 0 ) exec ( setupImages , activeTableId ) ;
119
+ return layoutInfo ;
123
120
}
124
121
125
122
function getWebPlotRequest ( tableModel , hlrow ) {
@@ -208,3 +205,17 @@ function makePlotIds(highlightedRow, totalRows, totalPlots) {
208
205
return plotIds ;
209
206
}
210
207
208
+
209
+ /**
210
+ * A simple wrapper to catch the exception then log it to console
211
+ * @param {function } f function to execute
212
+ * @param {* } args function's arguments.
213
+ */
214
+ function exec ( f , args ) {
215
+ try {
216
+ f ( args ) ;
217
+ } catch ( E ) {
218
+ console . log ( E . toString ( ) ) ;
219
+ }
220
+
221
+ }
0 commit comments