@@ -24,11 +24,10 @@ import {FieldGroupTabs, Tab} from '../../ui/panel/TabPanel.jsx';
24
24
import './ImageSelectPanel.css' ;
25
25
26
26
export const panelKey = 'FileUploadAnalysis' ;
27
- const summaryTableGroup = 'UPLOAD_SUMMARY_GROUP' ;
28
- const headerTableGroup = 'HEADER_SUMMARY_GROUP' ;
29
27
const fileId = 'fileUpload' ;
30
28
const urlId = 'urlUpload' ;
31
29
30
+ const SUMMARY_INDEX_COL = 0 ;
32
31
const SUMMARY_TYPE_COL = 2 ;
33
32
const HEADER_KEY_COL = 1 ;
34
33
const HEADER_VAL_COL = 2 ;
@@ -39,6 +38,11 @@ const isFitsFile = (analysisModel) => {
39
38
return analysisModel && get ( analysisModel , 'fileFormat' , '' ) . toLowerCase ( ) . includes ( 'fits' ) ;
40
39
} ;
41
40
41
+ /**
42
+ * check if table model contain data
43
+ * @param model
44
+ * @returns {*|boolean }
45
+ */
42
46
const isNoDataInModel = ( model ) => {
43
47
const row = model && get ( model , [ 'totalRows' ] ) ;
44
48
@@ -61,6 +65,52 @@ function makeHeaderTable(model, highlightedRow) {
61
65
return hlTable ;
62
66
}
63
67
68
+ /**
69
+ * compute highlightedRow to be the row in original table
70
+ * @param tableModel
71
+ * @param highlightedRow
72
+ * @returns {* }
73
+ */
74
+ function adjustHighlightedRow ( tableModel , highlightedRow ) {
75
+ const { data} = get ( tableModel , 'tableData' ) ;
76
+
77
+ if ( ! isNil ( highlightedRow ) ) {
78
+ return parseInt ( data [ highlightedRow ] [ SUMMARY_INDEX_COL ] ) ;
79
+ }
80
+
81
+ return - 1 ;
82
+ }
83
+
84
+ /**
85
+ * compute the selected row to be the row in the original table
86
+ * @param tableModel
87
+ * @param selectInfo
88
+ * @returns {* }
89
+ */
90
+ function adjustSelectInfo ( tableModel , selectInfo ) {
91
+ const selectInfoCls = SelectInfo . newInstance ( selectInfo ) ;
92
+ const newSelectCls = new SelectInfo . newInstance ( { rowCount : tableModel . totalRows } , selectInfoCls . offset ) ;
93
+
94
+ let bNew = false ;
95
+
96
+ Array . from ( selectInfoCls . getSelected ( ) ) . forEach ( ( idx ) => {
97
+ const newIdx = adjustHighlightedRow ( tableModel , idx ) ;
98
+
99
+ newSelectCls . setRowSelect ( newIdx , true ) ;
100
+ if ( idx !== newIdx ) {
101
+ bNew = true ;
102
+ }
103
+ } ) ;
104
+
105
+ return bNew ? newSelectCls . data : selectInfo ;
106
+ }
107
+
108
+ /**
109
+ * analyze the selected units - image, table, no data contained, exceeding the limit
110
+ * @param model
111
+ * @param limit
112
+ * @returns {{image: Array, table: Array, noDataUnit: Array, extra: Array} }
113
+ */
64
114
const getSelectionResult = ( model , limit ) => {
65
115
const { selectInfo} = model || { } ;
66
116
let results = { image : [ ] , table : [ ] , noDataUnit : [ ] , extra :[ ] } ;
@@ -105,6 +155,7 @@ export class FileUploadViewPanel extends PureComponent {
105
155
if ( ! analysisFields ) analysisFields = FieldGroupUtils . getGroupFields ( panelKey ) ;
106
156
107
157
const uploadSrc = get ( analysisFields , [ 'uploadTabs' , 'value' ] ) ;
158
+ const displayValue = get ( analysisFields , [ uploadSrc , 'displayValue' ] ) ;
108
159
const currentAnaResult = get ( analysisFields , [ uploadSrc , 'analysisResult' ] , '' ) ;
109
160
const analysisResultObj = currentAnaResult ? JSON . parse ( currentAnaResult ) : { } ;
110
161
const { analysisSummary= '' } = analysisResultObj ;
@@ -126,6 +177,7 @@ export class FileUploadViewPanel extends PureComponent {
126
177
updatePreferColumnWidth ( analysisModel ) ;
127
178
128
179
const tblInfo = getTblInfoById ( crtAnalysisId ) ;
180
+
129
181
let selectInfo = get ( tblInfo , 'selectInfo' , null ) ;
130
182
131
183
if ( ! selectInfo ) {
@@ -138,7 +190,7 @@ export class FileUploadViewPanel extends PureComponent {
138
190
}
139
191
140
192
return { analysisModel, analysisResult : currentAnaResult , analysisSummary, highlightedRow, hlHeaderTable,
141
- crtAnalysisId, isUploading : false } ;
193
+ crtAnalysisId, isUploading : false , displayValue } ;
142
194
} ;
143
195
144
196
this . state = this . getNextState ( ) ;
@@ -159,27 +211,46 @@ export class FileUploadViewPanel extends PureComponent {
159
211
if ( this . iAmMounted ) {
160
212
const analysisFields = FieldGroupUtils . getGroupFields ( panelKey ) ;
161
213
const uploadSrc = get ( analysisFields , [ 'uploadTabs' , 'value' ] ) ;
162
- const { analysisResult= '' , valid= true } = get ( analysisFields , uploadSrc ) || { } ;
214
+ const { analysisResult= '' , valid= true , displayValue } = get ( analysisFields , uploadSrc ) || { } ;
163
215
164
216
if ( ! valid ) { // upload fails
165
- this . setState ( { isUploading : false , analysisModel : null , analysisResult : '' , analysisSummary : '' , highlightedRow : - 1 ,
166
- hlHeaderTable : null } ) ;
217
+ this . setState ( {
218
+ isUploading : false ,
219
+ analysisModel : null ,
220
+ analysisResult : '' ,
221
+ analysisSummary : '' ,
222
+ highlightedRow : - 1 ,
223
+ hlHeaderTable : null
224
+ } ) ;
225
+ } else if ( ( displayValue && displayValue !== this . state . displayValue ) && uploadSrc === fileId ) { // in uploading the new file
226
+ this . setState ( {
227
+ isUploading : true ,
228
+ displayValue
229
+ } ) ;
167
230
} else if ( analysisResult !== this . state . analysisResult ) { // a new file is successfully loaded
168
231
this . setState ( this . getNextState ( analysisFields ) ) ;
169
232
} else if ( this . state . analysisModel ) { // check if highlight or selection is changed
170
233
const { crtAnalysisId} = this . state ;
171
234
172
235
if ( getTblById ( crtAnalysisId ) ) {
173
- const { highlightedRow, selectInfo} = getTblInfoById ( crtAnalysisId ) ;
236
+ let { highlightedRow, selectInfo} = getTblInfoById ( crtAnalysisId ) ;
237
+ const { tableModel} = getTblInfoById ( crtAnalysisId ) ;
174
238
175
- if ( highlightedRow !== this . state . highlightedRow ) {
176
- const hlHeaderTable = makeHeaderTable ( this . state . analysisModel , highlightedRow ) ;
239
+ if ( tableModel && tableModel . tableData ) {
240
+ highlightedRow = adjustHighlightedRow ( tableModel , highlightedRow ) ;
241
+ if ( highlightedRow !== this . state . highlightedRow ) {
242
+ const hlHeaderTable = makeHeaderTable ( this . state . analysisModel , highlightedRow ) ;
243
+
244
+ this . setState ( { highlightedRow, hlHeaderTable} ) ;
245
+ }
246
+
247
+ selectInfo = adjustSelectInfo ( tableModel , selectInfo ) ;
248
+ if ( selectInfo && ! isEqual ( selectInfo , get ( this . state . analysisModel , 'selectInfo' ) ) ) {
249
+ const analysisModel = Object . assign ( { } , this . state . analysisModel , { selectInfo} ) ;
250
+ this . setState ( { analysisModel} ) ;
251
+
252
+ }
177
253
178
- this . setState ( { highlightedRow, hlHeaderTable} ) ;
179
- }
180
- if ( selectInfo && ! isEqual ( selectInfo , get ( this . state . analysisModel , 'selectInfo' ) ) ) {
181
- const analysisModel = Object . assign ( { } , this . state . analysisModel , { selectInfo} ) ;
182
- this . setState ( { analysisModel} ) ;
183
254
}
184
255
}
185
256
}
@@ -200,39 +271,41 @@ export class FileUploadViewPanel extends PureComponent {
200
271
201
272
var displayHeaderTable = ( ) => {
202
273
203
- if ( hlHeaderTable ) {
204
- const title = hlHeaderTable . title ;
205
- const { columns, data} = get ( hlHeaderTable , 'tableData' ) || { } ;
274
+ if ( ! hlHeaderTable ) {
275
+ return false ;
276
+ }
277
+ const { columns, data} = get ( hlHeaderTable , 'tableData' ) || { } ;
206
278
207
- if ( columns && data ) {
208
- const widths = calcColumnWidths ( columns , data ) ;
279
+ if ( columns && data ) {
280
+ const widths = calcColumnWidths ( columns , data ) ;
209
281
210
- columns . forEach ( ( col , idx ) => {
211
- col . prefWidth = widths [ idx ] + 4 ;
212
- } ) ;
213
- }
282
+ columns . forEach ( ( col , idx ) => {
283
+ col . prefWidth = widths [ idx ] + 4 ;
284
+ } ) ;
285
+ }
214
286
215
- return (
216
- < div style = { { width : ( widthTotal - w1 ) , ...summaryStyle } } >
217
- < p style = { pStyle } > { title } </ p >
218
- < div style = { tableStyle } >
219
- < TablePanel
220
- key = { headerTableGroup + nowTime ( ) }
221
- tbl_ui_id = { hlHeaderTable . tbl_id }
222
- showToolbar = { false }
223
- showOptionButton = { false }
224
- selectable = { false }
225
- tableModel = { hlHeaderTable }
226
- />
227
- </ div >
287
+ return (
288
+ < div style = { { width : ( widthTotal - w1 ) , ...summaryStyle } } >
289
+ < p style = { pStyle } > { hlHeaderTable . title } </ p >
290
+ < div style = { tableStyle } >
291
+ < TablePanel
292
+ key = { hlHeaderTable . tbl_id }
293
+ tbl_ui_id = { hlHeaderTable . tbl_id }
294
+ showToolbar = { false }
295
+ showOptionButton = { false }
296
+ selectable = { false }
297
+ tableModel = { hlHeaderTable }
298
+ />
228
299
</ div >
229
- ) ;
230
- } else {
231
- return false ;
232
- }
300
+ </ div >
301
+ ) ;
233
302
} ;
234
303
235
304
var displayTable = ( ) => {
305
+ if ( ! analysisModel ) {
306
+ return false ;
307
+ }
308
+
236
309
let { selectInfo} = analysisModel || getTblInfoById ( analysisModel . tbl_id ) || { } ;
237
310
if ( isNil ( selectInfo ) ) {
238
311
selectInfo = selectRowFromSummaryTable ( analysisModel ) ;
@@ -255,7 +328,7 @@ export class FileUploadViewPanel extends PureComponent {
255
328
< p style = { pStyle } > File Summary</ p >
256
329
< div style = { tableStyle } >
257
330
< TablePanel
258
- key = { summaryTableGroup }
331
+ key = { hlTbl . tbl_id }
259
332
tbl_ui_id = { hlTbl . tbl_id }
260
333
showToolbar = { false }
261
334
showOptionButton = { false }
@@ -470,7 +543,7 @@ export function validateModelSelection(uploadTabs) {
470
543
}
471
544
472
545
const crtAnalysisId = analysisTblIds [ analysisTblIds . length - 1 ] ;
473
- const { selectInfo} = getTblInfoById ( crtAnalysisId ) ; // check if no valid extension or table selected
546
+ const { selectInfo, tableModel } = getTblInfoById ( crtAnalysisId ) ; // check if no valid extension or table selected
474
547
const selectInfoCls = SelectInfo . newInstance ( selectInfo ) ;
475
548
const bFits = isFitsFile ( analysisModel ) ;
476
549
const selList = selectInfoCls . getSelected ( ) ;
@@ -482,7 +555,7 @@ export function validateModelSelection(uploadTabs) {
482
555
} ) ;
483
556
}
484
557
485
- const resultModel = Object . assign ( { } , analysisModel , { selectInfo} ) ;
558
+ const resultModel = Object . assign ( { } , analysisModel , { selectInfo : adjustSelectInfo ( tableModel , selectInfo ) } ) ;
486
559
const limit = 20 ;
487
560
const selectResults = getSelectionResult ( resultModel , limit ) ; // a search limit is set
488
561
0 commit comments