Browse Source

Fallback to keyCollectionDefinition if no collection items were found

collection-component
mohamedsalem401 2 years ago
parent
commit
acbd15cf35
  1. 9
      packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts

9
packages/core/src/data_sources/model/data_collection/ComponentDataCollection.ts

@ -69,8 +69,8 @@ export default class ComponentDataCollection extends Component {
toJSON(opts?: ObjectAny) { toJSON(opts?: ObjectAny) {
const json = super.toJSON.call(this, opts) as ComponentDataCollectionDefinition; const json = super.toJSON.call(this, opts) as ComponentDataCollectionDefinition;
const firstChild = this.getComponentDef(); const firstChildJSON = this.getComponentDef();
json[keyCollectionDefinition].componentDef = firstChild; json[keyCollectionDefinition].componentDef = firstChildJSON ?? this.get(keyCollectionDefinition);
delete json.components; delete json.components;
delete json.droppable; delete json.droppable;
@ -78,8 +78,9 @@ export default class ComponentDataCollection extends Component {
} }
private getComponentDef() { private getComponentDef() {
const firstChildJSON = JSON.parse(JSON.stringify(this.components().at(0))); const firstChild = this.components().at(0);
delete firstChildJSON.draggable; const firstChildJSON = firstChild?.toJSON();
delete firstChildJSON?.draggable;
return firstChildJSON; return firstChildJSON;
} }

Loading…
Cancel
Save