From acbd15cf35a20c14f1b8fa14e04abe5f3f7b8be4 Mon Sep 17 00:00:00 2001 From: mohamedsalem401 Date: Wed, 29 Jan 2025 13:43:18 +0200 Subject: [PATCH] Fallback to keyCollectionDefinition if no collection items were found --- .../model/data_collection/ComponentDataCollection.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts b/packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts index 2b015f87c..b9b3f2368 100644 --- a/packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts +++ b/packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts @@ -69,8 +69,8 @@ export default class ComponentDataCollection extends Component { toJSON(opts?: ObjectAny) { const json = super.toJSON.call(this, opts) as ComponentDataCollectionDefinition; - const firstChild = this.getComponentDef(); - json[keyCollectionDefinition].componentDef = firstChild; + const firstChildJSON = this.getComponentDef(); + json[keyCollectionDefinition].componentDef = firstChildJSON ?? this.get(keyCollectionDefinition); delete json.components; delete json.droppable; @@ -78,8 +78,9 @@ export default class ComponentDataCollection extends Component { } private getComponentDef() { - const firstChildJSON = JSON.parse(JSON.stringify(this.components().at(0))); - delete firstChildJSON.draggable; + const firstChild = this.components().at(0); + const firstChildJSON = firstChild?.toJSON(); + delete firstChildJSON?.draggable; return firstChildJSON; }