mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 15:55:24 +02:00
Warn when reverting to original state (no actual changes)
This commit is contained in:
@@ -473,6 +473,7 @@ export default function App() {
|
|||||||
{activeModule === 'history' && (
|
{activeModule === 'history' && (
|
||||||
<HistoryView
|
<HistoryView
|
||||||
headers={appState.headers}
|
headers={appState.headers}
|
||||||
|
data={appState.data}
|
||||||
onRevert={(articleNo, revertedData) => {
|
onRevert={(articleNo, revertedData) => {
|
||||||
// Find the row in appState.data and update it
|
// Find the row in appState.data and update it
|
||||||
const rowIndex = appState.data.findIndex(r => String(r[COLUMNS.ARTICLE_NO]) === articleNo);
|
const rowIndex = appState.data.findIndex(r => String(r[COLUMNS.ARTICLE_NO]) === articleNo);
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import { cn } from '../lib/utils';
|
|||||||
|
|
||||||
interface HistoryViewProps {
|
interface HistoryViewProps {
|
||||||
headers: string[];
|
headers: string[];
|
||||||
|
data: ExcelRow[];
|
||||||
onRevert: (articleNo: string, oldData: ExcelRow) => void;
|
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 [history, setHistory] = useState<HistoryEntry[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [expandedId, setExpandedId] = useState<string | null>(null);
|
const [expandedId, setExpandedId] = useState<string | null>(null);
|
||||||
@@ -157,7 +158,15 @@ export function HistoryView({ headers, onRevert }: HistoryViewProps) {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (window.confirm(`Are you sure you want to revert changes for ${entry.article_name}?`)) {
|
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"
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user