Delete history entry after revert

This commit is contained in:
Christian Vidal Wolf
2026-04-10 09:47:35 +02:00
parent 0cf4f59937
commit 23f4b508c8
3 changed files with 135 additions and 131 deletions
+15 -13
View File
@@ -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) {
<button
onClick={(e) => {
e.stopPropagation();
if (window.confirm(`Are you sure you want to revert changes for ${entry.article_name}?`)) {
// Check if old_data equals current data in appState
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?")) {
onRevert(entry.product_id, entry.old_data);
}
} else {
onRevert(entry.product_id, entry.old_data);
}
}
handleRevert(entry);
}}
className="flex items-center gap-1.5 px-3 py-1.5 rounded-md bg-orange-500/10 text-orange-400 hover:bg-orange-500/20 transition-colors border border-orange-500/20"
>