revert row changes command

This commit is contained in:
Jan Prochazka 2020-03-27 21:35:14 +01:00
parent 03550f1d27
commit 54976ca21f
2 changed files with 18 additions and 2 deletions

View File

@ -179,3 +179,13 @@ export function changeSetToSql(changeSet: ChangeSet): Command[] {
...changeSet.deletes.map(deleteToSql),
];
}
export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet {
const [field, item] = findExistingChangeSetItem(changeSet, definition);
if (item)
return {
...changeSet,
[field]: changeSet[field].filter(x => x != item),
};
return changeSet;
}

View File

@ -26,7 +26,7 @@ import DataGridRow from './DataGridRow';
import { countColumnSizes, countVisibleRealColumns } from './gridutil';
import useModalState from '../modals/useModalState';
import ConfirmSqlModal from '../modals/ConfirmSqlModal';
import { changeSetToSql, createChangeSet } from '@dbgate/datalib';
import { changeSetToSql, createChangeSet, revertChangeSetRowChanges } from '@dbgate/datalib';
import { scriptToSql } from '@dbgate/sqltree';
import { sleep } from '../utility/common';
@ -327,6 +327,12 @@ export default function DataGridCore(props) {
}
}
function revertRowChanges() {
if (loadedRows && currentCell && loadedRows[currentCell[0]]) {
setChangeSet(revertChangeSetRowChanges(changeSet, display.getChangeSetRow(loadedRows[currentCell[0]])));
}
}
function handleGridWheel(event) {
let newFirstVisibleRowScrollIndex = firstVisibleRowScrollIndex;
if (event.deltaY > 0) {
@ -391,7 +397,7 @@ export default function DataGridCore(props) {
if (event.keyCode == keycodes.r && event.ctrlKey) {
event.preventDefault();
// revertRowChanges();
revertRowChanges();
// this.saveAndFocus();
}