From e2d4bbe2ed2f401c288ec48648875d0d0537e26f Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Mon, 6 Jan 2025 14:15:02 +0200 Subject: [PATCH] Refactor CollectionStateVariableType --- .../model/collection_component/types.ts | 24 +++++++++++++------ .../dom_components/model/ComponentTypes.ts | 5 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/core/src/data_sources/model/collection_component/types.ts b/packages/core/src/data_sources/model/collection_component/types.ts index 3b78451ee..e670974fb 100644 --- a/packages/core/src/data_sources/model/collection_component/types.ts +++ b/packages/core/src/data_sources/model/collection_component/types.ts @@ -11,14 +11,24 @@ type CollectionConfig = { dataSource: CollectionDataSource; }; +export enum CollectionStateVariableType { + current_index = 'current_index', + start_index = 'start_index', + current_item = 'current_item', + end_index = 'end_index', + collection_name = 'collection_name', + total_items = 'total_items', + remaining_items = 'remaining_items', +} + export type CollectionState = { - current_index: number; - start_index: number; - current_item: any; - end_index: number; - collection_name?: string; - total_items: number; - remaining_items: number; + [CollectionStateVariableType.current_index]: number; + [CollectionStateVariableType.start_index]: number; + [CollectionStateVariableType.current_item]: any; + [CollectionStateVariableType.end_index]: number; + [CollectionStateVariableType.collection_name]?: string; + [CollectionStateVariableType.total_items]: number; + [CollectionStateVariableType.remaining_items]: number; }; export type CollectionsStateMap = { diff --git a/packages/core/test/specs/dom_components/model/ComponentTypes.ts b/packages/core/test/specs/dom_components/model/ComponentTypes.ts index 1d240e46a..2cc912b97 100644 --- a/packages/core/test/specs/dom_components/model/ComponentTypes.ts +++ b/packages/core/test/specs/dom_components/model/ComponentTypes.ts @@ -1,5 +1,5 @@ import { CollectionVariableType } from '../../../../src/data_sources/model/collection_component/constants'; -import { CollectionState } from '../../../../src/data_sources/model/collection_component/types'; +import { CollectionStateVariableType } from '../../../../src/data_sources/model/collection_component/types'; import Editor from '../../../../src/editor'; describe('Component Types', () => { @@ -98,9 +98,10 @@ describe('Component Types', () => { expect(cmp.components().at(0).is('svg-in')).toBe(true); }); }); + export type CollectionVariableDefinition = { type: typeof CollectionVariableType; - variable_type: keyof CollectionState; + variable_type: CollectionStateVariableType; collection_name?: string; path?: string; };