Browse Source

Fixed KPN downlink credentials visibility and validation (#16504)

pull/16508/head
Maksym Tsymbarov 1 month ago
committed by GitHub
parent
commit
10203ce3df
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      ui-ngx/src/app/modules/home/components/integration/configuration/integration-configuration.component.html
  2. 37
      ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.html
  3. 57
      ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.ts
  4. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

1
ui-ngx/src/app/modules/home/components/integration/configuration/integration-configuration.component.html

@ -54,6 +54,7 @@
@case (integrationTypes.KPN) {
<tb-kpn-integration-form formControlName="configuration"
[routingKey]="routingKey"
[isSetDownlink]="isSetDownlink"
[executeRemotelyTemplate]="executeRemotelyTemplate"
[genericAdditionalInfoTemplate]="genericAdditionalInfoTemplate"
[allowLocalNetwork]="allowLocalNetwork">

37
ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.html

@ -35,30 +35,19 @@
</button>
</div>
<mat-expansion-panel class="expansion-panel-setting" [expanded]="kpnIntegrationConfigForm.get('allowDownlink').value">
<mat-expansion-panel-header>
<mat-panel-title class="flex flex-col items-start justify-start gap-2">
<mat-slide-toggle formControlName="allowDownlink" (click)="$event.stopPropagation()">
{{ 'integration.allow-downlink' | translate }}
</mat-slide-toggle>
</mat-panel-title>
</mat-expansion-panel-header>
<ng-template matExpansionPanelContent>
<section class="expansion-panel-setting-content">
<fieldset class="fields-group">
<legend class="group-title" translate>integration.credentials</legend>
<div class="flex flex-col gt-xs:gap-2">
<tb-secret-key-input formControlName="apiId" class="mat-block flex-1" appearance="outline"
label="{{ 'integration.api-id' | translate }}">
</tb-secret-key-input>
<tb-secret-key-input formControlName="apiKey" class="mat-block flex-1" appearance="outline"
label="{{ 'integration.api-key' | translate }}">
</tb-secret-key-input>
</div>
</fieldset>
</section>
</ng-template>
</mat-expansion-panel>
@if (isSetDownlink) {
<fieldset class="fields-group">
<legend class="group-title" translate>integration.downlink-credentials</legend>
<div class="flex flex-col gt-xs:gap-2">
<tb-secret-key-input formControlName="apiId" class="mat-block flex-1" appearance="outline"
label="{{ 'integration.api-id' | translate }}">
</tb-secret-key-input>
<tb-secret-key-input formControlName="apiKey" class="mat-block flex-1" appearance="outline"
label="{{ 'integration.api-key' | translate }}">
</tb-secret-key-input>
</div>
</fieldset>
}
<mat-expansion-panel class="expansion-panel-setting"
[expanded]="kpnIntegrationConfigForm.get('enableSecurity').value">

57
ui-ngx/src/app/modules/home/components/integration/configuration/kpn-integration-form/kpn-integration-form.component.ts

@ -50,10 +50,24 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont
@Input()
routingKey: string;
@Input()
set isSetDownlink(value: boolean) {
if (this.isSetDownlinkValue !== value) {
this.isSetDownlinkValue = value;
this.updateCredentialsValidators();
}
}
get isSetDownlink(): boolean {
return this.isSetDownlinkValue;
}
private integrationType = IntegrationType.KPN;
private isSetDownlinkValue = false;
private propagateChangePending = false;
private propagateChange = (v: any) => { };
private validatorChange = () => { };
constructor(private fb: UntypedFormBuilder,
private store: Store<AppState>,
@ -75,20 +89,14 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont
}],
enableSecurity: [false],
headersFilter: [{}],
allowDownlink: [false],
apiId:[],
apiKey:[]
apiId: [],
apiKey: []
});
this.kpnIntegrationConfigForm.get('baseUrl').valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe((value) => {
const httpEndpoint = integrationEndPointUrl(this.integrationType, value, this.routingKey);
this.kpnIntegrationConfigForm.get('httpEndpoint').patchValue(httpEndpoint);
});
this.kpnIntegrationConfigForm.get('allowDownlink').valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe(() => {
this.updateEnableFields();
});
this.kpnIntegrationConfigForm.valueChanges.pipe(
takeUntil(this.destroy$)
@ -96,14 +104,12 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont
this.updateModels(this.kpnIntegrationConfigForm.getRawValue());
});
this.kpnIntegrationConfigForm.removeControl('replaceNoContentToOk', {emitEvent: false});
this.updateCredentialsValidators();
}
writeValue(value: KpnIntegration) {
if (isDefinedAndNotNull(value)) {
this.kpnIntegrationConfigForm.reset(value, {emitEvent: false});
if (!this.disabled) {
this.updateEnableFields();
}
} else {
this.propagateChangePending = true;
}
@ -121,13 +127,16 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont
registerOnTouched(fn: any) { }
registerOnValidatorChange(fn: () => void) {
this.validatorChange = fn;
}
setDisabledState(isDisabled: boolean) {
this.disabled = isDisabled;
if (isDisabled) {
this.kpnIntegrationConfigForm.disable({emitEvent: false});
} else {
this.kpnIntegrationConfigForm.enable({emitEvent: false});
this.updateEnableFields();
this.kpnIntegrationConfigForm.get('httpEndpoint').disable({emitEvent: false});
}
}
@ -154,22 +163,14 @@ export class KpnIntegrationFormComponent extends IntegrationForm implements Cont
this.propagateChange(value);
}
private updateEnableFields() {
const allowDownlink = this.kpnIntegrationConfigForm.get('allowDownlink').value;
if (allowDownlink) {
this.kpnIntegrationConfigForm.get('apiId').enable({emitEvent: false});
this.kpnIntegrationConfigForm.get('apiKey').enable({emitEvent: false});
this.kpnIntegrationConfigForm.get('apiId').setValidators(Validators.required);
this.kpnIntegrationConfigForm.get('apiKey').setValidators(Validators.required);
} else {
this.kpnIntegrationConfigForm.get('apiId').disable({emitEvent: false});
this.kpnIntegrationConfigForm.get('apiKey').disable({emitEvent: false});
this.kpnIntegrationConfigForm.get('apiId').clearValidators();
this.kpnIntegrationConfigForm.get('apiKey').clearValidators();
private updateCredentialsValidators() {
if (this.kpnIntegrationConfigForm) {
const validators = this.isSetDownlink ? [Validators.required] : [];
this.kpnIntegrationConfigForm.get('apiId').setValidators(validators);
this.kpnIntegrationConfigForm.get('apiKey').setValidators(validators);
this.kpnIntegrationConfigForm.get('apiId').updateValueAndValidity({emitEvent: false});
this.kpnIntegrationConfigForm.get('apiKey').updateValueAndValidity({emitEvent: false});
this.validatorChange();
}
this.kpnIntegrationConfigForm.get('apiId').updateValueAndValidity({emitEvent: false});
this.kpnIntegrationConfigForm.get('apiKey').updateValueAndValidity({emitEvent: false});
this.kpnIntegrationConfigForm.get('destinationSharedSecret').updateValueAndValidity({emitEvent: false});
}
}

1
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -5578,6 +5578,7 @@
"credentials": "Credentials",
"credentials-type": "Credentials type",
"credentials-type-required": "Credentials type is required.",
"downlink-credentials": "Downlink credentials",
"username": "Username",
"username-required": "Username is required.",
"password": "Password",

Loading…
Cancel
Save