mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 11:56:00 +00:00
revert row changes, delete - for all selected rows
This commit is contained in:
@@ -194,7 +194,9 @@ export function changeSetToSql(changeSet: ChangeSet): Command[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet {
|
export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet {
|
||||||
|
console.log('definition', definition)
|
||||||
const [field, item] = findExistingChangeSetItem(changeSet, definition);
|
const [field, item] = findExistingChangeSetItem(changeSet, definition);
|
||||||
|
console.log('field, item', field, item)
|
||||||
if (item)
|
if (item)
|
||||||
return {
|
return {
|
||||||
...changeSet,
|
...changeSet,
|
||||||
|
|||||||
@@ -371,21 +371,19 @@ export abstract class GridDisplay {
|
|||||||
if (!this.baseTable) return null;
|
if (!this.baseTable) return null;
|
||||||
if (this.baseTable.pureName != col.pureName || this.baseTable.schemaName != col.schemaName) return null;
|
if (this.baseTable.pureName != col.pureName || this.baseTable.schemaName != col.schemaName) return null;
|
||||||
return {
|
return {
|
||||||
pureName: col.pureName,
|
...this.getChangeSetRow(row, insertedRowIndex),
|
||||||
schemaName: col.schemaName,
|
|
||||||
uniqueName: uniqueName,
|
uniqueName: uniqueName,
|
||||||
columnName: col.columnName,
|
columnName: col.columnName,
|
||||||
insertedRowIndex,
|
|
||||||
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getChangeSetRow(row): ChangeSetRowDefinition {
|
getChangeSetRow(row, insertedRowIndex): ChangeSetRowDefinition {
|
||||||
if (!this.baseTable) return null;
|
if (!this.baseTable) return null;
|
||||||
return {
|
return {
|
||||||
pureName: this.baseTable.pureName,
|
pureName: this.baseTable.pureName,
|
||||||
schemaName: this.baseTable.schemaName,
|
schemaName: this.baseTable.schemaName,
|
||||||
condition: this.getChangeSetCondition(row),
|
insertedRowIndex,
|
||||||
|
condition: insertedRowIndex == null ? this.getChangeSetCondition(row) : null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -339,16 +339,36 @@ export default function DataGridCore(props) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function revertRowChanges() {
|
function getSelectedRowDefinitions() {
|
||||||
if (loadedRows && currentCell && loadedRows[currentCell[0]]) {
|
const res = [];
|
||||||
setChangeSet(revertChangeSetRowChanges(changeSet, display.getChangeSetRow(loadedRows[currentCell[0]])));
|
if (!loadedAndInsertedRows) return res;
|
||||||
|
const rowIndexes = _.uniq((selectedCells || []).map(x => x[0]));
|
||||||
|
for (const index of rowIndexes) {
|
||||||
|
if (loadedAndInsertedRows[index] && _.isNumber(index)) {
|
||||||
|
const insertedRowIndex =
|
||||||
|
firstVisibleRowScrollIndex + index >= loadedRows.length
|
||||||
|
? firstVisibleRowScrollIndex + index - loadedRows.length
|
||||||
|
: null;
|
||||||
|
res.push(display.getChangeSetRow(loadedAndInsertedRows[index], insertedRowIndex));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function revertRowChanges() {
|
||||||
|
const updatedChangeSet = getSelectedRowDefinitions().reduce(
|
||||||
|
(chs, row) => revertChangeSetRowChanges(chs, row),
|
||||||
|
changeSet
|
||||||
|
);
|
||||||
|
setChangeSet(updatedChangeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteCurrentRow() {
|
function deleteCurrentRow() {
|
||||||
if (loadedRows && currentCell && loadedRows[currentCell[0]]) {
|
const updatedChangeSet = getSelectedRowDefinitions().reduce(
|
||||||
setChangeSet(deleteChangeSetRows(changeSet, display.getChangeSetRow(loadedRows[currentCell[0]])));
|
(chs, row) => deleteChangeSetRows(chs, row),
|
||||||
}
|
changeSet
|
||||||
|
);
|
||||||
|
setChangeSet(updatedChangeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGridWheel(event) {
|
function handleGridWheel(event) {
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ export default function DataGridRow({
|
|||||||
insertedRowIndex,
|
insertedRowIndex,
|
||||||
}) {
|
}) {
|
||||||
// console.log('RENDER ROW', rowIndex);
|
// console.log('RENDER ROW', rowIndex);
|
||||||
const rowDefinition = display.getChangeSetRow(row);
|
const rowDefinition = display.getChangeSetRow(row, insertedRowIndex);
|
||||||
const [matchedField, matchedChangeSetItem] = findExistingChangeSetItem(changeSet, rowDefinition);
|
const [matchedField, matchedChangeSetItem] = findExistingChangeSetItem(changeSet, rowDefinition);
|
||||||
const rowUpdated = matchedChangeSetItem ? { ...row, ...matchedChangeSetItem.fields } : row;
|
const rowUpdated = matchedChangeSetItem ? { ...row, ...matchedChangeSetItem.fields } : row;
|
||||||
const hintFieldsAllowed = visibleRealColumns
|
const hintFieldsAllowed = visibleRealColumns
|
||||||
|
|||||||
Reference in New Issue
Block a user