Add Notebook Views dropdown (#16228)

This adds the entry point to NVs. It is currently hidden behind a feature flag, which can be enabled in the settings.
This commit is contained in:
Daniel Grajeda
2021-08-03 22:15:11 -06:00
committed by GitHub
parent da7585eb44
commit e2dd257fa9
13 changed files with 349 additions and 14 deletions

View File

@@ -7,15 +7,15 @@ import * as assert from 'assert';
import * as azdata from 'azdata';
import * as sinon from 'sinon';
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
import { AddCellAction, ClearAllOutputsAction, CollapseCellsAction, kernelNotSupported, KernelsDropdown, msgChanging, NewNotebookAction, noKernelName, noParameterCell, noParametersInCell, RunAllCellsAction, RunParametersAction, TrustedAction } from 'sql/workbench/contrib/notebook/browser/notebookActions';
import { ClientSessionStub, ContextViewProviderStub, NotebookComponentStub, NotebookModelStub, NotebookServiceStub } from 'sql/workbench/contrib/notebook/test/stubs';
import { AddCellAction, ClearAllOutputsAction, CollapseCellsAction, CreateNotebookViewAction, DashboardViewAction, kernelNotSupported, KernelsDropdown, msgChanging, NewNotebookAction, noKernelName, noParameterCell, noParametersInCell, NotebookViewAction, NotebookViewsActionProvider, RunAllCellsAction, RunParametersAction, TrustedAction } from 'sql/workbench/contrib/notebook/browser/notebookActions';
import { ClientSessionStub, ContextViewProviderStub, NotebookComponentStub, NotebookModelStub, NotebookServiceStub, NotebookViewsStub, NotebookViewStub } from 'sql/workbench/contrib/notebook/test/stubs';
import { NotebookEditorStub } from 'sql/workbench/contrib/notebook/test/testCommon';
import { ICellModel, INotebookModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
import { ICellModel, INotebookModel, ViewMode } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
import { IStandardKernelWithProvider } from 'sql/workbench/services/notebook/browser/models/notebookUtils';
import { INotebookEditor, INotebookService } from 'sql/workbench/services/notebook/browser/notebookService';
import { CellType, CellTypes } from 'sql/workbench/services/notebook/common/contracts';
import * as TypeMoq from 'typemoq';
import { Emitter } from 'vs/base/common/event';
import { Emitter, Event } from 'vs/base/common/event';
import { TestCommandService } from 'vs/editor/test/browser/editorTestServices';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationChangeEvent, IConfigurationOverrides, IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -26,6 +26,9 @@ import { workbenchInstantiationService } from 'vs/workbench/test/browser/workben
import { URI } from 'vs/base/common/uri';
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
import { MockQuickInputService } from 'sql/workbench/contrib/notebook/test/common/quickInputServiceMock';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { Separator } from 'vs/base/common/actions';
import { INotebookView, INotebookViews } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViews';
class TestClientSession extends ClientSessionStub {
private _errorState: boolean = false;
@@ -519,6 +522,50 @@ suite('Notebook Actions', function (): void {
assert.strictEqual(actualMsg, expectedMsg);
});
test('notebookViewsActionProvider', async () => {
const testGuid = '1';
const testName = 'Notebook-0';
const testNotebookModel: INotebookModel = <INotebookModel>{
viewMode: ViewMode.Notebook
};
const notebookEditor = new NotebookEditorStub({ model: testNotebookModel });
const mockNotification = TypeMoq.Mock.ofType<INotificationService>(TestNotificationService);
const notebookViews = TypeMoq.Mock.ofType<INotebookViews>(NotebookViewsStub);
const notebookView = TypeMoq.Mock.ofType<INotebookView>(NotebookViewStub);
notebookView.setup(x => x.guid).returns(() => testGuid);
notebookView.setup(x => x.name).returns(() => testName);
const views: INotebookView[] = [notebookView.object];
notebookViews.setup(x => x.getViews()).returns(() => views);
notebookViews.setup(x => x.getActiveView()).returns(() => undefined);
const notebookViewAction = new NotebookViewAction('notebookView.backToNotebook', 'Editor', 'notebook-button', mockNotebookService.object);
const createNotebookViewAction = new CreateNotebookViewAction('notebookView.newView', 'Create New View', 'notebook-button notebook-button-newview', mockNotebookService.object);
const separator = new Separator();
// Create a mocked out instantiation service
const mockInstantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Strict);
mockInstantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(NotebookViewAction), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => notebookViewAction);
mockInstantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(CreateNotebookViewAction), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => createNotebookViewAction);
mockInstantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(Separator))).returns(() => separator);
const viewsContainer = document.createElement('li');
const viewsActionsProvider = new NotebookViewsActionProvider(viewsContainer, notebookViews.object, notebookEditor.modelReady, mockNotebookService.object, mockNotification.object, mockInstantiationService.object);
await Event.toPromise(viewsActionsProvider.onUpdated);
const actions = viewsActionsProvider.getActions();
// It includes all the options
assert.strictEqual(actions.filter(a => a instanceof DashboardViewAction).length, 1);
assert.strictEqual(actions.filter(a => a instanceof NotebookViewAction).length, 1);
assert.strictEqual(actions.filter(a => a instanceof CreateNotebookViewAction).length, 1);
});
suite('Kernels dropdown', async () => {
let kernelsDropdown: KernelsDropdown;
let contextViewProvider: ContextViewProviderStub;

View File

@@ -132,6 +132,7 @@ suite('Notebook Editor Model', function (): void {
notebookParams: undefined,
modelReady: undefined,
model: notebookModel,
views: undefined,
isDirty: undefined,
isActive: undefined,
isVisible: undefined,

View File

@@ -19,6 +19,8 @@ import { QueryTextEditor } from 'sql/workbench/browser/modelComponents/queryText
import { IContextViewProvider, IDelegate } from 'vs/base/browser/ui/contextview/contextview';
import { IEditorPane } from 'vs/workbench/common/editor';
import { INotebookShowOptions } from 'sql/workbench/api/common/sqlExtHost.protocol';
import { NotebookViewsExtension } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViewsExtension';
import { INotebookView, INotebookViewCell, INotebookViews } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViews';
export class NotebookModelStub implements INotebookModel {
constructor(private _languageInfo?: nb.ILanguageInfo, private _cells?: ICellModel[], private _testContents?: nb.INotebookContents) {
@@ -490,6 +492,9 @@ export class NotebookComponentStub implements INotebookEditor {
get model(): INotebookModel {
throw new Error('Method not implemented.');
}
get views(): NotebookViewsExtension {
throw new Error('Method not implemented.');
}
isDirty(): boolean {
throw new Error('Method not implemented.');
}
@@ -684,6 +689,7 @@ export class NotebookEditorStub implements INotebookEditor {
cellEditors: CellEditorProviderStub[];
modelReady: Promise<INotebookModel>;
model: INotebookModel;
views: NotebookViewsExtension;
viewMode: string;
isDirty(): boolean {
throw new Error('Method not implemented.');
@@ -754,3 +760,77 @@ export class ContextViewProviderStub implements IContextViewProvider {
throw new Error('Method not implemented.');
}
}
export class NotebookViewStub implements INotebookView {
isNew: boolean;
name: string = '';
guid: string = '';
cells: readonly ICellModel[] = [];
hiddenCells: readonly ICellModel[];
displayedCells: readonly ICellModel[];
onDeleted: vsEvent.Event<INotebookView>;
initialize(): void {
throw new Error('Method not implemented.');
}
nameAvailable(name: string): boolean {
throw new Error('Method not implemented.');
}
getCellMetadata(cell: ICellModel): INotebookViewCell {
throw new Error('Method not implemented.');
}
hideCell(cell: ICellModel): void {
throw new Error('Method not implemented.');
}
moveCell(cell: ICellModel, x: number, y: number): void {
throw new Error('Method not implemented.');
}
resizeCell(cell: ICellModel, width: number, height: number): void {
throw new Error('Method not implemented.');
}
compactCells() {
throw new Error('Method not implemented.');
}
markAsViewed(): void {
throw new Error('Method not implemented.');
}
getCell(guid: string): Readonly<ICellModel> {
throw new Error('Method not implemented.');
}
insertCell(cell: ICellModel): void {
throw new Error('Method not implemented.');
}
save(): void {
throw new Error('Method not implemented.');
}
delete(): void {
throw new Error('Method not implemented.');
}
}
export class NotebookViewsStub implements INotebookViews {
notebook: INotebookModel;
onViewDeleted: vsEvent.Event<void>;
createNewView(name?: string): INotebookView {
throw new Error('Method not implemented.');
}
removeView(guid: string): void {
throw new Error('Method not implemented.');
}
generateDefaultViewName(): string {
throw new Error('Method not implemented.');
}
getViews(): INotebookView[] {
throw new Error('Method not implemented.');
}
getActiveView(): INotebookView {
throw new Error('Method not implemented.');
}
setActiveView(view: INotebookView): void {
throw new Error('Method not implemented.');
}
viewNameIsTaken(name: string): boolean {
throw new Error('Method not implemented.');
}
}

View File

@@ -13,15 +13,17 @@ import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtil
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { TestEditorGroupsService, TestEditorService, TestTextResourceConfigurationService } from 'vs/workbench/test/browser/workbenchTestServices';
import { TestStorageService } from 'vs/workbench/test/common/workbenchTestServices';
import { NotebookViewsExtension } from 'sql/workbench/services/notebook/browser/notebookViews/notebookViewsExtension';
// Typically you will pass in either editor or the instantiationService parameter.
// Leave both undefined when you want the underlying object(s) to have an undefined editor.
export class NotebookEditorStub extends stubs.NotebookEditorStub {
// Normally one needs to provide either the editor or the instantiationService as the constructor parameter
constructor({ cellGuid, instantiationService, editor, model, notebookParams }: { cellGuid?: string; instantiationService?: IInstantiationService; editor?: QueryTextEditor; model?: INotebookModel, notebookParams?: INotebookParams } = {}) {
constructor({ cellGuid, instantiationService, editor, model, views, notebookParams }: { cellGuid?: string; instantiationService?: IInstantiationService; editor?: QueryTextEditor; model?: INotebookModel, views?: NotebookViewsExtension, notebookParams?: INotebookParams } = {}) {
super();
this.cells = [];
this.model = model;
this.views = views;
this.notebookParams = notebookParams;
this.cellEditors = [new CellEditorProviderStub({ cellGuid: cellGuid, instantiationService: instantiationService, editor: editor })];
this.id = this.notebookParams?.notebookUri?.toString();