Fix #4047 Redesign notebook model to handle single client session (#4371)

* Start single client session based on the default kernel or saved kernel in NB.

* Added kernel displayName to standardKernel.
Modified name to allign wtih Juptyer Kernel.name.
So we can show the displayName during startup and use the name to start the session.

* Change session.OnSessionReady event in KernelDropDown

* Added model.KernelChnaged for switching kernel in the same provider

* Fixed session.Ready sequence

* Fixed merge issues

* Solve merged issue

* Fixed wrong kernel name in saved NB

* Added new event in Model to notify kernel change.
Toolbar depends on ModelReady to load

* Change attachTo to wait for ModelReady like KenelDropDown

* sanitizeSavedKernelInfo to fix invalid kernel and display_name. For example: PySpark1111 and PySpark 1111


* Added _contextsChangingEmitter to change loadContext msg when changing kernel

* Resolve PR comments
This commit is contained in:
Yurong He
2019-03-11 17:59:13 -07:00
committed by GitHub
parent b44d2b1bb3
commit 118d2c7273
20 changed files with 425 additions and 313 deletions

View File

@@ -12,7 +12,7 @@ import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview
import { INotificationService, Severity, INotificationActions } from 'vs/platform/notification/common/notification';
import { SelectBox, ISelectBoxOptionsWithLabel } from 'sql/base/browser/ui/selectBox/selectBox';
import { INotebookModel, IDefaultConnection } from 'sql/parts/notebook/models/modelInterfaces';
import { INotebookModel } from 'sql/parts/notebook/models/modelInterfaces';
import { CellType } from 'sql/parts/notebook/models/contracts';
import { NotebookComponent } from 'sql/parts/notebook/notebook.component';
import { getErrorMessage, formatServerNameWithDatabaseNameForAttachTo, getServerFromFormattedAttachToName, getDatabaseFromFormattedAttachToName } from 'sql/parts/notebook/notebookUtils';
@@ -21,6 +21,7 @@ import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilit
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { noKernel } from 'sql/workbench/services/notebook/common/sessionManager';
import { IConnectionDialogService } from 'sql/workbench/services/connection/common/connectionDialogService';
import { NotebookModel } from 'sql/parts/notebook/models/notebookModel';
const msgLoading = localize('loading', 'Loading kernels...');
const kernelLabel: string = localize('Kernel', 'Kernel: ');
@@ -233,16 +234,12 @@ export class TrustedAction extends ToggleableAction {
}
export class KernelsDropdown extends SelectBox {
private model: INotebookModel;
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, modelRegistered: Promise<INotebookModel>
) {
let selectBoxOptionsWithLabel: ISelectBoxOptionsWithLabel = {
labelText: kernelLabel,
labelOnTop: false
};
super([msgLoading], msgLoading, contextViewProvider, container, selectBoxOptionsWithLabel);
if (modelRegistered) {
modelRegistered
private model: NotebookModel;
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, modelReady: Promise<INotebookModel>) {
super([msgLoading], msgLoading, contextViewProvider, container, { labelText: kernelLabel, labelOnTop: false } as ISelectBoxOptionsWithLabel);
if (modelReady) {
modelReady
.then((model) => this.updateModel(model))
.catch((err) => {
// No-op for now
@@ -253,44 +250,42 @@ export class KernelsDropdown extends SelectBox {
}
updateModel(model: INotebookModel): void {
this.model = model;
this._register(model.kernelsChanged((defaultKernel) => {
this.updateKernel(defaultKernel);
this.model = model as NotebookModel;
this._register(this.model.kernelChanged((changedArgs: azdata.nb.IKernelChangedArgs) => {
this.updateKernel(changedArgs.newValue);
}));
if (model.clientSession) {
this._register(model.clientSession.kernelChanged((changedArgs: azdata.nb.IKernelChangedArgs) => {
if (changedArgs.newValue) {
this.updateKernel(changedArgs.newValue);
}
}));
}
}
// Update SelectBox values
private updateKernel(defaultKernel: azdata.nb.IKernelSpec) {
let specs = this.model.specs;
if (specs && specs.kernels) {
let index = specs.kernels.findIndex((kernel => kernel.name === defaultKernel.name));
this.setOptions(specs.kernels.map(kernel => kernel.display_name), index);
public updateKernel(kernel: azdata.nb.IKernel) {
if (kernel) {
let standardKernel = this.model.getStandardKernelFromName(kernel.name);
let kernels: string[] = this.model.standardKernelsDisplayName();
if (kernels && standardKernel) {
let index = kernels.findIndex((kernel => kernel === standardKernel.displayName));
this.setOptions(kernels, index);
}
}
}
public doChangeKernel(displayName: string): void {
this.setOptions([msgLoading], 0);
this.model.changeKernel(displayName);
}
}
export class AttachToDropdown extends SelectBox {
private model: INotebookModel;
private model: NotebookModel;
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, modelRegistered: Promise<INotebookModel>,
constructor(container: HTMLElement, contextViewProvider: IContextViewProvider, modelReady: Promise<INotebookModel>,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IConnectionDialogService private _connectionDialogService: IConnectionDialogService,
@INotificationService private _notificationService: INotificationService,
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService) {
super([msgLoadingContexts], msgLoadingContexts, contextViewProvider, container, { labelText: attachToLabel, labelOnTop: false } as ISelectBoxOptionsWithLabel);
if (modelRegistered) {
modelRegistered
if (modelReady) {
modelReady
.then(model => {
this.updateModel(model);
this.updateAttachToDropdown(model);
@@ -305,17 +300,19 @@ export class AttachToDropdown extends SelectBox {
}
public updateModel(model: INotebookModel): void {
this.model = model;
this.model = model as NotebookModel;
this._register(model.contextsChanged(() => {
let kernelDisplayName: string = this.getKernelDisplayName();
if (kernelDisplayName) {
this.loadAttachToDropdown(this.model, kernelDisplayName);
}
}));
this._register(this.model.contextsLoading(() => {
this.setOptions([msgLoadingContexts], 0);
}));
}
private updateAttachToDropdown(model: INotebookModel): void {
this.model = model;
model.onValidConnectionSelected(validConnection => {
let kernelDisplayName: string = this.getKernelDisplayName();
if (kernelDisplayName) {