Commit 62a159ed0da92e3144135583b54fa50ff75d8b06
Committed by
GitHub
Merge pull request #5531 from vvlladd28/bug/json-attribute/double-error-message
[3.3.2] UI: Fixed json attribute widget - showed two errors at the same time
Showing
3 changed files
with
23 additions
and
39 deletions
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | class="tb-json-input__form" |
23 | 23 | [formGroup]="attributeUpdateFormGroup" |
24 | 24 | (ngSubmit)="save()"> |
25 | - <div fxLayout="column" fxLayoutGap="10px" fxFlex *ngIf="entityDetected && isValidParameter && dataKeyDetected"> | |
25 | + <div fxLayout="column" fxLayoutGap="10px" fxFlex *ngIf="datasourceDetected && !errorMessage; else errorContainer"> | |
26 | 26 | <fieldset fxFlex> |
27 | 27 | <tb-json-object-edit |
28 | 28 | [editorStyle]="{minHeight: '100px'}" |
... | ... | @@ -51,19 +51,10 @@ |
51 | 51 | </div> |
52 | 52 | </div> |
53 | 53 | |
54 | - <div fxLayout="column" fxLayoutAlign="center center" fxFlex *ngIf="!entityDetected || !dataKeyDetected || !isValidParameter"> | |
55 | - <div class="tb-json-input__error" | |
56 | - *ngIf="!entityDetected"> | |
57 | - {{ 'widgets.input-widgets.no-entity-selected' | translate }} | |
58 | - </div> | |
59 | - <div class="tb-json-input__error" | |
60 | - *ngIf="entityDetected && !dataKeyDetected"> | |
61 | - {{ 'widgets.input-widgets.no-datakey-selected' | translate }} | |
62 | - </div> | |
63 | - <div class="tb-json-input__error" | |
64 | - *ngIf="dataKeyDetected && !isValidParameter"> | |
54 | + <ng-template #errorContainer> | |
55 | + <div class="tb-json-input__error" fxLayout="column" fxLayoutAlign="center center" fxFlex> | |
65 | 56 | {{ errorMessage | translate }} |
66 | 57 | </div> |
67 | - </div> | |
58 | + </ng-template> | |
68 | 59 | </form> |
69 | 60 | </div> | ... | ... |
... | ... | @@ -28,7 +28,7 @@ import { AttributeService } from '@core/http/attribute.service'; |
28 | 28 | import { AttributeData, AttributeScope, DataKeyType, LatestTelemetry } from '@shared/models/telemetry/telemetry.models'; |
29 | 29 | import { EntityId } from '@shared/models/id/entity-id'; |
30 | 30 | import { EntityType } from '@shared/models/entity-type.models'; |
31 | -import { createLabelFromDatasource } from '@core/utils'; | |
31 | +import { createLabelFromDatasource, isDefinedAndNotNull } from '@core/utils'; | |
32 | 32 | import { Observable } from 'rxjs'; |
33 | 33 | |
34 | 34 | enum JsonInputWidgetMode { |
... | ... | @@ -63,9 +63,7 @@ export class JsonInputWidgetComponent extends PageComponent implements OnInit { |
63 | 63 | |
64 | 64 | labelValue: string; |
65 | 65 | |
66 | - entityDetected = false; | |
67 | - dataKeyDetected = false; | |
68 | - isValidParameter = false; | |
66 | + datasourceDetected = false; | |
69 | 67 | errorMessage: string; |
70 | 68 | |
71 | 69 | isFocused: boolean; |
... | ... | @@ -111,30 +109,26 @@ export class JsonInputWidgetComponent extends PageComponent implements OnInit { |
111 | 109 | } |
112 | 110 | |
113 | 111 | private validateDatasources() { |
114 | - if (this.datasource?.type === DatasourceType.entity) { | |
115 | - this.entityDetected = true; | |
116 | - if (this.datasource.dataKeys.length) { | |
117 | - this.dataKeyDetected = true; | |
118 | - | |
119 | - if (this.settings.widgetMode === JsonInputWidgetMode.ATTRIBUTE) { | |
120 | - if (this.datasource.dataKeys[0].type === DataKeyType.attribute) { | |
121 | - if (this.settings.attributeScope === AttributeScope.SERVER_SCOPE || this.datasource.entityType === EntityType.DEVICE) { | |
122 | - this.isValidParameter = true; | |
123 | - } else { | |
124 | - this.errorMessage = 'widgets.input-widgets.not-allowed-entity'; | |
125 | - } | |
126 | - } else { | |
127 | - this.errorMessage = 'widgets.input-widgets.no-attribute-selected'; | |
112 | + this.datasourceDetected = isDefinedAndNotNull(this.datasource); | |
113 | + if (!this.datasourceDetected) { | |
114 | + return; | |
115 | + } | |
116 | + if (this.datasource.type === DatasourceType.entity) { | |
117 | + if (this.settings.widgetMode === JsonInputWidgetMode.ATTRIBUTE) { | |
118 | + if (this.datasource.dataKeys[0].type === DataKeyType.attribute) { | |
119 | + if (this.settings.attributeScope !== AttributeScope.SERVER_SCOPE && this.datasource.entityType !== EntityType.DEVICE) { | |
120 | + this.errorMessage = 'widgets.input-widgets.not-allowed-entity'; | |
128 | 121 | } |
129 | 122 | } else { |
130 | - if (this.datasource.dataKeys[0].type === DataKeyType.timeseries) { | |
131 | - this.isValidParameter = true; | |
132 | - } else { | |
133 | - this.errorMessage = 'widgets.input-widgets.no-timeseries-selected'; | |
134 | - } | |
123 | + this.errorMessage = 'widgets.input-widgets.no-attribute-selected'; | |
124 | + } | |
125 | + } else { | |
126 | + if (this.datasource.dataKeys[0].type !== DataKeyType.timeseries) { | |
127 | + this.errorMessage = 'widgets.input-widgets.no-timeseries-selected'; | |
135 | 128 | } |
136 | - | |
137 | 129 | } |
130 | + } else { | |
131 | + this.errorMessage = 'widgets.input-widgets.no-entity-selected'; | |
138 | 132 | } |
139 | 133 | } |
140 | 134 | |
... | ... | @@ -152,7 +146,7 @@ export class JsonInputWidgetComponent extends PageComponent implements OnInit { |
152 | 146 | } |
153 | 147 | |
154 | 148 | private updateWidgetData(data: Array<DatasourceData>) { |
155 | - if (this.isValidParameter) { | |
149 | + if (!this.errorMessage) { | |
156 | 150 | let value = {}; |
157 | 151 | if (data[0].data[0][1] !== '') { |
158 | 152 | try { | ... | ... |