From 145b2491dfa9a23f2737f9bc672f32c95d29dfe8 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Fri, 20 Nov 2020 18:29:00 -0800 Subject: [PATCH] Cleanup Resource Deployment ModelView (#13510) --- extensions/arc/package.json | 12 +++---- extensions/asde-deployment/package.json | 1 - .../resource-deployment/src/interfaces.ts | 2 -- .../src/ui/modelViewUtils.ts | 31 ++++--------------- .../ui/radioGroupLoadingComponentBuilder.ts | 8 +++-- 5 files changed, 17 insertions(+), 37 deletions(-) diff --git a/extensions/arc/package.json b/extensions/arc/package.json index dd8acade4e..98e2361faf 100644 --- a/extensions/arc/package.json +++ b/extensions/arc/package.json @@ -210,7 +210,6 @@ "type": "azure_account", "required": true, "subscriptionVariableName": "AZDATA_NB_VAR_ARC_SUBSCRIPTION", - "displaySubscriptionVariableName": "AZDATA_NB_VAR_ARC_DISPLAY_SUBSCRIPTION", "resourceGroupVariableName": "AZDATA_NB_VAR_ARC_RESOURCE_GROUP" }, { @@ -219,7 +218,6 @@ "defaultValue": "eastus", "required": true, "locationVariableName": "AZDATA_NB_VAR_ARC_DATA_CONTROLLER_LOCATION", - "displayLocationVariableName": "AZDATA_NB_VAR_ARC_DATA_CONTROLLER_DISPLAY_LOCATION", "locations": [ "australiaeast", "centralus", @@ -273,7 +271,7 @@ "defaultValue": "", "enabled": { "target": "AZDATA_NB_VAR_ARC_DATA_CONTROLLER_CONNECTIVITY_MODE", - "value": "%arc.data.controller.direct%" + "value": "direct" } }, { @@ -284,7 +282,7 @@ "defaultValue": "", "enabled": { "target": "AZDATA_NB_VAR_ARC_DATA_CONTROLLER_CONNECTIVITY_MODE", - "value": "%arc.data.controller.direct%" + "value": "direct" } }, { @@ -295,7 +293,7 @@ "defaultValue": "", "enabled": { "target": "AZDATA_NB_VAR_ARC_DATA_CONTROLLER_CONNECTIVITY_MODE", - "value": "%arc.data.controller.direct%" + "value": "direct" } } ] @@ -542,7 +540,7 @@ "label": "%arc.data.controller.summary.subscription%", "type": "readonly_text", "isEvaluated": true, - "defaultValue": "$(AZDATA_NB_VAR_ARC_DISPLAY_SUBSCRIPTION)", + "defaultValue": "$(AZDATA_NB_VAR_ARC_SUBSCRIPTION)", "inputWidth": "600" }, { @@ -555,7 +553,7 @@ "label": "%arc.data.controller.summary.location%", "type": "readonly_text", "isEvaluated": true, - "defaultValue": "$(AZDATA_NB_VAR_ARC_DATA_CONTROLLER_DISPLAY_LOCATION)" + "defaultValue": "$(AZDATA_NB_VAR_ARC_DATA_CONTROLLER_LOCATION)" } ] }, diff --git a/extensions/asde-deployment/package.json b/extensions/asde-deployment/package.json index 2144544cfd..30df4793dd 100644 --- a/extensions/asde-deployment/package.json +++ b/extensions/asde-deployment/package.json @@ -296,7 +296,6 @@ "defaultValue": "westus", "required": true, "locationVariableName": "AZDATA_NB_VAR_ASDE_AZURE_LOCATION", - "displayLocationVariableName": "AZDATA_NB_VAR_ASDE_AZURE_LOCATION_TEXT", "locations": [ "australiaeast", "australiasoutheast", diff --git a/extensions/resource-deployment/src/interfaces.ts b/extensions/resource-deployment/src/interfaces.ts index 36a90a8b52..67029ad98c 100644 --- a/extensions/resource-deployment/src/interfaces.ts +++ b/extensions/resource-deployment/src/interfaces.ts @@ -316,7 +316,6 @@ export interface KubeClusterContextFieldInfo extends FieldInfo { configFileVariableName?: string; } export interface AzureAccountFieldInfo extends AzureLocationsFieldInfo { - displaySubscriptionVariableName?: string; subscriptionVariableName?: string; resourceGroupVariableName?: string; allowNewResourceGroup?: boolean; @@ -326,7 +325,6 @@ export interface AzureAccountFieldInfo extends AzureLocationsFieldInfo { export interface AzureLocationsFieldInfo extends FieldInfo { locationVariableName?: string; - displayLocationVariableName?: string; locations?: string[] } diff --git a/extensions/resource-deployment/src/ui/modelViewUtils.ts b/extensions/resource-deployment/src/ui/modelViewUtils.ts index f55a909064..5686e9551d 100644 --- a/extensions/resource-deployment/src/ui/modelViewUtils.ts +++ b/extensions/resource-deployment/src/ui/modelViewUtils.ts @@ -37,6 +37,7 @@ export type InputComponent = azdata.TextComponent | azdata.InputBoxComponent | a export type InputComponentInfo = { component: T; getValue: () => Promise; + getDisplayValue?: () => Promise; onValueChanged: vscode.Event; isPassword?: boolean }; @@ -262,6 +263,7 @@ export function createDropdownInputInfo(view: azdata.ModelView, info: { defaultV return { component: dropdown, getValue: async (): Promise => typeof dropdown.value === 'string' ? dropdown.value : dropdown.value?.name, + getDisplayValue: async (): Promise => (typeof dropdown.value === 'string' ? dropdown.value : dropdown.value?.displayName) || '', onValueChanged: dropdown.onValueChanged, }; } @@ -753,7 +755,7 @@ function processEvaluatedTextField(context: FieldContext): ReadOnlyFieldInputs { /** * Returns a string that interpolates all variable names in the {@param inputValue} string de-marked as $(VariableName) - * substituted with their corresponding values. + * substituted with their corresponding values. Will use the display value of the target input values if possible. * * Only variables in the current model starting with {@see NoteBookEnvironmentVariablePrefix} are replaced. * @@ -764,7 +766,7 @@ async function substituteVariableValues(inputComponents: InputComponents, inputV await Promise.all(Object.keys(inputComponents) .filter(key => key.startsWith(NoteBookEnvironmentVariablePrefix)) .map(async key => { - const value = (await inputComponents[key].getValue()) ?? ''; + const value = (await (inputComponents[key].getDisplayValue ? inputComponents[key].getDisplayValue!() : inputComponents[key].getValue())) ?? ''; const re: RegExp = new RegExp(`\\\$\\\(${key}\\\)`, 'gi'); inputValue = inputValue?.replace(re, value.toString()); }) @@ -927,6 +929,7 @@ async function createRadioOptions(context: FieldContext, getRadioButtonInfo?: (( context.onNewInputComponentCreated(context.fieldInfo.variableName || context.fieldInfo.label, { component: radioGroupLoadingComponentBuilder, getValue: async (): Promise => radioGroupLoadingComponentBuilder.value, + getDisplayValue: async (): Promise => radioGroupLoadingComponentBuilder.displayValue, onValueChanged: radioGroupLoadingComponentBuilder.onValueChanged, }); addLabelInputPairToContainer(context.view, context.components, label, radioGroupLoadingComponentBuilder.component(), context.fieldInfo); @@ -1118,15 +1121,9 @@ function createAzureSubscriptionDropdown( const inputValue = (await subscriptionDropdown.getValue())?.toString() || ''; return subscriptionValueToSubscriptionMap.get(inputValue)?.id || inputValue; }, + getDisplayValue: subscriptionDropdown.getDisplayValue, onValueChanged: subscriptionDropdown.onValueChanged }); - if (context.fieldInfo.displaySubscriptionVariableName) { - context.fieldInfo.subFields!.push({ - label: label.value!, - variableName: context.fieldInfo.displaySubscriptionVariableName - }); - context.onNewInputComponentCreated(context.fieldInfo.displaySubscriptionVariableName!, subscriptionDropdown); - } addLabelInputPairToContainer(context.view, context.components, label, subscriptionDropdown.component, context.fieldInfo); return subscriptionDropdown.component; } @@ -1341,22 +1338,6 @@ async function processAzureLocationsField(context: AzureLocationsFieldContext): }); context.onNewInputComponentCreated(context.fieldInfo.locationVariableName, locationDropdown); } - if (context.fieldInfo.displayLocationVariableName) { - context.fieldInfo.subFields!.push({ - label: label.value!, - variableName: context.fieldInfo.displayLocationVariableName - }); - // Create a special input component that maps the dropdown to the display name for the location - // so that we have two variables - one for the value and one for the display name - context.onNewInputComponentCreated(context.fieldInfo.displayLocationVariableName, { - component: locationDropdown.component, - getValue: async (): Promise => { - const inputValue = (await locationDropdown.getValue())?.toString(); - return apiService.azurecoreApi.getRegionDisplayName(inputValue); - }, - onValueChanged: locationDropdown.onValueChanged, - }); - } addLabelInputPairToContainer(context.view, context.components, label, locationDropdown.component, context.fieldInfo); return locationDropdown.component; } diff --git a/extensions/resource-deployment/src/ui/radioGroupLoadingComponentBuilder.ts b/extensions/resource-deployment/src/ui/radioGroupLoadingComponentBuilder.ts index 120f68f7d9..218c35a0f4 100644 --- a/extensions/resource-deployment/src/ui/radioGroupLoadingComponentBuilder.ts +++ b/extensions/resource-deployment/src/ui/radioGroupLoadingComponentBuilder.ts @@ -49,8 +49,8 @@ export class RadioGroupLoadingComponentBuilder implements azdata.ComponentBuilde : op as azdata.CategoryValue; const radioOption = this._view!.modelBuilder.radioButton().withProperties({ label: option.displayName, + value: option.name, checked: option.displayName === defaultValue, - name: option.name, enabled: instanceOfDynamicEnablementInfo(this._fieldInfo.enabled) ? false : this._fieldInfo.enabled // Dynamic enablement is initially set to false }).component(); if (radioOption.checked) { @@ -75,7 +75,11 @@ export class RadioGroupLoadingComponentBuilder implements azdata.ComponentBuilde } get value(): string | undefined { - return this._currentRadioOption?.label; + return this._currentRadioOption?.value || this._currentRadioOption?.label; + } + + get displayValue(): string { + return this._currentRadioOption.label || ''; } get checked(): azdata.RadioButtonComponent {