mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-16 17:23:38 -05:00
Returning EditCell in EditRows (#302)
Instead of returning DbCellValues inside an EditRow, we should be returning EditCells. This way we can preserve dirty state when scrolling.
This commit is contained in:
@@ -25,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
|
||||
/// The cells in the row. If the row has pending changes, they will be represented in
|
||||
/// this list
|
||||
/// </summary>
|
||||
public DbCellValue[] Cells { get; set; }
|
||||
public EditCell[] Cells { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Internal ID of the row. This should be used whenever referencing a row in row edit operations.
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
EditRow er = new EditRow
|
||||
{
|
||||
Id = rowId,
|
||||
Cells = cachedRows.Rows[i],
|
||||
Cells = cachedRows.Rows[i].Select(cell => new EditCell(cell, false)).ToArray(),
|
||||
State = EditRow.EditRowState.Clean
|
||||
};
|
||||
editRows.Add(er);
|
||||
|
||||
@@ -130,9 +130,13 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
public override EditRow GetEditRow(DbCellValue[] cachedRow)
|
||||
{
|
||||
// Iterate over the new cells. If they are null, generate a blank value
|
||||
DbCellValue[] editCells = newCells.Select(cell => cell == null
|
||||
? new DbCellValue {DisplayValue = string.Empty, IsNull = false, RawObject = null}
|
||||
: cell.AsDbCellValue)
|
||||
EditCell[] editCells = newCells.Select(cell =>
|
||||
{
|
||||
DbCellValue dbCell = cell == null
|
||||
? new DbCellValue {DisplayValue = string.Empty, IsNull = false, RawObject = null}
|
||||
: cell.AsDbCellValue;
|
||||
return new EditCell(dbCell, true);
|
||||
})
|
||||
.ToArray();
|
||||
return new EditRow
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
@@ -86,7 +87,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
return new EditRow
|
||||
{
|
||||
Id = RowId,
|
||||
Cells = cachedRow,
|
||||
Cells = cachedRow.Select(cell => new EditCell(cell, true)).ToArray(),
|
||||
State = EditRow.EditRowState.DirtyDelete
|
||||
};
|
||||
}
|
||||
|
||||
@@ -122,16 +122,19 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
{
|
||||
Validate.IsNotNull(nameof(cachedRow), cachedRow);
|
||||
|
||||
// For each cell that is pending update, replace the db cell value with a new one
|
||||
// Treat all the cells as clean initially
|
||||
EditCell[] editCells = cachedRow.Select(cell => new EditCell(cell, false)).ToArray();
|
||||
|
||||
// For each cell that is pending update, replace the db cell value with a dirty one
|
||||
foreach (var cellUpdate in cellUpdates)
|
||||
{
|
||||
cachedRow[cellUpdate.Key] = cellUpdate.Value.AsDbCellValue;
|
||||
editCells[cellUpdate.Key] = cellUpdate.Value.AsEditCell;
|
||||
}
|
||||
|
||||
return new EditRow
|
||||
{
|
||||
Id = RowId,
|
||||
Cells = cachedRow,
|
||||
Cells = editCells,
|
||||
State = EditRow.EditRowState.DirtyUpdate
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user