mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Hook up generateScriptButton to lastPageValidation (#13339)
This commit is contained in:
@@ -57,10 +57,20 @@ export class NotebookWizardModel extends ResourceTypeModel {
|
|||||||
public onCancel(): void {
|
public onCancel(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async onGenerateScript(): Promise<void> {
|
/**
|
||||||
|
* 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();
|
const notebook = await this.prepareNotebookAndEnvironment();
|
||||||
await this.openNotebook(notebook);
|
await this.openNotebook(notebook);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async onOk(): Promise<void> {
|
public async onOk(): Promise<void> {
|
||||||
const notebook = await this.prepareNotebookAndEnvironment();
|
const notebook = await this.prepareNotebookAndEnvironment();
|
||||||
const openedNotebook = await this.openNotebook(notebook);
|
const openedNotebook = await this.openNotebook(notebook);
|
||||||
|
|||||||
@@ -108,6 +108,13 @@ export class NotebookWizardPage extends ResourceTypePage {
|
|||||||
* The first condition checks that edge case.
|
* The first condition checks that edge case.
|
||||||
*/
|
*/
|
||||||
if (pcInfo.newPage === undefined || pcInfo.newPage > pcInfo.lastPage) {
|
if (pcInfo.newPage === undefined || pcInfo.newPage > pcInfo.lastPage) {
|
||||||
|
return this.validatePage();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public validatePage(): boolean {
|
||||||
const messages: string[] = [];
|
const messages: string[] = [];
|
||||||
|
|
||||||
this.validators.forEach((validator) => {
|
this.validators.forEach((validator) => {
|
||||||
@@ -119,8 +126,7 @@ export class NotebookWizardPage extends ResourceTypePage {
|
|||||||
|
|
||||||
if (messages.length > 0) {
|
if (messages.length > 0) {
|
||||||
this.wizard.wizardObject.message = {
|
this.wizard.wizardObject.message = {
|
||||||
text:
|
text: messages.length === 1
|
||||||
messages.length === 1
|
|
||||||
? messages[0]
|
? messages[0]
|
||||||
: localize(
|
: localize(
|
||||||
"wizardPage.ValidationError",
|
"wizardPage.ValidationError",
|
||||||
@@ -132,7 +138,4 @@ export class NotebookWizardPage extends ResourceTypePage {
|
|||||||
}
|
}
|
||||||
return messages.length === 0;
|
return messages.length === 0;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ export abstract class ResourceTypeModel extends Model {
|
|||||||
abstract initialize(): void;
|
abstract initialize(): void;
|
||||||
abstract async onOk(): Promise<void>;
|
abstract async onOk(): Promise<void>;
|
||||||
abstract onCancel(): void;
|
abstract onCancel(): void;
|
||||||
async onGenerateScript(): Promise<void> { }
|
/**
|
||||||
|
* performs the script generation and returns true if script was generated successfully
|
||||||
|
**/
|
||||||
|
async onGenerateScript(): Promise<boolean> { return true; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ export class ResourceTypeWizard {
|
|||||||
return this._model;
|
return this._model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get lastPage(): ResourceTypePage | undefined {
|
||||||
|
return this.pages.length > 0 ? this.pages[this.pages.length - 1] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public resourceType: ResourceType,
|
public resourceType: ResourceType,
|
||||||
public _kubeService: IKubeService,
|
public _kubeService: IKubeService,
|
||||||
@@ -93,9 +97,10 @@ export class ResourceTypeWizard {
|
|||||||
this.dispose();
|
this.dispose();
|
||||||
}));
|
}));
|
||||||
this.toDispose.push(this.wizardObject.generateScriptButton.onClick(async () => {
|
this.toDispose.push(this.wizardObject.generateScriptButton.onClick(async () => {
|
||||||
await this._model.onGenerateScript();
|
if (await this._model.onGenerateScript()) {
|
||||||
this.dispose();
|
this.dispose();
|
||||||
this.wizardObject.close(); // close the wizard. This is already hooked up into doneButton, so it is not needed for that button above.
|
this.wizardObject.close(); // close the wizard. This is already hooked up into doneButton, so it is not needed for that button above.
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
this.toDispose.push(this.wizardObject.cancelButton.onClick(() => {
|
this.toDispose.push(this.wizardObject.cancelButton.onClick(() => {
|
||||||
this._model.onCancel();
|
this._model.onCancel();
|
||||||
|
|||||||
Reference in New Issue
Block a user