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

@@ -8,7 +8,7 @@ import * as nls from 'vscode-nls';
import { NotebookBasedDialogInfo } from './interfaces';
import { NotebookService } from './services/notebookService';
import { PlatformService } from './services/platformService';
import { ResourceTypeService } from './services/resourceTypeService';
import { OptionValuesFilter, ResourceTypeService } from './services/resourceTypeService';
import { ToolsService } from './services/toolsService';
import { DeploymentInputDialog } from './ui/deploymentInputDialog';
import { ResourceTypePickerDialog } from './ui/resourceTypePickerDialog';
@@ -37,12 +37,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<rd.IEx
* @param resourceTypeNameFilters Optional filters to apply to the resource types displayed. If undefined all
* resource types will be displayed
*/
const openDialog = (defaultResourceTypeName: string, resourceTypeNameFilters?: string[]) => {
const openDialog = (defaultResourceTypeName: string, resourceTypeNameFilters?: string[], optionValuesFilter?: OptionValuesFilter) => {
const defaultResourceType = resourceTypes.find(resourceType => resourceType.name === defaultResourceTypeName);
if (!defaultResourceType) {
vscode.window.showErrorMessage(localize('resourceDeployment.UnknownResourceType', "The resource type: {0} is not defined", defaultResourceTypeName));
} else {
const dialog = new ResourceTypePickerDialog(resourceTypeService, defaultResourceType, resourceTypeNameFilters);
const dialog = new ResourceTypePickerDialog(resourceTypeService, defaultResourceType, resourceTypeNameFilters, optionValuesFilter);
dialog.open();
}
};
@@ -53,14 +53,21 @@ export async function activate(context: vscode.ExtensionContext): Promise<rd.IEx
vscode.commands.registerCommand('azdata.resource.sql-bdc.deploy', () => {
openDialog('sql-bdc');
});
vscode.commands.registerCommand('azdata.resource.deploy', (defaultResourceTypeName?: string, resourceTypeNameFilters?: string[]) => {
/**
* Command to open the Resource Deployment wizard - with options to filter the values shown
* @param defaultResourceTypeName - The default resourceType to be selected
* @param resourceTypeNameFilters - The list of resourceTypes to show in the wizard
* @param optionValuesFilter - The list of resourceType option values to show in the wizard. This is an object in the format
* { "resource-type-name": { "option-name": ["option-value-1", "option-value-2"] } }
*/
vscode.commands.registerCommand('azdata.resource.deploy', (defaultResourceTypeName?: string, resourceTypeNameFilters?: string[], optionValuesFilter?: OptionValuesFilter) => {
if ((resourceTypeNameFilters && !Array.isArray(resourceTypeNameFilters) ||
(resourceTypeNameFilters && resourceTypeNameFilters.length > 0 && typeof resourceTypeNameFilters[0] !== 'string'))) {
throw new Error('resourceTypeNameFilters must either be undefined or an array of strings');
}
if (typeof defaultResourceTypeName === 'string') {
openDialog(defaultResourceTypeName, resourceTypeNameFilters);
openDialog(defaultResourceTypeName, resourceTypeNameFilters, optionValuesFilter);
} else {
let defaultDeploymentType: string;
if (platformService.platform() === 'win32') {
@@ -68,7 +75,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<rd.IEx
} else {
defaultDeploymentType = 'sql-image';
}
openDialog(defaultDeploymentType, resourceTypeNameFilters);
openDialog(defaultDeploymentType, resourceTypeNameFilters, optionValuesFilter);
}
});
vscode.commands.registerCommand('azdata.openNotebookInputDialog', (dialogInfo: NotebookBasedDialogInfo) => {

View File

@@ -21,10 +21,17 @@ import { deepClone } from '../common/utils';
const localize = nls.loadMessageBundle();
/**
* Used to filter the specific optionValues that the deployment wizard shows
*/
export interface OptionValuesFilter {
[key: string]: Record<string, string[]>
}
export interface IResourceTypeService {
getResourceTypes(filterByPlatform?: boolean): ResourceType[];
validateResourceTypes(resourceTypes: ResourceType[]): string[];
startDeployment(resourceType: ResourceType): void;
startDeployment(resourceType: ResourceType, optionValuesFilter?: OptionValuesFilter): void;
}
export class ResourceTypeService implements IResourceTypeService {
@@ -301,8 +308,8 @@ export class ResourceTypeService implements IResourceTypeService {
return undefined;
}
public startDeployment(resourceType: ResourceType): void {
const wizard = new ResourceTypeWizard(resourceType, new KubeService(), new AzdataService(this.platformService), this.notebookService, this.toolsService, this.platformService, this);
public startDeployment(resourceType: ResourceType, optionValuesFilter?: OptionValuesFilter): void {
const wizard = new ResourceTypeWizard(resourceType, new KubeService(), new AzdataService(this.platformService), this.notebookService, this.toolsService, this.platformService, this, optionValuesFilter);
wizard.open();
}

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);
});