@ukhomeoffice/cop-react-form-renderer 5.88.4 → 5.88.7
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.
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _optionIsSelected = _interopRequireDefault(require("../../../utils/Component/optionIsSelected"));
|
|
8
|
+
var _getCollectionPageActiveId = _interopRequireDefault(require("../../../utils/CollectionPage/getCollectionPageActiveId"));
|
|
9
|
+
var _getCollectionPageData = _interopRequireDefault(require("../../../utils/CollectionPage/getCollectionPageData"));
|
|
10
|
+
var _setCollectionPageData = _interopRequireDefault(require("../../../utils/CollectionPage/setCollectionPageData"));
|
|
8
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
12
|
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); }
|
|
10
13
|
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; }
|
|
@@ -13,6 +16,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
13
16
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
17
|
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); } // Local imports
|
|
15
18
|
var parentComponents = ['radios', 'checkboxes'];
|
|
19
|
+
var getActiveIds = function getActiveIds(collectionName, formData) {
|
|
20
|
+
var nameParts = collectionName.split('.');
|
|
21
|
+
var result = {};
|
|
22
|
+
nameParts.forEach(function (part) {
|
|
23
|
+
result["".concat(part, "ActiveId")] = formData["".concat(part, "ActiveId")];
|
|
24
|
+
});
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
16
27
|
function getIdsToDelete(component, selectedValue) {
|
|
17
28
|
var _component$data;
|
|
18
29
|
var idsToDelete = [];
|
|
@@ -25,29 +36,30 @@ function getIdsToDelete(component, selectedValue) {
|
|
|
25
36
|
});
|
|
26
37
|
return idsToDelete;
|
|
27
38
|
}
|
|
28
|
-
;
|
|
29
39
|
var cleanHiddenNestedData = function cleanHiddenNestedData(patch, page) {
|
|
40
|
+
var _patch = patch;
|
|
30
41
|
page.components.forEach(function (component) {
|
|
31
42
|
if (!parentComponents.includes(component.type)) {
|
|
32
43
|
return;
|
|
33
44
|
}
|
|
34
|
-
var _patch = patch;
|
|
35
45
|
var idsToDelete = getIdsToDelete(component, _patch[component.id]);
|
|
36
46
|
idsToDelete.forEach(function (id) {
|
|
37
47
|
delete _patch[id];
|
|
38
48
|
});
|
|
39
49
|
});
|
|
40
|
-
if (page.collection
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
if (page.collection) {
|
|
51
|
+
_patch = _objectSpread(_objectSpread({}, getActiveIds(page.collection.name, page.formData)), _patch);
|
|
52
|
+
var collectionData = (0, _getCollectionPageData.default)(page.collection.name, _patch);
|
|
53
|
+
if (collectionData) {
|
|
54
|
+
var activeId = (0, _getCollectionPageActiveId.default)(page.collection.name, _patch);
|
|
55
|
+
var modifiedCollection = collectionData.map(function (entry) {
|
|
56
|
+
return entry.id === activeId ? cleanHiddenNestedData(entry, _objectSpread(_objectSpread({}, page), {}, {
|
|
57
|
+
collection: undefined
|
|
58
|
+
})) : entry;
|
|
59
|
+
});
|
|
60
|
+
(0, _setCollectionPageData.default)(page.collection.name, modifiedCollection, _patch);
|
|
61
|
+
}
|
|
49
62
|
}
|
|
50
|
-
;
|
|
51
|
-
return patch;
|
|
63
|
+
return _patch;
|
|
52
64
|
};
|
|
53
65
|
var _default = exports.default = cleanHiddenNestedData;
|
|
@@ -78,7 +78,7 @@ describe('components', function () {
|
|
|
78
78
|
expect(updatedPatchCheckboxes.nested1).toBeFalsy();
|
|
79
79
|
expect(updatedPatchCheckboxes.nested2).toBeTruthy();
|
|
80
80
|
});
|
|
81
|
-
it('remove data corresponding to hidden nested components within the active collection entry', function () {
|
|
81
|
+
it('should remove data corresponding to hidden nested components within the active collection entry', function () {
|
|
82
82
|
var patch = {
|
|
83
83
|
collectionNameActiveId: '456',
|
|
84
84
|
collectionName: [{
|
|
@@ -100,6 +100,9 @@ describe('components', function () {
|
|
|
100
100
|
collection: {
|
|
101
101
|
name: 'collectionName'
|
|
102
102
|
},
|
|
103
|
+
formData: {
|
|
104
|
+
collectionNameActiveId: '456'
|
|
105
|
+
},
|
|
103
106
|
components: [{
|
|
104
107
|
id: 'parent',
|
|
105
108
|
type: 'radios',
|
|
@@ -126,6 +129,61 @@ describe('components', function () {
|
|
|
126
129
|
expect(updatedPatch.collectionName[1].nested1).toBeFalsy();
|
|
127
130
|
expect(updatedPatch.collectionName[1].nested2).toBeTruthy();
|
|
128
131
|
});
|
|
132
|
+
it('should remove data corresponding to hidden nested components when collection is nested within an entity', function () {
|
|
133
|
+
var patch = {
|
|
134
|
+
collectionNameActiveId: '456',
|
|
135
|
+
entities: [{
|
|
136
|
+
id: '777',
|
|
137
|
+
collectionName: [{
|
|
138
|
+
id: '123',
|
|
139
|
+
parent: 'option1',
|
|
140
|
+
nested1: 'should be included',
|
|
141
|
+
nested2: 'should be included'
|
|
142
|
+
}, {
|
|
143
|
+
id: '456',
|
|
144
|
+
parent: 'option2',
|
|
145
|
+
nested1: 'should not be included',
|
|
146
|
+
nested2: 'should be included'
|
|
147
|
+
}]
|
|
148
|
+
}]
|
|
149
|
+
};
|
|
150
|
+
var page = {
|
|
151
|
+
id: 'page',
|
|
152
|
+
name: 'page',
|
|
153
|
+
title: 'Page',
|
|
154
|
+
collection: {
|
|
155
|
+
name: 'entities.collectionName'
|
|
156
|
+
},
|
|
157
|
+
formData: {
|
|
158
|
+
collectionNameActiveId: '456',
|
|
159
|
+
entitiesActiveId: '777'
|
|
160
|
+
},
|
|
161
|
+
components: [{
|
|
162
|
+
id: 'parent',
|
|
163
|
+
type: 'radios',
|
|
164
|
+
data: {
|
|
165
|
+
options: [{
|
|
166
|
+
value: 'option1',
|
|
167
|
+
nested: [{
|
|
168
|
+
id: 'nested1',
|
|
169
|
+
fieldId: 'nested1'
|
|
170
|
+
}]
|
|
171
|
+
}, {
|
|
172
|
+
value: 'option2',
|
|
173
|
+
nested: [{
|
|
174
|
+
id: 'nested2',
|
|
175
|
+
fieldId: 'nested2'
|
|
176
|
+
}]
|
|
177
|
+
}]
|
|
178
|
+
}
|
|
179
|
+
}]
|
|
180
|
+
};
|
|
181
|
+
var updatedPatch = (0, _cleanHiddenNestedData.default)(patch, page);
|
|
182
|
+
expect(updatedPatch.entities[0].collectionName[0].nested1).toBeTruthy();
|
|
183
|
+
expect(updatedPatch.entities[0].collectionName[0].nested2).toBeTruthy();
|
|
184
|
+
expect(updatedPatch.entities[0].collectionName[1].nested1).toBeFalsy();
|
|
185
|
+
expect(updatedPatch.entities[0].collectionName[1].nested2).toBeTruthy();
|
|
186
|
+
});
|
|
129
187
|
});
|
|
130
188
|
});
|
|
131
189
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "5.88.
|
|
3
|
+
"version": "5.88.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "3.24.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "3.24.1",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|
|
@@ -101,4 +101,4 @@
|
|
|
101
101
|
"last 1 safari version"
|
|
102
102
|
]
|
|
103
103
|
}
|
|
104
|
-
}
|
|
104
|
+
}
|