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
This commit is contained in:
Kim Santiago
2020-07-09 16:47:55 -07:00
committed by GitHub
parent 1796b519e5
commit 7d5ecfe905
3 changed files with 45 additions and 16 deletions

View File

@@ -118,7 +118,11 @@
{ {
"command": "sqlDatabaseProjects.importDatabase", "command": "sqlDatabaseProjects.importDatabase",
"title": "%sqlDatabaseProjects.importDatabase%", "title": "%sqlDatabaseProjects.importDatabase%",
"category": "%sqlDatabaseProjects.displayName%" "category": "%sqlDatabaseProjects.displayName%",
"icon": {
"dark": "images/extension.png",
"light": "images/extension.png"
}
}, },
{ {
"command": "sqlDatabaseProjects.addDatabaseReference", "command": "sqlDatabaseProjects.addDatabaseReference",
@@ -277,6 +281,12 @@
"when": "connectionProvider == MSSQL && nodeType && nodeType == Database && mssql:engineedition != 11", "when": "connectionProvider == MSSQL && nodeType && nodeType == Database && mssql:engineedition != 11",
"group": "export" "group": "export"
} }
],
"dashboard/toolbar": [
{
"command": "sqlDatabaseProjects.importDatabase",
"when": "connectionProvider == 'MSSQL' && mssql:engineedition != 11"
}
] ]
}, },
"views": { "views": {

View File

@@ -39,6 +39,7 @@ export const sqlDatabaseProject = localize('sqlDatabaseProject', "SQL database p
export const yesString = localize('yesString', "Yes"); export const yesString = localize('yesString', "Yes");
export const noString = localize('noString', "No"); export const noString = localize('noString', "No");
export const extractTargetInput = localize('extractTargetInput', "Select folder structure for SQL files"); 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 selectString = localize('selectString', "Select");
export const addDatabaseReferenceInput = localize('addDatabaseReferenceInput', "Add database reference for:"); export const addDatabaseReferenceInput = localize('addDatabaseReferenceInput', "Add database reference for:");
export const systemDatabaseReferenceInput = localize('systemDatabaseReferenceInput', "System Database:"); export const systemDatabaseReferenceInput = localize('systemDatabaseReferenceInput', "System Database:");

View File

@@ -632,16 +632,18 @@ export class ProjectsController {
* Imports a new SQL database project from the existing database, * Imports a new SQL database project from the existing database,
* prompting the user for a name, file path location and extract target * prompting the user for a name, file path location and extract target
*/ */
public async importNewDatabaseProject(context: any): Promise<void> { public async importNewDatabaseProject(context: IConnectionProfile | any): Promise<void> {
let model = <ImportDataModel>{}; let model = <ImportDataModel>{};
// TODO: Refactor code // TODO: Refactor code
try { try {
let profile = context ? <IConnectionProfile>context.connectionProfile : undefined; let profile = this.getConnectionProfileFromContext(context);
//TODO: Prompt for new connection addition and get database information if context information isn't provided. //TODO: Prompt for new connection addition and get database information if context information isn't provided.
let connectionId;
if (profile) { if (profile) {
model.serverId = profile.id;
model.database = profile.databaseName; model.database = profile.databaseName;
connectionId = profile.id;
} }
else { else {
const connection = await this.apiWrapper.openConnectionDialog(); const connection = await this.apiWrapper.openConnectionDialog();
@@ -649,23 +651,29 @@ export class ProjectsController {
return; return;
} }
const connectionId = connection.connectionId; connectionId = connection.connectionId;
let database;
// use database that was connected to if it isn't master // use database that was connected to
if (connection.options['database'] && connection.options['database'] !== constants.master) { if (connection.options['database']) {
database = connection.options['database']; model.database = connection.options['database'];
} else { }
}
// choose database if connection was to a server or master
if (!model.database || model.database === constants.master) {
const databaseList = await this.apiWrapper.listDatabases(connectionId); const databaseList = await this.apiWrapper.listDatabases(connectionId);
database = (await this.apiWrapper.showQuickPick(databaseList.map(dbName => { return { label: dbName }; })))?.label; let database = (await this.apiWrapper.showQuickPick(databaseList.map(dbName => { return { label: dbName }; }),
{
canPickMany: false,
placeHolder: constants.extractDatabaseSelection
}))?.label;
if (!database) { if (!database) {
throw new Error(constants.databaseSelectionRequired); throw new Error(constants.databaseSelectionRequired);
} }
}
model.serverId = connectionId;
model.database = database; model.database = database;
model.serverId = connectionId;
} }
// Get project name // 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 (<any>context).connectionProfile ? (<any>context).connectionProfile : context;
}
private async getProjectName(dbName: string): Promise<string | undefined> { private async getProjectName(dbName: string): Promise<string | undefined> {
let projName = await this.apiWrapper.showInputBox({ let projName = await this.apiWrapper.showInputBox({
prompt: constants.newDatabaseProjectName, prompt: constants.newDatabaseProjectName,