revert row changes, delete - for all selected rows

This commit is contained in:
Jan Prochazka
2020-03-29 13:16:58 +02:00
parent 50bf392e4a
commit 54d3f8383a
4 changed files with 33 additions and 13 deletions

View File

@@ -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,

View File

@@ -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,
}; };
} }
} }

View File

@@ -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) {

View File

@@ -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