Skip to content

Commit d6116fb

Browse files
ngAlexander9shilorigins
authored andcommitted
refactor: simplify CSV tag validation by removing async progress tracking
Removed the async progress callback and chunked processing from `validateCSVTags` function. The validation now runs synchronously without progress updates, simplifying the implementation while maintaining the same validation logic and results. Updated function signature and removed progress-related code from both the validation function and its caller in CSVImportDialog.
1 parent e1d04d9 commit d6116fb

2 files changed

Lines changed: 17 additions & 47 deletions

File tree

src/components/CSVImportDialog.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,7 @@ export function CSVImportDialog({
109109
status: 'validating',
110110
});
111111

112-
const validationResults = await validateCSVTags(
113-
result.data,
114-
availableTagGroups,
115-
(processedRows, totalRows) => {
116-
setParsingProgress({
117-
processedRows,
118-
totalRows,
119-
status: 'validating',
120-
});
121-
}
122-
);
112+
const validationResults = await validateCSVTags(result.data, availableTagGroups);
123113

124114
const summary = createValidationSummary(
125115
validationResults.rejectedGroups,

src/utils/csvParser.ts

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -282,64 +282,44 @@ export function createValidationSummary(
282282

283283
/**
284284
* Bulk tag validation for CSV import
285-
* Validates all CSV rows against available tag groups and provides progress feedback
285+
* Validates all CSV rows against available tag groups
286286
*
287287
* @param csvData - Array of parsed CSV rows with tag groups
288288
* @param availableTagGroups - Available tag groups from backend
289-
* @param onProgress - Optional callback for progress updates (processedRows, totalRows)
290289
* @returns Validation results with rejected groups and values
291290
*/
292291
export interface BulkTagValidationResult {
293292
rejectedGroups: string[];
294293
rejectedValues: Record<string, string[]>;
295294
}
296295

297-
export async function validateCSVTags(
296+
export function validateCSVTags(
298297
csvData: ParsedCSVRow[],
299298
availableTagGroups: Array<{
300299
id: string;
301300
name: string;
302301
tags: Array<{ id: string; name: string }>;
303-
}>,
304-
onProgress?: (processedRows: number, totalRows: number) => void
305-
): Promise<BulkTagValidationResult> {
302+
}>
303+
): BulkTagValidationResult {
306304
// Collect all rejected groups and values across all rows
307305
const allRejectedGroups = new Set<string>();
308306
const allRejectedValues: Record<string, Set<string>> = {};
309307

310-
// Process validation in chunks to prevent blocking the main thread
311-
const chunkSize = 50;
312-
const totalRows = csvData.length;
308+
// Process each row
309+
csvData.forEach((row) => {
310+
const mapping = createTagMapping(row.groups, availableTagGroups);
313311

314-
for (let start = 0; start < csvData.length; start += chunkSize) {
315-
const chunk = csvData.slice(start, start + chunkSize);
312+
// Collect rejected groups (groups that don't exist in backend)
313+
mapping.rejectedGroups.forEach((group) => allRejectedGroups.add(group));
316314

317-
// Process each row in the current chunk
318-
chunk.forEach((row) => {
319-
const mapping = createTagMapping(row.groups, availableTagGroups);
320-
321-
// Collect rejected groups (groups that don't exist in backend)
322-
mapping.rejectedGroups.forEach((group) => allRejectedGroups.add(group));
323-
324-
// Collect rejected values (values that don't exist for their group in backend)
325-
Object.entries(mapping.rejectedValues).forEach(([group, values]) => {
326-
if (!allRejectedValues[group]) {
327-
allRejectedValues[group] = new Set();
328-
}
329-
values.forEach((value) => allRejectedValues[group].add(value));
330-
});
315+
// Collect rejected values (values that don't exist for their group in backend)
316+
Object.entries(mapping.rejectedValues).forEach(([group, values]) => {
317+
if (!allRejectedValues[group]) {
318+
allRejectedValues[group] = new Set();
319+
}
320+
values.forEach((value) => allRejectedValues[group].add(value));
331321
});
332-
333-
// Update progress indicator for real-time UI feedback
334-
const processedRows = Math.min(start + chunk.length, totalRows);
335-
if (onProgress) {
336-
onProgress(processedRows, totalRows);
337-
}
338-
339-
// Yield control to allow UI updates and prevent blocking
340-
// eslint-disable-next-line no-await-in-loop, no-promise-executor-return
341-
await new Promise((resolve) => setTimeout(resolve, 0));
342-
}
322+
});
343323

344324
// Convert sets to arrays
345325
const rejectedGroups = Array.from(allRejectedGroups);

0 commit comments

Comments
 (0)