@ukhomeoffice/cop-react-form-renderer 3.26.3 → 3.32.0
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/CheckYourAnswers.js +5 -2
- package/dist/components/CollectionPage/CollectionPage.js +149 -0
- package/dist/components/CollectionPage/CollectionPage.test.js +428 -0
- package/dist/components/CollectionPage/index.js +13 -0
- package/dist/components/FormPage/FormPage.js +6 -1
- package/dist/components/FormRenderer/FormRenderer.js +61 -17
- package/dist/components/PageActions/ActionButton.js +1 -1
- package/dist/components/TaskList/TaskList.js +11 -7
- package/dist/components/TaskList/TaskList.scss +26 -4
- package/dist/components/TaskList/TaskList.test.js +5 -5
- package/dist/models/PageAction.js +5 -1
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +85 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +107 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +6 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +4 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +10 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.js +45 -0
- package/dist/utils/CollectionPage/duplicateCollectionPageActiveEntry.test.js +41 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.js +34 -0
- package/dist/utils/CollectionPage/getCollectionPageActiveIndex.test.js +54 -0
- package/dist/utils/CollectionPage/index.js +23 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.js +69 -0
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +131 -0
- package/dist/utils/Validate/validatePage.js +16 -2
- package/dist/utils/Validate/validatePage.test.js +352 -206
- package/dist/utils/index.js +3 -0
- package/package.json +2 -2
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getCollectionPageActiveIndex = _interopRequireDefault(require("./getCollectionPageActiveIndex"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
// Local imports
|
|
8
|
+
describe('utils.CollectionPage.getCollectionPageActiveIndex', function () {
|
|
9
|
+
it('should return the index of the active item in the collection, if one exists', function () {
|
|
10
|
+
var COLLECTION_NAME = 'test';
|
|
11
|
+
var ACTIVE_ID = '002';
|
|
12
|
+
var FORM_DATA = {
|
|
13
|
+
testActiveId: ACTIVE_ID,
|
|
14
|
+
test: [{
|
|
15
|
+
id: '001'
|
|
16
|
+
}, {
|
|
17
|
+
id: '002'
|
|
18
|
+
}]
|
|
19
|
+
};
|
|
20
|
+
var PAGE = {
|
|
21
|
+
collection: {
|
|
22
|
+
name: COLLECTION_NAME
|
|
23
|
+
},
|
|
24
|
+
formData: FORM_DATA
|
|
25
|
+
};
|
|
26
|
+
expect((0, _getCollectionPageActiveIndex.default)(PAGE.collection.name, PAGE.formData)).toEqual(1);
|
|
27
|
+
});
|
|
28
|
+
it('should return null if no active item can be found in the collection', function () {
|
|
29
|
+
var COLLECTION_NAME = 'test';
|
|
30
|
+
var ACTIVE_ID = '002';
|
|
31
|
+
var FORM_DATA = {
|
|
32
|
+
testActiveId: ACTIVE_ID,
|
|
33
|
+
test: [{
|
|
34
|
+
id: '001'
|
|
35
|
+
}]
|
|
36
|
+
};
|
|
37
|
+
var PAGE = {
|
|
38
|
+
collection: {
|
|
39
|
+
name: COLLECTION_NAME
|
|
40
|
+
},
|
|
41
|
+
formData: FORM_DATA
|
|
42
|
+
};
|
|
43
|
+
expect((0, _getCollectionPageActiveIndex.default)(PAGE.collection.name, PAGE.formData)).toEqual(null);
|
|
44
|
+
});
|
|
45
|
+
it('should return null if formData is null', function () {
|
|
46
|
+
var COLLECTION_NAME = 'test';
|
|
47
|
+
var PAGE = {
|
|
48
|
+
collection: {
|
|
49
|
+
name: COLLECTION_NAME
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
expect((0, _getCollectionPageActiveIndex.default)(PAGE.collection.name, null)).toEqual(null);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _duplicateCollectionPageActiveEntry = _interopRequireDefault(require("./duplicateCollectionPageActiveEntry"));
|
|
9
|
+
|
|
10
|
+
var _getCollectionPageActiveIndex = _interopRequireDefault(require("./getCollectionPageActiveIndex"));
|
|
11
|
+
|
|
12
|
+
var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
// Local imports
|
|
17
|
+
var CollectionPage = {
|
|
18
|
+
duplicateActiveEntry: _duplicateCollectionPageActiveEntry.default,
|
|
19
|
+
getActiveIndex: _getCollectionPageActiveIndex.default,
|
|
20
|
+
mergePages: _mergeCollectionPages.default
|
|
21
|
+
};
|
|
22
|
+
var _default = CollectionPage;
|
|
23
|
+
exports.default = _default;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _showFormPageCYA = _interopRequireDefault(require("../FormPage/showFormPageCYA"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
+
|
|
16
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
|
|
18
|
+
var createMasterPage = function createMasterPage(page) {
|
|
19
|
+
return _objectSpread(_objectSpread({}, page), {}, {
|
|
20
|
+
title: page.collection.name.charAt(0).toUpperCase() + page.collection.name.slice(1)
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var mergeIntoMasterPage = function mergeIntoMasterPage(page, masterPage) {
|
|
25
|
+
masterPage.collection = _objectSpread(_objectSpread({}, masterPage.collection), page.collection);
|
|
26
|
+
masterPage.components = [].concat(masterPage.components, page.components);
|
|
27
|
+
masterPage.formData = _objectSpread({}, page.formData);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Loop over an array of pages, merging any CollectionPages into a
|
|
31
|
+
* single master page for that collection. A master page is created
|
|
32
|
+
* for each unique collection.name that exists.
|
|
33
|
+
* These master pages contain all the fields needed to represent an
|
|
34
|
+
* entry in the collection.
|
|
35
|
+
* The master page for each collection is positioned at the index
|
|
36
|
+
* of the first CollectionPage in that collection.
|
|
37
|
+
* @param { array } pages Array of pages in the form.
|
|
38
|
+
* @returns An array of the same pages, with a master page for each collection.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
var mergeCollectionPages = function mergeCollectionPages(pages) {
|
|
43
|
+
var masterPages = {};
|
|
44
|
+
return pages.map(function (page) {
|
|
45
|
+
var _page$collection;
|
|
46
|
+
|
|
47
|
+
if ((_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name && (0, _showFormPageCYA.default)(page, page.formData)) {
|
|
48
|
+
if (!masterPages[page.collection.name]) {
|
|
49
|
+
// If no master page exists for this collection.name, then
|
|
50
|
+
// we kick one off using this page as a template.
|
|
51
|
+
masterPages[page.collection.name] = createMasterPage(page);
|
|
52
|
+
return masterPages[page.collection.name];
|
|
53
|
+
} else {
|
|
54
|
+
// If a master page already exists for this collection.name
|
|
55
|
+
// then we just merge this page into it and remove this page
|
|
56
|
+
// from the array.
|
|
57
|
+
mergeIntoMasterPage(page, masterPages[page.collection.name]);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return page;
|
|
63
|
+
}).filter(function (page) {
|
|
64
|
+
return !!page;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
var _default = mergeCollectionPages;
|
|
69
|
+
exports.default = _default;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
// Local imports
|
|
8
|
+
describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
9
|
+
var TEXT_COMP = {
|
|
10
|
+
id: 'testText',
|
|
11
|
+
fieldId: 'testText',
|
|
12
|
+
type: 'text'
|
|
13
|
+
};
|
|
14
|
+
var DATE_COMP = {
|
|
15
|
+
id: 'testDate',
|
|
16
|
+
fieldId: 'testDate',
|
|
17
|
+
type: 'date'
|
|
18
|
+
};
|
|
19
|
+
it('should return the same array if no pages belong to collections', function () {
|
|
20
|
+
var PAGES = [{
|
|
21
|
+
id: 'page1'
|
|
22
|
+
}, {
|
|
23
|
+
id: 'page2'
|
|
24
|
+
}];
|
|
25
|
+
expect((0, _mergeCollectionPages.default)(PAGES)).toEqual(PAGES);
|
|
26
|
+
});
|
|
27
|
+
it('should merge pages from the same collection into a single page', function () {
|
|
28
|
+
var PAGES = [{
|
|
29
|
+
id: 'page1',
|
|
30
|
+
collection: {
|
|
31
|
+
name: 'collection'
|
|
32
|
+
},
|
|
33
|
+
components: [TEXT_COMP]
|
|
34
|
+
}, {
|
|
35
|
+
id: 'page2',
|
|
36
|
+
collection: {
|
|
37
|
+
name: 'collection'
|
|
38
|
+
},
|
|
39
|
+
components: [DATE_COMP]
|
|
40
|
+
}];
|
|
41
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
42
|
+
expect(RESULT.length).toEqual(1);
|
|
43
|
+
expect(RESULT[0]).toEqual({
|
|
44
|
+
id: 'page1',
|
|
45
|
+
title: 'Collection',
|
|
46
|
+
collection: {
|
|
47
|
+
name: 'collection'
|
|
48
|
+
},
|
|
49
|
+
components: [TEXT_COMP, DATE_COMP],
|
|
50
|
+
formData: {}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('should leave non-collection pages unaffected', function () {
|
|
54
|
+
var PAGES = [{
|
|
55
|
+
id: 'page1',
|
|
56
|
+
collection: {
|
|
57
|
+
name: 'collection'
|
|
58
|
+
},
|
|
59
|
+
components: [TEXT_COMP]
|
|
60
|
+
}, {
|
|
61
|
+
id: 'page2',
|
|
62
|
+
collection: {
|
|
63
|
+
name: 'collection'
|
|
64
|
+
},
|
|
65
|
+
components: [DATE_COMP]
|
|
66
|
+
}, {
|
|
67
|
+
id: 'page3'
|
|
68
|
+
}];
|
|
69
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
70
|
+
expect(RESULT.length).toEqual(2);
|
|
71
|
+
expect(RESULT[0]).toEqual({
|
|
72
|
+
id: 'page1',
|
|
73
|
+
title: 'Collection',
|
|
74
|
+
collection: {
|
|
75
|
+
name: 'collection'
|
|
76
|
+
},
|
|
77
|
+
components: [TEXT_COMP, DATE_COMP],
|
|
78
|
+
formData: {}
|
|
79
|
+
});
|
|
80
|
+
expect(RESULT[1]).toEqual({
|
|
81
|
+
id: 'page3'
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it('should handle multiple collections', function () {
|
|
85
|
+
var PAGES = [{
|
|
86
|
+
id: 'page1',
|
|
87
|
+
collection: {
|
|
88
|
+
name: 'collection1'
|
|
89
|
+
},
|
|
90
|
+
components: []
|
|
91
|
+
}, {
|
|
92
|
+
id: 'page2',
|
|
93
|
+
collection: {
|
|
94
|
+
name: 'collection1'
|
|
95
|
+
},
|
|
96
|
+
components: []
|
|
97
|
+
}, {
|
|
98
|
+
id: 'page3',
|
|
99
|
+
collection: {
|
|
100
|
+
name: 'collection2'
|
|
101
|
+
},
|
|
102
|
+
components: []
|
|
103
|
+
}, {
|
|
104
|
+
id: 'page4',
|
|
105
|
+
collection: {
|
|
106
|
+
name: 'collection2'
|
|
107
|
+
},
|
|
108
|
+
components: []
|
|
109
|
+
}];
|
|
110
|
+
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
111
|
+
expect(RESULT.length).toEqual(2);
|
|
112
|
+
expect(RESULT[0]).toEqual({
|
|
113
|
+
id: 'page1',
|
|
114
|
+
collection: {
|
|
115
|
+
name: 'collection1'
|
|
116
|
+
},
|
|
117
|
+
title: 'Collection1',
|
|
118
|
+
components: [],
|
|
119
|
+
formData: {}
|
|
120
|
+
});
|
|
121
|
+
expect(RESULT[1]).toEqual({
|
|
122
|
+
id: 'page3',
|
|
123
|
+
collection: {
|
|
124
|
+
name: 'collection2'
|
|
125
|
+
},
|
|
126
|
+
title: 'Collection2',
|
|
127
|
+
components: [],
|
|
128
|
+
formData: {}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -9,6 +9,8 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
9
9
|
|
|
10
10
|
var _validateComponent = _interopRequireDefault(require("./validateComponent"));
|
|
11
11
|
|
|
12
|
+
var _CollectionPage = _interopRequireDefault(require("../CollectionPage"));
|
|
13
|
+
|
|
12
14
|
var _showFormPage = _interopRequireDefault(require("../FormPage/showFormPage"));
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -25,12 +27,24 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
25
27
|
* @returns An array containing all of the errors.
|
|
26
28
|
*/
|
|
27
29
|
var validatePage = function validatePage(page) {
|
|
30
|
+
var data = page.formData;
|
|
31
|
+
|
|
32
|
+
if (page.collection) {
|
|
33
|
+
var activeIndex = _CollectionPage.default.getActiveIndex(page.collection.name, page.formData);
|
|
34
|
+
|
|
35
|
+
if (activeIndex !== null) {
|
|
36
|
+
var _page$formData$page$c;
|
|
37
|
+
|
|
38
|
+
data = (_page$formData$page$c = page.formData[page.collection.name]) === null || _page$formData$page$c === void 0 ? void 0 : _page$formData$page$c[activeIndex];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
28
42
|
if ((0, _showFormPage.default)(page, page.formData) && Array.isArray(page.components)) {
|
|
29
43
|
var errs = page.components.reduce(function (errors, component) {
|
|
30
|
-
var componentErrors = (0, _validateComponent.default)(component,
|
|
44
|
+
var componentErrors = (0, _validateComponent.default)(component, data, data);
|
|
31
45
|
return errors.concat(componentErrors).flat().map(function (err) {
|
|
32
46
|
return !!err ? _objectSpread(_objectSpread({}, err), {}, {
|
|
33
|
-
error: _copReactComponents.Utils.interpolateString(err.error,
|
|
47
|
+
error: _copReactComponents.Utils.interpolateString(err.error, data)
|
|
34
48
|
}) : err;
|
|
35
49
|
});
|
|
36
50
|
}, []).filter(function (e) {
|