mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 14:45:24 +02:00
feat: update Dropbox source URL and implement smart dirty-checking for row highlight
This commit is contained in:
+30
-5
@@ -318,23 +318,48 @@ export default function App() {
|
|||||||
|
|
||||||
const handleSaveRow = (rowIndex: number, updatedRow: ExcelRow) => {
|
const handleSaveRow = (rowIndex: number, updatedRow: ExcelRow) => {
|
||||||
const articleNo = String(updatedRow[COLUMNS.ARTICLE_NO]);
|
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 => {
|
setAppState(prev => {
|
||||||
const newData = [...prev.data];
|
const newData = [...prev.data];
|
||||||
newData[rowIndex] = updatedRow;
|
newData[rowIndex] = updatedRow;
|
||||||
return { ...prev, data: newData, hasUnsavedChanges: true };
|
return { ...prev, data: newData, hasUnsavedChanges: true };
|
||||||
});
|
});
|
||||||
setPendingRows(prev => ({
|
|
||||||
|
if (isActuallyModified) {
|
||||||
|
setPendingRows(prev => {
|
||||||
|
const next = {
|
||||||
...prev,
|
...prev,
|
||||||
[articleNo]: {
|
[articleNo]: {
|
||||||
rowIndex,
|
rowIndex,
|
||||||
// Keep the very first originalData if already pending (re-edit case)
|
originalData,
|
||||||
originalData: prev[articleNo]?.originalData ?? originalData,
|
|
||||||
newData: updatedRow,
|
newData: updatedRow,
|
||||||
articleName: String(updatedRow[COLUMNS.ARTICLE_NAME] || articleNo),
|
articleName: String(updatedRow[COLUMNS.ARTICLE_NAME] || articleNo),
|
||||||
}
|
}
|
||||||
}));
|
};
|
||||||
|
setAppState(app => ({ ...app, hasUnsavedChanges: true }));
|
||||||
|
return next;
|
||||||
|
});
|
||||||
setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' }));
|
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);
|
setEditingRowIndex(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user