Merge pull request #10981 from maxunbearable/response-topic-exp-required

Made response topic expression required in gateway dashboard
This commit is contained in:
Vladyslav Prykhodko 2024-06-21 14:46:20 +03:00 committed by GitHub
commit e81284e809
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core'; import { Component, EventEmitter, forwardRef, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { import {
ControlValueAccessor, ControlValueAccessor,
FormArray, FormArray,
@ -53,6 +53,8 @@ import {
} from '@shared/components/dialog/json-object-edit-dialog.component'; } from '@shared/components/dialog/json-object-edit-dialog.component';
import { jsonRequired } from '@shared/components/json-object-edit.component'; import { jsonRequired } from '@shared/components/json-object-edit.component';
import { deepClone } from '@core/utils'; import { deepClone } from '@core/utils';
import { takeUntil, tap } from "rxjs/operators";
import { Subject } from "rxjs";
@Component({ @Component({
selector: 'tb-gateway-service-rpc-connector', selector: 'tb-gateway-service-rpc-connector',
@ -66,7 +68,7 @@ import { deepClone } from '@core/utils';
} }
] ]
}) })
export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValueAccessor { export class GatewayServiceRPCConnectorComponent implements OnInit, OnDestroy, ControlValueAccessor {
@Input() @Input()
connectorType: ConnectorType; connectorType: ConnectorType;
@ -105,6 +107,7 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValue
private propagateChange = (v: any) => { private propagateChange = (v: any) => {
} }
private destroy$ = new Subject<void>();
constructor(private fb: FormBuilder, constructor(private fb: FormBuilder,
private dialog: MatDialog,) { private dialog: MatDialog,) {
@ -138,6 +141,12 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValue
} }
}); });
this.isMQTTWithResponse = this.fb.control(false); this.isMQTTWithResponse = this.fb.control(false);
this.observeMQTTWithResponse();
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
} }
connectorParamsFormGroupByType(type: ConnectorType): FormGroup { connectorParamsFormGroupByType(type: ConnectorType): FormGroup {
@ -148,7 +157,7 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValue
formGroup = this.fb.group({ formGroup = this.fb.group({
methodFilter: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], methodFilter: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
requestTopicExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], requestTopicExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
responseTopicExpression: [null, [Validators.pattern(noLeadTrailSpacesRegex)]], responseTopicExpression: [{ value: null, disabled: true }, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
responseTimeout: [null, [Validators.min(10), Validators.pattern(this.numbersOnlyPattern)]], responseTimeout: [null, [Validators.min(10), Validators.pattern(this.numbersOnlyPattern)]],
valueExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]], valueExpression: [null, [Validators.required, Validators.pattern(noLeadTrailSpacesRegex)]],
}) })
@ -424,4 +433,14 @@ export class GatewayServiceRPCConnectorComponent implements OnInit, ControlValue
this.commandForm.patchValue(value, {onlySelf: false}); this.commandForm.patchValue(value, {onlySelf: false});
} }
} }
private observeMQTTWithResponse(): void {
this.isMQTTWithResponse.valueChanges.pipe(
tap((isActive: boolean) => {
const responseControl = this.commandForm.get('responseTopicExpression');
isActive ? responseControl.enable() : responseControl.disable();
}),
takeUntil(this.destroy$),
).subscribe();
}
} }