Commit 43d221e5cebf427fd875e9869283e9c431f7f332
1 parent
d61890a9
Fix data resolution for entity count datasource type.
Showing
3 changed files
with
32 additions
and
14 deletions
@@ -60,6 +60,16 @@ export class EntityDataService { | @@ -60,6 +60,16 @@ export class EntityDataService { | ||
60 | constructor(private telemetryService: TelemetryWebsocketService, | 60 | constructor(private telemetryService: TelemetryWebsocketService, |
61 | private utils: UtilsService) {} | 61 | private utils: UtilsService) {} |
62 | 62 | ||
63 | + private static isUnresolvedDatasource(datasource: Datasource, pageLink: EntityDataPageLink): boolean { | ||
64 | + if (datasource.type === DatasourceType.entity) { | ||
65 | + return !datasource.entityFilter || !pageLink; | ||
66 | + } else if (datasource.type === DatasourceType.entityCount) { | ||
67 | + return !datasource.entityFilter; | ||
68 | + } else { | ||
69 | + return false; | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
63 | public prepareSubscription(listener: EntityDataListener, | 73 | public prepareSubscription(listener: EntityDataListener, |
64 | ignoreDataUpdateOnIntervalTick = false): Observable<EntityDataLoadResult> { | 74 | ignoreDataUpdateOnIntervalTick = false): Observable<EntityDataLoadResult> { |
65 | const datasource = listener.configDatasource; | 75 | const datasource = listener.configDatasource; |
@@ -71,7 +81,7 @@ export class EntityDataService { | @@ -71,7 +81,7 @@ export class EntityDataService { | ||
71 | null, | 81 | null, |
72 | false, | 82 | false, |
73 | ignoreDataUpdateOnIntervalTick); | 83 | ignoreDataUpdateOnIntervalTick); |
74 | - if (datasource.type === DatasourceType.entity && (!datasource.entityFilter || !datasource.pageLink)) { | 84 | + if (EntityDataService.isUnresolvedDatasource(datasource, datasource.pageLink)) { |
75 | return of(null); | 85 | return of(null); |
76 | } | 86 | } |
77 | listener.subscription = new EntityDataSubscription(listener, this.telemetryService, this.utils); | 87 | listener.subscription = new EntityDataSubscription(listener, this.telemetryService, this.utils); |
@@ -100,7 +110,7 @@ export class EntityDataService { | @@ -100,7 +110,7 @@ export class EntityDataService { | ||
100 | keyFilters, | 110 | keyFilters, |
101 | true, | 111 | true, |
102 | ignoreDataUpdateOnIntervalTick); | 112 | ignoreDataUpdateOnIntervalTick); |
103 | - if (datasource.type === DatasourceType.entity && (!datasource.entityFilter || !pageLink)) { | 113 | + if (EntityDataService.isUnresolvedDatasource(datasource, pageLink)) { |
104 | listener.dataLoaded(emptyPageData<EntityData>(), [], | 114 | listener.dataLoaded(emptyPageData<EntityData>(), [], |
105 | listener.configDatasourceIndex, listener.subscriptionOptions.pageLink); | 115 | listener.configDatasourceIndex, listener.subscriptionOptions.pageLink); |
106 | return of(null); | 116 | return of(null); |
@@ -271,19 +271,27 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit | @@ -271,19 +271,27 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit | ||
271 | ); | 271 | ); |
272 | } else { | 272 | } else { |
273 | const targetEntityType = this.checkEntityType(value.entityType); | 273 | const targetEntityType = this.checkEntityType(value.entityType); |
274 | - this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true, ignoreErrors: true}).subscribe( | ||
275 | - (entity) => { | ||
276 | - this.modelValue = entity.id.id; | ||
277 | - this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false}); | ||
278 | - }, | ||
279 | - () => { | ||
280 | - this.modelValue = null; | ||
281 | - this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); | ||
282 | - if (value !== null) { | ||
283 | - this.propagateChange(this.modelValue); | 274 | + if (value.id) { |
275 | + this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true, ignoreErrors: true}).subscribe( | ||
276 | + (entity) => { | ||
277 | + this.modelValue = entity.id.id; | ||
278 | + this.selectEntityFormGroup.get('entity').patchValue(entity, {emitEvent: false}); | ||
279 | + }, | ||
280 | + () => { | ||
281 | + this.modelValue = null; | ||
282 | + this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); | ||
283 | + if (value !== null) { | ||
284 | + this.propagateChange(this.modelValue); | ||
285 | + } | ||
284 | } | 286 | } |
287 | + ); | ||
288 | + } else { | ||
289 | + this.modelValue = null; | ||
290 | + this.selectEntityFormGroup.get('entity').patchValue('', {emitEvent: false}); | ||
291 | + if (value !== null) { | ||
292 | + this.propagateChange(this.modelValue); | ||
285 | } | 293 | } |
286 | - ); | 294 | + } |
287 | } | 295 | } |
288 | } else { | 296 | } else { |
289 | this.modelValue = null; | 297 | this.modelValue = null; |
@@ -818,7 +818,7 @@ export function updateDatasourceFromEntityInfo(datasource: Datasource, entity: E | @@ -818,7 +818,7 @@ export function updateDatasourceFromEntityInfo(datasource: Datasource, entity: E | ||
818 | }; | 818 | }; |
819 | datasource.entityId = entity.id; | 819 | datasource.entityId = entity.id; |
820 | datasource.entityType = entity.entityType; | 820 | datasource.entityType = entity.entityType; |
821 | - if (datasource.type === DatasourceType.entity) { | 821 | + if (datasource.type === DatasourceType.entity || datasource.type === DatasourceType.entityCount) { |
822 | datasource.entityName = entity.name; | 822 | datasource.entityName = entity.name; |
823 | datasource.entityLabel = entity.label; | 823 | datasource.entityLabel = entity.label; |
824 | datasource.name = entity.name; | 824 | datasource.name = entity.name; |