From 860a4305bf86f774f7df074adb54364573b576b4 Mon Sep 17 00:00:00 2001 From: Julien Schneider Date: Mon, 4 Mar 2024 14:39:18 +0100 Subject: [PATCH] refactor: type common input (#1500) --- .../action/login-form/login-form.component.ts | 11 +++++------ .../common-input/common-input.component.ts | 15 ++++----------- .../resource-class-form.component.ts | 3 +-- .../reusable-project-form.component.ts | 16 ++++++++-------- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/apps/dsp-app/src/app/main/action/login-form/login-form.component.ts b/apps/dsp-app/src/app/main/action/login-form/login-form.component.ts index 0211a4a385..f71db8f507 100644 --- a/apps/dsp-app/src/app/main/action/login-form/login-form.component.ts +++ b/apps/dsp-app/src/app/main/action/login-form/login-form.component.ts @@ -1,6 +1,6 @@ import { Location } from '@angular/common'; import { Component, OnDestroy, OnInit } from '@angular/core'; -import { UntypedFormBuilder, Validators } from '@angular/forms'; +import { FormBuilder, Validators } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { NotificationService } from '@dasch-swiss/vre/shared/app-notification'; import { AuthService } from '@dasch-swiss/vre/shared/app-session'; @@ -12,8 +12,7 @@ import { finalize, takeLast, tap } from 'rxjs/operators'; template: `
@@ -21,10 +20,10 @@ import { finalize, takeLast, tap } from 'rxjs/operators'; - + {{ errors | humanReadableError }} @@ -63,7 +62,7 @@ export class LoginFormComponent implements OnInit, OnDestroy { private subscription: Subscription; constructor( - private _fb: UntypedFormBuilder, + private _fb: FormBuilder, private router: Router, private _authService: AuthService, private route: ActivatedRoute, diff --git a/apps/dsp-app/src/app/project/common-input/common-input.component.ts b/apps/dsp-app/src/app/project/common-input/common-input.component.ts index 4fd8f1d8f9..7fd60a20fe 100644 --- a/apps/dsp-app/src/app/project/common-input/common-input.component.ts +++ b/apps/dsp-app/src/app/project/common-input/common-input.component.ts @@ -1,13 +1,13 @@ import { Component, Input } from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; +import { FormControl } from '@angular/forms'; @Component({ selector: 'app-common-input', template: ` {{ prefixIcon }} - - + + {{ errors | humanReadableError: validatorErrors }} @@ -15,15 +15,8 @@ import { FormControl, FormGroup } from '@angular/forms'; styles: [':host { display: block;}'], }) export class CommonInputComponent { - @Input() formGroup: FormGroup; - @Input() controlName: string; + @Input() control: FormControl; @Input() placeholder: string; @Input() prefixIcon: string | null = null; @Input() validatorErrors: { errorKey: string; message: string }[] | null = null; - - get formControl() { - return this.formGroup.controls[this.controlName] as FormControl; - } - - protected readonly FormGroup = FormGroup; } diff --git a/apps/dsp-app/src/app/project/ontology/resource-class-form/resource-class-form.component.ts b/apps/dsp-app/src/app/project/ontology/resource-class-form/resource-class-form.component.ts index e69d31b30a..cf4c8ef6b7 100644 --- a/apps/dsp-app/src/app/project/ontology/resource-class-form/resource-class-form.component.ts +++ b/apps/dsp-app/src/app/project/ontology/resource-class-form/resource-class-form.component.ts @@ -18,8 +18,7 @@ import { ResourceClassForm } from './resource-class-form.type'; diff --git a/apps/dsp-app/src/app/project/reusable-project-form/reusable-project-form.component.ts b/apps/dsp-app/src/app/project/reusable-project-form/reusable-project-form.component.ts index 4c4ae48960..697576cfa4 100644 --- a/apps/dsp-app/src/app/project/reusable-project-form/reusable-project-form.component.ts +++ b/apps/dsp-app/src/app/project/reusable-project-form/reusable-project-form.component.ts @@ -14,16 +14,14 @@ import { shortcodeExistsValidator } from './shortcode-exists.validator';
@@ -31,9 +29,8 @@ import { shortcodeExistsValidator } from './shortcode-exists.validator'; + [control]="form.controls.longname" + data-cy="longname-input"> - +