@@ -85,69 +85,41 @@ const _getColTypeFromTypeArray = (typeArray) => {
8585 return 'string' ; // Fall back to default type
8686} ;
8787
88- const validateDateFormat = ( value , options = { } ) => {
89- if ( typeof value !== 'string' ) return false ;
90- const { dateFormat = 'yyyy-MM-dd' } = options ;
91-
92- const formatRegex = dateFormat
93- . replace ( / y y y y / , '\\d{4}' )
94- . replace ( / M M / , '(0[1-9]|1[0-2])' )
95- . replace ( / d d / , '(0[1-9]|[12]\\d|3[01])' )
96- . replace ( / \/ / g, '\\/' )
97- . replace ( / - / g, '-' ) ;
98-
99- const regex = new RegExp ( `^${ formatRegex } $` ) ;
100- return regex . test ( value ) ;
101- } ;
102-
10388const _validateFormat = ( rows , hasHeader , cols , options ) => {
10489 const colsData = cols . map ( ( col ) => ( { ...col , type : _getColTypeFromTypeArray ( col . type ) } ) ) ;
10590 const errors = [ ] ;
10691 const knownColsCount = colsData . length ;
10792 const startIndex = hasHeader ? 1 : 0 ;
108-
109- const colMeta = cols . map ( ( col ) => ( {
110- field : col . field ,
111- type : _getColTypeFromTypeArray ( col . type ) ,
112- acceptsEmptyFields : col . acceptsEmptyFields ?? col . cellEditorParams ?. acceptsEmptyFields ?? false ,
113- colOptions : {
114- ...options ,
115- enumValues : col . enumValues ?? col . cellEditorParams ?. enumValues ,
116- minValue : col . minValue ,
117- maxValue : col . maxValue ,
118- } ,
119- } ) ) ;
120-
12193 for ( let rowIndex = startIndex ; rowIndex < rows . length ; rowIndex ++ ) {
12294 const row = rows [ rowIndex ] ;
12395 while ( row [ row . length - 1 ] === undefined && row . length > knownColsCount ) row . pop ( ) ;
124- if ( row . length !== knownColsCount || row . includes ( undefined ) ) {
125- _forgeColumnsCountError ( row , rowIndex + 1 , cols , errors ) ;
126- continue ;
127- }
128-
129- for ( let colIndex = 0 ; colIndex < knownColsCount ; colIndex ++ ) {
130- const { type, colOptions, acceptsEmptyFields, field } = colMeta [ colIndex ] ;
131- const value = row [ colIndex ] ;
132- if ( value === undefined ) continue ;
133-
134- if ( type === 'date' && ! validateDateFormat ( value , colOptions ) ) {
135- const expectedFormat = colOptions . dateFormat || 'dd/MM/yyyy' ;
136- const errorSummary = 'Incorrect date value' ;
137- const errorContext = `Incorrect value: "${ value } " for type date\nExpected format: ${ expectedFormat } ` ;
138- const errorLoc = `Line ${ rowIndex + 1 } , Column ${ colIndex + 1 } ("${ field } ")` ;
139- errors . push ( new PanelError ( errorSummary , errorLoc , errorContext ) ) ;
140- continue ;
141- }
142-
143- const validationResult = ValidationUtils . isValid ( value , type , colOptions , acceptsEmptyFields ) ;
144- if ( validationResult !== true ) {
145- const { summary : errorSummary , context : errorContext } = validationResult ;
146- const errorLoc = `Line ${ rowIndex + 1 } , Column ${ colIndex + 1 } ("${ field } ")` ;
147- errors . push ( new PanelError ( errorSummary , errorLoc , errorContext ) ) ;
96+ if ( row . length !== knownColsCount || row . includes ( undefined ) )
97+ _forgeColumnsCountError ( row , rowIndex + 1 , colsData , errors ) ;
98+ row . forEach ( ( rowCell , colIndex ) => {
99+ if ( colIndex < knownColsCount ) {
100+ const colType = colsData [ colIndex ] . type ;
101+ if ( colType && rowCell !== undefined ) {
102+ // use of cellEditorParams is deprecated
103+ const colOptions = {
104+ ...options ,
105+ enumValues : colsData [ colIndex ] ?. enumValues ?? colsData [ colIndex ] ?. cellEditorParams ?. enumValues ,
106+ minValue : colsData [ colIndex ] ?. minValue ,
107+ maxValue : colsData [ colIndex ] ?. maxValue ,
108+ } ;
109+ const acceptsEmptyFields =
110+ // use of cellEditorParams is deprecated
111+ colsData [ colIndex ] . acceptsEmptyFields ?? colsData [ colIndex ] . cellEditorParams ?. acceptsEmptyFields ?? false ;
112+ const validationResult = ValidationUtils . isValid ( rowCell , colType , colOptions , acceptsEmptyFields ) ;
113+ if ( validationResult !== true ) {
114+ const { summary : errorSummary , context : errorContext } = validationResult ;
115+ const errorLoc = `Line ${ rowIndex + 1 } , Column ${ colIndex + 1 } ("${ colsData [ colIndex ] . field } ")` ;
116+ errors . push ( new PanelError ( errorSummary , errorLoc , errorContext ) ) ;
117+ }
118+ }
148119 }
149- }
120+ } ) ;
150121 }
122+
151123 return errors ;
152124} ;
153125
0 commit comments