Skip to content

Commit

Permalink
Merge pull request #2032 from bcgov/feature/ALCS-2431-remove-message-…
Browse files Browse the repository at this point in the history
…flash-QA

ALCS-2431 Prevents validation flash
  • Loading branch information
fbarreta authored Dec 18, 2024
2 parents d87af10 + 514953f commit ae6842a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Decision Condition Type</h4>
<div>
<mat-checkbox formControlName="isAdministrativeFeeAmountChecked">Administrative Fee Amount</mat-checkbox>
<app-error-message
*ngIf="!conditionTypeForm.controls['isAdministrativeFeeAmountChecked'].valid"
*ngIf="!conditionTypeForm.controls['isAdministrativeFeeAmountChecked'].valid && !isLoading"
[message]="'Field contains data, cannot be removed'"
></app-error-message>
</div>
Expand Down Expand Up @@ -82,7 +82,7 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Decision Condition Type</h4>
<div>
<mat-checkbox formControlName="isDateChecked"> Date </mat-checkbox>
<app-error-message
*ngIf="!conditionTypeForm.controls['isDateChecked'].valid"
*ngIf="!conditionTypeForm.controls['isDateChecked'].valid && !isLoading"
[message]="'Field contains data, cannot be removed'"
></app-error-message>
</div>
Expand Down Expand Up @@ -122,7 +122,7 @@ <h4>{{ isEdit ? 'Edit' : 'Create' }} Decision Condition Type</h4>
<div>
<mat-checkbox formControlName="isSecurityAmountChecked">Security Amount</mat-checkbox>
<app-error-message
*ngIf="!conditionTypeForm.controls['isSecurityAmountChecked'].valid"
*ngIf="!conditionTypeForm.controls['isSecurityAmountChecked'].valid && !isLoading"
[message]="'Field contains data, cannot be removed'"
></app-error-message>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class DecisionConditionTypesDialogComponent {
@Inject(MAT_DIALOG_DATA) public data: DecisionDialogDataInterface | undefined,
private dialogRef: MatDialogRef<DecisionConditionTypesDialogComponent>,
) {
this.isLoading = true;
this.service = data?.service;
this.conditionService = data?.conditionService;
this.isEdit = !!data?.content;
Expand Down Expand Up @@ -111,6 +112,7 @@ export class DecisionConditionTypesDialogComponent {

this.conditionTypeForm.get('isComponentToConditionChecked')?.disable();
this.conditionTypeForm.get('isDescriptionChecked')?.disable();
this.isLoading = false;
}

ngOnInit(): void {
Expand Down Expand Up @@ -144,6 +146,9 @@ export class DecisionConditionTypesDialogComponent {
if (this.conditionTypeForm.get('administrativeFeeAmount')?.value !== '') {
dto.administrativeFeeAmount = this.conditionTypeForm.get('administrativeFeeAmount')?.value;
}
if (!dto.isAdministrativeFeeAmountChecked) {
dto.administrativeFeeAmount = null;
}
if (!this.service) return;
if (this.isEdit) {
await this.service.update(dto.code, dto);
Expand All @@ -158,11 +163,15 @@ export class DecisionConditionTypesDialogComponent {
return (control: AbstractControl): Observable<{ [key: string]: any } | null> => {
return of(control.value).pipe(
debounceTime(300),
switchMap(() => {
switchMap(async () => {
if (!this.conditionService) {
throw Error('Condition service not found');
}
return this.conditionService.fetchByTypeCode(this.conditionTypeForm.controls['code'].value);
// prevents the message flash by setting isLoading while fetching codes.
this.isLoading = true;
const result = await this.conditionService.fetchByTypeCode(this.conditionTypeForm.controls['code'].value);
this.isLoading = false;
return result;
}),
map((conditions) =>
{
Expand Down

0 comments on commit ae6842a

Please sign in to comment.