mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
* #3897: Unified connection integration - sql connection improvements * variable name change * Misc changes * Misc change
This commit is contained in:
@@ -378,6 +378,9 @@ export interface INotebookModel {
|
|||||||
pushEditOperations(edits: ISingleNotebookEditOperation[]): void;
|
pushEditOperations(edits: ISingleNotebookEditOperation[]): void;
|
||||||
|
|
||||||
getApplicableConnectionProviderIds(kernelName: string): string[];
|
getApplicableConnectionProviderIds(kernelName: string): string[];
|
||||||
|
|
||||||
|
/** Event fired once we get call back from ConfigureConnection method in sqlops extension */
|
||||||
|
readonly onValidConnectionSelected: Event<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NotebookContentChange {
|
export interface NotebookContentChange {
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
|||||||
private _defaultKernel: nb.IKernelSpec;
|
private _defaultKernel: nb.IKernelSpec;
|
||||||
private _kernelDisplayNameToConnectionProviderIds: Map<string, string[]> = new Map<string, string[]>();
|
private _kernelDisplayNameToConnectionProviderIds: Map<string, string[]> = new Map<string, string[]>();
|
||||||
private _kernelDisplayNameToNotebookProviderIds: Map<string, string> = new Map<string, string>();
|
private _kernelDisplayNameToNotebookProviderIds: Map<string, string> = new Map<string, string>();
|
||||||
|
private _onValidConnectionSelected = new Emitter<boolean>();
|
||||||
|
|
||||||
constructor(private notebookOptions: INotebookModelOptions, startSessionImmediately?: boolean, private connectionProfile?: IConnectionProfile) {
|
constructor(private notebookOptions: INotebookModelOptions, startSessionImmediately?: boolean, private connectionProfile?: IConnectionProfile) {
|
||||||
super();
|
super();
|
||||||
@@ -229,6 +230,10 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
|||||||
return this._onProviderIdChanged.event;
|
return this._onProviderIdChanged.event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get onValidConnectionSelected(): Event<boolean>{
|
||||||
|
return this._onValidConnectionSelected.event;
|
||||||
|
}
|
||||||
|
|
||||||
public getApplicableConnectionProviderIds(kernelDisplayName: string): string[] {
|
public getApplicableConnectionProviderIds(kernelDisplayName: string): string[] {
|
||||||
let ids = [];
|
let ids = [];
|
||||||
if (kernelDisplayName) {
|
if (kernelDisplayName) {
|
||||||
@@ -451,11 +456,18 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
|||||||
let newConnectionProfile = new ConnectionProfile(this.notebookOptions.capabilitiesService, newConnection);
|
let newConnectionProfile = new ConnectionProfile(this.notebookOptions.capabilitiesService, newConnection);
|
||||||
this._activeConnection = newConnectionProfile;
|
this._activeConnection = newConnectionProfile;
|
||||||
this.refreshConnections(newConnectionProfile);
|
this.refreshConnections(newConnectionProfile);
|
||||||
this._activeClientSession.updateConnection(this._activeConnection.toIConnectionProfile()).catch((error) => {
|
this._activeClientSession.updateConnection(this._activeConnection.toIConnectionProfile()).then(
|
||||||
if (error) {
|
result => {
|
||||||
this.notifyError(error.message);
|
//Remove 'Select connection' from 'Attach to' drop-down since its a valid connection
|
||||||
}
|
this._onValidConnectionSelected.fire(true);
|
||||||
});
|
},
|
||||||
|
error => {
|
||||||
|
if (error) {
|
||||||
|
this.notifyError(notebookUtils.getErrorMessage(error));
|
||||||
|
//Selected a wrong connection, Attach to should be defaulted with 'Select connection'
|
||||||
|
this._onValidConnectionSelected.fire(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
let msg = notebookUtils.getErrorMessage(err);
|
let msg = notebookUtils.getErrorMessage(err);
|
||||||
this.notifyError(localize('changeContextFailed', 'Changing context failed: {0}', msg));
|
this.notifyError(localize('changeContextFailed', 'Changing context failed: {0}', msg));
|
||||||
|
|||||||
@@ -215,8 +215,11 @@ export class AttachToDropdown extends SelectBox {
|
|||||||
super([msgLoadingContexts], msgLoadingContexts, contextViewProvider, container, { labelText: attachToLabel, labelOnTop: false } as ISelectBoxOptionsWithLabel);
|
super([msgLoadingContexts], msgLoadingContexts, contextViewProvider, container, { labelText: attachToLabel, labelOnTop: false } as ISelectBoxOptionsWithLabel);
|
||||||
if (modelRegistered) {
|
if (modelRegistered) {
|
||||||
modelRegistered
|
modelRegistered
|
||||||
.then((model) => this.updateModel(model))
|
.then(model => {
|
||||||
.catch((err) => {
|
this.updateModel(model);
|
||||||
|
this.updateAttachToDropdown(model);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
// No-op for now
|
// No-op for now
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -229,16 +232,37 @@ export class AttachToDropdown extends SelectBox {
|
|||||||
public updateModel(model: INotebookModel): void {
|
public updateModel(model: INotebookModel): void {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
model.contextsChanged(() => {
|
model.contextsChanged(() => {
|
||||||
if (this.model.clientSession.kernel && this.model.clientSession.kernel.name) {
|
let kernelDisplayName: string = this.getKernelDisplayName();
|
||||||
let nameLower = this.model.clientSession.kernel.name.toLowerCase();
|
if (kernelDisplayName) {
|
||||||
let currentKernelSpec = this.model.specs.kernels.find(kernel => kernel.name && kernel.name.toLowerCase() === nameLower);
|
this.loadAttachToDropdown(this.model, kernelDisplayName);
|
||||||
this.loadAttachToDropdown(this.model, currentKernelSpec.display_name);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateAttachToDropdown(model: INotebookModel): void {
|
||||||
|
this.model = model;
|
||||||
|
model.onValidConnectionSelected(validConnection => {
|
||||||
|
let kernelDisplayName: string = this.getKernelDisplayName();
|
||||||
|
if (kernelDisplayName) {
|
||||||
|
this.loadAttachToDropdown(this.model, kernelDisplayName, !validConnection);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private getKernelDisplayName(): string {
|
||||||
|
let kernelDisplayName: string;
|
||||||
|
if (this.model.clientSession && this.model.clientSession.kernel && this.model.clientSession.kernel.name) {
|
||||||
|
let currentKernelName = this.model.clientSession.kernel.name.toLowerCase();
|
||||||
|
let currentKernelSpec = this.model.specs.kernels.find(kernel => kernel.name && kernel.name.toLowerCase() === currentKernelName);
|
||||||
|
if (currentKernelSpec) {
|
||||||
|
kernelDisplayName = currentKernelSpec.display_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return kernelDisplayName;
|
||||||
|
}
|
||||||
|
|
||||||
// Load "Attach To" dropdown with the values corresponding to Kernel dropdown
|
// Load "Attach To" dropdown with the values corresponding to Kernel dropdown
|
||||||
public async loadAttachToDropdown(model: INotebookModel, currentKernel: string): Promise<void> {
|
public async loadAttachToDropdown(model: INotebookModel, currentKernel: string, showSelectConnection?: boolean): Promise<void> {
|
||||||
let connProviderIds = this.model.getApplicableConnectionProviderIds(currentKernel);
|
let connProviderIds = this.model.getApplicableConnectionProviderIds(currentKernel);
|
||||||
if ((connProviderIds && connProviderIds.length === 0) || currentKernel === noKernel) {
|
if ((connProviderIds && connProviderIds.length === 0) || currentKernel === noKernel) {
|
||||||
this.setOptions([msgLocalHost]);
|
this.setOptions([msgLocalHost]);
|
||||||
@@ -246,16 +270,30 @@ export class AttachToDropdown extends SelectBox {
|
|||||||
else {
|
else {
|
||||||
let connections = this.getConnections(model);
|
let connections = this.getConnections(model);
|
||||||
this.enable();
|
this.enable();
|
||||||
if (connections.length === 1 && connections[0] === msgAddNewConnection) {
|
if (showSelectConnection) {
|
||||||
connections.unshift(msgSelectConnection);
|
connections = this.loadWithSelectConnection(connections);
|
||||||
this.selectWithOptionName(msgSelectConnection);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
connections.push(msgAddNewConnection);
|
if (connections.length === 1 && connections[0] === msgAddNewConnection) {
|
||||||
|
connections.unshift(msgSelectConnection);
|
||||||
|
this.selectWithOptionName(msgSelectConnection);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
connections.push(msgAddNewConnection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.setOptions(connections);
|
this.setOptions(connections);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadWithSelectConnection(connections: string[]): string[] {
|
||||||
|
if (connections && connections.length > 0) {
|
||||||
|
connections.unshift(msgSelectConnection);
|
||||||
|
this.selectWithOptionName(msgSelectConnection);
|
||||||
|
connections.push(msgAddNewConnection);
|
||||||
|
this.setOptions(connections);
|
||||||
|
}
|
||||||
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get connections from context
|
//Get connections from context
|
||||||
|
|||||||
@@ -89,7 +89,11 @@ export class NotebookModelStub implements INotebookModel {
|
|||||||
}
|
}
|
||||||
getApplicableConnectionProviderIds(kernelName: string): string[] {
|
getApplicableConnectionProviderIds(kernelName: string): string[] {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
get onValidConnectionSelected(): Event<boolean>
|
||||||
|
{
|
||||||
|
throw new Error('method not implemented.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NotebookManagerStub implements INotebookManager {
|
export class NotebookManagerStub implements INotebookManager {
|
||||||
|
|||||||
Reference in New Issue
Block a user