From 8fc94812f5188943a308de0d9adb9f3df0e3ea20 Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Mon, 30 Dec 2024 04:06:35 +0200 Subject: [PATCH] Fix path for static datasource --- .../CollectionComponent.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts b/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts index d9441feeb..4a3c70102 100644 --- a/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts +++ b/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]; }