Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/CB2-10033 - Additional Examiner Note #1448

Merged
merged 33 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
059bd49
feat(cb2-10241): update adr notes to use custom component
BrandonT95 Mar 27, 2024
d078144
feat(cb2-11250): format table
tomcrawleyy Mar 27, 2024
ee711c0
feat(cb2-11250): set up router link
tomcrawleyy Mar 27, 2024
491dfa0
feat(cb2-11250): blank page link working
tomcrawleyy Mar 27, 2024
436cc7e
feat(cb2-11250): revert unnecessary changes
tomcrawleyy Mar 27, 2024
8222b11
feat(cb2-11250): amend routing function
tomcrawleyy Mar 27, 2024
71bf1c5
feat(cb2-11250): fix linting and add unit test
tomcrawleyy Mar 28, 2024
1674375
feat(cb2-11250): fix linting and add unit test
tomcrawleyy Mar 28, 2024
aaa721a
feat(cb2-11250): update link design
tomcrawleyy Mar 28, 2024
43cf905
Merge branch 'release/v1.23' into feat/cb2-11250
tomcrawleyy Mar 28, 2024
f558964
feat(cb2-11250): fix button link styling
tomcrawleyy Mar 28, 2024
12cb975
feat(cb2-10033): basic setup and grabbed selected note from record
tomcrawleyy Mar 28, 2024
eba2597
feat(cb2-10033): stash for mobbing
tomcrawleyy Mar 28, 2024
41ad7c3
feat(cb2-10033): hook form up to display note which is to be edited
tomcrawleyy Mar 28, 2024
c5f8445
feat(cb2-10033): set up model binding to component
tomcrawleyy Apr 2, 2024
b22ac5b
feat(cb2-10033): use correct directive and basic form validation
tomcrawleyy Apr 2, 2024
60cddad
feat(cb2-10033): merge holding branch in
tomcrawleyy Apr 2, 2024
39a34d1
feat(cb2-10033): amend routing title for notifiable alteration
tomcrawleyy Apr 2, 2024
887d7b3
feat(cb2-10033): remove validation as requirements confirmed not needed
tomcrawleyy Apr 2, 2024
253f116
feat(cb2-10033): implement state management solution
tomcrawleyy Apr 2, 2024
10a1325
feat(cb2-10033): fix display for summary screen
tomcrawleyy Apr 2, 2024
4769a0a
feat(cb2-10033): refactor state and data handling approach
tomcrawleyy Apr 2, 2024
f525b6d
feat(cb2-10033): reducer tests
tomcrawleyy Apr 2, 2024
17e8ec1
feat(cb2-10033): basic unit testing draft
tomcrawleyy Apr 2, 2024
c06d39e
feat(cb2-10033): unit testing
tomcrawleyy Apr 3, 2024
f44616e
feat(cb2-10033): linting fix
tomcrawleyy Apr 3, 2024
11541af
feat(cb2-10033): rebase against release branch
tomcrawleyy Apr 3, 2024
16fc329
feat(cb2-10033): fix review screen
tomcrawleyy Apr 4, 2024
049c8d3
feat(cb2-10033): git stash for mobbing
tomcrawleyy Apr 4, 2024
a0cb8c9
feat(cb2-10033): add logic to hide collapse function and fix missing acs
tomcrawleyy Apr 5, 2024
5b5a9b9
feat(cb2-10033): move title from component to templates
tomcrawleyy Apr 5, 2024
4cb1819
feat(cb2-10033): acordion issues solved
Apr 5, 2024
95fb0bb
Merge branch 'feature/RELEASE-123' into feat/cb2-10033
tomevs88 Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
<div>This is a blank page right now.</div>
<div *ngIf="currentTechRecord">
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<dl class="govuk-summary-list">
<h1 class="govuk-heading-l">Edit Additional Examiner Note</h1>
<div class="govuk-summary-list__row">
<form [formGroup]="form">
<app-text-area
#examinerNote
formControlName="additionalExaminerNote"
name="AdditionalExaminerNote"
[width]="width.L"
(ngModelChange)="ngOnChanges(examinerNote.value)"
>
</app-text-area>
</form>
</div>
</dl>
</div>
</div>
<app-button-group>
<app-button id="submit-examiner-note" (clicked)="handleSubmit()">Save</app-button>
<app-button id="cancel-amend-examiner-note" design="link" data-module="govuk-button" (clicked)="navigateBack()">Cancel</app-button>
</app-button-group>
</div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,101 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { TechnicalRecordService } from '@services/technical-record/technical-record.service';
import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type';
import { ReplaySubject, take, takeUntil } from 'rxjs';
import { GlobalErrorService } from '@core/components/global-error/global-error.service';
import {
CustomFormControl,
FormNodeEditTypes,
FormNodeTypes,
FormNodeWidth,
} from '@forms/services/dynamic-form.types';
import { FormGroup, Validators } from '@angular/forms';
import { Store } from '@ngrx/store';
import { State } from '@store/index';
import { updateExistingADRAdditionalExaminerNote } from '@store/technical-records';

