From ebef518f119aa5077771ad6e7c96c88a2356e556 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 23 Apr 2026 16:29:46 +0200 Subject: [PATCH] fix: apply Supabase edits by diff vs Excel, not by editable column index Instead of relying on resolvedCols.PRODUCT_TYPE (which can resolve to the wrong index if the column header doesn't match the pattern), compare the saved Supabase row against the fresh Excel row: any index where they differ is a user edit and gets applied. This fixes TYPE / 'Surprise Bath bomb' not appearing after reload. Co-Authored-By: Claude Sonnet 4.6 --- src/App.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 3adb236..112dd16 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -168,11 +168,20 @@ const articleNoIdx = resolvedCols.ARTICLE_NO; // Load manual edits: status 'edited' = saved edits, 'pending' = unsaved edits if (synced && (synced.status === 'edited' || synced.status === 'pending')) { - editableColumns.forEach(idx => { - if (synced.data[idx] !== undefined && synced.data[idx] !== null) { - finalRow[idx] = synced.data[idx]; + // Compare saved row vs fresh Excel row: wherever Supabase differs from Excel, + // that means the user edited that column — apply it regardless of editableColumns + // index resolution, which can vary across sessions. + const savedLen = Array.isArray(synced.data) ? synced.data.length : 0; + for (let idx = 0; idx < savedLen; idx++) { + const savedVal = synced.data[idx]; + const excelVal = row[idx]; + const savedStr = savedVal == null ? '' : String(savedVal); + const excelStr = excelVal == null ? '' : String(excelVal); + if (savedStr !== excelStr) { + // Value differs from Excel → user edited it, apply the saved value + finalRow[idx] = savedVal; } - }); + } setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status })); }