mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 09:35:41 -05:00
Change Azure region dropdown to use azurecore API (#11131)
* Change Azure region dropdown to use azurecore API for getting display name * Fix compile errors * Adding a few things to the vscodeignore * and another
This commit is contained in:
@@ -7,7 +7,6 @@ import { EOL, homedir as os_homedir } from 'os';
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import * as azurecore from '../../../azurecore/src/azurecore';
|
||||
import { azureResource } from '../../../azurecore/src/azureResource/azure-resource';
|
||||
import { AzureAccountFieldInfo, AzureLocationsFieldInfo, ComponentCSSStyles, DialogInfoBase, FieldInfo, FieldType, KubeClusterContextFieldInfo, LabelPosition, NoteBookEnvironmentVariablePrefix, OptionsInfo, OptionsType, PageInfoBase, RowInfo, SectionInfo, TextCSSStyles } from '../interfaces';
|
||||
import * as loc from '../localizedConstants';
|
||||
@@ -176,8 +175,8 @@ export function initializeDialog(dialogContext: DialogContext): void {
|
||||
const tabs: azdata.window.DialogTab[] = [];
|
||||
dialogContext.dialogInfo.tabs.forEach(tabInfo => {
|
||||
const tab = azdata.window.createTab(tabInfo.title);
|
||||
tab.registerContent((view: azdata.ModelView) => {
|
||||
const sections = tabInfo.sections.map(sectionInfo => {
|
||||
tab.registerContent(async (view: azdata.ModelView) => {
|
||||
const sections = await Promise.all(tabInfo.sections.map(sectionInfo => {
|
||||
sectionInfo.inputWidth = sectionInfo.inputWidth || tabInfo.inputWidth || DefaultInputWidth;
|
||||
sectionInfo.labelWidth = sectionInfo.labelWidth || tabInfo.labelWidth || DefaultLabelWidth;
|
||||
sectionInfo.fieldAlignItems = sectionInfo.fieldAlignItems || tabInfo.fieldAlignItems || DefaultFieldAlignItems;
|
||||
@@ -193,7 +192,7 @@ export function initializeDialog(dialogContext: DialogContext): void {
|
||||
container: dialogContext.container,
|
||||
inputComponents: dialogContext.inputComponents
|
||||
});
|
||||
});
|
||||
}));
|
||||
const formBuilder = view.modelBuilder.formContainer().withFormItems(
|
||||
sections.map(section => {
|
||||
return { title: '', component: section };
|
||||
@@ -212,8 +211,8 @@ export function initializeDialog(dialogContext: DialogContext): void {
|
||||
}
|
||||
|
||||
export function initializeWizardPage(context: WizardPageContext): void {
|
||||
context.page.registerContent((view: azdata.ModelView) => {
|
||||
const sections = context.pageInfo.sections.map(sectionInfo => {
|
||||
context.page.registerContent(async (view: azdata.ModelView) => {
|
||||
const sections = await Promise.all(context.pageInfo.sections.map(sectionInfo => {
|
||||
sectionInfo.inputWidth = sectionInfo.inputWidth || context.pageInfo.inputWidth || context.wizardInfo.inputWidth || DefaultInputWidth;
|
||||
sectionInfo.labelWidth = sectionInfo.labelWidth || context.pageInfo.labelWidth || context.wizardInfo.labelWidth || DefaultLabelWidth;
|
||||
sectionInfo.fieldAlignItems = sectionInfo.fieldAlignItems || context.pageInfo.fieldAlignItems || DefaultFieldAlignItems;
|
||||
@@ -229,7 +228,7 @@ export function initializeWizardPage(context: WizardPageContext): void {
|
||||
onNewValidatorCreated: context.onNewValidatorCreated,
|
||||
sectionInfo: sectionInfo
|
||||
});
|
||||
});
|
||||
}));
|
||||
const formBuilder = view.modelBuilder.formContainer().withFormItems(
|
||||
sections.map(section => { return { title: '', component: section }; }),
|
||||
{
|
||||
@@ -242,7 +241,7 @@ export function initializeWizardPage(context: WizardPageContext): void {
|
||||
});
|
||||
}
|
||||
|
||||
export function createSection(context: SectionContext): azdata.GroupContainer {
|
||||
export async function createSection(context: SectionContext): Promise<azdata.GroupContainer> {
|
||||
const components: azdata.Component[] = [];
|
||||
context.sectionInfo.inputWidth = context.sectionInfo.inputWidth || DefaultInputWidth;
|
||||
context.sectionInfo.labelWidth = context.sectionInfo.labelWidth || DefaultLabelWidth;
|
||||
@@ -250,11 +249,11 @@ export function createSection(context: SectionContext): azdata.GroupContainer {
|
||||
context.sectionInfo.fieldWidth = context.sectionInfo.fieldWidth || DefaultFieldWidth;
|
||||
context.sectionInfo.fieldHeight = context.sectionInfo.fieldHeight || DefaultFieldHeight;
|
||||
if (context.sectionInfo.fields) {
|
||||
processFields(context.sectionInfo.fields, components, context);
|
||||
await processFields(context.sectionInfo.fields, components, context);
|
||||
} else if (context.sectionInfo.rows) {
|
||||
context.sectionInfo.rows.forEach(rowInfo => {
|
||||
components.push(processRow(rowInfo, context));
|
||||
});
|
||||
for (const rowInfo of context.sectionInfo.rows) {
|
||||
components.push(await processRow(rowInfo, context));
|
||||
}
|
||||
}
|
||||
|
||||
return createGroupContainer(context.view, components, {
|
||||
@@ -264,19 +263,19 @@ export function createSection(context: SectionContext): azdata.GroupContainer {
|
||||
});
|
||||
}
|
||||
|
||||
function processRow(rowInfo: RowInfo, context: SectionContext): azdata.Component {
|
||||
async function processRow(rowInfo: RowInfo, context: SectionContext): Promise<azdata.Component> {
|
||||
const items: azdata.Component[] = [];
|
||||
if ('items' in rowInfo.items[0]) { // rowInfo.items is RowInfo[]
|
||||
const rowItems = rowInfo.items as RowInfo[];
|
||||
items.push(...rowItems.map(rowInfo => processRow(rowInfo, context)));
|
||||
items.push(...(await Promise.all(rowItems.map(rowInfo => processRow(rowInfo, context)))));
|
||||
} else { // rowInfo.items is FieldInfo[]
|
||||
const fieldItems = rowInfo.items as FieldInfo[];
|
||||
processFields(fieldItems, items, context, context.sectionInfo.spaceBetweenFields === undefined ? '50px' : context.sectionInfo.spaceBetweenFields);
|
||||
await processFields(fieldItems, items, context, context.sectionInfo.spaceBetweenFields === undefined ? '50px' : context.sectionInfo.spaceBetweenFields);
|
||||
}
|
||||
return createFlexContainer(context.view, items, true, context.sectionInfo.fieldWidth, context.sectionInfo.fieldHeight, context.sectionInfo.fieldAlignItems, rowInfo.cssStyles);
|
||||
}
|
||||
|
||||
function processFields(fieldInfoArray: FieldInfo[], components: azdata.Component[], context: SectionContext, spaceBetweenFields?: string): void {
|
||||
async function processFields(fieldInfoArray: FieldInfo[], components: azdata.Component[], context: SectionContext, spaceBetweenFields?: string): Promise<void> {
|
||||
for (let i = 0; i < fieldInfoArray.length; i++) {
|
||||
const fieldInfo = fieldInfoArray[i];
|
||||
fieldInfo.labelWidth = fieldInfo.labelWidth || context.sectionInfo.labelWidth;
|
||||
@@ -285,7 +284,7 @@ function processFields(fieldInfoArray: FieldInfo[], components: azdata.Component
|
||||
fieldInfo.fieldWidth = fieldInfo.fieldWidth || context.sectionInfo.fieldWidth;
|
||||
fieldInfo.fieldHeight = fieldInfo.fieldHeight || context.sectionInfo.fieldHeight;
|
||||
fieldInfo.labelPosition = fieldInfo.labelPosition === undefined ? context.sectionInfo.labelPosition : fieldInfo.labelPosition;
|
||||
processField({
|
||||
await processField({
|
||||
view: context.view,
|
||||
onNewDisposableCreated: context.onNewDisposableCreated,
|
||||
onNewInputComponentCreated: context.onNewInputComponentCreated,
|
||||
@@ -338,7 +337,7 @@ function addLabelInputPairToContainer(view: azdata.ModelView, components: azdata
|
||||
}
|
||||
}
|
||||
|
||||
function processField(context: FieldContext): void {
|
||||
async function processField(context: FieldContext): Promise<void> {
|
||||
switch (context.fieldInfo.type) {
|
||||
case FieldType.Options:
|
||||
processOptionsTypeField(context);
|
||||
@@ -366,7 +365,7 @@ function processField(context: FieldContext): void {
|
||||
processAzureAccountField(context);
|
||||
break;
|
||||
case FieldType.AzureLocations:
|
||||
processAzureLocationsField(context);
|
||||
await processAzureLocationsField(context);
|
||||
break;
|
||||
case FieldType.FilePicker:
|
||||
processFilePickerField(context);
|
||||
@@ -735,7 +734,7 @@ async function processAzureAccountField(context: AzureAccountFieldContext): Prom
|
||||
const accountDropdown = createAzureAccountDropdown(context);
|
||||
const subscriptionDropdown = createAzureSubscriptionDropdown(context, subscriptionValueToSubscriptionMap);
|
||||
const resourceGroupDropdown = createAzureResourceGroupsDropdown(context, accountDropdown, accountValueToAccountMap, subscriptionDropdown, subscriptionValueToSubscriptionMap);
|
||||
const locationDropdown = context.fieldInfo.locations && processAzureLocationsField(context);
|
||||
const locationDropdown = context.fieldInfo.locations && await processAzureLocationsField(context);
|
||||
accountDropdown.onValueChanged(async selectedItem => {
|
||||
const selectedAccount = accountValueToAccountMap.get(selectedItem.selected)!;
|
||||
await handleSelectedAccountChanged(context, selectedAccount, subscriptionDropdown, subscriptionValueToSubscriptionMap, resourceGroupDropdown, locationDropdown);
|
||||
@@ -942,35 +941,26 @@ async function handleSelectedSubscriptionChanged(context: AzureAccountFieldConte
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of known Azure location friendly names to their internal names
|
||||
*/
|
||||
const knownAzureLocationNameMappings = new Map<string, string>([
|
||||
['East US', azurecore.AzureRegion.eastus],
|
||||
['East US 2', azurecore.AzureRegion.eastus2],
|
||||
['Central US', azurecore.AzureRegion.centralus],
|
||||
['West Europe', azurecore.AzureRegion.westeurope],
|
||||
['Southeast Asia', azurecore.AzureRegion.southeastasia],
|
||||
['West US 2', azurecore.AzureRegion.westus2]
|
||||
]);
|
||||
|
||||
/**
|
||||
* An Azure Locations field consists of a dropdown field for azure locations
|
||||
* @param context The context to use to create the field
|
||||
*/
|
||||
function processAzureLocationsField(context: AzureLocationsFieldContext): azdata.DropDownComponent {
|
||||
async function processAzureLocationsField(context: AzureLocationsFieldContext): Promise<azdata.DropDownComponent> {
|
||||
const label = createLabel(context.view, {
|
||||
text: context.fieldInfo.label || loc.location,
|
||||
required: context.fieldInfo.required,
|
||||
width: context.fieldInfo.labelWidth,
|
||||
cssStyles: context.fieldInfo.labelCSSStyles
|
||||
});
|
||||
const azurecoreApi = await apiService.getAzurecoreApi();
|
||||
const locationValues = context.fieldInfo.locations?.map(l => { return { name: l, displayName: azurecoreApi.getRegionDisplayName(l) }; });
|
||||
const locationDropdown = createDropdown(context.view, {
|
||||
defaultValue: locationValues?.find(l => l.name === context.fieldInfo.defaultValue),
|
||||
width: context.fieldInfo.inputWidth,
|
||||
editable: false,
|
||||
required: context.fieldInfo.required,
|
||||
label: loc.location,
|
||||
values: context.fieldInfo.locations
|
||||
values: locationValues
|
||||
});
|
||||
locationDropdown.fireOnTextChange = true;
|
||||
context.fieldInfo.subFields = context.fieldInfo.subFields || [];
|
||||
@@ -979,12 +969,6 @@ function processAzureLocationsField(context: AzureLocationsFieldContext): azdata
|
||||
label: label.value!,
|
||||
variableName: context.fieldInfo.locationVariableName
|
||||
});
|
||||
context.onNewInputComponentCreated(context.fieldInfo.locationVariableName, {
|
||||
component: locationDropdown,
|
||||
inputValueTransformer: (inputValue: string) => {
|
||||
return knownAzureLocationNameMappings.get(inputValue) || inputValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (context.fieldInfo.displayLocationVariableName) {
|
||||
context.fieldInfo.subFields!.push({
|
||||
@@ -993,12 +977,6 @@ function processAzureLocationsField(context: AzureLocationsFieldContext): azdata
|
||||
});
|
||||
context.onNewInputComponentCreated(context.fieldInfo.displayLocationVariableName, { component: locationDropdown });
|
||||
}
|
||||
context.onNewInputComponentCreated(context.fieldInfo.variableName!, {
|
||||
component: locationDropdown,
|
||||
inputValueTransformer: (inputValue: string) => {
|
||||
return knownAzureLocationNameMappings.get(inputValue) || inputValue;
|
||||
}
|
||||
});
|
||||
addLabelInputPairToContainer(context.view, context.components, label, locationDropdown, context.fieldInfo);
|
||||
return locationDropdown;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user