@ukhomeoffice/cop-react-form-renderer 6.0.0 → 6.0.2-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/CheckYourAnswers/CheckYourAnswers.scss +2 -2
- package/dist/components/CollectionSummary/BannerStrip.js +3 -1
- package/dist/components/CollectionSummary/BannerStrip.scss +7 -3
- package/dist/components/CollectionSummary/CollectionSummary.js +34 -7
- package/dist/components/CollectionSummary/CollectionSummary.scss +1 -1
- package/dist/components/CollectionSummary/CollectionSummary.test.js +82 -4
- package/dist/components/CollectionSummary/Confirmation.scss +1 -1
- package/dist/components/CollectionSummary/RenderListView.js +9 -5
- package/dist/components/CollectionSummary/RenderListView.scss +1 -1
- package/dist/components/CollectionSummary/RenderListView.test.js +24 -3
- package/dist/components/CollectionSummary/SummaryCard.js +18 -45
- package/dist/components/CollectionSummary/SummaryCard.scss +4 -147
- package/dist/components/CollectionSummary/SummaryCard.test.js +53 -191
- package/dist/components/CollectionSummary/SummaryCardDetails.js +117 -0
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +158 -0
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +319 -0
- package/dist/components/FormPage/FormPage.scss +1 -1
- package/dist/components/FormRenderer/FormRenderer.scss +1 -1
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/component-used-in-multiple-pages-data.json +4 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/component-used-in-multiple-pages-form.json +61 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-collection-data-removed.json +4 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-collections.json +8 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-components-removed.json +3 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-components.json +5 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-entire-collection-removed.json +3 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-nested-component-removed.json +10 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/data-with-nested-components.json +11 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-for-nested-components.json +96 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections-delete-entire.json +47 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-collections.json +46 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/form-with-components.json +48 -0
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +139 -0
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +113 -0
- package/dist/components/FormRenderer/helpers/deleteNodeByPath.js +20 -0
- package/dist/components/FormRenderer/helpers/deleteNodeByPath.test.js +56 -0
- package/dist/components/FormRenderer/helpers/index.js +3 -1
- package/dist/components/FormRenderer/onPageAction.js +8 -2
- package/dist/components/FormRenderer/onPageAction.test.js +5 -0
- package/dist/components/SummaryList/SummaryList.scss +2 -2
- package/dist/components/TaskList/TaskList.scss +1 -1
- package/dist/utils/CollectionPage/mergeCollectionPages.js +15 -5
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +48 -1
- package/dist/utils/CollectionPage/setCollectionPageData.js +2 -2
- package/dist/utils/CollectionPage/setCollectionPageData.test.js +31 -0
- package/dist/utils/FormPage/getConditionalText.js +54 -0
- package/dist/utils/FormPage/getConditionalText.test.js +162 -0
- package/dist/utils/FormPage/index.js +5 -2
- package/package.json +4 -4
- package/dist/utils/FormPage/getPageTitle.js +0 -32
- package/dist/utils/FormPage/getPageTitle.test.js +0 -138
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@import "govuk-frontend/
|
|
2
|
-
@import "govuk-frontend/
|
|
1
|
+
@import "node_modules/govuk-frontend/govuk/_base";
|
|
2
|
+
@import "node_modules/govuk-frontend/govuk/overrides/spacing";
|
|
3
3
|
|
|
4
4
|
.govuk-link {
|
|
5
5
|
@include govuk-font($size: 19);
|
|
@@ -36,7 +36,9 @@ var BannerStrip = function BannerStrip(_ref) {
|
|
|
36
36
|
id: bannerId,
|
|
37
37
|
key: bannerId,
|
|
38
38
|
className: classes('banner')
|
|
39
|
-
},
|
|
39
|
+
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.Markup, {
|
|
40
|
+
content: _utils.default.interpolateString(banner, formData)
|
|
41
|
+
}));
|
|
40
42
|
}
|
|
41
43
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Tag, {
|
|
42
44
|
key: bannerId,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@import "govuk-frontend/
|
|
2
|
-
@import "govuk-frontend/
|
|
1
|
+
@import "node_modules/govuk-frontend/govuk/_base";
|
|
2
|
+
@import "node_modules/govuk-frontend/govuk/components/tag/_index";
|
|
3
3
|
|
|
4
4
|
.hods-form-banner-strip {
|
|
5
5
|
display: block;
|
|
@@ -7,9 +7,13 @@
|
|
|
7
7
|
padding: 0;
|
|
8
8
|
margin: 0 0 govuk-spacing(1) 0;
|
|
9
9
|
&__banner {
|
|
10
|
-
@include govuk-font($size: 19
|
|
10
|
+
@include govuk-font($size: 19);
|
|
11
11
|
display: inline-block;
|
|
12
12
|
margin-right: govuk-spacing(2);
|
|
13
|
+
|
|
14
|
+
p {
|
|
15
|
+
margin: 0;
|
|
16
|
+
}
|
|
13
17
|
}
|
|
14
18
|
&__tag {
|
|
15
19
|
@extend .govuk-tag;
|
|
@@ -64,17 +64,34 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
64
64
|
return _utils.default.CollectionPage.getData(config.collectionName, formData) || [];
|
|
65
65
|
}, [formData]);
|
|
66
66
|
var masterPage = (0, _react.useMemo)(function () {
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
var collectionNameParts = config.collectionName.split('.');
|
|
68
|
+
var childPages = _utils.default.CollectionPage.mergePages(pages || []) || [];
|
|
69
|
+
return collectionNameParts.reduce(function (acc, current, index) {
|
|
70
|
+
var _childPages$find;
|
|
71
|
+
var currentPath = index === 0 ? "".concat(acc).concat(current) : "".concat(acc, ".").concat(current);
|
|
72
|
+
if (index === collectionNameParts.length - 1) {
|
|
73
|
+
var _childPages;
|
|
74
|
+
return ((_childPages = childPages) === null || _childPages === void 0 ? void 0 : _childPages.find(function (p) {
|
|
75
|
+
var _p$collection;
|
|
76
|
+
return ((_p$collection = p.collection) === null || _p$collection === void 0 ? void 0 : _p$collection.name) === currentPath;
|
|
77
|
+
})) || null;
|
|
78
|
+
}
|
|
79
|
+
childPages = ((_childPages$find = childPages.find(function (p) {
|
|
80
|
+
var _p$collection2;
|
|
81
|
+
return ((_p$collection2 = p.collection) === null || _p$collection2 === void 0 ? void 0 : _p$collection2.name) === currentPath;
|
|
82
|
+
})) === null || _childPages$find === void 0 ? void 0 : _childPages$find.childPages) || null;
|
|
83
|
+
return currentPath;
|
|
84
|
+
}, "");
|
|
72
85
|
}, [pages]);
|
|
73
86
|
var validateEntries = function validateEntries() {
|
|
87
|
+
var stored = [];
|
|
74
88
|
// We only clear errors if it's not empty to avoid
|
|
75
89
|
// triggering a race condition with the 'data' memo
|
|
76
90
|
// above.
|
|
77
91
|
if (errors.length > 0) {
|
|
92
|
+
stored = errors.filter(function (e) {
|
|
93
|
+
return e.id === config.id;
|
|
94
|
+
});
|
|
78
95
|
clearErrors();
|
|
79
96
|
}
|
|
80
97
|
var allErrors = [];
|
|
@@ -99,6 +116,9 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
99
116
|
});
|
|
100
117
|
allErrors = allErrors.concat(entryErrors);
|
|
101
118
|
});
|
|
119
|
+
if (stored.length > 0) {
|
|
120
|
+
allErrors = allErrors.concat(stored);
|
|
121
|
+
}
|
|
102
122
|
// We only add allErrors if it's not empty to avoid
|
|
103
123
|
// triggering a race condition with the 'data' memo
|
|
104
124
|
// above.
|
|
@@ -107,7 +127,11 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
107
127
|
}
|
|
108
128
|
};
|
|
109
129
|
(0, _react.useEffect)(function () {
|
|
110
|
-
|
|
130
|
+
// An empty array here indicates nothing to validate, higher level validation
|
|
131
|
+
// such as 'required' is taken care of at the page level not here
|
|
132
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
133
|
+
validateEntries();
|
|
134
|
+
}
|
|
111
135
|
}, [data]);
|
|
112
136
|
var onSummaryCardChange = function onSummaryCardChange(page, entryId) {
|
|
113
137
|
if (typeof onAction !== 'function') {
|
|
@@ -213,6 +237,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
213
237
|
return onChange(target);
|
|
214
238
|
},
|
|
215
239
|
parentCollectionName: config.collectionName.split('.').shift(),
|
|
240
|
+
childCollections: config.childCollections || [],
|
|
216
241
|
formData: formData,
|
|
217
242
|
classModifiers: entry === entryToDelete ? ['deleting-summary-card'] : [''],
|
|
218
243
|
inError: errors.filter(function (e) {
|
|
@@ -224,6 +249,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
224
249
|
CollectionSummary.propTypes = {
|
|
225
250
|
config: _propTypes.default.shape({
|
|
226
251
|
fieldId: _propTypes.default.string.isRequired,
|
|
252
|
+
id: _propTypes.default.string.isRequired,
|
|
227
253
|
collectionName: _propTypes.default.string.isRequired,
|
|
228
254
|
addButton: _propTypes.default.shape({
|
|
229
255
|
label: _propTypes.default.string,
|
|
@@ -248,7 +274,8 @@ CollectionSummary.propTypes = {
|
|
|
248
274
|
confirmation: _propTypes.default.shape({
|
|
249
275
|
message: _propTypes.default.string,
|
|
250
276
|
label: _propTypes.default.string
|
|
251
|
-
})
|
|
277
|
+
}),
|
|
278
|
+
childCollections: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
252
279
|
}).isRequired,
|
|
253
280
|
onAction: _propTypes.default.func,
|
|
254
281
|
onChange: _propTypes.default.func,
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
var _react = _interopRequireDefault(require("react"));
|
|
5
4
|
var _react2 = require("@testing-library/react");
|
|
6
5
|
var _setupTests = require("../../setupTests");
|
|
6
|
+
var _context = require("../../context");
|
|
7
|
+
var _ValidationContext = require("../../context/ValidationContext");
|
|
7
8
|
var _hooks = require("../../hooks");
|
|
8
9
|
var _CollectionSummary = _interopRequireWildcard(require("./CollectionSummary"));
|
|
9
10
|
var _Confirmation = require("./Confirmation");
|
|
10
11
|
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); }
|
|
11
12
|
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; }
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
|
|
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); }
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
19
|
+
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.
|
|
15
20
|
// Local imports.
|
|
16
|
-
|
|
17
21
|
describe('components.CollectionSummary.CollectionSummary', function () {
|
|
18
22
|
var CONFIG = {
|
|
19
23
|
id: 'testSummary',
|
|
@@ -106,6 +110,80 @@ describe('components.CollectionSummary.CollectionSummary', function () {
|
|
|
106
110
|
expect(summary.children[0].id).toEqual("".concat(CONFIG.fieldId, ".confirmation"));
|
|
107
111
|
expect(summary.children[0].classList).toContain(_Confirmation.DEFAULT_CLASS);
|
|
108
112
|
});
|
|
113
|
+
it('should keep higher level errors that relate to the CollectionSummary', function () {
|
|
114
|
+
var errors = [{
|
|
115
|
+
id: 'testSummary',
|
|
116
|
+
error: 'add at least one'
|
|
117
|
+
}];
|
|
118
|
+
var clearErrorCount = 0;
|
|
119
|
+
var errorsAdded = [];
|
|
120
|
+
var clearErrors = function clearErrors() {
|
|
121
|
+
clearErrorCount += 1;
|
|
122
|
+
};
|
|
123
|
+
var addErrors = function addErrors(newErrors) {
|
|
124
|
+
errorsAdded = errorsAdded.concat(newErrors);
|
|
125
|
+
};
|
|
126
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_context.HooksContextProvider, null, /*#__PURE__*/_react.default.createElement(_ValidationContext.ValidationContext.Provider, {
|
|
127
|
+
value: {
|
|
128
|
+
errors: errors,
|
|
129
|
+
clearErrors: clearErrors,
|
|
130
|
+
addErrors: addErrors,
|
|
131
|
+
validate: function validate() {}
|
|
132
|
+
}
|
|
133
|
+
}, /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
134
|
+
config: _objectSpread(_objectSpread({}, CONFIG), {}, {
|
|
135
|
+
required: true
|
|
136
|
+
}),
|
|
137
|
+
formData: _objectSpread(_objectSpread({}, FORM_DATA), {}, {
|
|
138
|
+
testCollection: [{
|
|
139
|
+
id: '000',
|
|
140
|
+
testText: 'value'
|
|
141
|
+
}]
|
|
142
|
+
}),
|
|
143
|
+
onAction: ON_ACTION,
|
|
144
|
+
pages: PAGES
|
|
145
|
+
}))));
|
|
146
|
+
expect(clearErrorCount).toEqual(1);
|
|
147
|
+
expect(errorsAdded[0]).toEqual({
|
|
148
|
+
id: 'testSummary',
|
|
149
|
+
error: 'add at least one'
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
it('should ignore higher level errors that do not relate to the CollectionSummary', function () {
|
|
153
|
+
var errors = [{
|
|
154
|
+
id: 'somethingElse',
|
|
155
|
+
error: 'add at least one'
|
|
156
|
+
}];
|
|
157
|
+
var clearErrorCount = 0;
|
|
158
|
+
var errorsAdded = [];
|
|
159
|
+
var clearErrors = function clearErrors() {
|
|
160
|
+
clearErrorCount += 1;
|
|
161
|
+
};
|
|
162
|
+
var addErrors = function addErrors(newErrors) {
|
|
163
|
+
errorsAdded = errorsAdded.concat(newErrors);
|
|
164
|
+
};
|
|
165
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_context.HooksContextProvider, null, /*#__PURE__*/_react.default.createElement(_ValidationContext.ValidationContext.Provider, {
|
|
166
|
+
value: {
|
|
167
|
+
errors: errors,
|
|
168
|
+
clearErrors: clearErrors,
|
|
169
|
+
addErrors: addErrors
|
|
170
|
+
}
|
|
171
|
+
}, /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
|
|
172
|
+
config: _objectSpread(_objectSpread({}, CONFIG), {}, {
|
|
173
|
+
required: true
|
|
174
|
+
}),
|
|
175
|
+
formData: _objectSpread(_objectSpread({}, FORM_DATA), {}, {
|
|
176
|
+
testCollection: [{
|
|
177
|
+
id: '000',
|
|
178
|
+
testText: 'value'
|
|
179
|
+
}]
|
|
180
|
+
}),
|
|
181
|
+
onAction: ON_ACTION,
|
|
182
|
+
pages: PAGES
|
|
183
|
+
}))));
|
|
184
|
+
expect(clearErrorCount).toEqual(1);
|
|
185
|
+
expect(errorsAdded.length).toEqual(0);
|
|
186
|
+
});
|
|
109
187
|
describe('Add Another button', function () {
|
|
110
188
|
it('should render with an Add button if one is configured', function () {
|
|
111
189
|
var CONFIG_WITH_BUTTON = {
|
|
@@ -12,12 +12,14 @@ var _SummaryListRow = _interopRequireDefault(require("../SummaryList/SummaryList
|
|
|
12
12
|
var _Answer = _interopRequireDefault(require("../CheckYourAnswers/Answer"));
|
|
13
13
|
require("./RenderListView.scss");
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
20
|
+
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.
|
|
17
21
|
// Local imports.
|
|
18
|
-
|
|
19
22
|
// Styles.
|
|
20
|
-
|
|
21
23
|
var DEFAULT_CLASS = exports.DEFAULT_CLASS = 'govuk-summary-card';
|
|
22
24
|
var DEFAULT_LIST_CLASS = exports.DEFAULT_LIST_CLASS = 'govuk-summary-list';
|
|
23
25
|
var DEFAULT_TITLE = exports.DEFAULT_TITLE = 'Item';
|
|
@@ -43,7 +45,9 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
43
45
|
className: classes('title-wrapper', [], 'dark')
|
|
44
46
|
}, /*#__PURE__*/_react.default.createElement("h2", {
|
|
45
47
|
className: classes('title')
|
|
46
|
-
}, _copReactComponents.Utils.interpolateString(config.title || DEFAULT_TITLE, entryData)
|
|
48
|
+
}, _copReactComponents.Utils.interpolateString(config.title || DEFAULT_TITLE, _objectSpread(_objectSpread({}, entryData), {}, {
|
|
49
|
+
index: entryData.index + 1
|
|
50
|
+
}))), /*#__PURE__*/_react.default.createElement("ul", {
|
|
47
51
|
className: classes('actions')
|
|
48
52
|
}, /*#__PURE__*/_react.default.createElement("li", {
|
|
49
53
|
className: classes('action')
|
|
@@ -60,7 +60,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
60
60
|
}]
|
|
61
61
|
};
|
|
62
62
|
var CONFIG = {
|
|
63
|
-
title: 'Title text',
|
|
63
|
+
title: 'Title text 1',
|
|
64
64
|
listView: true,
|
|
65
65
|
changeAction: {
|
|
66
66
|
label: 'Change label',
|
|
@@ -140,6 +140,27 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
140
140
|
expect(thirdRowKey.textContent).toEqual('Item 3');
|
|
141
141
|
expect(thirdRowValue.textContent).toEqual('Value 3Value 4');
|
|
142
142
|
});
|
|
143
|
+
it('should render the index correctly in the title', function () {
|
|
144
|
+
var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_RenderListView.default, {
|
|
145
|
+
id: ID,
|
|
146
|
+
entryData: ENTRY,
|
|
147
|
+
config: CONFIG,
|
|
148
|
+
onChange: ON_CHANGE,
|
|
149
|
+
onDelete: ON_DELETE,
|
|
150
|
+
masterPage: MASTER_PAGE
|
|
151
|
+
})),
|
|
152
|
+
container = _renderWithValidation2.container;
|
|
153
|
+
var listViewDiv = checkSetup(container);
|
|
154
|
+
|
|
155
|
+
// Check title wrapper and title text
|
|
156
|
+
var titleWrapper = listViewDiv.querySelector('.govuk-summary-card__title-wrapper');
|
|
157
|
+
expect(titleWrapper).not.toBeNull();
|
|
158
|
+
var title = titleWrapper.querySelector('.govuk-summary-card__title');
|
|
159
|
+
expect(title.textContent).toEqual(CONFIG.title);
|
|
160
|
+
|
|
161
|
+
// Check if the index is rendered as expected in the title
|
|
162
|
+
expect(title.textContent).toContain("Title text ".concat(ENTRY.index + 1));
|
|
163
|
+
});
|
|
143
164
|
describe('Action buttons in RenderListView', function () {
|
|
144
165
|
beforeEach(function () {
|
|
145
166
|
onChangeArgs = [];
|
|
@@ -148,7 +169,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
148
169
|
onDeleteCalls = 0;
|
|
149
170
|
});
|
|
150
171
|
it('should render and handle action buttons correctly', function () {
|
|
151
|
-
var
|
|
172
|
+
var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_RenderListView.default, {
|
|
152
173
|
id: ID,
|
|
153
174
|
entryData: ENTRY,
|
|
154
175
|
config: CONFIG,
|
|
@@ -156,7 +177,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
156
177
|
onDelete: ON_DELETE,
|
|
157
178
|
masterPage: MASTER_PAGE
|
|
158
179
|
})),
|
|
159
|
-
container =
|
|
180
|
+
container = _renderWithValidation3.container;
|
|
160
181
|
var listViewDiv = container.querySelector('.govuk-summary-card');
|
|
161
182
|
expect(listViewDiv).not.toBeNull();
|
|
162
183
|
|
|
@@ -11,10 +11,10 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
12
12
|
var _getQuickEditPage = _interopRequireDefault(require("../../utils/CollectionPage/getQuickEditPage"));
|
|
13
13
|
var _hooks = require("../../hooks");
|
|
14
|
-
var _FormComponent = _interopRequireDefault(require("../FormComponent"));
|
|
15
14
|
var _FormPage = _interopRequireDefault(require("../FormPage"));
|
|
16
15
|
var _BannerStrip = _interopRequireDefault(require("./BannerStrip"));
|
|
17
16
|
var _RenderListView = _interopRequireDefault(require("./RenderListView"));
|
|
17
|
+
var _SummaryCardDetails = _interopRequireDefault(require("./SummaryCardDetails"));
|
|
18
18
|
require("./SummaryCard.scss");
|
|
19
19
|
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); }
|
|
20
20
|
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; }
|
|
@@ -44,7 +44,7 @@ var DEFAULT_DUPLICATE_BUTTON_LABEL = exports.DEFAULT_DUPLICATE_BUTTON_LABEL = 'D
|
|
|
44
44
|
var DEFAULT_DETAILS_TITLE = exports.DEFAULT_DETAILS_TITLE = 'Full details';
|
|
45
45
|
var DEFAULT_CHANGE_BUTTON_CLASS = exports.DEFAULT_CHANGE_BUTTON_CLASS = 'secondary';
|
|
46
46
|
var SummaryCard = function SummaryCard(_ref) {
|
|
47
|
-
var _config$changeAction2, _config$changeAction3, _config$
|
|
47
|
+
var _config$changeAction2, _config$changeAction3, _config$deleteAction, _config$duplicateActi;
|
|
48
48
|
var id = _ref.id,
|
|
49
49
|
entryData = _ref.entryData,
|
|
50
50
|
config = _ref.config,
|
|
@@ -54,6 +54,7 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
54
54
|
onDuplicate = _ref.onDuplicate,
|
|
55
55
|
onQuickEdit = _ref.onQuickEdit,
|
|
56
56
|
parentCollectionName = _ref.parentCollectionName,
|
|
57
|
+
childCollections = _ref.childCollections,
|
|
57
58
|
formData = _ref.formData,
|
|
58
59
|
masterPage = _ref.masterPage,
|
|
59
60
|
hideDetails = _ref.hideDetails,
|
|
@@ -162,7 +163,7 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
162
163
|
}, _utils.default.FormPage.getTitle(config.title, entryData)), config.details && /*#__PURE__*/_react.default.createElement("div", {
|
|
163
164
|
id: "".concat(id, ".titleDetail"),
|
|
164
165
|
className: classes('header-content-detail')
|
|
165
|
-
},
|
|
166
|
+
}, _utils.default.FormPage.getConditionalText(config.details, entryData))), /*#__PURE__*/_react.default.createElement("div", {
|
|
166
167
|
className: classes('header-actions')
|
|
167
168
|
}, config.quickEdit && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
168
169
|
id: "".concat(id, ".quickEditButton"),
|
|
@@ -180,19 +181,19 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
180
181
|
return onChange((_config$changeAction = config.changeAction) === null || _config$changeAction === void 0 ? void 0 : _config$changeAction.page, entryData.id);
|
|
181
182
|
},
|
|
182
183
|
classModifiers: ((_config$changeAction2 = config.changeAction) === null || _config$changeAction2 === void 0 ? void 0 : _config$changeAction2.classModifiers) || DEFAULT_CHANGE_BUTTON_CLASS
|
|
183
|
-
}, ((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.label) || DEFAULT_CHANGE_BUTTON_LABEL), config.
|
|
184
|
-
id: "".concat(id, ".
|
|
184
|
+
}, ((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.label) || DEFAULT_CHANGE_BUTTON_LABEL), config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
185
|
+
id: "".concat(id, ".deleteButton"),
|
|
185
186
|
onClick: function onClick() {
|
|
186
|
-
|
|
187
|
+
return onDelete(entryData);
|
|
187
188
|
},
|
|
188
189
|
classModifiers: "secondary"
|
|
189
|
-
}, ((_config$
|
|
190
|
-
id: "".concat(id, ".
|
|
190
|
+
}, ((_config$deleteAction = config.deleteAction) === null || _config$deleteAction === void 0 ? void 0 : _config$deleteAction.label) || DEFAULT_DELETE_BUTTON_LABEL), config.duplicateAction && typeof onDuplicate === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
191
|
+
id: "".concat(id, ".duplicateButton"),
|
|
191
192
|
onClick: function onClick() {
|
|
192
|
-
|
|
193
|
+
onDuplicate(entryData);
|
|
193
194
|
},
|
|
194
195
|
classModifiers: "secondary"
|
|
195
|
-
}, ((_config$
|
|
196
|
+
}, ((_config$duplicateActi = config.duplicateAction) === null || _config$duplicateActi === void 0 ? void 0 : _config$duplicateActi.label) || DEFAULT_DUPLICATE_BUTTON_LABEL))), quickEdit && quickEditPage && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
|
|
196
197
|
page: quickEditPage,
|
|
197
198
|
onAction: function onAction(action, patch) {
|
|
198
199
|
return _onAction(action, patch);
|
|
@@ -203,41 +204,11 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
203
204
|
}, !hideDetails && /*#__PURE__*/_react.default.createElement(_copReactComponents.Details, {
|
|
204
205
|
summary: config.detailsTitle || DEFAULT_DETAILS_TITLE,
|
|
205
206
|
className: "details"
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
215
|
-
key: section.title,
|
|
216
|
-
className: classes('section')
|
|
217
|
-
}, /*#__PURE__*/_react.default.createElement("h3", {
|
|
218
|
-
className: classes('section-title')
|
|
219
|
-
}, section.title), /*#__PURE__*/_react.default.createElement("div", {
|
|
220
|
-
className: classes('section-content', "columns-".concat(section.columns))
|
|
221
|
-
}, (_section$fields = section.fields) === null || _section$fields === void 0 ? void 0 : _section$fields.map(function (fieldId) {
|
|
222
|
-
var component = allPageComponents.find(function (comp) {
|
|
223
|
-
return comp.fieldId === fieldId;
|
|
224
|
-
});
|
|
225
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
226
|
-
key: fieldId,
|
|
227
|
-
className: classes('field')
|
|
228
|
-
}, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
229
|
-
component: _objectSpread(_objectSpread({}, component), {}, {
|
|
230
|
-
hint: ''
|
|
231
|
-
}),
|
|
232
|
-
value: entryData[component === null || component === void 0 ? void 0 : component.fieldId],
|
|
233
|
-
formData: entryData,
|
|
234
|
-
wrap: true,
|
|
235
|
-
readonly: true
|
|
236
|
-
}));
|
|
237
|
-
})));
|
|
238
|
-
});
|
|
239
|
-
}).filter(function (e) {
|
|
240
|
-
return !!e;
|
|
207
|
+
}, /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
208
|
+
masterPage: masterPage,
|
|
209
|
+
childCollections: childCollections,
|
|
210
|
+
formData: formData,
|
|
211
|
+
entryData: entryData
|
|
241
212
|
}))));
|
|
242
213
|
};
|
|
243
214
|
SummaryCard.propTypes = {
|
|
@@ -280,6 +251,7 @@ SummaryCard.propTypes = {
|
|
|
280
251
|
onDuplicate: _propTypes.default.func,
|
|
281
252
|
onQuickEdit: _propTypes.default.func,
|
|
282
253
|
parentCollectionName: _propTypes.default.string.isRequired,
|
|
254
|
+
childCollections: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
283
255
|
formData: _propTypes.default.shape({}).isRequired,
|
|
284
256
|
hideDetails: _propTypes.default.bool,
|
|
285
257
|
inError: _propTypes.default.bool
|
|
@@ -290,6 +262,7 @@ SummaryCard.defaultProps = {
|
|
|
290
262
|
onDelete: null,
|
|
291
263
|
onDuplicate: null,
|
|
292
264
|
onQuickEdit: null,
|
|
265
|
+
childCollections: [],
|
|
293
266
|
hideDetails: false,
|
|
294
267
|
inError: false
|
|
295
268
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
$govuk-font-family: 'Roboto', arial, sans-serif;
|
|
2
2
|
|
|
3
|
-
@import "govuk-frontend/
|
|
3
|
+
@import "node_modules/govuk-frontend/govuk/_base";
|
|
4
4
|
|
|
5
5
|
.govuk-grid-column-two-thirds:has(.hods-form-summary-card) {
|
|
6
6
|
width: 100% !important;
|
|
@@ -71,7 +71,9 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
&__editpage {
|
|
74
|
-
margin: 0 govuk-spacing(4)
|
|
74
|
+
margin: 0 govuk-spacing(4);
|
|
75
|
+
padding: govuk-spacing(4) govuk-spacing(4) 0;
|
|
76
|
+
background-color: #FFFFFF
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
&__body {
|
|
@@ -87,111 +89,6 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
87
89
|
margin-bottom: 0;
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
&__section {
|
|
92
|
-
border-bottom: 2px solid #A9A9A9;
|
|
93
|
-
|
|
94
|
-
&-title {
|
|
95
|
-
font-weight: bold;
|
|
96
|
-
margin: govuk-spacing(2) 0 govuk-spacing(6) 0;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
&-content {
|
|
100
|
-
display: flex;
|
|
101
|
-
flex-wrap: wrap;
|
|
102
|
-
gap: govuk-spacing(2);
|
|
103
|
-
|
|
104
|
-
.hods-form-summary-card__field {
|
|
105
|
-
box-sizing: border-box;
|
|
106
|
-
margin-bottom: govuk-spacing(4);
|
|
107
|
-
|
|
108
|
-
.govuk-label,
|
|
109
|
-
.govuk-fieldset__legend {
|
|
110
|
-
font-weight: bold;
|
|
111
|
-
margin-bottom: govuk-spacing(1) !important;
|
|
112
|
-
|
|
113
|
-
&::after {
|
|
114
|
-
content: " :";
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
div.govuk-form-group div:has(img){
|
|
119
|
-
display: flex;
|
|
120
|
-
flex-wrap: wrap;
|
|
121
|
-
|
|
122
|
-
.hods-readonly.hods-readonly--success {
|
|
123
|
-
font-size: 0;
|
|
124
|
-
line-height: 0;
|
|
125
|
-
|
|
126
|
-
.cop-upload-preview__thumb {
|
|
127
|
-
display: inline-block;
|
|
128
|
-
margin-right: govuk-spacing(1);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
&--columns-1,
|
|
136
|
-
&--columns-2,
|
|
137
|
-
&--columns-3 {
|
|
138
|
-
position: relative;
|
|
139
|
-
margin-bottom: govuk-spacing(1);
|
|
140
|
-
|
|
141
|
-
&::before {
|
|
142
|
-
content: "";
|
|
143
|
-
position: absolute;
|
|
144
|
-
top: 0;
|
|
145
|
-
width: 2px;
|
|
146
|
-
height: 100%;
|
|
147
|
-
background-color: #A9A9A9;
|
|
148
|
-
left: 0;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
&--columns-2 {
|
|
153
|
-
&::after {
|
|
154
|
-
content: "";
|
|
155
|
-
position: absolute;
|
|
156
|
-
top: 0;
|
|
157
|
-
width: 2px;
|
|
158
|
-
height: 100%;
|
|
159
|
-
background-color: #A9A9A9;
|
|
160
|
-
left: 50%;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
.hods-form-summary-card__field {
|
|
164
|
-
flex: 0 0 calc(50% - 10px);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
&--columns-3 {
|
|
169
|
-
&::after {
|
|
170
|
-
content: "";
|
|
171
|
-
position: absolute;
|
|
172
|
-
top: 0;
|
|
173
|
-
left: 33.333%;
|
|
174
|
-
width: 2px;
|
|
175
|
-
height: 100%;
|
|
176
|
-
background-color: #A9A9A9;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
.hods-form-summary-card__field {
|
|
180
|
-
flex: 0 0 calc(33.333% - 10px);
|
|
181
|
-
|
|
182
|
-
&:nth-child(2)::after {
|
|
183
|
-
content: "";
|
|
184
|
-
position: absolute;
|
|
185
|
-
top: 0;
|
|
186
|
-
right: 33.333%;
|
|
187
|
-
width: 2px;
|
|
188
|
-
height: 100%;
|
|
189
|
-
background-color: #A9A9A9;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
92
|
}
|
|
196
93
|
|
|
197
94
|
@media (max-width: 640px) {
|
|
@@ -208,45 +105,5 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
208
105
|
margin-top: govuk-spacing(2);
|
|
209
106
|
}
|
|
210
107
|
}
|
|
211
|
-
|
|
212
|
-
&__section {
|
|
213
|
-
&-content {
|
|
214
|
-
display: block;
|
|
215
|
-
|
|
216
|
-
.hods-form-summary-card__field {
|
|
217
|
-
width: 100%;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
.hods-form-summary-card__field:nth-child(2)::after {
|
|
221
|
-
display: none;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
&--columns-2,
|
|
225
|
-
&--columns-3 {
|
|
226
|
-
position: relative;
|
|
227
|
-
margin-bottom: govuk-spacing(1);
|
|
228
|
-
|
|
229
|
-
&::before {
|
|
230
|
-
content: '';
|
|
231
|
-
position: absolute;
|
|
232
|
-
top: 0;
|
|
233
|
-
width: 2px;
|
|
234
|
-
height: 100%;
|
|
235
|
-
background-color: #A9A9A9;
|
|
236
|
-
left: 0;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
&::after {
|
|
240
|
-
display: none;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
&--columns-3 {
|
|
245
|
-
.hods-form-summary-card__field:nth-child(2)::after {
|
|
246
|
-
content: none;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
108
|
}
|
|
252
109
|
}
|