@ukhomeoffice/cop-react-form-renderer 4.44.0 → 4.46.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.
- package/dist/components/SummaryList/SummaryList.js +11 -0
- package/dist/components/SummaryList/SummaryList.scss +19 -0
- package/dist/components/SummaryList/SummaryListHeadingRow.js +31 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +59 -6
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +213 -49
- package/dist/utils/CollectionPage/mergeCollectionPages.js +13 -32
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +17 -87
- package/package.json +1 -1
|
@@ -15,6 +15,8 @@ var _GroupAction = _interopRequireDefault(require("./GroupAction"));
|
|
|
15
15
|
|
|
16
16
|
var _SummaryListRow = _interopRequireDefault(require("./SummaryListRow"));
|
|
17
17
|
|
|
18
|
+
var _SummaryListHeadingRow = _interopRequireDefault(require("./SummaryListHeadingRow"));
|
|
19
|
+
|
|
18
20
|
var _SummaryListTitleRow = _interopRequireDefault(require("./SummaryListTitleRow"));
|
|
19
21
|
|
|
20
22
|
require("./SummaryList.scss");
|
|
@@ -67,6 +69,15 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
if (row.type === 'heading') {
|
|
73
|
+
return /*#__PURE__*/_react.default.createElement(_SummaryListHeadingRow.default, {
|
|
74
|
+
key: key,
|
|
75
|
+
title: row.key,
|
|
76
|
+
size: row.size || 's',
|
|
77
|
+
classes: classes
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
70
81
|
if (row.type === 'action') {
|
|
71
82
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
72
83
|
key: "".concat(key, "-actions")
|
|
@@ -14,6 +14,25 @@
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
.govuk-summary-list__heading {
|
|
18
|
+
width: 100%;
|
|
19
|
+
white-space: nowrap;
|
|
20
|
+
.govuk-heading-s {
|
|
21
|
+
margin-bottom: 10px;
|
|
22
|
+
}
|
|
23
|
+
.govuk-heading-m {
|
|
24
|
+
margin-bottom: 10px;
|
|
25
|
+
}
|
|
26
|
+
&:not(:first-child) {
|
|
27
|
+
.govuk-heading-s {
|
|
28
|
+
margin-top: 20px;
|
|
29
|
+
}
|
|
30
|
+
.govuk-heading-m {
|
|
31
|
+
margin-top: 30px;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
17
36
|
.changeRow {
|
|
18
37
|
.govuk-link {
|
|
19
38
|
float: right;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
// Global imports
|
|
17
|
+
var SummaryListHeadingRow = function SummaryListHeadingRow(_ref) {
|
|
18
|
+
var title = _ref.title,
|
|
19
|
+
size = _ref.size,
|
|
20
|
+
classes = _ref.classes;
|
|
21
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
22
|
+
className: "".concat(classes('heading'))
|
|
23
|
+
}, size === 's' && /*#__PURE__*/_react.default.createElement(_copReactComponents.SmallHeading, null, title), size === 'm' && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, title));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
SummaryListHeadingRow.propTypes = {
|
|
27
|
+
title: _propTypes.default.string.isRequired,
|
|
28
|
+
classes: _propTypes.default.func.isRequired
|
|
29
|
+
};
|
|
30
|
+
var _default = SummaryListHeadingRow;
|
|
31
|
+
exports.default = _default;
|
|
@@ -9,12 +9,16 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
9
9
|
|
|
10
10
|
var _models = require("../../models");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _addShowWhen = _interopRequireDefault(require("../Component/addShowWhen"));
|
|
13
|
+
|
|
14
|
+
var _showFormPageCYA = _interopRequireDefault(require("../FormPage/showFormPageCYA"));
|
|
13
15
|
|
|
14
16
|
var _getCYACollectionDeleteAction = _interopRequireDefault(require("./getCYACollectionDeleteAction"));
|
|
15
17
|
|
|
16
18
|
var _getCYACollectionChangeAction = _interopRequireDefault(require("./getCYACollectionChangeAction"));
|
|
17
19
|
|
|
20
|
+
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
21
|
+
|
|
18
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
23
|
|
|
20
24
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -30,7 +34,14 @@ var getContainerForPage = function getContainerForPage(page, item, labelCount, f
|
|
|
30
34
|
type: _models.ComponentTypes.CONTAINER,
|
|
31
35
|
required: true,
|
|
32
36
|
full_path: full_path,
|
|
33
|
-
components: page.components
|
|
37
|
+
components: page.components.map(function (component) {
|
|
38
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
39
|
+
label: _copReactComponents.Utils.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
|
|
40
|
+
index: labelCount
|
|
41
|
+
})),
|
|
42
|
+
full_path: "".concat(full_path, ".").concat(component.fieldId)
|
|
43
|
+
});
|
|
44
|
+
})
|
|
34
45
|
};
|
|
35
46
|
};
|
|
36
47
|
|
|
@@ -44,7 +55,23 @@ var getTitleRowForItem = function getTitleRowForItem(page, item, pageId, labelCo
|
|
|
44
55
|
key: _copReactComponents.Utils.interpolateString(labels.item, _objectSpread(_objectSpread({}, item), {}, {
|
|
45
56
|
index: labelCount
|
|
46
57
|
})),
|
|
47
|
-
type: '
|
|
58
|
+
type: 'heading',
|
|
59
|
+
size: page.collection.titleSize || 's'
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var getHeadingRow = function getHeadingRow(config, pageId, labelCount) {
|
|
64
|
+
if (config.text === '') {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
pageId: pageId,
|
|
70
|
+
fieldId: "heading".concat(labelCount),
|
|
71
|
+
full_path: "heading".concat(labelCount),
|
|
72
|
+
key: config.text,
|
|
73
|
+
type: 'heading',
|
|
74
|
+
size: config.size || 's'
|
|
48
75
|
};
|
|
49
76
|
};
|
|
50
77
|
|
|
@@ -69,16 +96,42 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
|
|
|
69
96
|
var _page$formData, _page$formData$page$c;
|
|
70
97
|
|
|
71
98
|
var rows = [];
|
|
99
|
+
|
|
100
|
+
if (!page.collection.hideNameFromCYA) {
|
|
101
|
+
rows.push({
|
|
102
|
+
pageId: page.id,
|
|
103
|
+
fieldId: "".concat(page.collection.name, "Title"),
|
|
104
|
+
full_path: "".concat(page.collection.name, "Title"),
|
|
105
|
+
key: page.collection.name.charAt(0).toUpperCase() + page.collection.name.slice(1),
|
|
106
|
+
type: 'heading',
|
|
107
|
+
size: 'm'
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
72
111
|
(_page$formData = page.formData) === null || _page$formData === void 0 ? void 0 : (_page$formData$page$c = _page$formData[page.collection.name]) === null || _page$formData$page$c === void 0 ? void 0 : _page$formData$page$c.forEach(function (item, index) {
|
|
73
112
|
var labelCount = index + 1;
|
|
74
113
|
var full_path = "".concat(page.collection.name, "[").concat(index, "]");
|
|
75
|
-
var container = getContainerForPage(page, item, labelCount, full_path);
|
|
76
|
-
var containerRows = (0, _getCYARowsForContainer.default)(page, container, item, undefined);
|
|
77
114
|
var titleRow = getTitleRowForItem(page, item, page.id, labelCount, full_path);
|
|
78
115
|
var actionRows = getActionRows(page, item, onAction, labelCount);
|
|
79
116
|
rows = rows.concat(titleRow);
|
|
80
117
|
rows = rows.concat(actionRows);
|
|
81
|
-
|
|
118
|
+
page.collectionPages.forEach(function (p) {
|
|
119
|
+
if (p.collection.route) {
|
|
120
|
+
var pageWithRoute = (0, _addShowWhen.default)(p, p.collection.route);
|
|
121
|
+
p = pageWithRoute || p;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if ((0, _showFormPageCYA.default)(p, _objectSpread(_objectSpread({}, p.formData), item))) {
|
|
125
|
+
if (p.collection.heading) {
|
|
126
|
+
var headingRow = getHeadingRow(p.collection.heading, p.id, labelCount);
|
|
127
|
+
rows = rows.concat(headingRow);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
var container = getContainerForPage(p, item, labelCount, full_path);
|
|
131
|
+
var containerRows = (0, _getCYARowsForContainer.default)(p, container, item, undefined);
|
|
132
|
+
rows = rows.concat(containerRows);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
82
135
|
});
|
|
83
136
|
return rows.filter(function (row) {
|
|
84
137
|
return !!row;
|
|
@@ -17,6 +17,25 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
17
17
|
label: 'Test text',
|
|
18
18
|
type: 'text'
|
|
19
19
|
};
|
|
20
|
+
var DATE_COMP = {
|
|
21
|
+
id: 'testDate',
|
|
22
|
+
fieldId: 'testDate',
|
|
23
|
+
label: 'Test date',
|
|
24
|
+
type: 'date'
|
|
25
|
+
};
|
|
26
|
+
var PAGES = [{
|
|
27
|
+
id: 'page1',
|
|
28
|
+
collection: {
|
|
29
|
+
name: 'collection'
|
|
30
|
+
},
|
|
31
|
+
components: [TEXT_COMP]
|
|
32
|
+
}, {
|
|
33
|
+
id: 'page2',
|
|
34
|
+
collection: {
|
|
35
|
+
name: 'collection'
|
|
36
|
+
},
|
|
37
|
+
components: [DATE_COMP]
|
|
38
|
+
}];
|
|
20
39
|
var MASTER_PAGE = {
|
|
21
40
|
id: 'page1',
|
|
22
41
|
collection: {
|
|
@@ -36,16 +55,29 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
36
55
|
page: 'confirmDelete'
|
|
37
56
|
}]
|
|
38
57
|
},
|
|
39
|
-
|
|
40
|
-
components: [TEXT_COMP]
|
|
58
|
+
collectionPages: PAGES
|
|
41
59
|
};
|
|
42
|
-
it('should return
|
|
60
|
+
it('should return just a heading for the collection if it has no entries', function () {
|
|
43
61
|
var FORM_DATA = {};
|
|
44
62
|
|
|
45
63
|
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
46
64
|
formData: FORM_DATA
|
|
47
65
|
});
|
|
48
66
|
|
|
67
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
68
|
+
expect(ROWS.length).toEqual(1);
|
|
69
|
+
expect(ROWS[0].key).toEqual('Collection');
|
|
70
|
+
});
|
|
71
|
+
it('should accept the hideNameFromCYA collection flag', function () {
|
|
72
|
+
var FORM_DATA = {};
|
|
73
|
+
|
|
74
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
75
|
+
formData: FORM_DATA,
|
|
76
|
+
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
77
|
+
hideNameFromCYA: true
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
|
|
49
81
|
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
50
82
|
expect(ROWS.length).toEqual(0);
|
|
51
83
|
});
|
|
@@ -62,9 +94,9 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
62
94
|
});
|
|
63
95
|
|
|
64
96
|
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
65
|
-
expect(ROWS.length).toEqual(
|
|
97
|
+
expect(ROWS.length).toEqual(7); // Collection title, item title, action rows & component rows
|
|
66
98
|
|
|
67
|
-
expect(ROWS[
|
|
99
|
+
expect(ROWS[1].key).toEqual('Collection entry 1');
|
|
68
100
|
});
|
|
69
101
|
it('should provide default titles if collection.labels.item is not specified', function () {
|
|
70
102
|
var FORM_DATA = {
|
|
@@ -82,9 +114,9 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
82
114
|
});
|
|
83
115
|
|
|
84
116
|
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
85
|
-
expect(ROWS.length).toEqual(
|
|
117
|
+
expect(ROWS.length).toEqual(7); // Collection title, item title, action rows & component rows
|
|
86
118
|
|
|
87
|
-
expect(ROWS[
|
|
119
|
+
expect(ROWS[1].key).toEqual('Item 1');
|
|
88
120
|
});
|
|
89
121
|
it('should return correctly formatted rows for mutliple entries', function () {
|
|
90
122
|
var FORM_DATA = {
|
|
@@ -102,24 +134,42 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
102
134
|
});
|
|
103
135
|
|
|
104
136
|
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
105
|
-
expect(ROWS.length).toEqual(
|
|
106
|
-
|
|
107
|
-
expect(ROWS[0]
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
expect(ROWS[
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
expect(ROWS[
|
|
116
|
-
expect(ROWS[
|
|
117
|
-
|
|
118
|
-
expect(ROWS[
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
expect(ROWS[
|
|
137
|
+
expect(ROWS.length).toEqual(13); // Title row + component row for each item
|
|
138
|
+
|
|
139
|
+
expect(ROWS[0]).toMatchObject({
|
|
140
|
+
type: 'heading',
|
|
141
|
+
key: 'Collection'
|
|
142
|
+
});
|
|
143
|
+
expect(ROWS[1]).toMatchObject({
|
|
144
|
+
type: 'heading',
|
|
145
|
+
key: 'Collection entry 1'
|
|
146
|
+
});
|
|
147
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
148
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
149
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
150
|
+
expect(ROWS[5]).toMatchObject({
|
|
151
|
+
value: 'value',
|
|
152
|
+
key: 'Test text'
|
|
153
|
+
});
|
|
154
|
+
expect(ROWS[6]).toMatchObject({
|
|
155
|
+
value: '',
|
|
156
|
+
key: 'Test date'
|
|
157
|
+
});
|
|
158
|
+
expect(ROWS[7]).toMatchObject({
|
|
159
|
+
type: 'heading',
|
|
160
|
+
key: 'Collection entry 2'
|
|
161
|
+
});
|
|
162
|
+
expect(ROWS[8].action.label).toEqual('Change');
|
|
163
|
+
expect(ROWS[9].action.label).toEqual('custom remove label');
|
|
164
|
+
expect(ROWS[10].action.label).toEqual('custom change label');
|
|
165
|
+
expect(ROWS[11]).toMatchObject({
|
|
166
|
+
value: 'value',
|
|
167
|
+
key: 'Test text'
|
|
168
|
+
});
|
|
169
|
+
expect(ROWS[12]).toMatchObject({
|
|
170
|
+
value: '',
|
|
171
|
+
key: 'Test date'
|
|
172
|
+
});
|
|
123
173
|
});
|
|
124
174
|
it('should exclude components that should not be shown', function () {
|
|
125
175
|
var FD = {
|
|
@@ -133,38 +183,152 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
133
183
|
testText: 'testing'
|
|
134
184
|
}]
|
|
135
185
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
186
|
+
|
|
187
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
188
|
+
collection: {
|
|
189
|
+
name: 'collection'
|
|
190
|
+
},
|
|
191
|
+
formData: FD,
|
|
192
|
+
collectionPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
193
|
+
components: [{
|
|
194
|
+
id: 'testText',
|
|
195
|
+
fieldId: 'testText',
|
|
196
|
+
label: 'Test text',
|
|
197
|
+
type: 'text',
|
|
198
|
+
show_when: {
|
|
199
|
+
field: "otherField",
|
|
200
|
+
op: "!=",
|
|
201
|
+
value: "yes"
|
|
202
|
+
}
|
|
203
|
+
}]
|
|
204
|
+
})]
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
208
|
+
expect(ROWS.length).toEqual(4);
|
|
209
|
+
expect(ROWS[0]).toMatchObject({
|
|
210
|
+
type: 'heading',
|
|
211
|
+
key: 'Collection'
|
|
212
|
+
});
|
|
213
|
+
expect(ROWS[1]).toMatchObject({
|
|
214
|
+
type: 'heading',
|
|
215
|
+
key: 'Item 1'
|
|
216
|
+
});
|
|
217
|
+
expect(ROWS[2]).toMatchObject({
|
|
218
|
+
type: 'heading',
|
|
219
|
+
key: 'Item 2'
|
|
220
|
+
});
|
|
221
|
+
expect(ROWS[3]).toMatchObject({
|
|
222
|
+
value: 'testing',
|
|
223
|
+
key: 'Test text'
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
it('should exclude pages that should not be shown', function () {
|
|
227
|
+
var FD = {
|
|
228
|
+
collection: [{
|
|
229
|
+
id: '01',
|
|
230
|
+
otherField: 'yes',
|
|
231
|
+
testText: 'testing'
|
|
232
|
+
}]
|
|
146
233
|
};
|
|
147
|
-
|
|
148
|
-
|
|
234
|
+
|
|
235
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
149
236
|
collection: {
|
|
150
237
|
name: 'collection'
|
|
151
238
|
},
|
|
152
|
-
|
|
153
|
-
|
|
239
|
+
formData: FD,
|
|
240
|
+
collectionPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
241
|
+
show_when: {
|
|
242
|
+
field: "otherField",
|
|
243
|
+
op: "!=",
|
|
244
|
+
value: "yes"
|
|
245
|
+
}
|
|
246
|
+
}), PAGES[1]]
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
250
|
+
expect(ROWS.length).toEqual(3); // Missing the page with the text component on.
|
|
251
|
+
|
|
252
|
+
expect(ROWS[0]).toMatchObject({
|
|
253
|
+
type: 'heading',
|
|
254
|
+
key: 'Collection'
|
|
255
|
+
});
|
|
256
|
+
expect(ROWS[1]).toMatchObject({
|
|
257
|
+
type: 'heading',
|
|
258
|
+
key: 'Item 1'
|
|
259
|
+
});
|
|
260
|
+
expect(ROWS[2]).toMatchObject({
|
|
261
|
+
value: '',
|
|
262
|
+
key: 'Test date'
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
it('should include rows for custom headings', function () {
|
|
266
|
+
var FORM_DATA = {
|
|
267
|
+
collection: [{
|
|
268
|
+
id: '01',
|
|
269
|
+
testText: 'value'
|
|
270
|
+
}]
|
|
154
271
|
};
|
|
155
272
|
|
|
156
|
-
var PAGE = _objectSpread(_objectSpread({},
|
|
157
|
-
formData:
|
|
273
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
274
|
+
formData: FORM_DATA,
|
|
275
|
+
collectionPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
276
|
+
collection: _objectSpread(_objectSpread({}, PAGES[0].collection), {}, {
|
|
277
|
+
heading: {
|
|
278
|
+
size: 'm',
|
|
279
|
+
text: 'Custom page heading'
|
|
280
|
+
}
|
|
281
|
+
})
|
|
282
|
+
})]
|
|
158
283
|
});
|
|
159
284
|
|
|
160
285
|
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
161
|
-
expect(ROWS.length).toEqual(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
expect(ROWS[1]
|
|
167
|
-
|
|
168
|
-
|
|
286
|
+
expect(ROWS.length).toEqual(7);
|
|
287
|
+
expect(ROWS[0]).toMatchObject({
|
|
288
|
+
type: 'heading',
|
|
289
|
+
key: 'Collection'
|
|
290
|
+
});
|
|
291
|
+
expect(ROWS[1]).toMatchObject({
|
|
292
|
+
type: 'heading',
|
|
293
|
+
key: 'Collection entry 1'
|
|
294
|
+
});
|
|
295
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
296
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
297
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
298
|
+
expect(ROWS[5]).toMatchObject({
|
|
299
|
+
type: 'heading',
|
|
300
|
+
key: 'Custom page heading',
|
|
301
|
+
size: 'm'
|
|
302
|
+
});
|
|
303
|
+
expect(ROWS[6]).toMatchObject({
|
|
304
|
+
value: 'value',
|
|
305
|
+
key: 'Test text'
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
it('should default to a title size of small if one is not specified', function () {
|
|
309
|
+
var FORM_DATA = {
|
|
310
|
+
collection: [{
|
|
311
|
+
id: '01',
|
|
312
|
+
testText: 'value'
|
|
313
|
+
}]
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
317
|
+
formData: FORM_DATA,
|
|
318
|
+
collectionPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
319
|
+
collection: _objectSpread(_objectSpread({}, PAGES[0].collection), {}, {
|
|
320
|
+
heading: {
|
|
321
|
+
text: 'Custom page heading'
|
|
322
|
+
}
|
|
323
|
+
})
|
|
324
|
+
})]
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
|
|
328
|
+
expect(ROWS[5]).toMatchObject({
|
|
329
|
+
type: 'heading',
|
|
330
|
+
key: 'Custom page heading',
|
|
331
|
+
size: 's'
|
|
332
|
+
});
|
|
169
333
|
});
|
|
170
334
|
});
|
|
@@ -5,53 +5,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _addShowWhen = _interopRequireDefault(require("../Component/addShowWhen"));
|
|
9
|
-
|
|
10
|
-
var _applyToComponentTree = _interopRequireDefault(require("../Component/applyToComponentTree"));
|
|
11
|
-
|
|
12
|
-
var _showFormPageCYA = _interopRequireDefault(require("../FormPage/showFormPageCYA"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
9
|
|
|
18
10
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
11
|
|
|
20
12
|
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
13
|
|
|
22
|
-
var getComponentsWithRouting = function getComponentsWithRouting(page) {
|
|
23
|
-
if (!page.collection.route) {
|
|
24
|
-
return page.components;
|
|
25
|
-
} // Apply show_whens to components on certain conditional pages.
|
|
26
|
-
// This ensures that those components aren't shown on the CYA
|
|
27
|
-
// screen if they were never visited by the user.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return page.components.map(function (component) {
|
|
31
|
-
return (0, _applyToComponentTree.default)(component, function (c) {
|
|
32
|
-
return (0, _addShowWhen.default)(c, page.collection.route);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
14
|
var createMasterPage = function createMasterPage(page) {
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
return {
|
|
16
|
+
id: page.id,
|
|
17
|
+
collection: _objectSpread({
|
|
18
|
+
masterPage: true
|
|
19
|
+
}, page.collection),
|
|
20
|
+
formData: _objectSpread({}, page.formData),
|
|
21
|
+
collectionPages: [page]
|
|
22
|
+
};
|
|
42
23
|
};
|
|
43
24
|
|
|
44
25
|
var mergeIntoMasterPage = function mergeIntoMasterPage(page, masterPage) {
|
|
45
26
|
masterPage.collection = _objectSpread(_objectSpread({}, masterPage.collection), page.collection);
|
|
46
|
-
masterPage.
|
|
47
|
-
masterPage.
|
|
27
|
+
masterPage.formData = _objectSpread(_objectSpread({}, masterPage.formData), page.formData);
|
|
28
|
+
masterPage.collectionPages = [].concat(masterPage.collectionPages, [page]);
|
|
48
29
|
};
|
|
49
30
|
/**
|
|
50
31
|
* Loop over an array of pages, merging any CollectionPages into a
|
|
51
32
|
* single master page for that collection. A master page is created
|
|
52
33
|
* for each unique collection.name that exists.
|
|
53
|
-
* These master pages contain all the
|
|
54
|
-
*
|
|
34
|
+
* These master pages contain all the pages that are needed to
|
|
35
|
+
* represent an item in that collection.
|
|
55
36
|
* The master page for each collection is positioned at the index
|
|
56
37
|
* of the first CollectionPage in that collection.
|
|
57
38
|
* @param { array } pages Array of pages in the form.
|
|
@@ -64,7 +45,7 @@ var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
|
64
45
|
return pages.map(function (page) {
|
|
65
46
|
var _page$collection;
|
|
66
47
|
|
|
67
|
-
if (page !== null && page !== void 0 && (_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name
|
|
48
|
+
if (page !== null && page !== void 0 && (_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name) {
|
|
68
49
|
if (!masterPages[page.collection.name]) {
|
|
69
50
|
// If no master page exists for this collection.name, then
|
|
70
51
|
// we kick one off using this page as a template.
|
|
@@ -40,14 +40,14 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
40
40
|
}];
|
|
41
41
|
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
42
42
|
expect(RESULT.length).toEqual(1);
|
|
43
|
-
expect(RESULT[0]).
|
|
43
|
+
expect(RESULT[0]).toMatchObject({
|
|
44
44
|
id: 'page1',
|
|
45
|
-
title: 'Collection',
|
|
46
45
|
collection: {
|
|
47
|
-
name: 'collection'
|
|
46
|
+
name: 'collection',
|
|
47
|
+
masterPage: true
|
|
48
48
|
},
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
formData: {},
|
|
50
|
+
collectionPages: PAGES
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
53
|
it('should leave non-collection pages unaffected', function () {
|
|
@@ -70,12 +70,12 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
70
70
|
expect(RESULT.length).toEqual(2);
|
|
71
71
|
expect(RESULT[0]).toEqual({
|
|
72
72
|
id: 'page1',
|
|
73
|
-
title: 'Collection',
|
|
74
73
|
collection: {
|
|
75
|
-
name: 'collection'
|
|
74
|
+
name: 'collection',
|
|
75
|
+
masterPage: true
|
|
76
76
|
},
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
formData: {},
|
|
78
|
+
collectionPages: [PAGES[0], PAGES[1]]
|
|
79
79
|
});
|
|
80
80
|
expect(RESULT[1]).toEqual({
|
|
81
81
|
id: 'page3'
|
|
@@ -112,90 +112,20 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
112
112
|
expect(RESULT[0]).toEqual({
|
|
113
113
|
id: 'page1',
|
|
114
114
|
collection: {
|
|
115
|
-
name: 'collection1'
|
|
115
|
+
name: 'collection1',
|
|
116
|
+
masterPage: true
|
|
116
117
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
formData: {}
|
|
118
|
+
formData: {},
|
|
119
|
+
collectionPages: [PAGES[0], PAGES[1]]
|
|
120
120
|
});
|
|
121
121
|
expect(RESULT[1]).toEqual({
|
|
122
122
|
id: 'page3',
|
|
123
123
|
collection: {
|
|
124
|
-
name: 'collection2'
|
|
125
|
-
|
|
126
|
-
title: 'Collection2',
|
|
127
|
-
components: [],
|
|
128
|
-
formData: {}
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
it('should add a defined route as a show_when to components on the page', function () {
|
|
132
|
-
var PAGES = [{
|
|
133
|
-
id: 'page1',
|
|
134
|
-
collection: {
|
|
135
|
-
name: 'collection',
|
|
136
|
-
route: {
|
|
137
|
-
field: 'field',
|
|
138
|
-
op: '=',
|
|
139
|
-
value: 'value'
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
components: [{
|
|
143
|
-
type: 'text'
|
|
144
|
-
}]
|
|
145
|
-
}, {
|
|
146
|
-
id: 'page2',
|
|
147
|
-
collection: {
|
|
148
|
-
name: 'collection',
|
|
149
|
-
route: {
|
|
150
|
-
field: 'field',
|
|
151
|
-
op: '=',
|
|
152
|
-
value: 'otherValue'
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
components: [{
|
|
156
|
-
type: 'container',
|
|
157
|
-
components: [{
|
|
158
|
-
type: 'date'
|
|
159
|
-
}]
|
|
160
|
-
}]
|
|
161
|
-
}];
|
|
162
|
-
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
163
|
-
expect(RESULT.length).toEqual(1);
|
|
164
|
-
expect(RESULT[0]).toEqual({
|
|
165
|
-
id: 'page1',
|
|
166
|
-
title: 'Collection',
|
|
167
|
-
collection: {
|
|
168
|
-
name: 'collection',
|
|
169
|
-
route: {
|
|
170
|
-
field: 'field',
|
|
171
|
-
op: '=',
|
|
172
|
-
value: 'otherValue'
|
|
173
|
-
}
|
|
124
|
+
name: 'collection2',
|
|
125
|
+
masterPage: true
|
|
174
126
|
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
show_when: {
|
|
178
|
-
field: 'field',
|
|
179
|
-
op: '=',
|
|
180
|
-
value: 'value'
|
|
181
|
-
}
|
|
182
|
-
}, {
|
|
183
|
-
type: 'container',
|
|
184
|
-
components: [{
|
|
185
|
-
type: 'date',
|
|
186
|
-
show_when: {
|
|
187
|
-
field: 'field',
|
|
188
|
-
op: '=',
|
|
189
|
-
value: 'otherValue'
|
|
190
|
-
}
|
|
191
|
-
}],
|
|
192
|
-
show_when: {
|
|
193
|
-
field: 'field',
|
|
194
|
-
op: '=',
|
|
195
|
-
value: 'otherValue'
|
|
196
|
-
}
|
|
197
|
-
}],
|
|
198
|
-
formData: {}
|
|
127
|
+
formData: {},
|
|
128
|
+
collectionPages: [PAGES[2], PAGES[3]]
|
|
199
129
|
});
|
|
200
130
|
});
|
|
201
131
|
});
|