bloomreach / spa-sdk

Apache License 2.0
15 stars 16 forks source link

Params in component not accessible #24

Open ienemien opened 10 months ago

ienemien commented 10 months ago

We are trying to add some 'dynamic' parameters (not dynamic as in that they are added to the component config of a dynamic component, but I extended the backend so that these parameters are added dynamically). This means they are not in the "paramsInfo" in the pagemodel, but in the "params" (this is expected according to this documentation: https://xmdocumentation.bloomreach.com/library/concepts/page-model-api/page-model-api-v1.0.html).

I also see this field in the ContainerItemMeta interface in: https://github.com/bloomreach/spa-sdk/blob/main/packages/spa-sdk/src/page/container-item.ts but they are not returned when calling component.getParameters() and there's also no other method to reach them. Would it be possible to return them in addition to the paramsInfo when calling getParameters()? I see that in the Component class, it does return the params instead of paramsInfo, but most of the components where we want this are of type ContainerItemImpl.

joerideg commented 9 months ago

Hi @ienemien , Sorry for the late reply, it slipped my radar. Yes I agree this should be possible and is not right now. I notice that in the Component class the getProperties method returns the meta.params but then we override it in the ContainerItem class by returning meta.paramsInfo. We should at least return a merge of the two.

I'll plan in an improvement issue for this.

joerideg commented 9 months ago

As a temporary work around you can access the params and paramsInfo properties directly from the component instance models.meta property like:

const params = props.component.model.meta.params; 
const paramsInfo = props.component.model.meta.paramsInfo; 

Of course you might have to convince Typescript that this is ok :)