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
This commit is contained in:
Kim Santiago
2023-03-01 10:25:09 -08:00
committed by GitHub
parent e69346e7fa
commit d6358b3e29
2 changed files with 25 additions and 14 deletions

View File

@@ -47,5 +47,7 @@ export enum TelemetryActions {
optionsChanged = 'optionsChanged',
profileLoaded = 'profileLoaded',
SchemaComparisonFinished = 'SchemaComparisonFinished',
SchemaComparisonStarted = 'SchemaComparisonStarted'
SchemaComparisonStarted = 'SchemaComparisonStarted',
rename = "rename",
move = "move"
}

View File

@@ -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<void> {
private async move(node: BaseProjectTreeItem, projectFilePath: string, destinationRelativePath: string): Promise<azdataType.ResultStatus | undefined> {
// 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;
}
}