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 = { const componentDefinition: ComponentDefinition = {
...componentJSON, ...componentJSON,
components: children, components: children,
[collectionsStateMapKey]: collectionsStateMap [collectionsStateMapKey]: collectionsStateMap,
}; };
return componentDefinition; return componentDefinition;
@ -246,14 +246,22 @@ function resolveCurrentItem(
collectionItem: CollectionState, collectionItem: CollectionState,
path: string, path: string,
) { ) {
const valueIsDataVariable = collectionItem.current_item?.type === DataVariableType; if (variableType === 'current_item') {
if (variableType === 'current_item' && valueIsDataVariable) { const valueIsDataVariable = collectionItem.current_item?.type === DataVariableType;
const currentItem_path = collectionItem.current_item.path; if (valueIsDataVariable) {
const resolvedPath = currentItem_path ? `${currentItem_path}.${path}` : path; const currentItem_path = collectionItem.current_item.path;
return { const resolvedPath = currentItem_path ? `${currentItem_path}.${path}` : path;
...collectionItem.current_item, return {
path: resolvedPath, ...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]; return collectionItem[variableType];
} }

Loading…
Cancel
Save