From fed1d7c765862e4fd371503cc9d393761f8e81c8 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 8 Dec 2025 13:55:24 +0400 Subject: [PATCH] Update resolveCollectionVariable --- .../src/data_sources/model/DataVariable.ts | 40 +++---------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/packages/core/src/data_sources/model/DataVariable.ts b/packages/core/src/data_sources/model/DataVariable.ts index 0f9bcf191..f8adf61d2 100644 --- a/packages/core/src/data_sources/model/DataVariable.ts +++ b/packages/core/src/data_sources/model/DataVariable.ts @@ -150,41 +150,13 @@ export default class DataVariable extends Model { ctx: DataVariableOptions, ) { const { collectionId = '', variableType, path, defaultValue = '' } = params; - const { em, collectionsStateMap } = ctx; + const { collectionsStateMap, em } = ctx; + const collectionItemState = collectionsStateMap?.[collectionId] as DataCollectionState | undefined; - if (!collectionsStateMap) return defaultValue; + if (!collectionItemState || !variableType) return defaultValue; - const collectionItem = collectionsStateMap[collectionId]; - if (!collectionItem) return defaultValue; - - if (!variableType) { - em.logError(`Missing collection variable type for collection: ${collectionId}`); - return defaultValue; - } - - if (variableType === 'currentItem') { - return DataVariable.resolveCurrentItem(collectionItem as DataCollectionState, path) ?? defaultValue; - } - - const state = collectionItem as DataCollectionState; - return state[variableType] ?? defaultValue; - } - - private static resolveCurrentItem(collectionItem: DataCollectionState, path: string | undefined) { - const currentItem = collectionItem.currentItem; - if (!currentItem) { - return; - } - - if (currentItem.type === DataVariableType) { - const resolvedPath = currentItem.path ? `${currentItem.path}.${path}` : path; - return { type: DataVariableType, path: resolvedPath }; - } - - if (path && !(currentItem as any)[path]) { - return; - } - - return path ? (currentItem as any)[path] : currentItem; + return em.DataSources.getValue(`${variableType}${path ? `.${path}` : ''}`, defaultValue, { + context: collectionItemState, + }); } }