@ukhomeoffice/cop-react-form-renderer 4.35.0 → 4.36.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/FormRenderer/helpers/cleanHiddenNestedData.js +16 -0
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +45 -0
- package/dist/models/ComponentTypes.js +4 -0
- package/dist/utils/Component/getComponent.js +45 -0
- package/dist/utils/Component/getComponentTests/getComponent.list.test.js +50 -0
- package/dist/utils/Component/getComponentTests/getComponent.paragraph.test.js +49 -0
- package/package.json +1 -1
|
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
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; }
|
|
9
|
+
|
|
10
|
+
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; }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
7
14
|
var parentComponents = ['radios'];
|
|
8
15
|
|
|
9
16
|
var cleanHiddenNestedData = function cleanHiddenNestedData(patch, page) {
|
|
@@ -17,6 +24,15 @@ var cleanHiddenNestedData = function cleanHiddenNestedData(patch, page) {
|
|
|
17
24
|
delete patch[id];
|
|
18
25
|
});
|
|
19
26
|
});
|
|
27
|
+
|
|
28
|
+
if (page.collection && patch[page.collection.name]) {
|
|
29
|
+
patch[page.collection.name] = patch[page.collection.name].map(function (entry) {
|
|
30
|
+
return cleanHiddenNestedData(entry, _objectSpread(_objectSpread({}, page), {}, {
|
|
31
|
+
collection: undefined
|
|
32
|
+
}));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
20
36
|
return patch;
|
|
21
37
|
};
|
|
22
38
|
|
|
@@ -44,6 +44,51 @@ describe('components', function () {
|
|
|
44
44
|
expect(updatedPatch['nested1']).toBeFalsy();
|
|
45
45
|
expect(updatedPatch['nested2']).toBeTruthy();
|
|
46
46
|
});
|
|
47
|
+
it('remove data corresponding to hidden nested components within a collection', function () {
|
|
48
|
+
var patch = {
|
|
49
|
+
collectionName: [{
|
|
50
|
+
parent: 'option1',
|
|
51
|
+
nested1: 'should be included',
|
|
52
|
+
nested2: 'should not be included'
|
|
53
|
+
}, {
|
|
54
|
+
parent: 'option2',
|
|
55
|
+
nested1: 'should not be included',
|
|
56
|
+
nested2: 'should be included'
|
|
57
|
+
}]
|
|
58
|
+
};
|
|
59
|
+
var page = {
|
|
60
|
+
id: 'page',
|
|
61
|
+
name: 'page',
|
|
62
|
+
title: 'Page',
|
|
63
|
+
collection: {
|
|
64
|
+
name: 'collectionName'
|
|
65
|
+
},
|
|
66
|
+
components: [{
|
|
67
|
+
id: 'parent',
|
|
68
|
+
type: 'radios',
|
|
69
|
+
data: {
|
|
70
|
+
options: [{
|
|
71
|
+
value: 'option1',
|
|
72
|
+
nested: [{
|
|
73
|
+
id: 'nested1',
|
|
74
|
+
fieldId: 'nested1'
|
|
75
|
+
}]
|
|
76
|
+
}, {
|
|
77
|
+
value: 'option2',
|
|
78
|
+
nested: [{
|
|
79
|
+
id: 'nested2',
|
|
80
|
+
fieldId: 'nested2'
|
|
81
|
+
}]
|
|
82
|
+
}]
|
|
83
|
+
}
|
|
84
|
+
}]
|
|
85
|
+
};
|
|
86
|
+
var updatedPatch = (0, _cleanHiddenNestedData.default)(patch, page);
|
|
87
|
+
expect(updatedPatch['collectionName'][0]['nested1']).toBeTruthy();
|
|
88
|
+
expect(updatedPatch['collectionName'][0]['nested2']).toBeFalsy();
|
|
89
|
+
expect(updatedPatch['collectionName'][1]['nested1']).toBeFalsy();
|
|
90
|
+
expect(updatedPatch['collectionName'][1]['nested2']).toBeTruthy();
|
|
91
|
+
});
|
|
47
92
|
});
|
|
48
93
|
});
|
|
49
94
|
});
|
|
@@ -17,6 +17,8 @@ var TYPE_FILE = 'file';
|
|
|
17
17
|
var TYPE_HEADING = 'heading';
|
|
18
18
|
var TYPE_HTML = 'html';
|
|
19
19
|
var TYPE_INSET_TEXT = 'inset-text';
|
|
20
|
+
var TYPE_LIST = 'list';
|
|
21
|
+
var TYPE_PARAGRAPH = 'paragraph';
|
|
20
22
|
var TYPE_PHONE_NUMBER = 'phone-number';
|
|
21
23
|
var TYPE_RADIOS = 'radios';
|
|
22
24
|
var TYPE_SELECT = 'select';
|
|
@@ -38,6 +40,8 @@ var ComponentTypes = {
|
|
|
38
40
|
HEADING: TYPE_HEADING,
|
|
39
41
|
HTML: TYPE_HTML,
|
|
40
42
|
INSET_TEXT: TYPE_INSET_TEXT,
|
|
43
|
+
LIST: TYPE_LIST,
|
|
44
|
+
PARAGRAPH: TYPE_PARAGRAPH,
|
|
41
45
|
PHONE_NUMBER: TYPE_PHONE_NUMBER,
|
|
42
46
|
RADIOS: TYPE_RADIOS,
|
|
43
47
|
SELECT: TYPE_SELECT,
|
|
@@ -23,14 +23,23 @@ var _wrapInFormGroup = _interopRequireDefault(require("./wrapInFormGroup"));
|
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
25
|
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
26
32
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
27
33
|
|
|
34
|
+
var LIST_CLASS = 'govuk-list';
|
|
35
|
+
var BODY_CLASS = 'govuk-body';
|
|
28
36
|
/**
|
|
29
37
|
* Separate function for each component type for the sake of
|
|
30
38
|
* code clarity - having the additional bits and pieces in the
|
|
31
39
|
* switch statement increases the cyclomatic complexity and
|
|
32
40
|
* makes it much harder to follow what's going on.
|
|
33
41
|
*/
|
|
42
|
+
|
|
34
43
|
var getAlert = function getAlert(config) {
|
|
35
44
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
36
45
|
|
|
@@ -118,6 +127,36 @@ var getInsetText = function getInsetText(config) {
|
|
|
118
127
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.InsetText, attrs, config.content);
|
|
119
128
|
};
|
|
120
129
|
|
|
130
|
+
var getList = function getList(config) {
|
|
131
|
+
var _attrs$items;
|
|
132
|
+
|
|
133
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
134
|
+
var tagName = attrs.ordered ? 'ol' : 'ul';
|
|
135
|
+
var bullet = attrs.ordered ? 'number' : 'bullet';
|
|
136
|
+
|
|
137
|
+
var classes = _copReactComponents.Utils.classBuilder(LIST_CLASS, bullet);
|
|
138
|
+
|
|
139
|
+
var content = (_attrs$items = attrs.items) === null || _attrs$items === void 0 ? void 0 : _attrs$items.map(function (item) {
|
|
140
|
+
return "<li>".concat(item, "</li>");
|
|
141
|
+
}).join('');
|
|
142
|
+
return getHTML(_objectSpread(_objectSpread({}, attrs), {}, {
|
|
143
|
+
className: classes(),
|
|
144
|
+
tagName: tagName,
|
|
145
|
+
content: content,
|
|
146
|
+
type: _models.ComponentTypes.HTML
|
|
147
|
+
}));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var getParagraph = function getParagraph(config) {
|
|
151
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
152
|
+
return getHTML(_objectSpread(_objectSpread({
|
|
153
|
+
className: BODY_CLASS
|
|
154
|
+
}, attrs), {}, {
|
|
155
|
+
tagName: 'p',
|
|
156
|
+
type: _models.ComponentTypes.HTML
|
|
157
|
+
}));
|
|
158
|
+
};
|
|
159
|
+
|
|
121
160
|
var getRadios = function getRadios(config) {
|
|
122
161
|
var options = [];
|
|
123
162
|
|
|
@@ -223,6 +262,12 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
223
262
|
case _models.ComponentTypes.ALERT:
|
|
224
263
|
return getAlert(config);
|
|
225
264
|
|
|
265
|
+
case _models.ComponentTypes.PARAGRAPH:
|
|
266
|
+
return getParagraph(config);
|
|
267
|
+
|
|
268
|
+
case _models.ComponentTypes.LIST:
|
|
269
|
+
return getList(config);
|
|
270
|
+
|
|
226
271
|
default:
|
|
227
272
|
{
|
|
228
273
|
return null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _models = require("../../../models");
|
|
6
|
+
|
|
7
|
+
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
// Global imports
|
|
12
|
+
// Local imports
|
|
13
|
+
describe('utils.Component.get', function () {
|
|
14
|
+
it('should return a ul tag and correct className for an unordered list component', function () {
|
|
15
|
+
var ID = 'test-id';
|
|
16
|
+
var ITEMS = ['paragraph content1', 'paragraph content2'];
|
|
17
|
+
var COMPONENT = {
|
|
18
|
+
type: _models.ComponentTypes.LIST,
|
|
19
|
+
ordered: false,
|
|
20
|
+
items: ITEMS,
|
|
21
|
+
'data-testid': ID
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
25
|
+
container = _render.container;
|
|
26
|
+
|
|
27
|
+
var ul = (0, _react.getByTestId)(container, ID);
|
|
28
|
+
expect(ul.innerHTML).toContain('<li>paragraph content1</li><li>paragraph content2</li>');
|
|
29
|
+
expect(ul.tagName).toEqual('UL');
|
|
30
|
+
expect(ul.className).toEqual('govuk-list govuk-list--bullet');
|
|
31
|
+
});
|
|
32
|
+
it('should return a ol tag and correct className for an ordered list component', function () {
|
|
33
|
+
var ID = 'test-id';
|
|
34
|
+
var ITEMS = ['paragraph content1', 'paragraph content2'];
|
|
35
|
+
var COMPONENT = {
|
|
36
|
+
type: _models.ComponentTypes.LIST,
|
|
37
|
+
ordered: true,
|
|
38
|
+
items: ITEMS,
|
|
39
|
+
'data-testid': ID
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
43
|
+
container = _render2.container;
|
|
44
|
+
|
|
45
|
+
var ol = (0, _react.getByTestId)(container, ID);
|
|
46
|
+
expect(ol.innerHTML).toContain('<li>paragraph content1</li><li>paragraph content2</li>');
|
|
47
|
+
expect(ol.tagName).toEqual('OL');
|
|
48
|
+
expect(ol.className).toEqual('govuk-list govuk-list--number');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _models = require("../../../models");
|
|
6
|
+
|
|
7
|
+
var _getComponent = _interopRequireDefault(require("../getComponent"));
|
|
8
|
+
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
// Global imports
|
|
12
|
+
// Local imports
|
|
13
|
+
describe('utils.Component.get', function () {
|
|
14
|
+
it('should return a p tag and correct className for a paragraph component', function () {
|
|
15
|
+
var ID = 'test-id';
|
|
16
|
+
var CONTENT = 'paragraph content';
|
|
17
|
+
var COMPONENT = {
|
|
18
|
+
type: _models.ComponentTypes.PARAGRAPH,
|
|
19
|
+
content: CONTENT,
|
|
20
|
+
'data-testid': ID
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var _render = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
24
|
+
container = _render.container;
|
|
25
|
+
|
|
26
|
+
var p = (0, _react.getByTestId)(container, ID);
|
|
27
|
+
expect(p.innerHTML).toContain(CONTENT);
|
|
28
|
+
expect(p.tagName).toEqual('P');
|
|
29
|
+
expect(p.className).toEqual('govuk-body');
|
|
30
|
+
});
|
|
31
|
+
it('should override default className for a paragraph component', function () {
|
|
32
|
+
var ID = 'test-id';
|
|
33
|
+
var CONTENT = 'paragraph content';
|
|
34
|
+
var COMPONENT = {
|
|
35
|
+
type: _models.ComponentTypes.PARAGRAPH,
|
|
36
|
+
content: CONTENT,
|
|
37
|
+
'data-testid': ID,
|
|
38
|
+
className: 'govuk-body highlight'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var _render2 = (0, _react.render)((0, _getComponent.default)(COMPONENT)),
|
|
42
|
+
container = _render2.container;
|
|
43
|
+
|
|
44
|
+
var p = (0, _react.getByTestId)(container, ID);
|
|
45
|
+
expect(p.innerHTML).toContain(CONTENT);
|
|
46
|
+
expect(p.tagName).toEqual('P');
|
|
47
|
+
expect(p.className).toEqual('govuk-body highlight');
|
|
48
|
+
});
|
|
49
|
+
});
|