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 | 60 | constructor(private telemetryService: TelemetryWebsocketService, |
61 | 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 | 73 | public prepareSubscription(listener: EntityDataListener, |
64 | 74 | ignoreDataUpdateOnIntervalTick = false): Observable<EntityDataLoadResult> { |
65 | 75 | const datasource = listener.configDatasource; |
... | ... | @@ -71,7 +81,7 @@ export class EntityDataService { |
71 | 81 | null, |
72 | 82 | false, |
73 | 83 | ignoreDataUpdateOnIntervalTick); |
74 | - if (datasource.type === DatasourceType.entity && (!datasource.entityFilter || !datasource.pageLink)) { | |
84 | + if (EntityDataService.isUnresolvedDatasource(datasource, datasource.pageLink)) { | |
75 | 85 | return of(null); |
76 | 86 | } |
77 | 87 | listener.subscription = new EntityDataSubscription(listener, this.telemetryService, this.utils); |
... | ... | @@ -100,7 +110,7 @@ export class EntityDataService { |
100 | 110 | keyFilters, |
101 | 111 | true, |
102 | 112 | ignoreDataUpdateOnIntervalTick); |
103 | - if (datasource.type === DatasourceType.entity && (!datasource.entityFilter || !pageLink)) { | |
113 | + if (EntityDataService.isUnresolvedDatasource(datasource, pageLink)) { | |
104 | 114 | listener.dataLoaded(emptyPageData<EntityData>(), [], |
105 | 115 | listener.configDatasourceIndex, listener.subscriptionOptions.pageLink); |
106 | 116 | return of(null); | ... | ... |
... | ... | @@ -271,19 +271,27 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit |
271 | 271 | ); |
272 | 272 | } else { |
273 | 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 | 296 | } else { |
289 | 297 | this.modelValue = null; | ... | ... |
... | ... | @@ -818,7 +818,7 @@ export function updateDatasourceFromEntityInfo(datasource: Datasource, entity: E |
818 | 818 | }; |
819 | 819 | datasource.entityId = entity.id; |
820 | 820 | datasource.entityType = entity.entityType; |
821 | - if (datasource.type === DatasourceType.entity) { | |
821 | + if (datasource.type === DatasourceType.entity || datasource.type === DatasourceType.entityCount) { | |
822 | 822 | datasource.entityName = entity.name; |
823 | 823 | datasource.entityLabel = entity.label; |
824 | 824 | datasource.name = entity.name; | ... | ... |