@ukhomeoffice/cop-react-form-renderer 6.16.0-beta → 7.0.0-charlie
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/Answer.js +5 -2
- package/dist/components/CheckYourAnswers/Answer.test.js +8 -7
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +86 -68
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +22 -22
- package/dist/components/CollectionPage/CollectionPage.js +3 -3
- package/dist/components/CollectionPage/CollectionPage.test.js +12 -12
- package/dist/components/CollectionSummary/BannerStrip.js +22 -21
- package/dist/components/CollectionSummary/BannerStrip.test.js +8 -8
- package/dist/components/CollectionSummary/CollectionSummary.js +105 -99
- package/dist/components/CollectionSummary/CollectionSummary.test.js +23 -19
- package/dist/components/CollectionSummary/Confirmation.js +16 -10
- package/dist/components/CollectionSummary/Confirmation.test.js +12 -11
- package/dist/components/CollectionSummary/RenderListView.js +78 -65
- package/dist/components/CollectionSummary/RenderListView.test.js +18 -12
- package/dist/components/CollectionSummary/SummaryCard.js +83 -72
- package/dist/components/CollectionSummary/SummaryCard.test.js +105 -101
- package/dist/components/CollectionSummary/SummaryCardButtons.js +17 -13
- package/dist/components/CollectionSummary/SummaryCardButtons.test.js +3 -2
- package/dist/components/CollectionSummary/SummaryCardDetails.js +72 -67
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +12 -12
- package/dist/components/CollectionSummary/SummaryCardValidationContext.js +6 -5
- package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +29 -13
- package/dist/components/FormComponent/Collection.js +91 -82
- package/dist/components/FormComponent/Collection.test.js +16 -15
- package/dist/components/FormComponent/Container.js +21 -22
- package/dist/components/FormComponent/Container.test.js +9 -8
- package/dist/components/FormComponent/FormComponent.js +7 -8
- package/dist/components/FormComponent/FormComponent.test.js +18 -13
- package/dist/components/FormPage/FormPage.js +29 -23
- package/dist/components/FormPage/FormPage.test.js +10 -10
- package/dist/components/FormRenderer/FormRenderer.js +81 -92
- package/dist/components/FormRenderer/FormRenderer.test.js +23 -24
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-component-with-nested-questions-visible-elsewhere.json +118 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-nested-answers-hidden-by-option-visible-elsewhere.json +113 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-page-nested-component.json +26003 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-hidden-component-with-nested-questions-visible-elsewhere.json +12 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-nested-answers-hidden-by-option-visible-elsewhere.json +12 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-page-nested-component.json +63 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-hidden-component-with-nested-questions-visible-elsewhere-removed.json +11 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-nested-answers-hidden-by-option-visible-elsewhere-removed.json +12 -0
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-page-nested-component.json +63 -0
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +18 -16
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +31 -0
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutesUtils.js +44 -35
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutesUtils.test.js +1 -2
- package/dist/components/PageActions/ActionButton.js +12 -6
- package/dist/components/PageActions/ActionButton.test.js +5 -5
- package/dist/components/PageActions/PageActions.js +7 -5
- package/dist/components/PageActions/PageActions.test.js +5 -4
- package/dist/components/SummaryList/GroupAction.js +14 -8
- package/dist/components/SummaryList/GroupAction.test.js +5 -4
- package/dist/components/SummaryList/RowAction.js +12 -6
- package/dist/components/SummaryList/RowAction.test.js +5 -4
- package/dist/components/SummaryList/SummaryList.js +54 -49
- package/dist/components/SummaryList/SummaryList.test.js +33 -19
- package/dist/components/SummaryList/SummaryListHeadingRow.js +9 -3
- package/dist/components/SummaryList/SummaryListHeadingRowWithAction.js +20 -12
- package/dist/components/SummaryList/SummaryListRow.js +16 -11
- package/dist/components/SummaryList/SummaryListTitleRow.js +7 -3
- package/dist/components/TaskList/Task.js +20 -17
- package/dist/components/TaskList/Task.test.js +8 -7
- package/dist/components/TaskList/TaskList.js +68 -45
- package/dist/components/TaskList/TaskList.test.js +11 -11
- package/dist/components/TaskList/TaskState.js +5 -3
- package/dist/components/TaskList/TaskState.test.js +8 -7
- package/dist/context/HooksContext/HooksContext.js +6 -5
- package/dist/context/HooksContext/HooksContext.test.js +14 -6
- package/dist/context/HooksContext/index.js +1 -2
- package/dist/context/ValidationContext/ValidationContext.js +6 -5
- package/dist/context/ValidationContext/ValidationContext.test.js +33 -9
- package/dist/context/ValidationContext/index.js +1 -2
- package/dist/hooks/index.js +1 -2
- package/dist/hooks/useRefData.js +1 -2
- package/dist/index.js +1 -2
- package/dist/setupTests.js +23 -18
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +19 -16
- package/dist/utils/CheckYourAnswers/getSummaryListRowForDetails.js +5 -5
- package/dist/utils/CollectionPage/getQuickEditPage.js +2 -2
- package/dist/utils/Component/cleanAttributes.test.js +1 -2
- package/dist/utils/Component/getComponent.js +38 -28
- package/dist/utils/Component/getDefaultValueFromConfig.js +1 -2
- package/dist/utils/Component/isEditable.test.js +1 -2
- package/dist/utils/Component/wrapInFormGroup.js +10 -4
- package/dist/utils/Format/formatDataForComponent.test.js +1 -2
- package/dist/utils/Format/formatDataForPage.test.js +1 -2
- package/dist/utils/Validate/validateDate.test.js +1 -2
- package/dist/utils/Validate/validateMultifile.test.js +1 -2
- package/package.json +43 -13
|
@@ -14,8 +14,8 @@ var _getCYARowsForContainer = _interopRequireDefault(require("../../utils/CheckY
|
|
|
14
14
|
var _showComponent = _interopRequireDefault(require("../../utils/Component/showComponent"));
|
|
15
15
|
var _Condition = _interopRequireDefault(require("../../utils/Condition"));
|
|
16
16
|
require("./SummaryCardDetails.scss");
|
|
17
|
-
|
|
18
|
-
function _interopRequireWildcard(e, r) { if (!
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
19
19
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
20
|
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; }
|
|
21
21
|
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; }
|
|
@@ -55,23 +55,23 @@ const SummaryCardDetails = _ref => {
|
|
|
55
55
|
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
56
56
|
const containerRows = (0, _getCYARowsForContainer.default)(childPage, component, entryData);
|
|
57
57
|
rowIndex += 1;
|
|
58
|
-
return /*#__PURE__*/
|
|
59
|
-
key: fieldId,
|
|
58
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
60
59
|
className: classes('field'),
|
|
61
60
|
style: {
|
|
62
61
|
'--column': columnIndex + 1,
|
|
63
62
|
'--row': rowIndex
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
},
|
|
64
|
+
children: containerRows.map(subComponent => {
|
|
65
|
+
var _entryData$component$;
|
|
66
|
+
// Put value for current subcomponent at top level
|
|
67
|
+
const modEntry = _objectSpread(_objectSpread({}, entryData), {
|
|
68
|
+
[subComponent.fieldId]: (_entryData$component$ = entryData[component.fieldId]) === null || _entryData$component$ === void 0 ? void 0 : _entryData$component$[subComponent.fieldId]
|
|
69
|
+
});
|
|
70
|
+
return (0, _getSummaryListRowForDetails.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
|
|
71
|
+
label: subComponent.key
|
|
72
|
+
}), classes, modEntry, optionalFieldPlaceholder);
|
|
73
|
+
})
|
|
74
|
+
}, fieldId);
|
|
75
75
|
}
|
|
76
76
|
if (component.type === _models.ComponentTypes.COLLECTION) {
|
|
77
77
|
const collectionRows = (0, _getCYARowsForCollection.default)(_objectSpread(_objectSpread({}, childPage), {}, {
|
|
@@ -79,45 +79,46 @@ const SummaryCardDetails = _ref => {
|
|
|
79
79
|
}), component, entryData[component.id]);
|
|
80
80
|
rowIndex += 1;
|
|
81
81
|
let collectionHeadingIndex = 0;
|
|
82
|
-
return /*#__PURE__*/
|
|
83
|
-
key: fieldId,
|
|
82
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
84
83
|
className: classes('field'),
|
|
85
84
|
style: {
|
|
86
85
|
'--column': columnIndex + 1,
|
|
87
86
|
'--row': rowIndex
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
87
|
+
},
|
|
88
|
+
children: collectionRows.map(subComponent => {
|
|
89
|
+
var _entryData$component$2;
|
|
90
|
+
// Put value for current subComponent at the top level
|
|
91
|
+
const modEntry = _objectSpread(_objectSpread({}, entryData), {
|
|
92
|
+
[subComponent.fieldId]: (_entryData$component$2 = entryData[component.fieldId]) === null || _entryData$component$2 === void 0 ? void 0 : _entryData$component$2[subComponent.fieldId]
|
|
93
|
+
});
|
|
94
|
+
const rowContent = (0, _getSummaryListRowForDetails.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
|
|
95
|
+
label: subComponent.key
|
|
96
|
+
}), classes, modEntry, optionalFieldPlaceholder);
|
|
97
|
+
// Because collections are flat, we need to identify the subsequent titles (2, 3, 4... etc) in order to apply appropriate spacing
|
|
98
|
+
if (subComponent.type === 'title') {
|
|
99
|
+
collectionHeadingIndex += 1;
|
|
100
|
+
if (collectionHeadingIndex > 1) {
|
|
101
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
102
|
+
style: {
|
|
103
|
+
marginTop: '40px'
|
|
104
|
+
},
|
|
105
|
+
children: rowContent
|
|
106
|
+
});
|
|
107
|
+
}
|
|
107
108
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
})
|
|
109
|
+
return rowContent;
|
|
110
|
+
})
|
|
111
|
+
}, fieldId);
|
|
111
112
|
}
|
|
112
113
|
rowIndex += 1;
|
|
113
|
-
return /*#__PURE__*/
|
|
114
|
-
key: fieldId,
|
|
114
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
115
115
|
className: classes('field'),
|
|
116
116
|
style: {
|
|
117
117
|
'--column': columnIndex + 1,
|
|
118
118
|
'--row': rowIndex
|
|
119
|
-
}
|
|
120
|
-
|
|
119
|
+
},
|
|
120
|
+
children: (0, _getSummaryListRowForDetails.default)(childPage, component, classes, entryData, optionalFieldPlaceholder)
|
|
121
|
+
}, fieldId);
|
|
121
122
|
});
|
|
122
123
|
}).filter(e => !!e);
|
|
123
124
|
// If the column that's just been generated has anything in it
|
|
@@ -127,13 +128,12 @@ const SummaryCardDetails = _ref => {
|
|
|
127
128
|
const lastColumn = index === columns.length - 1;
|
|
128
129
|
if (!lastColumn && columnContent.length !== 0) {
|
|
129
130
|
columnIndex += 2;
|
|
130
|
-
return [].concat(columnContent, [/*#__PURE__*/
|
|
131
|
-
key: "divider".concat(columnIndex),
|
|
131
|
+
return [].concat(columnContent, [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
132
132
|
className: classes('divider'),
|
|
133
133
|
style: {
|
|
134
134
|
'--column': columnIndex
|
|
135
135
|
}
|
|
136
|
-
})]);
|
|
136
|
+
}, "divider".concat(columnIndex))]);
|
|
137
137
|
}
|
|
138
138
|
return columnContent;
|
|
139
139
|
}).filter(e => !!e);
|
|
@@ -149,31 +149,36 @@ const SummaryCardDetails = _ref => {
|
|
|
149
149
|
const childMasterPage = childMasterPages.find(p => p.collection.name === section.collectionName);
|
|
150
150
|
const childFormData = entryData[section.collectionName.split('.').pop()] || [];
|
|
151
151
|
if (childMasterPage && childFormData.length > 0) {
|
|
152
|
-
return /*#__PURE__*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
152
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
153
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
154
|
+
className: classes('section-title'),
|
|
155
|
+
children: section.title
|
|
156
|
+
}), childFormData.map(entry => /*#__PURE__*/(0, _jsxRuntime.jsx)(SummaryCardDetails, {
|
|
157
|
+
masterPage: childMasterPage,
|
|
158
|
+
childMasterPages: [],
|
|
159
|
+
formData: _objectSpread(_objectSpread(_objectSpread({}, formData), entryData), entry),
|
|
160
|
+
entryData: entry,
|
|
161
|
+
hideChildSectionTitles: true,
|
|
162
|
+
optionalFieldPlaceholder: optionalFieldPlaceholder
|
|
163
|
+
}))]
|
|
164
|
+
});
|
|
162
165
|
}
|
|
163
166
|
return null;
|
|
164
167
|
}
|
|
165
168
|
const columns = section.columns.filter(column => _Condition.default.meetsAll(column, _objectSpread(_objectSpread({}, childPage.formData), entryData)));
|
|
166
|
-
return /*#__PURE__*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
169
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
170
|
+
className: classes('section'),
|
|
171
|
+
children: [!hideChildSectionTitles && /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
172
|
+
className: classes('section-title'),
|
|
173
|
+
children: _utils.default.FormPage.getConditionalText(section.title, _objectSpread(_objectSpread({}, childPage.formData), entryData))
|
|
174
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("dl", {
|
|
175
|
+
className: classes('section-content'),
|
|
176
|
+
style: {
|
|
177
|
+
'--dividers': columns.length - 1
|
|
178
|
+
},
|
|
179
|
+
children: getSectionContent(columns, allPageComponents, childPage)
|
|
180
|
+
})]
|
|
181
|
+
}, section.title);
|
|
177
182
|
});
|
|
178
183
|
}).filter(e => !!e)) || null;
|
|
179
184
|
};
|
|
@@ -4,8 +4,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
4
4
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
5
5
|
var _setupTests = require("../../setupTests");
|
|
6
6
|
var _SummaryCardDetails = _interopRequireWildcard(require("./SummaryCardDetails"));
|
|
7
|
-
|
|
8
|
-
function _interopRequireWildcard(e, r) { if (!
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
11
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -62,7 +62,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
62
62
|
};
|
|
63
63
|
const {
|
|
64
64
|
container
|
|
65
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
65
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
66
66
|
masterPage: MASTER_PAGE,
|
|
67
67
|
childMasterPages: [],
|
|
68
68
|
formData: {},
|
|
@@ -128,7 +128,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
128
128
|
};
|
|
129
129
|
const {
|
|
130
130
|
container
|
|
131
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
131
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
132
132
|
masterPage: MASTER_PAGE,
|
|
133
133
|
childMasterPages: [],
|
|
134
134
|
formData: {},
|
|
@@ -217,7 +217,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
217
217
|
};
|
|
218
218
|
const {
|
|
219
219
|
container
|
|
220
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
220
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
221
221
|
masterPage: MASTER_PAGE,
|
|
222
222
|
childMasterPages: [],
|
|
223
223
|
formData: {},
|
|
@@ -280,7 +280,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
280
280
|
});
|
|
281
281
|
const {
|
|
282
282
|
container
|
|
283
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
283
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
284
284
|
masterPage: MASTER_PAGE,
|
|
285
285
|
childMasterPages: [],
|
|
286
286
|
formData: {},
|
|
@@ -340,7 +340,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
340
340
|
});
|
|
341
341
|
const {
|
|
342
342
|
container
|
|
343
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
343
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
344
344
|
masterPage: MASTER_PAGE,
|
|
345
345
|
childMasterPages: [],
|
|
346
346
|
formData: {},
|
|
@@ -395,7 +395,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
395
395
|
};
|
|
396
396
|
const {
|
|
397
397
|
container
|
|
398
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
398
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
399
399
|
masterPage: MASTER_PAGE,
|
|
400
400
|
childMasterPages: [],
|
|
401
401
|
formData: {},
|
|
@@ -461,7 +461,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
461
461
|
});
|
|
462
462
|
const {
|
|
463
463
|
container
|
|
464
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
464
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
465
465
|
masterPage: MASTER_PAGE,
|
|
466
466
|
childMasterPages: [],
|
|
467
467
|
formData: {
|
|
@@ -511,7 +511,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
511
511
|
};
|
|
512
512
|
const {
|
|
513
513
|
container
|
|
514
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
514
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
515
515
|
masterPage: MASTER_PAGE,
|
|
516
516
|
childMasterPages: [],
|
|
517
517
|
formData: {
|
|
@@ -576,7 +576,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
576
576
|
const CHILD_COLLECTIONS = ['childCollection'];
|
|
577
577
|
const {
|
|
578
578
|
container
|
|
579
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
579
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
580
580
|
masterPage: MASTER_PAGE,
|
|
581
581
|
childCollections: CHILD_COLLECTIONS,
|
|
582
582
|
formData: {},
|
|
@@ -632,7 +632,7 @@ describe('components.CollectionSummary.SummaryCardDetails', () => {
|
|
|
632
632
|
};
|
|
633
633
|
const {
|
|
634
634
|
container
|
|
635
|
-
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/
|
|
635
|
+
} = (0, _setupTests.renderWithValidation)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardDetails.default, {
|
|
636
636
|
masterPage: MASTER_PAGE,
|
|
637
637
|
childMasterPages: [],
|
|
638
638
|
formData: {},
|
|
@@ -9,9 +9,9 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
var _ValidationContext = require("../../context/ValidationContext");
|
|
10
10
|
var _hooks = require("../../hooks");
|
|
11
11
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
function
|
|
14
|
-
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 && {}.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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
15
|
/* eslint-disable react/jsx-no-constructed-context-values, no-shadow */
|
|
16
16
|
// Global imports
|
|
17
17
|
|
|
@@ -54,15 +54,16 @@ const SummaryCardValidationContextProvider = _ref => {
|
|
|
54
54
|
return allErrors;
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
return /*#__PURE__*/
|
|
57
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ValidationContext.ValidationContext.Provider, {
|
|
58
58
|
value: {
|
|
59
59
|
addErrors,
|
|
60
60
|
errors: errors === null ? [].concat(initialErrors) : errors,
|
|
61
61
|
resetQuickEditErrors,
|
|
62
62
|
clearTopLevelErrorsForCard,
|
|
63
63
|
validate
|
|
64
|
-
}
|
|
65
|
-
|
|
64
|
+
},
|
|
65
|
+
children: children
|
|
66
|
+
});
|
|
66
67
|
};
|
|
67
68
|
var _default = exports.default = SummaryCardValidationContextProvider;
|
|
68
69
|
SummaryCardValidationContextProvider.propTypes = {
|
|
@@ -7,9 +7,9 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
7
7
|
var _hooks = require("../../hooks");
|
|
8
8
|
var _context = require("../../context");
|
|
9
9
|
var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
function
|
|
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 && {}.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
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
13
|
// Global imports
|
|
14
14
|
|
|
15
15
|
// Local imports
|
|
@@ -29,18 +29,31 @@ const TestComponent = _ref => {
|
|
|
29
29
|
addErrors(customErrors);
|
|
30
30
|
}
|
|
31
31
|
}, [customErrors]);
|
|
32
|
-
return /*#__PURE__*/
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
33
|
+
children: [typeof addErrors === 'function' && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
34
|
+
children: "addErrors is a function"
|
|
35
|
+
}), typeof resetQuickEditErrors === 'function' && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
36
|
+
children: "resetQuickEditErrors is a function"
|
|
37
|
+
}), typeof validate.page === 'function' && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
38
|
+
children: "validate.page is a function"
|
|
39
|
+
}), Array.isArray(errors) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
40
|
+
children: ["errors is an array of length ", errors.length]
|
|
41
|
+
}), (errors === null || errors === void 0 ? void 0 : errors.length) > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copReactComponents.ErrorSummary, {
|
|
42
|
+
errors: errors
|
|
43
|
+
})]
|
|
44
|
+
});
|
|
35
45
|
};
|
|
36
46
|
describe('context.SummaryCardValidationContext', () => {
|
|
37
47
|
it('should appropriately set up the context', async () => {
|
|
38
48
|
const {
|
|
39
49
|
container
|
|
40
|
-
} = (0, _react.render)(/*#__PURE__*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
} = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_context.HooksContextProvider, {
|
|
51
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardValidationContext.default, {
|
|
52
|
+
entryId: "123",
|
|
53
|
+
topLevelErrors: [],
|
|
54
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {})
|
|
55
|
+
})
|
|
56
|
+
}));
|
|
44
57
|
expect(container.childNodes.length).toEqual(4);
|
|
45
58
|
expect(container.textContent).toContain('addErrors is a function');
|
|
46
59
|
expect(container.textContent).toContain('resetQuickEditErrors is a function');
|
|
@@ -66,10 +79,13 @@ describe('context.SummaryCardValidationContext', () => {
|
|
|
66
79
|
}];
|
|
67
80
|
const {
|
|
68
81
|
container
|
|
69
|
-
} = (0, _react.render)(/*#__PURE__*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
} = (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_context.HooksContextProvider, {
|
|
83
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SummaryCardValidationContext.default, {
|
|
84
|
+
entryId: "123",
|
|
85
|
+
topLevelErrors: TOP_LEVEL_ERRORS,
|
|
86
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(TestComponent, {})
|
|
87
|
+
})
|
|
88
|
+
}));
|
|
73
89
|
expect(container.childNodes.length).toEqual(5);
|
|
74
90
|
expect(container.textContent).toContain('addErrors is a function');
|
|
75
91
|
expect(container.textContent).toContain('resetQuickEditErrors is a function');
|
|
@@ -12,12 +12,12 @@ var _models = require("../../models");
|
|
|
12
12
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
13
13
|
var _Container = _interopRequireDefault(require("./Container"));
|
|
14
14
|
require("./Collection.scss");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
const _excluded = ["firstOnlyLabel"];
|
|
16
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
-
function
|
|
18
|
-
function
|
|
19
|
-
function
|
|
20
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
19
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
20
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
21
21
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
22
|
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; }
|
|
23
23
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
@@ -96,86 +96,95 @@ const Collection = _ref => {
|
|
|
96
96
|
}, [config.minimumEntries, value.length]);
|
|
97
97
|
const labels = _objectSpread(_objectSpread({}, _models.CollectionLabels), config.labels);
|
|
98
98
|
const classes = _utils.default.classBuilder(DEFAULT_CLASS, [], config.className);
|
|
99
|
-
return /*#__PURE__*/
|
|
99
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
100
100
|
className: classes(),
|
|
101
|
-
id: config.id
|
|
102
|
-
}, config.label && /*#__PURE__*/_react.default.createElement(_copReactComponents.Label, {
|
|
103
101
|
id: config.id,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
index
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
102
|
+
children: [config.label && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copReactComponents.Label, {
|
|
103
|
+
id: config.id,
|
|
104
|
+
required: config.required,
|
|
105
|
+
className: classes('title'),
|
|
106
|
+
children: config.label
|
|
107
|
+
}), Array.isArray(value) && value.map((item, index) => {
|
|
108
|
+
var _config$removeLocatio;
|
|
109
|
+
const fullPath = "".concat(config.full_path || config.fieldId, "[").concat(index, "]");
|
|
110
|
+
const labelCount = (config.countOffset || 0) + index + 1;
|
|
111
|
+
const itemTitle = _utils.default.interpolateString(labels.item, _objectSpread(_objectSpread({}, item), {}, {
|
|
112
|
+
index: labelCount
|
|
113
|
+
}));
|
|
114
|
+
const removeLabel = _utils.default.interpolateString(labels.remove, _objectSpread(_objectSpread({}, item), {}, {
|
|
115
|
+
index: labelCount
|
|
116
|
+
}));
|
|
117
|
+
const removeStyle = config.disableAddAndRemove || index === 0 && config.minimumEntries ? '' : (_config$removeLocatio = config.removeLocation) !== null && _config$removeLocatio !== void 0 ? _config$removeLocatio : 'start';
|
|
118
|
+
const addStyle = index !== 0 && config.subsequentItemStyle ? config.subsequentItemStyle : {};
|
|
119
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
120
|
+
className: "".concat(classes('item')),
|
|
121
|
+
style: addStyle,
|
|
122
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_copReactComponents.Label, {
|
|
123
|
+
id: item.id,
|
|
124
|
+
required: true,
|
|
125
|
+
className: classes('item-title'),
|
|
126
|
+
children: [itemTitle, removeStyle === 'start' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copReactComponents.Button, {
|
|
127
|
+
onClick: () => onRemoveItem(item),
|
|
128
|
+
classModifiers: "secondary",
|
|
129
|
+
children: removeLabel
|
|
130
|
+
})]
|
|
131
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Container.default, {
|
|
132
|
+
container: {
|
|
133
|
+
id: item.id,
|
|
134
|
+
fieldId: item.id,
|
|
135
|
+
type: 'container',
|
|
136
|
+
required: config.required,
|
|
137
|
+
full_path: fullPath,
|
|
138
|
+
components: config.item.map(component => {
|
|
139
|
+
const {
|
|
140
|
+
firstOnlyLabel
|
|
141
|
+
} = component,
|
|
142
|
+
cleanedComponent = _objectWithoutProperties(component, _excluded);
|
|
143
|
+
let {
|
|
144
|
+
hint
|
|
145
|
+
} = component;
|
|
146
|
+
if (config.restrictHint && index > 0) {
|
|
147
|
+
hint = undefined;
|
|
148
|
+
}
|
|
149
|
+
let {
|
|
150
|
+
label
|
|
151
|
+
} = component;
|
|
152
|
+
if (index === 0) {
|
|
153
|
+
var _component$firstOnlyL;
|
|
154
|
+
label = (_component$firstOnlyL = component.firstOnlyLabel) !== null && _component$firstOnlyL !== void 0 ? _component$firstOnlyL : component.label;
|
|
155
|
+
}
|
|
156
|
+
return _objectSpread(_objectSpread({}, cleanedComponent), {}, {
|
|
157
|
+
hint,
|
|
158
|
+
readonly: !!(config !== null && config !== void 0 && config.readonly || component.readonly),
|
|
159
|
+
label: _utils.default.interpolateString(label, _objectSpread(_objectSpread({}, item), {}, {
|
|
160
|
+
index: labelCount
|
|
161
|
+
})),
|
|
162
|
+
full_path: "".concat(fullPath, ".").concat(component.fieldId)
|
|
163
|
+
});
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
value: item,
|
|
167
|
+
formData: formData,
|
|
168
|
+
onChange: onCollectionChange,
|
|
169
|
+
onTopLevelChange: onTopLevelChange,
|
|
170
|
+
wrap: wrap
|
|
171
|
+
}), removeStyle === 'end' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copReactComponents.ButtonGroup, {
|
|
172
|
+
className: "govuk-!-margin-top-2",
|
|
173
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_copReactComponents.Button, {
|
|
174
|
+
onClick: () => onRemoveItem(item),
|
|
175
|
+
classModifiers: "secondary",
|
|
176
|
+
children: removeLabel
|
|
177
|
+
})
|
|
178
|
+
})]
|
|
179
|
+
}, item.id);
|
|
180
|
+
}), !config.disableAddAndRemove && /*#__PURE__*/(0, _jsxRuntime.jsx)(_copReactComponents.ButtonGroup, {
|
|
181
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_copReactComponents.Button, {
|
|
182
|
+
onClick: onAddAnother,
|
|
183
|
+
classModifiers: "secondary",
|
|
184
|
+
children: getAddLabel(labels)
|
|
185
|
+
})
|
|
186
|
+
})]
|
|
187
|
+
});
|
|
179
188
|
};
|
|
180
189
|
Collection.propTypes = {
|
|
181
190
|
config: _propTypes.default.shape({
|