Skip to content

Commit 8cf995e

Browse files
authored
Update resolveCollectionVariable (#6670)
1 parent 9e065b1 commit 8cf995e

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

packages/core/src/data_sources/model/DataVariable.ts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -150,41 +150,13 @@ export default class DataVariable extends Model<DataVariableProps> {
150150
ctx: DataVariableOptions,
151151
) {
152152
const { collectionId = '', variableType, path, defaultValue = '' } = params;
153-
const { em, collectionsStateMap } = ctx;
153+
const { collectionsStateMap, em } = ctx;
154+
const collectionItemState = collectionsStateMap?.[collectionId] as DataCollectionState | undefined;
154155

155-
if (!collectionsStateMap) return defaultValue;
156+
if (!collectionItemState || !variableType) return defaultValue;
156157

157-
const collectionItem = collectionsStateMap[collectionId];
158-
if (!collectionItem) return defaultValue;
159-
160-
if (!variableType) {
161-
em.logError(`Missing collection variable type for collection: ${collectionId}`);
162-
return defaultValue;
163-
}
164-
165-
if (variableType === 'currentItem') {
166-
return DataVariable.resolveCurrentItem(collectionItem as DataCollectionState, path) ?? defaultValue;
167-
}
168-
169-
const state = collectionItem as DataCollectionState;
170-
return state[variableType] ?? defaultValue;
171-
}
172-
173-
private static resolveCurrentItem(collectionItem: DataCollectionState, path: string | undefined) {
174-
const currentItem = collectionItem.currentItem;
175-
if (!currentItem) {
176-
return;
177-
}
178-
179-
if (currentItem.type === DataVariableType) {
180-
const resolvedPath = currentItem.path ? `${currentItem.path}.${path}` : path;
181-
return { type: DataVariableType, path: resolvedPath };
182-
}
183-
184-
if (path && !(currentItem as any)[path]) {
185-
return;
186-
}
187-
188-
return path ? (currentItem as any)[path] : currentItem;
158+
return em.DataSources.getValue(`${variableType}${path ? `.${path}` : ''}`, defaultValue, {
159+
context: collectionItemState,
160+
});
189161
}
190162
}

0 commit comments

Comments
 (0)