fixed delete changeset rows

This commit is contained in:
Jan Prochazka 2022-02-13 09:33:15 +01:00
parent ada7ee7cab
commit bc593d25ae
3 changed files with 24 additions and 9 deletions

View File

@ -337,6 +337,25 @@ export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: Chan
return changeSet; return changeSet;
} }
function consolidateInsertIndexes(changeSet: ChangeSet, name: NamedObjectInfo): ChangeSet {
const indexes = changeSet.inserts
.filter(x => x.pureName == name.pureName && x.schemaName == name.schemaName)
.map(x => x.insertedRowIndex);
indexes.sort((a, b) => a - b);
if (indexes[indexes.length - 1] != indexes.length - 1) {
return {
...changeSet,
inserts: changeSet.inserts.map(x => ({
...x,
insertedRowIndex: indexes.indexOf(x.insertedRowIndex),
})),
};
}
return changeSet;
}
export function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet { export function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet {
let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition); let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
if (fieldName == 'updates') { if (fieldName == 'updates') {
@ -344,7 +363,7 @@ export function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetR
[fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition); [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
} }
if (fieldName == 'inserts') { if (fieldName == 'inserts') {
return revertChangeSetRowChanges(changeSet, definition); return consolidateInsertIndexes(revertChangeSetRowChanges(changeSet, definition), definition);
} else { } else {
if (existingItem && fieldName == 'deletes') return changeSet; if (existingItem && fieldName == 'deletes') return changeSet;
return { return {
@ -390,11 +409,7 @@ export function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectIn
}; };
} }
export function changeSetInsertDocuments( export function changeSetInsertDocuments(changeSet: ChangeSet, documents: any[], name?: NamedObjectInfo): ChangeSet {
changeSet: ChangeSet,
documents: any[],
name?: NamedObjectInfo
): ChangeSet {
const insertedRows = getChangeSetInsertedRows(changeSet, name); const insertedRows = getChangeSetInsertedRows(changeSet, name);
return { return {
...changeSet, ...changeSet,

View File

@ -391,7 +391,7 @@
export function deleteSelectedRows() { export function deleteSelectedRows() {
grider.beginUpdate(); grider.beginUpdate();
for (const index of getSelectedRowIndexes()) { for (const index of _.sortBy(getSelectedRowIndexes(), x => -x)) {
if (_.isNumber(index)) grider.deleteRow(index); if (_.isNumber(index)) grider.deleteRow(index);
} }
grider.endUpdate(); grider.endUpdate();
@ -750,7 +750,7 @@
export function generateSqlFromData() { export function generateSqlFromData() {
const columnIndexes = _.uniq(selectedCells.map(x => x[1])); const columnIndexes = _.uniq(selectedCells.map(x => x[1]));
columnIndexes.sort(); columnIndexes.sort((a, b) => a - b);
showModal(GenerateSqlFromDataModal, { showModal(GenerateSqlFromDataModal, {
rows: getSelectedRowData(), rows: getSelectedRowData(),

View File

@ -68,7 +68,7 @@ export class SeriesSizes {
// _.map(this.intKeys(_.keys(this.sizeOverridesByModelIndex)), (x) => this.modelToReal(x) - this.frozenCount), // _.map(this.intKeys(_.keys(this.sizeOverridesByModelIndex)), (x) => this.modelToReal(x) - this.frozenCount),
x => x >= 0 x => x >= 0
); );
this.scrollIndexes.sort(); this.scrollIndexes.sort((a, b) => a - b);
let lastScrollIndex: number = -1; let lastScrollIndex: number = -1;
let lastEndPosition: number = 0; let lastEndPosition: number = 0;
this.scrollIndexes.forEach(scrollIndex => { this.scrollIndexes.forEach(scrollIndex => {