Add resource deployment filtering by option values (#14101)

* Add resource deployment filtering by option values

* Fix compile error
This commit is contained in:
Charles Gagnon
2021-01-28 17:19:08 -08:00
committed by GitHub
parent 5bf1f640e8
commit db845754c6
6 changed files with 44 additions and 19 deletions

View File

@@ -6,7 +6,7 @@ import * as vscode from 'vscode';
import * as azdata from 'azdata';
import * as nls from 'vscode-nls';
import { ResourceType } from '../interfaces';
import { IResourceTypeService } from '../services/resourceTypeService';
import { IResourceTypeService, OptionValuesFilter } from '../services/resourceTypeService';
import * as loc from './../localizedConstants';
import { DialogBase } from './dialogBase';
import * as constants from '../constants';
@@ -27,7 +27,8 @@ export class ResourceTypePickerDialog extends DialogBase {
constructor(
private resourceTypeService: IResourceTypeService,
defaultResourceType: ResourceType,
private _resourceTypeNameFilters?: string[]) {
private _resourceTypeNameFilters?: string[],
private _optionValuesFilter?: OptionValuesFilter) {
super(loc.resourceTypePickerDialogTitle, 'ResourceTypePickerDialog', true);
this._selectedResourceType = defaultResourceType;
this._dialogObject.okButton.label = loc.select;
@@ -188,7 +189,7 @@ export class ResourceTypePickerDialog extends DialogBase {
}
protected async onComplete(): Promise<void> {
this.resourceTypeService.startDeployment(this._selectedResourceType);
this.resourceTypeService.startDeployment(this._selectedResourceType, this._optionValuesFilter);
}
private getAllResourceTags(): string[] {

View File

@@ -19,7 +19,7 @@ import { ResourceTypePage } from './resourceTypePage';
import { NotebookWizardModel } from './notebookWizard/notebookWizardModel';
import { DeployAzureSQLDBWizardModel } from './deployAzureSQLDBWizard/deployAzureSQLDBWizardModel';
import { ToolsAndEulaPage } from './toolsAndEulaSettingsPage';
import { ResourceTypeService } from '../services/resourceTypeService';
import { OptionValuesFilter, ResourceTypeService } from '../services/resourceTypeService';
import { PageLessDeploymentModel } from './pageLessDeploymentModel';
export class ResourceTypeWizard {
@@ -58,7 +58,8 @@ export class ResourceTypeWizard {
public notebookService: INotebookService,
public toolsService: IToolsService,
public platformService: IPlatformService,
public resourceTypeService: ResourceTypeService) {
public resourceTypeService: ResourceTypeService,
private _optionValuesFilter?: OptionValuesFilter) {
/**
* Setting the first provider from the first value of the dropdowns.
* If there are no options (dropdowns) then the resource type has only one provider which is set as default here.
@@ -93,6 +94,7 @@ export class ResourceTypeWizard {
}));
this.toDispose.push(this.wizardObject.doneButton.onClick(async () => {
// TODO - Don't close this when the button is clicked, set up a page validator instead
await this._model.onOk();
this.dispose();
}));
@@ -144,7 +146,7 @@ export class ResourceTypeWizard {
}
public setPages(pages: ResourceTypePage[]) {
pages.unshift(new ToolsAndEulaPage(this));
pages.unshift(new ToolsAndEulaPage(this, this._optionValuesFilter));
this.wizardObject!.pages = pages.map(p => p.pageObject);
this.pages = pages;
this.pages.forEach((page) => {

View File

@@ -13,6 +13,7 @@ import { IToolsService } from '../services/toolsService';
import { getErrorMessage } from '../common/utils';
import { ResourceTypePage } from './resourceTypePage';
import { ResourceTypeWizard } from './resourceTypeWizard';
import { OptionValuesFilter as OptionValuesFilter } from '../services/resourceTypeService';
const localize = nls.loadMessageBundle();
@@ -41,7 +42,7 @@ export class ToolsAndEulaPage extends ResourceTypePage {
return this.wizard.toolsService;
}
constructor(wizard: ResourceTypeWizard) {
constructor(wizard: ResourceTypeWizard, private optionValuesFilter?: OptionValuesFilter) {
super(localize('notebookWizard.toolsAndEulaPageTitle', "Deployment pre-requisites"), '', wizard);
this._resourceType = wizard.resourceType;
}
@@ -192,19 +193,25 @@ export class ToolsAndEulaPage extends ResourceTypePage {
}).component();
this._optionsContainer.addItem(optionsTitle);
this._resourceType.options.forEach((option, index) => {
let optionValues = option.values;
const optionValueFilter = this.optionValuesFilter?.[this._resourceType.name]?.[option.name];
if (optionValueFilter) {
optionValues = optionValues.filter(optionValue => optionValueFilter.includes(optionValue.name));
}
const optionLabel = this.view.modelBuilder.text().withProperties<azdata.TextComponentProperties>({
value: option.displayName,
}).component();
optionLabel.width = '150px';
const optionSelectedValue = (this.wizard.toolsEulaPagePresets) ? this.wizard.toolsEulaPagePresets[index] : option.values[0];
const optionSelectedValue = (this.wizard.toolsEulaPagePresets) ? this.wizard.toolsEulaPagePresets[index] : optionValues[0];
const optionSelectBox = this.view.modelBuilder.dropDown().withProperties<azdata.DropDownProperties>({
values: option.values,
values: optionValues,
value: optionSelectedValue,
width: '300px',
ariaLabel: option.displayName
}).component();
resourceTypeOptions.push(optionSelectedValue);
this.wizard.registerDisposable(optionSelectBox.onValueChanged(async () => {
@@ -216,6 +223,7 @@ export class ToolsAndEulaPage extends ResourceTypePage {
}));
this._optionDropDownMap.set(option.name, optionSelectBox);
this.wizard.provider = this.getCurrentProvider();
const row = this.view.modelBuilder.flexContainer().withItems([optionLabel, optionSelectBox], { flex: '0 0 auto', CSSStyles: { 'margin-right': '20px' } }).withLayout({ flexFlow: 'row', alignItems: 'center' }).component();
this._optionsContainer.addItem(row);
});