From 8ffcae5eef96a9291865a6faccb17b7718c0f56b Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 23 Apr 2026 19:28:25 +0200 Subject: [PATCH] fix: prefer history data over synced data for internal columns --- src/App.tsx | 12 +++--------- src/lib/supabase.ts | 15 +-------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 4303dc0..c34410b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -137,7 +137,6 @@ export default function App() { console.log('Fetching history data from Supabase for merge...'); const historyData = await getHistoryDataForMerge(); console.log('Supabase synced rows:', Object.keys(syncedData).length, '| History rows:', Object.keys(historyData).length); - console.log('[DEBUG] historyData["59272EN"] exists:', '59272EN' in historyData, '| value:', historyData['59272EN']?.[103], '| type:', typeof historyData['59272EN']); // Extend headers with virtual columns if the Excel is shorter than the saved data. // COLUMNS hardcoded indices (PRODUCT_TYPE=103, ITEM_TO_LOGISTIC=104, etc.) are used @@ -201,7 +200,9 @@ const articleNoIdx = resolvedCols.ARTICLE_NO; } // Merge logic: Prioritize internal control columns from syncedData or historyData - const sourceForInternal = synced?.data || hist; + // Use synced.data only if it has internal cols (>= 100), otherwise use hist + const syncedHasInternalCols = synced?.data && Object.values(COLUMNS).some(idx => idx >= 100 && synced.data[idx] !== undefined && synced.data[idx] !== null); + const sourceForInternal = syncedHasInternalCols ? synced!.data : (hist || synced?.data); if (sourceForInternal) { // 1. ALWAYS restore Internal Control Columns (indices >= 100) @@ -229,13 +230,6 @@ const articleNoIdx = resolvedCols.ARTICLE_NO; } } - if (articleNo === '59272EN') { - console.log('[DEBUG 59272EN] hist?.length:', hist?.length, '| hist?.[103]:', hist?.[103], '| hist type:', typeof hist); - console.log('[DEBUG 59272EN] synced?.data?.[103]:', synced?.data?.[103]); - console.log('[DEBUG 59272EN] sourceForInternal?.[103]:', sourceForInternal?.[103]); - console.log('[DEBUG 59272EN] FINAL processedRow[103]:', finalRow[103], '| length:', finalRow.length); - } - return finalRow.map((val: any, idx: number) => { if (val === undefined || val === null || val === '') return val; const header = (extendedHeaders[idx] || '').toLowerCase(); diff --git a/src/lib/supabase.ts b/src/lib/supabase.ts index eaa4ada..a16b721 100644 --- a/src/lib/supabase.ts +++ b/src/lib/supabase.ts @@ -14,12 +14,8 @@ async function safeFetch(url: string, options: RequestInit = {}): Promise return {}; } const entries: Array<{ product_id: string; new_data: ExcelRow }> = await response.json(); - console.log('[getHistoryDataForMerge] Raw entries count:', entries.length); - const entry_59272 = entries.find(e => e.product_id === '59272EN'); - console.log('[getHistoryDataForMerge] 59272EN entry found:', !!entry_59272); - if (entry_59272) { - console.log('[getHistoryDataForMerge] 59272EN new_data length:', entry_59272.new_data?.length); - console.log('[getHistoryDataForMerge] 59272EN new_data[103]:', entry_59272.new_data?.[103]); - console.log('[getHistoryDataForMerge] 59272EN new_data type:', typeof entry_59272.new_data); - } const result: Record = {}; const seen = new Set();