mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 13:35:25 +02:00
fix: always use fresh Dropbox Excel values on load
This commit is contained in:
+20
-53
@@ -158,65 +158,32 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const articleNoIdx = resolvedCols.ARTICLE_NO;
|
const articleNoIdx = resolvedCols.ARTICLE_NO;
|
||||||
const processedRows = rows.map(row => {
|
const processedRows = rows.map(row => {
|
||||||
const articleNo = String(row[articleNoIdx]);
|
// Simply use Dropbox values - no merge logic
|
||||||
const synced = syncedData[articleNo];
|
// Manual edits are preserved in Supabase and shown in Change History
|
||||||
|
// but fresh Excel data takes precedence on reload
|
||||||
// Start with Dropbox values (default) - fresh from Excel
|
|
||||||
let finalRow = [...row];
|
let finalRow = [...row];
|
||||||
|
|
||||||
// Only preserve Supabase value if it's DIFFERENT from Dropbox (meaning someone edited it intentionally)
|
|
||||||
// This keeps the TYPE = "Surprise Bath bomb" edits while avoiding stale SRP/UVP values
|
|
||||||
if (synced) {
|
|
||||||
const oldData = synced.data;
|
|
||||||
const valAt12 = oldData[12];
|
|
||||||
const needsShift = typeof valAt12 === 'number' || (typeof valAt12 === 'string' && /^[0-9.]+$/.test(valAt12));
|
|
||||||
|
|
||||||
editableColumns.forEach(idx => {
|
|
||||||
let mergeIdx = idx;
|
|
||||||
if (needsShift && idx >= 12) {
|
|
||||||
mergeIdx = idx - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dbxValue = row[idx];
|
|
||||||
const supabaseValue = oldData[mergeIdx];
|
|
||||||
|
|
||||||
// Only use Supabase value if it's different from Dropbox (edited intentionally)
|
|
||||||
if (supabaseValue !== undefined && supabaseValue !== null) {
|
|
||||||
// Compare as strings to handle numeric formatting differences
|
|
||||||
const dbxStr = String(dbxValue ?? '');
|
|
||||||
const supabaseStr = String(supabaseValue);
|
|
||||||
|
|
||||||
// Keep Supabase value only if it was actually edited (different from Excel)
|
|
||||||
if (dbxStr !== supabaseStr) {
|
|
||||||
finalRow[idx] = supabaseValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status || 'synced' }));
|
|
||||||
}
|
|
||||||
// Otherwise use Dropbox values (don't merge, just process formatting)
|
|
||||||
|
|
||||||
return finalRow.map((val: any, idx: number) => {
|
return finalRow.map((val: any, idx: number) => {
|
||||||
if (val === undefined || val === null || val === '') return val;
|
if (val === undefined || val === null || val === '') return val;
|
||||||
const header = (headers[idx] || '').toLowerCase();
|
const header = (headers[idx] || '').toLowerCase();
|
||||||
|
|
||||||
if ((header.includes('id') || header.includes('no') || header.includes('code') ||
|
if ((header.includes('id') || header.includes('no') || header.includes('code') ||
|
||||||
header.includes('art.') || header.includes('barcode') || header.includes('article')) &&
|
header.includes('art.') || header.includes('barcode') || header.includes('article')) &&
|
||||||
!(header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg'))) {
|
!(header.includes('nw') || header.includes('gw') || header.includes('weight') || header.includes('kg'))) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
|
const formatKeywords = ['price', 'eur', 'cost', 'msrp', 'net', 'gross', 'netto', 'brutto', 'pp', 'pph', 'uvp', 'vpe', 'stk', 'nw', 'gw', 'weight', 'kg'];
|
||||||
const shouldFormat = formatKeywords.some(kw => header.includes(kw));
|
const shouldFormat = formatKeywords.some(kw => header.includes(kw));
|
||||||
|
|
||||||
if (typeof val === 'number') {
|
if (typeof val === 'number') {
|
||||||
return Number(val.toFixed(2));
|
return Number(val.toFixed(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof val === 'string') {
|
if (typeof val === 'string') {
|
||||||
const normalized = val.trim().replace(',', '.');
|
const normalized = val.trim().replace(',', '.');
|
||||||
const num = parseFloat(normalized);
|
const num = parseFloat(normalized);
|
||||||
if (!isNaN(num) && (shouldFormat || val.includes('.') || val.includes(','))) {
|
if (!isNaN(num) && (shouldFormat || val.includes('.') || val.includes(','))) {
|
||||||
return num.toFixed(2);
|
return num.toFixed(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user