Add modifiable sort priority to OE nodes (#1627)

* modifiable sort priority, dropped ledger folders sorted to the bottom

* reorganizing dropped table and view objects in OE integration test

* update to Int32
This commit is contained in:
Jordan Hays
2022-08-11 10:46:14 -07:00
committed by GitHub
parent 86346ca30a
commit 007e852f1a
6 changed files with 66 additions and 61 deletions

View File

@@ -34,8 +34,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
{ {
get get
{ {
// SMO objects are already sorted so no need to sort them again // SMO objects are already sorted so no need to sort them again, unless they have dropped folders
return this.FirstOrDefault() is SmoTreeNode; bool anyDroppedFolders = this.Any(
node => node is FolderNode &&
(node.NodeTypeId == NodeTypes.DroppedLedgerTables ||
node.NodeTypeId == NodeTypes.DroppedLedgerViews));
return this.FirstOrDefault() is SmoTreeNode && !anyDroppedFolders;
} }
} }

View File

@@ -413,23 +413,16 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
return CompareSamePriorities(this, other); return CompareSamePriorities(this, other);
} }
if (this.SortPriority.HasValue && // Higher SortPriority = lower in the list. A couple nodes are defined with SortPriority of Int16.MaxValue
!other.SortPriority.HasValue) // so they're placed at the bottom of the node list (Dropped Ledger Tables and Dropped Ledger Views folders)
{ // Individual objects, like tables and views, don't have a SortPriority defined, so their values need
return -1; // this is above other // to be resolved. If a node doesn't have a SortPriority, set it to the second-highest value.
} int thisPriority = this.SortPriority ?? Int32.MaxValue - 1;
if (!this.SortPriority.HasValue) int otherPriority = other.SortPriority ?? Int32.MaxValue - 1;
{
return 1; // this is below other
}
// Both have sort priority // diff > 0 == this below other
int priDiff = this.SortPriority.Value - other.SortPriority.Value; // diff < 0 == other below this
if (priDiff < 0) return thisPriority - otherPriority;
return -1; // this is below other
if (priDiff == 0)
return 0;
return 1;
} }
} }
} }

View File

@@ -858,7 +858,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeTypeId = NodeTypes.DroppedLedgerTables, NodeTypeId = NodeTypes.DroppedLedgerTables,
IsSystemObject = false, IsSystemObject = false,
ValidFor = ValidForFlag.Sql2022|ValidForFlag.AzureV12, ValidFor = ValidForFlag.Sql2022|ValidForFlag.AzureV12,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = Int32.MaxValue,
}); });
} }
@@ -922,7 +922,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeTypeId = NodeTypes.DroppedLedgerViews, NodeTypeId = NodeTypes.DroppedLedgerViews,
IsSystemObject = false, IsSystemObject = false,
IsMsShippedOwned = true, IsMsShippedOwned = true,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = Int32.MaxValue,
}); });
} }

View File

