[Table Designer] api change for insert and move col (#1477)

* make api change for insert and move col
* bump DacFx
This commit is contained in:
Hai Cao
2022-05-06 15:00:34 -07:00
committed by GitHub
parent fb1a12c6d2
commit 24910c5b5c
7 changed files with 73 additions and 17 deletions

View File

@@ -22,7 +22,7 @@
<PackageReference Update="Microsoft.Data.SqlClient" Version="3.1.0"/> <PackageReference Update="Microsoft.Data.SqlClient" Version="3.1.0"/>
<PackageReference Update="Microsoft.SqlServer.SqlManagementObjects" Version="161.47008.0" /> <PackageReference Update="Microsoft.SqlServer.SqlManagementObjects" Version="161.47008.0" />
<PackageReference Update="Microsoft.SqlServer.Management.SmoMetadataProvider" Version="161.47008.0" /> <PackageReference Update="Microsoft.SqlServer.Management.SmoMetadataProvider" Version="161.47008.0" />
<PackageReference Update="Microsoft.SqlServer.DACFx" Version="160.6107.0-preview" GeneratePathProperty="true" /> <PackageReference Update="Microsoft.SqlServer.DACFx" Version="160.6143.0-preview" GeneratePathProperty="true" />
<PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" /> <PackageReference Update="Microsoft.Azure.Kusto.Data" Version="9.0.4" />
<PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4"/> <PackageReference Update="Microsoft.Azure.Kusto.Language" Version="9.0.4"/>
<PackageReference Update="Microsoft.SqlServer.Assessment" Version="[1.0.305]" /> <PackageReference Update="Microsoft.SqlServer.Assessment" Version="[1.0.305]" />

View File

@@ -41,6 +41,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
/// </summary> /// </summary>
public bool CanRemoveRows { get; set; } = true; public bool CanRemoveRows { get; set; } = true;
/// <summary>
/// Whether rows can be moved.
/// </summary>
public bool CanMoveRows { get; set; } = false;
/// <summary>
/// Whether rows can be inserted.
/// </summary>
public bool CanInsertRows { get; set; } = false;
/// <summary> /// <summary>
/// Whether a confirmation should be shown when a row is about to be removed. /// Whether a confirmation should be shown when a row is about to be removed.
/// </summary> /// </summary>

View File

@@ -18,6 +18,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
Remove, Remove,
[EnumMember(Value = "Update")] [EnumMember(Value = "Update")]
Update, Update,
[EnumMember(Value = "Move")]
Move,
} }
/// <summary> /// <summary>

View File

@@ -31,6 +31,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
public List<string> PropertiesToDisplay { get; set; } = new List<string>(); public List<string> PropertiesToDisplay { get; set; } = new List<string>();
public bool CanAddRows { get; set; } = true; public bool CanAddRows { get; set; } = true;
public bool CanRemoveRows { get; set; } = true; public bool CanRemoveRows { get; set; } = true;
public bool CanMoveRows { get; set; } = false;
public bool CanInsertRows { get; set; } = false;
public List<DesignerDataPropertyInfo> AdditionalProperties { get; set; } = new List<DesignerDataPropertyInfo>(); public List<DesignerDataPropertyInfo> AdditionalProperties { get; set; } = new List<DesignerDataPropertyInfo>();
public string RemoveRowConfirmationMessage { get; set; } public string RemoveRowConfirmationMessage { get; set; }
public bool ShowRemoveRowConfirmation { get; set; } = false; public bool ShowRemoveRowConfirmation { get; set; } = false;

View File

