mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Make loading components not valid and improve RD radio group (#13738)
This commit is contained in:
@@ -614,7 +614,6 @@ async function processOptionsTypeField(context: FieldContext): Promise<void> {
|
|||||||
if (context.fieldInfo.options.source?.providerId) {
|
if (context.fieldInfo.options.source?.providerId) {
|
||||||
try {
|
try {
|
||||||
context.fieldInfo.options.source.provider = optionsSourcesService.getOptionsSource(context.fieldInfo.options.source.providerId);
|
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) {
|
catch (e) {
|
||||||
disableControlButtons(context.container);
|
disableControlButtons(context.container);
|
||||||
@@ -628,16 +627,25 @@ async function processOptionsTypeField(context: FieldContext): Promise<void> {
|
|||||||
context.fieldInfo.subFields = context.fieldInfo.subFields || [];
|
context.fieldInfo.subFields = context.fieldInfo.subFields || [];
|
||||||
}
|
}
|
||||||
let optionsComponent: RadioGroupLoadingComponentBuilder | azdata.DropDownComponent;
|
let optionsComponent: RadioGroupLoadingComponentBuilder | azdata.DropDownComponent;
|
||||||
|
const options = context.fieldInfo.options;
|
||||||
|
const optionsSource = options.source;
|
||||||
if (context.fieldInfo.options.optionsType === OptionsType.Radio) {
|
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 {
|
} else {
|
||||||
throwUnless(context.fieldInfo.options.optionsType === OptionsType.Dropdown, loc.optionsTypeRadioOrDropdown);
|
throwUnless(context.fieldInfo.options.optionsType === OptionsType.Dropdown, loc.optionsTypeRadioOrDropdown);
|
||||||
optionsComponent = processDropdownOptionsTypeField(context);
|
optionsComponent = processDropdownOptionsTypeField(context);
|
||||||
}
|
}
|
||||||
const optionsSource = context.fieldInfo.options.source;
|
|
||||||
if (optionsSource?.provider) {
|
if (optionsSource?.provider) {
|
||||||
const optionsSourceProvider = 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);
|
await configureOptionsSourceSubfields(context, optionsSource, key, optionsComponent, optionsSourceProvider);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -966,8 +974,8 @@ async function processKubeConfigClusterPickerField(context: KubeClusterContextFi
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processRadioOptionsTypeField(context: FieldContext): Promise<RadioGroupLoadingComponentBuilder> {
|
async function processRadioOptionsTypeField(context: FieldContext, getRadioButtonInfo?: () => Promise<OptionsInfo>): Promise<RadioGroupLoadingComponentBuilder> {
|
||||||
return await createRadioOptions(context);
|
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);
|
addLabelInputPairToContainer(context.view, context.components, label, radioGroupLoadingComponentBuilder.component(), context.fieldInfo);
|
||||||
const options = context.fieldInfo.options as OptionsInfo;
|
const options = context.fieldInfo.options as OptionsInfo;
|
||||||
await radioGroupLoadingComponentBuilder.loadOptions(
|
// Start loading the options but continue on so that we can continue setting up the rest of the components - the group
|
||||||
getRadioButtonInfo || options); // wait for the radioGroup to be fully initialized
|
// 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;
|
return radioGroupLoadingComponentBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ export default class LoadingComponent extends ComponentBase<azdata.LoadingCompon
|
|||||||
if (!this._component) {
|
if (!this._component) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (this.loading) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return this.modelStore.getComponent(this._component.id).validate();
|
return this.modelStore.getComponent(this._component.id).validate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user