@ukhomeoffice/cop-react-form-renderer 5.56.3 → 6.0.0-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/CollectionSummary/CollectionSummary.js +21 -6
- package/dist/components/CollectionSummary/SummaryCard.js +10 -39
- package/dist/components/CollectionSummary/SummaryCard.scss +0 -145
- package/dist/components/CollectionSummary/SummaryCard.test.js +0 -243
- 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/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 +134 -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 +1 -0
- package/dist/components/FormRenderer/onPageAction.test.js +5 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +15 -5
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +48 -1
- package/package.json +1 -1
|
@@ -64,11 +64,24 @@ 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() {
|
|
74
87
|
var stored = [];
|
|
@@ -224,6 +237,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
224
237
|
return onChange(target);
|
|
225
238
|
},
|
|
226
239
|
parentCollectionName: config.collectionName.split('.').shift(),
|
|
240
|
+
childCollections: config.childCollections || [],
|
|
227
241
|
formData: formData,
|
|
228
242
|
classModifiers: entry === entryToDelete ? ['deleting-summary-card'] : [''],
|
|
229
243
|
inError: errors.filter(function (e) {
|
|
@@ -260,7 +274,8 @@ CollectionSummary.propTypes = {
|
|
|
260
274
|
confirmation: _propTypes.default.shape({
|
|
261
275
|
message: _propTypes.default.string,
|
|
262
276
|
label: _propTypes.default.string
|
|
263
|
-
})
|
|
277
|
+
}),
|
|
278
|
+
childCollections: _propTypes.default.arrayOf(_propTypes.default.string)
|
|
264
279
|
}).isRequired,
|
|
265
280
|
onAction: _propTypes.default.func,
|
|
266
281
|
onChange: _propTypes.default.func,
|
|
@@ -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$deleteAction, _config$duplicateActi
|
|
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,
|
|
@@ -203,43 +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
|
-
return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.sections.map(function (section) {
|
|
212
|
-
var _section$fields;
|
|
213
|
-
if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
217
|
-
key: section.title,
|
|
218
|
-
className: classes('section')
|
|
219
|
-
}, /*#__PURE__*/_react.default.createElement("h3", {
|
|
220
|
-
className: classes('section-title')
|
|
221
|
-
}, section.title), /*#__PURE__*/_react.default.createElement("div", {
|
|
222
|
-
className: classes('section-content', "columns-".concat(section.columns))
|
|
223
|
-
}, (_section$fields = section.fields) === null || _section$fields === void 0 ? void 0 : _section$fields.map(function (fieldId) {
|
|
224
|
-
var component = allPageComponents.find(function (comp) {
|
|
225
|
-
return comp.fieldId === fieldId;
|
|
226
|
-
});
|
|
227
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
228
|
-
key: fieldId,
|
|
229
|
-
className: classes('field')
|
|
230
|
-
}, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
231
|
-
component: _objectSpread(_objectSpread({}, component), {}, {
|
|
232
|
-
hint: ''
|
|
233
|
-
}),
|
|
234
|
-
value: entryData[component === null || component === void 0 ? void 0 : component.fieldId],
|
|
235
|
-
formData: entryData,
|
|
236
|
-
wrap: true,
|
|
237
|
-
readonly: true
|
|
238
|
-
}));
|
|
239
|
-
})));
|
|
240
|
-
});
|
|
241
|
-
}).filter(function (e) {
|
|
242
|
-
return !!e;
|
|
207
|
+
}, /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
208
|
+
masterPage: masterPage,
|
|
209
|
+
childCollections: childCollections,
|
|
210
|
+
formData: formData,
|
|
211
|
+
entryData: entryData
|
|
243
212
|
}))));
|
|
244
213
|
};
|
|
245
214
|
SummaryCard.propTypes = {
|
|
@@ -282,6 +251,7 @@ SummaryCard.propTypes = {
|
|
|
282
251
|
onDuplicate: _propTypes.default.func,
|
|
283
252
|
onQuickEdit: _propTypes.default.func,
|
|
284
253
|
parentCollectionName: _propTypes.default.string.isRequired,
|
|
254
|
+
childCollections: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
285
255
|
formData: _propTypes.default.shape({}).isRequired,
|
|
286
256
|
hideDetails: _propTypes.default.bool,
|
|
287
257
|
inError: _propTypes.default.bool
|
|
@@ -292,6 +262,7 @@ SummaryCard.defaultProps = {
|
|
|
292
262
|
onDelete: null,
|
|
293
263
|
onDuplicate: null,
|
|
294
264
|
onQuickEdit: null,
|
|
265
|
+
childCollections: [],
|
|
295
266
|
hideDetails: false,
|
|
296
267
|
inError: false
|
|
297
268
|
};
|
|
@@ -89,111 +89,6 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
89
89
|
margin-bottom: 0;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
&__section {
|
|
94
|
-
border-bottom: 2px solid #E9EBED;
|
|
95
|
-
|
|
96
|
-
&-title {
|
|
97
|
-
font-weight: bold;
|
|
98
|
-
margin: govuk-spacing(2) 0 govuk-spacing(6) 0;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
&-content {
|
|
102
|
-
display: flex;
|
|
103
|
-
flex-wrap: wrap;
|
|
104
|
-
gap: govuk-spacing(2);
|
|
105
|
-
|
|
106
|
-
.hods-form-summary-card__field {
|
|
107
|
-
box-sizing: border-box;
|
|
108
|
-
margin-bottom: govuk-spacing(4);
|
|
109
|
-
|
|
110
|
-
.govuk-label,
|
|
111
|
-
.govuk-fieldset__legend {
|
|
112
|
-
font-weight: bold;
|
|
113
|
-
margin-bottom: govuk-spacing(1) !important;
|
|
114
|
-
|
|
115
|
-
&::after {
|
|
116
|
-
content: " :";
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
div.govuk-form-group div:has(img){
|
|
121
|
-
display: flex;
|
|
122
|
-
flex-wrap: wrap;
|
|
123
|
-
|
|
124
|
-
.hods-readonly.hods-readonly--success {
|
|
125
|
-
font-size: 0;
|
|
126
|
-
line-height: 0;
|
|
127
|
-
|
|
128
|
-
.cop-upload-preview__thumb {
|
|
129
|
-
display: inline-block;
|
|
130
|
-
margin-right: govuk-spacing(1);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
&--columns-1,
|
|
138
|
-
&--columns-2,
|
|
139
|
-
&--columns-3 {
|
|
140
|
-
position: relative;
|
|
141
|
-
margin-bottom: govuk-spacing(1);
|
|
142
|
-
|
|
143
|
-
&::before {
|
|
144
|
-
content: "";
|
|
145
|
-
position: absolute;
|
|
146
|
-
top: 0;
|
|
147
|
-
width: 2px;
|
|
148
|
-
height: 100%;
|
|
149
|
-
background-color: #E9EBED;
|
|
150
|
-
left: 0;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
&--columns-2 {
|
|
155
|
-
&::after {
|
|
156
|
-
content: "";
|
|
157
|
-
position: absolute;
|
|
158
|
-
top: 0;
|
|
159
|
-
width: 2px;
|
|
160
|
-
height: 100%;
|
|
161
|
-
background-color: #E9EBED;
|
|
162
|
-
left: 50%;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
.hods-form-summary-card__field {
|
|
166
|
-
flex: 0 0 calc(50% - 10px);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
&--columns-3 {
|
|
171
|
-
&::after {
|
|
172
|
-
content: "";
|
|
173
|
-
position: absolute;
|
|
174
|
-
top: 0;
|
|
175
|
-
left: 33.333%;
|
|
176
|
-
width: 2px;
|
|
177
|
-
height: 100%;
|
|
178
|
-
background-color: #E9EBED;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
.hods-form-summary-card__field {
|
|
182
|
-
flex: 0 0 calc(33.333% - 10px);
|
|
183
|
-
|
|
184
|
-
&:nth-child(2)::after {
|
|
185
|
-
content: "";
|
|
186
|
-
position: absolute;
|
|
187
|
-
top: 0;
|
|
188
|
-
right: 33.333%;
|
|
189
|
-
width: 2px;
|
|
190
|
-
height: 100%;
|
|
191
|
-
background-color: #E9EBED;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
92
|
}
|
|
198
93
|
|
|
199
94
|
@media (max-width: 640px) {
|
|
@@ -210,45 +105,5 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
210
105
|
margin-top: govuk-spacing(2);
|
|
211
106
|
}
|
|
212
107
|
}
|
|
213
|
-
|
|
214
|
-
&__section {
|
|
215
|
-
&-content {
|
|
216
|
-
display: block;
|
|
217
|
-
|
|
218
|
-
.hods-form-summary-card__field {
|
|
219
|
-
width: 100%;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
.hods-form-summary-card__field:nth-child(2)::after {
|
|
223
|
-
display: none;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
&--columns-2,
|
|
227
|
-
&--columns-3 {
|
|
228
|
-
position: relative;
|
|
229
|
-
margin-bottom: govuk-spacing(1);
|
|
230
|
-
|
|
231
|
-
&::before {
|
|
232
|
-
content: '';
|
|
233
|
-
position: absolute;
|
|
234
|
-
top: 0;
|
|
235
|
-
width: 2px;
|
|
236
|
-
height: 100%;
|
|
237
|
-
background-color: #A9A9A9;
|
|
238
|
-
left: 0;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
&::after {
|
|
242
|
-
display: none;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
&--columns-3 {
|
|
247
|
-
.hods-form-summary-card__field:nth-child(2)::after {
|
|
248
|
-
content: none;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
108
|
}
|
|
254
109
|
}
|
|
@@ -1366,247 +1366,4 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
1366
1366
|
expect(detailsComponent).toBeNull();
|
|
1367
1367
|
});
|
|
1368
1368
|
});
|
|
1369
|
-
describe('SummaryLayout config behavior', function () {
|
|
1370
|
-
it('should render sections and fields based on summaryLayout config', function () {
|
|
1371
|
-
var CHILD_PAGES = [{
|
|
1372
|
-
summaryLayout: {
|
|
1373
|
-
sections: [{
|
|
1374
|
-
title: 'Section 1',
|
|
1375
|
-
columns: 2,
|
|
1376
|
-
fields: ['fieldA', 'fieldB']
|
|
1377
|
-
}, {
|
|
1378
|
-
title: 'Section 2',
|
|
1379
|
-
columns: 1,
|
|
1380
|
-
fields: ['fieldC']
|
|
1381
|
-
}]
|
|
1382
|
-
},
|
|
1383
|
-
components: [{
|
|
1384
|
-
fieldId: 'fieldA'
|
|
1385
|
-
}, {
|
|
1386
|
-
fieldId: 'fieldB'
|
|
1387
|
-
}, {
|
|
1388
|
-
fieldId: 'fieldC'
|
|
1389
|
-
}]
|
|
1390
|
-
}];
|
|
1391
|
-
var CONFIG = {
|
|
1392
|
-
title: 'Title'
|
|
1393
|
-
};
|
|
1394
|
-
var _renderWithValidation36 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1395
|
-
id: ID,
|
|
1396
|
-
entryData: ENTRY,
|
|
1397
|
-
config: CONFIG,
|
|
1398
|
-
parentCollectionName: "parent",
|
|
1399
|
-
pages: CHILD_PAGES,
|
|
1400
|
-
formData: {},
|
|
1401
|
-
masterPage: {
|
|
1402
|
-
childPages: CHILD_PAGES
|
|
1403
|
-
}
|
|
1404
|
-
})),
|
|
1405
|
-
container = _renderWithValidation36.container;
|
|
1406
|
-
|
|
1407
|
-
// Function to find an element by its text content
|
|
1408
|
-
function getByTextContent(parent, text) {
|
|
1409
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
1410
|
-
return el.textContent === text;
|
|
1411
|
-
});
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
// Check for section titles
|
|
1415
|
-
var section1Title = getByTextContent(container, 'Section 1');
|
|
1416
|
-
var section2Title = getByTextContent(container, 'Section 2');
|
|
1417
|
-
expect(section1Title).not.toBeUndefined();
|
|
1418
|
-
expect(section2Title).not.toBeUndefined();
|
|
1419
|
-
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1420
|
-
expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
|
|
1421
|
-
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1422
|
-
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
1423
|
-
});
|
|
1424
|
-
it('should render sections if they have show_when checks and pass them', function () {
|
|
1425
|
-
var CHILD_PAGES = [{
|
|
1426
|
-
summaryLayout: {
|
|
1427
|
-
sections: [{
|
|
1428
|
-
title: 'Section 1',
|
|
1429
|
-
columns: 2,
|
|
1430
|
-
fields: ['fieldA', 'fieldB'],
|
|
1431
|
-
show_when: [{
|
|
1432
|
-
field: 'showSection1',
|
|
1433
|
-
op: "=",
|
|
1434
|
-
value: true
|
|
1435
|
-
}]
|
|
1436
|
-
}, {
|
|
1437
|
-
title: 'Section 2',
|
|
1438
|
-
columns: 1,
|
|
1439
|
-
fields: ['fieldC']
|
|
1440
|
-
}]
|
|
1441
|
-
},
|
|
1442
|
-
components: [{
|
|
1443
|
-
fieldId: 'fieldA'
|
|
1444
|
-
}, {
|
|
1445
|
-
fieldId: 'fieldB'
|
|
1446
|
-
}, {
|
|
1447
|
-
fieldId: 'fieldC'
|
|
1448
|
-
}]
|
|
1449
|
-
}];
|
|
1450
|
-
var CONFIG = {
|
|
1451
|
-
title: 'Title'
|
|
1452
|
-
};
|
|
1453
|
-
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
1454
|
-
showSection1: true
|
|
1455
|
-
});
|
|
1456
|
-
var _renderWithValidation37 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1457
|
-
id: ID,
|
|
1458
|
-
entryData: CUSTOM_ENTRY,
|
|
1459
|
-
config: CONFIG,
|
|
1460
|
-
parentCollectionName: "parent",
|
|
1461
|
-
pages: CHILD_PAGES,
|
|
1462
|
-
formData: {},
|
|
1463
|
-
masterPage: {
|
|
1464
|
-
childPages: CHILD_PAGES
|
|
1465
|
-
}
|
|
1466
|
-
})),
|
|
1467
|
-
container = _renderWithValidation37.container;
|
|
1468
|
-
|
|
1469
|
-
// Function to find an element by its text content
|
|
1470
|
-
function getByTextContent(parent, text) {
|
|
1471
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
1472
|
-
return el.textContent === text;
|
|
1473
|
-
});
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
// Check for section titles
|
|
1477
|
-
var section1Title = getByTextContent(container, 'Section 1');
|
|
1478
|
-
var section2Title = getByTextContent(container, 'Section 2');
|
|
1479
|
-
expect(section1Title).not.toBeUndefined();
|
|
1480
|
-
expect(section2Title).not.toBeUndefined();
|
|
1481
|
-
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1482
|
-
expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
|
|
1483
|
-
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1484
|
-
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
1485
|
-
});
|
|
1486
|
-
it('should not render sections if they have show_when checks and fail them', function () {
|
|
1487
|
-
var CHILD_PAGES = [{
|
|
1488
|
-
summaryLayout: {
|
|
1489
|
-
sections: [{
|
|
1490
|
-
title: 'Section 1',
|
|
1491
|
-
columns: 2,
|
|
1492
|
-
fields: ['fieldA', 'fieldB'],
|
|
1493
|
-
show_when: [{
|
|
1494
|
-
field: 'showSection1',
|
|
1495
|
-
op: "=",
|
|
1496
|
-
value: true
|
|
1497
|
-
}]
|
|
1498
|
-
}, {
|
|
1499
|
-
title: 'Section 2',
|
|
1500
|
-
columns: 1,
|
|
1501
|
-
fields: ['fieldC']
|
|
1502
|
-
}]
|
|
1503
|
-
},
|
|
1504
|
-
components: [{
|
|
1505
|
-
fieldId: 'fieldA'
|
|
1506
|
-
}, {
|
|
1507
|
-
fieldId: 'fieldB'
|
|
1508
|
-
}, {
|
|
1509
|
-
fieldId: 'fieldC'
|
|
1510
|
-
}]
|
|
1511
|
-
}];
|
|
1512
|
-
var CONFIG = {
|
|
1513
|
-
title: 'Title'
|
|
1514
|
-
};
|
|
1515
|
-
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
1516
|
-
showSection1: false
|
|
1517
|
-
});
|
|
1518
|
-
var _renderWithValidation38 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1519
|
-
id: ID,
|
|
1520
|
-
entryData: CUSTOM_ENTRY,
|
|
1521
|
-
config: CONFIG,
|
|
1522
|
-
parentCollectionName: "parent",
|
|
1523
|
-
pages: CHILD_PAGES,
|
|
1524
|
-
formData: {},
|
|
1525
|
-
masterPage: {
|
|
1526
|
-
childPages: CHILD_PAGES
|
|
1527
|
-
}
|
|
1528
|
-
})),
|
|
1529
|
-
container = _renderWithValidation38.container;
|
|
1530
|
-
|
|
1531
|
-
// Function to find an element by its text content
|
|
1532
|
-
function getByTextContent(parent, text) {
|
|
1533
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
1534
|
-
return el.textContent === text;
|
|
1535
|
-
});
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
// Check for section titles
|
|
1539
|
-
var section1Title = getByTextContent(container, 'Section 1');
|
|
1540
|
-
var section2Title = getByTextContent(container, 'Section 2');
|
|
1541
|
-
expect(section1Title).toBeUndefined();
|
|
1542
|
-
expect(section2Title).not.toBeUndefined();
|
|
1543
|
-
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
1544
|
-
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
1545
|
-
});
|
|
1546
|
-
it('should not render sections on pages that fail show_when checks', function () {
|
|
1547
|
-
var CHILD_PAGES = [{
|
|
1548
|
-
show_when: [{
|
|
1549
|
-
field: 'testField',
|
|
1550
|
-
op: '=',
|
|
1551
|
-
value: true
|
|
1552
|
-
}],
|
|
1553
|
-
summaryLayout: {
|
|
1554
|
-
sections: [{
|
|
1555
|
-
title: 'Section 1',
|
|
1556
|
-
columns: 2,
|
|
1557
|
-
fields: ['fieldA', 'fieldB'],
|
|
1558
|
-
show_when: [{
|
|
1559
|
-
field: 'showSection1',
|
|
1560
|
-
op: "=",
|
|
1561
|
-
value: true
|
|
1562
|
-
}]
|
|
1563
|
-
}, {
|
|
1564
|
-
title: 'Section 2',
|
|
1565
|
-
columns: 1,
|
|
1566
|
-
fields: ['fieldC']
|
|
1567
|
-
}]
|
|
1568
|
-
},
|
|
1569
|
-
components: [{
|
|
1570
|
-
fieldId: 'fieldA'
|
|
1571
|
-
}, {
|
|
1572
|
-
fieldId: 'fieldB'
|
|
1573
|
-
}, {
|
|
1574
|
-
fieldId: 'fieldC'
|
|
1575
|
-
}]
|
|
1576
|
-
}];
|
|
1577
|
-
var CONFIG = {
|
|
1578
|
-
title: 'Title'
|
|
1579
|
-
};
|
|
1580
|
-
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
1581
|
-
showSection1: false
|
|
1582
|
-
});
|
|
1583
|
-
var _renderWithValidation39 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
|
|
1584
|
-
id: ID,
|
|
1585
|
-
entryData: CUSTOM_ENTRY,
|
|
1586
|
-
config: CONFIG,
|
|
1587
|
-
parentCollectionName: "parent",
|
|
1588
|
-
pages: CHILD_PAGES,
|
|
1589
|
-
formData: {
|
|
1590
|
-
testField: false
|
|
1591
|
-
},
|
|
1592
|
-
masterPage: {
|
|
1593
|
-
childPages: CHILD_PAGES
|
|
1594
|
-
}
|
|
1595
|
-
})),
|
|
1596
|
-
container = _renderWithValidation39.container;
|
|
1597
|
-
|
|
1598
|
-
// Function to find an element by its text content
|
|
1599
|
-
function getByTextContent(parent, text) {
|
|
1600
|
-
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
1601
|
-
return el.textContent === text;
|
|
1602
|
-
});
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
// Check for section titles
|
|
1606
|
-
var section1Title = getByTextContent(container, 'Section 1');
|
|
1607
|
-
var section2Title = getByTextContent(container, 'Section 2');
|
|
1608
|
-
expect(section1Title).toBeUndefined();
|
|
1609
|
-
expect(section2Title).toBeUndefined();
|
|
1610
|
-
});
|
|
1611
|
-
});
|
|
1612
1369
|
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DEFAULT_CLASS = void 0;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
10
|
+
var _FormComponent = _interopRequireDefault(require("../FormComponent"));
|
|
11
|
+
require("./SummaryCardDetails.scss");
|
|
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
|
+
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; }
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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.
|
|
21
|
+
// Local imports.
|
|
22
|
+
// Styles.
|
|
23
|
+
var DEFAULT_CLASS = exports.DEFAULT_CLASS = 'hods-form-summary-card-details';
|
|
24
|
+
var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
25
|
+
var _masterPage$childPage;
|
|
26
|
+
var masterPage = _ref.masterPage,
|
|
27
|
+
childCollections = _ref.childCollections,
|
|
28
|
+
formData = _ref.formData,
|
|
29
|
+
entryData = _ref.entryData,
|
|
30
|
+
classModifiers = _ref.classModifiers,
|
|
31
|
+
hideChildSectionTitles = _ref.hideChildSectionTitles;
|
|
32
|
+
var classes = _utils.default.classBuilder(DEFAULT_CLASS, classModifiers);
|
|
33
|
+
var childMasterPages = (0, _react.useMemo)(function () {
|
|
34
|
+
return childCollections.map(function (childName) {
|
|
35
|
+
return masterPage.childPages.find(function (page) {
|
|
36
|
+
var _page$collection;
|
|
37
|
+
return ((_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name) === childName;
|
|
38
|
+
});
|
|
39
|
+
}).filter(function (e) {
|
|
40
|
+
return !!e;
|
|
41
|
+
});
|
|
42
|
+
}, [masterPage, childCollections]);
|
|
43
|
+
return (masterPage === null || masterPage === void 0 || (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.filter(function (p) {
|
|
44
|
+
return _utils.default.FormPage.show(p, _objectSpread(_objectSpread({}, formData), entryData));
|
|
45
|
+
}).map(function (childPage) {
|
|
46
|
+
var _childPage$summaryLay;
|
|
47
|
+
var allPageComponents = _utils.default.Component.elevateNested(childPage === null || childPage === void 0 ? void 0 : childPage.components, entryData);
|
|
48
|
+
return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.sections.map(function (section) {
|
|
49
|
+
var _section$fields;
|
|
50
|
+
if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (section.type === 'childCollection') {
|
|
54
|
+
var childMasterPage = childMasterPages.find(function (p) {
|
|
55
|
+
return p.collection.name === section.collectionName;
|
|
56
|
+
});
|
|
57
|
+
var childFormData = entryData[section.collectionName.split('.').pop()] || [];
|
|
58
|
+
if (childMasterPage && childFormData.length > 0) {
|
|
59
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h3", {
|
|
60
|
+
className: classes('section-title')
|
|
61
|
+
}, section.title), childFormData.map(function (entry) {
|
|
62
|
+
return /*#__PURE__*/_react.default.createElement(SummaryCardDetails, {
|
|
63
|
+
masterPage: childMasterPage,
|
|
64
|
+
childMasterPages: [],
|
|
65
|
+
formData: _objectSpread(_objectSpread(_objectSpread({}, formData), entryData), entry),
|
|
66
|
+
entryData: entry,
|
|
67
|
+
hideChildSectionTitles: true
|
|
68
|
+
});
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
74
|
+
key: section.title,
|
|
75
|
+
className: classes('section')
|
|
76
|
+
}, !hideChildSectionTitles && /*#__PURE__*/_react.default.createElement("h3", {
|
|
77
|
+
className: classes('section-title')
|
|
78
|
+
}, section.title), /*#__PURE__*/_react.default.createElement("div", {
|
|
79
|
+
className: classes('section-content', "columns-".concat(section.columns))
|
|
80
|
+
}, (_section$fields = section.fields) === null || _section$fields === void 0 ? void 0 : _section$fields.map(function (fieldId) {
|
|
81
|
+
var component = allPageComponents.find(function (comp) {
|
|
82
|
+
return comp.fieldId === fieldId;
|
|
83
|
+
});
|
|
84
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
85
|
+
key: fieldId,
|
|
86
|
+
className: classes('field')
|
|
87
|
+
}, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
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
|
+
}));
|
|
96
|
+
})));
|
|
97
|
+
});
|
|
98
|
+
}).filter(function (e) {
|
|
99
|
+
return !!e;
|
|
100
|
+
})) || null;
|
|
101
|
+
};
|
|
102
|
+
SummaryCardDetails.propTypes = {
|
|
103
|
+
childCollections: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
104
|
+
masterPage: _propTypes.default.shape({
|
|
105
|
+
childPages: _propTypes.default.arrayOf(_propTypes.default.shape({})).isRequired
|
|
106
|
+
}).isRequired,
|
|
107
|
+
formData: _propTypes.default.shape({}).isRequired,
|
|
108
|
+
entryData: _propTypes.default.shape({}).isRequired,
|
|
109
|
+
classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
110
|
+
hideChildSectionTitles: _propTypes.default.bool
|
|
111
|
+
};
|
|
112
|
+
SummaryCardDetails.defaultProps = {
|
|
113
|
+
childCollections: [],
|
|
114
|
+
classModifiers: null,
|
|
115
|
+
hideChildSectionTitles: false
|
|
116
|
+
};
|
|
117
|
+
var _default = exports.default = SummaryCardDetails;
|