diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index 2856a518..2e543415 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -8445,6 +8445,70 @@ namespace Microsoft.SqlTools.ServiceLayer } } + public static string TableEditPathNotProvidedException + { + get + { + return Keys.GetString(Keys.TableEditPathNotProvidedException); + } + } + + public static string TableColumnIdentityGroupName + { + get + { + return Keys.GetString(Keys.TableColumnIdentityGroupName); + } + } + + public static string TableColumnIsIdentityPropertyTitle + { + get + { + return Keys.GetString(Keys.TableColumnIsIdentityPropertyTitle); + } + } + + public static string TableColumnIsIdentityPropertyDescription + { + get + { + return Keys.GetString(Keys.TableColumnIsIdentityPropertyDescription); + } + } + + public static string TableColumnIdentityIncrementPropertyTitle + { + get + { + return Keys.GetString(Keys.TableColumnIdentityIncrementPropertyTitle); + } + } + + public static string TableColumnIdentityIncrementPropertyDescription + { + get + { + return Keys.GetString(Keys.TableColumnIdentityIncrementPropertyDescription); + } + } + + public static string TableColumnIdentitySeedPropertyTitle + { + get + { + return Keys.GetString(Keys.TableColumnIdentitySeedPropertyTitle); + } + } + + public static string TableColumnIdentitySeedPropertyDescription + { + get + { + return Keys.GetString(Keys.TableColumnIdentitySeedPropertyDescription); + } + } + public static string ConnectionServiceListDbErrorNotConnected(string uri) { return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, uri); @@ -8710,6 +8774,16 @@ namespace Microsoft.SqlTools.ServiceLayer return Keys.GetString(Keys.NameValuePair, name, value); } + public static string TableNotInitializedException(string tableId) + { + return Keys.GetString(Keys.TableNotInitializedException, tableId); + } + + public static string InvalidTableEditPathException(string path, string editType) + { + return Keys.GetString(Keys.InvalidTableEditPathException, path, editType); + } + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Keys { @@ -12033,6 +12107,36 @@ namespace Microsoft.SqlTools.ServiceLayer public const string SizeInTeraBytesFormat = "SizeInTeraBytesFormat"; + public const string TableNotInitializedException = "TableNotInitializedException"; + + + public const string TableEditPathNotProvidedException = "TableEditPathNotProvidedException"; + + + public const string InvalidTableEditPathException = "InvalidTableEditPathException"; + + + public const string TableColumnIdentityGroupName = "TableColumnIdentityGroupName"; + + + public const string TableColumnIsIdentityPropertyTitle = "TableColumnIsIdentityPropertyTitle"; + + + public const string TableColumnIsIdentityPropertyDescription = "TableColumnIsIdentityPropertyDescription"; + + + public const string TableColumnIdentityIncrementPropertyTitle = "TableColumnIdentityIncrementPropertyTitle"; + + + public const string TableColumnIdentityIncrementPropertyDescription = "TableColumnIdentityIncrementPropertyDescription"; + + + public const string TableColumnIdentitySeedPropertyTitle = "TableColumnIdentitySeedPropertyTitle"; + + + public const string TableColumnIdentitySeedPropertyDescription = "TableColumnIdentitySeedPropertyDescription"; + + private Keys() { } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index 42f4edbf..66505671 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -4590,4 +4590,46 @@ {0} TB Size in TeraBytes format + + Initialization is not properly done for table with id '{0}' + . + Parameters: 0 - tableId (string) + + + The path in the table change information cannot be empty + + + + The path '{0}' in the table change information is not valid for edit type: '{1}' + . + Parameters: 0 - path (string), 1 - editType (string) + + + Identity Specification + + + + Is Identity + + + + Specifies whether the column is the identity column for the table. + + + + Identity Increment + + + + Displays the value added to the maximum existing row identity value when generating the next identity value. + + + + Identity Seed + + + + Displays the initial row value for an identity column. + + diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index 616fb167..79ad96ea 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -2212,4 +2212,18 @@ SizeInMegaBytesFormat = {0} MB ;Size in GigaBytes format SizeInGigaBytesFormat = {0} GB ;Size in TeraBytes format -SizeInTeraBytesFormat = {0} TB \ No newline at end of file +SizeInTeraBytesFormat = {0} TB + +############################################################################ +# Table Designer + +TableNotInitializedException(string tableId) = Initialization is not properly done for table with id '{0}' +TableEditPathNotProvidedException = The path in the table change information cannot be empty +InvalidTableEditPathException(string path, string editType) = The path '{0}' in the table change information is not valid for edit type: '{1}' +TableColumnIdentityGroupName = Identity Specification +TableColumnIsIdentityPropertyTitle = Is Identity +TableColumnIsIdentityPropertyDescription = Specifies whether the column is the identity column for the table. +TableColumnIdentityIncrementPropertyTitle = Identity Increment +TableColumnIdentityIncrementPropertyDescription = Displays the value added to the maximum existing row identity value when generating the next identity value. +TableColumnIdentitySeedPropertyTitle = Identity Seed +TableColumnIdentitySeedPropertyDescription = Displays the initial row value for an identity column. diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index a5644bdf..af360256 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -5579,6 +5579,58 @@ {0} TB Size in TeraBytes format + + Initialization is not properly done for table with id '{0}' + Initialization is not properly done for table with id '{0}' + . + Parameters: 0 - tableId (string) + + + Identity Specification + Identity Specification + + + + Is Identity + Is Identity + + + + Specifies whether the column is the identity column for the table. + Specifies whether the column is the identity column for the table. + + + + Identity Increment + Identity Increment + + + + Displays the value added to the maximum existing row identity value when generating the next identity value. + Displays the value added to the maximum existing row identity value when generating the next identity value. + + + + Identity Seed + Identity Seed + + + + Displays the initial row value for an identity column. + Displays the initial row value for an identity column. + + + + The path in the table change information cannot be empty + The path in the table change information cannot be empty + + + + The path '{0}' in the table change information is not valid for edit type: '{1}' + The path '{0}' in the table change information is not valid for edit type: '{1}' + . + Parameters: 0 - path (string), 1 - editType (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs index 8459ae3f..b1267acb 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs @@ -3,12 +3,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using System; -using System.Threading.Tasks; -using Microsoft.SqlTools.Hosting.Protocol; -using Microsoft.SqlTools.ServiceLayer.Hosting; -using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts; - namespace Microsoft.SqlTools.ServiceLayer.TableDesigner { public static class TablePropertyNames @@ -29,5 +23,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner public const string IsPrimaryKey = "isPrimaryKey"; public const string Precision = "precision"; public const string Scale = "scale"; + public const string IsIdentity = "isIdentity"; + public const string IdentityIncrement = "identityIncrement"; + public const string IdentitySeed = "identitySeed"; } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/DesignerDataPropertyInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/DesignerDataPropertyInfo.cs index d51225ca..3ca91355 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/DesignerDataPropertyInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/DesignerDataPropertyInfo.cs @@ -3,6 +3,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts { /// @@ -23,17 +27,35 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts /// /// The component type of the property /// - public string ComponentType { get; set; } + public DesignerComponentType ComponentType { get; set; } /// /// The name of the group the property will be placed in whe displayed in /// public string Group { get; set; } + /// + /// The name of the group the property will be placed in whe displayed in + /// + public bool ShowInPropertiesView { get; set; } + /// /// The properties of component /// public ComponentPropertiesBase ComponentProperties { get; set; } } + + [JsonConverter(typeof(StringEnumConverter))] + public enum DesignerComponentType + { + [EnumMember(Value = "checkbox")] + Checkbox, + [EnumMember(Value = "dropdown")] + Dropdown, + [EnumMember(Value = "input")] + Input, + [EnumMember(Value = "table")] + Table + } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableChangeInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableChangeInfo.cs index 6818953e..8e901713 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableChangeInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableChangeInfo.cs @@ -28,41 +28,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts { public DesignerEditType Type { get; set; } - [JsonConverter(typeof(TableDesignerPropertyConverter))] - public object Property { get; set; } + public object[] Path { get; set; } public object Value { get; set; } } - - /// - /// The property "Property" of TableDesignerChangeInfo could be string or TableDesignerPropertyIdentifier, use this custom converter to set the property value. - /// - public class TableDesignerPropertyConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - { - return true; - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - object property; - if (reader.TokenType == JsonToken.StartObject) - { - TableDesignerPropertyIdentifier obj = serializer.Deserialize(reader, typeof(TableDesignerPropertyIdentifier)) as TableDesignerPropertyIdentifier; - property = obj; - } - else - { - property = reader.Value; - } - return property; - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - // We don't need to serialize this class. - throw new NotImplementedException(); - } - } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerPropertyIdentifier.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerPropertyIdentifier.cs deleted file mode 100644 index 62c7a923..00000000 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerPropertyIdentifier.cs +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts -{ - /// - /// The information that can identify a property in a collection. - /// - public class TableDesignerPropertyIdentifier - { - public string ParentProperty { get; set; } - - public int Index { get; set; } - - public string Property { get; set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs index 44ae65ab..202b2a85 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/TableDesignerView.cs @@ -3,6 +3,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System.Collections.Generic; + namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts { /// @@ -11,8 +13,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts /// public class TableDesignerView { - public DesignerDataPropertyInfo[] AdditionalTableProperties { get; set; } + public List AdditionalTableProperties { get; set; } = new List(); - public DesignerDataPropertyInfo[] AdditionalTableColumnProperties { get; set; } + public List AdditionalTableColumnProperties { get; set; } = new List(); + + public List ColumnsTableProperties { get; set; } = new List(); + + public bool CanAddColumns { get; set; } + + public bool CanRemoveColumns { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableColumnViewModel.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableColumnViewModel.cs index c5e35e68..b8b38753 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableColumnViewModel.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableColumnViewModel.cs @@ -25,5 +25,11 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts public InputBoxProperties DefaultValue { get; set; } = new InputBoxProperties(); public CheckBoxProperties IsPrimaryKey { get; set; } = new CheckBoxProperties(); + + public CheckBoxProperties IsIdentity { get; set; } = new CheckBoxProperties(); + + public InputBoxProperties IdentitySeed { get; set; } = new InputBoxProperties(); + + public InputBoxProperties IdentityIncrement { get; set; } = new InputBoxProperties(); } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/DesignerPathUtils.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/DesignerPathUtils.cs new file mode 100644 index 00000000..4a193be5 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/DesignerPathUtils.cs @@ -0,0 +1,80 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Collections; +using System.Linq; +using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts; + +namespace Microsoft.SqlTools.ServiceLayer.TableDesigner +{ + public static class DesignerPathUtils + { + /// + /// 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. + /// 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']. + /// 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']. + /// 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]. + /// + public static void Validate(object[] path, DesignerEditType editType) + { + if (path == null || path.Length == 0) + { + throw new ArgumentException(SR.TableEditPathNotProvidedException); + } + + // Length validation + int[] validLengthList; + if (editType == DesignerEditType.Add) + { + validLengthList = new int[] { 1, 3 }; + } + else if (editType == DesignerEditType.Update) + { + validLengthList = new int[] { 1, 3, 5 }; + } + else + { + validLengthList = new int[] { 2, 4 }; + } + + bool isValid = validLengthList.ToList().Contains(path.Length); + if (isValid) + { + for (int i = 0; i < path.Length; i++) + { + // On odd number positions, the value must be a number. + if (i % 2 != 0) + { + int val; + isValid = Int32.TryParse(path[i]?.ToString(), out val); + } + else + { + isValid = path[i] is string; + } + if (!isValid) + { + break; + } + } + } + + if (!isValid) + { + throw new ArgumentException(SR.InvalidTableEditPathException(string.Join(',', path), editType.ToString())); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index 69f81086..fa15860d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -57,102 +57,92 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner this.ServiceHost.SetRequestHandler(SaveTableChangesRequest.Type, HandleSaveTableChangesRequest); this.ServiceHost.SetRequestHandler(DisposeTableDesignerRequest.Type, HandleDisposeTableDesignerRequest); } - - private async Task HandleGetTableDesignerInfoRequest(TableInfo tableInfo, RequestContext requestContext) + private Task HandleRequest(RequestContext requestContext, Func action) { - await Task.Run(async () => - { - try - { - var schemas = this.GetSchemas(tableInfo); - var viewModel = this.GetTableViewModel(tableInfo, schemas); - var view = this.GetDesignerViewInfo(tableInfo); - await requestContext.SendResult(new TableDesignerInfo() - { - ViewModel = viewModel, - View = view, - ColumnTypes = this.GetSupportedColumnTypes(tableInfo), - Schemas = schemas - }); - } - catch (Exception e) - { - await requestContext.SendError(e); - } - }); + // The request handling will take some time to return, we need to use a separate task to run the request handler so that it won't block the main thread. + // For any specific table designer instance, ADS UI can make sure there are at most one request being processed at any given time, so we don't have to worry about race conditions. + Task.Run(async () => + { + try + { + await action(); + } + catch (Exception e) + { + await requestContext.SendError(e); + } + }); + return Task.CompletedTask; } - private async Task HandleProcessTableDesignerEditRequest(ProcessTableDesignerEditRequestParams requestParams, RequestContext requestContext) + private Task HandleGetTableDesignerInfoRequest(TableInfo tableInfo, RequestContext requestContext) { - await Task.Run(async () => - { - try - { - switch (requestParams.TableChangeInfo.Type) - { - case DesignerEditType.Add: - this.HandleAddItemRequest(requestParams); - break; - case DesignerEditType.Remove: - // TODO: Handle 'Remove' request - break; - default: - // TODO: Handle 'Update' request - break; - } - await requestContext.SendResult(new ProcessTableDesignerEditResponse() - { - ViewModel = requestParams.ViewModel, - IsValid = true - }); - } - catch (Exception e) - { - await requestContext.SendError(e); - } - }); + return this.HandleRequest(requestContext, async () => + { + var schemas = this.GetSchemas(tableInfo); + var viewModel = this.GetTableViewModel(tableInfo, schemas); + var view = this.GetDesignerViewInfo(tableInfo); + await requestContext.SendResult(new TableDesignerInfo() + { + ViewModel = viewModel, + View = view, + ColumnTypes = this.GetSupportedColumnTypes(tableInfo), + Schemas = schemas + }); + }); } - private async Task HandleSaveTableChangesRequest(SaveTableChangesRequestParams requestParams, RequestContext requestContext) + private Task HandleProcessTableDesignerEditRequest(ProcessTableDesignerEditRequestParams requestParams, RequestContext requestContext) { - await Task.Run(async () => - { - try - { - // TODO: Handle the save changes request. - await requestContext.SendResult(new SaveTableChangesResponse()); - } - catch (Exception e) - { - await requestContext.SendError(e); - } - }); + return this.HandleRequest(requestContext, async () => + { + DesignerPathUtils.Validate(requestParams.TableChangeInfo.Path, requestParams.TableChangeInfo.Type); + switch (requestParams.TableChangeInfo.Type) + { + case DesignerEditType.Add: + this.HandleAddItemRequest(requestParams); + break; + case DesignerEditType.Remove: + this.HandleRemoveItemRequest(requestParams); + break; + default: + // TODO: Handle 'Update' request + break; + } + await requestContext.SendResult(new ProcessTableDesignerEditResponse() + { + ViewModel = requestParams.ViewModel, + IsValid = true + }); + }); + } + + private Task HandleSaveTableChangesRequest(SaveTableChangesRequestParams requestParams, RequestContext requestContext) + { + return this.HandleRequest(requestContext, async () => + { + // TODO: Handle the save changes request. + await requestContext.SendResult(new SaveTableChangesResponse()); + }); } - private async Task HandleDisposeTableDesignerRequest(TableInfo tableInfo, RequestContext requestContext) + private Task HandleDisposeTableDesignerRequest(TableInfo tableInfo, RequestContext requestContext) { - await Task.Run(async () => - { - try - { - // TODO: Handle the dispose table designer request. - await requestContext.SendResult(new DisposeTableDesignerResponse()); - } - catch (Exception e) - { - await requestContext.SendError(e); - } - }); + return this.HandleRequest(requestContext, async () => + { + // TODO: Handle the save changes request. + await requestContext.SendResult(new DisposeTableDesignerResponse()); + }); } private void HandleAddItemRequest(ProcessTableDesignerEditRequestParams requestParams) { - var property = requestParams.TableChangeInfo.Property; + var path = requestParams.TableChangeInfo.Path; // Handle the add item request on top level table properties, e.g. Columns, Indexes. - if (property.GetType() == typeof(string)) + if (path.Length == 1) { - string propertyName = property as string; + var propertyName = path[0] as string; switch (propertyName) { case TablePropertyNames.Columns: @@ -168,6 +158,28 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner } } + private void HandleRemoveItemRequest(ProcessTableDesignerEditRequestParams requestParams) + { + var path = requestParams.TableChangeInfo.Path; + // Handle the add item request on top level table properties, e.g. Columns, Indexes. + if (path.Length == 2) + { + var propertyName = path[0] as string; + switch (propertyName) + { + case TablePropertyNames.Columns: + requestParams.ViewModel.Columns.Data.RemoveAt(Convert.ToInt32(path[1])); + break; + default: + break; + } + } + else + { + // TODO: Handle the add item request on second level properties, e.g. Adding a column to an index + } + } + private List GetSupportedColumnTypes(TableInfo tableInfo) { //TODO: get the supported column types. @@ -200,8 +212,42 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner private TableDesignerView GetDesignerViewInfo(TableInfo tableInfo) { - // TODO: set the view information var view = new TableDesignerView(); + view.AdditionalTableColumnProperties.Add(new DesignerDataPropertyInfo() + { + PropertyName = TableColumnPropertyNames.IsIdentity, + Description = SR.TableColumnIsIdentityPropertyDescription, + Group = SR.TableColumnIdentityGroupName, + ComponentType = DesignerComponentType.Checkbox, + ComponentProperties = new CheckBoxProperties() + { + Title = SR.TableColumnIsIdentityPropertyTitle + } + }); + view.AdditionalTableColumnProperties.Add(new DesignerDataPropertyInfo() + { + PropertyName = TableColumnPropertyNames.IdentitySeed, + Description = SR.TableColumnIdentitySeedPropertyDescription, + Group = SR.TableColumnIdentityGroupName, + ComponentType = DesignerComponentType.Input, + ComponentProperties = new InputBoxProperties() + { + Title = SR.TableColumnIdentitySeedPropertyTitle + } + }); + view.AdditionalTableColumnProperties.Add(new DesignerDataPropertyInfo() + { + PropertyName = TableColumnPropertyNames.IdentityIncrement, + Description = SR.TableColumnIdentityIncrementPropertyDescription, + Group = SR.TableColumnIdentityGroupName, + ComponentType = DesignerComponentType.Input, + ComponentProperties = new InputBoxProperties() + { + Title = SR.TableColumnIdentityIncrementPropertyTitle + } + }); + view.CanAddColumns = true; + view.CanRemoveColumns = true; return view; } diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/DesignerPathUtilsTest.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/DesignerPathUtilsTest.cs new file mode 100644 index 00000000..6a3ee936 --- /dev/null +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/DesignerPathUtilsTest.cs @@ -0,0 +1,66 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using Microsoft.SqlTools.ServiceLayer.TableDesigner; +using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts; +using NUnit.Framework; + +namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner +{ + public class DesignerPathUtilsTest + { + [Test] + 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", "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, "property2", 1, "property3" }, editType, false); + this.RunTest(new object[] { }, editType, false); + this.RunTest(null, editType, false); + + editType = DesignerEditType.Remove; + this.RunTest(new object[] { "property1", 0 }, editType, true); + this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, true); + this.RunTest(new object[] { "property1" }, editType, false); + this.RunTest(new object[] { "property1", 1, "property2" }, editType, false); + this.RunTest(new object[] { "property1", 1, "property2", 1, "property3", 1 }, editType, false); + this.RunTest(new object[] { }, editType, false); + this.RunTest(null, editType, false); + + editType = DesignerEditType.Update; + this.RunTest(new object[] { "property1" }, editType, true); + this.RunTest(new object[] { "property1", 1, "property2" }, editType, true); + this.RunTest(new object[] { "property1", 1, "property2", 1, "property3" }, editType, true); + this.RunTest(new object[] { "property1", "abc" }, editType, false); + this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, false); + this.RunTest(new object[] { "property1", 1, "property2", 1, "property3", 2, "property4" }, editType, false); + this.RunTest(new object[] { }, editType, false); + this.RunTest(null, editType, false); + } + + private void RunTest(object[] path, DesignerEditType editType, bool isValidPath) + { + if (isValidPath) + { + Assert.DoesNotThrow(() => + { + DesignerPathUtils.Validate(path, editType); + }, string.Format("Path '{0}' should be a valid path for edit type: '{1}'.", path, editType.ToString())); + } + else + { + Assert.Throws(() => + { + DesignerPathUtils.Validate(path, editType); + }, string.Format("Path '{0}' should not be a valid path for edit type: '{1}'.", path, editType.ToString())); + } + } + } +} diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/TableDesignerChangeInfoTest.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/TableDesignerChangeInfoTest.cs deleted file mode 100644 index c7a79d7a..00000000 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/TableDesigner/TableDesignerChangeInfoTest.cs +++ /dev/null @@ -1,30 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -using System; -using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts; -using NUnit.Framework; -using Newtonsoft.Json; - -namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner -{ - public class TableDesignerChangeInfoTest - { - [Test] - public void DeserializeTableChangeProperty() - { - string testJsonStringType = "{\"type\": 1, \"property\": \"columns\"}"; - TableDesignerChangeInfo changeInfo = JsonConvert.DeserializeObject(testJsonStringType); - Assert.IsNotNull(changeInfo, "string property: the changeInfo shouldn't be null."); - Assert.IsNotNull(changeInfo.Property, "string property: the property shouldn't be null."); - Assert.IsTrue(changeInfo.Property.GetType() == typeof(string)); - string testJsonObjectType = "{\"type\": 1, \"property\": {\"parentProperty\": \"columns\",\"index\": 0,\"property\": \"length\"}}"; - changeInfo = JsonConvert.DeserializeObject(testJsonObjectType); - Assert.IsNotNull(changeInfo, "object property: the changeInfo shouldn't be null."); - Assert.IsNotNull(changeInfo.Property, "object property: the property shouldn't be null."); - Assert.IsTrue(changeInfo.Property.GetType() == typeof(TableDesignerPropertyIdentifier)); - } - } -}