From 43d221e5cebf427fd875e9869283e9c431f7f332 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Fri, 12 Mar 2021 14:39:23 +0200 Subject: [PATCH] Fix data resolution for entity count datasource type. --- .../src/app/core/api/entity-data.service.ts | 14 +++++++-- .../entity/entity-autocomplete.component.ts | 30 ++++++++++++------- .../app/shared/models/query/query.models.ts | 2 +- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/ui-ngx/src/app/core/api/entity-data.service.ts b/ui-ngx/src/app/core/api/entity-data.service.ts index 6466ba918f..d9df28baba 100644 --- a/ui-ngx/src/app/core/api/entity-data.service.ts +++ b/ui-ngx/src/app/core/api/entity-data.service.ts @@ -60,6 +60,16 @@ export class EntityDataService { constructor(private telemetryService: TelemetryWebsocketService, private utils: UtilsService) {} + private static isUnresolvedDatasource(datasource: Datasource, pageLink: EntityDataPageLink): boolean { + if (datasource.type === DatasourceType.entity) { + return !datasource.entityFilter || !pageLink; + } else if (datasource.type === DatasourceType.entityCount) { + return !datasource.entityFilter; + } else { + return false; + } + } + public prepareSubscription(listener: EntityDataListener, ignoreDataUpdateOnIntervalTick = false): Observable { const datasource = listener.configDatasource; @@ -71,7 +81,7 @@ export class EntityDataService { null, false, ignoreDataUpdateOnIntervalTick); - if (datasource.type === DatasourceType.entity && (!datasource.entityFilter || !datasource.pageLink)) { + if (EntityDataService.isUnresolvedDatasource(datasource, datasource.pageLink)) { return of(null); } listener.subscription = new EntityDataSubscription(listener, this.telemetryService, this.utils); @@ -100,7 +110,7 @@ export class EntityDataService { keyFilters, true, ignoreDataUpdateOnIntervalTick); - if (datasource.type === DatasourceType.entity && (!datasource.entityFilter || !pageLink)) { + if (EntityDataService.isUnresolvedDatasource(datasource, pageLink)) { listener.dataLoaded(emptyPageData(), [], listener.configDatasourceIndex, listener.subscriptionOptions.pageLink); return of(null); diff --git a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts index bdd2ac0d4d..d862e30d42 100644 --- a/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts +++ b/ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts @@ -271,19 +271,27 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit ); } else { const targetEntityType = this.checkEntityType(value.entityType); - this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true, ignoreErrors: true}).subscribe( - (entity) => { - this.modelValue = entity.id.id; - this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false}); - }, - () => { - this.modelValue = null; - this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); - if (value !== null) { - this.propagateChange(this.modelValue); + if (value.id) { + this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true, ignoreErrors: true}).subscribe( + (entity) => { + this.modelValue = entity.id.id; + this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false}); + }, + () => { + this.modelValue = null; + this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); + if (value !== null) { + this.propagateChange(this.modelValue); + } } + ); + } else { + this.modelValue = null; + this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); + if (value !== null) { + this.propagateChange(this.modelValue); } - ); + } } } else { this.modelValue = null; diff --git a/ui-ngx/src/app/shared/models/query/query.models.ts b/ui-ngx/src/app/shared/models/query/query.models.ts index 6bc2d74487..fd7fa68b5e 100644 --- a/ui-ngx/src/app/shared/models/query/query.models.ts +++ b/ui-ngx/src/app/shared/models/query/query.models.ts @@ -818,7 +818,7 @@ export function updateDatasourceFromEntityInfo(datasource: Datasource, entity: E }; datasource.entityId = entity.id; datasource.entityType = entity.entityType; - if (datasource.type === DatasourceType.entity) { + if (datasource.type === DatasourceType.entity || datasource.type === DatasourceType.entityCount) { datasource.entityName = entity.name; datasource.entityLabel = entity.label; datasource.name = entity.name;