@ukhomeoffice/cop-react-form-renderer 5.43.0 → 5.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -50,7 +50,8 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
50
50
|
noGroupAction = _ref.noGroupAction,
|
|
51
51
|
groups = _ref.groups,
|
|
52
52
|
sections = _ref.sections,
|
|
53
|
-
type = _ref.type
|
|
53
|
+
type = _ref.type,
|
|
54
|
+
hideBlankRows = _ref.hideBlankRows;
|
|
54
55
|
var _useState = (0, _react.useState)([]),
|
|
55
56
|
_useState2 = _slicedToArray(_useState, 2),
|
|
56
57
|
pages = _useState2[0],
|
|
@@ -179,18 +180,25 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
179
180
|
}));
|
|
180
181
|
});
|
|
181
182
|
}), type !== _models.FormTypes.TASK_CYA && pages && pages.map(function (page, pageIndex, array) {
|
|
182
|
-
var
|
|
183
|
+
var filteredRows = !hideBlankRows || page.collection ? page.rows : page.rows.filter(function (row) {
|
|
184
|
+
var _row$value;
|
|
185
|
+
return row === null || row === void 0 || (_row$value = row.value) === null || _row$value === void 0 || (_row$value = _row$value.props) === null || _row$value === void 0 ? void 0 : _row$value.value;
|
|
186
|
+
});
|
|
187
|
+
if (filteredRows.length === 0) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
var showPageTitle = !hide_page_titles && page.title && !isGroup(page.id);
|
|
191
|
+
var pageMarginBottom = isLastPage(pageIndex) || isGroup(array[pageIndex].id) || array.length > pageIndex + 1 && isGroup(array[pageIndex + 1].id) ? DEFAULT_MARGIN_BOTTOM : listMarginBottom;
|
|
183
192
|
var currentGroup = isGroup(page.id) ? getGroupForPage(page.id) : undefined;
|
|
184
193
|
var className = "govuk-!-margin-bottom-".concat(pageMarginBottom);
|
|
185
194
|
var hideActionButtons = isGroup(page.id) || noChangeAction;
|
|
186
|
-
var showHeading = !hide_page_titles && page.title && !isGroup(page.id);
|
|
187
195
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, {
|
|
188
196
|
key: pageIndex
|
|
189
|
-
},
|
|
197
|
+
}, showPageTitle && getPageHeading(page, 'm'), currentGroup && /*#__PURE__*/_react.default.createElement("div", {
|
|
190
198
|
className: "group-title"
|
|
191
199
|
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, currentGroup.title || _utils.default.FormPage.getTitle(page.title, page.formData))), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
|
|
192
200
|
className: className,
|
|
193
|
-
rows:
|
|
201
|
+
rows: filteredRows,
|
|
194
202
|
classModifiers: summaryListClassModifiers,
|
|
195
203
|
noChangeAction: hideActionButtons,
|
|
196
204
|
noGroupAction: noGroupAction,
|
|
@@ -224,7 +232,8 @@ CheckYourAnswers.propTypes = {
|
|
|
224
232
|
})),
|
|
225
233
|
summaryListClassModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
226
234
|
title: _propTypes.default.string,
|
|
227
|
-
type: _propTypes.default.string
|
|
235
|
+
type: _propTypes.default.string,
|
|
236
|
+
hideBlankRows: _propTypes.default.bool
|
|
228
237
|
};
|
|
229
238
|
CheckYourAnswers.defaultProps = {
|
|
230
239
|
actions: [],
|
|
@@ -237,6 +246,7 @@ CheckYourAnswers.defaultProps = {
|
|
|
237
246
|
sections: [],
|
|
238
247
|
summaryListClassModifiers: null,
|
|
239
248
|
title: DEFAULT_TITLE,
|
|
240
|
-
type: null
|
|
249
|
+
type: null,
|
|
250
|
+
hideBlankRows: false
|
|
241
251
|
};
|
|
242
252
|
var _default = exports.default = CheckYourAnswers;
|
|
@@ -771,5 +771,54 @@ describe('components', function () {
|
|
|
771
771
|
}
|
|
772
772
|
}, _callee30);
|
|
773
773
|
})));
|
|
774
|
+
it('Show answers from multiple address fields into in one DL correctly when hideBlankRows is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
|
|
775
|
+
var ADDRESS_DATA, GROUP_PAGES, cya, groupedComponent, keyGroup, valueGroup, changeButtonDiv, changeButton;
|
|
776
|
+
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
777
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
778
|
+
case 0:
|
|
779
|
+
ADDRESS_DATA = _utils.default.Data.setupForm(_group.default.pages, _group.default.components, _groupData.default);
|
|
780
|
+
GROUP_PAGES = _utils.default.FormPage.getAll(_group.default.pages, _group.default.components, _objectSpread({}, ADDRESS_DATA));
|
|
781
|
+
_context32.next = 4;
|
|
782
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
|
|
783
|
+
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
784
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
785
|
+
case 0:
|
|
786
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
787
|
+
pages: GROUP_PAGES,
|
|
788
|
+
onRowAction: ON_ROW_ACTION,
|
|
789
|
+
onAction: ON_ACTION,
|
|
790
|
+
hide_title: true,
|
|
791
|
+
hideBlankRows: true
|
|
792
|
+
}), container);
|
|
793
|
+
case 1:
|
|
794
|
+
case "end":
|
|
795
|
+
return _context31.stop();
|
|
796
|
+
}
|
|
797
|
+
}, _callee31);
|
|
798
|
+
})));
|
|
799
|
+
case 4:
|
|
800
|
+
cya = checkCYA(container);
|
|
801
|
+
groupedComponent = cya.childNodes[6];
|
|
802
|
+
keyGroup = groupedComponent.childNodes[0].childNodes[0].childNodes[0];
|
|
803
|
+
expect(keyGroup.tagName).toEqual('DT');
|
|
804
|
+
expect(keyGroup.textContent).toEqual('Address details');
|
|
805
|
+
valueGroup = groupedComponent.childNodes[0].childNodes[0].childNodes[1];
|
|
806
|
+
expect(valueGroup.childNodes.length).toEqual(4);
|
|
807
|
+
expect(valueGroup.tagName).toEqual('DD');
|
|
808
|
+
expect(valueGroup.childNodes[0].textContent).toContain('10 Downing Street');
|
|
809
|
+
expect(valueGroup.childNodes[1].textContent).toContain('City of Westminster');
|
|
810
|
+
expect(valueGroup.childNodes[2].textContent).toContain('London');
|
|
811
|
+
expect(valueGroup.childNodes[3].textContent).toContain('SW1A 2AA');
|
|
812
|
+
changeButtonDiv = groupedComponent.childNodes[0].childNodes[0].childNodes[2];
|
|
813
|
+
expect(changeButtonDiv.classList).toContain('govuk-summary-list__actions');
|
|
814
|
+
changeButton = changeButtonDiv.childNodes[0];
|
|
815
|
+
expect(changeButton.tagName).toEqual('A');
|
|
816
|
+
expect(changeButton.textContent).toEqual('Change address details');
|
|
817
|
+
case 21:
|
|
818
|
+
case "end":
|
|
819
|
+
return _context32.stop();
|
|
820
|
+
}
|
|
821
|
+
}, _callee32);
|
|
822
|
+
})));
|
|
774
823
|
});
|
|
775
824
|
});
|
|
@@ -59,7 +59,8 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
59
59
|
summaryListClassModifiers = _ref.summaryListClassModifiers,
|
|
60
60
|
noChangeAction = _ref.noChangeAction,
|
|
61
61
|
newPageId = _ref.newPageId,
|
|
62
|
-
viewOnly = _ref.viewOnly
|
|
62
|
+
viewOnly = _ref.viewOnly,
|
|
63
|
+
hideBlankRows = _ref.hideBlankRows;
|
|
63
64
|
return /*#__PURE__*/_react.default.createElement(_context.HooksContextProvider, {
|
|
64
65
|
overrides: hooks
|
|
65
66
|
}, /*#__PURE__*/_react.default.createElement(_context.ValidationContextProvider, null, /*#__PURE__*/_react.default.createElement(InternalFormRenderer, {
|
|
@@ -78,7 +79,8 @@ var FormRenderer = function FormRenderer(_ref) {
|
|
|
78
79
|
summaryListClassModifiers: summaryListClassModifiers,
|
|
79
80
|
noChangeAction: noChangeAction,
|
|
80
81
|
newPageId: newPageId,
|
|
81
|
-
viewOnly: viewOnly
|
|
82
|
+
viewOnly: viewOnly,
|
|
83
|
+
hideBlankRows: hideBlankRows
|
|
82
84
|
})));
|
|
83
85
|
};
|
|
84
86
|
var DEFAULT_CLASS = exports.DEFAULT_CLASS = 'hods-form';
|
|
@@ -99,7 +101,8 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
99
101
|
summaryListClassModifiers = _ref2.summaryListClassModifiers,
|
|
100
102
|
noChangeAction = _ref2.noChangeAction,
|
|
101
103
|
newPageId = _ref2.newPageId,
|
|
102
|
-
viewOnly = _ref2.viewOnly
|
|
104
|
+
viewOnly = _ref2.viewOnly,
|
|
105
|
+
hideBlankRows = _ref2.hideBlankRows;
|
|
103
106
|
// Set up the initial states.
|
|
104
107
|
var _useState = (0, _react.useState)({}),
|
|
105
108
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -341,7 +344,8 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
341
344
|
noChangeAction: (_formState$cya$hideCh = formState.cya.hideChangeActions) !== null && _formState$cya$hideCh !== void 0 ? _formState$cya$hideCh : noChangeAction,
|
|
342
345
|
noGroupAction: (_formState$cya$hideGr = formState.cya.hideGroupActions) !== null && _formState$cya$hideGr !== void 0 ? _formState$cya$hideGr : false,
|
|
343
346
|
sections: typeof hubDetails !== 'undefined' ? hubDetails.sections : [],
|
|
344
|
-
type: type
|
|
347
|
+
type: type,
|
|
348
|
+
hideBlankRows: hideBlankRows
|
|
345
349
|
})), hub === _models.HubFormats.TASK && formState.pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_TaskList.default, _extends({}, taskDetails, {
|
|
346
350
|
refNumber: data.businessKey,
|
|
347
351
|
onTaskAction: function onTaskAction(task) {
|
|
@@ -398,7 +402,8 @@ var propTypes = {
|
|
|
398
402
|
title: _propTypes.default.string,
|
|
399
403
|
/** See <a href="/?path=/docs/f-json--page#formtypes">FormTypes</a>. */
|
|
400
404
|
type: _propTypes.default.oneOf([_models.FormTypes.CYA, _models.FormTypes.FORM, _models.FormTypes.HUB, _models.FormTypes.TASK, _models.FormTypes.WIZARD, _models.FormTypes.TASK_CYA, _models.FormTypes.FORM_WITH_TASK]).isRequired,
|
|
401
|
-
viewOnly: _propTypes.default.bool
|
|
405
|
+
viewOnly: _propTypes.default.bool,
|
|
406
|
+
hideBlankRows: _propTypes.default.bool
|
|
402
407
|
};
|
|
403
408
|
var defaultProps = {
|
|
404
409
|
classBlock: DEFAULT_CLASS,
|
|
@@ -419,7 +424,8 @@ var defaultProps = {
|
|
|
419
424
|
noChangeAction: false,
|
|
420
425
|
summaryListClassModifiers: [],
|
|
421
426
|
title: '',
|
|
422
|
-
viewOnly: true
|
|
427
|
+
viewOnly: true,
|
|
428
|
+
hideBlankRows: false
|
|
423
429
|
};
|
|
424
430
|
FormRenderer.propTypes = propTypes;
|
|
425
431
|
InternalFormRenderer.propTypes = propTypes;
|
|
@@ -1119,5 +1119,63 @@ describe('components', function () {
|
|
|
1119
1119
|
}
|
|
1120
1120
|
}, _callee38);
|
|
1121
1121
|
})));
|
|
1122
|
+
it('should handle page navigation correctly when hideBlankRows is true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40() {
|
|
1123
|
+
var ON_PAGE_CHANGE_CALLS, ON_PAGE_CHANGE, HOOKS, form, hub, _hub$childNodes7, lineManagerList, link, page, pageHeading, continueButton, newPageHeading;
|
|
1124
|
+
return _regeneratorRuntime().wrap(function _callee40$(_context40) {
|
|
1125
|
+
while (1) switch (_context40.prev = _context40.next) {
|
|
1126
|
+
case 0:
|
|
1127
|
+
ON_PAGE_CHANGE_CALLS = [];
|
|
1128
|
+
ON_PAGE_CHANGE = function ON_PAGE_CHANGE(pageId) {
|
|
1129
|
+
ON_PAGE_CHANGE_CALLS.push(pageId);
|
|
1130
|
+
};
|
|
1131
|
+
HOOKS = {
|
|
1132
|
+
onPageChange: ON_PAGE_CHANGE
|
|
1133
|
+
};
|
|
1134
|
+
_context40.next = 5;
|
|
1135
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
|
|
1136
|
+
return _regeneratorRuntime().wrap(function _callee39$(_context39) {
|
|
1137
|
+
while (1) switch (_context39.prev = _context39.next) {
|
|
1138
|
+
case 0:
|
|
1139
|
+
(0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
|
|
1140
|
+
data: _userProfileData.default,
|
|
1141
|
+
hooks: HOOKS,
|
|
1142
|
+
hideBlankRows: true
|
|
1143
|
+
})), container);
|
|
1144
|
+
case 1:
|
|
1145
|
+
case "end":
|
|
1146
|
+
return _context39.stop();
|
|
1147
|
+
}
|
|
1148
|
+
}, _callee39);
|
|
1149
|
+
})));
|
|
1150
|
+
case 5:
|
|
1151
|
+
form = checkForm(container); // Navigate to the "Add or change a line manager" page.
|
|
1152
|
+
hub = form.childNodes[1]; // Hub = CYA
|
|
1153
|
+
_hub$childNodes7 = _slicedToArray(hub.childNodes, 4), lineManagerList = _hub$childNodes7[3];
|
|
1154
|
+
link = getChangeLink(lineManagerList);
|
|
1155
|
+
expect(ON_PAGE_CHANGE_CALLS.length).toEqual(0);
|
|
1156
|
+
_react.fireEvent.click(link, {});
|
|
1157
|
+
expect(ON_PAGE_CHANGE_CALLS[0]).toEqual(_userProfile.default.pages[4].id);
|
|
1158
|
+
|
|
1159
|
+
// Should be on the page explaining what changing the line manager means.
|
|
1160
|
+
page = form.childNodes[0];
|
|
1161
|
+
pageHeading = page.childNodes[0];
|
|
1162
|
+
expect(pageHeading.tagName).toEqual('H1');
|
|
1163
|
+
expect(pageHeading.textContent).toEqual(_userProfile.default.pages[4].title);
|
|
1164
|
+
|
|
1165
|
+
// Now click on the "Continue" button on here.
|
|
1166
|
+
continueButton = getContinueButton(page);
|
|
1167
|
+
expect(ON_PAGE_CHANGE_CALLS.length).toEqual(1);
|
|
1168
|
+
_react.fireEvent.click(continueButton, {});
|
|
1169
|
+
expect(ON_PAGE_CHANGE_CALLS.length).toEqual(2);
|
|
1170
|
+
expect(ON_PAGE_CHANGE_CALLS[1]).toEqual(_userProfile.default.pages[5].id);
|
|
1171
|
+
newPageHeading = form.childNodes[0].childNodes[0];
|
|
1172
|
+
expect(newPageHeading.tagName).toEqual('H1');
|
|
1173
|
+
expect(newPageHeading.textContent).toEqual(_userProfile.default.pages[5].title);
|
|
1174
|
+
case 24:
|
|
1175
|
+
case "end":
|
|
1176
|
+
return _context40.stop();
|
|
1177
|
+
}
|
|
1178
|
+
}, _callee40);
|
|
1179
|
+
})));
|
|
1122
1180
|
});
|
|
1123
1181
|
});
|