Fixed #3954 pass connection info to new notebook flow (#4000)

* Fixed #3954 
The problem is: connectionProfileId is not passed into New Notebook flow.
The fix is: plumbing connectionProfileId via NotebookInput.

* Resolved PR comments
This commit is contained in:
Yurong He
2019-02-11 15:28:05 -08:00
committed by GitHub
parent 6d37329e74
commit 62404721ed
8 changed files with 47 additions and 7 deletions

View File

@@ -102,9 +102,15 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
private updateProfile(): void { private updateProfile(): void {
this.profile = this.notebookParams ? this.notebookParams.profile : undefined; this.profile = this.notebookParams ? this.notebookParams.profile : undefined;
let profile: IConnectionProfile;
if (!this.profile) { if (!this.profile) {
// use global connection if possible // Use connectionProfile passed in first
let profile = TaskUtilities.getCurrentGlobalConnection(this.objectExplorerService, this.connectionManagementService, this.editorService); if (this._notebookParams.connectionProfileId !== undefined && this._notebookParams.connectionProfileId) {
profile = this.connectionManagementService.getConnectionProfileById(this._notebookParams.connectionProfileId);
} else {
// Second use global connection if possible
profile = TaskUtilities.getCurrentGlobalConnection(this.objectExplorerService, this.connectionManagementService, this.editorService);
}
// TODO use generic method to match kernel with valid connection that's compatible. For now, we only have 1 // TODO use generic method to match kernel with valid connection that's compatible. For now, we only have 1
if (profile && profile.providerName) { if (profile && profile.providerName) {
this.profile = profile; this.profile = profile;

View File

@@ -92,7 +92,8 @@ export class NotebookEditor extends BaseEditor {
input: input, input: input,
providerId: input.providerId ? input.providerId : DEFAULT_NOTEBOOK_PROVIDER, providerId: input.providerId ? input.providerId : DEFAULT_NOTEBOOK_PROVIDER,
providers: input.providers ? input.providers : [DEFAULT_NOTEBOOK_PROVIDER], providers: input.providers ? input.providers : [DEFAULT_NOTEBOOK_PROVIDER],
isTrusted: input.isTrusted isTrusted: input.isTrusted,
connectionProfileId: input.connectionProfileId
}; };
bootstrapAngular(this.instantiationService, bootstrapAngular(this.instantiationService,
NotebookModule, NotebookModule,

View File

@@ -28,7 +28,14 @@ export class NotebookInputModel extends EditorModel {
private _providerId: string; private _providerId: string;
private _standardKernels: IStandardKernelWithProvider[]; private _standardKernels: IStandardKernelWithProvider[];
private _defaultKernel: sqlops.nb.IKernelSpec; private _defaultKernel: sqlops.nb.IKernelSpec;
constructor(public readonly notebookUri: URI, private readonly handle: number, private _isTrusted: boolean = false, private saveHandler?: ModeViewSaveHandler, provider?: string, private _providers?: string[]) { constructor(public readonly notebookUri: URI,
private readonly handle: number,
private _isTrusted: boolean = false,
private saveHandler?: ModeViewSaveHandler,
provider?: string,
private _providers?: string[],
private _connectionProfileId?: string) {
super(); super();
this.dirty = false; this.dirty = false;
this._providerId = provider; this._providerId = provider;
@@ -51,6 +58,10 @@ export class NotebookInputModel extends EditorModel {
this._providers = value; this._providers = value;
} }
public get connectionProfileId(): string {
return this._connectionProfileId;
}
public get standardKernels(): IStandardKernelWithProvider[] { public get standardKernels(): IStandardKernelWithProvider[] {
return this._standardKernels; return this._standardKernels;
} }
@@ -131,6 +142,10 @@ export class NotebookInput extends EditorInput {
return this._model.providers; return this._model.providers;
} }
public get connectionProfileId(): string {
return this._model.connectionProfileId;
}
public get standardKernels(): IStandardKernelWithProvider[] { public get standardKernels(): IStandardKernelWithProvider[] {
return this._model.standardKernels; return this._model.standardKernels;
} }

View File

@@ -272,6 +272,11 @@ export interface IConnectionManagementService {
* Serialize connection string with optional provider * Serialize connection string with optional provider
*/ */
buildConnectionInfo(connectionString: string, provider?: string): Thenable<sqlops.ConnectionInfo>; buildConnectionInfo(connectionString: string, provider?: string): Thenable<sqlops.ConnectionInfo>;
/**
* Get connection profile by id
*/
getConnectionProfileById(profileId: string): IConnectionProfile;
} }
export const IConnectionDialogService = createDecorator<IConnectionDialogService>('connectionDialogService'); export const IConnectionDialogService = createDecorator<IConnectionDialogService>('connectionDialogService');

View File

@@ -1378,6 +1378,14 @@ export class ConnectionManagementService extends Disposable implements IConnecti
return serverInfo; return serverInfo;
} }
public getConnectionProfileById(profileId: string): IConnectionProfile {
let profile = this._connectionStatusManager.findConnectionByProfileId(profileId);
if (!profile) {
return undefined;
}
return profile.connectionProfile;
}
/** /**
* Get the connection string for the provided connection ID * Get the connection string for the provided connection ID
*/ */

View File

@@ -361,7 +361,7 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
pinned: !options.preview pinned: !options.preview
}; };
let trusted = uri.scheme === Schemas.untitled; let trusted = uri.scheme === Schemas.untitled;
let model = new NotebookInputModel(uri, undefined, trusted, undefined); let model = new NotebookInputModel(uri, undefined, trusted, undefined, undefined, undefined, options.connectionId);
let providerId = options.providerId; let providerId = options.providerId;
let providers: string[] = undefined; let providers: string[] = undefined;
// Ensure there is always a sensible provider ID for this file type // Ensure there is always a sensible provider ID for this file type

View File

@@ -94,6 +94,7 @@ export interface INotebookParams extends IBootstrapParams {
isTrusted: boolean; isTrusted: boolean;
profile?: IConnectionProfile; profile?: IConnectionProfile;
modelFactory?: ModelFactory; modelFactory?: ModelFactory;
connectionProfileId?: string;
} }
export interface INotebookEditor { export interface INotebookEditor {

View File

@@ -265,4 +265,8 @@ export class TestConnectionManagementService implements IConnectionManagementSer
buildConnectionInfo(connectionString: string, provider?: string): Thenable<sqlops.ConnectionInfo> { buildConnectionInfo(connectionString: string, provider?: string): Thenable<sqlops.ConnectionInfo> {
return undefined; return undefined;
} }
getConnectionProfileById(profileId: string): IConnectionProfile {
return undefined;
}
} }