@Component({
selector: 'tech-record-edit-additional-examiner-note',
templateUrl: './tech-record-edit-additional-examiner-note.component.html',
styleUrls: ['./tech-record-edit-additional-examiner-note.component.scss'],
})
export class TechRecordEditAdditionalExaminerNoteComponent {
export class TechRecordEditAdditionalExaminerNoteComponent implements OnInit {
currentTechRecord!: TechRecordType<'hgv' | 'trl' | 'lgv'>;
examinerNoteIndex!: number;
editedExaminerNote: string = '';
originalExaminerNote: string = '';
destroy$ = new ReplaySubject<boolean>(1);
form!: FormGroup;
formControl!: CustomFormControl;

constructor(
private router: Router,
private route: ActivatedRoute,
private technicalRecordService: TechnicalRecordService,
private globalErrorService: GlobalErrorService,
private store: Store<State>,
) { }

ngOnInit() {
this.technicalRecordService.techRecord$.pipe(takeUntil(this.destroy$)).subscribe((currentTechRecord) => {
this.currentTechRecord = currentTechRecord as TechRecordType<'hgv' | 'lgv' | 'trl'>;
});
this.getExaminerNote();
this.setupForm();
}

getExaminerNote() {
this.route.params.pipe(take(1)).subscribe((params) => {
this.examinerNoteIndex = params['examinerNoteIndex'];
});
const additionalExaminerNotes = this.currentTechRecord?.techRecord_adrDetails_additionalExaminerNotes;
if (additionalExaminerNotes) {
const examinerNote = additionalExaminerNotes[this.examinerNoteIndex].note;
if (examinerNote) {
this.originalExaminerNote = examinerNote;
this.editedExaminerNote = examinerNote;
}
}
}

setupForm() {
this.formControl = new CustomFormControl({
name: 'additionalExaminerNote', type: FormNodeTypes.CONTROL,
}, '', [Validators.required]);
this.form = new FormGroup({
additionalExaminerNote: this.formControl,
});
this.formControl.patchValue(this.editedExaminerNote);
}

navigateBack() {
this.globalErrorService.clearErrors();
void this.router.navigate(['../../'], { relativeTo: this.route });
}

handleSubmit(): void {
if (this.originalExaminerNote !== this.editedExaminerNote) {
this.store.dispatch(
updateExistingADRAdditionalExaminerNote({
examinerNoteIndex: this.examinerNoteIndex,
additionalExaminerNote: this.editedExaminerNote,
}),
);
}
this.navigateBack();
}

ngOnChanges(examinerNote: string) {
this.editedExaminerNote = examinerNote;
}

get editTypes(): typeof FormNodeEditTypes {
return FormNodeEditTypes;
}

get width(): typeof FormNodeWidth {
return FormNodeWidth;
}

}
4 changes: 2 additions & 2 deletions src/app/features/tech-record/tech-record-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const routes: Routes = [
path: TechRecordRoutes.CORRECT_ERROR_EDIT_ADDITIONAL_EXAMINER_NOTE,
component: TechRecordEditAdditionalExaminerNoteComponent,
data: {
title: 'edit-additional-examiner-note',
title: 'Edit Additional Examiner Note',
roles: Roles.TechRecordAmend,
isEditing: true,
reason: ReasonForEditing.CORRECTING_AN_ERROR,
Expand Down Expand Up @@ -207,7 +207,7 @@ const routes: Routes = [
path: TechRecordRoutes.NOTIFIABLE_ALTERNATION_NEEDED_EDIT_ADDITIONAL_EXAMINER_NOTE,
component: TechRecordEditAdditionalExaminerNoteComponent,
data: {
title: 'edit-additional-examiner-note',
title: 'Edit Additional Examiner Note',
roles: Roles.TechRecordAmend,
isEditing: true,
reason: ReasonForEditing.NOTIFIABLE_ALTERATION_NEEDED,
Expand Down
2 changes: 1 addition & 1 deletion src/app/forms/templates/general/adr-summary.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ export const AdrSummaryTemplate: FormNode = {
label: 'Additional examiner notes history',
value: null,
type: FormNodeTypes.CONTROL,
viewType: FormNodeViewTypes.HIDDEN,
viewType: FormNodeViewTypes.CUSTOM,
viewComponent: AdrExaminerNotesHistoryViewComponent,
editType: FormNodeEditTypes.CUSTOM,
editComponent: AdrExaminerNotesHistoryEditComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@ngrx/store';
// eslint-disable-next-line import/no-unresolved
import { TypedAction } from '@ngrx/store/src/models';
import { AdditionalExaminerNotes } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/complete';

const prefix = '[Technical Record Service]';

Expand Down Expand Up @@ -98,7 +99,12 @@ export const clearScrollPosition = createAction(`${prefix} clearScrollPosition`)

export const clearADRDetailsBeforeUpdate = createAction(`${prefix} clearADRDetailsBeforeUpdate`);

export const updateADRAdditionalExaminerNotes = createAction(`${prefix} handleADRExaminerNoteChanges`, props<{ username: string }>());
export const updateADRAdditionalExaminerNotes = createAction(`${prefix} updateADRAdditionalExaminerNotes`, props<{ username: string }>());

export const updateExistingADRAdditionalExaminerNote = createAction(
`${prefix} updateExistingADRAdditionalExaminerNote`,
props<{ additionalExaminerNote: string, examinerNoteIndex: number }>(),
);

export const generateADRCertificate = createAction(`${prefix} generateADRCertificate`, props<{
systemNumber: string, createdTimestamp: string, certificateType: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
updateBody,
updateBrakeForces,
updateEditingTechRecord,
updateEditingTechRecordCancel,
updateEditingTechRecordCancel, updateExistingADRAdditionalExaminerNote,
updateScrollPosition,
updateTechRecord,
updateTechRecordFailure,
Expand Down Expand Up @@ -586,4 +586,29 @@ describe('Vehicle Technical Record Reducer', () => {
.toContainEqual(testNote);
});
});
describe('handleUpdateExistingADRExaminerNote', () => {
it('should', () => {
const state: TechnicalRecordServiceState = {
...initialState,
editingTechRecord: {
systemNumber: 'foo',
createdTimestamp: 'bar',
vin: 'testVin',
techRecord_adrDetails_additionalExaminerNotes: [
{
note: 'foo',
createdAtDate: 'bar',
lastUpdatedBy: 'foo',
},
],
} as unknown as TechRecordType<'put'>,
loading: true,
};
const newNote = 'foobar';
const action = updateExistingADRAdditionalExaminerNote({ additionalExaminerNote: newNote, examinerNoteIndex: 0 });
const newState = vehicleTechRecordReducer(state, action);
const editingTechRecord = newState.editingTechRecord as unknown as (NonVerbTechRecordType<'hgv' | 'lgv' | 'trl'>);
expect(editingTechRecord.techRecord_adrDetails_additionalExaminerNotes![0].note).toEqual(newNote);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import {
updateBody,
updateBrakeForces,
updateEditingTechRecord,
updateEditingTechRecordCancel,
updateEditingTechRecordCancel, updateExistingADRAdditionalExaminerNote,
updateScrollPosition,
updateTechRecord,
updateTechRecordFailure,
Expand Down Expand Up @@ -153,6 +153,8 @@ export const vehicleTechRecordReducer = createReducer(

on(updateADRAdditionalExaminerNotes, (state, action) => handleADRExaminerNoteChanges(state, action.username)),

on(updateExistingADRAdditionalExaminerNote, (state, action) => handleUpdateExistingADRExaminerNote(state, action)),

on(addAxle, (state) => handleAddAxle(state)),
on(removeAxle, (state, action) => handleRemoveAxle(state, action)),

Expand Down Expand Up @@ -547,3 +549,17 @@ function handleADRExaminerNoteChanges(state: TechnicalRecordServiceState, userna
}
return { ...state, editingTechRecord: additionalNoteTechRecord as unknown as (TechRecordType<'put'>) };
}

function handleUpdateExistingADRExaminerNote(
state: TechnicalRecordServiceState,
action: { additionalExaminerNote: string, examinerNoteIndex: number },
) {
const { editingTechRecord } = state;
const editedTechRecord = editingTechRecord as unknown as
(NonVerbTechRecordType<'hgv' | 'lgv' | 'trl'>);
if (editedTechRecord) {
const examinerNotes = editedTechRecord.techRecord_adrDetails_additionalExaminerNotes;
examinerNotes![action.examinerNoteIndex].note = action.additionalExaminerNote;
}
return { ...state, editingTechRecord: editingTechRecord as unknown as (TechRecordType<'put'>) };
}
Loading