Add notebook feature flag that is enabled by default (#3210)

* Add notebook feature flag that is enabled by default
- After this, the `notebook.enabled` flag must be set to true when testing notebook integration
This commit is contained in:
Kevin Cunnane
2018-11-14 11:33:22 -08:00
committed by GitHub
parent d8cd78cd6b
commit 43faa13cb5
3 changed files with 58 additions and 25 deletions

View File

@@ -16,7 +16,7 @@ import { QueryResultsInput } from 'sql/parts/query/common/queryResultsInput';
import { QueryInput } from 'sql/parts/query/common/queryInput'; import { QueryInput } from 'sql/parts/query/common/queryInput';
import { IQueryEditorOptions } from 'sql/parts/query/common/queryEditorService'; import { IQueryEditorOptions } from 'sql/parts/query/common/queryEditorService';
import { QueryPlanInput } from 'sql/parts/queryPlan/queryPlanInput'; import { QueryPlanInput } from 'sql/parts/queryPlan/queryPlanInput';
import { NotebookInput, NotebookInputModel } from 'sql/parts/notebook/notebookInput'; import { NotebookInput, NotebookInputModel, NotebookInputValidator } from 'sql/parts/notebook/notebookInput';
import { Extensions, INotebookProviderRegistry } from 'sql/services/notebook/notebookRegistry'; import { Extensions, INotebookProviderRegistry } from 'sql/services/notebook/notebookRegistry';
import { DEFAULT_NOTEBOOK_PROVIDER } from 'sql/services/notebook/notebookService'; import { DEFAULT_NOTEBOOK_PROVIDER } from 'sql/services/notebook/notebookService';
@@ -57,8 +57,9 @@ export function convertEditorInput(input: EditorInput, options: IQueryEditorOpti
} }
//Notebook //Notebook
let notebookValidator = instantiationService.createInstance(NotebookInputValidator);
uri = getNotebookEditorUri(input); uri = getNotebookEditorUri(input);
if(uri){ if(uri && notebookValidator.isNotebookEnabled()){
//TODO: We need to pass in notebook data either through notebook input or notebook service //TODO: We need to pass in notebook data either through notebook input or notebook service
let fileName: string = 'untitled'; let fileName: string = 'untitled';
let providerId: string = DEFAULT_NOTEBOOK_PROVIDER; let providerId: string = DEFAULT_NOTEBOOK_PROVIDER;
@@ -162,6 +163,8 @@ function getNotebookEditorUri(input: EditorInput): URI {
return undefined; return undefined;
} }
// If this editor is not already of type notebook input // If this editor is not already of type notebook input
if (!(input instanceof NotebookInput)) { if (!(input instanceof NotebookInput)) {
let uri: URI = getSupportedInputResource(input); let uri: URI = getSupportedInputResource(input);

View File

@@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor'; import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { IConfigurationRegistry, Extensions as ConfigExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions'; import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { Action } from 'vs/base/common/actions'; import { Action } from 'vs/base/common/actions';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
@@ -15,8 +15,9 @@ import URI from 'vs/base/common/uri';
import { localize } from 'vs/nls'; import { localize } from 'vs/nls';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { NotebookInput, NotebookInputModel } from 'sql/parts/notebook/notebookInput'; import { NotebookInput, NotebookInputModel, notebooksEnabledCondition } from 'sql/parts/notebook/notebookInput';
import { NotebookEditor } from 'sql/parts/notebook/notebookEditor'; import { NotebookEditor } from 'sql/parts/notebook/notebookEditor';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
let counter = 0; let counter = 0;
@@ -25,10 +26,10 @@ let counter = 0;
* todo: Will remove this code. * todo: Will remove this code.
* This is the entry point to open the new Notebook * This is the entry point to open the new Notebook
*/ */
export class OpenNotebookAction extends Action { export class NewNotebookAction extends Action {
public static ID = 'OpenNotebookAction'; public static ID = 'workbench.action.newnotebook';
public static LABEL = localize('OpenNotebookAction', 'Open Notebook editor'); public static LABEL = localize('workbench.action.newnotebook.description', 'New Notebook');
constructor( constructor(
id: string, id: string,
@@ -40,12 +41,11 @@ export class OpenNotebookAction extends Action {
} }
public run(): TPromise<void> { public run(): TPromise<void> {
return new TPromise<void>((resolve, reject) => { let title = `Untitled-${counter++}`;
let untitledUri = URI.from({ scheme: Schemas.untitled, path: `Untitled-${counter++}`}); let untitledUri = URI.from({ scheme: Schemas.untitled, path: title });
let model = new NotebookInputModel(untitledUri, undefined, false, undefined); let model = new NotebookInputModel(untitledUri, undefined, false, undefined);
let input = this._instantiationService.createInstance(NotebookInput, 'modelViewId', model); let input = this._instantiationService.createInstance(NotebookInput, title, model);
this._editorService.openEditor(input, { pinned: true }); return this._editorService.openEditor(input, { pinned: true }).then(() => undefined);
});
} }
} }
@@ -59,15 +59,30 @@ const viewModelEditorDescriptor = new EditorDescriptor(
Registry.as<IEditorRegistry>(EditorExtensions.Editors) Registry.as<IEditorRegistry>(EditorExtensions.Editors)
.registerEditor(viewModelEditorDescriptor, [new SyncDescriptor(NotebookInput)]); .registerEditor(viewModelEditorDescriptor, [new SyncDescriptor(NotebookInput)]);
// todo: Will remove this code. // Feature flag for built-in Notebooks. Will be removed in the future.
// this is the entry point to open the new Notebook const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigExtensions.Configuration);
let actionRegistry = <IWorkbenchActionRegistry>Registry.as(Extensions.WorkbenchActions); configurationRegistry.registerConfiguration({
actionRegistry.registerWorkbenchAction( 'id': 'notebook',
new SyncActionDescriptor( 'title': 'Notebook',
OpenNotebookAction, 'type': 'object',
OpenNotebookAction.ID, 'properties': {
OpenNotebookAction.LABEL 'notebook.enabled': {
), 'type': 'boolean',
OpenNotebookAction.LABEL 'default': false,
); 'description': localize('notebook.enabledDescription', 'Enable viewing notebook files using built-in notebook editor.')
}
}
});
// this is the entry point to open the new Notebook
CommandsRegistry.registerCommand(NewNotebookAction.ID, serviceAccessor => {
serviceAccessor.get(IInstantiationService).createInstance(NewNotebookAction, NewNotebookAction.ID, NewNotebookAction.LABEL).run();
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: NewNotebookAction.ID,
title:NewNotebookAction.LABEL,
},
when: notebooksEnabledCondition
});

View File

@@ -10,10 +10,15 @@ import { IEditorModel } from 'vs/platform/editor/common/editor';
import { EditorInput, EditorModel, ConfirmResult } from 'vs/workbench/common/editor'; import { EditorInput, EditorModel, ConfirmResult } from 'vs/workbench/common/editor';
import { Emitter, Event } from 'vs/base/common/event'; import { Emitter, Event } from 'vs/base/common/event';
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { INotebookService } from 'sql/services/notebook/notebookService'; import { INotebookService } from 'sql/services/notebook/notebookService';
export type ModeViewSaveHandler = (handle: number) => Thenable<boolean>; export type ModeViewSaveHandler = (handle: number) => Thenable<boolean>;
export let notebooksEnabledCondition = ContextKeyExpr.equals('config.notebook.enabled', true);
export class NotebookInputModel extends EditorModel { export class NotebookInputModel extends EditorModel {
private dirty: boolean; private dirty: boolean;
private readonly _onDidChangeDirty: Emitter<void> = this._register(new Emitter<void>()); private readonly _onDidChangeDirty: Emitter<void> = this._register(new Emitter<void>());
@@ -59,6 +64,16 @@ export class NotebookInputModel extends EditorModel {
return TPromise.wrap(true); return TPromise.wrap(true);
} }
} }
export class NotebookInputValidator {
constructor(@IContextKeyService private readonly _contextKeyService: IContextKeyService) {}
public isNotebookEnabled(): boolean {
return this._contextKeyService.contextMatchesRules(notebooksEnabledCondition);
}
}
export class NotebookInput extends EditorInput { export class NotebookInput extends EditorInput {
public static ID: string = 'workbench.editorinputs.notebookInput'; public static ID: string = 'workbench.editorinputs.notebookInput';