From d6c35836ccf27efe8e3bc3ecff259bf724e6af64 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Wed, 15 Feb 2023 15:18:10 -0800 Subject: [PATCH] Adding group by schema to OE (#21941) * Adding group by schema and updating schema icon * Adding item context menu * Fixing command logic * Adding telemetry for group by and changing default config * reverting no child nodes error message * Code cleanup * Cleaning up constants * Removing unused imports * Update extensions/mssql/src/main.ts Co-authored-by: Charles Gagnon * converting to sendActionEvent * sendActionEvent * Adding telemetryViews and telemetry actions * Fixing localized string * registering context --------- Co-authored-by: Charles Gagnon --- extensions/mssql/config.json | 2 +- extensions/mssql/package.json | 31 ++++++++++ extensions/mssql/package.nls.json | 6 +- extensions/mssql/src/constants.ts | 7 +++ extensions/mssql/src/main.ts | 33 +++++++++-- extensions/mssql/src/telemetry.ts | 9 +++ .../browser/media/objectTypes/Schema.svg | 59 +++++++++++-------- 7 files changed, 116 insertions(+), 31 deletions(-) diff --git a/extensions/mssql/config.json b/extensions/mssql/config.json index aa0bbb27b0..6529b3a25a 100644 --- a/extensions/mssql/config.json +++ b/extensions/mssql/config.json @@ -1,6 +1,6 @@ { "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", - "version": "4.5.0.18", + "version": "4.5.0.20", "downloadFileNames": { "Windows_86": "win-x86-net7.0.zip", "Windows_64": "win-x64-net7.0.zip", diff --git a/extensions/mssql/package.json b/extensions/mssql/package.json index 0d0b6dede6..10493ab8e1 100644 --- a/extensions/mssql/package.json +++ b/extensions/mssql/package.json @@ -66,6 +66,16 @@ "command": "mssql.designTable", "category": "MSSQL", "title": "%title.designTable%" + }, + { + "command": "mssql.enableGroupBySchema", + "category": "MSSQL", + "title": "%mssql.objectExplorer.enableGroupBySchema%" + }, + { + "command": "mssql.disableGroupBySchema", + "category": "MSSQL", + "title": "%mssql.objectExplorer.disableGroupBySchema%" } ], "outputChannels": [ @@ -356,6 +366,11 @@ "type": "boolean", "default": false, "description": "%mssql.tableDesigner.preloadDatabaseModel%" + }, + "mssql.objectExplorer.groupBySchema": { + "type": "boolean", + "default": false, + "description": "%mssql.objectExplorer.groupBySchema%" } } }, @@ -388,6 +403,14 @@ "command": "mssql.newTable", "when": "connectionProvider == MSSQL && nodeType == Folder && objectType == Tables", "group": "0_query@1" + }, + { + "command": "mssql.enableGroupBySchema", + "when": "connectionProvider == MSSQL && nodeType && nodeType =~ /^(Server|Database)$/ && !config.mssql.objectExplorer.groupBySchema" + }, + { + "command": "mssql.disableGroupBySchema", + "when": "connectionProvider == MSSQL && nodeType && nodeType =~ /^(Server|Database)$/ && config.mssql.objectExplorer.groupBySchema" } ], "dataExplorer/context": [ @@ -400,6 +423,14 @@ "command": "mssql.newTable", "when": "connectionProvider == MSSQL && nodeType == Folder && objectType == Tables", "group": "connection@1" + }, + { + "command": "mssql.enableGroupBySchema", + "when": "connectionProvider == MSSQL && nodeType && nodeType =~ /^(Server|Database)$/ && !config.mssql.objectExplorer.groupBySchema" + }, + { + "command": "mssql.disableGroupBySchema", + "when": "connectionProvider == MSSQL && nodeType && nodeType =~ /^(Server|Database)$/ && config.mssql.objectExplorer.groupBySchema" } ], "notebook/toolbar": [ diff --git a/extensions/mssql/package.nls.json b/extensions/mssql/package.nls.json index e40599717d..8ad3a8f4ef 100644 --- a/extensions/mssql/package.nls.json +++ b/extensions/mssql/package.nls.json @@ -178,5 +178,9 @@ "title.newTable": "New Table", "title.designTable": "Design", "mssql.parallelMessageProcessing" : "[Experimental] Whether the requests to the SQL Tools Service should be handled in parallel. This is introduced to discover the issues there might be when handling all requests in parallel. The default value is false. Relaunch of ADS is required when the value is changed.", - "mssql.tableDesigner.preloadDatabaseModel": "Whether to preload the database model when the database node in the object explorer is expanded. When enabled, the loading time of table designer can be reduced. Note: You might see higher than normal memory usage if you need to expand a lot of database nodes." + "mssql.tableDesigner.preloadDatabaseModel": "Whether to preload the database model when the database node in the object explorer is expanded. When enabled, the loading time of table designer can be reduced. Note: You might see higher than normal memory usage if you need to expand a lot of database nodes.", + + "mssql.objectExplorer.groupBySchema": "When enabled, the database objects in Object Explorer will be categorized by schema.", + "mssql.objectExplorer.enableGroupBySchema":"Enable Group By Schema", + "mssql.objectExplorer.disableGroupBySchema":"Disable Group By Schema" } diff --git a/extensions/mssql/src/constants.ts b/extensions/mssql/src/constants.ts index b270f1a2c5..1fe08cf20d 100644 --- a/extensions/mssql/src/constants.ts +++ b/extensions/mssql/src/constants.ts @@ -24,3 +24,10 @@ export const SqlMigrationService = 'sqlMigrationService'; export const NotebookConvertService = 'notebookConvertService'; export const AzureBlobService = 'azureBlobService'; export const TdeMigrationService = 'tdeMigrationService'; + +// CONFIGURATION VALUES ////////////////////////////////////////////////////////// +export const configObjectExplorerGroupBySchemaFlagName = 'mssql.objectExplorer.groupBySchema'; + +// COMMANDNAMES ////////////////////////////////////////////////////////// +export const cmdObjectExplorerEnableGroupBySchemaCommand = 'mssql.enableGroupBySchema'; +export const cmdObjectExplorerDisableGroupBySchemaCommand = 'mssql.disableGroupBySchema'; diff --git a/extensions/mssql/src/main.ts b/extensions/mssql/src/main.ts index ad8c95f5d8..b62229f792 100644 --- a/extensions/mssql/src/main.ts +++ b/extensions/mssql/src/main.ts @@ -22,7 +22,7 @@ import { IconPathHelper } from './iconHelper'; import * as nls from 'vscode-nls'; import { INotebookConvertService } from './notebookConvert/notebookConvertService'; import { registerTableDesignerCommands } from './tableDesigner/tableDesigner'; -import { TelemetryReporter } from './telemetry'; +import { TelemetryActions, TelemetryReporter, TelemetryViews } from './telemetry'; const localize = nls.loadMessageBundle(); @@ -63,7 +63,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { + context.subscriptions.push(vscode.commands.registerCommand('mssql.exportSqlAsNotebook', async (uri: vscode.Uri) => { try { const result = await appContext.getService(Constants.NotebookConvertService).convertSqlToNotebook(uri.toString()); const title = findNextUntitledEditorName(); @@ -72,9 +72,9 @@ export async function activate(context: vscode.ExtensionContext): Promise { + context.subscriptions.push(vscode.commands.registerCommand('mssql.exportNotebookToSql', async (uri: vscode.Uri) => { try { // SqlToolsService doesn't currently store anything about Notebook documents so we have to pass the raw JSON to it directly // We use vscode.workspace.textDocuments here because the azdata.nb.notebookDocuments don't actually contain their contents @@ -85,7 +85,30 @@ export async function activate(context: vscode.ExtensionContext): Promise { + await vscode.workspace.getConfiguration().update(Constants.configObjectExplorerGroupBySchemaFlagName, true, true); + })); + + context.subscriptions.push(vscode.commands.registerCommand(Constants.cmdObjectExplorerDisableGroupBySchemaCommand, async () => { + await vscode.workspace.getConfiguration().update(Constants.configObjectExplorerGroupBySchemaFlagName, false, true); + })); + + context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(async e => { + if (e.affectsConfiguration(Constants.configObjectExplorerGroupBySchemaFlagName)) { + const groupBySchemaTelemetryActionEvent = vscode.workspace.getConfiguration().get(Constants.configObjectExplorerGroupBySchemaFlagName) ? TelemetryActions.GroupBySchemaEnabled : TelemetryActions.GroupBySchemaDisabled; + TelemetryReporter.sendActionEvent(TelemetryViews.MssqlObjectExplorer, groupBySchemaTelemetryActionEvent); + const activeConnections = await azdata.objectexplorer.getActiveConnectionNodes(); + const connections = await azdata.connection.getConnections(); + activeConnections.forEach(async node => { + const connectionProfile = connections.find(c => c.connectionId === node.connectionId); + if (connectionProfile?.providerId === Constants.providerId) { + await node.refresh(); + } + }); + } + })); registerTableDesignerCommands(appContext); diff --git a/extensions/mssql/src/telemetry.ts b/extensions/mssql/src/telemetry.ts index 7c80572fd3..08d54bf260 100644 --- a/extensions/mssql/src/telemetry.ts +++ b/extensions/mssql/src/telemetry.ts @@ -76,3 +76,12 @@ export class LanguageClientErrorHandler implements ErrorHandler { return CloseAction.DoNotRestart; } } + +export enum TelemetryViews { + MssqlObjectExplorer = 'mssqlObjectExplorer' +} + +export enum TelemetryActions { + GroupBySchemaEnabled = 'objectExplorerGroupBySchemaEnabled', + GroupBySchemaDisabled = 'objectExplorerGroupBySchemaDisabled', +} diff --git a/src/sql/workbench/services/objectExplorer/browser/media/objectTypes/Schema.svg b/src/sql/workbench/services/objectExplorer/browser/media/objectTypes/Schema.svg index c3fed3a829..5709caa27f 100644 --- a/src/sql/workbench/services/objectExplorer/browser/media/objectTypes/Schema.svg +++ b/src/sql/workbench/services/objectExplorer/browser/media/objectTypes/Schema.svg @@ -1,25 +1,36 @@ - - - - - - - - - - - - - - - - + + + + + + + + +