Skip to content

Commit 23c0e63

Browse files
author
Salim Terres
committed
Bug #15468 [Profile Groups] – The “Next” button becomes clickable before the name is validated.
1 parent 5aba3c5 commit 23c0e63

File tree

6 files changed

+39
-36
lines changed

6 files changed

+39
-36
lines changed

ui/ui-frontend/projects/identity/src/app/external-param-profile/external-param-profile-create/external-param-profile-create.component.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
]"
88
></vitamui-dialog-header>
99

10-
<form [formGroup]="externalParamProfileForm" (ngSubmit)="onSubmit()">
10+
<form [formGroup]="form" (ngSubmit)="onSubmit()">
1111
<vitamui-stepper #stepper>
1212
<cdk-step>
1313
<mat-dialog-content class="gap-3 align-items-stretch">
14-
<vitamui-slide-toggle formControlName="enabled"
15-
>{{ 'EXTERNAL_PARAM_PROFILE.PROFILE' | translate }} <span *ngIf="!externalParamProfileForm.get('enabled').value">in</span
16-
>{{ 'COMMON.ACTIVE' | translate }}</vitamui-slide-toggle
17-
>
14+
<vitamui-slide-toggle formControlName="enabled">
15+
{{ 'EXTERNAL_PARAM_PROFILE.PROFILE' | translate }}
16+
<span *ngIf="!form.controls.enabled.value">in</span>
17+
{{ 'COMMON.ACTIVE' | translate }}
18+
</vitamui-slide-toggle>
1819

1920
<vitamui-input
2021
formControlName="name"
@@ -51,7 +52,7 @@
5152
{{ 'EXTERNAL_PARAM_PROFILE.USE_PLATFORM_BULK_OPERATIONS_THRESHOLD_TITLE' | translate }}
5253
</vitamui-slide-toggle>
5354

54-
<div class="select-threshold" *ngIf="!externalParamProfileForm.get('usePlatformThreshold').value">
55+
<div class="select-threshold" *ngIf="!form.controls.usePlatformThreshold.value">
5556
<vitamui-select
5657
class="w-100"
5758
formControlName="bulkOperationsThreshold"
@@ -71,7 +72,7 @@
7172

7273
<mat-dialog-actions>
7374
<div>
74-
<button type="submit" class="btn primary" [disabled]="onValidate()">
75+
<button type="submit" class="btn primary" [disabled]="isFormInvalid()">
7576
{{ 'COMMON.SUBMIT' | translate }}
7677
</button>
7778
<button type="button" class="btn link cancel" (click)="onCancel()">