@@ -241,7 +241,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
WriteLine(" {"); WriteLine(" {");
foreach (var child in children) foreach (var child in children)
{ {
XmlElement childAsXmlElement = GetNodeElement(xmlFile, child.GetAttribute("Name")); var childName = child.GetAttribute("Name");
XmlElement childAsXmlElement = GetNodeElement(xmlFile, childName);
if (childAsXmlElement == null) if (childAsXmlElement == null)
{ {
// TODO SHould we error with clear message that this needs to be fixed? // TODO SHould we error with clear message that this needs to be fixed?
@@ -251,16 +253,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
var msShippedOwned = childAsXmlElement.GetAttributeNode("IsMsShippedOwned"); var msShippedOwned = childAsXmlElement.GetAttributeNode("IsMsShippedOwned");
var validFor = childAsXmlElement.GetAttribute("ValidFor"); var validFor = childAsXmlElement.GetAttribute("ValidFor");
if (TreeNodeExists(xmlFile, child.GetAttribute("Name") + "TreeNode")) var sortPriority = childAsXmlElement.GetAttribute("SortPriority");
if (sortPriority == string.Empty)
{ {
WriteLine(" currentChildren.Add(new {0}TreeNode {{ SortPriority = SmoTreeNode.NextSortPriority }} );", child.GetAttribute("Name")); sortPriority = "SmoTreeNode.NextSortPriority";
}
if (TreeNodeExists(xmlFile, childName + "TreeNode"))
{
WriteLine(" currentChildren.Add(new {0}TreeNode {{ SortPriority = {1} }} );", childName, sortPriority);
} }
else else
{ {
WriteLine(" currentChildren.Add(new FolderNode {"); WriteLine(" currentChildren.Add(new FolderNode {");
WriteLine(" NodeValue = {0},", childAsXmlElement.GetAttribute("LocLabel")); WriteLine(" NodeValue = {0},", childAsXmlElement.GetAttribute("LocLabel"));
WriteLine(" NodeType = \"{0}\",", "Folder"); WriteLine(" NodeType = \"{0}\",", "Folder");
WriteLine(" NodeTypeId = NodeTypes.{0},", child.GetAttribute("Name")); WriteLine(" NodeTypeId = NodeTypes.{0},", childName);
WriteLine(" IsSystemObject = {0},", child.GetAttribute("IsSystemObject") == "1" ? "true" : "false"); WriteLine(" IsSystemObject = {0},", child.GetAttribute("IsSystemObject") == "1" ? "true" : "false");
if (msShippedOwned != null) if (msShippedOwned != null)
@@ -271,7 +279,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
WriteLine(" ValidFor = {0},", GetValidForFlags(validFor)); WriteLine(" ValidFor = {0},", GetValidForFlags(validFor));
} }
WriteLine(" SortPriority = SmoTreeNode.NextSortPriority,"); WriteLine(" SortPriority = {0},", sortPriority);
WriteLine(" });"); WriteLine(" });");
} }
} }

View File

@@ -165,7 +165,7 @@
<Filter Property="IsSystemObject" Value="1" Type="bool" /> <Filter Property="IsSystemObject" Value="1" Type="bool" />
</Filters> </Filters>
</Node> </Node>
<Node Name="DroppedLedgerTables" LocLabel="SR.SchemaHierarchy_DroppedLedgerTables" BaseClass="ModelBased" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlTable" TreeNode="TableTreeNode" ValidFor="Sql2022|AzureV12"> <Node Name="DroppedLedgerTables" LocLabel="SR.SchemaHierarchy_DroppedLedgerTables" BaseClass="ModelBased" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlTable" TreeNode="TableTreeNode" ValidFor="Sql2022|AzureV12" SortPriority="Int32.MaxValue">
<Filters > <Filters >
<Filter Property="IsDroppedLedgerTable" Value="1" Type="bool" /> <Filter Property="IsDroppedLedgerTable" Value="1" Type="bool" />
</Filters> </Filters>
@@ -251,7 +251,7 @@
</Filters> </Filters>
</Node> </Node>
<Node Name="DroppedLedgerViews" LocLabel="SR.SchemaHierarchy_DroppedLedgerViews" BaseClass="ModelBased" IsMsShippedOwned="true" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlView" TreeNode="ViewTreeNode"> <Node Name="DroppedLedgerViews" LocLabel="SR.SchemaHierarchy_DroppedLedgerViews" BaseClass="ModelBased" IsMsShippedOwned="true" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlView" TreeNode="ViewTreeNode" SortPriority="Int32.MaxValue">
<Filters> <Filters>
<Filter Property="IsDroppedLedgerView" Value="1" Type="bool" ValidFor="Sql2022|AzureV12" /> <Filter Property="IsDroppedLedgerView" Value="1" Type="bool" ValidFor="Sql2022|AzureV12" />
</Filters> </Filters>

View File