@@ -14,17 +14,20 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
///<summary> ///<summary>
/// validate the path in the table designer change information. /// validate the path in the table designer change information.
/// Below are the 3 scenarios and their expected path. /// 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 /// 1. 'Add' scenario
/// a. ['propertyName1']. Example: add a column to the columns property: ['columns']. /// a. ['propertyName1',index1]. Example: add a column to the columns property: ['columns',0].
/// b. ['propertyName1',index-1,'propertyName2']. Example: add a column mapping to the first foreign key: ['foreignKeys',0,'mappings']. /// b. ['propertyName1',index1,'propertyName2',index2]. Example: add a column mapping to the first foreign key: ['foreignKeys',0,'mappings',0].
/// 2. 'Update' scenario /// 2. 'Update' scenario
/// a. ['propertyName1']. Example: update the name of the table: ['name']. /// 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']. /// b. ['propertyName1',index1,'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']. /// 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 /// 3. 'Remove' scenario
/// a. ['propertyName1',index-1]. Example: remove a column from the columns property: ['columns',0']. /// a. ['propertyName1',index1]. 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]. /// 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].
///<summary> ///<summary>
public static void Validate(object[] path, DesignerEditType editType) public static void Validate(object[] path, DesignerEditType editType)
{ {
@@ -37,13 +40,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
int[] validLengthList; int[] validLengthList;
if (editType == DesignerEditType.Add) if (editType == DesignerEditType.Add)
{ {
validLengthList = new int[] { 1, 3 }; validLengthList = new int[] { 2, 4 };
} }
else if (editType == DesignerEditType.Update) else if (editType == DesignerEditType.Update)
{ {
validLengthList = new int[] { 1, 3, 5 }; validLengthList = new int[] { 1, 3, 5 };
} }
else else if (editType == DesignerEditType.Remove)
{
validLengthList = new int[] { 2, 4 };
} else
{ {
validLengthList = new int[] { 2, 4 }; validLengthList = new int[] { 2, 4 };
} }

View File

@@ -113,6 +113,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
case DesignerEditType.Update: case DesignerEditType.Update:
refreshViewRequired = this.HandleUpdateItemRequest(requestParams); refreshViewRequired = this.HandleUpdateItemRequest(requestParams);
break; break;
case DesignerEditType.Move:
this.HandleMoveItemRequest(requestParams);
break;
default: default:
break; break;
} }
@@ -212,13 +215,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
var table = this.GetTableDesigner(requestParams.TableInfo).TableViewModel; var table = this.GetTableDesigner(requestParams.TableInfo).TableViewModel;
var path = requestParams.TableChangeInfo.Path; var path = requestParams.TableChangeInfo.Path;
// Handle the add item request on top level table properties, e.g. Columns, Indexes. // 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 propertyName = path[0] as string;
var index = Convert.ToInt32(path[1]);
switch (propertyName) switch (propertyName)
{ {
case TablePropertyNames.Columns: case TablePropertyNames.Columns:
table.Columns.AddNew(); table.Columns.AddNew(index);
break; break;
case TablePropertyNames.CheckConstraints: case TablePropertyNames.CheckConstraints:
table.CheckConstraints.AddNew(); table.CheckConstraints.AddNew();
@@ -243,11 +247,12 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
break; break;
} }
} }
else if (path.Length == 3) else if (path.Length == 4)
{ {
var propertyNameL1 = path[0] as string; var propertyNameL1 = path[0] as string;
var indexL1 = Convert.ToInt32(path[1]); var indexL1 = Convert.ToInt32(path[1]);
var propertyNameL2 = path[2] as string; var propertyNameL2 = path[2] as string;
var indexL2 = Convert.ToInt32(path[3]);
switch (propertyNameL1) switch (propertyNameL1)
{ {
case TablePropertyNames.ForeignKeys: case TablePropertyNames.ForeignKeys:
@@ -691,6 +696,27 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
return refreshView; 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) private int GetInt32Value(object value)
{ {
return Int32.Parse(value as string); return Int32.Parse(value as string);
@@ -982,6 +1008,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
}); });
view.ColumnTableOptions.CanAddRows = true; view.ColumnTableOptions.CanAddRows = true;
view.ColumnTableOptions.CanRemoveRows = true; view.ColumnTableOptions.CanRemoveRows = true;
view.ColumnTableOptions.CanMoveRows = true;
view.ColumnTableOptions.CanInsertRows = true;
view.ColumnTableOptions.RemoveRowConfirmationMessage = SR.TableDesignerDeleteColumnConfirmationMessage; view.ColumnTableOptions.RemoveRowConfirmationMessage = SR.TableDesignerDeleteColumnConfirmationMessage;
view.ColumnTableOptions.ShowRemoveRowConfirmation = true; view.ColumnTableOptions.ShowRemoveRowConfirmation = true;
} }
@@ -1012,6 +1040,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
}); });
view.ForeignKeyTableOptions.CanAddRows = true; view.ForeignKeyTableOptions.CanAddRows = true;
view.ForeignKeyTableOptions.CanRemoveRows = true; view.ForeignKeyTableOptions.CanRemoveRows = true;
view.ForeignKeyTableOptions.CanMoveRows = false;
view.ForeignKeyTableOptions.CanInsertRows = false;
} }
private void SetCheckConstraintsViewInfo(TableDesignerView view) private void SetCheckConstraintsViewInfo(TableDesignerView view)
@@ -1029,6 +1059,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
}); });
view.CheckConstraintTableOptions.CanAddRows = true; view.CheckConstraintTableOptions.CanAddRows = true;
view.CheckConstraintTableOptions.CanRemoveRows = true; view.CheckConstraintTableOptions.CanRemoveRows = true;
view.CheckConstraintTableOptions.CanMoveRows = false;
view.CheckConstraintTableOptions.CanInsertRows = false;
} }
private void SetIndexesViewInfo(TableDesignerView view) private void SetIndexesViewInfo(TableDesignerView view)
@@ -1079,6 +1111,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
view.IndexTableOptions.PropertiesToDisplay = new List<string>() { IndexPropertyNames.Name, IndexPropertyNames.ColumnsDisplayValue, IndexPropertyNames.IsClustered, IndexPropertyNames.IsUnique }; view.IndexTableOptions.PropertiesToDisplay = new List<string>() { IndexPropertyNames.Name, IndexPropertyNames.ColumnsDisplayValue, IndexPropertyNames.IsClustered, IndexPropertyNames.IsUnique };
view.IndexTableOptions.CanAddRows = true; view.IndexTableOptions.CanAddRows = true;
view.IndexTableOptions.CanRemoveRows = true; view.IndexTableOptions.CanRemoveRows = true;
view.IndexTableOptions.CanMoveRows = false;
view.IndexTableOptions.CanInsertRows = false;
view.IndexColumnSpecificationTableOptions.AdditionalProperties.Add( view.IndexColumnSpecificationTableOptions.AdditionalProperties.Add(
new DesignerDataPropertyInfo() new DesignerDataPropertyInfo()
@@ -1094,6 +1128,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
view.IndexColumnSpecificationTableOptions.PropertiesToDisplay.AddRange(new string[] { IndexColumnSpecificationPropertyNames.Column, IndexColumnSpecificationPropertyNames.Ascending }); view.IndexColumnSpecificationTableOptions.PropertiesToDisplay.AddRange(new string[] { IndexColumnSpecificationPropertyNames.Column, IndexColumnSpecificationPropertyNames.Ascending });
view.IndexColumnSpecificationTableOptions.CanAddRows = true; view.IndexColumnSpecificationTableOptions.CanAddRows = true;
view.IndexColumnSpecificationTableOptions.CanRemoveRows = true; view.IndexColumnSpecificationTableOptions.CanRemoveRows = true;
view.IndexColumnSpecificationTableOptions.CanMoveRows = false;
view.IndexColumnSpecificationTableOptions.CanInsertRows = false;
} }
private void SetGraphTableViewInfo(TableDesignerView view, Dac.TableDesigner tableDesigner) private void SetGraphTableViewInfo(TableDesignerView view, Dac.TableDesigner tableDesigner)

View File

@@ -16,11 +16,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner
public void ParseDesignerPathTest() public void ParseDesignerPathTest()
{ {
DesignerEditType editType = DesignerEditType.Add; DesignerEditType editType = DesignerEditType.Add;
this.RunTest(new object[] { "property1" }, editType, true); this.RunTest(new object[] { "property1" }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2" }, editType, true); this.RunTest(new object[] { "property1", 1, "property2" }, editType, false);
this.RunTest(new object[] { "property1", "xx", "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 }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, false); 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[] { "property1", 1, "property2", 1, "property3" }, editType, false);
this.RunTest(new object[] { }, editType, false); this.RunTest(new object[] { }, editType, false);
this.RunTest(null, editType, false); this.RunTest(null, editType, false);