fix: prefer history data over synced data for internal columns

This commit is contained in:
Christian Vidal Wolf
2026-04-23 19:28:25 +02:00
parent a987a5b750
commit 8ffcae5eef
2 changed files with 4 additions and 23 deletions
+3 -9
View File
@@ -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();