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:
Christian Vidal Wolf
2026-04-23 15:55:13 +02:00
parent ce343a1b1f
commit dbaf0e76fe
+15 -3
View File
@@ -168,10 +168,22 @@ export default function App() {
// 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')) {
// 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 => {
if (synced.data[idx] !== undefined && synced.data[idx] !== null) {
finalRow[idx] = synced.data[idx];
let mergeIdx = idx;
if (needsShift && idx >= 12) {
mergeIdx = idx - 1;
}
if (oldData[mergeIdx] !== undefined && oldData[mergeIdx] !== null) {
finalRow[idx] = oldData[mergeIdx];
}
});
setRowStatuses(prev => ({ ...prev, [articleNo]: 'synced' }));