Make loading components not valid and improve RD radio group (#13738)

This commit is contained in:
Charles Gagnon
2020-12-09 13:15:35 -08:00
committed by GitHub
parent 91522caa67
commit e7884b8b61
2 changed files with 21 additions and 8 deletions

View File

@@ -614,7 +614,6 @@ async function processOptionsTypeField(context: FieldContext): Promise<void> {
if (context.fieldInfo.options.source?.providerId) {
try {
context.fieldInfo.options.source.provider = optionsSourcesService.getOptionsSource(context.fieldInfo.options.source.providerId);
context.fieldInfo.options.values = await context.fieldInfo.options.source.provider.getOptions();
}
catch (e) {
disableControlButtons(context.container);
@@ -628,16 +627,25 @@ async function processOptionsTypeField(context: FieldContext): Promise<void> {
context.fieldInfo.subFields = context.fieldInfo.subFields || [];
}
let optionsComponent: RadioGroupLoadingComponentBuilder | azdata.DropDownComponent;
const options = context.fieldInfo.options;
const optionsSource = options.source;
if (context.fieldInfo.options.optionsType === OptionsType.Radio) {
optionsComponent = await processRadioOptionsTypeField(context);
let getRadioOptions: (() => Promise<OptionsInfo>) | undefined = undefined;
// If the options are provided for us then set up the callback to load those options async'ly
if (optionsSource?.provider) {
getRadioOptions = async () => {
return { defaultValue: options.defaultValue, values: await optionsSource.provider!.getOptions() };
};
}
optionsComponent = await processRadioOptionsTypeField(context, getRadioOptions);
} else {
throwUnless(context.fieldInfo.options.optionsType === OptionsType.Dropdown, loc.optionsTypeRadioOrDropdown);
optionsComponent = processDropdownOptionsTypeField(context);
}
const optionsSource = context.fieldInfo.options.source;
if (optionsSource?.provider) {
const optionsSourceProvider = optionsSource.provider;
await Promise.all(Object.keys(context.fieldInfo.options.source?.variableNames ?? {}).map(async key => {
await Promise.all(Object.keys(optionsSource?.variableNames ?? {}).map(async key => {
await configureOptionsSourceSubfields(context, optionsSource, key, optionsComponent, optionsSourceProvider);
}));
}
@@ -966,8 +974,8 @@ async function processKubeConfigClusterPickerField(context: KubeClusterContextFi
}
async function processRadioOptionsTypeField(context: FieldContext): Promise<RadioGroupLoadingComponentBuilder> {
return await createRadioOptions(context);
async function processRadioOptionsTypeField(context: FieldContext, getRadioButtonInfo?: () => Promise<OptionsInfo>): Promise<RadioGroupLoadingComponentBuilder> {
return await createRadioOptions(context, getRadioButtonInfo);
}
@@ -989,8 +997,10 @@ async function createRadioOptions(context: FieldContext, getRadioButtonInfo?: ((
});
addLabelInputPairToContainer(context.view, context.components, label, radioGroupLoadingComponentBuilder.component(), context.fieldInfo);
const options = context.fieldInfo.options as OptionsInfo;
await radioGroupLoadingComponentBuilder.loadOptions(
getRadioButtonInfo || options); // wait for the radioGroup to be fully initialized
// Start loading the options but continue on so that we can continue setting up the rest of the components - the group
// will show a loading spinner while the options are loaded
radioGroupLoadingComponentBuilder.loadOptions(
getRadioButtonInfo || options).catch(e => console.log('Error loading options for radio group ', e));
return radioGroupLoadingComponentBuilder;
}