Splits the work of the assessment dialog into smaller managable chunks (#12172)

* Splits the work of the assessment dialog into smaller managable chunks

* Use the new assessment dialog page
This commit is contained in:
Amir Omidi
2020-09-08 17:22:23 -07:00
committed by GitHub
parent 9ed274fb39
commit f56e09cfa1
9 changed files with 264 additions and 137 deletions

View File

@@ -1,133 +0,0 @@
/*---------------------------------------------------------------------------------------------
* 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 * as mssql from '../../../mssql';
import { MigrationStateModel } from '../models/stateMachine';
export class AssessmentResultsDialog {
private static readonly OkButtonText: string = 'OK';
private static readonly CancelButtonText: string = 'Cancel';
// protected _onSuccess: vscode.EventEmitter<T> = new vscode.EventEmitter<T>();
protected _isOpen: boolean = false;
// public readonly onSuccess: vscode.Event<T> = this._onSuccess.event;
public dialog: azdata.window.Dialog | undefined;
private assessmentTable: azdata.TableComponent | undefined;
// Dialog Name for Telemetry
public dialogName: string | undefined;
constructor(public ownerUri: string, public model: MigrationStateModel, public title: string) {
}
protected async updateModel(): Promise<void> {
return undefined;
}
protected async initializeDialog(dialog: azdata.window.Dialog): Promise<void> {
dialog.registerContent(async view => {
this.assessmentTable = view.modelBuilder.table()
.withProperties({
columns: [
'Target',
'Target Name',
'Rule ID',
'Rule Name',
'Description',
'Impacted Objects'
],
data: [],
height: 700,
width: 1100
}).component();
let formModel = view.modelBuilder.formContainer()
.withFormItems([
{
components: [{
component: this.assessmentTable,
title: 'Results',
layout: {
info: 'Assessment Results'
}
}],
title: 'Assessment Results'
}]).withLayout({ width: '100%' }).component();
await view.initializeModel(formModel);
let data = this.convertAssessmentToData(this.model.assessmentResults);
this.assessmentTable.data = data;
});
}
private convertAssessmentToData(assessments: mssql.SqlMigrationAssessmentResultItem[] | undefined): Array<string | number>[] {
let result: Array<string | number>[] = [];
if (assessments) {
assessments.forEach(assessment => {
if (assessment.impactedObjects && assessment.impactedObjects.length > 0) {
assessment.impactedObjects.forEach(impactedObject => {
this.addAssessmentColumn(result, assessment, impactedObject);
});
} else {
this.addAssessmentColumn(result, assessment, undefined);
}
});
}
return result;
}
private addAssessmentColumn(
result: Array<string | number>[],
assessment: mssql.SqlMigrationAssessmentResultItem,
impactedObject: mssql.SqlMigrationImpactedObjectInfo | undefined): void {
let cols = [];
cols.push(assessment.appliesToMigrationTargetPlatform);
cols.push(assessment.displayName);
cols.push(assessment.checkId);
cols.push(assessment.rulesetName);
cols.push(assessment.description);
cols.push(impactedObject?.name ?? '');
result.push(cols);
}
public async openDialog(dialogName?: string) {
if (!this._isOpen) {
this._isOpen = true;
this.dialog = azdata.window.createModelViewDialog(this.title, this.title, true);
// await this.model.initialize();
await this.initializeDialog(this.dialog);
this.dialog.okButton.label = AssessmentResultsDialog.OkButtonText;
this.dialog.okButton.onClick(async () => await this.execute());
this.dialog.cancelButton.label = AssessmentResultsDialog.CancelButtonText;
this.dialog.cancelButton.onClick(async () => await this.cancel());
azdata.window.openDialog(this.dialog);
}
}
protected async execute() {
this.updateModel();
// await this.model.save();
this._isOpen = false;
// this._onSuccess.fire(this.model);
}
protected async cancel() {
this._isOpen = false;
}
public get isOpen(): boolean {
return this._isOpen;
}
}

View File

@@ -10,7 +10,7 @@ import { MigrationStateModel, StateChangeEvent } from '../models/stateMachine';
import { Product, ProductLookupTable } from '../models/product';
import { SKU_RECOMMENDATION_PAGE_TITLE, SKU_RECOMMENDATION_CHOOSE_A_TARGET } from '../models/strings';
import { Disposable } from 'vscode';
import { AssessmentResultsDialog } from './assessmentResultsDialog';
import { AssessmentResultsDialog } from '../dialog/assessmentResults/assessmentResultsDialog';
export class SKURecommendationPage extends MigrationWizardPage {
// For future reference: DO NOT EXPOSE WIZARD DIRECTLY THROUGH HERE.
@@ -40,7 +40,7 @@ export class SKURecommendationPage extends MigrationWizardPage {
}).component();
assessmentLink.onDidClick(async () => {
let dialog = new AssessmentResultsDialog('ownerUri', this.migrationStateModel, 'Assessment Dialog');
dialog.openDialog();
await dialog.openDialog();
});
const assessmentFormLink = {