fix: per-sheet column detection in Excel importer

CRITICAL FIX for Entity_* placeholder names in multi-sheet Excel imports

Root Cause:
- Column detection ran globally on first row of all combined sheets
- Different sheets have different column structures (Term vs Name, etc.)
- Concepts sheet: [Term, Definition] → detected 'Term' column 
- Characters sheet: [Name, Description] → looked for 'Term' column 
- Result: Characters/Places/Other fell back to Entity_* placeholders

Fix:
- Group rows by sheet (_sheet field)
- Detect columns per-sheet, not globally
- Each sheet now uses its own column mapping
- Characters/Places sheets now correctly find 'Name' column

Impact:
- Concepts: Still work (no change)
- Characters/Places/Other: NOW USE ACTUAL NAMES! 🎉

Also removed debug logging from v4.8.5 (performance overhead)

Fixes: Workshop File Explorer showing Entity_* instead of real names
Ref: BRAINY_V4.8.4_VFS_UNDEFINED_NAMES_BUG.md
This commit is contained in:
David Snelling 2025-10-28 14:30:31 -07:00
parent 14ffd3a477
commit 401443a4b0
4 changed files with 24 additions and 50 deletions

View file

@ -227,8 +227,25 @@ export class SmartExcelImporter {
return this.emptyResult(startTime)
}
// Detect column names
const columns = this.detectColumns(rows[0], opts)
// CRITICAL FIX (v4.8.6): Detect columns per-sheet, not globally
// Different sheets may have different column structures (Term vs Name, etc.)
// Group rows by sheet and detect columns for each sheet separately
const rowsBySheet = new Map<string, typeof rows>()
for (const row of rows) {
const sheet = row._sheet || 'default'
if (!rowsBySheet.has(sheet)) {
rowsBySheet.set(sheet, [])
}
rowsBySheet.get(sheet)!.push(row)
}
// Detect columns for each sheet
const columnsBySheet = new Map<string, ReturnType<typeof this.detectColumns>>()
for (const [sheet, sheetRows] of rowsBySheet) {
if (sheetRows.length > 0) {
columnsBySheet.set(sheet, this.detectColumns(sheetRows[0], opts))
}
}
// Process each row with BATCHED PARALLEL PROCESSING (v3.38.0)
const extractedRows: ExtractedRow[] = []
@ -252,6 +269,10 @@ export class SmartExcelImporter {
chunk.map(async (row, chunkIndex) => {
const i = chunkStart + chunkIndex
// CRITICAL FIX (v4.8.6): Use sheet-specific column mapping
const sheet = row._sheet || 'default'
const columns = columnsBySheet.get(sheet) || this.detectColumns(row, opts)
// Extract data from row
const term = this.getColumnValue(row, columns.term) || `Entity_${i}`
const definition = this.getColumnValue(row, columns.definition) || ''