Skip to content

Commit

Permalink
exui-2536-to update-nested-dynamice-list
Browse files Browse the repository at this point in the history
  • Loading branch information
RiteshHMCTS committed Nov 20, 2024
1 parent 3913532 commit 5d071f3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 8 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## RELEASE NOTES

### Version 7.0.75-exui-2536-rc-1
**EXUI-2536** issue with DynamicMultiSelectList

### Version 7.0.75-exui-2462-rc1
**EXUI-2462** DynamicRadioList incorrectly selects the wrong radio button

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.0.75-exui-2462-rc",
"version": "7.0.75-exui-2536-rc-1",
"engines": {
"node": ">=18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ccd-case-ui-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.0.75-exui-2462-rc",
"version": "7.0.75-exui-2536-rc-1",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,36 @@ describe('FieldTypeSanitiser', () => {
display_context: 'MANDATORY'
}]
}
},
{
id: 'field1',
field_type: {
type: 'Complex',
complex_fields: [
{
id: 'subfield1',
field_type: {
type: 'Complex',
complex_fields: [
{
id: 'subsubfield1',
field_type: {
type: 'DynamicMultiSelectList',
},
display_context: 'MANDATORY',
},
],
},
},
],
},
_value: {
subfield1: {
subsubfield1: {
list_items: ['nestedItem1', 'nestedItem2'],
},
},
},
}
] as unknown as CaseField[];
});
Expand Down Expand Up @@ -274,5 +304,10 @@ describe('FieldTypeSanitiser', () => {
{ code: '192', label: 'Peter Pan' }
]);
});

it('should add list_items to type DynamicMultiSelectList in deeply nested field', () => {
const result = fieldTypeSanitiser.ensureDynamicMultiSelectListPopulated(mockCaseFields);
expect(result[2].field_type.complex_fields[0].field_type.complex_fields[0].list_items).toEqual(['nestedItem1', 'nestedItem2']);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,39 @@ export class FieldTypeSanitiser {
if (field.field_type.type !== 'Complex') {
return field;
}
const complexFieldsUpdated = field.field_type.complex_fields.map((complexField) =>
complexField.field_type.type === FieldTypeSanitiser.FIELD_TYPE_DYNAMIC_MULTISELECT_LIST && complexField.display_context !== 'HIDDEN' && field._value?.[complexField.id]
? { ...complexField, list_items: field._value[complexField.id]?.list_items } : complexField
);
return { ...field, field_type: { ...field.field_type, complex_fields: complexFieldsUpdated } } as CaseField;
const caseFieldData = field._value;
// Process each complex field
field.field_type.complex_fields.forEach((complexField) => {
if (complexField.field_type.type === FieldTypeSanitiser.FIELD_TYPE_COMPLEX) {
this.checkNestedDynamicList(complexField, caseFieldData?.[complexField.id]);
} else if (
complexField.field_type.type === FieldTypeSanitiser.FIELD_TYPE_DYNAMIC_MULTISELECT_LIST &&
complexField.display_context !== 'HIDDEN' &&
field._value?.[complexField.id]
) {
complexField.list_items = field._value[complexField.id]?.list_items;
}
});
// Final transformation: construct updated field object
return { ...field, field_type: { ...field?.field_type } } as CaseField;
});
}
private checkNestedDynamicList(caseField: CaseField, fieldData: any = null): void {
caseField.field_type.complex_fields.forEach((complexField) => {
if (complexField.field_type.type === FieldTypeSanitiser.FIELD_TYPE_COMPLEX) {
this.checkNestedDynamicList(complexField, fieldData?.[complexField.id]);
} else if (
complexField.field_type.type === FieldTypeSanitiser.FIELD_TYPE_DYNAMIC_MULTISELECT_LIST &&
complexField.display_context !== 'HIDDEN' &&
fieldData?.[complexField.id]
) {
complexField.list_items = fieldData?.[complexField.id]?.list_items;
}
});
}

private convertArrayToDynamicListOutput(field: CaseField, data: any): void {
const values = data[field.id];

if (Array.isArray(values)) {
const listItems = this.getListItems(field);
const matches = listItems.filter(item => values.map(v => v.code).indexOf(item.code) !== -1);
Expand Down

0 comments on commit 5d071f3

Please sign in to comment.