improve cpnp history restore

This commit is contained in:
Christian Vidal Wolf
2026-05-20 15:00:26 +02:00
parent cb913b9d72
commit 39a3588078
+12
View File
@@ -1,4 +1,5 @@
import { refreshSession, getStoredSession } from './auth'; import { refreshSession, getStoredSession } from './auth';
import { COLUMNS } from '../types';
const SUPABASE_URL = 'https://hwithddwaapyhnfwcesj.supabase.co'; const SUPABASE_URL = 'https://hwithddwaapyhnfwcesj.supabase.co';
const SUPABASE_ANON_KEY = 'sb_publishable_fGXkh0bSrAOqSk2jWKAzSg_NJD9YPCv'; const SUPABASE_ANON_KEY = 'sb_publishable_fGXkh0bSrAOqSk2jWKAzSg_NJD9YPCv';
@@ -323,6 +324,17 @@ export async function getHistoryDataForMerge(): Promise<Record<string, ExcelRow>
for (const idx of changedIndices) { for (const idx of changedIndices) {
target[idx] = entry.new_data?.[idx]; target[idx] = entry.new_data?.[idx];
} }
// CPNP values were saved through multiple code paths over time.
// Preserve the latest non-empty value even when a given history row
// does not surface it as a changed index.
const latestCpnp =
entry.new_data?.[COLUMNS.CPNP_NO] ??
entry.old_data?.[COLUMNS.CPNP_NO];
if (latestCpnp !== undefined && latestCpnp !== null && latestCpnp !== '') {
target[COLUMNS.CPNP_NO] = latestCpnp;
}
} }
return result; return result;