@ukhomeoffice/cop-react-form-renderer 5.68.0 → 5.68.2
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/SummaryCard.js +8 -4
- package/dist/components/CollectionSummary/SummaryCard.test.js +4 -0
- package/dist/components/FormComponent/FormComponent.js +1 -0
- package/dist/components/FormRenderer/FormRenderer.js +6 -4
- package/dist/context/ValidationContext/ValidationContext.js +0 -2
- package/dist/utils/CollectionPage/getQuickEditPage.js +7 -1
- 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;
|
|
@@ -185,7 +185,8 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
185
185
|
});
|
|
186
186
|
},
|
|
187
187
|
classModifiers: "primary",
|
|
188
|
-
disabled: quickEdit
|
|
188
|
+
disabled: quickEdit,
|
|
189
|
+
name: "QuickEdit"
|
|
189
190
|
}, DEFAULT_EDIT_LABEL), config.changeAction && typeof onFullEdit === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
190
191
|
id: "".concat(id, ".changeButton"),
|
|
191
192
|
onClick: function onClick() {
|
|
@@ -193,21 +194,24 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
193
194
|
return onFullEdit((_config$changeAction = config.changeAction) === null || _config$changeAction === void 0 ? void 0 : _config$changeAction.page, entryData.id);
|
|
194
195
|
},
|
|
195
196
|
classModifiers: ((_config$changeAction2 = config.changeAction) === null || _config$changeAction2 === void 0 ? void 0 : _config$changeAction2.classModifiers) || DEFAULT_CHANGE_BUTTON_CLASS,
|
|
196
|
-
"aria-label": _utils.default.FormPage.getConditionalText((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.aria_label, entryData)
|
|
197
|
+
"aria-label": _utils.default.FormPage.getConditionalText((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.aria_label, entryData),
|
|
198
|
+
name: "Change"
|
|
197
199
|
}, ((_config$changeAction4 = config.changeAction) === null || _config$changeAction4 === void 0 ? void 0 : _config$changeAction4.label) || DEFAULT_CHANGE_BUTTON_LABEL), config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
198
200
|
id: "".concat(id, ".deleteButton"),
|
|
199
201
|
onClick: function onClick() {
|
|
200
202
|
return onDelete(entryData);
|
|
201
203
|
},
|
|
202
204
|
classModifiers: "secondary",
|
|
203
|
-
"aria-label": _utils.default.FormPage.getConditionalText((_config$deleteAction = config.deleteAction) === null || _config$deleteAction === void 0 ? void 0 : _config$deleteAction.aria_label, entryData)
|
|
205
|
+
"aria-label": _utils.default.FormPage.getConditionalText((_config$deleteAction = config.deleteAction) === null || _config$deleteAction === void 0 ? void 0 : _config$deleteAction.aria_label, entryData),
|
|
206
|
+
name: "Delete"
|
|
204
207
|
}, ((_config$deleteAction2 = config.deleteAction) === null || _config$deleteAction2 === void 0 ? void 0 : _config$deleteAction2.label) || DEFAULT_DELETE_BUTTON_LABEL), config.duplicateAction && typeof onDuplicate === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
205
208
|
id: "".concat(id, ".duplicateButton"),
|
|
206
209
|
onClick: function onClick() {
|
|
207
210
|
onDuplicate(entryData);
|
|
208
211
|
},
|
|
209
212
|
classModifiers: "secondary",
|
|
210
|
-
"aria-label": _utils.default.FormPage.getConditionalText((_config$duplicateActi = config.duplicateAction) === null || _config$duplicateActi === void 0 ? void 0 : _config$duplicateActi.aria_label, entryData)
|
|
213
|
+
"aria-label": _utils.default.FormPage.getConditionalText((_config$duplicateActi = config.duplicateAction) === null || _config$duplicateActi === void 0 ? void 0 : _config$duplicateActi.aria_label, entryData),
|
|
214
|
+
name: "Duplicate"
|
|
211
215
|
}, ((_config$duplicateActi2 = config.duplicateAction) === null || _config$duplicateActi2 === void 0 ? void 0 : _config$duplicateActi2.label) || DEFAULT_DUPLICATE_BUTTON_LABEL))), quickEdit && quickEditPage && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
|
|
212
216
|
page: quickEditPage,
|
|
213
217
|
onAction: function onAction(action, patch) {
|
|
@@ -278,6 +278,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
278
278
|
headerActionDiv = _checkSetup7.headerActionDiv;
|
|
279
279
|
expect(headerActionDiv.children.length).toEqual(1);
|
|
280
280
|
var changeButton = headerActionDiv.children[0];
|
|
281
|
+
expect(changeButton.name).toEqual('Change');
|
|
281
282
|
expect(changeButton.tagName).toEqual('BUTTON');
|
|
282
283
|
expect(changeButton.textContent).toEqual(CONFIG.changeAction.label);
|
|
283
284
|
expect(changeButton.getAttribute('aria-label')).toEqual(CONFIG.changeAction.aria_label[0].text);
|
|
@@ -389,6 +390,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
389
390
|
headerActionDiv = _checkSetup11.headerActionDiv;
|
|
390
391
|
expect(headerActionDiv.children.length).toEqual(1);
|
|
391
392
|
var deleteButton = headerActionDiv.children[0];
|
|
393
|
+
expect(deleteButton.name).toEqual('Delete');
|
|
392
394
|
expect(deleteButton.tagName).toEqual('BUTTON');
|
|
393
395
|
expect(deleteButton.textContent).toEqual(CONFIG.deleteAction.label);
|
|
394
396
|
expect(deleteButton.getAttribute('aria-label')).toEqual(CONFIG.deleteAction.aria_label[0].text);
|
|
@@ -512,6 +514,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
512
514
|
headerActionDiv = _checkSetup15.headerActionDiv;
|
|
513
515
|
expect(headerActionDiv.children.length).toEqual(1);
|
|
514
516
|
var duplicateButton = headerActionDiv.children[0];
|
|
517
|
+
expect(duplicateButton.name).toEqual('Duplicate');
|
|
515
518
|
expect(duplicateButton.tagName).toEqual('BUTTON');
|
|
516
519
|
expect(duplicateButton.textContent).toEqual(CONFIG.duplicateAction.label);
|
|
517
520
|
_react.fireEvent.click(duplicateButton, {});
|
|
@@ -625,6 +628,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
|
|
|
625
628
|
|
|
626
629
|
// Shows edit button but no quick edit
|
|
627
630
|
var editButton = headerActionDiv.children[0];
|
|
631
|
+
expect(editButton.name).toEqual('QuickEdit');
|
|
628
632
|
expect(editButton.tagName).toEqual('BUTTON');
|
|
629
633
|
expect(editButton.textContent).toEqual('Quick Edit');
|
|
630
634
|
expect(container.childNodes[0].childNodes.length).toEqual(2); // Quick edit hidden
|
|
@@ -174,9 +174,9 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
174
174
|
});
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
|
+
clearErrors();
|
|
177
178
|
setGoingBack(true);
|
|
178
179
|
hooks.onGoingBack(e.state ? e.state : null);
|
|
179
|
-
clearErrors();
|
|
180
180
|
if (components && pages && data && (_formState$page = formState.page) !== null && _formState$page !== void 0 && _formState$page.formData && pagePoint === undefined) {
|
|
181
181
|
var submissionData = _utils.default.Format.form({
|
|
182
182
|
pages: pages,
|
|
@@ -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
|
};
|
|
@@ -6,8 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _meetsAllConditions = _interopRequireDefault(require("../Condition/meetsAllConditions"));
|
|
8
8
|
var _showFormPage = _interopRequireDefault(require("../FormPage/showFormPage"));
|
|
9
|
+
var _excluded = ["id"];
|
|
9
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
11
|
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); }
|
|
12
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
13
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
11
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; }
|
|
12
15
|
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; }
|
|
13
16
|
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; }
|
|
@@ -104,7 +107,10 @@ var getQuickEditPage = function getQuickEditPage(masterPage, entryData) {
|
|
|
104
107
|
}];
|
|
105
108
|
|
|
106
109
|
// Need to have the collection data at the top level
|
|
107
|
-
|
|
110
|
+
// Remove ID to stop overwriting top-level form ID.
|
|
111
|
+
var id = entryData.id,
|
|
112
|
+
entryWithNoId = _objectWithoutProperties(entryData, _excluded);
|
|
113
|
+
pageToReturn.formData = _objectSpread(_objectSpread({}, pageToReturn.formData), entryWithNoId);
|
|
108
114
|
delete pageToReturn.title;
|
|
109
115
|
delete pageToReturn.collection;
|
|
110
116
|
return pageToReturn;
|
|
@@ -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
|
});
|