GenerateToNotebook and Deploy buttons for Notebook Wizards (#12656)

* enable userChooses how to run notebook

* arc ext changes

* nb fixes

* working version

* revert unneeded changes

* fix comments

* Update interfaces.ts

* fix comments

* fix comments

* fix comments

* runAllCells instead of background execute

* pr feedback

* PR feedback

* pr feedback

* arc ext changes for new WizardInfo syntax

* fix doc comments

* pr feedback
This commit is contained in:
Arvind Ranasaria
2020-09-29 18:12:30 -07:00
committed by GitHub
parent fd5acf7ab1
commit b8de69dfac
15 changed files with 203 additions and 75 deletions

View File

@@ -3,7 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import * as loc from '../../localizedConstants';
import { INotebookService, Notebook } from '../../services/notebookService';
import { IToolsService } from '../../services/toolsService';
import { Model } from '../model';
@@ -14,8 +14,6 @@ import { IPlatformService } from './../../services/platformService';
import { NotebookWizardAutoSummaryPage } from './notebookWizardAutoSummaryPage';
import { NotebookWizardPage } from './notebookWizardPage';
const localize = nls.loadMessageBundle();
export class NotebookWizard extends WizardBase<NotebookWizard, NotebookWizardPage, Model> {
private _inputComponents: InputComponents = {};
@@ -40,7 +38,8 @@ export class NotebookWizard extends WizardBase<NotebookWizard, NotebookWizardPag
if (this._wizardInfo.codeCellInsertionPosition === undefined) {
this._wizardInfo.codeCellInsertionPosition = 0;
}
this.wizardObject.doneButton.label = _wizardInfo.actionText || this.wizardObject.doneButton.label;
this.wizardObject.doneButton.label = _wizardInfo.doneAction?.label || loc.deployNotebook;
this.wizardObject.generateScriptButton.label = _wizardInfo.scriptAction?.label || loc.scriptToNotebook;
}
public get deploymentType(): DeploymentType | undefined {
@@ -49,17 +48,37 @@ export class NotebookWizard extends WizardBase<NotebookWizard, NotebookWizardPag
protected initialize(): void {
this.setPages(this.getPages());
this.wizardObject.generateScriptButton.hidden = true;
this.wizardInfo.actionText = this.wizardInfo.actionText || localize('notebookWizard.ScriptToNotebook', "Script to Notebook");
this.wizardObject.doneButton.label = this.wizardInfo.actionText;
}
protected onCancel(): void {
}
protected async onGenerateScript(): Promise<void> {
try {
const notebook = await this.prepareNotebookAndEnvironment();
await this.openNotebook(notebook);
} catch (error) {
vscode.window.showErrorMessage(error);
}
}
protected async onOk(): Promise<void> {
try {
const notebook = await this.prepareNotebookAndEnvironment();
const openedNotebook = await this.openNotebook(notebook);
openedNotebook.runAllCells();
} catch (error) {
vscode.window.showErrorMessage(error);
}
}
private async openNotebook(notebook: Notebook) {
const notebookPath = this.notebookService.getNotebookPath(this.wizardInfo.notebook);
return await this.notebookService.openNotebookWithContent(notebookPath, JSON.stringify(notebook, undefined, 4));
}
private async prepareNotebookAndEnvironment() {
await setModelValues(this.inputComponents, this.model);
const env: NodeJS.ProcessEnv = {};
const env: NodeJS.ProcessEnv = process.env;
this.model.setEnvironmentVariables(env, (varName) => {
const isPassword = !!this.inputComponents[varName]?.isPassword;
return isPassword;
@@ -85,17 +104,7 @@ export class NotebookWizard extends WizardBase<NotebookWizard, NotebookWizardPag
execution_count: 0
}
);
try {
if (this.wizardInfo.runNotebook) {
this.notebookService.backgroundExecuteNotebook(this.wizardInfo.taskName, notebook, 'deploy', this.platformService, env);
} else {
Object.assign(process.env, env);
const notebookPath = this.notebookService.getNotebookPath(this.wizardInfo.notebook);
await this.notebookService.launchNotebookWithContent(notebookPath, JSON.stringify(notebook, undefined, 4));
}
} catch (error) {
vscode.window.showErrorMessage(error);
}
return notebook;
}
private getPages(): NotebookWizardPage[] {

View File

@@ -9,6 +9,7 @@ import * as nls from 'vscode-nls';
import { NotebookWizardPageInfo } from '../../interfaces';
import { initializeWizardPage, InputComponentInfo, setModelValues, Validator } from '../modelViewUtils';
import { WizardPageBase } from '../wizardPageBase';
import { WizardPageInfo } from '../wizardPageInfo';
import { NotebookWizard } from './notebookWizard';
const localize = nls.loadMessageBundle();
@@ -32,6 +33,20 @@ export class NotebookWizardPage extends WizardPageBase<NotebookWizard> {
);
}
/**
* If the return value is true then done button should be visible to the user
*/
private get isDoneButtonVisible(): boolean {
return !!this.wizard.wizardInfo.doneAction;
}
/**
* If the return value is true then generateScript button should be visible to the user
*/
private get isGenerateScriptButtonVisible(): boolean {
return !!this.wizard.wizardInfo.scriptAction;
}
public initialize(): void {
initializeWizardPage({
container: this.wizard.wizardObject,
@@ -64,7 +79,17 @@ export class NotebookWizardPage extends WizardPageBase<NotebookWizard> {
});
}
public async onEnter(): Promise<void> {
public async onEnter(pageInfo: WizardPageInfo): Promise<void> {
if (pageInfo.isLastPage) {
// on the last page either one or both of done button and generateScript button are visible depending on configuration of 'runNotebook' in wizard info
this.wizard.wizardObject.doneButton.hidden = !this.isDoneButtonVisible;
this.wizard.wizardObject.generateScriptButton.hidden = !this.isGenerateScriptButtonVisible;
} else {
//on any page but the last page doneButton and generateScriptButton are hidden
this.wizard.wizardObject.doneButton.hidden = true;
this.wizard.wizardObject.generateScriptButton.hidden = true;
}
if (this.pageInfo.isSummaryPage) {
await setModelValues(this.wizard.inputComponents, this.wizard.model);
}