mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 14:05:25 +02:00
fix: detect Units/Outer column dynamically instead of hardcoded index
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
81f0e76c3b
commit
8471a69529
@@ -168,7 +168,7 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
|
||||
}, [resizingColumn, resizeStartX, resizeStartWidth]);
|
||||
|
||||
// ── Dynamic column detection ──────────────────────────────────────────────
|
||||
const { uvpIdx, srpCols, containerCols, nwIdx, gwIdx } = useMemo(() => {
|
||||
const { uvpIdx, srpCols, containerCols, nwIdx, gwIdx, unitsOuterIdx } = useMemo(() => {
|
||||
const uvpIdx = findCol(headers, 'uvp');
|
||||
|
||||
// All SRP columns, sorted: INT first, UK second, then alphabetically
|
||||
@@ -193,7 +193,14 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
|
||||
const nwIdx = findCol(headers, 'nw');
|
||||
const gwIdx = findCol(headers, 'gw');
|
||||
|
||||
return { uvpIdx, srpCols: srp, containerCols: container, nwIdx, gwIdx };
|
||||
// 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;
|
||||
|
||||
return { uvpIdx, srpCols: srp, containerCols: container, nwIdx, gwIdx, unitsOuterIdx };
|
||||
}, [headers]);
|
||||
|
||||
// ── Error analysis per row ────────────────────────────────────────────────
|
||||
@@ -219,7 +226,7 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
|
||||
});
|
||||
|
||||
// Units per Outer check
|
||||
const unitsOuter = Number(row[COLUMNS.UNITS_OUTER]);
|
||||
const unitsOuter = Number(row[unitsOuterIdx]);
|
||||
if (!unitsOuter || unitsOuter === 0) {
|
||||
unitErrors.push('Units/Outer: missing');
|
||||
}
|
||||
@@ -270,8 +277,8 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
|
||||
[data]);
|
||||
|
||||
const uniqueUnitsOuter = useMemo(() =>
|
||||
Array.from(new Set(data.map(r => String(r[COLUMNS.UNITS_OUTER] || '')))).filter(v => v).sort(),
|
||||
[data]);
|
||||
Array.from(new Set(data.map(r => String(r[unitsOuterIdx] || '')))).filter(v => v).sort(),
|
||||
[data, unitsOuterIdx]);
|
||||
|
||||
const uniqueOuterW = useMemo(() =>
|
||||
Array.from(new Set(data.map(r => String(r[COLUMNS.OUTER_W] || '')))).filter(v => v).sort((a, b) => Number(a) - Number(b)),
|
||||
@@ -325,7 +332,7 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
|
||||
result = result.filter(r => classificationFilter.includes(String(r.row[COLUMNS.CLASSIFICATION] || '')));
|
||||
}
|
||||
if (unitsOuterFilter.length > 0) {
|
||||
result = result.filter(r => unitsOuterFilter.includes(String(r.row[COLUMNS.UNITS_OUTER] || '')));
|
||||
result = result.filter(r => unitsOuterFilter.includes(String(r.row[unitsOuterIdx] || '')));
|
||||
}
|
||||
if (outerWFilter.length > 0) {
|
||||
result = result.filter(r => outerWFilter.includes(String(r.row[COLUMNS.OUTER_W] || '')));
|
||||
@@ -373,7 +380,7 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
|
||||
case 'line': colIndex = COLUMNS.LINE; break;
|
||||
case 'classification': colIndex = COLUMNS.CLASSIFICATION; break;
|
||||
case 'productType': colIndex = COLUMNS.PRODUCT_TYPE; break;
|
||||
case 'unitsOuter': colIndex = COLUMNS.UNITS_OUTER; break;
|
||||
case 'unitsOuter': colIndex = unitsOuterIdx; break;
|
||||
case 'outerW': colIndex = COLUMNS.OUTER_W; break;
|
||||
case 'outerL': colIndex = COLUMNS.OUTER_L; break;
|
||||
case 'outerH': colIndex = COLUMNS.OUTER_H; break;
|
||||
@@ -552,7 +559,7 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
|
||||
COLUMNS.ARTICLE_NAME,
|
||||
COLUMNS.LINE,
|
||||
COLUMNS.CLASSIFICATION,
|
||||
COLUMNS.UNITS_OUTER,
|
||||
unitsOuterIdx,
|
||||
COLUMNS.OUTER_W,
|
||||
COLUMNS.OUTER_L,
|
||||
COLUMNS.OUTER_H,
|
||||
@@ -1267,7 +1274,7 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
|
||||
})}
|
||||
|
||||
{/* Units columns */}
|
||||
<td className="px-3 py-2.5">{unitOuterBadge(row[COLUMNS.UNITS_OUTER])}</td>
|
||||
<td className="px-3 py-2.5">{unitOuterBadge(row[unitsOuterIdx])}</td>
|
||||
<td className="px-3 py-2.5 text-slate-400 font-mono text-xs overflow-hidden truncate">{row[COLUMNS.OUTER_W] ?? '-'}</td>
|
||||
<td className="px-3 py-2.5 text-slate-400 font-mono text-xs overflow-hidden truncate">{row[COLUMNS.OUTER_L] ?? '-'}</td>
|
||||
<td className="px-3 py-2.5 text-slate-400 font-mono text-xs overflow-hidden truncate">{row[COLUMNS.OUTER_H] ?? '-'}</td>
|
||||
|
||||
Reference in New Issue
Block a user