@@ -82,10 +82,13 @@ const importerMappedColumnDetails = (data) => {
8282//--------------------------------------------------------------------
8383// As long as column->field mappings have been set up, this function will return
8484// an array indexed on column, with each element being list of possible formats
85- // for that column. The array element for a column will be false if the column is mapped to a
86- // field whose type does not require formats, otherwise it will be a list of
87- // objects with 'name' (internal code), 'displayName' (human-facing name) and
88- // 'description' (longer description) fields.
85+ // for that column. The array element for a column will be false if the column
86+ // is mapped to a field whose type does not require formats, otherwise it will
87+ // be TWO lists of objects with 'name' (internal code), 'displayName'
88+ // (human-facing name) and 'description' (longer description) fields. The first
89+ // is "safe" formats that will work for all the values in the column, the second
90+ // are "maybe" formats that will work for some of them. Those that work for none
91+ // of them are not present at all.
8992// --------------------------------------------------------------------
9093const importerPossibleColumnFormats = ( data ) => {
9194 // FIXME: This should probably move into the backend, as a SessionSuggestFormats function
@@ -105,11 +108,20 @@ const importerPossibleColumnFormats = (data) => {
105108 const columnDef = session . fields . find ( ( field ) => field . name == columnField ) ;
106109 const columnTypeName = columnDef . type ;
107110 const columnType = supportedTypes . get ( columnTypeName ) ;
108- let likelyFormats = new Set ( ) ; // Names of formats this column is likely to have, according to the guesser
109- if ( columnGuesses . types && columnGuesses . types . has ( columnTypeName ) ) {
110- const guessedFormats = columnGuesses . types . get ( columnTypeName ) ;
111+
112+ let safeFormats = new Set ( ) ; // Names of formats this column is likely to have, according to the guesser
113+ if ( columnGuesses . safeTypes && columnGuesses . safeTypes . has ( columnTypeName ) ) {
114+ const guessedFormats = columnGuesses . safeTypes . get ( columnTypeName ) ;
115+ if ( guessedFormats && columnType . formats ) {
116+ safeFormats = new Set ( Array . from ( columnType . formats . keys ( ) ) . filter ( ( fmtName ) => guessedFormats . includes ( fmtName ) ) ) ;
117+ }
118+ }
119+
120+ let maybeFormats = new Set ( ) ; // Names of formats this column merely might have, according to the guesser
121+ if ( columnGuesses . maybeTypes && columnGuesses . maybeTypes . has ( columnTypeName ) ) {
122+ const guessedFormats = columnGuesses . maybeTypes . get ( columnTypeName ) ;
111123 if ( guessedFormats && columnType . formats ) {
112- likelyFormats = new Set ( Array . from ( columnType . formats . keys ( ) ) . filter ( ( fmtName ) => guessedFormats . includes ( fmtName ) ) ) ;
124+ maybeFormats = new Set ( Array . from ( columnType . formats . keys ( ) ) . filter ( ( fmtName ) => guessedFormats . includes ( fmtName ) ) ) ;
113125 }
114126 }
115127
@@ -119,10 +131,13 @@ const importerPossibleColumnFormats = (data) => {
119131 name : fmtEntry [ 0 ] ,
120132 displayName : fmtEntry [ 1 ] . displayName ,
121133 description : fmtEntry [ 1 ] . description ,
122- likely : likelyFormats . has ( fmtEntry [ 0 ] )
134+ safe : safeFormats . has ( fmtEntry [ 0 ] ) ,
135+ maybe : maybeFormats . has ( fmtEntry [ 0 ] )
123136 } ;
124137 } ) ;
125- return options ;
138+ const formats = [ options . filter ( ( fmtEntry ) => fmtEntry . safe ) ,
139+ options . filter ( ( fmtEntry ) => fmtEntry . maybe ) ] ;
140+ return formats ;
126141 } else {
127142 return false ;
128143 }
@@ -158,19 +173,19 @@ const importerGetTrailingRows = (data, count) => {
158173// "All {n} rows of {sheet}"
159174//--------------------------------------------------------------------
160175const importerGetTableCaption =
161- ( data , prefix , rowsAskedFor , sheetName = null ) => {
162- const session_data = data [ IMPORTER_SESSION_KEY ] ;
163- const session = new session_lib . Session ( session_data )
176+ ( data , prefix , rowsAskedFor , sheetName = null ) => {
177+ const session_data = data [ IMPORTER_SESSION_KEY ] ;
178+ const session = new session_lib . Session ( session_data )
164179
165- const sheet = ( sheetName ??= session . sheet ) ;
166- const rowCount = sheets_lib . GetTotalRows ( session . backendSid , sheet ) ;
180+ const sheet = ( sheetName ??= session . sheet ) ;
181+ const rowCount = sheets_lib . GetTotalRows ( session . backendSid , sheet ) ;
167182
168- if ( rowCount > rowsAskedFor ) {
169- return `${ prefix } ${ rowsAskedFor } rows of '${ sheet } '` ;
170- }
183+ if ( rowCount > rowsAskedFor ) {
184+ return `${ prefix } ${ rowsAskedFor } rows of '${ sheet } '` ;
185+ }
171186
172- return `All rows of '${ sheet } '` ;
173- }
187+ return `All rows of '${ sheet } '` ;
188+ }
174189
175190//--------------------------------------------------------------------
176191// In the absence of a step to choose headers, we will instead provide
@@ -208,8 +223,8 @@ const importerGetHeaders = (data) => {
208223 session . backendSid ,
209224 session . sheet ,
210225 index ,
211- /* cellWidth */ 20 ,
212- /* count */ 5 ,
226+ /* cellWidth */ 20 ,
227+ /* count */ 5 ,
213228 ) . inputValues ;
214229
215230 let exampleString = examples . join ( ", " ) . trim ( ) ;
@@ -306,8 +321,8 @@ const data_avg = (data, column) => {
306321 }
307322
308323 const numbers = mapResults . resultRecords
309- . filter ( ( x ) => x !== undefined && x [ idx ] !== undefined )
310- . map ( ( x ) => parseNumberFromString ( x [ idx ] ) )
324+ . filter ( ( x ) => x !== undefined && x [ idx ] !== undefined )
325+ . map ( ( x ) => parseNumberFromString ( x [ idx ] ) )
311326
312327
313328 const avg = numbers . reduce ( ( acc , i ) => acc + i , 0 ) / numbers . length
@@ -354,7 +369,7 @@ module.exports = {
354369}
355370
356371/*
357- Local Variables:
358- js-indent-level: 4
359- End:
372+ Local Variables:
373+ js-indent-level: 4
374+ End:
360375*/
0 commit comments