mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 17:22:59 -05:00
skuRecommendationPage & azdata change (#11863)
* skuRecommendationPage * fix
This commit is contained in:
98
extensions/sql-migration/src/wizard/skuRecommendationPage.ts
Normal file
98
extensions/sql-migration/src/wizard/skuRecommendationPage.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { MigrationWizardPage } from '../models/migrationWizardPage';
|
||||
import { MigrationStateModel, StateChangeEvent } from '../models/stateMachine';
|
||||
import { Product } from '../models/product';
|
||||
import { CONGRATULATIONS, SKU_RECOMMENDATION_PAGE_TITLE, SKU_RECOMMENDATION_ALL_SUCCESSFUL } from '../models/strings';
|
||||
|
||||
export class SKURecommendationPage extends MigrationWizardPage {
|
||||
// For future reference: DO NOT EXPOSE WIZARD DIRECTLY THROUGH HERE.
|
||||
constructor(wizard: azdata.window.Wizard, migrationStateModel: MigrationStateModel) {
|
||||
super(wizard, azdata.window.createWizardPage(SKU_RECOMMENDATION_PAGE_TITLE), migrationStateModel);
|
||||
}
|
||||
|
||||
protected async registerContent(view: azdata.ModelView) {
|
||||
await this.initialState(view);
|
||||
}
|
||||
|
||||
private igComponent: azdata.FormComponent<azdata.TextComponent> | undefined;
|
||||
private detailsComponent: azdata.FormComponent<azdata.TextComponent> | undefined;
|
||||
private async initialState(view: azdata.ModelView) {
|
||||
this.igComponent = this.createIGComponent(view);
|
||||
this.detailsComponent = this.createDetailsComponent(view);
|
||||
}
|
||||
|
||||
private createIGComponent(view: azdata.ModelView): azdata.FormComponent<azdata.TextComponent> {
|
||||
const component = view.modelBuilder.text().withProperties<azdata.TextComponentProperties>({
|
||||
value: '',
|
||||
});
|
||||
|
||||
return {
|
||||
title: '',
|
||||
component: component.component(),
|
||||
};
|
||||
}
|
||||
|
||||
private createDetailsComponent(view: azdata.ModelView): azdata.FormComponent<azdata.TextComponent> {
|
||||
const component = view.modelBuilder.text().withProperties<azdata.TextComponentProperties>({
|
||||
value: '',
|
||||
});
|
||||
|
||||
return {
|
||||
title: '',
|
||||
component: component.component(),
|
||||
};
|
||||
}
|
||||
|
||||
private constructDetails(): void {
|
||||
const recommendations = this.migrationStateModel.skuRecommendations?.recommendations;
|
||||
|
||||
if (!recommendations) {
|
||||
return;
|
||||
}
|
||||
|
||||
const products = recommendations.map(recommendation => {
|
||||
return {
|
||||
checks: recommendation.checks,
|
||||
product: Product.FromMigrationProduct(recommendation.product)
|
||||
};
|
||||
});
|
||||
|
||||
const migratableDatabases: number = products?.length ?? 10; // force it to be used
|
||||
|
||||
const allDatabases = 10;
|
||||
|
||||
if (allDatabases === migratableDatabases) {
|
||||
this.allMigratable(migratableDatabases);
|
||||
}
|
||||
|
||||
// TODO handle other situations
|
||||
|
||||
}
|
||||
|
||||
private allMigratable(databaseCount: number): void {
|
||||
this.igComponent!.title = CONGRATULATIONS;
|
||||
this.igComponent!.component.value = SKU_RECOMMENDATION_ALL_SUCCESSFUL(databaseCount);
|
||||
this.detailsComponent!.component.value = ''; // force it to be used
|
||||
// fill in some of that information
|
||||
}
|
||||
|
||||
public async onPageEnter(): Promise<void> {
|
||||
this.constructDetails();
|
||||
}
|
||||
|
||||
public async onPageLeave(): Promise<void> {
|
||||
|
||||
}
|
||||
|
||||
protected async handleStateChange(e: StateChangeEvent): Promise<void> {
|
||||
switch (e.newState) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,26 +10,12 @@ import { MigrationStateModel, StateChangeEvent, State } from '../models/stateMac
|
||||
import { Disposable } from 'vscode';
|
||||
|
||||
export class SourceConfigurationPage extends MigrationWizardPage {
|
||||
constructor(migrationStateModel: MigrationStateModel) {
|
||||
super(azdata.window.createWizardPage(SOURCE_CONFIGURATION_PAGE_TITLE), migrationStateModel);
|
||||
// For future reference: DO NOT EXPOSE WIZARD DIRECTLY THROUGH HERE.
|
||||
constructor(wizard: azdata.window.Wizard, migrationStateModel: MigrationStateModel) {
|
||||
super(wizard, azdata.window.createWizardPage(SOURCE_CONFIGURATION_PAGE_TITLE), migrationStateModel);
|
||||
}
|
||||
|
||||
public async registerWizardContent(): Promise<void> {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
this.wizardPage.registerContent(async (view) => {
|
||||
try {
|
||||
await this.registerContent(view);
|
||||
resolve();
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
} finally {
|
||||
reject(new Error());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private async registerContent(view: azdata.ModelView) {
|
||||
protected async registerContent(view: azdata.ModelView) {
|
||||
await this.initialState(view);
|
||||
}
|
||||
|
||||
@@ -58,7 +44,7 @@ export class SourceConfigurationPage extends MigrationWizardPage {
|
||||
}
|
||||
|
||||
private async enterTargetSelectionState() {
|
||||
|
||||
this.goToNextPage();
|
||||
}
|
||||
|
||||
//#region component builders
|
||||
@@ -91,8 +77,11 @@ export class SourceConfigurationPage extends MigrationWizardPage {
|
||||
case State.COLLECTION_SOURCE_INFO_ERROR:
|
||||
return this.enterErrorState();
|
||||
case State.TARGET_SELECTION:
|
||||
// TODO: Allow pressing next in this state
|
||||
return this.enterTargetSelectionState();
|
||||
}
|
||||
}
|
||||
|
||||
public async canLeave(): Promise<boolean> {
|
||||
return this.migrationStateModel.currentState === State.TARGET_SELECTION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export class WizardController {
|
||||
private async createWizard(stateModel: MigrationStateModel): Promise<void> {
|
||||
const wizard = azdata.window.createWizard(WIZARD_TITLE, 'wide');
|
||||
wizard.generateScriptButton.enabled = false;
|
||||
const sourceConfigurationPage = new SourceConfigurationPage(stateModel);
|
||||
const sourceConfigurationPage = new SourceConfigurationPage(wizard, stateModel);
|
||||
|
||||
const pages: MigrationWizardPage[] = [sourceConfigurationPage];
|
||||
|
||||
@@ -42,6 +42,14 @@ export class WizardController {
|
||||
await pages[newPage]?.onPageEnter();
|
||||
});
|
||||
|
||||
wizard.registerNavigationValidator(async validator => {
|
||||
const lastPage = validator.lastPage;
|
||||
|
||||
const canLeave = await pages[lastPage]?.canLeave() ?? true;
|
||||
const canEnter = await pages[lastPage]?.canEnter() ?? true;
|
||||
|
||||
return canEnter && canLeave;
|
||||
});
|
||||
|
||||
await Promise.all(wizardSetupPromises);
|
||||
await pages[0].onPageEnter();
|
||||
|
||||
Reference in New Issue
Block a user