mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 17:35:23 +02:00
Implement smart merge of synced data to preserve external updates
This commit is contained in:
+28
-3
@@ -113,14 +113,39 @@ export default function App() {
|
||||
console.log('Fetching synced data from Supabase...');
|
||||
const syncedData = await getAllSyncedRows(session?.access_token);
|
||||
|
||||
const editableColumns = new Set([
|
||||
COLUMNS.LONG_DE, COLUMNS.LONG_EN,
|
||||
COLUMNS.SHORT_DE, COLUMNS.SHORT_EN,
|
||||
COLUMNS.DETAILS_DE, COLUMNS.DETAILS_EN,
|
||||
COLUMNS.INNER_L, COLUMNS.INNER_W, COLUMNS.INNER_H,
|
||||
COLUMNS.OUTER_L, COLUMNS.OUTER_W, COLUMNS.OUTER_H,
|
||||
COLUMNS.UNITS_OUTER, COLUMNS.MOQ
|
||||
]);
|
||||
|
||||
headers.forEach((h: any, i: number) => {
|
||||
const hl = String(h || '').toLowerCase();
|
||||
if (hl.includes('srp') || hl.includes('uvp') || hl.includes('40') || hl.includes('price')) {
|
||||
editableColumns.add(i);
|
||||
}
|
||||
});
|
||||
|
||||
const articleNoIdx = COLUMNS.ARTICLE_NO;
|
||||
const processedRows = rows.map(row => {
|
||||
const articleNo = String(row[articleNoIdx]);
|
||||
const synced = syncedData[articleNo];
|
||||
const finalRow = synced ? synced.data : row;
|
||||
|
||||
if (synced && synced.status === 'pending') {
|
||||
setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' }));
|
||||
const finalRow = [...row];
|
||||
if (synced) {
|
||||
// Smart Merge: Only overlay fields we logically "own" via this app's editors
|
||||
editableColumns.forEach(idx => {
|
||||
if (synced.data[idx] !== undefined && synced.data[idx] !== null) {
|
||||
finalRow[idx] = synced.data[idx];
|
||||
}
|
||||
});
|
||||
|
||||
if (synced.status === 'pending') {
|
||||
setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' }));
|
||||
}
|
||||
}
|
||||
|
||||
return finalRow.map((val: any, idx: number) => {
|
||||
|
||||
Reference in New Issue
Block a user