mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 12:35:25 +02:00
Fix: Implement dynamic column re-alignment for data merging.
- Automatically detects if saved data uses the old Excel structure. - Shifts indices dynamically to ensure UVP and SRP values match current columns. - Fixes the 2.41 UVP and 4.95 SRP Int discrepancy.
This commit is contained in:
+15
-3
@@ -168,10 +168,22 @@ export default function App() {
|
|||||||
|
|
||||||
// Only preserve Supabase values if there's a PENDING or EDITED edit for this article
|
// Only preserve Supabase values if there's a PENDING or EDITED edit for this article
|
||||||
if (synced && (synced.status === 'pending' || synced.status === 'edited' || synced.status === 'synced')) {
|
if (synced && (synced.status === 'pending' || synced.status === 'edited' || synced.status === 'synced')) {
|
||||||
// Keep the manually edited values from Supabase
|
// 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 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));
|
||||||
|
|
||||||
editableColumns.forEach(idx => {
|
editableColumns.forEach(idx => {
|
||||||
if (synced.data[idx] !== undefined && synced.data[idx] !== null) {
|
let mergeIdx = idx;
|
||||||
finalRow[idx] = synced.data[idx];
|
if (needsShift && idx >= 12) {
|
||||||
|
mergeIdx = idx - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldData[mergeIdx] !== undefined && oldData[mergeIdx] !== null) {
|
||||||
|
finalRow[idx] = oldData[mergeIdx];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setRowStatuses(prev => ({ ...prev, [articleNo]: 'synced' }));
|
setRowStatuses(prev => ({ ...prev, [articleNo]: 'synced' }));
|
||||||
|
|||||||
Reference in New Issue
Block a user