@memberjunction/ng-link-directives 0.9.124 → 0.9.127

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.
@@ -12,6 +12,7 @@ export declare class FieldLink extends BaseLink implements OnInit {
12
12
  fieldName: string;
13
13
  replaceText: boolean;
14
14
  private _targetEntity;
15
+ private _targetEntityInfo;
15
16
  private _targetRecordID;
16
17
  constructor(el: ElementRef, renderer: Renderer2, route: ActivatedRoute, router: Router);
17
18
  get field(): EntityField;
@@ -29,6 +29,10 @@ export class FieldLink extends BaseLink {
29
29
  if (relatedEntity && relatedEntity.length > 0) {
30
30
  this._targetEntity = relatedEntity;
31
31
  this._targetRecordID = this.field.Value;
32
+ const md = new Metadata();
33
+ this._targetEntityInfo = md.Entities.find(e => e.Name === relatedEntity);
34
+ if (!this._targetEntityInfo)
35
+ throw new Error('Related entity not found in metadata: ' + relatedEntity);
32
36
  this.CreateLink(this.el, this.field, this.renderer, '', false);
33
37
  if (this.replaceText) {
34
38
  // replace the value of the field with the record name
@@ -44,8 +48,11 @@ export class FieldLink extends BaseLink {
44
48
  // make sure that this.field.Value is not null or undefined
45
49
  // we didn't have the related field mapping info (above), no related entity name field map provided in the entity field metadata, so do a lookup
46
50
  // requires a server round trip and hitting the DB, so we try to avoid this
47
- const md = new Metadata();
48
- md.GetEntityRecordName(relatedEntity, [{ FieldName: "ID", Value: this.field.Value }]).then(recordName => {
51
+ const pkVals = [{
52
+ FieldName: this._targetEntityInfo.PrimaryKey.Name, // AT THE MOMENT - we only support foreign keys with a single value
53
+ Value: this.field.Value
54
+ }];
55
+ md.GetEntityRecordName(relatedEntity, pkVals).then(recordName => {
49
56
  if (recordName && recordName.length > 0)
50
57
  this.renderer.setProperty(this.el.nativeElement, 'textContent', recordName);
51
58
  });
@@ -58,7 +65,11 @@ export class FieldLink extends BaseLink {
58
65
  }
59
66
  onClick(event) {
60
67
  event.preventDefault();
61
- this.router.navigate(['resource', 'record', this._targetRecordID], { queryParams: { Entity: this._targetEntity } });
68
+ if (!this._targetEntityInfo)
69
+ throw new Error('targetEntityInfo not set');
70
+ // AT THE MOMENT - we only support foreign keys with a single value
71
+ const keyVals = `${this._targetEntityInfo.PrimaryKey.Name}|${this._targetRecordID}`;
72
+ this.router.navigate(['resource', 'record', keyVals], { queryParams: { Entity: this._targetEntity } });
62
73
  }
63
74
  }
64
75
  FieldLink.ɵfac = function FieldLink_Factory(t) { return new (t || FieldLink)(i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i1.ActivatedRoute), i0.ɵɵdirectiveInject(i1.Router)); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ng-link-directives",
3
- "version": "0.9.124",
3
+ "version": "0.9.127",
4
4
  "description": "MemberJunction: Angular Link Directives for turning an element in an angular app into an email, web, or record link",
5
5
  "main": "./dist/public-api.js",
6
6
  "typings": "./dist/public-api.d.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "tslib": "^2.3.0",
33
- "@memberjunction/core": "^0.9.168"
33
+ "@memberjunction/core": "^0.9.171"
34
34
  },
35
35
  "sideEffects": false
36
36
  }