Browse Source

Fix path for static datasource

collection-component
mohamedsalem401 2 years ago
parent
commit
8fc94812f5
  1. 26
      packages/core/src/data_sources/model/collection_component/CollectionComponent.ts

26
packages/core/src/data_sources/model/collection_component/CollectionComponent.ts

@ -172,7 +172,7 @@ function resolveComponent(
const componentDefinition: ComponentDefinition = {
...componentJSON,
components: children,
[collectionsStateMapKey]: collectionsStateMap
[collectionsStateMapKey]: collectionsStateMap,
};
return componentDefinition;
@ -246,14 +246,22 @@ function resolveCurrentItem(
collectionItem: CollectionState,
path: string,
) {
const valueIsDataVariable = collectionItem.current_item?.type === DataVariableType;
if (variableType === 'current_item' && valueIsDataVariable) {
const currentItem_path = collectionItem.current_item.path;
const resolvedPath = currentItem_path ? `${currentItem_path}.${path}` : path;
return {
...collectionItem.current_item,
path: resolvedPath,
};
if (variableType === 'current_item') {
const valueIsDataVariable = collectionItem.current_item?.type === DataVariableType;
if (valueIsDataVariable) {
const currentItem_path = collectionItem.current_item.path;
const resolvedPath = currentItem_path ? `${currentItem_path}.${path}` : path;
return {
...collectionItem.current_item,
path: resolvedPath,
};
} else if (!!path) {
if (!collectionItem.current_item?.[path]) {
throw new Error(`Path not found in current item: ${path}`);
}
return collectionItem.current_item[path];
}
}
return collectionItem[variableType];
}

Loading…
Cancel
Save