From 23f4b508c8affab29232257711f9f183fe6cd14d Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Fri, 10 Apr 2026 09:47:35 +0200 Subject: [PATCH] Delete history entry after revert --- src/App.tsx | 8 +- src/components/HistoryView.tsx | 28 ++-- src/lib/supabase.ts | 230 ++++++++++++++++----------------- 3 files changed, 135 insertions(+), 131 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 0bbadb7..2f2aca0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,7 @@ import { TopBar } from './components/TopBar'; import { ProductDescriptions } from './components/ProductDescriptions'; import { MatrixView } from './components/MatrixView'; import { EditPanel } from './components/EditPanel'; -import { getAllSyncedRows, saveRowToSupabase, resetAllPendingRows, saveHistoryEntry } from './lib/supabase'; +import { getAllSyncedRows, saveRowToSupabase, resetAllPendingRows, saveHistoryEntry, deleteHistoryEntry } from './lib/supabase'; import { getStoredSession, signOut, type AuthSession } from './lib/auth'; import { LoginPage } from './components/LoginPage'; import { DimensionsView } from './components/DimensionsView'; @@ -474,7 +474,7 @@ export default function App() { { + onRevert={async (articleNo, revertedData, historyId) => { // Find the row in appState.data and update it const rowIndex = appState.data.findIndex(r => String(r[COLUMNS.ARTICLE_NO]) === articleNo); if (rowIndex !== -1) { @@ -494,6 +494,10 @@ export default function App() { articleName: String(revertedData[COLUMNS.ARTICLE_NAME] || articleNo), } })); + // Delete the history entry after revert + if (historyId) { + await deleteHistoryEntry(String(historyId)); + } } }} /> diff --git a/src/components/HistoryView.tsx b/src/components/HistoryView.tsx index 6342582..559f026 100644 --- a/src/components/HistoryView.tsx +++ b/src/components/HistoryView.tsx @@ -1,13 +1,13 @@ import React, { useState, useEffect } from 'react'; import { History, RotateCcw, ChevronDown, ChevronRight, User, Calendar, Tag } from 'lucide-react'; -import { getHistory, HistoryEntry } from '../lib/supabase'; +import { getHistory, deleteHistoryEntry, HistoryEntry } from '../lib/supabase'; import { ExcelRow, COLUMNS } from '../types'; import { cn } from '../lib/utils'; interface HistoryViewProps { headers: string[]; data: ExcelRow[]; - onRevert: (articleNo: string, oldData: ExcelRow) => void; + onRevert: (articleNo: string, oldData: ExcelRow, historyId?: number) => void; } export function HistoryView({ headers, data, onRevert }: HistoryViewProps) { @@ -27,6 +27,18 @@ export function HistoryView({ headers, data, onRevert }: HistoryViewProps) { setLoading(false); }; + const handleRevert = (entry: HistoryEntry) => { + if (window.confirm(`Are you sure you want to revert changes for ${entry.article_name}?`)) { + const currentRow = data.find(r => String(r[0]) === entry.product_id); + if (currentRow && JSON.stringify(currentRow) === JSON.stringify(entry.old_data)) { + if (!window.confirm("Reverting will restore original data. No actual changes will be made. Continue?")) { + return; + } + } + onRevert(entry.product_id, entry.old_data, entry.id); + } + }; + const getChangedFields = (oldData: ExcelRow, newData: ExcelRow) => { const changes: { header: string; old: any; new: any; index: number }[] = []; const maxLen = Math.max(oldData.length, newData.length); @@ -157,17 +169,7 @@ export function HistoryView({ headers, data, onRevert }: HistoryViewProps) {