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 <chgagnon@microsoft.com>

* converting to sendActionEvent

* sendActionEvent

* Adding telemetryViews and telemetry actions

* Fixing localized string

* registering context

---------

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
Aasim Khan
2023-02-15 15:18:10 -08:00
committed by GitHub
parent f7fa9bece3
commit d6c35836cc
7 changed files with 116 additions and 31 deletions

View File

@@ -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';

View File

@@ -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<IExten
context.subscriptions.push(server);
await server.start(appContext);
vscode.commands.registerCommand('mssql.exportSqlAsNotebook', async (uri: vscode.Uri) => {
context.subscriptions.push(vscode.commands.registerCommand('mssql.exportSqlAsNotebook', async (uri: vscode.Uri) => {
try {
const result = await appContext.getService<INotebookConvertService>(Constants.NotebookConvertService).convertSqlToNotebook(uri.toString());
const title = findNextUntitledEditorName();
@@ -72,9 +72,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<IExten
} catch (err) {
void vscode.window.showErrorMessage(localize('mssql.errorConvertingToNotebook', "An error occurred converting the SQL document to a Notebook. Error : {0}", err.toString()));
}
});
}));
vscode.commands.registerCommand('mssql.exportNotebookToSql', async (uri: vscode.Uri) => {
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<IExten
} catch (err) {
void vscode.window.showErrorMessage(localize('mssql.errorConvertingToSQL', "An error occurred converting the Notebook document to SQL. Error : {0}", err.toString()));
}
});
}));
context.subscriptions.push(vscode.commands.registerCommand(Constants.cmdObjectExplorerEnableGroupBySchemaCommand, async () => {
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);

View File

@@ -76,3 +76,12 @@ export class LanguageClientErrorHandler implements ErrorHandler {
return CloseAction.DoNotRestart;
}
}
export enum TelemetryViews {
MssqlObjectExplorer = 'mssqlObjectExplorer'
}
export enum TelemetryActions {
GroupBySchemaEnabled = 'objectExplorerGroupBySchemaEnabled',
GroupBySchemaDisabled = 'objectExplorerGroupBySchemaDisabled',
}