diff --git a/ui-ngx/src/app/core/utils.ts b/ui-ngx/src/app/core/utils.ts index c03b10d4d1..b9c2697d0a 100644 --- a/ui-ngx/src/app/core/utils.ts +++ b/ui-ngx/src/app/core/utils.ts @@ -18,6 +18,8 @@ import _ from 'lodash'; import { Observable, Subject } from 'rxjs'; import { finalize, share } from 'rxjs/operators'; import { Datasource } from '@app/shared/models/widget.models'; +import { EntityId } from '@shared/models/id/entity-id'; +import { NULL_UUID } from '@shared/models/id/has-uuid'; const varsRegex = /\${([^}]*)}/g; @@ -431,3 +433,7 @@ export function generateSecret(length?: number): string { } return str.concat(generateSecret(length - str.length)); } + +export function validateEntityId(entityId: EntityId): boolean { + return isDefinedAndNotNull(entityId.id) && entityId.id !== NULL_UUID && isDefinedAndNotNull(entityId.entityType); +} diff --git a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts index aa47b97c20..e05de53e79 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts @@ -55,7 +55,7 @@ import { AppState } from '@core/core.state'; import { WidgetService } from '@core/http/widget.service'; import { UtilsService } from '@core/services/utils.service'; import { forkJoin, Observable, of, ReplaySubject, Subscription, throwError } from 'rxjs'; -import { deepClone, insertVariable, isDefined, objToBase64, objToBase64URI } from '@core/utils'; +import { deepClone, insertVariable, isDefined, objToBase64, objToBase64URI, validateEntityId } from '@core/utils'; import { IDynamicWidgetComponent, WidgetContext, @@ -1004,7 +1004,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI const type = descriptor.type; const targetEntityParamName = descriptor.stateEntityParamName; let targetEntityId: EntityId; - if (descriptor.setEntityId) { + if (descriptor.setEntityId && validateEntityId(entityId)) { targetEntityId = entityId; } switch (type) {