diff --git a/Packages.props b/Packages.props
index 9f08a694..5caa5203 100644
--- a/Packages.props
+++ b/Packages.props
@@ -22,7 +22,7 @@
-
+
diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Components/TableProperties.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Components/TableProperties.cs
index 88b2984a..6a2fde97 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Components/TableProperties.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/Components/TableProperties.cs
@@ -41,6 +41,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
///
public bool CanRemoveRows { get; set; } = true;
+ ///
+ /// Whether rows can be moved.
+ ///
+ public bool CanMoveRows { get; set; } = false;
+
+ ///
+ /// Whether rows can be inserted.
+ ///
+ public bool CanInsertRows { get; set; } = false;
+
///
/// Whether a confirmation should be shown when a row is about to be removed.
///
diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableChangeInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableChangeInfo.cs
index 7a099c80..27de42de 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableChangeInfo.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableChangeInfo.cs
@@ -18,6 +18,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
Remove,
[EnumMember(Value = "Update")]
Update,
+ [EnumMember(Value = "Move")]
+ Move,
}
///
diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs
index e6d017e8..eee4fd57 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs
@@ -31,6 +31,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
public List PropertiesToDisplay { get; set; } = new List();
public bool CanAddRows { get; set; } = true;
public bool CanRemoveRows { get; set; } = true;
+ public bool CanMoveRows { get; set; } = false;
+ public bool CanInsertRows { get; set; } = false;
public List AdditionalProperties { get; set; } = new List();
public string RemoveRowConfirmationMessage { get; set; }
public bool ShowRemoveRowConfirmation { get; set; } = false;
diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/DesignerPathUtils.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/DesignerPathUtils.cs
index b2ae7eb8..9c3ece77 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/DesignerPathUtils.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/DesignerPathUtils.cs
@@ -14,17 +14,20 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
///
/// validate the path in the table designer change information.
/// Below are the 3 scenarios and their expected path.
- /// Note: 'index-{x}' in the description below are numbers represent the index of the object in the list.
+ /// Note: 'index{x}' in the description below are numbers represent the index of the object in the list.
/// 1. 'Add' scenario
- /// a. ['propertyName1']. Example: add a column to the columns property: ['columns'].
- /// b. ['propertyName1',index-1,'propertyName2']. Example: add a column mapping to the first foreign key: ['foreignKeys',0,'mappings'].
+ /// a. ['propertyName1',index1]. Example: add a column to the columns property: ['columns',0].
+ /// b. ['propertyName1',index1,'propertyName2',index2]. Example: add a column mapping to the first foreign key: ['foreignKeys',0,'mappings',0].
/// 2. 'Update' scenario
/// a. ['propertyName1']. Example: update the name of the table: ['name'].
- /// b. ['propertyName1',index-1,'propertyName2']. Example: update the name of a column: ['columns',0,'name'].
- /// c. ['propertyName1',index-1,'propertyName2',index-2,'propertyName3']. Example: update the source column of an entry in a foreign key's column mapping table: ['foreignKeys',0,'mappings',0,'source'].
+ /// b. ['propertyName1',index1,'propertyName2']. Example: update the name of a column: ['columns',0,'name'].
+ /// c. ['propertyName1',index1,'propertyName2',index2,'propertyName3']. Example: update the source column of an entry in a foreign key's column mapping table: ['foreignKeys',0,'mappings',0,'source'].
/// 3. 'Remove' scenario
- /// a. ['propertyName1',index-1]. Example: remove a column from the columns property: ['columns',0'].
- /// b. ['propertyName1',index-1,'propertyName2',index-2]. Example: remove a column mapping from a foreign key's column mapping table: ['foreignKeys',0,'mappings',0].
+ /// a. ['propertyName1',index1]. Example: remove a column from the columns property: ['columns',0'].
+ /// b. ['propertyName1',index1,'propertyName2',index2]. Example: remove a column mapping from a foreign key's column mapping table: ['foreignKeys',0,'mappings',0].
+ /// 4. 'Move' scenario
+ /// a. ['propertyName1',index1]. Example: Move a column in the columns property: ['columns',0'].
+ /// b. ['propertyName1',index1,'propertyName2',index2]. Example: Move a column mapping within a foreign key's column mapping table: ['foreignKeys',0,'mappings',0].
///
public static void Validate(object[] path, DesignerEditType editType)
{
@@ -37,13 +40,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
int[] validLengthList;
if (editType == DesignerEditType.Add)
{
- validLengthList = new int[] { 1, 3 };
+ validLengthList = new int[] { 2, 4 };
}
else if (editType == DesignerEditType.Update)
{
validLengthList = new int[] { 1, 3, 5 };
}
- else
+ else if (editType == DesignerEditType.Remove)
+ {
+ validLengthList = new int[] { 2, 4 };
+ } else
{
validLengthList = new int[] { 2, 4 };
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs
index 5fa90f9b..f49975ef 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs
@@ -113,6 +113,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
case DesignerEditType.Update:
refreshViewRequired = this.HandleUpdateItemRequest(requestParams);
break;
+ case DesignerEditType.Move:
+ this.HandleMoveItemRequest(requestParams);
+ break;
default:
break;
}
@@ -212,13 +215,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
var table = this.GetTableDesigner(requestParams.TableInfo).TableViewModel;
var path = requestParams.TableChangeInfo.Path;
// Handle the add item request on top level table properties, e.g. Columns, Indexes.
- if (path.Length == 1)
+ if (path.Length == 2)
{
var propertyName = path[0] as string;
+ var index = Convert.ToInt32(path[1]);
switch (propertyName)
{
case TablePropertyNames.Columns:
- table.Columns.AddNew();
+ table.Columns.AddNew(index);
break;
case TablePropertyNames.CheckConstraints:
table.CheckConstraints.AddNew();
@@ -243,11 +247,12 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
break;
}
}
- else if (path.Length == 3)
+ else if (path.Length == 4)
{
var propertyNameL1 = path[0] as string;
var indexL1 = Convert.ToInt32(path[1]);
var propertyNameL2 = path[2] as string;
+ var indexL2 = Convert.ToInt32(path[3]);
switch (propertyNameL1)
{
case TablePropertyNames.ForeignKeys:
@@ -691,6 +696,27 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
return refreshView;
}
+ private void HandleMoveItemRequest(ProcessTableDesignerEditRequestParams requestParams)
+ {
+ var table = this.GetTableDesigner(requestParams.TableInfo).TableViewModel;
+ var path = requestParams.TableChangeInfo.Path;
+ // Handle the move item request on top level table properties, e.g. Columns, Indexes.
+ if (path.Length == 2)
+ {
+ var propertyName = path[0] as string;
+ var fromIndex = Convert.ToInt32(path[1]);
+ var toIndex = Convert.ToInt32(requestParams.TableChangeInfo.Value);
+ switch (propertyName)
+ {
+ case TablePropertyNames.Columns:
+ table.Columns.Move(fromIndex, toIndex);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
private int GetInt32Value(object value)
{
return Int32.Parse(value as string);
@@ -982,6 +1008,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
});
view.ColumnTableOptions.CanAddRows = true;
view.ColumnTableOptions.CanRemoveRows = true;
+ view.ColumnTableOptions.CanMoveRows = true;
+ view.ColumnTableOptions.CanInsertRows = true;
view.ColumnTableOptions.RemoveRowConfirmationMessage = SR.TableDesignerDeleteColumnConfirmationMessage;
view.ColumnTableOptions.ShowRemoveRowConfirmation = true;
}
@@ -1012,6 +1040,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
});
view.ForeignKeyTableOptions.CanAddRows = true;
view.ForeignKeyTableOptions.CanRemoveRows = true;
+ view.ForeignKeyTableOptions.CanMoveRows = false;
+ view.ForeignKeyTableOptions.CanInsertRows = false;
}
private void SetCheckConstraintsViewInfo(TableDesignerView view)
@@ -1029,6 +1059,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
});
view.CheckConstraintTableOptions.CanAddRows = true;
view.CheckConstraintTableOptions.CanRemoveRows = true;
+ view.CheckConstraintTableOptions.CanMoveRows = false;
+ view.CheckConstraintTableOptions.CanInsertRows = false;
}
private void SetIndexesViewInfo(TableDesignerView view)
@@ -1079,6 +1111,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
view.IndexTableOptions.PropertiesToDisplay = new List() { IndexPropertyNames.Name, IndexPropertyNames.ColumnsDisplayValue, IndexPropertyNames.IsClustered, IndexPropertyNames.IsUnique };
view.IndexTableOptions.CanAddRows = true;
view.IndexTableOptions.CanRemoveRows = true;
+ view.IndexTableOptions.CanMoveRows = false;
+ view.IndexTableOptions.CanInsertRows = false;
view.IndexColumnSpecificationTableOptions.AdditionalProperties.Add(
new DesignerDataPropertyInfo()
@@ -1094,6 +1128,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
view.IndexColumnSpecificationTableOptions.PropertiesToDisplay.AddRange(new string[] { IndexColumnSpecificationPropertyNames.Column, IndexColumnSpecificationPropertyNames.Ascending });
view.IndexColumnSpecificationTableOptions.CanAddRows = true;
view.IndexColumnSpecificationTableOptions.CanRemoveRows = true;
+ view.IndexColumnSpecificationTableOptions.CanMoveRows = false;
+ view.IndexColumnSpecificationTableOptions.CanInsertRows = false;
}
private void SetGraphTableViewInfo(TableDesignerView view, Dac.TableDesigner tableDesigner)
diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/DesignerPathUtilsTest.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/DesignerPathUtilsTest.cs
index 6a3ee936..a9868db6 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/DesignerPathUtilsTest.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/DesignerPathUtilsTest.cs
@@ -16,11 +16,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner
public void ParseDesignerPathTest()
{
DesignerEditType editType = DesignerEditType.Add;
- this.RunTest(new object[] { "property1" }, editType, true);
- this.RunTest(new object[] { "property1", 1, "property2" }, editType, true);
+ this.RunTest(new object[] { "property1" }, editType, false);
+ this.RunTest(new object[] { "property1", 1, "property2" }, editType, false);
this.RunTest(new object[] { "property1", "xx", "property2" }, editType, false);
- this.RunTest(new object[] { "property1", 1 }, editType, false);
- this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, false);
+ this.RunTest(new object[] { "property1", 1 }, editType, true);
+ this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3" }, editType, false);
this.RunTest(new object[] { }, editType, false);
this.RunTest(null, editType, false);