ui/ui-frontend/projects/identity/src/app/external-param-profile/external-param-profile-create/external-param-profile-create.component.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
3838
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3939
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
4040
import { Observable, Subscription } from 'rxjs';
41-
import { ApplicationId, ConfirmDialogService, ExternalParamProfile, Option } from 'vitamui-library';
41+
import { ConfirmDialogService, ExternalParamProfile, Option } from 'vitamui-library';
4242
import { ExternalParamProfileService } from '../external-param-profile.service';
4343
import { ExternalParamProfileValidators } from '../external-param-profile.validators';
4444
import { map } from 'rxjs/operators';
@@ -52,7 +52,7 @@ import { DecimalPipe } from '@angular/common';
5252
standalone: false,
5353
})
5454
export class ExternalParamProfileCreateComponent implements OnInit, OnDestroy {
55-
externalParamProfileForm: FormGroup;
55+
form: FormGroup;
5656
activeAccessContractsIdentifiers$: Observable<string[]>;
5757
private keyPressSubscription: Subscription;
5858
tenantIdentifier: string;
@@ -91,25 +91,25 @@ export class ExternalParamProfileCreateComponent implements OnInit, OnDestroy {
9191
}
9292

9393
private initForm(tenantIdentifier: string) {
94-
this.externalParamProfileForm = this.formBuilder.group({
94+
this.form = this.formBuilder.group({
9595
enabled: true,
9696
accessContract: [null, Validators.required],
9797
description: [null, [Validators.required, Validators.minLength(2), Validators.maxLength(250)]],
98-
name: [null, [Validators.required, Validators.minLength(2), Validators.maxLength(100)]],
98+
name: [
99+
null,
100+
[Validators.required, Validators.minLength(2), Validators.maxLength(100)],
101+
[this.externalParamProfileValidators.nameExists(+tenantIdentifier)],
102+
],
99103
usePlatformThreshold: true,
100104
bulkOperationsThreshold: [null, []],
101105
});
102-
103-
this.externalParamProfileForm
104-
.get('name')
105-
.setAsyncValidators(this.externalParamProfileValidators.nameExists(+tenantIdentifier, ApplicationId.EXTERNAL_PARAM_PROFILE_APP));
106106
}
107107

108108
onSubmit() {
109-
if (this.externalParamProfileForm.invalid) {
109+
if (this.form.invalid) {
110110
return;
111111
}
112-
const externalParamProfile: ExternalParamProfile = this.externalParamProfileForm.getRawValue();
112+
const externalParamProfile: ExternalParamProfile = this.form.getRawValue();
113113
if (externalParamProfile.usePlatformThreshold) {
114114
externalParamProfile.bulkOperationsThreshold = null;
115115
}
@@ -126,22 +126,22 @@ export class ExternalParamProfileCreateComponent implements OnInit, OnDestroy {
126126
}
127127

128128
onCancel() {
129-
if (this.externalParamProfileForm.dirty) {
129+
if (this.form.dirty) {
130130
this.confirmDialogService.confirmBeforeClosing(this.dialogRef);
131131
} else {
132132
this.dialogRef.close();
133133
}
134134
}
135135

136-
onValidate() {
137-
return false;
136+
isFormInvalid() {
137+
return this.form.pending || this.form.invalid;
138138
}
139139

140140
firstStepInvalid(): boolean {
141-
return this.externalParamProfileForm.get('name').invalid || this.externalParamProfileForm.get('description').invalid;
142-
}
141+
const nameControl = this.form.controls.name;
142+
const descriptionControl = this.form.controls.description;
143+
const accessContractControl = this.form.controls.accessContract;
143144

144-
formValid(): boolean {
145-
return this.externalParamProfileForm.pending || this.externalParamProfileForm.invalid;
145+
return nameControl.invalid || nameControl.pending || descriptionControl.invalid || accessContractControl.invalid;
146146
}
147147
}

ui/ui-frontend/projects/identity/src/app/external-param-profile/external-param-profile-detail/information-tab/information-tab.component.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3939
import { of, skip, Subscription } from 'rxjs';
4040
import { catchError, distinctUntilChanged, filter, map, switchMap } from 'rxjs/operators';
4141
import { extend, isEqual } from 'underscore';
42-
import { ApplicationId, ExternalParamProfile } from 'vitamui-library';
42+
import { ExternalParamProfile } from 'vitamui-library';
4343
import { ExternalParamProfileService } from '../../external-param-profile.service';
4444
import { ExternalParamProfileValidators } from '../../external-param-profile.validators';
4545

@@ -127,13 +127,7 @@ export class InformationTabComponent implements OnDestroy, OnInit, OnChanges {
127127
private initFormValidators(externalParamProfile: ExternalParamProfile) {
128128
this.form
129129
.get('name')
130-
.setAsyncValidators(
131-
this.externalParamProfileValidators.nameExists(
132-
+this.tenantIdentifier,
133-
ApplicationId.EXTERNAL_PARAM_PROFILE_APP,
134-
externalParamProfile.name,
135-
),
136-
);
130+
.setAsyncValidators(this.externalParamProfileValidators.nameExists(+this.tenantIdentifier, externalParamProfile.name));
137131
}
138132

139133
private initFormActivationState(readOnly: boolean) {

ui/ui-frontend/projects/identity/src/app/external-param-profile/external-param-profile.validators.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { Injectable } from '@angular/core';
3838
import { AbstractControl, AsyncValidatorFn } from '@angular/forms';
3939
import { of, timer } from 'rxjs';
4040
import { map, switchMap, take } from 'rxjs/operators';
41+
import { ApplicationId } from 'vitamui-library';
4142
import { ExternalParamProfileService } from './external-param-profile.service';
4243

4344
@Injectable({
@@ -48,12 +49,12 @@ export class ExternalParamProfileValidators {
4849

4950
constructor(private externalParamProfileService: ExternalParamProfileService) {}
5051

51-
nameExists = (tenantIdentifier: number, applicationName: string, nameToIgnore?: string): AsyncValidatorFn => {
52+
nameExists = (tenantIdentifier: number, nameToIgnore?: string): AsyncValidatorFn => {
5253
return (control: AbstractControl) => {
5354
return timer(this.debounceTime).pipe(
5455
switchMap(() =>
5556
control.value !== nameToIgnore
56-
? this.externalParamProfileService.exists(tenantIdentifier, applicationName, control.value)
57+
? this.externalParamProfileService.exists(tenantIdentifier, ApplicationId.EXTERNAL_PARAMS, control.value)
5758
: of(false),
5859
),
5960
take(1),

ui/ui-frontend/projects/identity/src/app/group/group-create/group-create.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,17 @@ export class GroupCreateComponent implements OnInit, OnDestroy {
108108
}
109109

110110
firstStepInvalid(): boolean {
111-
return this.form.get('name').invalid || this.form.get('description').invalid || this.form.get('level').invalid;
111+
const nameControl = this.form.controls.name;
112+
const descriptionControl = this.form.controls.description;
113+
const levelControl = this.form.controls.level;
114+
115+
return nameControl.invalid || nameControl.pending || descriptionControl.invalid || levelControl.invalid;
112116
}
113117

114118
secondStepInvalid(): boolean {
115-
return this.form.get('profileIds').invalid;
119+
const profileIdsControl = this.form.controls.profileIds;
120+
121+
return profileIdsControl.invalid || profileIdsControl.pending;
116122
}
117123

118124
formValid(): boolean {

ui/ui-frontend/projects/vitamui-library/src/app/modules/application-id.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export enum ApplicationId {
6464
INGEST_APP_REF = 'INGEST_APP',
6565
LOGBOOK_MANAGEMENT_OPERATION_APP = 'LOGBOOK_MANAGEMENT_OPERATION_APP',
6666
EXTERNAL_PARAM_PROFILE_APP = 'EXTERNAL_PARAM_PROFILE_APP',
67+
EXTERNAL_PARAMS = 'EXTERNAL_PARAMS',
6768
MANAGEMENT_CONTRACT_APP = 'MANAGEMENT_CONTRACT_APP',
6869
COLLECT_APP = 'COLLECT_APP',
6970
}

0 commit comments

Comments
 (0)