From 3664aedfd43aa0023138c92b99c46587affee307 Mon Sep 17 00:00:00 2001 From: Tarnavskiy Date: Tue, 27 Dec 2022 15:32:47 +0200 Subject: [PATCH] Get currentEntity data from stateParams instead doing find-request --- ui-ngx/src/app/core/http/entity.service.ts | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index b66399de6c..2493b11a64 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -869,8 +869,38 @@ export class EntityService { }; aliasInfo.currentEntity = null; if (!aliasInfo.resolveMultiple && aliasInfo.entityFilter) { - return this.findSingleEntityInfoByEntityFilter(aliasInfo.entityFilter, - {ignoreLoading: true, ignoreErrors: true}).pipe( + let entityInfoObservable: Observable; + if (result.stateEntity && aliasInfo.entityFilter.type === AliasFilterType.singleEntity) { + let currentEntity: EntityInfo = null; + if (stateParams) { + if (result.entityParamName && result.entityParamName.length) { + const stateEntity = stateParams[result.entityParamName]; + if (stateEntity) { + currentEntity = { + id: stateEntity.entityId.id, + entityType: stateEntity.entityId.entityType, + name: stateEntity.entityName, + label: stateEntity.entityLabel + }; + } + } else { + if (stateParams.entityId) { + currentEntity = { + id: stateParams.entityId.id, + entityType: stateParams.entityId.entityType as EntityType, + name: stateParams.entityName, + label: stateParams.entityLabel + }; + } + } + } + entityInfoObservable = currentEntity ? of(currentEntity) : this.findSingleEntityInfoByEntityFilter(aliasInfo.entityFilter, + {ignoreLoading: true, ignoreErrors: true}); + } else { + entityInfoObservable = this.findSingleEntityInfoByEntityFilter(aliasInfo.entityFilter, + {ignoreLoading: true, ignoreErrors: true}); + } + return entityInfoObservable.pipe( map((entity) => { aliasInfo.currentEntity = entity; return aliasInfo;