mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 17:25:24 +02:00
Implement smart merge of synced data to preserve external updates
This commit is contained in:
+27
-2
@@ -113,15 +113,40 @@ export default function App() {
|
|||||||
console.log('Fetching synced data from Supabase...');
|
console.log('Fetching synced data from Supabase...');
|
||||||
const syncedData = await getAllSyncedRows(session?.access_token);
|
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 articleNoIdx = COLUMNS.ARTICLE_NO;
|
||||||
const processedRows = rows.map(row => {
|
const processedRows = rows.map(row => {
|
||||||
const articleNo = String(row[articleNoIdx]);
|
const articleNo = String(row[articleNoIdx]);
|
||||||
const synced = syncedData[articleNo];
|
const synced = syncedData[articleNo];
|
||||||
const finalRow = synced ? synced.data : row;
|
|
||||||
|
|
||||||
if (synced && synced.status === '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' }));
|
setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' }));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user