Hi everyone,
IExternalEnumerationProvider from js-commons cannot be implemented to fetch data remotely, because such call would need to be asynchronous. The possibility I see is for it to return values from a prop set by mapStateToProps, it means from the redux-store. Do you have any recommendation on how to load data for external enumerations? Should it be done by the DataLoader? It would then return an object of type FormData & { myEnumValues: EnumValue[] }.
Hi @krzysztof-smooth-brush the form engine itself doesn’t know how you load data for external enumeration. It just knows about IExternalEnumerationProvider which return the correct data as EnumValue.
You can define your own DataLoader (which is encourage whenever you need to load data from out side) allows you to load data within load function of DataLoader. Just to make sure when FormEngine initialize it needs the data from EnumerationProvider to give you the correct drop down display.
Within the new release 2.0.0 please notice <INTERNAL_LINK> the name has been changed from FormData to DocumentData.
If you load the enum values along with the actual data, then I would use the DataLoader. However, you must be careful that you actual data.document isn’t lost.
Another option would be to use Activity.slices. This is safer, but requires you to handle the loading in your own Saga - but if you already have one, it would be no problem.
Thank you for your opinions. I was able to use the DataLoader that loads the document to also load the values for the enum. The only thing that was not so obvious was that it is needed to postpone creation of the FormEngine until all data is in the store:
function BesuchsberichtContainer(props: ViewViews.FormEngineProps & StateProps): JSX.Element {
return props.activity.loadingState === "loaded" ?
<ViewViews.FormEngine
additionalOptions={{
externalEnumerationProvider: props.externalEnumerationProvider,
widgetFactory: new CustomWidgetFactory()
}}
{...props} /> :
<div />;
}
where the externalEnumerationProvider is implemented this way:
source => {
switch (source) {
case "dealer":
return activity.data.dealers;
default:
return [];
}
}
I think it is because the provider references initial copy of Activity.