From 79301dabf84e058f0e64d90a401481a316364e35 Mon Sep 17 00:00:00 2001 From: Julien Schneider Date: Thu, 7 Mar 2024 15:54:01 +0100 Subject: [PATCH] fix: hotfix for list is undefined (sentry JA-1) (#1508) --- .../resource-class-property-info.component.ts | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/apps/dsp-app/src/app/project/ontology/resource-class-info/resource-class-property-info/resource-class-property-info.component.ts b/apps/dsp-app/src/app/project/ontology/resource-class-info/resource-class-property-info/resource-class-property-info.component.ts index 335f227cd9..186c8179cf 100644 --- a/apps/dsp-app/src/app/project/ontology/resource-class-info/resource-class-property-info/resource-class-property-info.component.ts +++ b/apps/dsp-app/src/app/project/ontology/resource-class-info/resource-class-property-info/resource-class-property-info.component.ts @@ -6,6 +6,7 @@ import { Inject, Input, OnChanges, + OnDestroy, Output, } from '@angular/core'; import { @@ -21,6 +22,8 @@ import { DspApiConnectionToken } from '@dasch-swiss/vre/shared/app-config'; import { DefaultClass, DefaultProperty, OntologyService } from '@dasch-swiss/vre/shared/app-helper-services'; import { ListsSelectors, OntologiesSelectors } from '@dasch-swiss/vre/shared/app-state'; import { Store } from '@ngxs/store'; +import { Subject, Subscription } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; // property data structure export class Property { @@ -53,7 +56,7 @@ type CardinalityKey = 'multiple' | 'required'; templateUrl: './resource-class-property-info.component.html', styleUrls: ['./resource-class-property-info.component.scss'], }) -export class ResourceClassPropertyInfoComponent implements OnChanges, AfterContentInit { +export class ResourceClassPropertyInfoComponent implements OnChanges, AfterContentInit, OnDestroy { @Input() propDef: ResourcePropertyDefinitionWithAllLanguages; @Input() propCard: IHasProperty; @@ -78,6 +81,8 @@ export class ResourceClassPropertyInfoComponent implements OnChanges, AfterConte targetCardinality: GuiCardinality; }>(); + isDestroyed = new Subject(); + propInfo: Property = new Property(); propType: DefaultProperty; @@ -86,7 +91,6 @@ export class ResourceClassPropertyInfoComponent implements OnChanges, AfterConte propAttributeComment: string; propCanBeRemovedFromClass: boolean; - constructor( @Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection, @@ -143,16 +147,22 @@ export class ResourceClassPropertyInfoComponent implements OnChanges, AfterConte } // get current ontology lists to get linked list information - const currentOntologyLists = this._store.selectSnapshot(ListsSelectors.listsInProject); - if (currentOntologyLists && this.propDef.objectType === Constants.ListValue) { - // this property is a list property - const re = /\<([^)]+)\>/; - const listIri = this.propDef.guiAttributes[0].match(re)[1]; - const listUrl = `/project/${this.projectUuid}/list/${listIri.split('/').pop()}`; - const list = currentOntologyLists.find(i => i.id === listIri); - this.propAttribute = `${list.labels[0].value}`; - this.propAttributeComment = list.comments.length ? list.comments[0].value : null; - } + this._store + .select(ListsSelectors.listsInProject) + .pipe(takeUntil(this.isDestroyed)) + .subscribe(currentOntologyLists => { + if (currentOntologyLists && this.propDef.objectType === Constants.ListValue) { + // this property is a list property + const re = /\<([^)]+)\>/; + const listIri = this.propDef.guiAttributes[0].match(re)[1]; + const listUrl = `/project/${this.projectUuid}/list/${listIri.split('/').pop()}`; + const list = currentOntologyLists.find(i => i.id === listIri); + if (list) { + this.propAttribute = `${list.labels[0].value}`; + this.propAttributeComment = list.comments.length ? list.comments[0].value : null; + } + } + }); } /** @@ -192,4 +202,9 @@ export class ResourceClassPropertyInfoComponent implements OnChanges, AfterConte this._cd.markForCheck(); }); } + + ngOnDestroy() { + this.isDestroyed.next(); + this.isDestroyed.complete(); + } }