@trudb/tru-common-lib 0.2.282 → 0.2.283

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7722,6 +7722,32 @@ class TruDataGrid {
7722
7722
  setNoRowsTemplate = () => {
7723
7723
  //this.noRowsTemplate = `<span style="font-size:14px;font-weight:bold;">No data found.</span>`;
7724
7724
  };
7725
+ applyRelationships = (newEntity) => {
7726
+ if (this.entity) {
7727
+ newEntity[this.config.parentTableRelationshipRefName] = this.entity[this.config.parentTableRefName];
7728
+ }
7729
+ if (this.gridType === TruDataGridTypes.DetailManyToMany) {
7730
+ //let parentName = this.entity.constructor.name;
7731
+ let unassociatedType = this.config.resultConfig.entityManyToManyType;
7732
+ let ref = this.selectedUnassociatedChoice.value.$;
7733
+ let childToAssociate = this.dataContext.entityAccess().searchByRefCacheOnly(unassociatedType, ref, true);
7734
+ if (childToAssociate) {
7735
+ let enhancedEntity = this.enhanceRowDataForEntity(newEntity);
7736
+ enhancedEntity.$entity[unassociatedType.name + 'Ref'] = childToAssociate[unassociatedType.name + 'Ref'];
7737
+ enhancedEntity.$entity[this.config.parentTableRelationshipRefName] = this.entity[this.config.parentTableRefName];
7738
+ // remove item from the add dropdown control
7739
+ let itemIndex = this.unassociatedChoices.findIndex((choice) => {
7740
+ return choice[unassociatedType.name + 'Ref'] === childToAssociate[unassociatedType.name + 'Ref'];
7741
+ });
7742
+ this.unassociatedChoices.splice(itemIndex, 1);
7743
+ // clear add selection
7744
+ this.selectedUnassociatedChoice = undefined;
7745
+ // add row to grid
7746
+ this.unsavedEntities.push(enhancedEntity);
7747
+ this.api.applyTransaction({ add: [enhancedEntity], addIndex: 0 });
7748
+ }
7749
+ }
7750
+ };
7725
7751
  subscribeTo = () => {
7726
7752
  this.subs.push(this.appEnvironment.onSaveComplete$.pipe(skip(1)).subscribe(event => {
7727
7753
  if (event?.successful)
@@ -7828,6 +7854,7 @@ class TruDataGrid {
7828
7854
  if (!entityAlreadyInGrid) {
7829
7855
  let enhancedEntity = this.enhanceRowDataForEntity(entity);
7830
7856
  if (changeArgs.entity.Ref < 0) {
7857
+ this.applyRelationships(entity);
7831
7858
  this.rowData.push(enhancedEntity);
7832
7859
  this.api.applyTransaction({ add: [enhancedEntity], addIndex: 0 });
7833
7860
  }