Warn when reverting to original state (no actual changes)

This commit is contained in:
Christian Vidal Wolf
2026-04-10 09:42:04 +02:00
parent 7bf37eb017
commit 0cf4f59937
2 changed files with 12 additions and 2 deletions
+1
View File
@@ -473,6 +473,7 @@ export default function App() {
{activeModule === 'history' && (
<HistoryView
headers={appState.headers}
data={appState.data}
onRevert={(articleNo, revertedData) => {
// Find the row in appState.data and update it
const rowIndex = appState.data.findIndex(r => String(r[COLUMNS.ARTICLE_NO]) === articleNo);
+11 -2
View File
@@ -6,10 +6,11 @@ import { cn } from '../lib/utils';
interface HistoryViewProps {
headers: string[];
data: ExcelRow[];
onRevert: (articleNo: string, oldData: ExcelRow) => void;
}
export function HistoryView({ headers, onRevert }: HistoryViewProps) {
export function HistoryView({ headers, data, onRevert }: HistoryViewProps) {
const [history, setHistory] = useState<HistoryEntry[]>([]);
const [loading, setLoading] = useState(true);
const [expandedId, setExpandedId] = useState<string | null>(null);
@@ -157,7 +158,15 @@ export function HistoryView({ headers, onRevert }: HistoryViewProps) {
onClick={(e) => {
e.stopPropagation();
if (window.confirm(`Are you sure you want to revert changes for ${entry.article_name}?`)) {
onRevert(entry.product_id, entry.old_data);
// 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);
}
}
}}
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"