diff --git a/src/components/sync/DiffTable.tsx b/src/components/sync/DiffTable.tsx index c6d57ce..1d61d1f 100644 --- a/src/components/sync/DiffTable.tsx +++ b/src/components/sync/DiffTable.tsx @@ -56,28 +56,33 @@ export function DiffTable({ diff }: DiffTableProps) { {paginated.length === 0 ? (
Aucun changement dans cette catégorie.
) : ( -| Ref | Type | -Champs modifiés | +Détail | |
|---|---|---|---|---|
| {change.ref} | -+ | {change.ref} | +{TYPE_CONFIG[change.type].label} | {change.type === 'update' && change.changedFields?.map((f) => ( - + {f.field} : - {f.from} - → + {f.from} + → {f.to} ))} diff --git a/src/lib/googleSheets.ts b/src/lib/googleSheets.ts index 57879e1..25bc8fa 100644 --- a/src/lib/googleSheets.ts +++ b/src/lib/googleSheets.ts @@ -12,21 +12,33 @@ function normalizeHandle(ref: string): string { * Colonnes : A=Référence, B=Nom, C=Description, D=Prix, E=Stock, F=Statut * Exporté pour les tests unitaires. */ +const HEADER_WORDS = new Set(['id', 'ref', 'sku', 'nom', 'titre', 'reference', 'prix', 'statut']) + +function isValidRef(ref: string): boolean { + if (ref.length < 2) return false + if (/^[^a-zA-Z0-9]+$/.test(ref)) return false // que des caractères spéciaux + if (HEADER_WORDS.has(ref.toLowerCase())) return false + return true +} + export function parseSheetRows(rows: string[][]): SyncProduct[] { return rows .map((row): SyncProduct | null => { const ref = row[0]?.trim() - if (!ref) return null + if (!ref || !isValidRef(ref)) return null const rawPrice = (row[3] ?? '').replace(',', '.').trim() const price = parseFloat(rawPrice || '0') + // Ligne sans prix valide = séparateur ou note, pas un produit + if (isNaN(price) || price <= 0) return null + return { ref, handle: normalizeHandle(ref), title: row[1]?.trim() || ref, description: row[2]?.trim() || '', - price: isNaN(price) ? '0.00' : price.toFixed(2), + price: price.toFixed(2), stock: parseInt(row[4] ?? '0', 10) || 0, status: (row[5] ?? '').toLowerCase().includes('inac') ? 'draft' : 'active', } |