From d40bc9fa9c0344d5d616df5b0b444554825d8a9d Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Wed, 20 May 2026 15:12:36 +0200 Subject: [PATCH] restore legacy cpnp history index --- src/App.tsx | 12 ++++++++++++ src/lib/supabase.ts | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index e30fb6d..49b7a44 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -56,6 +56,7 @@ const FORCED_ZERO_STOCK_SKUS = new Set([ ]); const BC_SYNC_QUEUE_STORAGE_KEY = 'craze_bc_sync_queue'; +const LEGACY_CPNP_INDEX = 77; type BcSyncStatus = 'queued' | 'previewed' | 'preview_only' | 'syncing' | 'synced' | 'failed'; @@ -413,6 +414,17 @@ export default function App() { } }); + // Older cosmetic edits stored CPNP in index 77 before the dedicated + // internal CPNP column was stabilized at index 107. + const legacyCpnp = + hist?.[COLUMNS.CPNP_NO] ?? + synced?.data?.[COLUMNS.CPNP_NO] ?? + hist?.[LEGACY_CPNP_INDEX] ?? + synced?.data?.[LEGACY_CPNP_INDEX]; + if (legacyCpnp !== undefined && legacyCpnp !== null && String(legacyCpnp).trim() !== '') { + finalRow[COLUMNS.CPNP_NO] = legacyCpnp; + } + // When a row is still in an edited/pending state, restore editable business fields too. // This includes historical CPNP edits that were persisted directly in products. if (synced?.status === 'pending' || synced?.status === 'edited') { diff --git a/src/lib/supabase.ts b/src/lib/supabase.ts index d10ef56..f2653e7 100644 --- a/src/lib/supabase.ts +++ b/src/lib/supabase.ts @@ -3,6 +3,7 @@ import { COLUMNS } from '../types'; const SUPABASE_URL = 'https://hwithddwaapyhnfwcesj.supabase.co'; const SUPABASE_ANON_KEY = 'sb_publishable_fGXkh0bSrAOqSk2jWKAzSg_NJD9YPCv'; +const LEGACY_CPNP_INDEX = 77; export async function safeFetch(url: string, options: RequestInit = {}): Promise { const session = getStoredSession(); @@ -330,10 +331,15 @@ export async function getHistoryDataForMerge(): Promise // does not surface it as a changed index. const latestCpnp = entry.new_data?.[COLUMNS.CPNP_NO] ?? + entry.new_data?.[LEGACY_CPNP_INDEX] ?? entry.old_data?.[COLUMNS.CPNP_NO]; + const fallbackCpnp = + latestCpnp !== undefined && latestCpnp !== null && latestCpnp !== '' + ? latestCpnp + : entry.old_data?.[LEGACY_CPNP_INDEX]; - if (latestCpnp !== undefined && latestCpnp !== null && latestCpnp !== '') { - target[COLUMNS.CPNP_NO] = latestCpnp; + if (fallbackCpnp !== undefined && fallbackCpnp !== null && fallbackCpnp !== '') { + target[COLUMNS.CPNP_NO] = fallbackCpnp; } }