Browse Source

Throw an error when using the name of a non-existent collection.

collection-component
mohamedsalem401 2 years ago
parent
commit
4a22be0c0e
  1. 23
      packages/core/src/data_sources/model/collection_component/CollectionComponent.ts

23
packages/core/src/data_sources/model/collection_component/CollectionComponent.ts

@ -151,17 +151,18 @@ function resolveBlockValues(context: any, block: any): any {
const collectionItem = blockValue.collection_name const collectionItem = blockValue.collection_name
? context[blockValue.collection_name] ? context[blockValue.collection_name]
: innerMostCollectionItem; : innerMostCollectionItem;
if (!collectionItem) continue; if (!collectionItem) {
throw new Error(
switch (blockValue.variable_type) { `Collection not found: ${blockValue.collection_name || 'default collection'}`
case 'current_item': );
clonedBlock[key] = blockValue.path }
? resolvePathValue(collectionItem.current_item, blockValue.path)
: JSON.stringify(collectionItem.current_item); if (blockValue.variable_type === 'current_item') {
break; clonedBlock[key] = blockValue.path
default: ? resolvePathValue(collectionItem.current_item, blockValue.path)
clonedBlock[key] = collectionItem[blockValue.variable_type]; : JSON.stringify(collectionItem.current_item);
break; } else {
clonedBlock[key] = collectionItem[blockValue.variable_type];
} }
} else if (Array.isArray(blockValue)) { } else if (Array.isArray(blockValue)) {
// Resolve each item in the array // Resolve each item in the array

Loading…
Cancel
Save