From dbaf0e76fef30be7320833b5958768dc747a991a Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 23 Apr 2026 15:55:13 +0200 Subject: [PATCH] Fix: Implement dynamic column re-alignment for data merging. - Automatically detects if saved data uses the old Excel structure. - Shifts indices dynamically to ensure UVP and SRP values match current columns. - Fixes the 2.41 UVP and 4.95 SRP Int discrepancy. --- src/App.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index d635a2f..1a17d0f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -168,10 +168,22 @@ export default function App() { // Only preserve Supabase values if there's a PENDING or EDITED edit for this article if (synced && (synced.status === 'pending' || synced.status === 'edited' || synced.status === 'synced')) { - // Keep the manually edited values from Supabase + // DETECT COLUMN SHIFT: If the saved data uses the old structure (where index 12 was a numeric date), + // we need to shift all indices from 12 onwards by +1 to match today's Excel structure. + const oldData = synced.data; + const valAt12 = oldData[12]; + // Launch Date was index 12 yesterday and it's always a numeric serial. + // PM Classification is index 12 today and it's a string or empty. + const needsShift = typeof valAt12 === 'number' || (typeof valAt12 === 'string' && /^[0-9.]+$/.test(valAt12)); + editableColumns.forEach(idx => { - if (synced.data[idx] !== undefined && synced.data[idx] !== null) { - finalRow[idx] = synced.data[idx]; + let mergeIdx = idx; + if (needsShift && idx >= 12) { + mergeIdx = idx - 1; + } + + if (oldData[mergeIdx] !== undefined && oldData[mergeIdx] !== null) { + finalRow[idx] = oldData[mergeIdx]; } }); setRowStatuses(prev => ({ ...prev, [articleNo]: 'synced' }));