From d6358b3e2970d95d81ff41002f3add04fa1c19f7 Mon Sep 17 00:00:00 2001 From: Kim Santiago <31145923+kisantia@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:25:09 -0800 Subject: [PATCH] Add telemetry events for rename and move in sql project (#22068) * add telemetry events for rename and move in sql project * remove check * update telemetry events --- .../src/common/telemetry.ts | 4 ++- .../src/controllers/projectController.ts | 35 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/extensions/sql-database-projects/src/common/telemetry.ts b/extensions/sql-database-projects/src/common/telemetry.ts index 54af081a2c..9eb38ef47c 100644 --- a/extensions/sql-database-projects/src/common/telemetry.ts +++ b/extensions/sql-database-projects/src/common/telemetry.ts @@ -47,5 +47,7 @@ export enum TelemetryActions { optionsChanged = 'optionsChanged', profileLoaded = 'profileLoaded', SchemaComparisonFinished = 'SchemaComparisonFinished', - SchemaComparisonStarted = 'SchemaComparisonStarted' + SchemaComparisonStarted = 'SchemaComparisonStarted', + rename = "rename", + move = "move" } diff --git a/extensions/sql-database-projects/src/controllers/projectController.ts b/extensions/sql-database-projects/src/controllers/projectController.ts index 77711a1fec..3c2651c88d 100644 --- a/extensions/sql-database-projects/src/controllers/projectController.ts +++ b/extensions/sql-database-projects/src/controllers/projectController.ts @@ -857,10 +857,13 @@ export class ProjectsController { const newFilePath = path.join(path.dirname(utils.getPlatformSafeFileEntryPath(file?.relativePath!)), `${newFileName}.sql`); - try { - await this.move(node, node.projectFileUri.fsPath, newFilePath); - } catch (e) { - void vscode.window.showErrorMessage(constants.errorRenamingFile(file?.relativePath!, newFilePath, utils.getErrorMessage(e))); + const renameResult = await this.move(node, node.projectFileUri.fsPath, newFilePath); + + if (renameResult?.success) { + TelemetryReporter.sendActionEvent(TelemetryViews.ProjectTree, TelemetryActions.rename); + } else { + TelemetryReporter.sendErrorEvent2(TelemetryViews.ProjectTree, TelemetryActions.rename); + void vscode.window.showErrorMessage(constants.errorRenamingFile(file?.relativePath!, newFilePath, utils.getErrorMessage(renameResult?.errorMessage))); } this.refreshProjectsTree(context); @@ -1867,7 +1870,7 @@ export class ProjectsController { const newPath = path.join(folderPath!, sourceFileNode.friendlyName); // don't do anything if the path is the same - if (newPath === sourceFileNode.fileSystemUri.fsPath) { + if (newPath === sourceFileNode.relativeProjectUri.fsPath) { return; } @@ -1877,10 +1880,13 @@ export class ProjectsController { } // Move the file - try { - await this.move(sourceFileNode, projectUri.fsPath, newPath); - } catch (e) { - void vscode.window.showErrorMessage(constants.errorMovingFile(sourceFileNode.fileSystemUri.fsPath, newPath, utils.getErrorMessage(e))); + const moveResult = await this.move(sourceFileNode, projectUri.fsPath, newPath); + + if (moveResult?.success) { + TelemetryReporter.sendActionEvent(TelemetryViews.ProjectTree, TelemetryActions.move); + } else { + TelemetryReporter.sendErrorEvent2(TelemetryViews.ProjectTree, TelemetryActions.move); + void vscode.window.showErrorMessage(constants.errorMovingFile(sourceFileNode.fileSystemUri.fsPath, newPath, utils.getErrorMessage(moveResult?.errorMessage))); } } @@ -1890,7 +1896,7 @@ export class ProjectsController { * @param projectFilePath Full file path to .sqlproj * @param destinationRelativePath path of the destination, relative to .sqlproj */ - private async move(node: BaseProjectTreeItem, projectFilePath: string, destinationRelativePath: string): Promise { + private async move(node: BaseProjectTreeItem, projectFilePath: string, destinationRelativePath: string): Promise { // trim off the project folder at the beginning of the relative path stored in the tree const projectRelativeUri = vscode.Uri.file(path.basename(projectFilePath, constants.sqlprojExtension)); const originalRelativePath = utils.trimUri(projectRelativeUri, node.relativeProjectUri); @@ -1902,15 +1908,18 @@ export class ProjectsController { const sqlProjectsService = await utils.getSqlProjectsService(); + let result; if (node instanceof SqlObjectFileNode) { - await sqlProjectsService.moveSqlObjectScript(projectFilePath, destinationRelativePath, originalRelativePath) + result = await sqlProjectsService.moveSqlObjectScript(projectFilePath, destinationRelativePath, originalRelativePath) } else if (node instanceof PreDeployNode) { - await sqlProjectsService.movePreDeploymentScript(projectFilePath, destinationRelativePath, originalRelativePath) + result = await sqlProjectsService.movePreDeploymentScript(projectFilePath, destinationRelativePath, originalRelativePath) } else if (node instanceof PostDeployNode) { - await sqlProjectsService.movePostDeploymentScript(projectFilePath, destinationRelativePath, originalRelativePath) + result = await sqlProjectsService.movePostDeploymentScript(projectFilePath, destinationRelativePath, originalRelativePath) } // TODO add support for renaming none scripts after those are added in STS // TODO add support for renaming publish profiles when support is added in DacFx + + return result; } }