fix: prevent CPNP_NO from being overridden by dynamic column detection

CPNP_NO must stay hardcoded at index 107. Removed it from COLUMN_PATTERNS
and added guard to skip empty patterns in resolveColumnIndices.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
Christian Vidal Wolf
2026-05-12 12:19:09 +02:00
co-authored by claude-flow
parent 889e98b0ca
commit 1b4918a385
2 changed files with 7 additions and 8 deletions
+4 -6
View File
@@ -45,7 +45,7 @@ export function CosmeticItemsView({ data, headers, onSaveRow, onCaptureState, ro
if (!COSMETIC_LINES.some(l => lineVal === l)) return;
columns.forEach(({ col }) => {
result[col].add(String(row[col] ?? '').trim());
result[col].add(String(row[col] ?? '').replace(/\s+/g, ' ').trim());
});
});
@@ -82,11 +82,9 @@ export function CosmeticItemsView({ data, headers, onSaveRow, onCaptureState, ro
(Object.entries(columnFilters) as [string, string[]][]).forEach(([colIdx, filterValues]) => {
if (!filterValues || filterValues.length === 0) return;
const colNum = parseInt(colIdx);
const filterSet = new Set(filterValues.map(f => f.trim()));
result = result.filter(({ row }) => {
const val = String(row[colNum] ?? '').trim();
return filterSet.has(val);
});
const normalize = (v: any) => String(v ?? '').replace(/\s+/g, ' ').trim();
const filterSet = new Set(filterValues.map(normalize));
result = result.filter(({ row }) => filterSet.has(normalize(row[colNum])));
});
// Sort
+2 -1
View File
@@ -82,7 +82,7 @@ export const COLUMN_PATTERNS: Record<keyof typeof COLUMNS, string[]> = {
ITEM_TO_LOGISTIC: ['item', 'logistic'],
ANNA_CHECK: ['anna', 'check'],
ANNA_NOTE: ['anna', 'note'],
CPNP_NO: ['cpnp'],
CPNP_NO: [],
// Virtual/Extra columns stay hardcoded and are NOT auto-detected from headers
// to prevent internal data from being shifted or overwritten by Excel column shifts.
};
@@ -92,6 +92,7 @@ export function resolveColumnIndices(headers: string[]): typeof COLUMNS {
const h = headers.map(val => String(val || '').toLowerCase());
Object.entries(COLUMN_PATTERNS).forEach(([key, patterns]) => {
if (patterns.length === 0) return;
const idx = h.findIndex(headerText =>
patterns.every(p => headerText.includes(p.toLowerCase()))
);