mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
[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:
@@ -22,7 +22,7 @@
|
||||
<PackageReference Update="Microsoft.Data.SqlClient" Version="3.1.0"/>
|
||||
<PackageReference Update="Microsoft.SqlServer.SqlManagementObjects" 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.Language" Version="9.0.4"/>
|
||||
<PackageReference Update="Microsoft.SqlServer.Assessment" Version="[1.0.305]" />
|
||||
|
||||
@@ -41,6 +41,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
/// </summary>
|
||||
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>
|
||||
/// Whether a confirmation should be shown when a row is about to be removed.
|
||||
/// </summary>
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
Remove,
|
||||
[EnumMember(Value = "Update")]
|
||||
Update,
|
||||
[EnumMember(Value = "Move")]
|
||||
Move,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
|
||||
public List<string> PropertiesToDisplay { get; set; } = new List<string>();
|
||||
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<DesignerDataPropertyInfo> AdditionalProperties { get; set; } = new List<DesignerDataPropertyInfo>();
|
||||
public string RemoveRowConfirmationMessage { get; set; }
|
||||
public bool ShowRemoveRowConfirmation { get; set; } = false;
|
||||
|
||||
@@ -14,17 +14,20 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
///<summary>
|
||||
/// 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].
|
||||
///<summary>
|
||||
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 };
|
||||
}
|
||||
|
||||
@@ -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<string>() { 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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user