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 <noreply@anthropic.com>
This commit is contained in:
Christian Vidal Wolf
2026-04-23 16:29:46 +02:00
co-authored by Claude Sonnet 4.6
parent 63242d8852
commit ebef518f11
+13 -4
View File
@@ -168,11 +168,20 @@ const articleNoIdx = resolvedCols.ARTICLE_NO;
// Load manual edits: status 'edited' = saved edits, 'pending' = unsaved edits // Load manual edits: status 'edited' = saved edits, 'pending' = unsaved edits
if (synced && (synced.status === 'edited' || synced.status === 'pending')) { if (synced && (synced.status === 'edited' || synced.status === 'pending')) {
editableColumns.forEach(idx => { // Compare saved row vs fresh Excel row: wherever Supabase differs from Excel,
if (synced.data[idx] !== undefined && synced.data[idx] !== null) { // that means the user edited that column — apply it regardless of editableColumns
finalRow[idx] = synced.data[idx]; // 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 })); setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status }));
} }