@@ -1,21 +1,3 @@
NodeType: Table Label: HumanResources.MSSQL_DroppedLedgerTable_Ledger_For_Drop_<<NonDeterministic>> (Updatable Ledger) SubType:Ledger Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status:
NodeType: Column Label: ledger_start_transaction_id (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_start_sequence_number (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_sequence_number (bigint, null) SubType: Status:
NodeType: HistoryTable Label: HumanResources.MSSQL_DroppedLedgerHistory_Ledger_For_Drop_History_<<NonDeterministic>> (History) SubType:LedgerHistory Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status:
NodeType: Column Label: ledger_start_transaction_id (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_start_sequence_number (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_sequence_number (bigint, null) SubType: Status:
NodeType: Table Label: dbo.tableWithAllDataTypes SubType: Status: NodeType: Table Label: dbo.tableWithAllDataTypes SubType: Status:
NodeType: Column Label: cDecimal (decimal(18,5), null) SubType: Status: NodeType: Column Label: cDecimal (decimal(18,5), null) SubType: Status:
NodeType: Column Label: cNumeric (numeric(18,2), null) SubType: Status: NodeType: Column Label: cNumeric (numeric(18,2), null) SubType: Status:
@@ -178,15 +160,24 @@ NodeType: Constraint Label: DF_Person_ModifiedDate SubType: Status:
NodeType: Trigger Label: TableTrigger SubType: Status: NodeType: Trigger Label: TableTrigger SubType: Status:
NodeType: Index Label: PK_Person_BusinessEntityID (Unique, Clustered) SubType:PrimaryKey Status: NodeType: Index Label: PK_Person_BusinessEntityID (Unique, Clustered) SubType:PrimaryKey Status:
NodeType: Statistic Label: PK_Person_BusinessEntityID SubType: Status: NodeType: Statistic Label: PK_Person_BusinessEntityID SubType: Status:
NodeType: View Label: HumanResources.MSSQL_DroppedLedgerView_Ledger_For_Drop_Ledger_<<NonDeterministic>> (Ledger) SubType:Ledger Status: NodeType: Table Label: HumanResources.MSSQL_DroppedLedgerTable_Ledger_For_Drop_<<NonDeterministic>> (Updatable Ledger) SubType:Ledger Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status: NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status: NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status: NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status: NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status:
NodeType: Column Label: ledger_transaction_id (bigint, null) SubType: Status: NodeType: Column Label: ledger_start_transaction_id (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_sequence_number (bigint, null) SubType: Status: NodeType: Column Label: ledger_end_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_operation_type (int, not null) SubType: Status: NodeType: Column Label: ledger_start_sequence_number (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_operation_type_desc (nvarchar(6), not null) SubType: Status: NodeType: Column Label: ledger_end_sequence_number (bigint, null) SubType: Status:
NodeType: HistoryTable Label: HumanResources.MSSQL_DroppedLedgerHistory_Ledger_For_Drop_History_<<NonDeterministic>> (History) SubType:LedgerHistory Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status:
NodeType: Column Label: ledger_start_transaction_id (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_start_sequence_number (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_sequence_number (bigint, null) SubType: Status:
NodeType: View Label: HumanResources.Employee_Ledger_AppendOnly_Ledger (Ledger) SubType:Ledger Status: NodeType: View Label: HumanResources.Employee_Ledger_AppendOnly_Ledger (Ledger) SubType:Ledger Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status: NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status: NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
@@ -235,6 +226,15 @@ NodeType: Column Label: Suffix (nvarchar(10), null) SubType: Status:
NodeType: Column Label: JobTitle (nvarchar(50), not null) SubType: Status: NodeType: Column Label: JobTitle (nvarchar(50), not null) SubType: Status:
NodeType: Column Label: AdditionalContactInfo (AdditionalContactInfoSchemaCollection, null) SubType: Status: NodeType: Column Label: AdditionalContactInfo (AdditionalContactInfoSchemaCollection, null) SubType: Status:
NodeType: Trigger Label: ViewTrigger SubType: Status: NodeType: Trigger Label: ViewTrigger SubType: Status:
NodeType: View Label: HumanResources.MSSQL_DroppedLedgerView_Ledger_For_Drop_Ledger_<<NonDeterministic>> (Ledger) SubType:Ledger Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status:
NodeType: Column Label: ledger_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_sequence_number (bigint, null) SubType: Status:
NodeType: Column Label: ledger_operation_type (int, not null) SubType: Status:
NodeType: Column Label: ledger_operation_type_desc (nvarchar(6), not null) SubType: Status:
NodeType: Synonym Label: dbo.MyProduct SubType: Status: NodeType: Synonym Label: dbo.MyProduct SubType: Status:
NodeType: StoredProcedure Label: dbo.uspGetList SubType: Status: NodeType: StoredProcedure Label: dbo.uspGetList SubType: Status:
NodeType: StoredProcedureParameter Label: @Product (varchar, Input, No default) SubType:Input Status: NodeType: StoredProcedureParameter Label: @Product (varchar, Input, No default) SubType:Input Status: