Skip to content

Commit 7c237e0

Browse files
committed
Revert "perf: [10196] imporve perfromance of CSV parsing table"
This reverts commit 7bc60b8.
1 parent 8f3435c commit 7c237e0

File tree

1 file changed

+25
-53
lines changed

1 file changed

+25
-53
lines changed

src/FileUtils/AgGridUtils.js

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/yyyy/, '\\d{4}')
94-
.replace(/MM/, '(0[1-9]|1[0-2])')
95-
.replace(/dd/, '(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-
10388
const _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

Comments
 (0)