From 8e1190e20300a789db932535b32964f49de32bc9 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:16:50 +0000 Subject: [PATCH 1/2] fix(CB2-15660): fix issue where delete of tc3 inspection was not propagated --- .../tech-record-summary/tech-record-summary.component.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/features/tech-record/components/tech-record-summary/tech-record-summary.component.ts b/src/app/features/tech-record/components/tech-record-summary/tech-record-summary.component.ts index ce4a5a9a79..bc658d661c 100644 --- a/src/app/features/tech-record/components/tech-record-summary/tech-record-summary.component.ts +++ b/src/app/features/tech-record/components/tech-record-summary/tech-record-summary.component.ts @@ -156,7 +156,10 @@ export class TechRecordSummaryComponent implements OnInit, OnDestroy, AfterViewI }); this.form.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((changes) => { - this.handleFormState(changes); + // prevent merging of array of objects - always override + const isArray = (a: unknown, b: unknown) => (Array.isArray(a) ? b : undefined); + this.techRecordCalculated = mergeWith(cloneDeep(this.techRecordCalculated), changes, isArray); + this.technicalRecordService.updateEditingTechRecord(this.techRecordCalculated as TechRecordType<'put'>); }); } From b067b3bd59e696ec76e4aa46864588c82da01f41 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Thu, 2 Jan 2025 10:01:14 +0000 Subject: [PATCH 2/2] fix(CB2-15660): handle pre-populate UN Numbers --- .../adr-section-edit.component.ts | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts index 3e42d175a0..ce24d7b648 100644 --- a/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts +++ b/src/app/forms/custom-sections/adr-section/adr-section-edit/adr-section-edit.component.ts @@ -1,6 +1,6 @@ import { ViewportScroller } from '@angular/common'; import { Component, OnDestroy, OnInit, inject, input } from '@angular/core'; -import { ControlContainer, FormBuilder, FormGroup } from '@angular/forms'; +import { ControlContainer, FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { ADRAdditionalNotesNumber } from '@dvsa/cvs-type-definitions/types/v3/tech-record/enums/adrAdditionalNotesNumber.enum.js'; import { ADRBodyDeclarationTypes } from '@dvsa/cvs-type-definitions/types/v3/tech-record/enums/adrBodyDeclarationType.enum.js'; @@ -131,12 +131,8 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { 'Reference number or UN number 1 is required when selecting Product List' ), ]), - techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo: this.fb.array( - [ - this.fb.control(null, [ - this.commonValidators.maxLength(1500, 'UN number 1 must be less than or equal to 1500 characters'), - ]), - ], + techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo: this.fb.array>( + [], [ this.adrValidators.requiresAllUnNumbersToBePopulated(), this.adrValidators.requiresAUnNumberOrReferenceNumber( @@ -312,9 +308,30 @@ export class AdrSectionEditComponent implements OnInit, OnDestroy { } handleInitialiseUNNumbers() { - this.techRecord()?.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo?.forEach(() => - this.addUNNumber() - ); + const unNumbers = this.techRecord()?.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo; + + // If there are un numbers, then prepopulate them + if (Array.isArray(unNumbers) && unNumbers.length > 0) { + unNumbers?.forEach((number, index) => { + this.form.controls.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo.push( + this.fb.control(number, [ + this.commonValidators.maxLength( + 1500, + `UN number ${index + 1} must be less than or equal to 1500 characters` + ), + ]) + ); + }); + } + + // Otherwise, add a single empty UN number + else { + this.form.controls.techRecord_adrDetails_tank_tankDetails_tankStatement_productListUnNo.push( + this.fb.control(null, [ + this.commonValidators.maxLength(1500, 'UN number 1 must be less than or equal to 1500 characters'), + ]) + ); + } } handleInitialiseSubsequentTankInspections() {