From 71830ee5f9a64fed1fc5b80b83f86a91ebfb85f8 Mon Sep 17 00:00:00 2001 From: Hai Cao Date: Fri, 8 Apr 2022 11:42:55 -0700 Subject: [PATCH] A few table designer improvements (#1456) * add AdvancedType related contract & lib call * use type list from col * add description support to all view models * remove desc for edge constraint * bump DacFx to 160.6093.0-preview * nit --- Packages.props | 2 +- .../TableDesigner/Constants.cs | 6 ++++ .../ViewModel/ObjectViewModelBase.cs | 1 + .../ViewModel/TableColumnViewModel.cs | 1 + .../Contracts/ViewModel/TableViewModel.cs | 3 +- .../TableDesigner/TableDesignerService.cs | 36 +++++++++++++++++++ 6 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Packages.props b/Packages.props index 4c4d50c1..4c8abb5a 100644 --- a/Packages.props +++ b/Packages.props @@ -21,7 +21,7 @@ - + diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs index 13895295..f461f768 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Constants.cs @@ -23,6 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner public const string IsMemoryOptimized = "isMemoryOptimized"; public const string Durability = "durability"; public const string PrimaryKeyName = "primaryKeyName"; + public const string PrimaryKeyDescription = "primaryKeyDescription"; public const string PrimaryKeyIsClustered = "primaryKeyIsClustered"; public const string PrimaryKeyColumns = "primaryKeyColumns"; } @@ -30,6 +31,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner public static class TableColumnPropertyNames { public const string Name = "name"; + public const string Description = "description"; + public const string AdvancedType = "advancedType"; public const string Type = "type"; public const string DefaultValue = "defaultValue"; public const string Length = "length"; @@ -49,6 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner public static class ForeignKeyPropertyNames { public const string Name = "name"; + public const string Description = "description"; public const string Enabled = "enabled"; public const string OnDeleteAction = "onDeleteAction"; public const string OnUpdateAction = "onUpdateAction"; @@ -60,6 +64,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner public static class CheckConstraintPropertyNames { public const string Name = "name"; + public const string Description = "description"; public const string Enabled = "enabled"; public const string Expression = "expression"; } @@ -73,6 +78,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner public static class IndexPropertyNames { public const string Name = "name"; + public const string Description = "description"; public const string Enabled = "enabled"; public const string IsUnique = "isUnique"; public const string IsClustered = "isClustered"; diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/ObjectViewModelBase.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/ObjectViewModelBase.cs index c31092c5..85b4f770 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/ObjectViewModelBase.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/ObjectViewModelBase.cs @@ -11,5 +11,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts public abstract class ObjectViewModelBase { public InputBoxProperties Name { get; set; } = new InputBoxProperties(); + public InputBoxProperties Description { get; set; } = new InputBoxProperties(); } } \ 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 abff3983..d2511c7c 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableColumnViewModel.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableColumnViewModel.cs @@ -10,6 +10,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts /// public class TableColumnViewModel : ObjectViewModelBase { + public DropdownProperties AdvancedType { get; set; } = new DropdownProperties(); public DropdownProperties Type { get; set; } = new DropdownProperties(); public InputBoxProperties Length { get; set; } = new InputBoxProperties(); diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableViewModel.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableViewModel.cs index 8ae54036..8bfc6558 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableViewModel.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/Contracts/ViewModel/TableViewModel.cs @@ -12,8 +12,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts { public DropdownProperties Schema { get; set; } = new DropdownProperties(); - public InputBoxProperties Description { get; set; } = new InputBoxProperties(); - public DropdownProperties GraphTableType { get; set; } = new DropdownProperties(); public CheckBoxProperties IsMemoryOptimized { get; set; } = new CheckBoxProperties(); @@ -29,6 +27,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts public InputBoxProperties NewHistoryTableName { get; set; } = new InputBoxProperties(); public InputBoxProperties PrimaryKeyName { get; set; } = new InputBoxProperties(); + public InputBoxProperties PrimaryKeyDescription { get; set; } = new InputBoxProperties(); public CheckBoxProperties PrimaryKeyIsClustered { get; set; } = new CheckBoxProperties(); diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index 6f2d170b..66d3baeb 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -409,6 +409,12 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner table.PrimaryKey.Name = GetStringValue(newValue); } break; + case TablePropertyNames.PrimaryKeyDescription: + if (table.PrimaryKey != null) + { + table.PrimaryKey.Description = GetStringValue(newValue); + } + break; case TablePropertyNames.PrimaryKeyIsClustered: if (table.PrimaryKey != null) { @@ -463,6 +469,12 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner case TableColumnPropertyNames.Type: column.DataType = GetStringValue(newValue); break; + case TableColumnPropertyNames.AdvancedType: + column.AdvancedDataType = GetStringValue(newValue); + break; + case TableColumnPropertyNames.Description: + column.Description = GetStringValue(newValue); + break; case TableColumnPropertyNames.GeneratedAlwaysAs: column.GeneratedAlwaysAs = ColumnGeneratedAlwaysAsTypeUtil.Instance.GetValue(GetStringValue(newValue)); break; @@ -483,6 +495,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner case CheckConstraintPropertyNames.Name: checkConstraint.Name = GetStringValue(newValue); break; + case CheckConstraintPropertyNames.Description: + checkConstraint.Description = GetStringValue(newValue); + break; case CheckConstraintPropertyNames.Enabled: checkConstraint.Enabled = GetBooleanValue(newValue); break; @@ -506,6 +521,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner case ForeignKeyPropertyNames.Name: foreignKey.Name = GetStringValue(newValue); break; + case ForeignKeyPropertyNames.Description: + foreignKey.Description = GetStringValue(newValue); + break; case ForeignKeyPropertyNames.OnDeleteAction: foreignKey.OnDeleteAction = SqlForeignKeyActionUtil.Instance.GetValue(GetStringValue(newValue)); break; @@ -535,6 +553,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner case IndexPropertyNames.Name: sqlIndex.Name = GetStringValue(newValue); break; + case IndexPropertyNames.Description: + sqlIndex.Description = GetStringValue(newValue); + break; default: break; } @@ -682,6 +703,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner if (primaryKey != null) { tableViewModel.PrimaryKeyName.Value = primaryKey.Name; + tableViewModel.PrimaryKeyDescription.Value = primaryKey.Description; + tableViewModel.PrimaryKeyDescription.Enabled = primaryKey.CanEditDescription; tableViewModel.PrimaryKeyIsClustered.Checked = primaryKey.IsClustered; foreach (var cs in primaryKey.Columns) { @@ -722,6 +745,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner var columnViewModel = new TableColumnViewModel(); columnViewModel.Name.Value = column.Name; columnViewModel.Name.Enabled = column.CanEditName; + columnViewModel.Description.Value = column.Description; + columnViewModel.Description.Enabled = column.CanEditDescription; columnViewModel.Length.Value = column.Length; columnViewModel.Length.Enabled = column.CanEditLength; columnViewModel.Scale.Value = column.Scale?.ToString(); @@ -737,6 +762,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner columnViewModel.Type.Value = column.DataType; columnViewModel.Type.Enabled = column.CanEditDataType; columnViewModel.Type.Values = tableDesigner.DataTypes.ToList(); + columnViewModel.AdvancedType.Value = column.AdvancedDataType; + columnViewModel.AdvancedType.Enabled = column.CanEditDataType; + columnViewModel.AdvancedType.Values = column.AdvancedDataTypes.ToList(); columnViewModel.IsIdentity.Enabled = column.CanEditIsIdentity; columnViewModel.IsIdentity.Checked = column.IsIdentity; columnViewModel.IdentitySeed.Enabled = column.CanEditIdentityValues; @@ -758,6 +786,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner { var foreignKeyViewModel = new ForeignKeyViewModel(); foreignKeyViewModel.Name.Value = foreignKey.Name; + foreignKeyViewModel.Description.Value = foreignKey.Description; + foreignKeyViewModel.Description.Enabled = foreignKey.CanEditDescription; foreignKeyViewModel.Enabled.Checked = foreignKey.Enabled; foreignKeyViewModel.OnDeleteAction.Value = SqlForeignKeyActionUtil.Instance.GetName(foreignKey.OnDeleteAction); foreignKeyViewModel.OnDeleteAction.Values = SqlForeignKeyActionUtil.Instance.DisplayNames; @@ -784,6 +814,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner { var constraint = new CheckConstraintViewModel(); constraint.Name.Value = checkConstraint.Name; + constraint.Description.Value = checkConstraint.Description; + constraint.Description.Enabled = checkConstraint.CanEditDescription; constraint.Expression.Value = checkConstraint.Expression; constraint.Enabled.Checked = checkConstraint.Enabled; tableViewModel.CheckConstraints.Data.Add(constraint); @@ -794,6 +826,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner var indexVM = new IndexViewModel(); indexVM.Name.Value = index.Name; indexVM.Name.Enabled = tableInfo.IsNewTable; // renaming an index is not supported, it will cause a new index to be created. + indexVM.Description.Value = index.Description; + indexVM.Description.Enabled = index.CanEditDescription; indexVM.IsClustered.Checked = index.IsClustered; indexVM.Enabled.Checked = index.Enabled; indexVM.IsUnique.Checked = index.IsUnique; @@ -814,6 +848,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner { var constraintVM = new EdgeConstraintViewModel(); constraintVM.Name.Value = constraint.Name; + constraintVM.Description.Value = constraint.Description; + constraintVM.Description.Enabled = constraint.CanEditDescription; constraintVM.Enabled.Checked = constraint.Enabled; constraintVM.OnDeleteAction.Value = SqlForeignKeyActionUtil.Instance.GetName(constraint.OnDeleteAction); constraintVM.OnDeleteAction.Values = SqlForeignKeyActionUtil.Instance.EdgeConstraintOnDeleteActionNames;