Commit d61890a96ab6e33e319a93c9c30020f61866b3af
Committed by
GitHub
Merge pull request #4236 from vvlladd28/improvement/validate/entityId
UI: Added validate EntityId before update dashboard state
Showing
2 changed files
with
8 additions
and
2 deletions
@@ -18,6 +18,8 @@ import _ from 'lodash'; | @@ -18,6 +18,8 @@ import _ from 'lodash'; | ||
18 | import { Observable, Subject } from 'rxjs'; | 18 | import { Observable, Subject } from 'rxjs'; |
19 | import { finalize, share } from 'rxjs/operators'; | 19 | import { finalize, share } from 'rxjs/operators'; |
20 | import { Datasource } from '@app/shared/models/widget.models'; | 20 | import { Datasource } from '@app/shared/models/widget.models'; |
21 | +import { EntityId } from '@shared/models/id/entity-id'; | ||
22 | +import { NULL_UUID } from '@shared/models/id/has-uuid'; | ||
21 | 23 | ||
22 | const varsRegex = /\${([^}]*)}/g; | 24 | const varsRegex = /\${([^}]*)}/g; |
23 | 25 | ||
@@ -431,3 +433,7 @@ export function generateSecret(length?: number): string { | @@ -431,3 +433,7 @@ export function generateSecret(length?: number): string { | ||
431 | } | 433 | } |
432 | return str.concat(generateSecret(length - str.length)); | 434 | return str.concat(generateSecret(length - str.length)); |
433 | } | 435 | } |
436 | + | ||
437 | +export function validateEntityId(entityId: EntityId): boolean { | ||
438 | + return isDefinedAndNotNull(entityId.id) && entityId.id !== NULL_UUID && isDefinedAndNotNull(entityId.entityType); | ||
439 | +} |
@@ -55,7 +55,7 @@ import { AppState } from '@core/core.state'; | @@ -55,7 +55,7 @@ import { AppState } from '@core/core.state'; | ||
55 | import { WidgetService } from '@core/http/widget.service'; | 55 | import { WidgetService } from '@core/http/widget.service'; |
56 | import { UtilsService } from '@core/services/utils.service'; | 56 | import { UtilsService } from '@core/services/utils.service'; |
57 | import { forkJoin, Observable, of, ReplaySubject, Subscription, throwError } from 'rxjs'; | 57 | import { forkJoin, Observable, of, ReplaySubject, Subscription, throwError } from 'rxjs'; |
58 | -import { deepClone, insertVariable, isDefined, objToBase64, objToBase64URI } from '@core/utils'; | 58 | +import { deepClone, insertVariable, isDefined, objToBase64, objToBase64URI, validateEntityId } from '@core/utils'; |
59 | import { | 59 | import { |
60 | IDynamicWidgetComponent, | 60 | IDynamicWidgetComponent, |
61 | WidgetContext, | 61 | WidgetContext, |
@@ -1004,7 +1004,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI | @@ -1004,7 +1004,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI | ||
1004 | const type = descriptor.type; | 1004 | const type = descriptor.type; |
1005 | const targetEntityParamName = descriptor.stateEntityParamName; | 1005 | const targetEntityParamName = descriptor.stateEntityParamName; |
1006 | let targetEntityId: EntityId; | 1006 | let targetEntityId: EntityId; |
1007 | - if (descriptor.setEntityId) { | 1007 | + if (descriptor.setEntityId && validateEntityId(entityId)) { |
1008 | targetEntityId = entityId; | 1008 | targetEntityId = entityId; |
1009 | } | 1009 | } |
1010 | switch (type) { | 1010 | switch (type) { |