@ukhomeoffice/cop-react-form-renderer 5.71.4 → 5.71.6
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/RenderListView.js +6 -2
- package/dist/components/CollectionSummary/RenderListView.test.js +7 -1
- package/dist/components/CollectionSummary/SummaryCard.js +2 -2
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +9 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +26 -6
- package/dist/utils/CollectionPage/getQuickEditPage.js +7 -4
- package/dist/utils/CollectionPage/getQuickEditPage.test.js +14 -29
- package/dist/utils/Validate/validateEmail.js +1 -1
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
11
11
|
var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
|
|
12
|
+
var _Condition = _interopRequireDefault(require("../../utils/Condition"));
|
|
12
13
|
require("./RenderListView.scss");
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
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); }
|
|
@@ -80,7 +81,10 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
80
81
|
return _utils.default.Component.elevateNested([component], entryData);
|
|
81
82
|
}).flat().filter(Boolean);
|
|
82
83
|
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
|
-
var
|
|
84
|
+
var filteredColumns = section.columns.filter(function (column) {
|
|
85
|
+
return _Condition.default.meetsAll(column, _objectSpread(_objectSpread({}, childPage.formData), entryData));
|
|
86
|
+
});
|
|
87
|
+
var summaryFields = filteredColumns.flatMap(function (column) {
|
|
84
88
|
return column.fields || [];
|
|
85
89
|
});
|
|
86
90
|
if (summaryFields.length) {
|
|
@@ -88,7 +92,7 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
88
92
|
var component = elevatedComponents.find(function (comp) {
|
|
89
93
|
return comp.fieldId === fieldId;
|
|
90
94
|
});
|
|
91
|
-
if (!component) {
|
|
95
|
+
if (!component || !_Condition.default.meetsAll(component, _objectSpread(_objectSpread({}, childPage.formData), entryData))) {
|
|
92
96
|
return null;
|
|
93
97
|
}
|
|
94
98
|
return (0, _getComponentRowForCYA.default)(childPage, component, listClass, entryData);
|
|
@@ -19,6 +19,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
19
19
|
label: 'Value 3',
|
|
20
20
|
value: 'Value 3'
|
|
21
21
|
},
|
|
22
|
+
condition: 'test',
|
|
22
23
|
index: 0
|
|
23
24
|
};
|
|
24
25
|
var MASTER_PAGE = {
|
|
@@ -26,7 +27,12 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
26
27
|
summaryLayout: {
|
|
27
28
|
sections: [{
|
|
28
29
|
columns: [{
|
|
29
|
-
fields: ['item1', 'item2', 'item3']
|
|
30
|
+
fields: ['item1', 'item2', 'item3'],
|
|
31
|
+
show_when: {
|
|
32
|
+
field: "condition",
|
|
33
|
+
op: "in",
|
|
34
|
+
values: ["test"]
|
|
35
|
+
}
|
|
30
36
|
}]
|
|
31
37
|
}]
|
|
32
38
|
},
|
|
@@ -67,8 +67,8 @@ var SummaryCard = function SummaryCard(_ref) {
|
|
|
67
67
|
setQuickEdit = _useState2[1];
|
|
68
68
|
var classes = _copReactComponents.Utils.classBuilder(DEFAULT_CLASS, classModifiers, config.className);
|
|
69
69
|
var quickEditPage = (0, _react.useMemo)(function () {
|
|
70
|
-
return config.quickEdit ? (0, _getQuickEditPage.default)(masterPage, entryData) : null;
|
|
71
|
-
}, [masterPage, config, entryData, quickEdit]);
|
|
70
|
+
return config.quickEdit ? (0, _getQuickEditPage.default)(masterPage, formData, entryData) : null;
|
|
71
|
+
}, [masterPage, config, formData, entryData, quickEdit]);
|
|
72
72
|
|
|
73
73
|
// The validation context used here is a custom one for Summary Cards,
|
|
74
74
|
// not the standard context. See SummaryCardValidationContext.jsx.
|
|
@@ -40,7 +40,15 @@ var duplicateCollectionPageEntry = function duplicateCollectionPageEntry(collect
|
|
|
40
40
|
fieldsToIgnore.forEach(function (field) {
|
|
41
41
|
return delete newEntry[field];
|
|
42
42
|
});
|
|
43
|
-
collectionData.
|
|
43
|
+
var insertionIndex = collectionData.findIndex(function (entry) {
|
|
44
|
+
return entry.id === entryId;
|
|
45
|
+
}) + 1;
|
|
46
|
+
if (insertionIndex === -1) {
|
|
47
|
+
collectionData.push(newEntry);
|
|
48
|
+
} else {
|
|
49
|
+
collectionData.splice(insertionIndex, 0, newEntry);
|
|
50
|
+
}
|
|
51
|
+
|
|
44
52
|
// eslint-disable-next-line no-param-reassign
|
|
45
53
|
formData["".concat(collectionName.split('.').pop(), "ActiveId")] = newEntry.id;
|
|
46
54
|
return newEntryId;
|
|
@@ -24,6 +24,26 @@ describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
|
|
|
24
24
|
expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")]).toBeTruthy();
|
|
25
25
|
expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")] === '1').toBeFalsy();
|
|
26
26
|
});
|
|
27
|
+
it('should put the new entry under the original one', function () {
|
|
28
|
+
var _FORM_DATA2;
|
|
29
|
+
var FORM_DATA = (_FORM_DATA2 = {}, _defineProperty(_FORM_DATA2, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA2, COLLECTION_NAME, [{
|
|
30
|
+
id: '1',
|
|
31
|
+
value: 'value1'
|
|
32
|
+
}, {
|
|
33
|
+
id: '2',
|
|
34
|
+
value: 'value2'
|
|
35
|
+
}, {
|
|
36
|
+
id: '3',
|
|
37
|
+
value: 'value1'
|
|
38
|
+
}]), _FORM_DATA2);
|
|
39
|
+
(0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '1');
|
|
40
|
+
expect(FORM_DATA[COLLECTION_NAME].length).toEqual(4);
|
|
41
|
+
expect(FORM_DATA[COLLECTION_NAME][1].value).toEqual(FORM_DATA[COLLECTION_NAME][0].value);
|
|
42
|
+
expect(FORM_DATA[COLLECTION_NAME][1].id).toBeTruthy();
|
|
43
|
+
expect(FORM_DATA[COLLECTION_NAME][1].id === '1').toBeFalsy();
|
|
44
|
+
expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")]).toBeTruthy();
|
|
45
|
+
expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")] === '1').toBeFalsy();
|
|
46
|
+
});
|
|
27
47
|
it('should duplicate entries in nested collections correctly', function () {
|
|
28
48
|
var FORM_DATA = {
|
|
29
49
|
parentsActiveId: '2',
|
|
@@ -54,8 +74,8 @@ describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
|
|
|
54
74
|
expect((0, _getCollectionPageActiveId.default)('parents.children', FORM_DATA) === '2').toBeFalsy();
|
|
55
75
|
});
|
|
56
76
|
it('should ignore fields in the fieldToIgnore array', function () {
|
|
57
|
-
var
|
|
58
|
-
var FORM_DATA = (
|
|
77
|
+
var _FORM_DATA3;
|
|
78
|
+
var FORM_DATA = (_FORM_DATA3 = {}, _defineProperty(_FORM_DATA3, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA3, COLLECTION_NAME, [OBJ]), _FORM_DATA3);
|
|
59
79
|
;
|
|
60
80
|
var FIELDS_TO_IGNORE = ['value'];
|
|
61
81
|
(0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '1', FIELDS_TO_IGNORE);
|
|
@@ -66,8 +86,8 @@ describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
|
|
|
66
86
|
expect(FORM_DATA[COLLECTION_NAME][1].value).toBeUndefined();
|
|
67
87
|
});
|
|
68
88
|
it('should add fields from the fieldsToAdd object', function () {
|
|
69
|
-
var
|
|
70
|
-
var FORM_DATA = (
|
|
89
|
+
var _FORM_DATA4;
|
|
90
|
+
var FORM_DATA = (_FORM_DATA4 = {}, _defineProperty(_FORM_DATA4, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA4, COLLECTION_NAME, [OBJ]), _FORM_DATA4);
|
|
71
91
|
;
|
|
72
92
|
var FIELDS_TO_ADD = {
|
|
73
93
|
addedKey: 'addedValue'
|
|
@@ -81,8 +101,8 @@ describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
|
|
|
81
101
|
expect(FORM_DATA[COLLECTION_NAME][1].addedKey).toEqual('addedValue');
|
|
82
102
|
});
|
|
83
103
|
it('should do nothing if an entry with the given id does not exist', function () {
|
|
84
|
-
var
|
|
85
|
-
var FORM_DATA = (
|
|
104
|
+
var _FORM_DATA5, _expect$toEqual;
|
|
105
|
+
var FORM_DATA = (_FORM_DATA5 = {}, _defineProperty(_FORM_DATA5, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA5, COLLECTION_NAME, [OBJ]), _FORM_DATA5);
|
|
86
106
|
;
|
|
87
107
|
(0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '0');
|
|
88
108
|
expect(FORM_DATA).toEqual((_expect$toEqual = {}, _defineProperty(_expect$toEqual, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_expect$toEqual, COLLECTION_NAME, [OBJ]), _expect$toEqual));
|
|
@@ -50,16 +50,17 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
50
50
|
* editable or not.
|
|
51
51
|
*
|
|
52
52
|
* @param {object} masterPage The master page for the collection.
|
|
53
|
+
* @param {object} formData The top-level formData object.
|
|
53
54
|
* @param {object} entryData The data for the current collection entry.
|
|
54
55
|
* @returns Page suitble for rendering in a QuickEdit
|
|
55
56
|
*/
|
|
56
|
-
var getQuickEditPage = function getQuickEditPage(masterPage, entryData) {
|
|
57
|
+
var getQuickEditPage = function getQuickEditPage(masterPage, formData, entryData) {
|
|
57
58
|
if (!masterPage) {
|
|
58
59
|
return null;
|
|
59
60
|
}
|
|
60
61
|
var fullComponents = [];
|
|
61
62
|
masterPage.childPages.forEach(function (page) {
|
|
62
|
-
if (!page.summaryQuickEdit || !(0, _showFormPage.default)(page, _objectSpread(_objectSpread({},
|
|
63
|
+
if (!page.summaryQuickEdit || !(0, _showFormPage.default)(page, _objectSpread(_objectSpread({}, formData), entryData))) {
|
|
63
64
|
return;
|
|
64
65
|
}
|
|
65
66
|
page.summaryQuickEdit.forEach(function (quickEditComponent) {
|
|
@@ -81,7 +82,7 @@ var getQuickEditPage = function getQuickEditPage(masterPage, entryData) {
|
|
|
81
82
|
// that as a specific test for when the component should be quick
|
|
82
83
|
// editable - it doesn't get spread to the merged object.
|
|
83
84
|
if (quickEditComponent.show_when) {
|
|
84
|
-
if ((0, _meetsAllConditions.default)(quickEditComponent.show_when, _objectSpread(_objectSpread({},
|
|
85
|
+
if ((0, _meetsAllConditions.default)(quickEditComponent.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
|
|
85
86
|
fullComponents.push(_objectSpread(_objectSpread({}, mergedComponent), {}, {
|
|
86
87
|
show_when: originalComponent.show_when || []
|
|
87
88
|
}));
|
|
@@ -93,7 +94,9 @@ var getQuickEditPage = function getQuickEditPage(masterPage, entryData) {
|
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
// Put components and actions onto page object
|
|
96
|
-
var pageToReturn = _objectSpread({}, masterPage.childPages[0])
|
|
97
|
+
var pageToReturn = _objectSpread(_objectSpread({}, masterPage.childPages[0]), {}, {
|
|
98
|
+
formData: formData
|
|
99
|
+
});
|
|
97
100
|
pageToReturn.components = fullComponents;
|
|
98
101
|
pageToReturn.actions = [{
|
|
99
102
|
type: 'save',
|
|
@@ -9,6 +9,15 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
9
9
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
10
|
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); }
|
|
11
11
|
describe('Utils.CollectionPage.getQuickEditPage', function () {
|
|
12
|
+
var FORM_DATA = {
|
|
13
|
+
items: [{
|
|
14
|
+
id: '123',
|
|
15
|
+
testText1: 'value 1',
|
|
16
|
+
testText2: 'value 2',
|
|
17
|
+
conditionText: 'true',
|
|
18
|
+
testText3: 'value 3'
|
|
19
|
+
}]
|
|
20
|
+
};
|
|
12
21
|
var MASTER_PAGE = {
|
|
13
22
|
childPages: [{
|
|
14
23
|
id: 'firstPage',
|
|
@@ -44,15 +53,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
|
|
|
44
53
|
fieldId: 'testText2',
|
|
45
54
|
required: true
|
|
46
55
|
}],
|
|
47
|
-
formData:
|
|
48
|
-
items: [{
|
|
49
|
-
id: '123',
|
|
50
|
-
testText1: 'value 1',
|
|
51
|
-
testText2: 'value 2',
|
|
52
|
-
conditionText: 'true',
|
|
53
|
-
testText3: 'value 3'
|
|
54
|
-
}]
|
|
55
|
-
},
|
|
56
|
+
formData: FORM_DATA,
|
|
56
57
|
summaryQuickEdit: [{
|
|
57
58
|
use: "testText2",
|
|
58
59
|
show_when: {
|
|
@@ -69,15 +70,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
|
|
|
69
70
|
fieldId: 'testText3',
|
|
70
71
|
required: true
|
|
71
72
|
}],
|
|
72
|
-
formData:
|
|
73
|
-
items: [{
|
|
74
|
-
id: '123',
|
|
75
|
-
testText1: 'value 1',
|
|
76
|
-
testText2: 'value 2',
|
|
77
|
-
conditionText: 'true',
|
|
78
|
-
testText3: 'value 3'
|
|
79
|
-
}]
|
|
80
|
-
},
|
|
73
|
+
formData: FORM_DATA,
|
|
81
74
|
summaryQuickEdit: ["testText3"]
|
|
82
75
|
}]
|
|
83
76
|
};
|
|
@@ -103,15 +96,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
|
|
|
103
96
|
fieldId: 'testText3',
|
|
104
97
|
required: true
|
|
105
98
|
}],
|
|
106
|
-
formData:
|
|
107
|
-
items: [{
|
|
108
|
-
id: '123',
|
|
109
|
-
testText1: 'value 1',
|
|
110
|
-
testText2: 'value 2',
|
|
111
|
-
conditionText: 'true',
|
|
112
|
-
testText3: 'value 3'
|
|
113
|
-
}]
|
|
114
|
-
},
|
|
99
|
+
formData: FORM_DATA,
|
|
115
100
|
actions: [{
|
|
116
101
|
type: 'save',
|
|
117
102
|
label: 'Save',
|
|
@@ -131,7 +116,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
|
|
|
131
116
|
testText3: 'value 3'
|
|
132
117
|
};
|
|
133
118
|
it('should return a quick edit page', function () {
|
|
134
|
-
var createdPage = (0, _getQuickEditPage.default)(MASTER_PAGE, ENTRY_DATA);
|
|
119
|
+
var createdPage = (0, _getQuickEditPage.default)(MASTER_PAGE, FORM_DATA, ENTRY_DATA);
|
|
135
120
|
expect(createdPage).toMatchObject(EXPECTED_OUTPUT);
|
|
136
121
|
});
|
|
137
122
|
it('should return a quick edit page without components that fail the quick edit show_when', function () {
|
|
@@ -144,7 +129,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
|
|
|
144
129
|
var CUSTOM_ENTRY_DATA = _objectSpread(_objectSpread({}, ENTRY_DATA), {}, {
|
|
145
130
|
conditionText: 'false'
|
|
146
131
|
});
|
|
147
|
-
var createdPage = (0, _getQuickEditPage.default)(MASTER_PAGE, CUSTOM_ENTRY_DATA);
|
|
132
|
+
var createdPage = (0, _getQuickEditPage.default)(MASTER_PAGE, FORM_DATA, CUSTOM_ENTRY_DATA);
|
|
148
133
|
expect(createdPage).toMatchObject(CUSTOM_OUTPUT);
|
|
149
134
|
});
|
|
150
135
|
});
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
// eslint-disable-next-line no-control-regex
|
|
8
8
|
// const EMAIL_REGEX = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/i;
|
|
9
|
-
var HODS_EMAIL_REGEX = /^[a-z0-9._
|
|
9
|
+
var HODS_EMAIL_REGEX = /^[a-z0-9._\-']+@(digital\.)?homeoffice.gov.uk$/i;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Validates an email address, ensuring it is in the correct domain and
|