From fcc8c45e8cb922c351b384e34ce67dc660d3e5a2 Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Tue, 7 Jan 2025 12:09:49 +0200 Subject: [PATCH] Fix collection items traits --- .../model/collection_component/CollectionComponent.ts | 2 +- packages/core/src/dom_components/model/Component.ts | 5 +++-- .../dom_components/model/ComponentDynamicValueWatcher.ts | 4 ---- .../model/collection_component/CollectionComponent.ts | 3 +-- .../__snapshots__/CollectionComponent.ts.snap | 6 +++++- 5 files changed, 10 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 9cd735af4..f04e7dd87 100644 --- a/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts +++ b/packages/core/src/data_sources/model/collection_component/CollectionComponent.ts @@ -140,7 +140,7 @@ function getCollectionItems( [keyCollectionsStateMap]: collectionsStateMap, }, opt, - ).clone({ symbol: true }); + ); blockSymbolMain!.setSymbolOverride([keyCollectionsStateMap]); } blockSymbolMain!.set(keyCollectionsStateMap, collectionsStateMap); diff --git a/packages/core/src/dom_components/model/Component.ts b/packages/core/src/dom_components/model/Component.ts index e0250e513..60ff780a6 100644 --- a/packages/core/src/dom_components/model/Component.ts +++ b/packages/core/src/dom_components/model/Component.ts @@ -966,7 +966,7 @@ export default class Component extends StyleableModel { const value = trait.getInitValue(); if (trait.changeProp) { - this.set(name, value); + !this.get(name) && this.set(name, value); } else { if (name && value) attrs[name] = value; } @@ -1319,7 +1319,8 @@ export default class Component extends StyleableModel { clone(opt: { symbol?: boolean; symbolInv?: boolean } = {}): this { const em = this.em; const attr = { - ...this.componentDVListener.getPropsDefsOrValues(this.attributes), + ...this.attributes, + ...this.componentDVListener.getDynamicPropsDefs(), }; const opts = { ...this.opt }; const id = this.getId(); diff --git a/packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts b/packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts index b3be5d876..59ed335e5 100644 --- a/packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts +++ b/packages/core/src/dom_components/model/ComponentDynamicValueWatcher.ts @@ -90,10 +90,6 @@ export class ComponentDynamicValueWatcher { return this.attributeWatcher.getSerializableValues(attributes); } - getPropsDefsOrValues(props: ObjectAny) { - return this.propertyWatcher.getSerializableValues(props); - } - destroy() { this.propertyWatcher.removeListeners(); this.attributeWatcher.removeListeners(); diff --git a/packages/core/test/specs/data_sources/model/collection_component/CollectionComponent.ts b/packages/core/test/specs/data_sources/model/collection_component/CollectionComponent.ts index e1be911f9..fe4c4946f 100644 --- a/packages/core/test/specs/data_sources/model/collection_component/CollectionComponent.ts +++ b/packages/core/test/specs/data_sources/model/collection_component/CollectionComponent.ts @@ -167,8 +167,7 @@ describe('Collection component', () => { expect(firstChild.get('property_trait')).toBe('user1'); expect(secondChild.getAttributes()['attribute_trait']).toBe('user2'); - // TODO: Fix overrding traits - // expect(secondChild.get('property_trait')).toBe('user2'); + expect(secondChild.get('property_trait')).toBe('user2'); }); }); diff --git a/packages/core/test/specs/data_sources/model/collection_component/__snapshots__/CollectionComponent.ts.snap b/packages/core/test/specs/data_sources/model/collection_component/__snapshots__/CollectionComponent.ts.snap index 28b63f057..b90a3a6f6 100644 --- a/packages/core/test/specs/data_sources/model/collection_component/__snapshots__/CollectionComponent.ts.snap +++ b/packages/core/test/specs/data_sources/model/collection_component/__snapshots__/CollectionComponent.ts.snap @@ -22,7 +22,11 @@ exports[`Collection component Stringfication Collection with dynamic datasource "type": "parent-collection-variable", "variable_type": "current_item", }, - "property_trait": "user1", + "property_trait": { + "path": "user", + "type": "parent-collection-variable", + "variable_type": "current_item", + }, "type": "default", }, "collection_name": "my_collection",