From 7d5ecfe905e2e521e9c10c8ce8ffca881bc8c611 Mon Sep 17 00:00:00 2001 From: Kim Santiago <31145923+kisantia@users.noreply.github.com> Date: Thu, 9 Jul 2020 16:47:55 -0700 Subject: [PATCH] Add "Import New Database Project" to dashboard toolbar (#11229) * add import database project to database and server dashboard home toolbar * connection profile is getting passed to the extension * use MenuItemAction instead of creating a new one * move database picking * add comment * add helper function --- extensions/sql-database-projects/package.json | 12 ++++- .../src/common/constants.ts | 1 + .../src/controllers/projectController.ts | 48 +++++++++++++------ 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/extensions/sql-database-projects/package.json b/extensions/sql-database-projects/package.json index 340a581325..6fcc8b1285 100644 --- a/extensions/sql-database-projects/package.json +++ b/extensions/sql-database-projects/package.json @@ -118,7 +118,11 @@ { "command": "sqlDatabaseProjects.importDatabase", "title": "%sqlDatabaseProjects.importDatabase%", - "category": "%sqlDatabaseProjects.displayName%" + "category": "%sqlDatabaseProjects.displayName%", + "icon": { + "dark": "images/extension.png", + "light": "images/extension.png" + } }, { "command": "sqlDatabaseProjects.addDatabaseReference", @@ -277,6 +281,12 @@ "when": "connectionProvider == MSSQL && nodeType && nodeType == Database && mssql:engineedition != 11", "group": "export" } + ], + "dashboard/toolbar": [ + { + "command": "sqlDatabaseProjects.importDatabase", + "when": "connectionProvider == 'MSSQL' && mssql:engineedition != 11" + } ] }, "views": { diff --git a/extensions/sql-database-projects/src/common/constants.ts b/extensions/sql-database-projects/src/common/constants.ts index ddaa46c980..7ec68cbefd 100644 --- a/extensions/sql-database-projects/src/common/constants.ts +++ b/extensions/sql-database-projects/src/common/constants.ts @@ -39,6 +39,7 @@ export const sqlDatabaseProject = localize('sqlDatabaseProject', "SQL database p export const yesString = localize('yesString', "Yes"); export const noString = localize('noString', "No"); export const extractTargetInput = localize('extractTargetInput', "Select folder structure for SQL files"); +export const extractDatabaseSelection = localize('extractDatabaseSelection', "Select database to import"); export const selectString = localize('selectString', "Select"); export const addDatabaseReferenceInput = localize('addDatabaseReferenceInput', "Add database reference for:"); export const systemDatabaseReferenceInput = localize('systemDatabaseReferenceInput', "System Database:"); diff --git a/extensions/sql-database-projects/src/controllers/projectController.ts b/extensions/sql-database-projects/src/controllers/projectController.ts index c77b1cb6fe..737488192b 100644 --- a/extensions/sql-database-projects/src/controllers/projectController.ts +++ b/extensions/sql-database-projects/src/controllers/projectController.ts @@ -632,16 +632,18 @@ export class ProjectsController { * Imports a new SQL database project from the existing database, * prompting the user for a name, file path location and extract target */ - public async importNewDatabaseProject(context: any): Promise { + public async importNewDatabaseProject(context: IConnectionProfile | any): Promise { let model = {}; // TODO: Refactor code try { - let profile = context ? context.connectionProfile : undefined; + let profile = this.getConnectionProfileFromContext(context); //TODO: Prompt for new connection addition and get database information if context information isn't provided. + + let connectionId; if (profile) { - model.serverId = profile.id; model.database = profile.databaseName; + connectionId = profile.id; } else { const connection = await this.apiWrapper.openConnectionDialog(); @@ -649,23 +651,29 @@ export class ProjectsController { return; } - const connectionId = connection.connectionId; - let database; + connectionId = connection.connectionId; - // use database that was connected to if it isn't master - if (connection.options['database'] && connection.options['database'] !== constants.master) { - database = connection.options['database']; - } else { - const databaseList = await this.apiWrapper.listDatabases(connectionId); - database = (await this.apiWrapper.showQuickPick(databaseList.map(dbName => { return { label: dbName }; })))?.label; + // use database that was connected to + if (connection.options['database']) { + model.database = connection.options['database']; + } + } - if (!database) { - throw new Error(constants.databaseSelectionRequired); - } + // choose database if connection was to a server or master + if (!model.database || model.database === constants.master) { + const databaseList = await this.apiWrapper.listDatabases(connectionId); + let database = (await this.apiWrapper.showQuickPick(databaseList.map(dbName => { return { label: dbName }; }), + { + canPickMany: false, + placeHolder: constants.extractDatabaseSelection + }))?.label; + + if (!database) { + throw new Error(constants.databaseSelectionRequired); } - model.serverId = connectionId; model.database = database; + model.serverId = connectionId; } // Get project name @@ -727,6 +735,16 @@ export class ProjectsController { } } + private getConnectionProfileFromContext(context: IConnectionProfile | any): IConnectionProfile | undefined { + if (!context) { + return undefined; + } + + // depending on where import new project is launched from, the connection profile could be passed as just + // the profile or it could be wrapped in another object + return (context).connectionProfile ? (context).connectionProfile : context; + } + private async getProjectName(dbName: string): Promise { let projName = await this.apiWrapper.showInputBox({ prompt: constants.newDatabaseProjectName,