restore legacy cpnp history index

This commit is contained in:
Christian Vidal Wolf
2026-05-20 15:12:36 +02:00
parent 528d859742
commit d40bc9fa9c
2 changed files with 20 additions and 2 deletions
+12
View File
@@ -56,6 +56,7 @@ const FORCED_ZERO_STOCK_SKUS = new Set([
]); ]);
const BC_SYNC_QUEUE_STORAGE_KEY = 'craze_bc_sync_queue'; const BC_SYNC_QUEUE_STORAGE_KEY = 'craze_bc_sync_queue';
const LEGACY_CPNP_INDEX = 77;
type BcSyncStatus = 'queued' | 'previewed' | 'preview_only' | 'syncing' | 'synced' | 'failed'; 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. // 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. // This includes historical CPNP edits that were persisted directly in products.
if (synced?.status === 'pending' || synced?.status === 'edited') { if (synced?.status === 'pending' || synced?.status === 'edited') {
+8 -2
View File
@@ -3,6 +3,7 @@ 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';
const LEGACY_CPNP_INDEX = 77;
export async function safeFetch(url: string, options: RequestInit = {}): Promise<Response> { export async function safeFetch(url: string, options: RequestInit = {}): Promise<Response> {
const session = getStoredSession(); const session = getStoredSession();
@@ -330,10 +331,15 @@ export async function getHistoryDataForMerge(): Promise<Record<string, ExcelRow>
// does not surface it as a changed index. // does not surface it as a changed index.
const latestCpnp = const latestCpnp =
entry.new_data?.[COLUMNS.CPNP_NO] ?? entry.new_data?.[COLUMNS.CPNP_NO] ??
entry.new_data?.[LEGACY_CPNP_INDEX] ??
entry.old_data?.[COLUMNS.CPNP_NO]; 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 !== '') { if (fallbackCpnp !== undefined && fallbackCpnp !== null && fallbackCpnp !== '') {
target[COLUMNS.CPNP_NO] = latestCpnp; target[COLUMNS.CPNP_NO] = fallbackCpnp;
} }
} }