Default to current controller when deploying from Arc dashboard (#14409)

This commit is contained in:
Charles Gagnon
2021-02-23 17:17:52 -08:00
committed by GitHub
parent 0108da2a24
commit d5385f66d3
6 changed files with 27 additions and 14 deletions

View File

@@ -661,7 +661,7 @@
"fields": [
{
"label": "%arc.controller%",
"variableName": "",
"variableName": "CONTROLLER_NAME",
"type": "options",
"editable": false,
"required": true,
@@ -936,7 +936,7 @@
"fields": [
{
"label": "%arc.controller%",
"variableName": "",
"variableName": "CONTROLLER_NAME",
"type": "options",
"editable": false,
"required": true,

View File

@@ -147,7 +147,12 @@ export class ControllerDashboardOverviewPage extends DashboardPage {
this.disposables.push(
newInstance.onDidClick(async () => {
await vscode.commands.executeCommand('azdata.resource.deploy', 'azure-sql-mi', ['azure-sql-mi', 'arc.postgres'], { 'azure-sql-mi': { 'mi-type': ['arc-mi'] } });
const node = this._controllerModel.treeDataProvider.getControllerNode(this._controllerModel);
await vscode.commands.executeCommand('azdata.resource.deploy',
'azure-sql-mi', // Default option
['azure-sql-mi', 'arc.postgres'], // Type filter
{ 'azure-sql-mi': { 'mi-type': ['arc-mi'] } }, // Options filter
{ 'CONTROLLER_NAME': node?.label });
}));
// Refresh

View File

@@ -5,7 +5,7 @@
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { NotebookBasedDialogInfo } from './interfaces';
import { InitialVariableValues, NotebookBasedDialogInfo } from './interfaces';
import { NotebookService } from './services/notebookService';
import { PlatformService } from './services/platformService';
import { OptionValuesFilter, ResourceTypeService } from './services/resourceTypeService';
@@ -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[], optionValuesFilter?: OptionValuesFilter) => {
const openDialog = (defaultResourceTypeName: string, resourceTypeNameFilters?: string[], optionValuesFilter?: OptionValuesFilter, initialVariableValues?: InitialVariableValues) => {
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, optionValuesFilter);
const dialog = new ResourceTypePickerDialog(resourceTypeService, defaultResourceType, resourceTypeNameFilters, optionValuesFilter, initialVariableValues);
dialog.open();
}
};
@@ -59,15 +59,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<rd.IEx
* @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"] } }
* @param initialVariableValues - Optional list of initial values to assign to variables. This is an object of key/value pairs in the format
* { "VARIABLE_NAME": "value", "OTHER_VARIABLE_NAME": "value" }
*/
vscode.commands.registerCommand('azdata.resource.deploy', (defaultResourceTypeName?: string, resourceTypeNameFilters?: string[], optionValuesFilter?: OptionValuesFilter) => {
vscode.commands.registerCommand('azdata.resource.deploy', (defaultResourceTypeName?: string, resourceTypeNameFilters?: string[], optionValuesFilter?: OptionValuesFilter, initialVariableValues?: InitialVariableValues) => {
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, optionValuesFilter);
openDialog(defaultResourceTypeName, resourceTypeNameFilters, optionValuesFilter, initialVariableValues);
} else {
let defaultDeploymentType: string;
if (platformService.platform() === 'win32') {
@@ -75,7 +77,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<rd.IEx
} else {
defaultDeploymentType = 'sql-image';
}
openDialog(defaultDeploymentType, resourceTypeNameFilters, optionValuesFilter);
openDialog(defaultDeploymentType, resourceTypeNameFilters, optionValuesFilter, initialVariableValues);
}
});
vscode.commands.registerCommand('azdata.openNotebookInputDialog', (dialogInfo: NotebookBasedDialogInfo) => {

View File

@@ -31,7 +31,7 @@ export interface OptionValuesFilter {
export interface IResourceTypeService {
getResourceTypes(filterByPlatform?: boolean): ResourceType[];
validateResourceTypes(resourceTypes: ResourceType[]): string[];
startDeployment(resourceType: ResourceType, optionValuesFilter?: OptionValuesFilter): void;
startDeployment(resourceType: ResourceType, optionValuesFilter?: OptionValuesFilter, initialVariableValues?: InitialVariableValues): void;
}
export class ResourceTypeService implements IResourceTypeService {

View File

@@ -692,9 +692,14 @@ async function configureOptionsSourceSubfields(context: FieldContext, optionsSou
function processDropdownOptionsTypeField(context: FieldContext): azdata.DropDownComponent {
const label = createLabel(context.view, { text: context.fieldInfo.label, description: context.fieldInfo.description, required: context.fieldInfo.required, width: context.fieldInfo.labelWidth, cssStyles: context.fieldInfo.labelCSSStyles });
const options = context.fieldInfo.options as OptionsInfo;
// If we have an initial value then set it now - otherwise just default to the original default value.
// Note we don't currently check that the value actually exists in the list - if it doesn't then it'll
// just default to the first one anyways
const initialValue = context.fieldInfo.variableName && context.initialVariableValues?.[context.fieldInfo.variableName]?.toString();
const defaultValue = initialValue || options.defaultValue;
const dropdown = createDropdownInputInfo(context.view, {
values: options.values,
defaultValue: options.defaultValue,
defaultValue: defaultValue,
width: context.fieldInfo.inputWidth,
editable: context.fieldInfo.editable,
required: context.fieldInfo.required,

View File

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