Add Create Proj from DB to VS Code context menus (#16584)

* Add Create Proj from DB to VS Code context menus

* Fix error

* add comment

* use constant
This commit is contained in:
Charles Gagnon
2021-08-06 08:59:35 -07:00
committed by GitHub
parent e6f356accc
commit b8da94f9ef
5 changed files with 84 additions and 16 deletions

View File

@@ -863,10 +863,10 @@ export class ProjectsController {
* Creates a new SQL database project from the existing database,
* prompting the user for a name, file path location and extract target
*/
public async createProjectFromDatabase(context: azdataType.IConnectionProfile | any): Promise<CreateProjectFromDatabaseDialog | undefined> {
public async createProjectFromDatabase(context: azdataType.IConnectionProfile | mssqlVscode.ITreeNodeInfo | undefined): Promise<CreateProjectFromDatabaseDialog | undefined> {
const profile = this.getConnectionProfileFromContext(context);
if (utils.getAzdataApi()) {
let createProjectFromDatabaseDialog = this.getCreateProjectFromDatabaseDialog(profile);
let createProjectFromDatabaseDialog = this.getCreateProjectFromDatabaseDialog(profile as azdataType.IConnectionProfile);
createProjectFromDatabaseDialog.createProjectFromDatabaseCallback = async (model) => await this.createProjectFromDatabaseCallback(model);
@@ -874,7 +874,15 @@ export class ProjectsController {
return createProjectFromDatabaseDialog;
} else {
const model = await createNewProjectFromDatabaseWithQuickpick();
if (context) {
// The profile we get from VS Code is for the overall server connection and isn't updated based on the database node
// the command was launched from like it is in ADS. So get the actual database name from the MSSQL extension and
// update the connection info here.
const treeNodeContext = context as mssqlVscode.ITreeNodeInfo;
const databaseName = (await utils.getVscodeMssqlApi()).getDatabaseNameFromTreeNode(treeNodeContext);
(profile as mssqlVscode.IConnectionInfo).database = databaseName;
}
const model = await createNewProjectFromDatabaseWithQuickpick(profile as mssqlVscode.IConnectionInfo);
if (model) {
await this.createProjectFromDatabaseCallback(model);
}
@@ -925,14 +933,14 @@ export class ProjectsController {
}
}
private getConnectionProfileFromContext(context: azdataType.IConnectionProfile | any): azdataType.IConnectionProfile | undefined {
private getConnectionProfileFromContext(context: azdataType.IConnectionProfile | mssqlVscode.ITreeNodeInfo | undefined): azdataType.IConnectionProfile | mssqlVscode.IConnectionInfo | 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;
return (<any>context)?.connectionProfile ?? (context as mssqlVscode.ITreeNodeInfo).connectionInfo ?? context;
}
public async createProjectFromDatabaseApiCall(model: ImportDataModel): Promise<void> {