Fix: Implement dynamic column detection to handle Excel structure changes (insertion of PM Classification). This fixes the Missing data error in Pricing Units and other views.

This commit is contained in:
Christian Vidal Wolf
2026-04-22 16:52:59 +02:00
parent 8471a69529
commit d43d9931c6
15 changed files with 176 additions and 55 deletions
+5 -8
View File
@@ -1,5 +1,6 @@
import React, { useState, useMemo, useRef, useCallback, useEffect } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import {
AlertTriangle,
AlertCircle,
@@ -48,6 +49,7 @@ function findCol(headers: string[], ...keywords: string[]): number {
}
export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit, rowStatuses }: PricingViewProps) {
const COLUMNS = useColumns();
const [filterMode, setFilterMode] = useState<FilterMode>('all_errors');
const [search, setSearch] = useState('');
const [searchMode, setSearchMode] = useState<'all' | 'selected'>('all');
@@ -193,15 +195,10 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
const nwIdx = findCol(headers, 'nw');
const gwIdx = findCol(headers, 'gw');
// Units/Outer column — try dynamic detection first, fall back to hardcoded index
const unitsOuterIdx = findCol(headers, 'units', 'outer') >= 0
? findCol(headers, 'units', 'outer')
: findCol(headers, 'vpe') >= 0
? findCol(headers, 'vpe')
: COLUMNS.UNITS_OUTER;
const unitsOuterIdx = COLUMNS.UNITS_OUTER;
return { uvpIdx, srpCols: srp, containerCols: container, nwIdx, gwIdx, unitsOuterIdx };
}, [headers]);
}, [headers, COLUMNS]);
// ── Error analysis per row ────────────────────────────────────────────────
const analyzedRows = useMemo(() => {