@@ -9,6 +9,7 @@ import {ADQL_LINE_LENGTH} from './TapUtil.js';
99
1010const COLS_TO_DISPLAY_FIRST = [ 'column_name' , 'unit' , 'ucd' , 'description' , 'datatype' , 'arraysize' , 'utype' , 'xtype' , 'principal' ] ;
1111
12+ const SELECT_ALL_COLUMNS_WHEN_NO_PRINCIPAL = false ; //todo- determine what to if not of the principal columns are set
1213
1314export function TableColumnsConstraints ( { columnsModel} ) {
1415
@@ -125,8 +126,7 @@ function tableEffect(columnsModel, setTableModel, tbl_id, setFilterCount, setSel
125126 * @returns {boolean }
126127 */
127128function isPrincipalSet ( tableModel ) {
128- // 3 or more principle columns (coordinates and value) might be useful
129- return getColumnValues ( tableModel , 'principal' ) . filter ( ( v ) => v > 0 ) . length >= 3 ;
129+ return getColumnValues ( tableModel , 'principal' ) . filter ( ( v ) => v > 0 ) . length >= 1 ;
130130}
131131
132132/**
@@ -171,18 +171,16 @@ function reorganizeTableModel(tableModel, columnNames, reset) {
171171 e . splice ( constraintsColIdx , 0 , '' ) ;
172172 } ) ;
173173
174- // set selections
175- const selectInfoCls = SelectInfo . newInstance ( { rowCount : data . length } ) ;
176- if ( selectInfoCls . getSelectedCount ( ) === 0 ) {
177- let defaultSelected = [ ] ;
178- // default selected are the principal rows
179- if ( isPrincipalSet ( tableModel ) ) {
180- defaultSelected = getColumnValues ( tableModel , 'principal' ) . reduce ( ( sels , v , i ) => {
174+ // default selected are either all or the principal rows
175+ const usingPrincipal = isPrincipalSet ( tableModel ) ;
176+ const selectInfoCls = SelectInfo . newInstance ( { selectAll :! usingPrincipal , rowCount : data . length } ) ;
177+ if ( usingPrincipal ) {
178+ getColumnValues ( tableModel , 'principal' )
179+ . reduce ( ( sels , v , i ) => {
181180 if ( parseInt ( v ) === 1 ) sels . push ( i ) ;
182181 return sels ;
183- } , [ ] ) ;
184- }
185- defaultSelected . forEach ( ( idx ) => selectInfoCls . setRowSelect ( idx , true ) ) ;
182+ } , [ ] )
183+ . forEach ( ( idx ) => selectInfoCls . setRowSelect ( idx , true ) ) ;
186184 }
187185
188186 columns . forEach ( ( c ) => {
@@ -192,10 +190,9 @@ function reorganizeTableModel(tableModel, columnNames, reset) {
192190 c . prefWidth = 11 ;
193191 }
194192 } ) ;
193+ const selectInfo = ( usingPrincipal || SELECT_ALL_COLUMNS_WHEN_NO_PRINCIPAL ) ? selectInfoCls . data : undefined ;
195194
196- modifiedTableModel = { tbl_id, totalRows : data . length , tableData : { columns, data} ,
197- selectInfo : selectInfoCls . data , request : { tbl_id} } ;
198-
195+ modifiedTableModel = { tbl_id, totalRows : data . length , tableData : { columns, data} , selectInfo, request : { tbl_id} } ;
199196 return modifiedTableModel ;
200197}
201198
0 commit comments