From c2b229e8990cbcac631a814c2bdfade653bb6413 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 23 Apr 2026 16:07:16 +0200 Subject: [PATCH] fix: only preserve Supabase if value is different from Dropbox --- src/App.tsx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 40ecb27..d6d86f8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -163,17 +163,14 @@ export default function App() { const articleNo = String(row[articleNoIdx]); const synced = syncedData[articleNo]; - // Start with Dropbox values (default) + // Start with Dropbox values (default) - fresh from Excel let finalRow = [...row]; - // Preserve Supabase values (edits made in the app) - this shows in Change History + // Only preserve Supabase value if it's DIFFERENT from Dropbox (meaning someone edited it intentionally) + // This keeps the TYPE = "Surprise Bath bomb" edits while avoiding stale SRP/UVP values if (synced) { - // 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 => { @@ -182,8 +179,19 @@ export default function App() { mergeIdx = idx - 1; } - if (oldData[mergeIdx] !== undefined && oldData[mergeIdx] !== null) { - finalRow[idx] = oldData[mergeIdx]; + const dbxValue = row[idx]; + const supabaseValue = oldData[mergeIdx]; + + // Only use Supabase value if it's different from Dropbox (edited intentionally) + if (supabaseValue !== undefined && supabaseValue !== null) { + // Compare as strings to handle numeric formatting differences + const dbxStr = String(dbxValue ?? ''); + const supabaseStr = String(supabaseValue); + + // Keep Supabase value only if it was actually edited (different from Excel) + if (dbxStr !== supabaseStr) { + finalRow[idx] = supabaseValue; + } } }); setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status || 'synced' }));