@ukhomeoffice/cop-react-form-renderer 6.0.4-peter → 6.0.6-peter
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/CollectionPage/CollectionPage.js +2 -2
- package/dist/components/CollectionSummary/CollectionSummary.js +51 -6
- package/dist/components/CollectionSummary/CollectionSummary.test.js +30 -0
- package/dist/components/CollectionSummary/Confirmation.scss +12 -0
- package/dist/components/CollectionSummary/RenderListView.js +3 -21
- package/dist/components/CollectionSummary/RenderListView.scss +7 -0
- package/dist/components/CollectionSummary/RenderListView.test.js +20 -8
- package/dist/components/CollectionSummary/SummaryCard.scss +4 -6
- package/dist/components/CollectionSummary/SummaryCardDetails.js +5 -10
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +27 -17
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +2 -2
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +58 -36
- package/dist/utils/CheckYourAnswers/getComponentRowForCYA.js +37 -0
- package/dist/utils/CheckYourAnswers/getComponentRowForCYA.test.js +41 -0
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +4 -2
- package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +20 -0
- package/dist/utils/Condition/meetsAllConditions.js +5 -1
- package/dist/utils/Condition/meetsAllConditions.test.js +13 -0
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Global
|
|
|
29
29
|
// Styles
|
|
30
30
|
var DEFAULT_CLASS = exports.DEFAULT_CLASS = _FormPage2.DEFAULT_CLASS;
|
|
31
31
|
var CollectionPage = function CollectionPage(_ref) {
|
|
32
|
-
var _page$collection;
|
|
32
|
+
var _page$collection, _objectSpread4;
|
|
33
33
|
var page = _ref.page,
|
|
34
34
|
onCollectionChange = _ref.onCollectionChange,
|
|
35
35
|
onAction = _ref.onAction,
|
|
@@ -120,7 +120,7 @@ var CollectionPage = function CollectionPage(_ref) {
|
|
|
120
120
|
}
|
|
121
121
|
return /*#__PURE__*/_react.default.createElement(_FormPage.default, {
|
|
122
122
|
page: _objectSpread(_objectSpread({}, page), {}, {
|
|
123
|
-
formData: _objectSpread(_objectSpread(_objectSpread({}, page.formData), data[activeIndex]), {},
|
|
123
|
+
formData: _objectSpread(_objectSpread(_objectSpread({}, page.formData), data[activeIndex]), {}, (_objectSpread4 = {}, _defineProperty(_objectSpread4, "".concat(currentCollectionName, "ActiveIndex"), activeIndex), _defineProperty(_objectSpread4, "".concat(currentCollectionName, "NumberedIndex"), typeof activeIndex === 'number' ? activeIndex + 1 : null), _objectSpread4)),
|
|
124
124
|
components: page.components.map(function (component) {
|
|
125
125
|
return _objectSpread(_objectSpread({}, component), {}, {
|
|
126
126
|
pageCollection: _objectSpread({}, page.collection)
|
|
@@ -7,10 +7,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.DEFAULT_ADD_BUTTON_LABEL = void 0;
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _hooks = require("../../hooks");
|
|
10
11
|
var _PageAction = require("../../models/PageAction");
|
|
11
12
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
|
+
var _getCYARow = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARow"));
|
|
14
|
+
var _elevateNestedComponents = _interopRequireDefault(require("../../utils/Component/elevateNestedComponents"));
|
|
15
|
+
var _Answer = _interopRequireDefault(require("../CheckYourAnswers/Answer"));
|
|
12
16
|
var _ActionButton = _interopRequireDefault(require("../PageActions/ActionButton"));
|
|
13
|
-
var _hooks = require("../../hooks");
|
|
14
17
|
var _Confirmation = _interopRequireDefault(require("./Confirmation"));
|
|
15
18
|
var _SummaryCard = _interopRequireDefault(require("./SummaryCard"));
|
|
16
19
|
var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
|
|
@@ -46,7 +49,7 @@ var DEFAULT_ADD_BUTTON_LABEL = exports.DEFAULT_ADD_BUTTON_LABEL = 'Add';
|
|
|
46
49
|
// errors local to the Quick Edit page.
|
|
47
50
|
|
|
48
51
|
var CollectionSummary = function CollectionSummary(_ref) {
|
|
49
|
-
var _config$confirmation, _config$confirmation2;
|
|
52
|
+
var _config$confirmation, _config$confirmation2, _config$confirmation3;
|
|
50
53
|
var config = _ref.config,
|
|
51
54
|
formData = _ref.formData,
|
|
52
55
|
onAction = _ref.onAction,
|
|
@@ -83,6 +86,17 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
83
86
|
return currentPath;
|
|
84
87
|
}, "");
|
|
85
88
|
}, [pages]);
|
|
89
|
+
var allComponents = (0, _react.useMemo)(function () {
|
|
90
|
+
if (config.card.listView) {
|
|
91
|
+
var _masterPage$childPage;
|
|
92
|
+
var components = (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.reduce(function (acc, page) {
|
|
93
|
+
var elevatedComponents = (0, _elevateNestedComponents.default)(page.components, _objectSpread(_objectSpread({}, formData), entryToDelete));
|
|
94
|
+
return acc.concat(elevatedComponents);
|
|
95
|
+
}, []);
|
|
96
|
+
return components || [];
|
|
97
|
+
}
|
|
98
|
+
return [];
|
|
99
|
+
}, [masterPage, formData, entryToDelete, config.card.listView]);
|
|
86
100
|
var validateEntries = function validateEntries() {
|
|
87
101
|
var stored = [];
|
|
88
102
|
// We only clear errors if it's not empty to avoid
|
|
@@ -181,6 +195,23 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
181
195
|
setEntryToDelete(null);
|
|
182
196
|
validateEntries();
|
|
183
197
|
};
|
|
198
|
+
var renderFieldValue = function renderFieldValue(field) {
|
|
199
|
+
var component = allComponents.find(function (c) {
|
|
200
|
+
return c.fieldId === field;
|
|
201
|
+
});
|
|
202
|
+
if (!component) return null;
|
|
203
|
+
var row = (0, _getCYARow.default)(_objectSpread(_objectSpread({}, masterPage), {}, {
|
|
204
|
+
formData: _objectSpread(_objectSpread({}, formData), entryToDelete)
|
|
205
|
+
}), component);
|
|
206
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
207
|
+
key: field,
|
|
208
|
+
className: "confirmation-field-value"
|
|
209
|
+
}, /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
210
|
+
value: row.value,
|
|
211
|
+
component: row.component,
|
|
212
|
+
formData: row.formData
|
|
213
|
+
}));
|
|
214
|
+
};
|
|
184
215
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
185
216
|
id: config.fieldId
|
|
186
217
|
}, entryToDelete && /*#__PURE__*/_react.default.createElement(_Confirmation.default, {
|
|
@@ -191,7 +222,9 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
191
222
|
onCancel: function onCancel() {
|
|
192
223
|
return setEntryToDelete(null);
|
|
193
224
|
}
|
|
194
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
225
|
+
}, config.card.listView ? /*#__PURE__*/_react.default.createElement("div", {
|
|
226
|
+
className: "confirmation-content"
|
|
227
|
+
}, (_config$confirmation3 = config.confirmation) === null || _config$confirmation3 === void 0 ? void 0 : _config$confirmation3.displayFields.map(renderFieldValue)) : /*#__PURE__*/_react.default.createElement(_SummaryCard.default, {
|
|
195
228
|
id: "".concat(config.fieldId, ".confirmationChild"),
|
|
196
229
|
entryData: entryToDelete,
|
|
197
230
|
config: config.card ? _objectSpread(_objectSpread({}, config.card), {}, {
|
|
@@ -200,7 +233,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
200
233
|
masterPage: masterPage,
|
|
201
234
|
classModifiers: "nested",
|
|
202
235
|
hideDetails: true
|
|
203
|
-
})), config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
236
|
+
})), !config.card.listView && config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
204
237
|
id: "".concat(config.fieldId, ".addButton"),
|
|
205
238
|
action: {
|
|
206
239
|
collection: config.collectionName,
|
|
@@ -244,6 +277,16 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
244
277
|
return e.entryId === entry.id;
|
|
245
278
|
}).length > 0
|
|
246
279
|
}));
|
|
280
|
+
}), config.card.listView && config.addButton && /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
|
|
281
|
+
id: "".concat(config.fieldId, ".addButton"),
|
|
282
|
+
action: {
|
|
283
|
+
collection: config.collectionName,
|
|
284
|
+
label: config.addButton.label || DEFAULT_ADD_BUTTON_LABEL,
|
|
285
|
+
page: config.addButton.page,
|
|
286
|
+
type: _PageAction.PageActionTypes.COLLECTION_ADD,
|
|
287
|
+
classModifiers: ['secondary']
|
|
288
|
+
},
|
|
289
|
+
onAction: onAction
|
|
247
290
|
}));
|
|
248
291
|
};
|
|
249
292
|
CollectionSummary.propTypes = {
|
|
@@ -261,7 +304,8 @@ CollectionSummary.propTypes = {
|
|
|
261
304
|
details: _propTypes.default.string,
|
|
262
305
|
duplicateAction: _propTypes.default.shape({
|
|
263
306
|
fieldsToIgnore: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
264
|
-
})
|
|
307
|
+
}),
|
|
308
|
+
listView: _propTypes.default.bool
|
|
265
309
|
}),
|
|
266
310
|
errorCard: _propTypes.default.shape({
|
|
267
311
|
banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
|
|
@@ -273,7 +317,8 @@ CollectionSummary.propTypes = {
|
|
|
273
317
|
}),
|
|
274
318
|
confirmation: _propTypes.default.shape({
|
|
275
319
|
message: _propTypes.default.string,
|
|
276
|
-
label: _propTypes.default.string
|
|
320
|
+
label: _propTypes.default.string,
|
|
321
|
+
displayFields: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
277
322
|
}),
|
|
278
323
|
childCollections: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
279
324
|
}).isRequired,
|
|
@@ -283,5 +283,35 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
283
283
|
var roleAttribute = confirmation.getAttribute('role');
|
|
284
284
|
expect(roleAttribute).toEqual('alert');
|
|
285
285
|
});
|
|
286
|
+
it('should correctly render field values in confirmation view', function () {
|
|
287
|
+
var listViewConfig = _objectSpread(_objectSpread({}, CONFIG), {}, {
|
|
288
|
+
card: _objectSpread(_objectSpread({}, CONFIG.card), {}, {
|
|
289
|
+
listView: true
|
|
290
|
+
}),
|
|
291
|
+
confirmation: {
|
|
292
|
+
displayFields: ['testText']
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
296
|
+
config: listViewConfig,
|
|
297
|
+
formData: FORM_DATA,
|
|
298
|
+
onAction: ON_ACTION,
|
|
299
|
+
pages: PAGES
|
|
300
|
+
})),
|
|
301
|
+
container = _renderWithValidation9.container,
|
|
302
|
+
getByText = _renderWithValidation9.getByText;
|
|
303
|
+
var summary = checkSetup(container);
|
|
304
|
+
expect(summary.children.length).toEqual(2);
|
|
305
|
+
var card = summary.children[0];
|
|
306
|
+
var deleteButton = card.querySelector('.govuk-summary-card__actions li:last-child button');
|
|
307
|
+
_react2.fireEvent.click(deleteButton);
|
|
308
|
+
var confirmation = container.querySelector(".".concat(_Confirmation.DEFAULT_CLASS));
|
|
309
|
+
expect(confirmation).toBeTruthy();
|
|
310
|
+
listViewConfig.confirmation.displayFields.forEach(function (field) {
|
|
311
|
+
var fieldValue = FORM_DATA.testCollection[0][field];
|
|
312
|
+
var fieldElement = getByText(fieldValue);
|
|
313
|
+
expect(fieldElement).not.toBeNull();
|
|
314
|
+
});
|
|
315
|
+
});
|
|
286
316
|
});
|
|
287
317
|
});
|
|
@@ -11,4 +11,16 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
11
11
|
@extend .hods-button--warning;
|
|
12
12
|
margin-right: govuk-spacing(2);
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
.confirmation-content {
|
|
16
|
+
margin-bottom: govuk-spacing(6);
|
|
17
|
+
|
|
18
|
+
.hods-form-container .govuk-form-group {
|
|
19
|
+
margin-bottom: 0px;
|
|
20
|
+
|
|
21
|
+
label {
|
|
22
|
+
display: none;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
14
26
|
}
|
|
@@ -8,8 +8,7 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
|
-
var
|
|
12
|
-
var _Answer = _interopRequireDefault(require("../CheckYourAnswers/Answer"));
|
|
11
|
+
var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
|
|
13
12
|
require("./RenderListView.scss");
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
14
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
@@ -85,31 +84,14 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
85
84
|
}).flat().filter(Boolean);
|
|
86
85
|
return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 || (_childPage$summaryLay = _childPage$summaryLay.sections) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.flatMap(function (section) {
|
|
87
86
|
if (section.fields) {
|
|
88
|
-
|
|
89
|
-
return Object.prototype.hasOwnProperty.call(entryData, fieldId);
|
|
90
|
-
});
|
|
91
|
-
return fieldsToRender.map(function (fieldId) {
|
|
87
|
+
return section.fields.flatMap(function (fieldId) {
|
|
92
88
|
var component = elevatedComponents.find(function (comp) {
|
|
93
89
|
return comp.fieldId === fieldId;
|
|
94
90
|
});
|
|
95
91
|
if (!component) {
|
|
96
92
|
return null;
|
|
97
93
|
}
|
|
98
|
-
return
|
|
99
|
-
key: fieldId,
|
|
100
|
-
row: {
|
|
101
|
-
key: component.label,
|
|
102
|
-
value: _copReactComponents.Utils.interpolateString(entryData[component.fieldId], entryData) || /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
103
|
-
value: entryData[component.fieldId],
|
|
104
|
-
component: component,
|
|
105
|
-
formData: component.formData
|
|
106
|
-
}),
|
|
107
|
-
required: component.required
|
|
108
|
-
},
|
|
109
|
-
classes: function classes(element) {
|
|
110
|
-
return listClass(element);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
94
|
+
return (0, _getComponentRowForCYA.default)(childPage, component, listClass, entryData);
|
|
113
95
|
});
|
|
114
96
|
}
|
|
115
97
|
return null;
|
|
@@ -83,6 +83,13 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
83
83
|
@include govuk-media-query($until: tablet) {
|
|
84
84
|
margin-bottom: govuk-spacing(3);
|
|
85
85
|
}
|
|
86
|
+
.hods-form-container .govuk-form-group {
|
|
87
|
+
margin-bottom: 0px;
|
|
88
|
+
|
|
89
|
+
label {
|
|
90
|
+
display: none;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
.govuk-summary-list__value > p {
|
|
@@ -16,8 +16,8 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
16
16
|
item1: 'Value 1',
|
|
17
17
|
item2: 'Value 2',
|
|
18
18
|
item3: {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
label: 'Value 3',
|
|
20
|
+
value: 'Value 3'
|
|
21
21
|
},
|
|
22
22
|
index: 0
|
|
23
23
|
};
|
|
@@ -92,6 +92,15 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
92
92
|
beforeEach(function () {
|
|
93
93
|
onDeleteArgs = [];
|
|
94
94
|
});
|
|
95
|
+
var getComponentRow = function getComponentRow() {
|
|
96
|
+
return /*#__PURE__*/_react2.default.createElement("div", {
|
|
97
|
+
className: "govuk-summary-list__row"
|
|
98
|
+
}, /*#__PURE__*/_react2.default.createElement("dt", {
|
|
99
|
+
className: "govuk-summary-list__key"
|
|
100
|
+
}, "Test Key"), /*#__PURE__*/_react2.default.createElement("dd", {
|
|
101
|
+
className: "govuk-summary-list__value"
|
|
102
|
+
}, /*#__PURE__*/_react2.default.createElement("div", null, "Test Value")));
|
|
103
|
+
};
|
|
95
104
|
|
|
96
105
|
// Setup function to check rendered elements
|
|
97
106
|
var checkSetup = function checkSetup(container) {
|
|
@@ -107,7 +116,8 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
107
116
|
config: CONFIG,
|
|
108
117
|
onChange: ON_CHANGE,
|
|
109
118
|
onDelete: ON_DELETE,
|
|
110
|
-
masterPage: MASTER_PAGE
|
|
119
|
+
masterPage: MASTER_PAGE,
|
|
120
|
+
getComponentRow: getComponentRow
|
|
111
121
|
})),
|
|
112
122
|
container = _renderWithValidation.container;
|
|
113
123
|
var listViewDiv = checkSetup(container);
|
|
@@ -126,19 +136,19 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
126
136
|
var firstRowKey = rows[0].querySelector('.govuk-summary-list__key');
|
|
127
137
|
var firstRowValue = rows[0].querySelector('.govuk-summary-list__value');
|
|
128
138
|
expect(firstRowKey.textContent).toEqual('Item 1');
|
|
129
|
-
expect(firstRowValue.textContent).toEqual(
|
|
139
|
+
expect(firstRowValue.textContent).toEqual('Value 1');
|
|
130
140
|
|
|
131
141
|
// Check the second row
|
|
132
142
|
var secondRowKey = rows[1].querySelector('.govuk-summary-list__key');
|
|
133
143
|
var secondRowValue = rows[1].querySelector('.govuk-summary-list__value');
|
|
134
144
|
expect(secondRowKey.textContent).toEqual('Item 2 (optional)');
|
|
135
|
-
expect(secondRowValue.textContent).toEqual(
|
|
145
|
+
expect(secondRowValue.textContent).toEqual('Value 2');
|
|
136
146
|
|
|
137
147
|
// Check the third row
|
|
138
148
|
var thirdRowKey = rows[2].querySelector('.govuk-summary-list__key');
|
|
139
149
|
var thirdRowValue = rows[2].querySelector('.govuk-summary-list__value');
|
|
140
150
|
expect(thirdRowKey.textContent).toEqual('Item 3');
|
|
141
|
-
expect(thirdRowValue.textContent).toEqual('Value
|
|
151
|
+
expect(thirdRowValue.textContent).toEqual('Value 3');
|
|
142
152
|
});
|
|
143
153
|
it('should render the index correctly in the title', function () {
|
|
144
154
|
var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_RenderListView.default, {
|
|
@@ -147,7 +157,8 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
147
157
|
config: CONFIG,
|
|
148
158
|
onChange: ON_CHANGE,
|
|
149
159
|
onDelete: ON_DELETE,
|
|
150
|
-
masterPage: MASTER_PAGE
|
|
160
|
+
masterPage: MASTER_PAGE,
|
|
161
|
+
getComponentRow: getComponentRow
|
|
151
162
|
})),
|
|
152
163
|
container = _renderWithValidation2.container;
|
|
153
164
|
var listViewDiv = checkSetup(container);
|
|
@@ -175,7 +186,8 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
175
186
|
config: CONFIG,
|
|
176
187
|
onChange: ON_CHANGE,
|
|
177
188
|
onDelete: ON_DELETE,
|
|
178
|
-
masterPage: MASTER_PAGE
|
|
189
|
+
masterPage: MASTER_PAGE,
|
|
190
|
+
getComponentRow: getComponentRow
|
|
179
191
|
})),
|
|
180
192
|
container = _renderWithValidation3.container;
|
|
181
193
|
var listViewDiv = container.querySelector('.govuk-summary-card');
|
|
@@ -6,12 +6,6 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
6
6
|
width: 100% !important;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
.govuk-form-group:has(.hods-form-summary-card) {
|
|
10
|
-
.govuk-form-group:last-of-type {
|
|
11
|
-
margin-left: govuk-spacing(3);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
.hods-form-summary-card {
|
|
16
10
|
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
|
|
17
11
|
border: 1px solid #E5E4E2;
|
|
@@ -88,6 +82,10 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
88
82
|
.details.hods-details {
|
|
89
83
|
margin-bottom: 0;
|
|
90
84
|
}
|
|
85
|
+
|
|
86
|
+
.hods-form-container .govuk-form-group label{
|
|
87
|
+
display: none;
|
|
88
|
+
}
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
|
|
@@ -7,7 +7,7 @@ exports.default = exports.DEFAULT_CLASS = void 0;
|
|
|
7
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
10
|
-
var
|
|
10
|
+
var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
|
|
11
11
|
require("./SummaryCardDetails.scss");
|
|
12
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
13
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -81,18 +81,13 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
81
81
|
var component = allPageComponents.find(function (comp) {
|
|
82
82
|
return comp.fieldId === fieldId;
|
|
83
83
|
});
|
|
84
|
+
if (!component) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
84
87
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
85
88
|
key: fieldId,
|
|
86
89
|
className: classes('field')
|
|
87
|
-
},
|
|
88
|
-
component: _objectSpread(_objectSpread({}, component), {}, {
|
|
89
|
-
hint: ''
|
|
90
|
-
}),
|
|
91
|
-
value: entryData[component === null || component === void 0 ? void 0 : component.fieldId],
|
|
92
|
-
formData: entryData,
|
|
93
|
-
wrap: true,
|
|
94
|
-
readonly: true
|
|
95
|
-
}));
|
|
90
|
+
}, (0, _getComponentRowForCYA.default)(childPage, component, classes, entryData));
|
|
96
91
|
})));
|
|
97
92
|
});
|
|
98
93
|
}).filter(function (e) {
|
|
@@ -7,34 +7,44 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
.hods-form-summary-card-details {
|
|
10
|
-
&
|
|
11
|
-
|
|
10
|
+
&__row {
|
|
11
|
+
margin-left: govuk-spacing(5);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
margin: govuk-spacing(2) 0 govuk-spacing(6) 0;
|
|
13
|
+
.hods-button-group{
|
|
14
|
+
display: none;
|
|
16
15
|
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&__key {
|
|
19
|
+
font-weight: bold;
|
|
20
|
+
margin: govuk-spacing(2) 0 govuk-spacing(1) 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&__value {
|
|
24
|
+
margin: 0;
|
|
25
|
+
|
|
26
|
+
.hods-form-container .govuk-form-group {
|
|
27
|
+
margin-bottom: 0px;
|
|
28
|
+
|
|
29
|
+
label {
|
|
30
|
+
display: none;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&__section {
|
|
36
|
+
border-bottom: 2px solid #E9EBED;
|
|
17
37
|
|
|
18
38
|
&-content {
|
|
19
39
|
display: flex;
|
|
20
40
|
flex-wrap: wrap;
|
|
21
41
|
gap: govuk-spacing(2);
|
|
22
42
|
|
|
23
|
-
.hods-form-summary-
|
|
43
|
+
.hods-form-summary-card__field {
|
|
24
44
|
box-sizing: border-box;
|
|
25
45
|
margin-bottom: govuk-spacing(4);
|
|
26
46
|
|
|
27
|
-
.
|
|
28
|
-
.govuk-fieldset__legend {
|
|
29
|
-
font-weight: bold;
|
|
30
|
-
margin-bottom: govuk-spacing(1) !important;
|
|
31
|
-
|
|
32
|
-
&::after {
|
|
33
|
-
content: " :";
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
div.govuk-form-group div:has(img){
|
|
47
|
+
.hods-form-summary-card__row div:has(img){
|
|
38
48
|
display: flex;
|
|
39
49
|
flex-wrap: wrap;
|
|
40
50
|
|
|
@@ -313,7 +313,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
313
313
|
var childSectionTitles = getByTextContent(container, 'Hidden Title');
|
|
314
314
|
expect(childSectionTitles).toBeUndefined(); // Individual section title for child collections should be hidden.
|
|
315
315
|
|
|
316
|
-
var childFields = container.querySelectorAll(".".concat(classes('
|
|
317
|
-
expect(childFields.length).toEqual(
|
|
316
|
+
var childFields = container.querySelectorAll(".".concat(classes('section')));
|
|
317
|
+
expect(childFields.length).toEqual(2); // One for each entry in the child collection.
|
|
318
318
|
});
|
|
319
319
|
});
|
|
@@ -27,26 +27,36 @@ var recurseCheckForHiddenComponents = function recurseCheckForHiddenComponents(c
|
|
|
27
27
|
if (!(0, _optionIsSelected.default)(formData[component.id], option) && option.nested) {
|
|
28
28
|
option.nested.forEach(function (nested) {
|
|
29
29
|
path = nested.fieldId;
|
|
30
|
-
|
|
30
|
+
if (path) {
|
|
31
|
+
candidateComponentForDeletion.set(path, component);
|
|
32
|
+
}
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
} else if (!(0, _showComponent.default)(component, formData)) {
|
|
36
|
-
|
|
38
|
+
if (path) {
|
|
39
|
+
candidateComponentForDeletion.set(path, component);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
};
|
|
40
44
|
var buildListOfComponentsUsedInVisiblePages = function buildListOfComponentsUsedInVisiblePages(page, form, formData, componentsUsedInVisiblePagesIds) {
|
|
41
45
|
var _page$components;
|
|
42
46
|
(_page$components = page.components) === null || _page$components === void 0 || _page$components.forEach(function (component) {
|
|
43
|
-
var _form$components$find;
|
|
44
|
-
var componentObj = (_form$components$find = form.components.find(function (c) {
|
|
47
|
+
var _ref, _form$components$find;
|
|
48
|
+
var componentObj = (_ref = (_form$components$find = form.components.find(function (c) {
|
|
45
49
|
return c.fieldId === component.use;
|
|
46
|
-
})) !== null && _form$components$find !== void 0 ? _form$components$find :
|
|
50
|
+
})) !== null && _form$components$find !== void 0 ? _form$components$find : form.components.find(function (c) {
|
|
51
|
+
return c.id === component.use;
|
|
52
|
+
})) !== null && _ref !== void 0 ? _ref : component;
|
|
47
53
|
if (page && (0, _showComponent.default)(page, formData)) {
|
|
48
54
|
if (componentObj && (0, _showComponent.default)(componentObj, formData)) {
|
|
49
|
-
|
|
55
|
+
if (componentObj.fieldId) {
|
|
56
|
+
componentsUsedInVisiblePagesIds.push(componentObj.fieldId);
|
|
57
|
+
} else if (componentObj.id) {
|
|
58
|
+
componentsUsedInVisiblePagesIds.push(componentObj.id);
|
|
59
|
+
}
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
});
|
|
@@ -74,15 +84,19 @@ var markComponentsForDeletion = function markComponentsForDeletion(page, form, f
|
|
|
74
84
|
return;
|
|
75
85
|
}
|
|
76
86
|
(_page$components2 = page.components) === null || _page$components2 === void 0 || _page$components2.forEach(function (component) {
|
|
77
|
-
var _form$components$find2;
|
|
78
|
-
var componentObj = (_form$components$find2 = form.components.find(function (c) {
|
|
87
|
+
var _ref2, _form$components$find2;
|
|
88
|
+
var componentObj = (_ref2 = (_form$components$find2 = form.components.find(function (c) {
|
|
79
89
|
return c.fieldId === component.use;
|
|
80
|
-
})) !== null && _form$components$find2 !== void 0 ? _form$components$find2 :
|
|
90
|
+
})) !== null && _form$components$find2 !== void 0 ? _form$components$find2 : form.components.find(function (c) {
|
|
91
|
+
return c.id === component.use;
|
|
92
|
+
})) !== null && _ref2 !== void 0 ? _ref2 : component;
|
|
81
93
|
if (page && (0, _showComponent.default)(page, formData)) {
|
|
82
94
|
buildListOfComponentsUsedInVisiblePages(page, form, formData, componentsUsedInVisiblePages);
|
|
83
95
|
recurseCheckForHiddenComponents(componentObj, formData, null, candidateComponentForDeletion);
|
|
84
|
-
} else {
|
|
96
|
+
} else if (componentObj.fieldId) {
|
|
85
97
|
candidateComponentForDeletion.set(componentObj.fieldId, componentObj);
|
|
98
|
+
} else if (componentObj.id) {
|
|
99
|
+
candidateComponentForDeletion.set(componentObj.id, componentObj);
|
|
86
100
|
}
|
|
87
101
|
});
|
|
88
102
|
};
|
|
@@ -90,27 +104,50 @@ var deleteHiddenComponent = function deleteHiddenComponent(page, form, collectio
|
|
|
90
104
|
if (page.disableClearWhenHidden) {
|
|
91
105
|
return;
|
|
92
106
|
}
|
|
93
|
-
if (page && (0, _showComponent.default)(page,
|
|
107
|
+
if (page && (0, _showComponent.default)(page, formData)) {
|
|
94
108
|
var _page$components3;
|
|
95
109
|
(_page$components3 = page.components) === null || _page$components3 === void 0 || _page$components3.forEach(function (component) {
|
|
96
|
-
var _form$components$find3;
|
|
97
|
-
var componentObj = (_form$components$find3 = form.components.find(function (c) {
|
|
110
|
+
var _ref3, _form$components$find3;
|
|
111
|
+
var componentObj = (_ref3 = (_form$components$find3 = form.components.find(function (c) {
|
|
98
112
|
return c.fieldId === component.use;
|
|
99
|
-
})) !== null && _form$components$find3 !== void 0 ? _form$components$find3 :
|
|
113
|
+
})) !== null && _form$components$find3 !== void 0 ? _form$components$find3 : form.components.find(function (c) {
|
|
114
|
+
return c.id === component.use;
|
|
115
|
+
})) !== null && _ref3 !== void 0 ? _ref3 : component;
|
|
100
116
|
recurseDeleteComponents(componentObj, collectionData, null, true);
|
|
101
117
|
});
|
|
102
118
|
} else {
|
|
103
119
|
var _page$components4;
|
|
104
120
|
// recursively delete all components on the page
|
|
105
121
|
(_page$components4 = page.components) === null || _page$components4 === void 0 || _page$components4.forEach(function (component) {
|
|
106
|
-
var _form$components$find4;
|
|
107
|
-
var componentObj = (_form$components$find4 = form.components.find(function (c) {
|
|
122
|
+
var _ref4, _form$components$find4;
|
|
123
|
+
var componentObj = (_ref4 = (_form$components$find4 = form.components.find(function (c) {
|
|
108
124
|
return c.fieldId === component.use;
|
|
109
|
-
})) !== null && _form$components$find4 !== void 0 ? _form$components$find4 :
|
|
125
|
+
})) !== null && _form$components$find4 !== void 0 ? _form$components$find4 : form.components.find(function (c) {
|
|
126
|
+
return c.id === component.use;
|
|
127
|
+
})) !== null && _ref4 !== void 0 ? _ref4 : component;
|
|
110
128
|
recurseDeleteComponents(componentObj, collectionData, null, false);
|
|
111
129
|
});
|
|
112
130
|
}
|
|
113
131
|
};
|
|
132
|
+
function clearUncompletedRoutesForCollections(formData, page, form) {
|
|
133
|
+
var _page$collection;
|
|
134
|
+
var collectionDatas = formData[page === null || page === void 0 || (_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name];
|
|
135
|
+
if (collectionDatas) {
|
|
136
|
+
collectionDatas.forEach(function (collectionData) {
|
|
137
|
+
var _page$childPages;
|
|
138
|
+
/* eslint-disable consistent-return */
|
|
139
|
+
(_page$childPages = page.childPages) === null || _page$childPages === void 0 || _page$childPages.forEach(function (childPage) {
|
|
140
|
+
if (childPage.deleteCollectionWhenHidden) {
|
|
141
|
+
if (childPage && !(0, _showComponent.default)(childPage, formData)) {
|
|
142
|
+
delete formData[childPage.collection.name];
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
deleteHiddenComponent(childPage, form, collectionData, formData);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
114
151
|
var clearOutUncompletedRoutes = function clearOutUncompletedRoutes(form, formData) {
|
|
115
152
|
if (form.disableClearWhenHidden) {
|
|
116
153
|
return formData;
|
|
@@ -119,29 +156,14 @@ var clearOutUncompletedRoutes = function clearOutUncompletedRoutes(form, formDat
|
|
|
119
156
|
var candidateComponentForDeletion = new Map();
|
|
120
157
|
var componentsUsedInVisiblePagesIds = [];
|
|
121
158
|
condensedPages === null || condensedPages === void 0 || condensedPages.forEach(function (page) {
|
|
122
|
-
var _page$
|
|
123
|
-
if (page !== null && page !== void 0 && (_page$
|
|
124
|
-
|
|
125
|
-
var collectionDatas = formData[page === null || page === void 0 || (_page$collection2 = page.collection) === null || _page$collection2 === void 0 ? void 0 : _page$collection2.name];
|
|
126
|
-
if (collectionDatas) {
|
|
127
|
-
collectionDatas.forEach(function (collectionData) {
|
|
128
|
-
var _page$childPages;
|
|
129
|
-
/* eslint-disable consistent-return */
|
|
130
|
-
(_page$childPages = page.childPages) === null || _page$childPages === void 0 || _page$childPages.forEach(function (childPage) {
|
|
131
|
-
if (childPage.deleteCollectionWhenHidden) {
|
|
132
|
-
if (childPage && !(0, _showComponent.default)(childPage, collectionData) || childPage && !(0, _showComponent.default)(childPage, formData)) {
|
|
133
|
-
delete formData[childPage.collection.name];
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
deleteHiddenComponent(childPage, form, collectionData, formData);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
}
|
|
159
|
+
var _page$collection2;
|
|
160
|
+
if (page !== null && page !== void 0 && (_page$collection2 = page.collection) !== null && _page$collection2 !== void 0 && _page$collection2.name) {
|
|
161
|
+
clearUncompletedRoutesForCollections(formData, page, form);
|
|
141
162
|
} else {
|
|
142
163
|
markComponentsForDeletion(page, form, formData, candidateComponentForDeletion, componentsUsedInVisiblePagesIds);
|
|
143
164
|
}
|
|
144
165
|
});
|
|
166
|
+
componentsUsedInVisiblePagesIds = [].concat(new Set(componentsUsedInVisiblePagesIds));
|
|
145
167
|
componentsUsedInVisiblePagesIds.forEach(function (componentId) {
|
|
146
168
|
return candidateComponentForDeletion.delete(componentId);
|
|
147
169
|
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _Answer = _interopRequireDefault(require("../../components/CheckYourAnswers/Answer"));
|
|
9
|
+
var _SummaryListRow = _interopRequireDefault(require("../../components/SummaryList/SummaryListRow"));
|
|
10
|
+
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // Local imports
|
|
18
|
+
var getComponentRowForCYA = function getComponentRowForCYA(page, component, customClasses, entryData) {
|
|
19
|
+
var modifiedPage = _objectSpread(_objectSpread({}, page), {}, {
|
|
20
|
+
formData: _objectSpread(_objectSpread({}, page.formData), entryData)
|
|
21
|
+
});
|
|
22
|
+
var row = (0, _getCYARow.default)(modifiedPage, component);
|
|
23
|
+
return /*#__PURE__*/_react.default.createElement(_SummaryListRow.default, {
|
|
24
|
+
key: "".concat(row.fieldId),
|
|
25
|
+
row: {
|
|
26
|
+
key: row.key,
|
|
27
|
+
value: /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
28
|
+
value: row.value,
|
|
29
|
+
component: row.component,
|
|
30
|
+
formData: modifiedPage.formData
|
|
31
|
+
}),
|
|
32
|
+
required: row.required
|
|
33
|
+
},
|
|
34
|
+
classes: customClasses
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var _default = exports.default = getComponentRowForCYA;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getCYARowsForPage = _interopRequireDefault(require("./getCYARowsForPage"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils.CheckYourAnswers.getCYARowsForPage', function () {
|
|
6
|
+
var COMPONENT_A = {
|
|
7
|
+
type: 'text',
|
|
8
|
+
id: 'a',
|
|
9
|
+
fieldId: 'a',
|
|
10
|
+
label: 'Alpha'
|
|
11
|
+
};
|
|
12
|
+
var COMPONENT_B = {
|
|
13
|
+
type: 'text',
|
|
14
|
+
id: 'b',
|
|
15
|
+
fieldId: 'b',
|
|
16
|
+
label: 'Bravo'
|
|
17
|
+
};
|
|
18
|
+
var PAGE = {
|
|
19
|
+
id: 'page',
|
|
20
|
+
components: [COMPONENT_A, COMPONENT_B],
|
|
21
|
+
formData: {
|
|
22
|
+
a: 'Alpha Value',
|
|
23
|
+
b: 'Bravo Value'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
27
|
+
it('should get rows for a page with readonly text components', function () {
|
|
28
|
+
var rows = (0, _getCYARowsForPage.default)(PAGE, ON_ACTION);
|
|
29
|
+
expect(rows.length).toEqual(2);
|
|
30
|
+
expect(rows[0]).toEqual(expect.objectContaining({
|
|
31
|
+
fieldId: COMPONENT_A.fieldId,
|
|
32
|
+
key: COMPONENT_A.label,
|
|
33
|
+
value: 'Alpha Value'
|
|
34
|
+
}));
|
|
35
|
+
expect(rows[1]).toEqual(expect.objectContaining({
|
|
36
|
+
fieldId: COMPONENT_B.fieldId,
|
|
37
|
+
key: COMPONENT_B.label,
|
|
38
|
+
value: 'Bravo Value'
|
|
39
|
+
}));
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
/* eslint-disable no-param-reassign */
|
|
7
8
|
/**
|
|
8
9
|
* This function effectively adds a new entry to a page collection by
|
|
9
10
|
* invalidating the current active ID for that collection.
|
|
@@ -15,7 +16,8 @@ exports.default = void 0;
|
|
|
15
16
|
* @param {object} formData The top level formData object.
|
|
16
17
|
*/
|
|
17
18
|
var addCollectionPageEntry = function addCollectionPageEntry(collectionName, formData) {
|
|
18
|
-
|
|
19
|
-
formData["".concat(
|
|
19
|
+
var fieldName = collectionName.split('.').pop();
|
|
20
|
+
formData["".concat(fieldName, "ActiveId")] = '0';
|
|
21
|
+
formData["".concat(fieldName, "NumberedIndex")] = Number(formData["".concat(fieldName, "ActiveId")]) + 1;
|
|
20
22
|
};
|
|
21
23
|
var _default = exports.default = addCollectionPageEntry;
|
|
@@ -13,4 +13,24 @@ describe('Utils.CollectionPage.addCollectionPageEntry', function () {
|
|
|
13
13
|
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
14
14
|
expect(FORM_DATA.grandchildActiveId).toBeTruthy();
|
|
15
15
|
});
|
|
16
|
+
it('should correctly set the active ID for a top-level collection', function () {
|
|
17
|
+
var FORM_DATA = {};
|
|
18
|
+
(0, _addCollectionPageEntry.default)('testCollection', FORM_DATA);
|
|
19
|
+
expect(FORM_DATA.testCollectionActiveId).toBe('0');
|
|
20
|
+
});
|
|
21
|
+
it('should correctly set the active ID for a nested collection', function () {
|
|
22
|
+
var FORM_DATA = {};
|
|
23
|
+
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
24
|
+
expect(FORM_DATA.grandchildActiveId).toBe('0');
|
|
25
|
+
});
|
|
26
|
+
it('should correctly increment the numbered index for a top-level collection', function () {
|
|
27
|
+
var FORM_DATA = {};
|
|
28
|
+
(0, _addCollectionPageEntry.default)('testCollection', FORM_DATA);
|
|
29
|
+
expect(FORM_DATA.testCollectionNumberedIndex).toBe(1);
|
|
30
|
+
});
|
|
31
|
+
it('should correctly increment the numbered index for a nested collection', function () {
|
|
32
|
+
var FORM_DATA = {};
|
|
33
|
+
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
34
|
+
expect(FORM_DATA.grandchildNumberedIndex).toBe(1);
|
|
35
|
+
});
|
|
16
36
|
});
|
|
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
7
8
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
8
9
|
var _meetsCondition = _interopRequireDefault(require("./meetsCondition"));
|
|
9
10
|
var _setupConditions = _interopRequireDefault(require("./setupConditions"));
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
// Global imports
|
|
13
|
+
|
|
11
14
|
// Local imports
|
|
12
15
|
|
|
13
16
|
var testConditions = function testConditions(conditions, data) {
|
|
@@ -17,7 +20,8 @@ var testConditions = function testConditions(conditions, data) {
|
|
|
17
20
|
if (Array.isArray(condition.conditions)) {
|
|
18
21
|
return testConditions(condition.conditions, data, condition.type);
|
|
19
22
|
}
|
|
20
|
-
var
|
|
23
|
+
var field = condition.field.startsWith('interpolate::') ? _copReactComponents.Utils.interpolateString(condition.field, data).replace('interpolate::', '') : condition.field;
|
|
24
|
+
var sourceDataValue = _Data.default.getSource(data, field);
|
|
21
25
|
return (0, _meetsCondition.default)(condition, sourceDataValue, data);
|
|
22
26
|
};
|
|
23
27
|
return type === 'and' ? arr.every(testCallback) : arr.some(testCallback);
|
|
@@ -92,4 +92,17 @@ describe('utils.Condition.meetsAllConditions', function () {
|
|
|
92
92
|
expect((0, _meetsAllConditions.default)(CONDITIONS, VALID_DATA)).toBeTruthy();
|
|
93
93
|
expect((0, _meetsAllConditions.default)(CONDITIONS, INVALID_DATA)).toBeFalsy();
|
|
94
94
|
});
|
|
95
|
+
it('should evaluate conditions correctly using interpolated fields', function () {
|
|
96
|
+
var NEW_DATA = {
|
|
97
|
+
role: 'admin',
|
|
98
|
+
'admin_status': 'active'
|
|
99
|
+
};
|
|
100
|
+
var CONDITION = {
|
|
101
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
102
|
+
field: 'interpolate::${role}_status',
|
|
103
|
+
op: 'eq',
|
|
104
|
+
value: 'active'
|
|
105
|
+
};
|
|
106
|
+
expect((0, _meetsAllConditions.default)([CONDITION], NEW_DATA)).toBeTruthy();
|
|
107
|
+
});
|
|
95
108
|
});
|