@ukhomeoffice/cop-react-form-renderer 6.11.1 → 6.12.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/README.md +8 -0
- package/dist/components/CheckYourAnswers/Answer.js +1 -1
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +6 -2
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +131 -50
- package/dist/components/CollectionPage/CollectionPage.js +2 -1
- package/dist/components/CollectionSummary/CollectionSummary.js +6 -4
- package/dist/components/CollectionSummary/CollectionSummary.scss +5 -0
- package/dist/components/CollectionSummary/CollectionSummary.test.js +60 -36
- package/dist/components/CollectionSummary/RenderListView.js +18 -6
- package/dist/components/CollectionSummary/RenderListView.scss +9 -0
- package/dist/components/CollectionSummary/RenderListView.test.js +42 -5
- package/dist/components/CollectionSummary/SummaryCard.js +6 -4
- package/dist/components/CollectionSummary/SummaryCard.scss +6 -0
- package/dist/components/CollectionSummary/SummaryCard.test.js +5 -5
- package/dist/components/CollectionSummary/SummaryCardDetails.js +3 -2
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +2 -0
- package/dist/components/FormComponent/Collection.js +2 -1
- package/dist/components/FormComponent/Collection.scss +1 -1
- package/dist/components/FormComponent/Container.js +2 -0
- package/dist/components/FormComponent/Container.scss +15 -0
- package/dist/components/FormComponent/FormComponent.js +1 -1
- package/dist/components/FormPage/FormPage.js +19 -7
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +25 -13
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +59 -1
- package/dist/components/FormRenderer/onPageAction.js +5 -1
- package/dist/json/actions.json +17 -0
- package/dist/json/actionsNoSave.json +17 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +7 -4
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +39 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +2 -1
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -26
- package/dist/utils/CollectionPage/setCollectionPageData.js +2 -1
- package/dist/utils/Data/deleteValues.js +22 -0
- package/dist/utils/Data/deleteValues.test.js +57 -0
- package/dist/utils/Data/getAutocompleteSource.test.js +14 -5
- package/dist/utils/Data/getOptions.js +2 -1
- package/dist/utils/Data/getOptions.test.js +26 -8
- package/dist/utils/Data/index.js +2 -0
- package/dist/utils/Operate/deleteValueInFormData.js +26 -0
- package/dist/utils/Operate/deleteValueInFormData.test.js +60 -0
- package/dist/utils/Operate/runPageOperations.js +2 -0
- package/dist/utils/Validate/additional/conditionallyPermittedChange.js +25 -0
- package/dist/utils/Validate/additional/conditionallyPermittedChange.test.js +33 -0
- package/dist/utils/Validate/additional/index.js +6 -1
- package/dist/utils/Validate/additional/index.test.js +66 -0
- package/dist/utils/Validate/additional/mustBeOneOf.js +21 -0
- package/dist/utils/Validate/additional/mustBeOneOf.test.js +36 -0
- package/package.json +4 -3
|
@@ -7,6 +7,7 @@ exports.default = exports.DEFAULT_TITLE = exports.DEFAULT_LIST_CLASS = exports.D
|
|
|
7
7
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _BannerStrip = _interopRequireDefault(require("./BannerStrip"));
|
|
10
11
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
12
|
var _getSummaryListRowForDetails = _interopRequireDefault(require("../../utils/CheckYourAnswers/getSummaryListRowForDetails"));
|
|
12
13
|
var _Condition = _interopRequireDefault(require("../../utils/Condition"));
|
|
@@ -35,19 +36,26 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
35
36
|
onFullEdit = _ref.onFullEdit,
|
|
36
37
|
onDelete = _ref.onDelete,
|
|
37
38
|
masterPage = _ref.masterPage,
|
|
38
|
-
classModifiers = _ref.classModifiers
|
|
39
|
-
|
|
39
|
+
classModifiers = _ref.classModifiers,
|
|
40
|
+
optionalFieldPlaceholder = _ref.optionalFieldPlaceholder;
|
|
41
|
+
var classes = _copReactComponents.Utils.classBuilder(DEFAULT_CLASS, classModifiers, config.className);
|
|
40
42
|
var listClass = _copReactComponents.Utils.classBuilder(DEFAULT_LIST_CLASS);
|
|
41
43
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
42
44
|
className: classes(),
|
|
43
45
|
id: id
|
|
44
46
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
45
47
|
className: classes('title-wrapper', [], 'dark')
|
|
48
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
49
|
+
className: classes('title-content')
|
|
46
50
|
}, /*#__PURE__*/_react.default.createElement("h2", {
|
|
47
51
|
className: classes('title')
|
|
48
52
|
}, _copReactComponents.Utils.interpolateString(config.title || DEFAULT_TITLE, _objectSpread(_objectSpread({}, entryData), {}, {
|
|
49
53
|
index: entryData.index + 1
|
|
50
|
-
}))), /*#__PURE__*/_react.default.createElement(
|
|
54
|
+
}))), config.banners && /*#__PURE__*/_react.default.createElement(_BannerStrip.default, {
|
|
55
|
+
id: "BannerStrip".concat(entryData.id),
|
|
56
|
+
banners: config.banners,
|
|
57
|
+
formData: entryData
|
|
58
|
+
})), /*#__PURE__*/_react.default.createElement("ul", {
|
|
51
59
|
className: classes('actions')
|
|
52
60
|
}, /*#__PURE__*/_react.default.createElement("li", {
|
|
53
61
|
className: classes('action')
|
|
@@ -95,7 +103,7 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
95
103
|
if (!component) {
|
|
96
104
|
return null;
|
|
97
105
|
}
|
|
98
|
-
return (0, _getSummaryListRowForDetails.default)(childPage, component, listClass, entryData);
|
|
106
|
+
return (0, _getSummaryListRowForDetails.default)(childPage, component, listClass, entryData, optionalFieldPlaceholder);
|
|
99
107
|
});
|
|
100
108
|
}
|
|
101
109
|
return null;
|
|
@@ -109,6 +117,8 @@ RenderListView.propTypes = {
|
|
|
109
117
|
index: _propTypes.default.number.isRequired
|
|
110
118
|
}).isRequired,
|
|
111
119
|
config: _propTypes.default.shape({
|
|
120
|
+
className: _propTypes.default.string,
|
|
121
|
+
banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
|
|
112
122
|
title: _propTypes.default.string,
|
|
113
123
|
changeAction: _propTypes.default.shape({
|
|
114
124
|
label: _propTypes.default.string,
|
|
@@ -128,9 +138,11 @@ RenderListView.propTypes = {
|
|
|
128
138
|
components: _propTypes.default.arrayOf(_propTypes.default.shape())
|
|
129
139
|
})).isRequired
|
|
130
140
|
}).isRequired,
|
|
131
|
-
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)])
|
|
141
|
+
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
142
|
+
optionalFieldPlaceholder: _propTypes.default.string
|
|
132
143
|
};
|
|
133
144
|
RenderListView.defaultProps = {
|
|
134
|
-
classModifiers: null
|
|
145
|
+
classModifiers: null,
|
|
146
|
+
optionalFieldPlaceholder: null
|
|
135
147
|
};
|
|
136
148
|
var _default = exports.default = RenderListView;
|
|
@@ -183,6 +183,10 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
183
183
|
&--deleting-summary-card {
|
|
184
184
|
background-color: #FCF0EE;
|
|
185
185
|
}
|
|
186
|
+
|
|
187
|
+
&.error {
|
|
188
|
+
border-left: 7px solid red;
|
|
189
|
+
}
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
.govuk-summary-card__title-wrapper {
|
|
@@ -213,6 +217,11 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
219
|
|
|
220
|
+
.govuk-summary-card__title-content {
|
|
221
|
+
display: flex;
|
|
222
|
+
flex-direction: column;
|
|
223
|
+
}
|
|
224
|
+
|
|
216
225
|
.govuk-summary-card__actions {
|
|
217
226
|
@include govuk-typography-responsive($size: 19);
|
|
218
227
|
@include govuk-typography-weight-bold;
|
|
@@ -6,10 +6,13 @@ var _setupTests = require("../../setupTests");
|
|
|
6
6
|
var _RenderListView = _interopRequireDefault(require("./RenderListView"));
|
|
7
7
|
var _models = require("../../models");
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
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); } // Global imports.
|
|
11
15
|
// Local imports.
|
|
12
|
-
|
|
13
16
|
describe('components.CollectionSummary.RenderListView', function () {
|
|
14
17
|
var ENTRY = {
|
|
15
18
|
id: '001',
|
|
@@ -78,6 +81,13 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
78
81
|
label: 'Delete label'
|
|
79
82
|
}
|
|
80
83
|
};
|
|
84
|
+
var CONFIG_ERROR = _objectSpread({
|
|
85
|
+
className: 'error',
|
|
86
|
+
banners: [{
|
|
87
|
+
"text": "MORE DETAILS NEEDED",
|
|
88
|
+
"classModifiers": ["red"]
|
|
89
|
+
}]
|
|
90
|
+
}, CONFIG);
|
|
81
91
|
var ID = 'testListView';
|
|
82
92
|
var onChangeArgs = [];
|
|
83
93
|
var onChangeCalls = 0;
|
|
@@ -180,6 +190,33 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
180
190
|
// Check if the index is rendered as expected in the title
|
|
181
191
|
expect(title.textContent).toContain("Title text ".concat(ENTRY.index + 1));
|
|
182
192
|
});
|
|
193
|
+
it('should render an Error Tag with Error className when passed an error in the Banner and ClassName', function () {
|
|
194
|
+
var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_RenderListView.default, {
|
|
195
|
+
id: ID,
|
|
196
|
+
entryData: ENTRY,
|
|
197
|
+
config: CONFIG_ERROR,
|
|
198
|
+
onFullEdit: ON_CHANGE,
|
|
199
|
+
onDelete: ON_DELETE,
|
|
200
|
+
masterPage: MASTER_PAGE,
|
|
201
|
+
getComponentRow: getComponentRow
|
|
202
|
+
})),
|
|
203
|
+
container = _renderWithValidation3.container;
|
|
204
|
+
var listViewDiv = checkSetup(container);
|
|
205
|
+
|
|
206
|
+
// Check className
|
|
207
|
+
expect(listViewDiv.classList).toContain('error');
|
|
208
|
+
|
|
209
|
+
// Check for presence of Banner Strip
|
|
210
|
+
var bannerStrip = listViewDiv.querySelector('.hods-form-banner-strip');
|
|
211
|
+
expect(bannerStrip).not.toBeNull();
|
|
212
|
+
expect(bannerStrip.id).toEqual('BannerStrip001');
|
|
213
|
+
|
|
214
|
+
// Check for presence of Error Tag with correct tagName, className, and Text content
|
|
215
|
+
var errorTag = listViewDiv.querySelector('.hods-form-banner-strip__tag--red');
|
|
216
|
+
expect(errorTag).not.toBeNull();
|
|
217
|
+
expect(errorTag.tagName).toBe('STRONG');
|
|
218
|
+
expect(errorTag.innerHTML).toContain('MORE DETAILS NEEDED');
|
|
219
|
+
});
|
|
183
220
|
describe('Action buttons in RenderListView', function () {
|
|
184
221
|
beforeEach(function () {
|
|
185
222
|
onChangeArgs = [];
|
|
@@ -188,7 +225,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
188
225
|
onDeleteCalls = 0;
|
|
189
226
|
});
|
|
190
227
|
it('should render and handle action buttons correctly', function () {
|
|
191
|
-
var
|
|
228
|
+
var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_RenderListView.default, {
|
|
192
229
|
id: ID,
|
|
193
230
|
entryData: ENTRY,
|
|
194
231
|
config: CONFIG,
|
|
@@ -197,7 +234,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
197
234
|
masterPage: MASTER_PAGE,
|
|
198
235
|
getComponentRow: getComponentRow
|
|
199
236
|
})),
|
|
200
|
-
container =
|
|
237
|
+
container = _renderWithValidation4.container;
|
|
201
238
|
var listViewDiv = container.querySelector('.govuk-summary-card');
|
|
202
239
|
expect(listViewDiv).not.toBeNull();
|
|
203
240
|
|
|
@@ -47,7 +47,7 @@ var DEFAULT_DUPLICATE_BUTTON_LABEL = exports.DEFAULT_DUPLICATE_BUTTON_LABEL = 'D
|
|
|
47
47
|
var DEFAULT_DETAILS_TITLE = exports.DEFAULT_DETAILS_TITLE = 'Full details';
|
|
48
48
|
var DEFAULT_CHANGE_BUTTON_CLASS = exports.DEFAULT_CHANGE_BUTTON_CLASS = 'secondary';
|
|
49
49
|
var SummaryCard = function SummaryCard(_ref) {
|
|
50
|
-
var _config$changeAction2, _config$changeAction3, _config$changeAction4, _config$deleteAction, _config$deleteAction2, _config$duplicateActi, _config$duplicateActi2, _config$
|
|
50
|
+
var _config$changeAction2, _config$changeAction3, _config$changeAction4, _config$deleteAction, _config$deleteAction2, _config$duplicateActi, _config$duplicateActi2, _config$fullDetails2;
|
|
51
51
|
var id = _ref.id,
|
|
52
52
|
entryData = _ref.entryData,
|
|
53
53
|
config = _ref.config,
|
|
@@ -148,6 +148,7 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
148
148
|
|
|
149
149
|
// To render summary card in list view as per https://design-system.service.gov.uk/components/summary-list
|
|
150
150
|
if (config.listView) {
|
|
151
|
+
var _config$fullDetails;
|
|
151
152
|
return /*#__PURE__*/_react.default.createElement(_RenderListView.default, {
|
|
152
153
|
id: id,
|
|
153
154
|
entryData: entryData,
|
|
@@ -155,7 +156,8 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
155
156
|
onFullEdit: onFullEdit,
|
|
156
157
|
onDelete: onDelete,
|
|
157
158
|
masterPage: masterPage,
|
|
158
|
-
classModifiers: classModifiers
|
|
159
|
+
classModifiers: classModifiers,
|
|
160
|
+
optionalFieldPlaceholder: (_config$fullDetails = config.fullDetails) === null || _config$fullDetails === void 0 ? void 0 : _config$fullDetails.optionalFieldPlaceholder
|
|
159
161
|
});
|
|
160
162
|
}
|
|
161
163
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -169,7 +171,7 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
169
171
|
id: "BannerStrip".concat(entryData.id),
|
|
170
172
|
banners: config.banners,
|
|
171
173
|
formData: entryData
|
|
172
|
-
}), /*#__PURE__*/_react.default.createElement("
|
|
174
|
+
}), /*#__PURE__*/_react.default.createElement("h2", {
|
|
173
175
|
id: "".concat(id, ".titleText"),
|
|
174
176
|
className: classes('header-content-title')
|
|
175
177
|
}, _utils.default.FormPage.getTitle(config.title, entryData)), config.details && /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -234,7 +236,7 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
234
236
|
childCollections: childCollections,
|
|
235
237
|
formData: formData,
|
|
236
238
|
entryData: entryData,
|
|
237
|
-
optionalFieldPlaceholder: (
|
|
239
|
+
optionalFieldPlaceholder: (_config$fullDetails2 = config.fullDetails) === null || _config$fullDetails2 === void 0 ? void 0 : _config$fullDetails2.optionalFieldPlaceholder
|
|
238
240
|
}))));
|
|
239
241
|
};
|
|
240
242
|
SummaryCard.propTypes = {
|
|
@@ -81,7 +81,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
81
81
|
expect(headerBanners.tagName).toEqual('DIV');
|
|
82
82
|
expect(headerBanners.classList).toContain(_BannerStrip.DEFAULT_CLASS);
|
|
83
83
|
var headerTitle = headerContentDiv.children[1];
|
|
84
|
-
expect(headerTitle.tagName).toEqual('
|
|
84
|
+
expect(headerTitle.tagName).toEqual('H2');
|
|
85
85
|
expect(headerTitle.classList).toContain(classes('header-content-title'));
|
|
86
86
|
expect(headerTitle.textContent).toEqual(CONFIG.title);
|
|
87
87
|
var headerDetails = headerContentDiv.children[2];
|
|
@@ -113,7 +113,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
113
113
|
// and the details.
|
|
114
114
|
|
|
115
115
|
var headerTitle = headerContentDiv.children[0];
|
|
116
|
-
expect(headerTitle.tagName).toEqual('
|
|
116
|
+
expect(headerTitle.tagName).toEqual('H2');
|
|
117
117
|
expect(headerTitle.classList).toContain(classes('header-content-title'));
|
|
118
118
|
expect(headerTitle.textContent).toEqual(CONFIG.title);
|
|
119
119
|
var headerDetails = headerContentDiv.children[1];
|
|
@@ -148,7 +148,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
148
148
|
// the title.
|
|
149
149
|
|
|
150
150
|
var headerTitle = headerContentDiv.children[1];
|
|
151
|
-
expect(headerTitle.tagName).toEqual('
|
|
151
|
+
expect(headerTitle.tagName).toEqual('H2');
|
|
152
152
|
expect(headerTitle.classList).toContain(classes('header-content-title'));
|
|
153
153
|
expect(headerTitle.textContent).toEqual(CONFIG.title);
|
|
154
154
|
});
|
|
@@ -171,7 +171,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
171
171
|
var _checkSetup4 = checkSetup(container),
|
|
172
172
|
headerContentDiv = _checkSetup4.headerContentDiv;
|
|
173
173
|
var headerTitle = headerContentDiv.children[0];
|
|
174
|
-
expect(headerTitle.tagName).toEqual('
|
|
174
|
+
expect(headerTitle.tagName).toEqual('H2');
|
|
175
175
|
expect(headerTitle.classList).toContain(classes('header-content-title'));
|
|
176
176
|
expect(headerTitle.textContent).toEqual("".concat(ENTRY.titleText, " that is interpolated"));
|
|
177
177
|
});
|
|
@@ -211,7 +211,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
211
211
|
var _checkSetup5 = checkSetup(container),
|
|
212
212
|
headerContentDiv = _checkSetup5.headerContentDiv;
|
|
213
213
|
var headerTitle = headerContentDiv.children[0];
|
|
214
|
-
expect(headerTitle.tagName).toEqual('
|
|
214
|
+
expect(headerTitle.tagName).toEqual('H2');
|
|
215
215
|
expect(headerTitle.classList).toContain(classes('header-content-title'));
|
|
216
216
|
expect(headerTitle.textContent).toEqual("".concat(ENTRY.titleText, " that is interpolated"));
|
|
217
217
|
});
|
|
@@ -168,7 +168,8 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
168
168
|
childMasterPages: [],
|
|
169
169
|
formData: _objectSpread(_objectSpread(_objectSpread({}, formData), entryData), entry),
|
|
170
170
|
entryData: entry,
|
|
171
|
-
hideChildSectionTitles: true
|
|
171
|
+
hideChildSectionTitles: true,
|
|
172
|
+
optionalFieldPlaceholder: optionalFieldPlaceholder
|
|
172
173
|
});
|
|
173
174
|
}));
|
|
174
175
|
}
|
|
@@ -182,7 +183,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
182
183
|
className: classes('section')
|
|
183
184
|
}, !hideChildSectionTitles && /*#__PURE__*/_react.default.createElement("h3", {
|
|
184
185
|
className: classes('section-title')
|
|
185
|
-
}, _utils.default.FormPage.getConditionalText(section.title, _objectSpread(_objectSpread({}, childPage.formData), entryData))), /*#__PURE__*/_react.default.createElement("
|
|
186
|
+
}, _utils.default.FormPage.getConditionalText(section.title, _objectSpread(_objectSpread({}, childPage.formData), entryData))), /*#__PURE__*/_react.default.createElement("dl", {
|
|
186
187
|
className: classes('section-content'),
|
|
187
188
|
style: {
|
|
188
189
|
'--dividers': columns.length - 1
|
|
@@ -141,6 +141,8 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
141
141
|
grid-column-end: var(--column);
|
|
142
142
|
grid-row-start: var(--row);
|
|
143
143
|
grid-row-end: var(--row);
|
|
144
|
+
margin-block-start: 0;
|
|
145
|
+
margin-block-end: 0;
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
.hods-form-summary-card-details__divider {
|
|
@@ -8,6 +8,7 @@ exports.default = exports.DEFAULT_CLASS = void 0;
|
|
|
8
8
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _uuid = require("uuid");
|
|
11
12
|
var _models = require("../../models");
|
|
12
13
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
14
|
var _Container = _interopRequireDefault(require("./Container"));
|
|
@@ -78,7 +79,7 @@ var Collection = function Collection(_ref) {
|
|
|
78
79
|
while (1) switch (_context.prev = _context.next) {
|
|
79
80
|
case 0:
|
|
80
81
|
reportChange([].concat(value, [{
|
|
81
|
-
id:
|
|
82
|
+
id: (0, _uuid.v4)()
|
|
82
83
|
}]));
|
|
83
84
|
case 1:
|
|
84
85
|
case "end":
|
|
@@ -12,8 +12,10 @@ var _models = require("../../models");
|
|
|
12
12
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
13
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
14
14
|
var _getSourceData = _interopRequireDefault(require("../../utils/Data/getSourceData"));
|
|
15
|
+
require("./Container.scss");
|
|
15
16
|
var _excluded = ["container", "value", "formData", "onChange", "wrap", "onTopLevelChange"]; // Global imports
|
|
16
17
|
// Local imports
|
|
18
|
+
// Styles
|
|
17
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
20
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
19
21
|
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; }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.horizonal {
|
|
2
|
+
flex-direction: row;
|
|
3
|
+
display: flex;
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
gap: 2rem;
|
|
6
|
+
.horizonal{
|
|
7
|
+
justify-content: space-around;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
@media screen and (max-width: 640px) {
|
|
11
|
+
.horizonal {
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
gap:0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -89,7 +89,7 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
89
89
|
};
|
|
90
90
|
(0, _react.useEffect)(function () {
|
|
91
91
|
var defaultValue = _utils.default.Component.defaultValue(component, formData);
|
|
92
|
-
if (!value && defaultValue) {
|
|
92
|
+
if (!value && !(formData !== null && formData !== void 0 && formData[component.fieldId]) && defaultValue) {
|
|
93
93
|
if (typeof onComponentChange === 'function') {
|
|
94
94
|
onComponentChange({
|
|
95
95
|
target: {
|
|
@@ -62,13 +62,25 @@ var FormPage = function FormPage(_ref) {
|
|
|
62
62
|
var onPageChange = function onPageChange(_ref2) {
|
|
63
63
|
var target = _ref2.target;
|
|
64
64
|
var formPage = page;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
if (target.value == null) {
|
|
66
|
+
delete formPage.formData[target.name];
|
|
67
|
+
setPatch(function (prev) {
|
|
68
|
+
var data = prev;
|
|
69
|
+
return delete data[target.name];
|
|
70
|
+
});
|
|
71
|
+
setPatchLabel(function (prev) {
|
|
72
|
+
var data = prev;
|
|
73
|
+
return delete data[target.component];
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
formPage.formData[target.name] = target.value;
|
|
77
|
+
setPatch(function (prev) {
|
|
78
|
+
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, target.name, target.value));
|
|
79
|
+
});
|
|
80
|
+
setPatchLabel(function (prev) {
|
|
81
|
+
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, target.component, target.label));
|
|
82
|
+
});
|
|
83
|
+
}
|
|
72
84
|
if (typeof onChange === 'function') {
|
|
73
85
|
onChange(page.formData);
|
|
74
86
|
}
|
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _optionIsSelected = _interopRequireDefault(require("../../../utils/Component/optionIsSelected"));
|
|
8
|
+
var _getCollectionPageActiveId = _interopRequireDefault(require("../../../utils/CollectionPage/getCollectionPageActiveId"));
|
|
9
|
+
var _getCollectionPageData = _interopRequireDefault(require("../../../utils/CollectionPage/getCollectionPageData"));
|
|
10
|
+
var _setCollectionPageData = _interopRequireDefault(require("../../../utils/CollectionPage/setCollectionPageData"));
|
|
8
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
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); }
|
|
10
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; }
|
|
@@ -13,6 +16,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
13
16
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
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
|
|
15
18
|
var parentComponents = ['radios', 'checkboxes'];
|
|
19
|
+
var getActiveIds = function getActiveIds(collectionName, formData) {
|
|
20
|
+
var nameParts = collectionName.split('.');
|
|
21
|
+
var result = {};
|
|
22
|
+
nameParts.forEach(function (part) {
|
|
23
|
+
result["".concat(part, "ActiveId")] = formData["".concat(part, "ActiveId")];
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
16
27
|
function getIdsToDelete(component, selectedValue) {
|
|
17
28
|
var _component$data;
|
|
18
29
|
var idsToDelete = [];
|
|
@@ -25,29 +36,30 @@ function getIdsToDelete(component, selectedValue) {
|
|
|
25
36
|
});
|
|
26
37
|
return idsToDelete;
|
|
27
38
|
}
|
|
28
|
-
;
|
|
29
39
|
var cleanHiddenNestedData = function cleanHiddenNestedData(patch, page) {
|
|
40
|
+
var _patch = patch;
|
|
30
41
|
page.components.forEach(function (component) {
|
|
31
42
|
if (!parentComponents.includes(component.type)) {
|
|
32
43
|
return;
|
|
33
44
|
}
|
|
34
|
-
var _patch = patch;
|
|
35
45
|
var idsToDelete = getIdsToDelete(component, _patch[component.id]);
|
|
36
46
|
idsToDelete.forEach(function (id) {
|
|
37
47
|
delete _patch[id];
|
|
38
48
|
});
|
|
39
49
|
});
|
|
40
|
-
if (page.collection
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
if (page.collection) {
|
|
51
|
+
_patch = _objectSpread(_objectSpread({}, getActiveIds(page.collection.name, page.formData)), _patch);
|
|
52
|
+
var collectionData = (0, _getCollectionPageData.default)(page.collection.name, _patch);
|
|
53
|
+
if (collectionData) {
|
|
54
|
+
var activeId = (0, _getCollectionPageActiveId.default)(page.collection.name, _patch);
|
|
55
|
+
var modifiedCollection = collectionData.map(function (entry) {
|
|
56
|
+
return entry.id === activeId ? cleanHiddenNestedData(entry, _objectSpread(_objectSpread({}, page), {}, {
|
|
57
|
+
collection: undefined
|
|
58
|
+
})) : entry;
|
|
59
|
+
});
|
|
60
|
+
(0, _setCollectionPageData.default)(page.collection.name, modifiedCollection, _patch);
|
|
61
|
+
}
|
|
49
62
|
}
|
|
50
|
-
;
|
|
51
|
-
return patch;
|
|
63
|
+
return _patch;
|
|
52
64
|
};
|
|
53
65
|
var _default = exports.default = cleanHiddenNestedData;
|
|
@@ -78,7 +78,7 @@ describe('components', function () {
|
|
|
78
78
|
expect(updatedPatchCheckboxes.nested1).toBeFalsy();
|
|
79
79
|
expect(updatedPatchCheckboxes.nested2).toBeTruthy();
|
|
80
80
|
});
|
|
81
|
-
it('remove data corresponding to hidden nested components within the active collection entry', function () {
|
|
81
|
+
it('should remove data corresponding to hidden nested components within the active collection entry', function () {
|
|
82
82
|
var patch = {
|
|
83
83
|
collectionNameActiveId: '456',
|
|
84
84
|
collectionName: [{
|
|
@@ -100,6 +100,9 @@ describe('components', function () {
|
|
|
100
100
|
collection: {
|
|
101
101
|
name: 'collectionName'
|
|
102
102
|
},
|
|
103
|
+
formData: {
|
|
104
|
+
collectionNameActiveId: '456'
|
|
105
|
+
},
|
|
103
106
|
components: [{
|
|
104
107
|
id: 'parent',
|
|
105
108
|
type: 'radios',
|
|
@@ -126,6 +129,61 @@ describe('components', function () {
|
|
|
126
129
|
expect(updatedPatch.collectionName[1].nested1).toBeFalsy();
|
|
127
130
|
expect(updatedPatch.collectionName[1].nested2).toBeTruthy();
|
|
128
131
|
});
|
|
132
|
+
it('should remove data corresponding to hidden nested components when collection is nested within an entity', function () {
|
|
133
|
+
var patch = {
|
|
134
|
+
collectionNameActiveId: '456',
|
|
135
|
+
entities: [{
|
|
136
|
+
id: '777',
|
|
137
|
+
collectionName: [{
|
|
138
|
+
id: '123',
|
|
139
|
+
parent: 'option1',
|
|
140
|
+
nested1: 'should be included',
|
|
141
|
+
nested2: 'should be included'
|
|
142
|
+
}, {
|
|
143
|
+
id: '456',
|
|
144
|
+
parent: 'option2',
|
|
145
|
+
nested1: 'should not be included',
|
|
146
|
+
nested2: 'should be included'
|
|
147
|
+
}]
|
|
148
|
+
}]
|
|
149
|
+
};
|
|
150
|
+
var page = {
|
|
151
|
+
id: 'page',
|
|
152
|
+
name: 'page',
|
|
153
|
+
title: 'Page',
|
|
154
|
+
collection: {
|
|
155
|
+
name: 'entities.collectionName'
|
|
156
|
+
},
|
|
157
|
+
formData: {
|
|
158
|
+
collectionNameActiveId: '456',
|
|
159
|
+
entitiesActiveId: '777'
|
|
160
|
+
},
|
|
161
|
+
components: [{
|
|
162
|
+
id: 'parent',
|
|
163
|
+
type: 'radios',
|
|
164
|
+
data: {
|
|
165
|
+
options: [{
|
|
166
|
+
value: 'option1',
|
|
167
|
+
nested: [{
|
|
168
|
+
id: 'nested1',
|
|
169
|
+
fieldId: 'nested1'
|
|
170
|
+
}]
|
|
171
|
+
}, {
|
|
172
|
+
value: 'option2',
|
|
173
|
+
nested: [{
|
|
174
|
+
id: 'nested2',
|
|
175
|
+
fieldId: 'nested2'
|
|
176
|
+
}]
|
|
177
|
+
}]
|
|
178
|
+
}
|
|
179
|
+
}]
|
|
180
|
+
};
|
|
181
|
+
var updatedPatch = (0, _cleanHiddenNestedData.default)(patch, page);
|
|
182
|
+
expect(updatedPatch.entities[0].collectionName[0].nested1).toBeTruthy();
|
|
183
|
+
expect(updatedPatch.entities[0].collectionName[0].nested2).toBeTruthy();
|
|
184
|
+
expect(updatedPatch.entities[0].collectionName[1].nested1).toBeFalsy();
|
|
185
|
+
expect(updatedPatch.entities[0].collectionName[1].nested2).toBeTruthy();
|
|
186
|
+
});
|
|
129
187
|
});
|
|
130
188
|
});
|
|
131
189
|
});
|
|
@@ -100,7 +100,11 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
100
100
|
break;
|
|
101
101
|
}
|
|
102
102
|
;
|
|
103
|
-
|
|
103
|
+
|
|
104
|
+
// If a value has been deleted from formData,
|
|
105
|
+
// also delete it from data before doing object spread,
|
|
106
|
+
// or else it will reappear in submissionData.
|
|
107
|
+
_utils.default.Data.deleteValues(data, formState.page.formData);
|
|
104
108
|
|
|
105
109
|
// Save draft or submit.
|
|
106
110
|
var submissionData = _utils.default.Format.form({
|
|
@@ -204,8 +204,9 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
|
|
|
204
204
|
rows.push(getCollectionNameHeading(page, collectionName, page.collection.collectionHeading, headingChangeAction));
|
|
205
205
|
}
|
|
206
206
|
var itemIndex = 0;
|
|
207
|
-
var
|
|
208
|
-
|
|
207
|
+
var hideItemTitles = Array.isArray(page.collection.hideItemTitles) ? (0, _meetsAllConditions.default)(page.collection.hideItemTitles, data) : page.collection.hideItemTitles;
|
|
208
|
+
var onlyShowActiveEntry = Array.isArray(page.collection.onlyShowActiveEntryOnCYA) ? (0, _meetsAllConditions.default)(page.collection.onlyShowActiveEntryOnCYA, data) : page.collection.onlyShowActiveEntryOnCYA;
|
|
209
|
+
if (onlyShowActiveEntry) {
|
|
209
210
|
var activeEntry = collectionData.find(function (entry, index) {
|
|
210
211
|
itemIndex = index;
|
|
211
212
|
return entry.id === activeId;
|
|
@@ -222,9 +223,11 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
|
|
|
222
223
|
var labelCount = itemIndex + 1;
|
|
223
224
|
var actionPosition = ((_page$collection2 = page.collection) === null || _page$collection2 === void 0 ? void 0 : _page$collection2.actionPosition) || 'top';
|
|
224
225
|
var fullPath = "".concat(page.collection.name, "[").concat(itemIndex, "]");
|
|
225
|
-
var titleRow = getTitleRowForItem(page, item, page.id, labelCount, fullPath);
|
|
226
226
|
var actionRows = getActionRows(page, item, onAction, labelCount, activeIds);
|
|
227
|
-
|
|
227
|
+
if (!hideItemTitles) {
|
|
228
|
+
var titleRow = getTitleRowForItem(page, item, page.id, labelCount, fullPath);
|
|
229
|
+
rows = rows.concat(titleRow);
|
|
230
|
+
}
|
|
228
231
|
if (actionPosition === 'top') {
|
|
229
232
|
rows = rows.concat(actionRows);
|
|
230
233
|
}
|