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

@@ -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<void> {
public async importNewDatabaseProject(context: IConnectionProfile | any): Promise<void> {
let model = <ImportDataModel>{};
// TODO: Refactor code
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.
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 (<any>context).connectionProfile ? (<any>context).connectionProfile : context;
}
private async getProjectName(dbName: string): Promise<string | undefined> {
let projName = await this.apiWrapper.showInputBox({
prompt: constants.newDatabaseProjectName,