@ukhomeoffice/cop-react-form-renderer 5.67.1 → 5.68.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/dist/components/CollectionSummary/CollectionSummary.js +14 -11
- package/dist/components/CollectionSummary/RenderListView.js +5 -2
- package/dist/components/CollectionSummary/RenderListView.test.js +3 -1
- package/dist/components/CollectionSummary/SummaryCardDetails.js +67 -27
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +43 -6
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +40 -20
- package/dist/components/FormComponent/FormComponent.js +1 -0
- package/dist/components/FormRenderer/FormRenderer.js +5 -3
- package/dist/context/ValidationContext/ValidationContext.js +0 -2
- package/dist/utils/Validate/validatePage.js +4 -0
- package/dist/utils/Validate/validatePage.test.js +25 -0
- package/package.json +1 -1
|
@@ -57,6 +57,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
57
57
|
formData = _ref.formData,
|
|
58
58
|
onAction = _ref.onAction,
|
|
59
59
|
onChange = _ref.onChange,
|
|
60
|
+
onTopLevelChange = _ref.onTopLevelChange,
|
|
60
61
|
pages = _ref.pages;
|
|
61
62
|
var _useHooks = (0, _hooks.useHooks)(),
|
|
62
63
|
hooks = _useHooks.hooks;
|
|
@@ -121,7 +122,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
121
122
|
// validating.
|
|
122
123
|
var childPages = masterPage === null || masterPage === void 0 ? void 0 : masterPage.childPages.map(function (page) {
|
|
123
124
|
return _objectSpread(_objectSpread({}, page), {}, {
|
|
124
|
-
formData: _objectSpread(_objectSpread({},
|
|
125
|
+
formData: _objectSpread(_objectSpread({}, formData), {}, _defineProperty({}, "".concat(config.collectionName.split('.').pop(), "ActiveId"), entry.id))
|
|
125
126
|
});
|
|
126
127
|
});
|
|
127
128
|
var allPagesErrors = (childPages === null || childPages === void 0 ? void 0 : childPages.flatMap(function (page) {
|
|
@@ -182,14 +183,14 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
182
183
|
_utils.default.CollectionPage.duplicateEntry(config.collectionName, formData, entry.id, ((_config$card = config.card) === null || _config$card === void 0 || (_config$card = _config$card.duplicateAction) === null || _config$card === void 0 ? void 0 : _config$card.fieldsToIgnore) || [], {
|
|
183
184
|
isDuplicate: true
|
|
184
185
|
});
|
|
185
|
-
var
|
|
186
|
+
var topLevelCollectionName = config.collectionName.split('.').shift();
|
|
186
187
|
// Report the whole top-level collection as being changed. We have to do this
|
|
187
188
|
// because of how patch is applied to formData on a page submission.
|
|
188
|
-
if (typeof
|
|
189
|
-
|
|
189
|
+
if (typeof onTopLevelChange === 'function') {
|
|
190
|
+
onTopLevelChange({
|
|
190
191
|
target: {
|
|
191
|
-
name:
|
|
192
|
-
value: _utils.default.CollectionPage.getData(
|
|
192
|
+
name: topLevelCollectionName,
|
|
193
|
+
value: _utils.default.CollectionPage.getData(topLevelCollectionName, formData)
|
|
193
194
|
}
|
|
194
195
|
});
|
|
195
196
|
validateEntries();
|
|
@@ -200,14 +201,14 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
200
201
|
return;
|
|
201
202
|
}
|
|
202
203
|
_utils.default.CollectionPage.removeEntry(config.collectionName, formData, entryToDelete.id);
|
|
203
|
-
var
|
|
204
|
+
var topLevelCollectionName = config.collectionName.split('.').shift();
|
|
204
205
|
// Report the whole top-level collection as being changed. We have to do this
|
|
205
206
|
// because of how patch is applied to formData on a page submission.
|
|
206
|
-
if (typeof
|
|
207
|
-
|
|
207
|
+
if (typeof onTopLevelChange === 'function') {
|
|
208
|
+
onTopLevelChange({
|
|
208
209
|
target: {
|
|
209
|
-
name:
|
|
210
|
-
value: _utils.default.CollectionPage.getData(
|
|
210
|
+
name: topLevelCollectionName,
|
|
211
|
+
value: _utils.default.CollectionPage.getData(topLevelCollectionName, formData)
|
|
211
212
|
}
|
|
212
213
|
});
|
|
213
214
|
}
|
|
@@ -362,12 +363,14 @@ CollectionSummary.propTypes = {
|
|
|
362
363
|
}).isRequired,
|
|
363
364
|
onAction: _propTypes.default.func,
|
|
364
365
|
onChange: _propTypes.default.func,
|
|
366
|
+
onTopLevelChange: _propTypes.default.func,
|
|
365
367
|
formData: _propTypes.default.shape({}).isRequired,
|
|
366
368
|
pages: _propTypes.default.arrayOf(_propTypes.default.shape({}))
|
|
367
369
|
};
|
|
368
370
|
CollectionSummary.defaultProps = {
|
|
369
371
|
onAction: null,
|
|
370
372
|
onChange: null,
|
|
373
|
+
onTopLevelChange: null,
|
|
371
374
|
pages: []
|
|
372
375
|
};
|
|
373
376
|
var _default = exports.default = CollectionSummary;
|
|
@@ -80,8 +80,11 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
80
80
|
return _utils.default.Component.elevateNested([component], entryData);
|
|
81
81
|
}).flat().filter(Boolean);
|
|
82
82
|
return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 || (_childPage$summaryLay = _childPage$summaryLay.sections) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.flatMap(function (section) {
|
|
83
|
-
|
|
84
|
-
return
|
|
83
|
+
var summaryFields = section.columns.flatMap(function (column) {
|
|
84
|
+
return column.fields || [];
|
|
85
|
+
});
|
|
86
|
+
if (summaryFields.length) {
|
|
87
|
+
return summaryFields.flatMap(function (fieldId) {
|
|
85
88
|
var component = elevatedComponents.find(function (comp) {
|
|
86
89
|
return comp.fieldId === fieldId;
|
|
87
90
|
});
|
|
@@ -42,13 +42,75 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
42
42
|
return !!e;
|
|
43
43
|
});
|
|
44
44
|
}, [masterPage, childCollections]);
|
|
45
|
+
var getSectionContent = function getSectionContent(section, components, childPage) {
|
|
46
|
+
var columnIndex = 0;
|
|
47
|
+
return section.columns.flatMap(function (column, index) {
|
|
48
|
+
var _column$fields;
|
|
49
|
+
var rowIndex = 0;
|
|
50
|
+
var columnContent = (_column$fields = column.fields) === null || _column$fields === void 0 ? void 0 : _column$fields.flatMap(function (fieldId) {
|
|
51
|
+
var component = components.find(function (comp) {
|
|
52
|
+
return comp.fieldId === fieldId;
|
|
53
|
+
});
|
|
54
|
+
if (!component) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
58
|
+
var containerRows = (0, _getCYARowsForContainer.default)(childPage, component, entryData);
|
|
59
|
+
rowIndex += 1;
|
|
60
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
61
|
+
key: fieldId,
|
|
62
|
+
className: classes('field'),
|
|
63
|
+
style: {
|
|
64
|
+
'--column': columnIndex + 1,
|
|
65
|
+
'--row': rowIndex
|
|
66
|
+
}
|
|
67
|
+
}, containerRows.map(function (subComponent) {
|
|
68
|
+
var _entryData$component$;
|
|
69
|
+
// Put value for current subcomponent at top level
|
|
70
|
+
var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$ = entryData[component.fieldId]) === null || _entryData$component$ === void 0 ? void 0 : _entryData$component$[subComponent.fieldId]));
|
|
71
|
+
return (0, _getComponentRowForCYA.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
|
|
72
|
+
label: subComponent.key
|
|
73
|
+
}), classes, modEntry);
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
rowIndex += 1;
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
78
|
+
key: fieldId,
|
|
79
|
+
className: classes('field'),
|
|
80
|
+
style: {
|
|
81
|
+
'--column': columnIndex + 1,
|
|
82
|
+
'--row': rowIndex
|
|
83
|
+
}
|
|
84
|
+
}, (0, _getComponentRowForCYA.default)(childPage, component, classes, entryData));
|
|
85
|
+
}).filter(function (e) {
|
|
86
|
+
return !!e;
|
|
87
|
+
});
|
|
88
|
+
// If the column that's just been generated has anything in it
|
|
89
|
+
// then we stick a divider on it's right side. The divider isn't
|
|
90
|
+
// passed rowIndex as it spans all rows. columnIndex is incremented
|
|
91
|
+
// twice to account for the divider column too.
|
|
92
|
+
var lastColumn = index === section.columns.length - 1;
|
|
93
|
+
if (!lastColumn && columnContent.length !== 0) {
|
|
94
|
+
columnIndex += 2;
|
|
95
|
+
return [].concat(columnContent, [/*#__PURE__*/_react.default.createElement("div", {
|
|
96
|
+
key: "divider".concat(columnIndex),
|
|
97
|
+
className: classes('divider'),
|
|
98
|
+
style: {
|
|
99
|
+
'--column': columnIndex
|
|
100
|
+
}
|
|
101
|
+
})]);
|
|
102
|
+
}
|
|
103
|
+
return columnContent;
|
|
104
|
+
}).filter(function (e) {
|
|
105
|
+
return !!e;
|
|
106
|
+
});
|
|
107
|
+
};
|
|
45
108
|
return (masterPage === null || masterPage === void 0 || (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.filter(function (p) {
|
|
46
109
|
return _utils.default.FormPage.show(p, _objectSpread(_objectSpread({}, formData), entryData));
|
|
47
110
|
}).map(function (childPage) {
|
|
48
111
|
var _childPage$summaryLay;
|
|
49
112
|
var allPageComponents = _utils.default.Component.elevateNested(childPage === null || childPage === void 0 ? void 0 : childPage.components, entryData);
|
|
50
113
|
return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.sections.map(function (section) {
|
|
51
|
-
var _section$fields;
|
|
52
114
|
if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
|
|
53
115
|
return null;
|
|
54
116
|
}
|
|
@@ -78,33 +140,11 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
78
140
|
}, !hideChildSectionTitles && /*#__PURE__*/_react.default.createElement("h3", {
|
|
79
141
|
className: classes('section-title')
|
|
80
142
|
}, section.title), /*#__PURE__*/_react.default.createElement("div", {
|
|
81
|
-
className: classes('section-content',
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return comp.fieldId === fieldId;
|
|
85
|
-
});
|
|
86
|
-
if (!component) {
|
|
87
|
-
return null;
|
|
143
|
+
className: classes('section-content'),
|
|
144
|
+
style: {
|
|
145
|
+
'--dividers': section.columns.length - 1
|
|
88
146
|
}
|
|
89
|
-
|
|
90
|
-
var containerRows = (0, _getCYARowsForContainer.default)(childPage, component, entryData);
|
|
91
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
92
|
-
key: fieldId,
|
|
93
|
-
className: classes('field')
|
|
94
|
-
}, containerRows.map(function (subComponent) {
|
|
95
|
-
var _entryData$component$;
|
|
96
|
-
// Put value for current subcomponent at top level
|
|
97
|
-
var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$ = entryData[component.fieldId]) === null || _entryData$component$ === void 0 ? void 0 : _entryData$component$[subComponent.fieldId]));
|
|
98
|
-
return (0, _getComponentRowForCYA.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
|
|
99
|
-
label: subComponent.key
|
|
100
|
-
}), classes, modEntry);
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
104
|
-
key: fieldId,
|
|
105
|
-
className: classes('field')
|
|
106
|
-
}, (0, _getComponentRowForCYA.default)(childPage, component, classes, entryData));
|
|
107
|
-
})));
|
|
147
|
+
}, getSectionContent(section, allPageComponents, childPage)));
|
|
108
148
|
});
|
|
109
149
|
}).filter(function (e) {
|
|
110
150
|
return !!e;
|
|
@@ -36,9 +36,12 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
36
36
|
border-bottom: 2px solid #E9EBED;
|
|
37
37
|
|
|
38
38
|
&-content {
|
|
39
|
-
display:
|
|
40
|
-
|
|
39
|
+
display: grid;
|
|
40
|
+
grid-template-columns: repeat(var(--dividers), 1fr 2px) 1fr;
|
|
41
|
+
grid-auto-rows: minmax(100px, 1fr);
|
|
41
42
|
gap: govuk-spacing(2);
|
|
43
|
+
position: relative;
|
|
44
|
+
margin-bottom: govuk-spacing(1);
|
|
42
45
|
|
|
43
46
|
.hods-form-summary-card__field {
|
|
44
47
|
box-sizing: border-box;
|
|
@@ -61,6 +64,7 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
|
|
67
|
+
/*
|
|
64
68
|
&--columns-1,
|
|
65
69
|
&--columns-2,
|
|
66
70
|
&--columns-3 {
|
|
@@ -79,6 +83,9 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
&--columns-2 {
|
|
86
|
+
display: grid;
|
|
87
|
+
grid-template-columns: repeat(2, 1fr);
|
|
88
|
+
|
|
82
89
|
&::after {
|
|
83
90
|
content: "";
|
|
84
91
|
position: absolute;
|
|
@@ -89,12 +96,13 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
89
96
|
left: 50%;
|
|
90
97
|
}
|
|
91
98
|
|
|
92
|
-
|
|
93
|
-
flex: 0 0 calc(50% - 10px);
|
|
94
|
-
}
|
|
99
|
+
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
&--columns-3 {
|
|
103
|
+
display: grid;
|
|
104
|
+
grid-template-columns: repeat(2, 1fr);
|
|
105
|
+
|
|
98
106
|
&::after {
|
|
99
107
|
content: "";
|
|
100
108
|
position: absolute;
|
|
@@ -106,7 +114,10 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
.hods-form-summary-card-details__field {
|
|
109
|
-
|
|
117
|
+
grid-column-start: var("--column");
|
|
118
|
+
grid-column-end: var("--column");
|
|
119
|
+
grid-row-start: var("--row");
|
|
120
|
+
grid-row-end: var("--row");
|
|
110
121
|
|
|
111
122
|
&:nth-child(2)::after {
|
|
112
123
|
content: "";
|
|
@@ -119,6 +130,23 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
119
130
|
}
|
|
120
131
|
}
|
|
121
132
|
}
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
.hods-form-summary-card-details__field {
|
|
136
|
+
grid-column-start: var(--column);
|
|
137
|
+
grid-column-end: var(--column);
|
|
138
|
+
grid-row-start: var(--row);
|
|
139
|
+
grid-row-end: var(--row);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.hods-form-summary-card-details__divider {
|
|
143
|
+
position: absolute;
|
|
144
|
+
height: 100%;
|
|
145
|
+
width: 100%;
|
|
146
|
+
background-color: #E9EBED;
|
|
147
|
+
grid-column-start: var(--column);
|
|
148
|
+
grid-column-end: var(--column);
|
|
149
|
+
}
|
|
122
150
|
}
|
|
123
151
|
}
|
|
124
152
|
}
|
|
@@ -137,6 +165,15 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
|
|
|
137
165
|
display: none;
|
|
138
166
|
}
|
|
139
167
|
|
|
168
|
+
.hods-form-summary-card-details__divider {
|
|
169
|
+
position: absolute;
|
|
170
|
+
height: 0%;
|
|
171
|
+
width: 0%;
|
|
172
|
+
background-color: #E9EBED;
|
|
173
|
+
grid-column-start: var(--column);
|
|
174
|
+
grid-column-end: var(--column);
|
|
175
|
+
}
|
|
176
|
+
|
|
140
177
|
&--columns-2,
|
|
141
178
|
&--columns-3 {
|
|
142
179
|
position: relative;
|
|
@@ -38,12 +38,16 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
38
38
|
summaryLayout: {
|
|
39
39
|
sections: [{
|
|
40
40
|
title: 'Section 1',
|
|
41
|
-
columns:
|
|
42
|
-
|
|
41
|
+
columns: [{
|
|
42
|
+
fields: ['fieldA']
|
|
43
|
+
}, {
|
|
44
|
+
fields: ['fieldB']
|
|
45
|
+
}]
|
|
43
46
|
}, {
|
|
44
47
|
title: 'Section 2',
|
|
45
|
-
columns:
|
|
46
|
-
|
|
48
|
+
columns: [{
|
|
49
|
+
fields: ['fieldC']
|
|
50
|
+
}]
|
|
47
51
|
}]
|
|
48
52
|
},
|
|
49
53
|
components: [{
|
|
@@ -87,8 +91,9 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
87
91
|
summaryLayout: {
|
|
88
92
|
sections: [{
|
|
89
93
|
title: 'Section 1',
|
|
90
|
-
columns:
|
|
91
|
-
|
|
94
|
+
columns: [{
|
|
95
|
+
fields: ['containerComponent']
|
|
96
|
+
}]
|
|
92
97
|
}]
|
|
93
98
|
},
|
|
94
99
|
components: [{
|
|
@@ -156,8 +161,11 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
156
161
|
summaryLayout: {
|
|
157
162
|
sections: [{
|
|
158
163
|
title: 'Section 1',
|
|
159
|
-
columns:
|
|
160
|
-
|
|
164
|
+
columns: [{
|
|
165
|
+
fields: ['fieldA']
|
|
166
|
+
}, {
|
|
167
|
+
fields: ['fieldB']
|
|
168
|
+
}],
|
|
161
169
|
show_when: [{
|
|
162
170
|
field: 'showSection1',
|
|
163
171
|
op: "=",
|
|
@@ -165,8 +173,9 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
165
173
|
}]
|
|
166
174
|
}, {
|
|
167
175
|
title: 'Section 2',
|
|
168
|
-
columns:
|
|
169
|
-
|
|
176
|
+
columns: [{
|
|
177
|
+
fields: ['fieldC']
|
|
178
|
+
}]
|
|
170
179
|
}]
|
|
171
180
|
},
|
|
172
181
|
components: [{
|
|
@@ -213,8 +222,11 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
213
222
|
summaryLayout: {
|
|
214
223
|
sections: [{
|
|
215
224
|
title: 'Section 1',
|
|
216
|
-
columns:
|
|
217
|
-
|
|
225
|
+
columns: [{
|
|
226
|
+
fields: ['fieldA']
|
|
227
|
+
}, {
|
|
228
|
+
fields: ['fieldB']
|
|
229
|
+
}],
|
|
218
230
|
show_when: [{
|
|
219
231
|
field: 'showSection1',
|
|
220
232
|
op: "=",
|
|
@@ -222,8 +234,9 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
222
234
|
}]
|
|
223
235
|
}, {
|
|
224
236
|
title: 'Section 2',
|
|
225
|
-
columns:
|
|
226
|
-
|
|
237
|
+
columns: [{
|
|
238
|
+
fields: ['fieldC']
|
|
239
|
+
}]
|
|
227
240
|
}]
|
|
228
241
|
},
|
|
229
242
|
components: [{
|
|
@@ -273,8 +286,11 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
273
286
|
summaryLayout: {
|
|
274
287
|
sections: [{
|
|
275
288
|
title: 'Section 1',
|
|
276
|
-
columns:
|
|
277
|
-
|
|
289
|
+
columns: [{
|
|
290
|
+
fields: ['fieldA']
|
|
291
|
+
}, {
|
|
292
|
+
fields: ['fieldB']
|
|
293
|
+
}],
|
|
278
294
|
show_when: [{
|
|
279
295
|
field: 'showSection1',
|
|
280
296
|
op: "=",
|
|
@@ -282,8 +298,9 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
282
298
|
}]
|
|
283
299
|
}, {
|
|
284
300
|
title: 'Section 2',
|
|
285
|
-
columns:
|
|
286
|
-
|
|
301
|
+
columns: [{
|
|
302
|
+
fields: ['fieldC']
|
|
303
|
+
}]
|
|
287
304
|
}]
|
|
288
305
|
},
|
|
289
306
|
components: [{
|
|
@@ -337,8 +354,11 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
337
354
|
summaryLayout: {
|
|
338
355
|
sections: [{
|
|
339
356
|
title: 'Hidden Title',
|
|
340
|
-
columns:
|
|
341
|
-
|
|
357
|
+
columns: [{
|
|
358
|
+
fields: ['childfield1']
|
|
359
|
+
}, {
|
|
360
|
+
fields: ['childfield2']
|
|
361
|
+
}]
|
|
342
362
|
}]
|
|
343
363
|
}
|
|
344
364
|
}]
|
|
@@ -302,7 +302,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
302
302
|
setData(newData);
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
|
-
if (((_formState$page3 = formState.page) === null || _formState$page3 === void 0 ? void 0 : _formState$page3.type) === _models.FormPages.PARTIAL_CYA) {
|
|
305
|
+
if (((_formState$page3 = formState.page) === null || _formState$page3 === void 0 ? void 0 : _formState$page3.type) === _models.FormPages.PARTIAL_CYA && !cya.disableTaskSwitch) {
|
|
306
306
|
hubDetails.sections.every(function (section) {
|
|
307
307
|
return section.tasks.every(function (task) {
|
|
308
308
|
if (task.pages.includes(page.pageId) && task.name !== currentTask.name) {
|
|
@@ -383,7 +383,8 @@ var propTypes = {
|
|
|
383
383
|
className: _propTypes.default.string,
|
|
384
384
|
components: _propTypes.default.arrayOf(_propTypes.default.shape({})).isRequired,
|
|
385
385
|
cya: _propTypes.default.shape({
|
|
386
|
-
actions: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({}), _propTypes.default.string]))
|
|
386
|
+
actions: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({}), _propTypes.default.string])),
|
|
387
|
+
disableTaskSwitch: _propTypes.default.bool
|
|
387
388
|
}),
|
|
388
389
|
data: _propTypes.default.shape({
|
|
389
390
|
formStatus: _propTypes.default.shape({
|
|
@@ -412,7 +413,8 @@ var defaultProps = {
|
|
|
412
413
|
className: '',
|
|
413
414
|
classModifiers: [],
|
|
414
415
|
cya: {
|
|
415
|
-
actions: []
|
|
416
|
+
actions: [],
|
|
417
|
+
disableTaskSwitch: false
|
|
416
418
|
},
|
|
417
419
|
data: null,
|
|
418
420
|
hashLink: false,
|
|
@@ -112,7 +112,6 @@ var ValidationContextProvider = function ValidationContextProvider(_ref) {
|
|
|
112
112
|
var pageErrors = _utils.default.Validate.page(_page, queuedErrors);
|
|
113
113
|
var allErrors = hooks.onValidate(_page, pageErrors);
|
|
114
114
|
setErrors(allErrors);
|
|
115
|
-
setQueuedErrors([]);
|
|
116
115
|
return allErrors;
|
|
117
116
|
},
|
|
118
117
|
pages: function pages(_pages) {
|
|
@@ -123,7 +122,6 @@ var ValidationContextProvider = function ValidationContextProvider(_ref) {
|
|
|
123
122
|
return hooks.onValidate(page, pageErrors[index]);
|
|
124
123
|
});
|
|
125
124
|
setErrors(allErrors);
|
|
126
|
-
setQueuedErrors([]);
|
|
127
125
|
return allErrors;
|
|
128
126
|
}
|
|
129
127
|
};
|
|
@@ -8,6 +8,7 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
8
8
|
var _validateComponent = _interopRequireDefault(require("./validateComponent"));
|
|
9
9
|
var _CollectionPage = _interopRequireDefault(require("../CollectionPage"));
|
|
10
10
|
var _showFormPage = _interopRequireDefault(require("../FormPage/showFormPage"));
|
|
11
|
+
var _showComponent = _interopRequireDefault(require("../Component/showComponent"));
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
14
|
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; }
|
|
@@ -34,6 +35,9 @@ var validatePage = function validatePage(page) {
|
|
|
34
35
|
}
|
|
35
36
|
if ((0, _showFormPage.default)(page, data) && Array.isArray(page.components)) {
|
|
36
37
|
var errs = page.components.reduce(function (errors, component) {
|
|
38
|
+
if (!(0, _showComponent.default)(component, data)) {
|
|
39
|
+
return errors;
|
|
40
|
+
}
|
|
37
41
|
var queuedComponentErrors = queuedErrors.length > 0 ? queuedErrors.filter(function (e) {
|
|
38
42
|
return e.showFor ? e.showFor === component.id : e.id === component.id;
|
|
39
43
|
}) : [];
|
|
@@ -762,5 +762,30 @@ describe('utils.Validate.Page', function () {
|
|
|
762
762
|
expect(RESULT[0]).toEqual(_objectSpread({}, QUEUED_ERRORS[0]));
|
|
763
763
|
expect(RESULT[1]).toEqual(_objectSpread({}, QUEUED_ERRORS[1]));
|
|
764
764
|
});
|
|
765
|
+
it('should return any queued errors if the component is not shown', function () {
|
|
766
|
+
var COMPONENTS = [_objectSpread(_objectSpread({}, setup('a', _models.ComponentTypes.TEXT, 'Alpha', true)), {}, {
|
|
767
|
+
show_when: [{
|
|
768
|
+
field: 'b',
|
|
769
|
+
op: '=',
|
|
770
|
+
value: 'yes'
|
|
771
|
+
}]
|
|
772
|
+
})];
|
|
773
|
+
var PAGE = {
|
|
774
|
+
components: COMPONENTS,
|
|
775
|
+
formData: {
|
|
776
|
+
a: 'Value',
|
|
777
|
+
b: 'no'
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
var QUEUED_ERRORS = [{
|
|
781
|
+
id: 'a',
|
|
782
|
+
error: 'Error queued for Alpha 1'
|
|
783
|
+
}, {
|
|
784
|
+
id: 'a',
|
|
785
|
+
error: 'Error queued for Alpha 2'
|
|
786
|
+
}];
|
|
787
|
+
var RESULT = (0, _validatePage.default)(PAGE, QUEUED_ERRORS);
|
|
788
|
+
expect(RESULT.length).toEqual(0);
|
|
789
|
+
});
|
|
765
790
|
});
|
|
766
791
|
});
|