Browse Source

Add start and end index for collections

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

23
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,

Loading…
Cancel
Save