mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Add resource deployment filtering by option values (#14101)
* Add resource deployment filtering by option values * Fix compile error
This commit is contained in:
@@ -147,7 +147,7 @@ export class ControllerDashboardOverviewPage extends DashboardPage {
|
|||||||
|
|
||||||
this.disposables.push(
|
this.disposables.push(
|
||||||
newInstance.onDidClick(async () => {
|
newInstance.onDidClick(async () => {
|
||||||
await vscode.commands.executeCommand('azdata.resource.deploy', 'arc.sql', ['arc.sql', 'arc.postgres']);
|
await vscode.commands.executeCommand('azdata.resource.deploy', 'azure-sql-mi', ['azure-sql-mi', 'arc.postgres'], { 'azure-sql-mi': { 'mi-type': ['arc-mi'] } });
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Refresh
|
// Refresh
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import * as nls from 'vscode-nls';
|
|||||||
import { NotebookBasedDialogInfo } from './interfaces';
|
import { NotebookBasedDialogInfo } from './interfaces';
|
||||||
import { NotebookService } from './services/notebookService';
|
import { NotebookService } from './services/notebookService';
|
||||||
import { PlatformService } from './services/platformService';
|
import { PlatformService } from './services/platformService';
|
||||||
import { ResourceTypeService } from './services/resourceTypeService';
|
import { OptionValuesFilter, ResourceTypeService } from './services/resourceTypeService';
|
||||||
import { ToolsService } from './services/toolsService';
|
import { ToolsService } from './services/toolsService';
|
||||||
import { DeploymentInputDialog } from './ui/deploymentInputDialog';
|
import { DeploymentInputDialog } from './ui/deploymentInputDialog';
|
||||||
import { ResourceTypePickerDialog } from './ui/resourceTypePickerDialog';
|
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
|
* @param resourceTypeNameFilters Optional filters to apply to the resource types displayed. If undefined all
|
||||||
* resource types will be displayed
|
* 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);
|
const defaultResourceType = resourceTypes.find(resourceType => resourceType.name === defaultResourceTypeName);
|
||||||
if (!defaultResourceType) {
|
if (!defaultResourceType) {
|
||||||
vscode.window.showErrorMessage(localize('resourceDeployment.UnknownResourceType', "The resource type: {0} is not defined", defaultResourceTypeName));
|
vscode.window.showErrorMessage(localize('resourceDeployment.UnknownResourceType', "The resource type: {0} is not defined", defaultResourceTypeName));
|
||||||
} else {
|
} else {
|
||||||
const dialog = new ResourceTypePickerDialog(resourceTypeService, defaultResourceType, resourceTypeNameFilters);
|
const dialog = new ResourceTypePickerDialog(resourceTypeService, defaultResourceType, resourceTypeNameFilters, optionValuesFilter);
|
||||||
dialog.open();
|
dialog.open();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -53,14 +53,21 @@ export async function activate(context: vscode.ExtensionContext): Promise<rd.IEx
|
|||||||
vscode.commands.registerCommand('azdata.resource.sql-bdc.deploy', () => {
|
vscode.commands.registerCommand('azdata.resource.sql-bdc.deploy', () => {
|
||||||
openDialog('sql-bdc');
|
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) ||
|
if ((resourceTypeNameFilters && !Array.isArray(resourceTypeNameFilters) ||
|
||||||
(resourceTypeNameFilters && resourceTypeNameFilters.length > 0 && typeof resourceTypeNameFilters[0] !== 'string'))) {
|
(resourceTypeNameFilters && resourceTypeNameFilters.length > 0 && typeof resourceTypeNameFilters[0] !== 'string'))) {
|
||||||
throw new Error('resourceTypeNameFilters must either be undefined or an array of strings');
|
throw new Error('resourceTypeNameFilters must either be undefined or an array of strings');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof defaultResourceTypeName === 'string') {
|
if (typeof defaultResourceTypeName === 'string') {
|
||||||
openDialog(defaultResourceTypeName, resourceTypeNameFilters);
|
openDialog(defaultResourceTypeName, resourceTypeNameFilters, optionValuesFilter);
|
||||||
} else {
|
} else {
|
||||||
let defaultDeploymentType: string;
|
let defaultDeploymentType: string;
|
||||||
if (platformService.platform() === 'win32') {
|
if (platformService.platform() === 'win32') {
|
||||||
@@ -68,7 +75,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<rd.IEx
|
|||||||
} else {
|
} else {
|
||||||
defaultDeploymentType = 'sql-image';
|
defaultDeploymentType = 'sql-image';
|
||||||
}
|
}
|
||||||
openDialog(defaultDeploymentType, resourceTypeNameFilters);
|
openDialog(defaultDeploymentType, resourceTypeNameFilters, optionValuesFilter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
vscode.commands.registerCommand('azdata.openNotebookInputDialog', (dialogInfo: NotebookBasedDialogInfo) => {
|
vscode.commands.registerCommand('azdata.openNotebookInputDialog', (dialogInfo: NotebookBasedDialogInfo) => {
|
||||||
|
|||||||
@@ -21,10 +21,17 @@ import { deepClone } from '../common/utils';
|
|||||||
|
|
||||||
const localize = nls.loadMessageBundle();
|
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 {
|
export interface IResourceTypeService {
|
||||||
getResourceTypes(filterByPlatform?: boolean): ResourceType[];
|
getResourceTypes(filterByPlatform?: boolean): ResourceType[];
|
||||||
validateResourceTypes(resourceTypes: ResourceType[]): string[];
|
validateResourceTypes(resourceTypes: ResourceType[]): string[];
|
||||||
startDeployment(resourceType: ResourceType): void;
|
startDeployment(resourceType: ResourceType, optionValuesFilter?: OptionValuesFilter): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ResourceTypeService implements IResourceTypeService {
|
export class ResourceTypeService implements IResourceTypeService {
|
||||||
@@ -301,8 +308,8 @@ export class ResourceTypeService implements IResourceTypeService {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
public startDeployment(resourceType: ResourceType): void {
|
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);
|
const wizard = new ResourceTypeWizard(resourceType, new KubeService(), new AzdataService(this.platformService), this.notebookService, this.toolsService, this.platformService, this, optionValuesFilter);
|
||||||
wizard.open();
|
wizard.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import * as vscode from 'vscode';
|
|||||||
import * as azdata from 'azdata';
|
import * as azdata from 'azdata';
|
||||||
import * as nls from 'vscode-nls';
|
import * as nls from 'vscode-nls';
|
||||||
import { ResourceType } from '../interfaces';
|
import { ResourceType } from '../interfaces';
|
||||||
import { IResourceTypeService } from '../services/resourceTypeService';
|
import { IResourceTypeService, OptionValuesFilter } from '../services/resourceTypeService';
|
||||||
import * as loc from './../localizedConstants';
|
import * as loc from './../localizedConstants';
|
||||||
import { DialogBase } from './dialogBase';
|
import { DialogBase } from './dialogBase';
|
||||||
import * as constants from '../constants';
|
import * as constants from '../constants';
|
||||||
@@ -27,7 +27,8 @@ export class ResourceTypePickerDialog extends DialogBase {
|
|||||||
constructor(
|
constructor(
|
||||||
private resourceTypeService: IResourceTypeService,
|
private resourceTypeService: IResourceTypeService,
|
||||||
defaultResourceType: ResourceType,
|
defaultResourceType: ResourceType,
|
||||||
private _resourceTypeNameFilters?: string[]) {
|
private _resourceTypeNameFilters?: string[],
|
||||||
|
private _optionValuesFilter?: OptionValuesFilter) {
|
||||||
super(loc.resourceTypePickerDialogTitle, 'ResourceTypePickerDialog', true);
|
super(loc.resourceTypePickerDialogTitle, 'ResourceTypePickerDialog', true);
|
||||||
this._selectedResourceType = defaultResourceType;
|
this._selectedResourceType = defaultResourceType;
|
||||||
this._dialogObject.okButton.label = loc.select;
|
this._dialogObject.okButton.label = loc.select;
|
||||||
@@ -188,7 +189,7 @@ export class ResourceTypePickerDialog extends DialogBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async onComplete(): Promise<void> {
|
protected async onComplete(): Promise<void> {
|
||||||
this.resourceTypeService.startDeployment(this._selectedResourceType);
|
this.resourceTypeService.startDeployment(this._selectedResourceType, this._optionValuesFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getAllResourceTags(): string[] {
|
private getAllResourceTags(): string[] {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { ResourceTypePage } from './resourceTypePage';
|
|||||||
import { NotebookWizardModel } from './notebookWizard/notebookWizardModel';
|
import { NotebookWizardModel } from './notebookWizard/notebookWizardModel';
|
||||||
import { DeployAzureSQLDBWizardModel } from './deployAzureSQLDBWizard/deployAzureSQLDBWizardModel';
|
import { DeployAzureSQLDBWizardModel } from './deployAzureSQLDBWizard/deployAzureSQLDBWizardModel';
|
||||||
import { ToolsAndEulaPage } from './toolsAndEulaSettingsPage';
|
import { ToolsAndEulaPage } from './toolsAndEulaSettingsPage';
|
||||||
import { ResourceTypeService } from '../services/resourceTypeService';
|
import { OptionValuesFilter, ResourceTypeService } from '../services/resourceTypeService';
|
||||||
import { PageLessDeploymentModel } from './pageLessDeploymentModel';
|
import { PageLessDeploymentModel } from './pageLessDeploymentModel';
|
||||||
|
|
||||||
export class ResourceTypeWizard {
|
export class ResourceTypeWizard {
|
||||||
@@ -58,7 +58,8 @@ export class ResourceTypeWizard {
|
|||||||
public notebookService: INotebookService,
|
public notebookService: INotebookService,
|
||||||
public toolsService: IToolsService,
|
public toolsService: IToolsService,
|
||||||
public platformService: IPlatformService,
|
public platformService: IPlatformService,
|
||||||
public resourceTypeService: ResourceTypeService) {
|
public resourceTypeService: ResourceTypeService,
|
||||||
|
private _optionValuesFilter?: OptionValuesFilter) {
|
||||||
/**
|
/**
|
||||||
* Setting the first provider from the first value of the dropdowns.
|
* 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.
|
* 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 () => {
|
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();
|
await this._model.onOk();
|
||||||
this.dispose();
|
this.dispose();
|
||||||
}));
|
}));
|
||||||
@@ -144,7 +146,7 @@ export class ResourceTypeWizard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public setPages(pages: ResourceTypePage[]) {
|
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.wizardObject!.pages = pages.map(p => p.pageObject);
|
||||||
this.pages = pages;
|
this.pages = pages;
|
||||||
this.pages.forEach((page) => {
|
this.pages.forEach((page) => {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { IToolsService } from '../services/toolsService';
|
|||||||
import { getErrorMessage } from '../common/utils';
|
import { getErrorMessage } from '../common/utils';
|
||||||
import { ResourceTypePage } from './resourceTypePage';
|
import { ResourceTypePage } from './resourceTypePage';
|
||||||
import { ResourceTypeWizard } from './resourceTypeWizard';
|
import { ResourceTypeWizard } from './resourceTypeWizard';
|
||||||
|
import { OptionValuesFilter as OptionValuesFilter } from '../services/resourceTypeService';
|
||||||
|
|
||||||
const localize = nls.loadMessageBundle();
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ export class ToolsAndEulaPage extends ResourceTypePage {
|
|||||||
return this.wizard.toolsService;
|
return this.wizard.toolsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(wizard: ResourceTypeWizard) {
|
constructor(wizard: ResourceTypeWizard, private optionValuesFilter?: OptionValuesFilter) {
|
||||||
super(localize('notebookWizard.toolsAndEulaPageTitle', "Deployment pre-requisites"), '', wizard);
|
super(localize('notebookWizard.toolsAndEulaPageTitle', "Deployment pre-requisites"), '', wizard);
|
||||||
this._resourceType = wizard.resourceType;
|
this._resourceType = wizard.resourceType;
|
||||||
}
|
}
|
||||||
@@ -192,19 +193,25 @@ export class ToolsAndEulaPage extends ResourceTypePage {
|
|||||||
}).component();
|
}).component();
|
||||||
this._optionsContainer.addItem(optionsTitle);
|
this._optionsContainer.addItem(optionsTitle);
|
||||||
this._resourceType.options.forEach((option, index) => {
|
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>({
|
const optionLabel = this.view.modelBuilder.text().withProperties<azdata.TextComponentProperties>({
|
||||||
value: option.displayName,
|
value: option.displayName,
|
||||||
}).component();
|
}).component();
|
||||||
optionLabel.width = '150px';
|
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>({
|
const optionSelectBox = this.view.modelBuilder.dropDown().withProperties<azdata.DropDownProperties>({
|
||||||
values: option.values,
|
values: optionValues,
|
||||||
value: optionSelectedValue,
|
value: optionSelectedValue,
|
||||||
width: '300px',
|
width: '300px',
|
||||||
ariaLabel: option.displayName
|
ariaLabel: option.displayName
|
||||||
}).component();
|
}).component();
|
||||||
|
|
||||||
|
|
||||||
resourceTypeOptions.push(optionSelectedValue);
|
resourceTypeOptions.push(optionSelectedValue);
|
||||||
|
|
||||||
this.wizard.registerDisposable(optionSelectBox.onValueChanged(async () => {
|
this.wizard.registerDisposable(optionSelectBox.onValueChanged(async () => {
|
||||||
@@ -216,6 +223,7 @@ export class ToolsAndEulaPage extends ResourceTypePage {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
this._optionDropDownMap.set(option.name, optionSelectBox);
|
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();
|
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);
|
this._optionsContainer.addItem(row);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user