From dbcd6d622f76904dbb5ea04dec48f599b39e0814 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Fri, 10 Apr 2026 12:31:57 +0200 Subject: [PATCH] Implement smart merge of synced data to preserve external updates --- src/App.tsx | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8fe72a5..ca2de95 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -113,14 +113,39 @@ export default function App() { console.log('Fetching synced data from Supabase...'); const syncedData = await getAllSyncedRows(session?.access_token); + const editableColumns = new Set([ + COLUMNS.LONG_DE, COLUMNS.LONG_EN, + COLUMNS.SHORT_DE, COLUMNS.SHORT_EN, + COLUMNS.DETAILS_DE, COLUMNS.DETAILS_EN, + COLUMNS.INNER_L, COLUMNS.INNER_W, COLUMNS.INNER_H, + COLUMNS.OUTER_L, COLUMNS.OUTER_W, COLUMNS.OUTER_H, + COLUMNS.UNITS_OUTER, COLUMNS.MOQ + ]); + + headers.forEach((h: any, i: number) => { + const hl = String(h || '').toLowerCase(); + if (hl.includes('srp') || hl.includes('uvp') || hl.includes('40') || hl.includes('price')) { + editableColumns.add(i); + } + }); + const articleNoIdx = COLUMNS.ARTICLE_NO; const processedRows = rows.map(row => { const articleNo = String(row[articleNoIdx]); const synced = syncedData[articleNo]; - const finalRow = synced ? synced.data : row; - if (synced && synced.status === 'pending') { - setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' })); + const finalRow = [...row]; + if (synced) { + // Smart Merge: Only overlay fields we logically "own" via this app's editors + editableColumns.forEach(idx => { + if (synced.data[idx] !== undefined && synced.data[idx] !== null) { + finalRow[idx] = synced.data[idx]; + } + }); + + if (synced.status === 'pending') { + setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' })); + } } return finalRow.map((val: any, idx: number) => {