Skip to content

Commit

Permalink
Fallback to keyCollectionDefinition if no collection items were found
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Jan 29, 2025
1 parent 214f425 commit acbd15c
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ 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;
return json;
}

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;
}
Expand Down

0 comments on commit acbd15c

Please sign in to comment.