Implicit Revert Row Cleanup Logic (#297)

This change enhances the way that edit/updateCell and edit/revertCell operations are performed. 

## **THE API BREAKING CHANGES**:
* edit/updateCell now returns an EditCell (a DbCellValue with a dirty flag) and a row dirty flag.
* edit/revertCell now returns an EditCell (a DbCellValue with a dirty flag) and a row dirty flag.

If by setting the value of a cell via edit/updateCell the row no longer has any edits (an "implicit revert"), the entire row's edit will be removed from the cache. Additionally, if by requesting edit/revert all the pending edits for a row are removed, the entire row's edit will be removed from the cache. This will prevent issues where committing will generate an invalid script because it has no pending changes.

* Adding EditCell class
Returning EditCell with EditUpdateCellResult

* Adding code that will remove a row update if the row is clean after a cell update

* Adding code that will return an EditCell and row dirty flag when a cell is reverted.
If the row is reverted by the cell revert, the pending update will be removed

* Comments for edit cell

* Changes as per pull request comments
This commit is contained in:
Benjamin Russell
2017-03-29 13:51:29 -07:00
committed by GitHub
parent fc04f6822f
commit 42498446cc
16 changed files with 357 additions and 124 deletions

View File

@@ -0,0 +1,39 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
{
/// <summary>
/// Cell that wraps info from <see cref="DbCellValue"/> for edit purposes
/// </summary>
public class EditCell : DbCellValue
{
/// <summary>
/// Default, parameterless constructor to make sure that JSON serializing is happy
/// </summary>
public EditCell() {}
/// <summary>
/// Constructs a new EditCell based on a DbCellValue
/// </summary>
/// <param name="dbCellValue">The DbCellValue that will be enhanced</param>
/// <param name="isDirty">Whether or not the edit cell is dirty</param>
public EditCell(DbCellValue dbCellValue, bool isDirty)
{
IsDirty = isDirty;
DisplayValue = dbCellValue.DisplayValue;
IsNull = dbCellValue.IsNull;
RawObject = dbCellValue.RawObject;
}
/// <summary>
/// Whether or not the cell is considered dirty
/// </summary>
public bool IsDirty { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
{
/// <summary>
/// Parameters to return when a cell is updated in isolation
/// </summary>
public class EditCellResult
{
/// <summary>
/// The cell after the revert was applied
/// </summary>
public EditCell Cell { get; set; }
/// <summary>
/// Whether or not the row is dirty after the revert has been applied
/// </summary>
public bool IsRowDirty { get; set; }
}
}

View File

@@ -7,14 +7,19 @@ using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
{
/// <summary>
/// Parameters for the cell revert request
/// </summary>
public class EditRevertCellParams : RowOperationParams
{
public int ColumnId { get; set; }
}
public class EditRevertCellResult
/// <summary>
/// Parameters to return upon successful revert of the cell
/// </summary>
public class EditRevertCellResult : EditCellResult
{
public string NewValue { get; set; }
}
public class EditRevertCellRequest

View File

@@ -26,31 +26,8 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
/// <summary>
/// Parameters to return upon successful update of the cell
/// </summary>
public class EditUpdateCellResult
public class EditUpdateCellResult : EditCellResult
{
/// <summary>
/// Whether or not the cell value was modified from the provided string.
/// If <c>true</c>, the client should replace the display value of the cell with the value
/// in <see cref="NewValue"/>
/// </summary>
public bool HasCorrections { get; set; }
/// <summary>
/// Whether or not the cell was reverted with the change.
/// If <c>true</c>, the client should unmark the cell as having an update and replace the
/// display value of the cell with the value in <see cref="NewValue"/>
/// </summary>
public bool IsRevert { get; set; }
/// <summary>
/// Whether or not the new value of the cell is null
/// </summary>
public bool IsNull { get; set; }
/// <summary>
/// The new string value of the cell
/// </summary>
public string NewValue { get; set; }
}
public class EditUpdateCellRequest