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 {
this.profile = this.notebookParams ? this.notebookParams.profile : undefined;
let profile: IConnectionProfile;
if (!this.profile) {
// use global connection if possible
let profile = TaskUtilities.getCurrentGlobalConnection(this.objectExplorerService, this.connectionManagementService, this.editorService);
// Use connectionProfile passed in first
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
if (profile && profile.providerName) {
this.profile = profile;
@@ -481,10 +487,10 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
*/
private fillInActionsForCurrentContext(): void {
let primary: IAction[] = [];
let secondary: IAction[] = [];
let secondary: IAction[] = [];
let notebookBarMenu = this.menuService.createMenu(MenuId.NotebookToolbar, this.contextKeyService);
let groups = notebookBarMenu.getActions({ arg: null, shouldForwardArgs: true });
fillInActions(groups, {primary, secondary}, false, (group: string) => group === undefined);
fillInActions(groups, { primary, secondary }, false, (group: string) => group === undefined);
this.addPrimaryContributedActions(primary);
}

View File

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

View File

@@ -28,7 +28,14 @@ export class NotebookInputModel extends EditorModel {
private _providerId: string;
private _standardKernels: IStandardKernelWithProvider[];
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();
this.dirty = false;
this._providerId = provider;
@@ -51,6 +58,10 @@ export class NotebookInputModel extends EditorModel {
this._providers = value;
}
public get connectionProfileId(): string {
return this._connectionProfileId;
}
public get standardKernels(): IStandardKernelWithProvider[] {
return this._standardKernels;
}
@@ -131,6 +142,10 @@ export class NotebookInput extends EditorInput {
return this._model.providers;
}
public get connectionProfileId(): string {
return this._model.connectionProfileId;
}
public get standardKernels(): IStandardKernelWithProvider[] {
return this._model.standardKernels;
}

View File

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

View File

@@ -1378,6 +1378,14 @@ export class ConnectionManagementService extends Disposable implements IConnecti
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
*/

View File

@@ -361,7 +361,7 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
pinned: !options.preview
};
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 providers: string[] = undefined;
// 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;
profile?: IConnectionProfile;
modelFactory?: ModelFactory;
connectionProfileId?: string;
}
export interface INotebookEditor {