Browse Source

update test data to better names

pages-datasources
mohamedsalem401 1 year ago
parent
commit
d2c2579447
  1. 20
      packages/core/src/data_sources/model/DataVariable.ts

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

@ -146,26 +146,25 @@ export default class DataVariable extends Model<DataVariableProps> {
} }
static resolveCollectionVariable( static resolveCollectionVariable(
{ params: {
collectionId = '',
variableType,
path,
defaultValue = '',
}: {
collectionId?: string; collectionId?: string;
variableType?: DataCollectionStateType; variableType?: DataCollectionStateType;
path?: string; path?: string;
defaultValue?: string; defaultValue?: string;
}, },
{ em, collectionsStateMap }: DataVariableOptions, ctx: DataVariableOptions,
) { ) {
const { collectionId = '', variableType, path, defaultValue = '' } = params;
const { em, collectionsStateMap } = ctx;
if (!collectionsStateMap) return defaultValue; if (!collectionsStateMap) return defaultValue;
const collectionItem = collectionsStateMap[collectionId]; const collectionItem = collectionsStateMap[collectionId];
if (!collectionItem) return defaultValue; if (!collectionItem) return defaultValue;
if (collectionId === keyRootData) { if (collectionId === keyRootData) {
return path ? (collectionItem as RootDataType)?.[path as keyof RootDataType] : collectionItem; const root = collectionItem as RootDataType;
return path ? root?.[path as keyof RootDataType] : root;
} }
if (!variableType) { if (!variableType) {
@ -174,10 +173,11 @@ export default class DataVariable extends Model<DataVariableProps> {
} }
if (variableType === 'currentItem') { if (variableType === 'currentItem') {
return DataVariable.resolveCurrentItem(collectionItem, path, collectionId, em); return DataVariable.resolveCurrentItem(collectionItem as DataCollectionState, path, collectionId, em);
} }
return collectionItem[variableType] ?? defaultValue; const state = collectionItem as DataCollectionState;
return state[variableType] ?? defaultValue;
} }
private static resolveCurrentItem( private static resolveCurrentItem(

Loading…
Cancel
Save