Browse Source

Refactor collection keys

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

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

@ -8,9 +8,11 @@ import DataSource from '../DataSource';
import { ObjectAny } from '../../../common';
import EditorModel from '../../../editor/model/Editor';
export const CollectionVariableType = 'collection-component';
export const CollectionComponentType = 'collection-component';
export const CollectionVariableType = 'parent-collection-variable';
type CollectionVariable = {
type: 'parent-collection-variable';
type: typeof CollectionVariableType;
variable_type: keyof CollectionState;
collection_name?: string;
path?: string;
@ -39,7 +41,7 @@ type CollectionsStateMap = {
};
type CollectionDefinition = {
type: typeof CollectionVariableType;
type: typeof CollectionComponentType;
collection_name?: string;
config: CollectionConfig;
block: ComponentDefinition;
@ -99,7 +101,7 @@ export default class CollectionComponent extends Component {
const conditionalCmptDef = {
...props,
type: CollectionVariableType,
type: CollectionComponentType,
components: components,
dropbbable: false,
};
@ -108,7 +110,7 @@ export default class CollectionComponent extends Component {
}
static isComponent(el: HTMLElement) {
return toLowerCase(el.tagName) === CollectionVariableType;
return toLowerCase(el.tagName) === CollectionComponentType;
}
}
@ -186,11 +188,11 @@ function resolveBlockValues(collectionsStateMap: CollectionsStateMap, block: Obj
let hasCollectionVariable = false;
if (typeof blockValue === 'object') {
const isCollectionVariable = blockValue.type === 'parent-collection-variable';
const isCollectionVariable = blockValue.type === CollectionVariableType;
if (isCollectionVariable) {
const {
variable_type,
collection_name = 'innerMostCollectionItem',
collection_name = innerCollectionStateKey,
path = '',
} = blockValue as CollectionVariable;
const collectionItem = collectionsStateMap[collection_name];

Loading…
Cancel
Save