From 6d243e0ac875242f87ae6092b12b27e5d3779da3 Mon Sep 17 00:00:00 2001 From: Leila Lali Date: Wed, 2 May 2018 15:57:15 -0700 Subject: [PATCH] reverting row which escape is clicked and fixed the issue with reverting rows (#1333) * reverting row which escape is clicked and fixed the issue with reverting row --- .../grid/views/editData/editData.component.ts | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/sql/parts/grid/views/editData/editData.component.ts b/src/sql/parts/grid/views/editData/editData.component.ts index ed02b2b833..c0e22d886d 100644 --- a/src/sql/parts/grid/views/editData/editData.component.ts +++ b/src/sql/parts/grid/views/editData/editData.component.ts @@ -52,7 +52,7 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On private currentEditCellValue: string; private newRowVisible: boolean; private removingNewRow: boolean; - private rowIdMappings: {[gridRowId: number]: number} = {}; + private rowIdMappings: { [gridRowId: number]: number } = {}; // Edit Data functions public onActiveCellChanged: (event: { row: number, column: number }) => void; @@ -203,10 +203,12 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On return (index: number): void => { // Force focus to the first cell (completing any active edit operation) self.focusCell(index, 0, false); - + this.currentEditCellValue = null; // Perform a revert row operation self.dataService.revertRow(index) - .then(() => self.refreshResultsets()); + .then(() => { + self.refreshResultsets(); + }); }; } @@ -238,18 +240,18 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On return self.dataService.updateCell(sessionRowId, self.currentCell.column - 1, self.currentEditCellValue) .then( - result => { - // Cell update was successful, update the flags - self.currentEditCellValue = null; - self.setCellDirtyState(row, self.currentCell.column, result.cell.isDirty); - self.setRowDirtyState(row, result.isRowDirty); - return Promise.resolve(); - }, - error => { - // Cell update failed, jump back to the last cell we were on - self.focusCell(self.currentCell.row, self.currentCell.column, true); - return Promise.reject(null); - } + result => { + // Cell update was successful, update the flags + self.currentEditCellValue = null; + self.setCellDirtyState(row, self.currentCell.column, result.cell.isDirty); + self.setRowDirtyState(row, result.isRowDirty); + return Promise.resolve(); + }, + error => { + // Cell update failed, jump back to the last cell we were on + self.focusCell(self.currentCell.row, self.currentCell.column, true); + return Promise.reject(null); + } ); }); } @@ -259,18 +261,18 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On cellSelectTasks = cellSelectTasks.then(() => { return self.dataService.commitEdit() .then( - result => { - // Committing was successful, clean the grid - self.setGridClean(); - self.rowIdMappings = {}; - self.newRowVisible = false; - return Promise.resolve(); - }, - error => { - // Committing failed, jump back to the last selected cell - self.focusCell(self.currentCell.row, self.currentCell.column); - return Promise.reject(null); - } + result => { + // Committing was successful, clean the grid + self.setGridClean(); + self.rowIdMappings = {}; + self.newRowVisible = false; + return Promise.resolve(); + }, + error => { + // Committing failed, jump back to the last selected cell + self.focusCell(self.currentCell.row, self.currentCell.column); + return Promise.reject(null); + } ); }); } @@ -294,7 +296,7 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On }); // Cap off any failed promises, since they'll be handled - cellSelectTasks.catch(() => {}); + cellSelectTasks.catch(() => { }); } handleComplete(self: EditDataComponent, event: any): void { @@ -415,6 +417,10 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On this.newRowVisible = false; }); handled = true; + } else if (e.keyCode === jQuery.ui.keyCode.ESCAPE) { + this.currentEditCellValue = null; + this.onRevertRow()(this.currentCell.row); + handled = true; } return handled; } @@ -515,7 +521,7 @@ export class EditDataComponent extends GridParentComponent implements OnInit, On }, this.scrollTimeOutTime); } - private focusCell(row: number, column: number, forceEdit: boolean=true): void { + private focusCell(row: number, column: number, forceEdit: boolean = true): void { let slick: any = this.slickgrids.toArray()[0]; let grid = slick._grid; grid.gotoCell(row, column, forceEdit);