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

Loading…
Cancel
Save