feat: implement persistence system with visual highlighting and auto-reset on export

This commit is contained in:
Christian Vidal Wolf
2026-04-08 19:30:41 +02:00
parent 85451a6b31
commit 0d47f5be33
9 changed files with 152 additions and 58 deletions
+31 -6
View File
@@ -10,17 +10,17 @@ export async function saveRowToSupabase(articleNo: string, rowData: ExcelRow) {
headers: {
'apikey': SUPABASE_KEY,
'Authorization': `Bearer ${SUPABASE_KEY}`,
'Content-Type': 'application/json',
'Prefer': 'resolution=merge-duplicates'
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: articleNo,
data: rowData,
status_check: 'pending',
updated_at: new Date().toISOString()
})
});
if (response.status === 204 || response.ok) {
if (!response.ok) {
// If PATCH didn't find the record, try UPSERT
const upsertResponse = await fetch(`${SUPABASE_URL}/rest/v1/products_sync`, {
method: 'POST',
@@ -33,6 +33,7 @@ export async function saveRowToSupabase(articleNo: string, rowData: ExcelRow) {
body: JSON.stringify({
id: articleNo,
data: rowData,
status_check: 'pending',
updated_at: new Date().toISOString()
})
});
@@ -45,7 +46,7 @@ export async function saveRowToSupabase(articleNo: string, rowData: ExcelRow) {
}
}
export async function getAllSyncedRows(): Promise<Record<string, ExcelRow>> {
export async function getAllSyncedRows(): Promise<Record<string, { data: ExcelRow, status: string }>> {
try {
const response = await fetch(`${SUPABASE_URL}/rest/v1/products_sync`, {
headers: {
@@ -57,9 +58,12 @@ export async function getAllSyncedRows(): Promise<Record<string, ExcelRow>> {
if (!response.ok) return {};
const data = await response.json();
const result: Record<string, ExcelRow> = {};
const result: Record<string, { data: ExcelRow, status: string }> = {};
data.forEach((item: any) => {
result[item.id] = item.data;
result[item.id] = {
data: item.data,
status: item.status_check || 'original'
};
});
return result;
} catch (error) {
@@ -67,3 +71,24 @@ export async function getAllSyncedRows(): Promise<Record<string, ExcelRow>> {
return {};
}
}
export async function resetAllPendingRows() {
try {
const response = await fetch(`${SUPABASE_URL}/rest/v1/products_sync?status_check=eq.pending`, {
method: 'PATCH',
headers: {
'apikey': SUPABASE_KEY,
'Authorization': `Bearer ${SUPABASE_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
status_check: 'original',
updated_at: new Date().toISOString()
})
});
return response.ok;
} catch (error) {
console.error('Error resetting statuses in Supabase:', error);
return false;
}
}