Browse Source

Fix data resolution for entity count datasource type.

pull/4240/head
Igor Kulikov 6 years ago
parent
commit
43d221e5ce
  1. 14
      ui-ngx/src/app/core/api/entity-data.service.ts
  2. 30
      ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts
  3. 2
      ui-ngx/src/app/shared/models/query/query.models.ts

14
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<EntityDataLoadResult> {
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<EntityData>(), [],
listener.configDatasourceIndex, listener.subscriptionOptions.pageLink);
return of(null);

30
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;

2
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;

Loading…
Cancel
Save