mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-03 01:25:44 -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:
@@ -6,6 +6,7 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
@@ -101,6 +102,14 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a new EditCell that represents the contents of the cell update
|
||||
/// </summary>
|
||||
public EditCell AsEditCell
|
||||
{
|
||||
get { return new EditCell(AsDbCellValue, true); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The column that the cell will be placed in
|
||||
/// </summary>
|
||||
|
||||
@@ -184,14 +184,16 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// </summary>
|
||||
/// <param name="columnId">The ordinal ID of the cell to reset</param>
|
||||
/// <returns>The default value for the column, or null if no default is defined</returns>
|
||||
public override string RevertCell(int columnId)
|
||||
public override EditRevertCellResult RevertCell(int columnId)
|
||||
{
|
||||
// Validate that the column can be reverted
|
||||
Validate.IsWithinRange(nameof(columnId), columnId, 0, newCells.Length - 1);
|
||||
|
||||
// Remove the cell update from list of set cells
|
||||
newCells[columnId] = null;
|
||||
return null; // @TODO: Return default value when we have support checked in
|
||||
return new EditRevertCellResult {IsRowDirty = true, Cell = null};
|
||||
// @TODO: Return default value when we have support checked in
|
||||
// @TODO: RETURN THE DEFAULT VALUE
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -212,14 +214,11 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
newCells[columnId] = update;
|
||||
|
||||
// Put together a result of the change
|
||||
EditUpdateCellResult eucr = new EditUpdateCellResult
|
||||
return new EditUpdateCellResult
|
||||
{
|
||||
HasCorrections = update.ValueAsString != newValue,
|
||||
NewValue = update.ValueAsString != newValue ? update.ValueAsString : null,
|
||||
IsNull = update.Value == DBNull.Value,
|
||||
IsRevert = false // Editing cells of new rows cannot be reverts
|
||||
};
|
||||
return eucr;
|
||||
IsRowDirty = true, // Row creates will always be dirty
|
||||
Cell = update.AsEditCell
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// deletion.
|
||||
/// </summary>
|
||||
/// <param name="columnId">Ordinal of the column to update</param>
|
||||
public override string RevertCell(int columnId)
|
||||
public override EditRevertCellResult RevertCell(int columnId)
|
||||
{
|
||||
throw new InvalidOperationException(SR.EditDataDeleteSetCell);
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement
|
||||
/// </summary>
|
||||
/// <param name="columnId">Ordinal ID of the column to revert</param>
|
||||
/// <returns>String value of the original value of the cell</returns>
|
||||
public abstract string RevertCell(int columnId);
|
||||
public abstract EditRevertCellResult RevertCell(int columnId);
|
||||
|
||||
/// <summary>
|
||||
/// Changes the value a cell in the row.
|
||||
|
||||
@@ -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