From 2cab5eb43241d1e09b6973883cca540d189b5892 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:38:44 +0300 Subject: [PATCH 1/2] set default form values as null --- .../affiliation-update.component.ts | 44 +++++++++---------- ui/src/app/user/user-update.component.ts | 33 ++++++++------ 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/ui/src/app/affiliation/affiliation-update.component.ts b/ui/src/app/affiliation/affiliation-update.component.ts index f478f8233..36ff0ed7f 100644 --- a/ui/src/app/affiliation/affiliation-update.component.ts +++ b/ui/src/app/affiliation/affiliation-update.component.ts @@ -132,34 +132,34 @@ export class AffiliationUpdateComponent implements OnInit { editForm = this.fb.group( { - id: [null], - email: ['', [Validators.pattern(EMAIL_REGEXP), Validators.required]], - affiliationSection: ['', [Validators.required]], - departmentName: ['', [Validators.maxLength(4000)]], - roleTitle: ['', [Validators.maxLength(4000)]], - url: ['', [Validators.maxLength(8000)]], + id: [], + email: [null, [Validators.pattern(EMAIL_REGEXP), Validators.required]], + affiliationSection: [null, [Validators.required]], + departmentName: [null, [Validators.maxLength(4000)]], + roleTitle: [null, [Validators.maxLength(4000)]], + url: [null, [Validators.maxLength(8000)]], startYear: [null], startMonth: [null], startDay: [null], endYear: [null], endMonth: [null], endDay: [null], - orgName: ['', [Validators.required]], - orgCountry: ['', [Validators.required]], - orgCity: ['', [Validators.required]], - orgRegion: [''], - disambiguatedOrgId: ['', [Validators.required, disambiguatedOrgIdValidator()]], - disambiguationSource: ['', [Validators.required]], - externalId: [''], - externalIdType: [''], - externalIdUrl: [''], - putCode: [''], - created: [''], - modified: [''], - deletedFromORCID: [''], - status: [''], - ownerId: [''], - sent: [''], + orgName: [null, [Validators.required]], + orgCountry: [null, [Validators.required]], + orgCity: [null, [Validators.required]], + orgRegion: [], + disambiguatedOrgId: [null, [Validators.required, disambiguatedOrgIdValidator()]], + disambiguationSource: [null, [Validators.required]], + externalId: [], + externalIdType: [], + externalIdUrl: [], + putCode: [], + created: [], + modified: [], + deletedFromORCID: [], + status: [], + ownerId: [], + sent: [], }, { validators: dateValidator() } ) diff --git a/ui/src/app/user/user-update.component.ts b/ui/src/app/user/user-update.component.ts index c04b29cb4..fb62362b5 100644 --- a/ui/src/app/user/user-update.component.ts +++ b/ui/src/app/user/user-update.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectorRef, Component, OnInit } from '@angular/core' import { HttpResponse } from '@angular/common/http' -import { FormBuilder, Validators } from '@angular/forms' +import { FormBuilder, FormControl, Validators } from '@angular/forms' import { ActivatedRoute, Router } from '@angular/router' import { EMPTY, Observable } from 'rxjs' import * as moment from 'moment' @@ -32,19 +32,24 @@ export class UserUpdateComponent { validation: any editForm = this.fb.group({ - id: [''], - email: ['', [Validators.required, Validators.email, Validators.maxLength(50), emailValidator]], - firstName: ['', Validators.required], - lastName: ['', Validators.required], - mainContact: [false], - assertionServiceEnabled: [false], - salesforceId: ['', Validators.required], - activated: [false], - isAdmin: [false], - createdBy: [''], - createdDate: [''], - lastModifiedBy: [''], - lastModifiedDate: [''], + id: new FormControl(null), + email: new FormControl(null, [ + Validators.required, + Validators.email, + Validators.maxLength(50), + emailValidator, + ]), + firstName: new FormControl(null, Validators.required), + lastName: new FormControl(null, Validators.required), + mainContact: new FormControl(null), + assertionServiceEnabled: new FormControl(null), + salesforceId: new FormControl(null, Validators.required), + activated: new FormControl(null), + isAdmin: new FormControl(null), + createdBy: new FormControl(null), + createdDate: new FormControl(null), + lastModifiedBy: new FormControl(null), + lastModifiedDate: new FormControl(null), }) memberList = [] as IMember[] From 2b28d054ae6a06da1df415fa1425c9017d3adbb9 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:12:59 +0300 Subject: [PATCH 2/2] correct assertion to fit new logic --- ui/src/app/user/user-update.component.spec.ts | 6 +++--- ui/src/app/user/user-update.component.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/src/app/user/user-update.component.spec.ts b/ui/src/app/user/user-update.component.spec.ts index 02cea4a0a..b4c954cd9 100644 --- a/ui/src/app/user/user-update.component.spec.ts +++ b/ui/src/app/user/user-update.component.spec.ts @@ -1,7 +1,6 @@ -import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing' +import { ComponentFixture, TestBed } from '@angular/core/testing' import { FormBuilder, ReactiveFormsModule } from '@angular/forms' import { ActivatedRoute, Router } from '@angular/router' -import { BehaviorSubject, Observable, of } from 'rxjs' import { UserUpdateComponent } from './user-update.component' import { UserService } from './service/user.service' import { AccountService } from '../account' @@ -11,9 +10,10 @@ import { ErrorService } from '../error/service/error.service' import { IUser, User } from './model/user.model' import { Member } from '../member/model/member.model' import { UserValidation } from './model/user-validation.model' -import { RouterTestingModule } from '@angular/router/testing' import { FontAwesomeModule } from '@fortawesome/angular-fontawesome' import { NO_ERRORS_SCHEMA } from '@angular/core' +import { RouterTestingModule } from '@angular/router/testing' +import { of } from 'rxjs' describe('UserUpdateComponent', () => { let component: UserUpdateComponent diff --git a/ui/src/app/user/user-update.component.ts b/ui/src/app/user/user-update.component.ts index fb62362b5..18ae76874 100644 --- a/ui/src/app/user/user-update.component.ts +++ b/ui/src/app/user/user-update.component.ts @@ -284,7 +284,7 @@ export class UserUpdateComponent { private createFromForm(): IUser { return { ...new User(), - id: this.editForm.get(['id'])?.value !== '' ? this.editForm.get(['id'])?.value : undefined, + id: this.editForm.get(['id'])?.value ? this.editForm.get(['id'])?.value : undefined, email: this.editForm.get(['email'])?.value, firstName: this.editForm.get(['firstName'])?.value, lastName: this.editForm.get(['lastName'])?.value,