fix: preserve edited changes after export and on Dropbox reload

resetAllPendingRows was setting status to 'synced' instead of 'edited',
causing the merge logic on reload to skip those rows. Also keep 'edited'
and 'saved' statuses locally after export instead of clearing all.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Christian Vidal Wolf
2026-04-23 16:22:35 +02:00
co-authored by Claude Sonnet 4.6
parent 7de903a184
commit f3ed3cf147
2 changed files with 11 additions and 4 deletions
+9 -2
View File
@@ -325,12 +325,19 @@ const articleNoIdx = resolvedCols.ARTICLE_NO;
const dateStr = new Date().toISOString().split('T')[0]; const dateStr = new Date().toISOString().split('T')[0];
XLSX.writeFile(wb, `CRAZE_Products_Updated_${dateStr}.xlsx`); XLSX.writeFile(wb, `CRAZE_Products_Updated_${dateStr}.xlsx`);
// 3. Post-export: Reset pending statuses in Supabase // 3. Post-export: Reset pending statuses in Supabase (pending → edited to preserve on reload)
console.log('Resetting pending statuses in Supabase...'); console.log('Resetting pending statuses in Supabase...');
resetAllPendingRows().then(success => { resetAllPendingRows().then(success => {
if (success) { if (success) {
console.log('Successfully reset all pending statuses'); console.log('Successfully reset all pending statuses');
setRowStatuses({}); // Clear local statuses // Only clear 'pending' statuses locally; keep 'edited'/'saved' so they remain visible
setRowStatuses((prev: Record<string, string>) => {
const next: Record<string, string> = {};
for (const [id, status] of Object.entries(prev)) {
if (status !== 'pending') next[id] = status as string;
}
return next;
});
} }
}); });
+2 -2
View File
@@ -37,7 +37,7 @@ export interface ExcelRow extends Array<any> {}
export interface SyncedRow { export interface SyncedRow {
data: ExcelRow; data: ExcelRow;
status?: 'pending' | 'synced'; status?: 'pending' | 'edited' | 'synced' | 'excel';
} }
export async function getAllSyncedRows(): Promise<Record<string, SyncedRow>> { export async function getAllSyncedRows(): Promise<Record<string, SyncedRow>> {
@@ -208,7 +208,7 @@ export async function resetAllPendingRows(): Promise<boolean> {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Prefer': 'return=minimal', 'Prefer': 'return=minimal',
}, },
body: JSON.stringify({ status: 'synced' }) body: JSON.stringify({ status: 'edited' })
} }
); );