Hook up generateScriptButton to lastPageValidation (#13339)

This commit is contained in:
Arvind Ranasaria
2020-11-10 13:16:25 -08:00
committed by GitHub
parent 3dd74971d8
commit d7a6b55f82
4 changed files with 51 additions and 30 deletions

View File

@@ -57,10 +57,20 @@ export class NotebookWizardModel extends ResourceTypeModel {
public onCancel(): void {
}
public async onGenerateScript(): Promise<void> {
const notebook = await this.prepareNotebookAndEnvironment();
await this.openNotebook(notebook);
/**
* Generates the notebook and returns true on successful generation
**/
public async onGenerateScript(): Promise<boolean> {
const lastPage = this.wizard.lastPage! as NotebookWizardPage;
if (lastPage.validatePage()) {
const notebook = await this.prepareNotebookAndEnvironment();
await this.openNotebook(notebook);
return true;
} else {
return false;
}
}
public async onOk(): Promise<void> {
const notebook = await this.prepareNotebookAndEnvironment();
const openedNotebook = await this.openNotebook(notebook);

View File

@@ -108,31 +108,34 @@ export class NotebookWizardPage extends ResourceTypePage {
* The first condition checks that edge case.
*/
if (pcInfo.newPage === undefined || pcInfo.newPage > pcInfo.lastPage) {
const messages: string[] = [];
this.validators.forEach((validator) => {
const result = validator();
if (!result.valid) {
messages.push(result.message);
}
});
if (messages.length > 0) {
this.wizard.wizardObject.message = {
text:
messages.length === 1
? messages[0]
: localize(
"wizardPage.ValidationError",
"There are some errors on this page, click 'Show Details' to view the errors."
),
description: messages.length === 1 ? undefined : messages.join(EOL),
level: azdata.window.MessageLevel.Error,
};
}
return messages.length === 0;
return this.validatePage();
}
return true;
});
}
public validatePage(): boolean {
const messages: string[] = [];
this.validators.forEach((validator) => {
const result = validator();
if (!result.valid) {
messages.push(result.message);
}
});
if (messages.length > 0) {
this.wizard.wizardObject.message = {
text: messages.length === 1
? messages[0]
: localize(
"wizardPage.ValidationError",
"There are some errors on this page, click 'Show Details' to view the errors."
),
description: messages.length === 1 ? undefined : messages.join(EOL),
level: azdata.window.MessageLevel.Error,
};
}
return messages.length === 0;
}
}