mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 09:35:37 -05:00
Delete database reference (#12531)
* remove ItemGroup if node being removed is the only one * fix for if ItemGroup has elements with different tag names * fix for ItemGroups not at the end of the sqlproj * add delete for db references * fix failing tests * add test * cleanup * Addressing comments and fixing a string
This commit is contained in:
@@ -17,7 +17,7 @@ import * as azdata from 'azdata';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import { PublishDatabaseDialog } from '../dialogs/publishDatabaseDialog';
|
||||
import { Project, reservedProjectFolders, FileProjectEntry, SqlProjectReferenceProjectEntry } from '../models/project';
|
||||
import { Project, reservedProjectFolders, FileProjectEntry, SqlProjectReferenceProjectEntry, IDatabaseReferenceProjectEntry } from '../models/project';
|
||||
import { SqlDatabaseProjectTreeViewProvider } from './databaseProjectTreeViewProvider';
|
||||
import { FolderNode, FileNode } from '../models/tree/fileFolderTreeItem';
|
||||
import { IPublishSettings, IGenerateScriptSettings } from '../models/IPublishSettings';
|
||||
@@ -29,6 +29,7 @@ import { BuildHelper } from '../tools/buildHelper';
|
||||
import { PublishProfile, load } from '../models/publishProfile/publishProfile';
|
||||
import { AddDatabaseReferenceDialog } from '../dialogs/addDatabaseReferenceDialog';
|
||||
import { ISystemDatabaseReferenceSettings, IDacpacReferenceSettings, IProjectReferenceSettings } from '../models/IDatabaseReferenceSettings';
|
||||
import { DatabaseReferenceTreeItem } from '../models/tree/databaseReferencesTreeItem';
|
||||
import { WorkspaceTreeItem } from 'dataworkspace';
|
||||
|
||||
/**
|
||||
@@ -393,7 +394,15 @@ export class ProjectsController {
|
||||
public async delete(context: BaseProjectTreeItem): Promise<void> {
|
||||
const project = this.getProjectFromContext(context);
|
||||
|
||||
const confirmationPrompt = context instanceof FolderNode ? constants.deleteConfirmationContents(context.friendlyName) : constants.deleteConfirmation(context.friendlyName);
|
||||
let confirmationPrompt;
|
||||
if (context instanceof DatabaseReferenceTreeItem) {
|
||||
confirmationPrompt = constants.deleteReferenceConfirmation(context.friendlyName);
|
||||
} else if (context instanceof FolderNode) {
|
||||
confirmationPrompt = constants.deleteConfirmationContents(context.friendlyName);
|
||||
} else {
|
||||
confirmationPrompt = constants.deleteConfirmation(context.friendlyName);
|
||||
}
|
||||
|
||||
const response = await vscode.window.showWarningMessage(confirmationPrompt, { modal: true }, constants.yesString);
|
||||
|
||||
if (response !== constants.yesString) {
|
||||
@@ -402,7 +411,14 @@ export class ProjectsController {
|
||||
|
||||
let success = false;
|
||||
|
||||
if (context instanceof FileNode || FolderNode) {
|
||||
if (context instanceof DatabaseReferenceTreeItem) {
|
||||
const databaseReference = this.getDatabaseReference(project, context);
|
||||
|
||||
if (databaseReference) {
|
||||
await project.deleteDatabaseReference(databaseReference);
|
||||
success = true;
|
||||
}
|
||||
} else if (context instanceof FileNode || FolderNode) {
|
||||
const fileEntry = this.getFileProjectEntry(project, context);
|
||||
|
||||
if (fileEntry) {
|
||||
@@ -430,6 +446,17 @@ export class ProjectsController {
|
||||
return project.files.find(x => utils.getPlatformSafeFileEntryPath(x.relativePath) === utils.getPlatformSafeFileEntryPath(utils.trimUri(context.root.uri, context.uri)));
|
||||
}
|
||||
|
||||
private getDatabaseReference(project: Project, context: BaseProjectTreeItem): IDatabaseReferenceProjectEntry | undefined {
|
||||
const root = context.root as ProjectRootTreeItem;
|
||||
const databaseReference = context as DatabaseReferenceTreeItem;
|
||||
|
||||
if (root && databaseReference) {
|
||||
return project.databaseReferences.find(r => r.databaseName === databaseReference.treeItem.label);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the folder containing the project
|
||||
* @param context a treeItem in a project's hierarchy, to be used to obtain a Project
|
||||
|
||||
Reference in New Issue
Block a user