@ukhomeoffice/cop-react-form-renderer 2.7.1 → 2.8.1
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.
- package/dist/components/CheckYourAnswers/CheckYourAnswers.stories.mdx +392 -331
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +66 -7
- package/dist/components/FormRenderer/FormRenderer.test.js +8 -8
- package/dist/components/PageActions/ActionButton.js +2 -1
- package/dist/components/TaskList/TaskList.js +5 -3
- package/dist/components/TaskList/TaskList.scss +8 -3
- package/dist/components/TaskList/TaskList.test.js +21 -15
- package/dist/json/group.data.json +21 -0
- package/dist/json/group.json +418 -0
- package/dist/json/groupOfRow.json +17 -38
- package/dist/json/taskList.json +48 -11
- package/dist/json/userProfile.data.json +6 -0
- package/dist/models/PageAction.js +2 -1
- package/dist/models/TaskStates.js +4 -4
- package/dist/utils/CheckYourAnswers/getCYARow.js +1 -0
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +2 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +82 -0
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.test.js +78 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +29 -3
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +61 -0
- package/package.json +2 -2
|
@@ -22,16 +22,16 @@ var StateTypes = {
|
|
|
22
22
|
exports.StateTypes = StateTypes;
|
|
23
23
|
var StateDetails = (_StateDetails = {}, _defineProperty(_StateDetails, TYPE_COMPLETE, {
|
|
24
24
|
label: 'Completed',
|
|
25
|
-
colour: ''
|
|
25
|
+
colour: 'dark-blue'
|
|
26
26
|
}), _defineProperty(_StateDetails, TYPE_IN_PROGRESS, {
|
|
27
27
|
label: 'In Progress',
|
|
28
|
-
colour: '
|
|
28
|
+
colour: 'white'
|
|
29
29
|
}), _defineProperty(_StateDetails, TYPE_NOT_STARTED, {
|
|
30
30
|
label: 'Not Started',
|
|
31
|
-
colour: 'grey'
|
|
31
|
+
colour: 'dark-grey'
|
|
32
32
|
}), _defineProperty(_StateDetails, TYPE_CANNOT_START_YET, {
|
|
33
33
|
label: 'Cannot Start Yet',
|
|
34
|
-
colour: 'grey'
|
|
34
|
+
colour: 'dark-grey'
|
|
35
35
|
}), _StateDetails);
|
|
36
36
|
var TaskStates = {
|
|
37
37
|
TYPES: StateTypes,
|
|
@@ -31,6 +31,7 @@ var getCYARow = function getCYARow(page, component, onAction) {
|
|
|
31
31
|
|
|
32
32
|
return {
|
|
33
33
|
pageId: page.id,
|
|
34
|
+
id: component.id,
|
|
34
35
|
fieldId: component.fieldId,
|
|
35
36
|
key: component.label || component.cya_label,
|
|
36
37
|
component: _Component.default.editable(component) ? component : undefined,
|
|
@@ -58,6 +58,7 @@ describe('utils', function () {
|
|
|
58
58
|
|
|
59
59
|
expect((0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION)).toEqual({
|
|
60
60
|
pageId: PAGE.id,
|
|
61
|
+
id: COMPONENT.id,
|
|
61
62
|
fieldId: COMPONENT.fieldId,
|
|
62
63
|
key: COMPONENT.label,
|
|
63
64
|
value: '',
|
|
@@ -84,6 +85,7 @@ describe('utils', function () {
|
|
|
84
85
|
|
|
85
86
|
expect((0, _getCYARow.default)(PAGE, COMPONENT, ON_ACTION)).toEqual({
|
|
86
87
|
pageId: PAGE.id,
|
|
88
|
+
id: COMPONENT.id,
|
|
87
89
|
fieldId: COMPONENT.fieldId,
|
|
88
90
|
key: COMPONENT.label,
|
|
89
91
|
value: 'BLAH',
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _FormComponent = _interopRequireDefault(require("../../components/FormComponent"));
|
|
11
|
+
|
|
12
|
+
var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
|
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
+
|
|
20
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
|
|
22
|
+
var getRowValue = function getRowValue(row) {
|
|
23
|
+
if (!row.value) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!row.component) {
|
|
28
|
+
return row.value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
32
|
+
key: row.id
|
|
33
|
+
}, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
34
|
+
component: _objectSpread(_objectSpread({}, row.component), {}, {
|
|
35
|
+
readonly: true
|
|
36
|
+
}),
|
|
37
|
+
wrap: false,
|
|
38
|
+
value: row.value
|
|
39
|
+
}));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var getGroupValue = function getGroupValue(group, rows) {
|
|
43
|
+
var firstComponentIndex = -1;
|
|
44
|
+
|
|
45
|
+
var value = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, group.components.map(function (componentId) {
|
|
46
|
+
var rowIndex = rows.findIndex(function (r) {
|
|
47
|
+
return r.id === componentId;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (firstComponentIndex < 0) {
|
|
51
|
+
firstComponentIndex = rowIndex;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return rowIndex > -1 ? getRowValue(rows[rowIndex]) : null;
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
value: value,
|
|
59
|
+
firstComponentIndex: firstComponentIndex
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var getCYARowForGroup = function getCYARowForGroup(page, group, rows, onAction) {
|
|
64
|
+
var _getGroupValue = getGroupValue(group, rows),
|
|
65
|
+
value = _getGroupValue.value,
|
|
66
|
+
firstComponentIndex = _getGroupValue.firstComponentIndex;
|
|
67
|
+
|
|
68
|
+
var row = {
|
|
69
|
+
pageId: page.id,
|
|
70
|
+
fieldId: group.id,
|
|
71
|
+
key: group.label,
|
|
72
|
+
value: value,
|
|
73
|
+
action: (0, _getCYAAction.default)(false, page, onAction)
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
row: row,
|
|
77
|
+
insertAt: firstComponentIndex
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var _default = getCYARowForGroup;
|
|
82
|
+
exports.default = _default;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _getCYARowForGroup = _interopRequireDefault(require("./getCYARowForGroup"));
|
|
6
|
+
|
|
7
|
+
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
// Global imports
|
|
12
|
+
//local imports
|
|
13
|
+
describe('utils', function () {
|
|
14
|
+
describe('CheckYourAnswers', function () {
|
|
15
|
+
describe('getCYARowsForGroup', function () {
|
|
16
|
+
it('should check address values block', function () {
|
|
17
|
+
var COMPONENT_ADDRESS = {
|
|
18
|
+
id: 'firstLineOfTheAddress',
|
|
19
|
+
fieldId: 'firstLineOfTheAddress',
|
|
20
|
+
label: 'address',
|
|
21
|
+
type: 'text'
|
|
22
|
+
};
|
|
23
|
+
var COMPONENT_TOWN = {
|
|
24
|
+
id: 'town',
|
|
25
|
+
fieldId: 'town',
|
|
26
|
+
label: 'Town',
|
|
27
|
+
type: 'text'
|
|
28
|
+
};
|
|
29
|
+
var COMPONENT_CITY = {
|
|
30
|
+
id: 'city',
|
|
31
|
+
fieldId: 'city',
|
|
32
|
+
label: 'City',
|
|
33
|
+
type: 'text'
|
|
34
|
+
};
|
|
35
|
+
var COMPONENT_POSTCODE = {
|
|
36
|
+
id: 'postCode',
|
|
37
|
+
fieldId: 'postCode',
|
|
38
|
+
label: 'postCode',
|
|
39
|
+
type: 'text'
|
|
40
|
+
};
|
|
41
|
+
var PAGE = {
|
|
42
|
+
components: [COMPONENT_ADDRESS, COMPONENT_TOWN, COMPONENT_CITY, COMPONENT_POSTCODE],
|
|
43
|
+
id: 'addressDetails',
|
|
44
|
+
fieldId: 'UK address',
|
|
45
|
+
groups: [{
|
|
46
|
+
id: 'address',
|
|
47
|
+
label: 'Address details',
|
|
48
|
+
components: ['firstLineOfTheAddress', 'town', 'city', 'postCode']
|
|
49
|
+
}],
|
|
50
|
+
name: 'address-details',
|
|
51
|
+
title: 'Address details',
|
|
52
|
+
formData: {
|
|
53
|
+
firstLineOfTheAddress: '10 Downing Street',
|
|
54
|
+
town: 'City of Westminster',
|
|
55
|
+
city: 'London',
|
|
56
|
+
postCode: 'SW1A 2AA'
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
61
|
+
|
|
62
|
+
var rows = PAGE.components.map(function (component) {
|
|
63
|
+
return (0, _getCYARow.default)(PAGE, component, ON_ACTION);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
var _render = (0, _react.render)((0, _getCYARowForGroup.default)(PAGE, PAGE.groups[0], rows, ON_ACTION).row.value),
|
|
67
|
+
container = _render.container;
|
|
68
|
+
|
|
69
|
+
expect(container.childNodes.length).toEqual(4);
|
|
70
|
+
var addressValues = container.childNodes;
|
|
71
|
+
expect(addressValues[0].childNodes[0].textContent).toEqual('10 Downing Street');
|
|
72
|
+
expect(addressValues[1].childNodes[0].textContent).toEqual('City of Westminster');
|
|
73
|
+
expect(addressValues[2].childNodes[0].textContent).toEqual('London');
|
|
74
|
+
expect(addressValues[3].childNodes[0].textContent).toEqual('SW1A 2AA');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -11,6 +11,8 @@ var _FormPage = _interopRequireDefault(require("../FormPage"));
|
|
|
11
11
|
|
|
12
12
|
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
13
13
|
|
|
14
|
+
var _getCYARowForGroup2 = _interopRequireDefault(require("./getCYARowForGroup"));
|
|
15
|
+
|
|
14
16
|
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
15
17
|
|
|
16
18
|
var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
@@ -21,15 +23,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Gets an array of row objects, each configured appropriately for a Check your answers component.
|
|
24
|
-
*
|
|
26
|
+
*
|
|
25
27
|
* @param {object} page The page to show components for.
|
|
26
28
|
* @param {Function} onAction A function to invoke if the change link on any row is clicked.
|
|
27
|
-
*
|
|
29
|
+
*
|
|
28
30
|
* @returns An array of configuration objects for Check your answers rows.
|
|
29
31
|
*/
|
|
30
32
|
var getCYARowsForPage = function getCYARowsForPage(page, onAction) {
|
|
31
33
|
if (_FormPage.default.show(page, page.formData)) {
|
|
32
|
-
|
|
34
|
+
var _page$groups;
|
|
35
|
+
|
|
36
|
+
var rows = page.components.filter(function (c) {
|
|
33
37
|
return (0, _showComponentCYA.default)(c, page.formData);
|
|
34
38
|
}).flatMap(function (component) {
|
|
35
39
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
@@ -38,6 +42,28 @@ var getCYARowsForPage = function getCYARowsForPage(page, onAction) {
|
|
|
38
42
|
|
|
39
43
|
return (0, _getCYARow.default)(page, component, onAction);
|
|
40
44
|
});
|
|
45
|
+
|
|
46
|
+
if (((_page$groups = page.groups) === null || _page$groups === void 0 ? void 0 : _page$groups.length) > 0) {
|
|
47
|
+
page.groups.forEach(function (group) {
|
|
48
|
+
var _getCYARowForGroup = (0, _getCYARowForGroup2.default)(page, group, rows, onAction),
|
|
49
|
+
row = _getCYARowForGroup.row,
|
|
50
|
+
insertAt = _getCYARowForGroup.insertAt;
|
|
51
|
+
|
|
52
|
+
if (insertAt > -1) {
|
|
53
|
+
rows.splice(insertAt, 0, row);
|
|
54
|
+
} else {
|
|
55
|
+
rows.push(row);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
var allReplacedIds = page.groups.flatMap(function (g) {
|
|
59
|
+
return g.components;
|
|
60
|
+
});
|
|
61
|
+
return rows.filter(function (r) {
|
|
62
|
+
return !allReplacedIds.includes(r.id);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return rows;
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
return [];
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
3
5
|
var _models = require("../../models");
|
|
4
6
|
|
|
5
7
|
var _getCYARowsForPage = _interopRequireDefault(require("./getCYARowsForPage"));
|
|
6
8
|
|
|
7
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
10
|
|
|
11
|
+
// Global imports
|
|
9
12
|
// Local imports
|
|
10
13
|
describe('utils', function () {
|
|
11
14
|
describe('CheckYourAnswers', function () {
|
|
@@ -173,6 +176,64 @@ describe('utils', function () {
|
|
|
173
176
|
});
|
|
174
177
|
});
|
|
175
178
|
});
|
|
179
|
+
it('Add ability to display answers from multiple fields in a single row', function () {
|
|
180
|
+
var COMPONENT_ADDRESS = {
|
|
181
|
+
id: 'firstLineOfTheAddress',
|
|
182
|
+
fieldId: 'firstLineOfTheAddress',
|
|
183
|
+
label: 'address',
|
|
184
|
+
type: 'text'
|
|
185
|
+
};
|
|
186
|
+
var COMPONENT_TOWN = {
|
|
187
|
+
id: 'town',
|
|
188
|
+
fieldId: 'town',
|
|
189
|
+
label: 'Town',
|
|
190
|
+
type: 'text'
|
|
191
|
+
};
|
|
192
|
+
var COMPONENT_CITY = {
|
|
193
|
+
id: 'city',
|
|
194
|
+
fieldId: 'city',
|
|
195
|
+
label: 'City',
|
|
196
|
+
type: 'text'
|
|
197
|
+
};
|
|
198
|
+
var COMPONENT_POSTCODE = {
|
|
199
|
+
id: 'postCode',
|
|
200
|
+
fieldId: 'postCode',
|
|
201
|
+
label: 'postCode',
|
|
202
|
+
type: 'text'
|
|
203
|
+
};
|
|
204
|
+
var PAGE = {
|
|
205
|
+
components: [COMPONENT_ADDRESS, COMPONENT_TOWN, COMPONENT_CITY, COMPONENT_POSTCODE],
|
|
206
|
+
id: 'addressDetails',
|
|
207
|
+
fieldId: 'UK address',
|
|
208
|
+
groups: [{
|
|
209
|
+
id: 'address',
|
|
210
|
+
label: 'Address details',
|
|
211
|
+
components: ['firstLineOfTheAddress', 'town', 'city', 'postCode']
|
|
212
|
+
}],
|
|
213
|
+
name: 'address-details',
|
|
214
|
+
title: 'Address details',
|
|
215
|
+
formData: {
|
|
216
|
+
firstLineOfTheAddress: '10 Downing Street',
|
|
217
|
+
town: 'City of Westminster',
|
|
218
|
+
city: 'London',
|
|
219
|
+
postCode: 'SW1A 2AA'
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
224
|
+
|
|
225
|
+
var _render = (0, _react.render)((0, _getCYARowsForPage.default)(PAGE, ON_ACTION).map(function (row) {
|
|
226
|
+
return row.value;
|
|
227
|
+
})),
|
|
228
|
+
container = _render.container;
|
|
229
|
+
|
|
230
|
+
expect(container.childNodes.length).toEqual(4);
|
|
231
|
+
var addressValues = container.childNodes;
|
|
232
|
+
expect(addressValues[0].childNodes[0].textContent).toEqual('10 Downing Street');
|
|
233
|
+
expect(addressValues[1].childNodes[0].textContent).toEqual('City of Westminster');
|
|
234
|
+
expect(addressValues[2].childNodes[0].textContent).toEqual('London');
|
|
235
|
+
expect(addressValues[3].childNodes[0].textContent).toEqual('SW1A 2AA');
|
|
236
|
+
});
|
|
176
237
|
});
|
|
177
238
|
});
|
|
178
239
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "1.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "1.5.1",
|
|
20
20
|
"axios": "^0.21.1",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^3.13.0",
|