Skip to content

Commit b7c98e7

Browse files
Merge pull request #592 from hmcts/bugfix/EUI-2681-retain-hidden-value-fix-for-complex-types
EUI-2681: Fix retain hidden value support for complex field types
2 parents 95d6ec8 + 1255b8f commit b7c98e7

File tree

5 files changed

+52
-27
lines changed

5 files changed

+52
-27
lines changed

RELEASE-NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## RELEASE NOTES
2+
### Version 2.64.43-retain-hidden-value-fix-for-complex-types
3+
**EUI-2681** Fix: Do not set a field control's value to `null` if it corresponds to a complex `CaseField` type
4+
25
### Version 2.64.42-retain-hidden-value-support
36
**EUI-1783** Delete hidden field value except if `retain_hidden_value` flag is true
47

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmcts/ccd-case-ui-toolkit",
3-
"version": "2.64.42-retain-hidden-value-support",
3+
"version": "2.64.43-retain-hidden-value-fix-for-complex-types",
44
"engines": {
55
"yarn": "^1.12.3",
66
"npm": "^5.6.0"
@@ -173,11 +173,12 @@
173173
"mem": "^6.0.0",
174174
"minimatch": "^3.0.2",
175175
"minimist": "1.2.3",
176+
"node-fetch": "2.6.1",
177+
"node-forge": "^0.10.0",
176178
"npm-registry-fetch": "^4.0.5",
177179
"serialize-javascript": "^3.1.0",
178180
"tree-kill": "1.2.2",
179-
"yargs-parser": "18.1.2",
180-
"node-fetch": "2.6.1"
181+
"yargs-parser": "18.1.2"
181182
},
182183
"publishConfig": {
183184
"access": "public"

src/shared/components/case-editor/case-edit-submit/case-edit-submit.component.spec.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ describe('CaseEditSubmitComponent', () => {
4343
const FORM_GROUP = new FormGroup({
4444
'data': new FormGroup({ 'PersonLastName': new FormControl('Khaleesi') })
4545
});
46+
const COMPLEX_ELEMENT_HIDDEN = new FormGroup({
47+
'childField1': new FormControl('Child field of complex type')
48+
});
49+
COMPLEX_ELEMENT_HIDDEN.disable();
4650
const FORM_GROUP_WITH_HIDDEN_FIELDS = new FormGroup({
4751
'data': new FormGroup({
4852
'field1': new FormControl({ value: 'Hidden value to be retained', disabled: true }),
4953
'field2': new FormControl({ value: 'Hidden value not to be retained', disabled: true }),
50-
'field3': new FormControl('Hide both')
54+
'field3': new FormControl('Hide all'),
55+
'complexField1': COMPLEX_ELEMENT_HIDDEN
5156
})
5257
});
5358
let caseEditComponent: any;
@@ -58,10 +63,12 @@ describe('CaseEditSubmitComponent', () => {
5863
let profileNotifier;
5964
let profileNotifierSpy;
6065
let casesReferencePipe: any;
61-
let caseField1: CaseField = aCaseField('field1', 'field1', 'Text', 'OPTIONAL', 3);
62-
let caseField2: CaseField = aCaseField('field2', 'field2', 'Text', 'OPTIONAL', 2);
63-
let caseField3: CaseField = aCaseField('field3', 'field3', 'Text', 'OPTIONAL', 1);
64-
let caseFieldRetainHiddenValue: CaseField = aCaseField('field1', 'field1', 'Text', 'OPTIONAL', 3, null, true);
66+
const caseField1: CaseField = aCaseField('field1', 'field1', 'Text', 'OPTIONAL', 4);
67+
const caseField2: CaseField = aCaseField('field2', 'field2', 'Text', 'OPTIONAL', 3);
68+
const caseField3: CaseField = aCaseField('field3', 'field3', 'Text', 'OPTIONAL', 2);
69+
const complexSubField: CaseField = aCaseField('childField1', 'childField1', 'Text', 'OPTIONAL', 1);
70+
const complexCaseField: CaseField = aCaseField('complexField1', 'complexField1', 'Complex', 'OPTIONAL', 1, [complexSubField]);
71+
const caseFieldRetainHiddenValue: CaseField = aCaseField('field1', 'field1', 'Text', 'OPTIONAL', 4, null, true);
6572
const $EVENT_NOTES = By.css('#fieldset-event');
6673
let cancelled: any;
6774
let snapshot: any;
@@ -341,16 +348,16 @@ describe('CaseEditSubmitComponent', () => {
341348
});
342349

343350
it('should sort case fields with show_summary_content_option', () => {
344-
expect(comp.eventTrigger.case_fields[0].show_summary_content_option).toBe(3);
345-
expect(comp.eventTrigger.case_fields[1].show_summary_content_option).toBe(2);
346-
expect(comp.eventTrigger.case_fields[2].show_summary_content_option).toBe(1);
351+
expect(comp.eventTrigger.case_fields[0].show_summary_content_option).toBe(4);
352+
expect(comp.eventTrigger.case_fields[1].show_summary_content_option).toBe(3);
353+
expect(comp.eventTrigger.case_fields[2].show_summary_content_option).toBe(2);
347354
expect(orderService.sort).toHaveBeenCalledWith(
348355
comp.eventTrigger.case_fields,
349356
CaseEditSubmitComponent.SHOW_SUMMARY_CONTENT_COMPARE_FUNCTION);
350357
expect(comp.showSummaryFields.length).toBe(3);
351-
expect(comp.showSummaryFields[0].show_summary_content_option).toBe(1);
352-
expect(comp.showSummaryFields[1].show_summary_content_option).toBe(2);
353-
expect(comp.showSummaryFields[2].show_summary_content_option).toBe(3);
358+
expect(comp.showSummaryFields[0].show_summary_content_option).toBe(2);
359+
expect(comp.showSummaryFields[1].show_summary_content_option).toBe(3);
360+
expect(comp.showSummaryFields[2].show_summary_content_option).toBe(4);
354361
});
355362

356363
it('should return "Cancel" text label for cancel button when save and resume disabled', () => {
@@ -709,12 +716,14 @@ describe('CaseEditSubmitComponent', () => {
709716
aWizardPage('page1', 'Page 1', 1),
710717
];
711718
const firstPage = pages[0];
712-
caseFieldRetainHiddenValue.show_condition = 'field3!="Hide both"';
713-
caseField2.show_condition = 'field3!="Hide both"';
719+
caseFieldRetainHiddenValue.show_condition = 'field3!="Hide all"';
720+
caseField2.show_condition = 'field3!="Hide all"';
721+
complexCaseField.show_condition = 'field3!="Hide all"';
714722
const WP_FIELD_1: WizardPageField = { case_field_id: caseFieldRetainHiddenValue.id };
715723
const WP_FIELD_2: WizardPageField = { case_field_id: caseField2.id };
716724
const WP_FIELD_3: WizardPageField = { case_field_id: caseField3.id };
717-
firstPage.wizard_page_fields = [WP_FIELD_1, WP_FIELD_2, WP_FIELD_3];
725+
const WP_FIELD_4: WizardPageField = { case_field_id: complexCaseField.id };
726+
firstPage.wizard_page_fields = [WP_FIELD_1, WP_FIELD_2, WP_FIELD_3, WP_FIELD_4];
718727
wizard = new Wizard(pages);
719728
const queryParamMapNoProfile = createSpyObj('queryParamMap', ['get']);
720729
const snapshotNoProfile = {
@@ -749,15 +758,18 @@ describe('CaseEditSubmitComponent', () => {
749758
beforeEach(async(() => {
750759
// Need to set the page case_fields here because, for some reason, if set initially then these get overridden
751760
// by some unknown default!
752-
firstPage.case_fields = [caseFieldRetainHiddenValue, caseField2, caseField3];
761+
firstPage.case_fields = [caseFieldRetainHiddenValue, caseField2, caseField3, complexCaseField];
753762
orderService = new OrderService();
754763
casesReferencePipe = createSpyObj<CaseReferencePipe>('caseReference', ['transform']);
755764
cancelled = createSpyObj('cancelled', ['emit'])
756765
caseEditComponent = {
757766
'form': FORM_GROUP_WITH_HIDDEN_FIELDS,
758767
'fieldsPurger': new FieldsPurger(fieldsUtils),
759768
'data': '',
760-
'eventTrigger': { 'case_fields': [caseFieldRetainHiddenValue, caseField2, caseField3], 'can_save_draft': true },
769+
'eventTrigger': {
770+
'case_fields': [caseFieldRetainHiddenValue, caseField2, caseField3, complexCaseField],
771+
'can_save_draft': true
772+
},
761773
'wizard': wizard,
762774
'hasPrevious': () => true,
763775
'getPage': () => firstPage,
@@ -812,7 +824,7 @@ describe('CaseEditSubmitComponent', () => {
812824
fixture.detectChanges();
813825
});
814826

815-
it('should submit CaseEventData with null for any hidden fields whose values are not to be retained', () => {
827+
it('should submit CaseEventData with null for any hidden fields (excluding Complex types) whose values are not to be retained', () => {
816828
// Trigger the clearing of hidden fields by invoking next()
817829
caseEditComponent.next();
818830

@@ -821,7 +833,7 @@ describe('CaseEditSubmitComponent', () => {
821833
expect(caseEditComponent.submit).toHaveBeenCalledWith({
822834
data: {
823835
field2: null,
824-
field3: 'Hide both'
836+
field3: 'Hide all'
825837
},
826838
event_token: undefined,
827839
ignore_warning: false

src/shared/services/fields/fields.purger.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ export class FieldsPurger {
7070
// Removing the field means that it is *NOT* sent to the CCD backend, which means no changes are made in the data.
7171
// This is OK *if* the hidden value needs to be retained, i.e. field.retain_hidden_value = true, but the default
7272
// should be to set it to null and allow it to be sent as such.
73-
if (field.retain_hidden_value) {
73+
//
74+
// *Complex* field types, i.e. those that contain other fields, should assume the same behaviour as before, which
75+
// is to reset the `CaseField` value and remove the form control. The value of the *control* itself should be left
76+
// alone.
77+
//
78+
// The only reliable check if a field is a complex type or not is to obtain its corresponding control and check
79+
// whether it's a `FormControl` (simple field) or `FormGroup` (complex field) instance.
80+
if (field.retain_hidden_value || (form.get('data') as FormGroup).get(field.id) instanceof FormGroup) {
7481
// Reset the field value and remove its control. This does NOT update it in the CCD backend, since it is just
7582
// removed from the JSON structure
7683
if (Array.isArray(field.value)) {
@@ -84,7 +91,9 @@ export class FieldsPurger {
8491
} else {
8592
// Set the value of the field's control to null. This DOES update the value in the CCD backend
8693
const fieldControl = (form.get('data') as FormGroup).get(field.id);
87-
fieldControl.setValue(null);
94+
if (fieldControl) {
95+
fieldControl.setValue(null);
96+
}
8897
}
8998
}
9099

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7497,10 +7497,10 @@ [email protected], node-fetch@^2.2.0:
74977497
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
74987498
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
74997499

7500-
7501-
version "0.9.0"
7502-
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579"
7503-
integrity sha512-7ASaDa3pD+lJ3WvXFsxekJQelBKRpne+GOVbLbtHYdd7pFspyeuJHnWfLplGf3SwKGbfs/aYl5V/JCIaHVUKKQ==
7500+
[email protected], node-forge@^0.10.0:
7501+
version "0.10.0"
7502+
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"
7503+
integrity sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==
75047504

75057505
node-gyp@^3.8.0:
75067506
version "3.8.0"

0 commit comments

Comments
 (0)