From d631ca73036ac7343835bab8d84d81665d6b723c Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Thu, 19 Dec 2024 23:00:53 +0200 Subject: [PATCH] Add start and end index for collections --- .../CollectionComponent.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 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 9a180ad30..1ce8cdc15 100644 --- a/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts +++ b/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts @@ -73,15 +73,20 @@ export default class CollectionComponent extends Component { default: } - const components: ComponentDefinitionDefined[] = items.map((item: CollectionStateVariables, index) => { + const components: ComponentDefinitionDefined[] = []; + const resolvedStartIndex = Math.max(0, start_index); + const resolvedEndIndex = Math.min(items.length - 1, end_index); + for (let index = resolvedStartIndex; index <= resolvedEndIndex; index++) { + const item = items[index]; + const total_items = resolvedEndIndex - resolvedStartIndex + 1; const innerMostCollectionItem = { collection_name, current_index: index, current_item: item, - start_index, - end_index, - total_items: items.length, - remaining_items: items.length - (index + 1), + start_index: resolvedStartIndex, + end_index: resolvedEndIndex, + total_items: total_items, + remaining_items: total_items - (index + 1), }; const allCollectionItems = { @@ -91,11 +96,9 @@ export default class CollectionComponent extends Component { innerMostCollectionItem } - let components = resolveBlockValues(allCollectionItems, block); - components[componentCollectionKey] = allCollectionItems; - - return components; - }); + const component = resolveBlockValues(allCollectionItems, block); + components.push(component); + } const conditionalCmptDef = { ...props,