Save And Close Functionality (#17000)

* save and close

* wip

* working save and close

* cleanup

* pr changes

* pr changes

* fix capitalization

* fix build

* pr fix
This commit is contained in:
Christopher Suh
2021-09-24 14:59:35 -07:00
committed by GitHub
parent 177b56c5ff
commit 207254fa6c
12 changed files with 386 additions and 25 deletions

View File

@@ -24,6 +24,7 @@ export class AccountsSelectionPage extends MigrationWizardPage {
}
protected async registerContent(view: azdata.ModelView): Promise<void> {
this.wizard.customButtons[0].enabled = true;
const form = view.modelBuilder.formContainer()
.withFormItems(
[
@@ -95,6 +96,14 @@ export class AccountsSelectionPage extends MigrationWizardPage {
await this._accountTenantFlexContainer.updateCssStyles({
'display': 'none'
});
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= 0) {
(<azdata.CategoryValue[]>this._azureAccountsDropdown.values)?.forEach((account, index) => {
if (account.name === this.migrationStateModel.savedInfo.azureAccount?.displayInfo.userId) {
selectDropDownIndex(this._azureAccountsDropdown, index);
}
});
}
}
this.migrationStateModel._subscriptions = undefined!;
this.migrationStateModel._targetSubscription = undefined!;
@@ -162,12 +171,17 @@ export class AccountsSelectionPage extends MigrationWizardPage {
* All azure requests will only run on this tenant from now on
*/
const selectedIndex = findDropDownItemIndex(this._accountTenantDropdown, value);
const selectedTenant = this.migrationStateModel.getTenant(selectedIndex);
this.migrationStateModel._azureTenant = deepClone(selectedTenant);
if (selectedIndex > -1) {
this.migrationStateModel._azureAccount.properties.tenants = [this.migrationStateModel.getTenant(selectedIndex)];
this.migrationStateModel._subscriptions = undefined!;
this.migrationStateModel._targetSubscription = undefined!;
this.migrationStateModel._databaseBackup.subscription = undefined!;
}
const selectedAzureAccount = this.migrationStateModel.getAccount(selectedIndex);
this.migrationStateModel._azureAccount = deepClone(selectedAzureAccount);
}));
this._accountTenantFlexContainer = view.modelBuilder.flexContainer()

View File

@@ -105,7 +105,6 @@ export class DatabaseSelectorPage extends MigrationWizardPage {
|| assessedDatabases.length !== selectedDatabases.length
|| assessedDatabases.some(db => selectedDatabases.indexOf(db) < 0);
this.migrationStateModel._databaseAssessment = selectedDatabases;
this.wizard.message = {
text: '',
level: azdata.window.MessageLevel.Error
@@ -287,11 +286,17 @@ export class DatabaseSelectorPage extends MigrationWizardPage {
}
).component();
await this._databaseSelectorTable.setDataValues(this._databaseTableValues);
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= 1) {
await this._databaseSelectorTable.setDataValues(this.migrationStateModel.savedInfo.selectedDatabases);
} else {
await this._databaseSelectorTable.setDataValues(this._databaseTableValues);
}
this._disposables.push(this._databaseSelectorTable.onDataChanged(async () => {
await this._dbCount.updateProperties({
'value': constants.DATABASES_SELECTED(this.selectedDbs().length, this._databaseTableValues.length)
});
this.migrationStateModel._databaseAssessment = this.selectedDbs();
this.migrationStateModel.databaseSelectorTableValues = <azdata.DeclarativeTableCellValue[][]>this._databaseSelectorTable.dataValues;
}));
const flex = view.modelBuilder.flexContainer().withLayout({
flexFlow: 'column',

View File

@@ -97,6 +97,15 @@ export class MigrationModePage extends MigrationWizardPage {
}
}).component();
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= 3) {
if (this.migrationStateModel.savedInfo.migrationMode === MigrationMode.ONLINE) {
onlineButton.checked = true;
offlineButton.checked = false;
} else {
onlineButton.checked = false;
offlineButton.checked = true;
}
}
this._disposables.push(offlineButton.onDidChangeCheckedState((e) => {
if (e) {

View File

@@ -6,7 +6,7 @@
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { MigrationWizardPage } from '../models/migrationWizardPage';
import { MigrationStateModel, MigrationTargetType, StateChangeEvent } from '../models/stateMachine';
import { MigrationStateModel, MigrationTargetType, ServerAssessment, StateChangeEvent } from '../models/stateMachine';
import { AssessmentResultsDialog } from '../dialog/assessmentResults/assessmentResultsDialog';
import * as constants from '../constants/strings';
import { EOL } from 'os';
@@ -259,7 +259,13 @@ export class SKURecommendationPage extends MigrationWizardPage {
width: 100
}).component();
const serverName = (await this.migrationStateModel.getSourceConnectionProfile()).serverName;
let serverName = '';
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.serverName) {
serverName = this.migrationStateModel.serverName;
} else {
serverName = (await this.migrationStateModel.getSourceConnectionProfile()).serverName;
}
let miDialog = new AssessmentResultsDialog('ownerUri', this.migrationStateModel, constants.ASSESSMENT_TILE(serverName), this, MigrationTargetType.SQLMI);
let vmDialog = new AssessmentResultsDialog('ownerUri', this.migrationStateModel, constants.ASSESSMENT_TILE(serverName), this, MigrationTargetType.SQLVM);
@@ -467,7 +473,11 @@ export class SKURecommendationPage extends MigrationWizardPage {
const serverName = (await this.migrationStateModel.getSourceConnectionProfile()).serverName;
this._igComponent.value = constants.ASSESSMENT_COMPLETED(serverName);
try {
await this.migrationStateModel.getDatabaseAssessments(MigrationTargetType.SQLMI);
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage) {
this.migrationStateModel._assessmentResults = <ServerAssessment>this.migrationStateModel.savedInfo.serverAssessment;
} else {
await this.migrationStateModel.getDatabaseAssessments(MigrationTargetType.SQLMI);
}
this._detailsComponent.value = constants.SKU_RECOMMENDATION_ALL_SUCCESSFUL(this.migrationStateModel._assessmentResults.databaseAssessments.length);
const errors: string[] = [];
@@ -506,18 +516,29 @@ errorId: ${e.errorId}
}
private async populateSubscriptionDropdown(): Promise<void> {
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= 0) {
this.migrationStateModel._azureAccount = <azdata.Account>this.migrationStateModel.savedInfo.azureAccount;
}
if (!this.migrationStateModel._targetSubscription) {
this._managedInstanceSubscriptionDropdown.loading = true;
this._resourceDropdown.loading = true;
try {
this._managedInstanceSubscriptionDropdown.values = await this.migrationStateModel.getSubscriptionsDropdownValues();
selectDropDownIndex(this._managedInstanceSubscriptionDropdown, 0);
} catch (e) {
console.log(e);
} finally {
this._managedInstanceSubscriptionDropdown.loading = false;
this._resourceDropdown.loading = false;
}
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= 2 && this._managedInstanceSubscriptionDropdown.values) {
this._managedInstanceSubscriptionDropdown.values.forEach((subscription, index) => {
if ((<azdata.CategoryValue>subscription).name === this.migrationStateModel.savedInfo?.subscription?.id) {
selectDropDownIndex(this._managedInstanceSubscriptionDropdown, index);
}
});
} else {
selectDropDownIndex(this._managedInstanceSubscriptionDropdown, 0);
}
}
}
@@ -526,9 +547,25 @@ errorId: ${e.errorId}
this._azureLocationDropdown.loading = true;
try {
this._azureResourceGroupDropdown.values = await this.migrationStateModel.getAzureResourceGroupDropdownValues(this.migrationStateModel._targetSubscription);
selectDropDownIndex(this._azureResourceGroupDropdown, 0);
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= 2 && this._azureResourceGroupDropdown.values) {
this._azureResourceGroupDropdown.values.forEach((resourceGroup, index) => {
if (resourceGroup.name === this.migrationStateModel.savedInfo?.resourceGroup?.id) {
selectDropDownIndex(this._azureResourceGroupDropdown, index);
}
});
} else {
selectDropDownIndex(this._azureResourceGroupDropdown, 0);
}
this._azureLocationDropdown.values = await this.migrationStateModel.getAzureLocationDropdownValues(this.migrationStateModel._targetSubscription);
selectDropDownIndex(this._azureLocationDropdown, 0);
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= 2 && this._azureLocationDropdown.values) {
this._azureLocationDropdown.values.forEach((location, index) => {
if (location.displayName === this.migrationStateModel.savedInfo?.location?.displayName) {
selectDropDownIndex(this._azureLocationDropdown, index);
}
});
} else {
selectDropDownIndex(this._azureLocationDropdown, 0);
}
} catch (e) {
console.log(e);
} finally {
@@ -555,8 +592,15 @@ errorId: ${e.errorId}
this.migrationStateModel._location,
this.migrationStateModel._resourceGroup);
}
selectDropDownIndex(this._resourceDropdown, 0);
if (this.migrationStateModel.resumeAssessment && this.migrationStateModel.savedInfo.closedPage >= 2 && this._resourceDropdown.values) {
this._resourceDropdown.values.forEach((resource, index) => {
if (resource.displayName === this.migrationStateModel.savedInfo?.targetServerInstance?.name) {
selectDropDownIndex(this._resourceDropdown, index);
}
});
} else {
selectDropDownIndex(this._resourceDropdown, 0);
}
} catch (e) {
console.log(e);
} finally {

View File

@@ -21,6 +21,7 @@ export class SqlSourceConfigurationPage extends MigrationWizardPage {
}
protected async registerContent(view: azdata.ModelView): Promise<void> {
this.wizard.customButtons[0].enabled = true;
this._view = view;
const form = view.modelBuilder.formContainer()
.withFormItems(

View File

@@ -21,14 +21,13 @@ export const WIZARD_INPUT_COMPONENT_WIDTH = '600px';
export class WizardController {
private _wizardObject!: azdata.window.Wizard;
private _model!: MigrationStateModel;
constructor(private readonly extensionContext: vscode.ExtensionContext) {
constructor(private readonly extensionContext: vscode.ExtensionContext, model: MigrationStateModel) {
this._model = model;
}
public async openWizard(connectionId: string): Promise<void> {
const api = (await vscode.extensions.getExtension(mssql.extension.name)?.activate()) as mssql.IExtension;
if (api) {
this._model = new MigrationStateModel(this.extensionContext, connectionId, api.sqlMigration);
this.extensionContext.subscriptions.push(this._model);
await this.createWizard(this._model);
}
@@ -39,6 +38,8 @@ export class WizardController {
this._wizardObject = azdata.window.createWizard(loc.WIZARD_TITLE(serverName), 'MigrationWizard', 'wide');
this._wizardObject.generateScriptButton.enabled = false;
this._wizardObject.generateScriptButton.hidden = true;
const saveAndCloseButton = azdata.window.createButton(loc.SAVE_AND_CLOSE);
this._wizardObject.customButtons = [saveAndCloseButton];
const skuRecommendationPage = new SKURecommendationPage(this._wizardObject, stateModel);
const migrationModePage = new MigrationModePage(this._wizardObject, stateModel);
const databaseSelectorPage = new DatabaseSelectorPage(this._wizardObject, stateModel);
@@ -62,8 +63,11 @@ export class WizardController {
const wizardSetupPromises: Thenable<void>[] = [];
wizardSetupPromises.push(...pages.map(p => p.registerWizardContent()));
wizardSetupPromises.push(this._wizardObject.open());
if (this._model.resumeAssessment) {
wizardSetupPromises.push(this._wizardObject.setCurrentPage(this._model.savedInfo.closedPage));
}
this.extensionContext.subscriptions.push(this._wizardObject.onPageChanged(async (pageChangeInfo: azdata.window.WizardPageChangeInfo) => {
this._model.extensionContext.subscriptions.push(this._wizardObject.onPageChanged(async (pageChangeInfo: azdata.window.WizardPageChangeInfo) => {
const newPage = pageChangeInfo.newPage;
const lastPage = pageChangeInfo.lastPage;
this.sendPageButtonClickEvent(pageChangeInfo).catch(e => console.log(e));
@@ -82,13 +86,17 @@ export class WizardController {
});
await Promise.all(wizardSetupPromises);
this.extensionContext.subscriptions.push(this._wizardObject.onPageChanged(async (pageChangeInfo: azdata.window.WizardPageChangeInfo) => {
this._model.extensionContext.subscriptions.push(this._wizardObject.onPageChanged(async (pageChangeInfo: azdata.window.WizardPageChangeInfo) => {
await pages[0].onPageEnter(pageChangeInfo);
}));
this.extensionContext.subscriptions.push(this._wizardObject.doneButton.onClick(async (e) => {
this._model.extensionContext.subscriptions.push(this._wizardObject.doneButton.onClick(async (e) => {
await stateModel.startMigration();
}));
saveAndCloseButton.onClick(async () => {
await stateModel.saveInfo(serverName, this._wizardObject.currentPage);
await this._wizardObject.close();
});
this._wizardObject.cancelButton.onClick(e => {
sendSqlMigrationActionEvent(