mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-21 09:35:38 -05:00
Fix create project from db not loading dbs when disconnected (#19129)
* fix create project from database when launched from disconnected node * don't open dashboard * fix tests * update order so connection dialog opens first if can't connect
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type * as azdataType from 'azdata';
|
||||
import * as azdataType from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as constants from '../common/constants';
|
||||
import * as newProjectTool from '../tools/newProjectTool';
|
||||
@@ -50,11 +50,37 @@ export class CreateProjectFromDatabaseDialog {
|
||||
|
||||
this.dialog.cancelButton.label = constants.cancelButtonText;
|
||||
|
||||
let connected = false;
|
||||
if (this.profile) {
|
||||
const connections = await azdataType.connection.getConnections(true);
|
||||
connected = !!connections.find(c => c.connectionId === this.profile!.id);
|
||||
|
||||
if (!connected) {
|
||||
// if the connection clicked on isn't currently connected, try to connect
|
||||
const result = await azdataType.connection.connect(this.profile, true, false);
|
||||
connected = result.connected;
|
||||
|
||||
if (!result.connected) {
|
||||
// if can't connect automatically, open connection dialog with the info from the profile
|
||||
const connection = await azdataType.connection.openConnectionDialog(undefined, this.profile);
|
||||
connected = !!connection;
|
||||
|
||||
// update these fields if connection was successful, to ensure they match the connection made
|
||||
if (connected) {
|
||||
this.profile.id = connection.connectionId;
|
||||
this.profile.databaseName = connection.options['databaseName'];
|
||||
this.profile.serverName = connection.options['server'];
|
||||
this.profile.userName = connection.options['user'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getAzdataApi()!.window.openDialog(this.dialog);
|
||||
await this.initDialogComplete.promise;
|
||||
|
||||
if (this.profile) {
|
||||
await this.updateConnectionComponents(getConnectionName(this.profile), this.profile.id, this.profile.databaseName!);
|
||||
if (connected) {
|
||||
await this.updateConnectionComponents(getConnectionName(this.profile), this.profile!.id, this.profile!.databaseName);
|
||||
}
|
||||
|
||||
this.tryEnableCreateButton();
|
||||
|
||||
@@ -17,6 +17,8 @@ describe('Create Project From Database Dialog', () => {
|
||||
});
|
||||
|
||||
it('Should open dialog successfully', async function (): Promise<void> {
|
||||
sinon.stub(azdata.connection, 'getConnections').resolves([]);
|
||||
sinon.stub(azdata.connection, 'connect').resolves({ connected: true, connectionId: '0', errorMessage: '', errorCode: 0});
|
||||
sinon.stub(azdata.connection, 'listDatabases').resolves([]);
|
||||
const dialog = new CreateProjectFromDatabaseDialog(mockConnectionProfile);
|
||||
await dialog.openDialog();
|
||||
@@ -24,6 +26,8 @@ describe('Create Project From Database Dialog', () => {
|
||||
});
|
||||
|
||||
it('Should enable ok button correctly with a connection profile', async function (): Promise<void> {
|
||||
sinon.stub(azdata.connection, 'getConnections').resolves([]);
|
||||
sinon.stub(azdata.connection, 'connect').resolves({ connected: true, connectionId: '0', errorMessage: '', errorCode: 0});
|
||||
sinon.stub(azdata.connection, 'listDatabases').resolves([]);
|
||||
const dialog = new CreateProjectFromDatabaseDialog(mockConnectionProfile);
|
||||
await dialog.openDialog(); // should set connection details
|
||||
@@ -74,6 +78,8 @@ describe('Create Project From Database Dialog', () => {
|
||||
});
|
||||
|
||||
it('Should create default project name correctly when database information is populated', async function (): Promise<void> {
|
||||
sinon.stub(azdata.connection, 'getConnections').resolves([]);
|
||||
sinon.stub(azdata.connection, 'connect').resolves({ connected: true, connectionId: '0', errorMessage: '', errorCode: 0});
|
||||
sinon.stub(azdata.connection, 'listDatabases').resolves(['My Database']);
|
||||
const dialog = new CreateProjectFromDatabaseDialog(mockConnectionProfile);
|
||||
await dialog.openDialog();
|
||||
@@ -85,6 +91,8 @@ describe('Create Project From Database Dialog', () => {
|
||||
it('Should include all info in import data model and connect to appropriate call back properties', async function (): Promise<void> {
|
||||
const stubUri = 'My URI';
|
||||
const dialog = new CreateProjectFromDatabaseDialog(mockConnectionProfile);
|
||||
sinon.stub(azdata.connection, 'getConnections').resolves([]);
|
||||
sinon.stub(azdata.connection, 'connect').resolves({ connected: true, connectionId: '0', errorMessage: '', errorCode: 0});
|
||||
sinon.stub(azdata.connection, 'listDatabases').resolves(['My Database']);
|
||||
sinon.stub(azdata.connection, 'getUriForConnection').resolves(stubUri);
|
||||
await dialog.openDialog();
|
||||
|
||||
Reference in New Issue
Block a user