mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
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:
@@ -3,7 +3,6 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@@ -167,15 +166,21 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// </summary>
|
||||
/// <param name="columnId">Ordinal of the column to revert</param>
|
||||
/// <returns>The value that was </returns>
|
||||
public override string RevertCell(int columnId)
|
||||
public override EditRevertCellResult RevertCell(int columnId)
|
||||
{
|
||||
Validate.IsWithinRange(nameof(columnId), columnId, 0, associatedRow.Count - 1);
|
||||
|
||||
// Remove the cell update
|
||||
// NOTE: This is best effort. The only way TryRemove can fail is if it is already
|
||||
// removed. If this happens, it is OK.
|
||||
CellUpdate cellUpdate;
|
||||
cellUpdates.TryRemove(columnId, out cellUpdate);
|
||||
|
||||
return associatedRow[columnId].DisplayValue;
|
||||
return new EditRevertCellResult
|
||||
{
|
||||
IsRowDirty = cellUpdates.Count > 0,
|
||||
Cell = new EditCell(associatedRow[columnId], false)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -203,10 +208,8 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
cellUpdates.TryRemove(columnId, out cu);
|
||||
return new EditUpdateCellResult
|
||||
{
|
||||
HasCorrections = false,
|
||||
NewValue = associatedRow[columnId].DisplayValue,
|
||||
IsRevert = true,
|
||||
IsNull = associatedRow[columnId].IsNull
|
||||
IsRowDirty = cellUpdates.Count > 0,
|
||||
Cell = new EditCell(associatedRow[columnId], false)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -214,10 +217,8 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
cellUpdates.AddOrUpdate(columnId, update, (i, cu) => update);
|
||||
return new EditUpdateCellResult
|
||||
{
|
||||
HasCorrections = update.ValueAsString != newValue,
|
||||
NewValue = update.ValueAsString != newValue ? update.ValueAsString : null,
|
||||
IsNull = update.Value == DBNull.Value,
|
||||
IsRevert = false // If we're in this branch, it is not a revert
|
||||
IsRowDirty = true,
|
||||
Cell = update.AsEditCell
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user