mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 18:05:24 +02:00
feat: update Dropbox source URL and implement smart dirty-checking for row highlight
This commit is contained in:
+37
-12
@@ -318,23 +318,48 @@ export default function App() {
|
||||
|
||||
const handleSaveRow = (rowIndex: number, updatedRow: ExcelRow) => {
|
||||
const articleNo = String(updatedRow[COLUMNS.ARTICLE_NO]);
|
||||
const originalData = appState.data[rowIndex]; // Capture before update
|
||||
const currentPending = pendingRows[articleNo];
|
||||
const originalData = currentPending?.originalData ?? appState.data[rowIndex];
|
||||
|
||||
// Check if the new state is actually different from the original (not the current)
|
||||
const isActuallyModified = JSON.stringify(updatedRow) !== JSON.stringify(originalData);
|
||||
|
||||
setAppState(prev => {
|
||||
const newData = [...prev.data];
|
||||
newData[rowIndex] = updatedRow;
|
||||
return { ...prev, data: newData, hasUnsavedChanges: true };
|
||||
});
|
||||
setPendingRows(prev => ({
|
||||
...prev,
|
||||
[articleNo]: {
|
||||
rowIndex,
|
||||
// Keep the very first originalData if already pending (re-edit case)
|
||||
originalData: prev[articleNo]?.originalData ?? originalData,
|
||||
newData: updatedRow,
|
||||
articleName: String(updatedRow[COLUMNS.ARTICLE_NAME] || articleNo),
|
||||
}
|
||||
}));
|
||||
setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' }));
|
||||
|
||||
if (isActuallyModified) {
|
||||
setPendingRows(prev => {
|
||||
const next = {
|
||||
...prev,
|
||||
[articleNo]: {
|
||||
rowIndex,
|
||||
originalData,
|
||||
newData: updatedRow,
|
||||
articleName: String(updatedRow[COLUMNS.ARTICLE_NAME] || articleNo),
|
||||
}
|
||||
};
|
||||
setAppState(app => ({ ...app, hasUnsavedChanges: true }));
|
||||
return next;
|
||||
});
|
||||
setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' }));
|
||||
} else {
|
||||
// It was changed back to its original state - remove from pending
|
||||
setPendingRows(prev => {
|
||||
const n = { ...prev };
|
||||
delete n[articleNo];
|
||||
const stillHasChanges = Object.keys(n).length > 0;
|
||||
setAppState(app => ({ ...app, hasUnsavedChanges: stillHasChanges }));
|
||||
return n;
|
||||
});
|
||||
setRowStatuses(prev => {
|
||||
const n = { ...prev };
|
||||
delete n[articleNo];
|
||||
return n;
|
||||
});
|
||||
}
|
||||
setEditingRowIndex(null);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user