mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 15:25:24 +02:00
fix: only preserve Supabase if value is different from Dropbox
This commit is contained in:
+16
-8
@@ -163,17 +163,14 @@ export default function App() {
|
|||||||
const articleNo = String(row[articleNoIdx]);
|
const articleNo = String(row[articleNoIdx]);
|
||||||
const synced = syncedData[articleNo];
|
const synced = syncedData[articleNo];
|
||||||
|
|
||||||
// Start with Dropbox values (default)
|
// Start with Dropbox values (default) - fresh from Excel
|
||||||
let finalRow = [...row];
|
let finalRow = [...row];
|
||||||
|
|
||||||
// Preserve Supabase values (edits made in the app) - this shows in Change History
|
// 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) {
|
if (synced) {
|
||||||
// DETECT COLUMN SHIFT: If the saved data uses the old structure (where index 12 was a numeric date),
|
|
||||||
// we need to shift all indices from 12 onwards by +1 to match today's Excel structure.
|
|
||||||
const oldData = synced.data;
|
const oldData = synced.data;
|
||||||
const valAt12 = oldData[12];
|
const valAt12 = oldData[12];
|
||||||
// Launch Date was index 12 yesterday and it's always a numeric serial.
|
|
||||||
// PM Classification is index 12 today and it's a string or empty.
|
|
||||||
const needsShift = typeof valAt12 === 'number' || (typeof valAt12 === 'string' && /^[0-9.]+$/.test(valAt12));
|
const needsShift = typeof valAt12 === 'number' || (typeof valAt12 === 'string' && /^[0-9.]+$/.test(valAt12));
|
||||||
|
|
||||||
editableColumns.forEach(idx => {
|
editableColumns.forEach(idx => {
|
||||||
@@ -182,8 +179,19 @@ export default function App() {
|
|||||||
mergeIdx = idx - 1;
|
mergeIdx = idx - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldData[mergeIdx] !== undefined && oldData[mergeIdx] !== null) {
|
const dbxValue = row[idx];
|
||||||
finalRow[idx] = oldData[mergeIdx];
|
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' }));
|
setRowStatuses(prev => ({ ...prev, [articleNo]: synced.status || 'synced' }));
|
||||||
|
|||||||
Reference in New Issue
Block a user