From e0508d50d691251814398f8042d10ca0933d8298 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 23 Apr 2026 18:36:35 +0200 Subject: [PATCH] fix: restore internal control columns and protect them from Dropbox sync overrides --- api/dropbox-sync.js | 4 ++-- src/App.tsx | 11 +++++++---- src/types.ts | 10 ++-------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/api/dropbox-sync.js b/api/dropbox-sync.js index 00ffd63..d577f40 100644 --- a/api/dropbox-sync.js +++ b/api/dropbox-sync.js @@ -45,10 +45,10 @@ export default async function handler(req, res) { .from('products') .select('product_id, status'); - // Protect products with status 'edited' or 'pending' + // Protect ALL products that are not 'excel' status (i.e. they have manual edits or special status) const manuallyEditedIds = new Set( (existingProducts || []) - .filter(p => p.status === 'edited' || p.status === 'pending') + .filter(p => p.status && p.status !== 'excel') .map(p => p.product_id) ); diff --git a/src/App.tsx b/src/App.tsx index d917598..da1dbcd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -191,9 +191,10 @@ const articleNoIdx = resolvedCols.ARTICLE_NO; let finalRow = [...row]; // Merge logic: Prioritize internal control columns and active session edits - if (synced && (synced.status === 'edited' || synced.status === 'pending' || synced.status === 'synced')) { + if (synced && synced.data) { // 1. ALWAYS restore Internal Control Columns (indices >= 100) - // These are the "TYPE", "Item to Logistic", "Checking", etc. + // These are the "TYPE", "Item to Logistic", "Checking", etc. + // We use hardcoded indices from COLUMNS to ensure they stay at the end. Object.values(COLUMNS).forEach(idx => { if (idx >= 100 && synced.data[idx] !== undefined && synced.data[idx] !== null) { finalRow[idx] = synced.data[idx]; @@ -210,8 +211,10 @@ const articleNoIdx = resolvedCols.ARTICLE_NO; }); } - // Update row status in UI - setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status })); + // Update row status in UI if it's not the default 'excel' + if (synced.status && synced.status !== 'excel') { + setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status! })); + } } return finalRow.map((val: any, idx: number) => { diff --git a/src/types.ts b/src/types.ts index 863bd66..2feebc2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -74,14 +74,8 @@ export const COLUMN_PATTERNS: Record = { OUTER_W: ['outer', 'w'], OUTER_L: ['outer', 'l'], OUTER_H: ['outer', 'h'], - // Virtual/Extra columns stay hardcoded or managed elsewhere - VERIFIED_DIMS: ['verified'], - VALIDATED_CHECK: ['validated'], - VALIDATED_NOTE: ['note'], - PRODUCT_TYPE: ['type'], - ITEM_TO_LOGISTIC: ['item', 'to', 'logistic'], - ANNA_CHECK: ['anna', 'check'], - ANNA_NOTE: ['anna', 'note'] + // Virtual/Extra columns stay hardcoded and are NOT auto-detected from headers + // to prevent internal data from being shifted or overwritten by Excel column shifts. }; export function resolveColumnIndices(headers: string[]): typeof COLUMNS {