@ukhomeoffice/cop-react-form-renderer 5.88.6 → 5.88.8
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 +25 -13
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +59 -1
- package/dist/utils/Data/getAutocompleteSource.test.js +14 -5
- package/dist/utils/Data/getOptions.js +2 -1
- package/dist/utils/Data/getOptions.test.js +26 -8
- package/package.json +1 -1
|
@@ -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
|
});
|
|
@@ -14,6 +14,7 @@ describe('utils', function () {
|
|
|
14
14
|
var gbCurrency = {
|
|
15
15
|
currencyName: 'Great British Pounds',
|
|
16
16
|
currencyCode: 'GBP',
|
|
17
|
+
hint: 'hint',
|
|
17
18
|
value: 'GBP',
|
|
18
19
|
label: 'GBP',
|
|
19
20
|
slangTerm: 'quid'
|
|
@@ -21,6 +22,7 @@ describe('utils', function () {
|
|
|
21
22
|
var usCurrency = {
|
|
22
23
|
currencyName: 'United States Dollars',
|
|
23
24
|
currencyCode: 'USD',
|
|
25
|
+
hint: 'hint',
|
|
24
26
|
value: 'USD',
|
|
25
27
|
label: 'USD',
|
|
26
28
|
slangTerm: 'bucks',
|
|
@@ -29,19 +31,23 @@ describe('utils', function () {
|
|
|
29
31
|
var options = {
|
|
30
32
|
alpha: {
|
|
31
33
|
value: 'a',
|
|
32
|
-
label: 'Alpha'
|
|
34
|
+
label: 'Alpha',
|
|
35
|
+
hint: 'hint'
|
|
33
36
|
},
|
|
34
37
|
bravo: {
|
|
35
38
|
value: 'b',
|
|
36
|
-
label: 'Bravo'
|
|
39
|
+
label: 'Bravo',
|
|
40
|
+
hint: 'hint'
|
|
37
41
|
},
|
|
38
42
|
alIncluded: {
|
|
39
43
|
value: 'c',
|
|
40
|
-
label: 'Call me alan'
|
|
44
|
+
label: 'Call me alan',
|
|
45
|
+
hint: 'hint'
|
|
41
46
|
},
|
|
42
47
|
alStart: {
|
|
43
48
|
value: 'd',
|
|
44
|
-
label: 'Word Alphabet'
|
|
49
|
+
label: 'Word Alphabet',
|
|
50
|
+
hint: 'hint'
|
|
45
51
|
}
|
|
46
52
|
};
|
|
47
53
|
var testCurrencies = [gbCurrency, usCurrency];
|
|
@@ -71,7 +77,8 @@ describe('utils', function () {
|
|
|
71
77
|
expect(results.length).toEqual(1);
|
|
72
78
|
expect(results).toEqual([{
|
|
73
79
|
value: 'a',
|
|
74
|
-
label: 'Alpha'
|
|
80
|
+
label: 'Alpha',
|
|
81
|
+
hint: 'hint'
|
|
75
82
|
}]);
|
|
76
83
|
});
|
|
77
84
|
});
|
|
@@ -249,6 +256,7 @@ describe('utils', function () {
|
|
|
249
256
|
options: [gbCurrency, {
|
|
250
257
|
currencyName: 'United States Dollars',
|
|
251
258
|
currencyCode: 'USD',
|
|
259
|
+
hint: 'hint',
|
|
252
260
|
value: 'USD'
|
|
253
261
|
}]
|
|
254
262
|
}
|
|
@@ -263,6 +271,7 @@ describe('utils', function () {
|
|
|
263
271
|
expect(results).toEqual([gbCurrency, {
|
|
264
272
|
currencyName: 'United States Dollars',
|
|
265
273
|
currencyCode: 'USD',
|
|
274
|
+
hint: 'hint',
|
|
266
275
|
value: 'USD',
|
|
267
276
|
label: ''
|
|
268
277
|
}]);
|
|
@@ -32,7 +32,8 @@ var interpolateOptions = function interpolateOptions(config, options) {
|
|
|
32
32
|
}
|
|
33
33
|
return _objectSpread(_objectSpread({}, opt), {}, {
|
|
34
34
|
value: _copReactComponents.Utils.interpolateString(opt.value, config.formData),
|
|
35
|
-
label: _copReactComponents.Utils.interpolateString(opt.label, config.formData)
|
|
35
|
+
label: _copReactComponents.Utils.interpolateString(opt.label, config.formData),
|
|
36
|
+
hint: _copReactComponents.Utils.interpolateString(opt.hint, config.formData)
|
|
36
37
|
});
|
|
37
38
|
}).filter(function (n) {
|
|
38
39
|
return n;
|
|
@@ -16,10 +16,12 @@ describe('utils', function () {
|
|
|
16
16
|
var CONFIG = {
|
|
17
17
|
options: [{
|
|
18
18
|
value: 'a',
|
|
19
|
-
label: 'Alpha'
|
|
19
|
+
label: 'Alpha',
|
|
20
|
+
hint: ''
|
|
20
21
|
}, {
|
|
21
22
|
value: 'b',
|
|
22
|
-
label: 'Bravo'
|
|
23
|
+
label: 'Bravo',
|
|
24
|
+
hint: ''
|
|
23
25
|
}]
|
|
24
26
|
};
|
|
25
27
|
(0, _getOptions.default)(CONFIG, function (options) {
|
|
@@ -31,10 +33,12 @@ describe('utils', function () {
|
|
|
31
33
|
data: {
|
|
32
34
|
options: [{
|
|
33
35
|
value: 'a',
|
|
34
|
-
label: 'Alpha'
|
|
36
|
+
label: 'Alpha',
|
|
37
|
+
hint: ''
|
|
35
38
|
}, {
|
|
36
39
|
value: 'b',
|
|
37
|
-
label: 'Bravo'
|
|
40
|
+
label: 'Bravo',
|
|
41
|
+
hint: ''
|
|
38
42
|
}]
|
|
39
43
|
}
|
|
40
44
|
};
|
|
@@ -46,10 +50,12 @@ describe('utils', function () {
|
|
|
46
50
|
var CONFIG = {
|
|
47
51
|
options: [{
|
|
48
52
|
value: 'a',
|
|
49
|
-
label: 'Alpha'
|
|
53
|
+
label: 'Alpha',
|
|
54
|
+
hint: ''
|
|
50
55
|
}, {
|
|
51
56
|
value: 'b',
|
|
52
|
-
label: 'Bravo'
|
|
57
|
+
label: 'Bravo',
|
|
58
|
+
hint: ''
|
|
53
59
|
}],
|
|
54
60
|
data: {
|
|
55
61
|
options: [{
|
|
@@ -71,6 +77,7 @@ describe('utils', function () {
|
|
|
71
77
|
options: [{
|
|
72
78
|
value: 'a',
|
|
73
79
|
label: 'Alpha',
|
|
80
|
+
hint: '',
|
|
74
81
|
show_when: {
|
|
75
82
|
field: 'other',
|
|
76
83
|
op: 'eq',
|
|
@@ -79,6 +86,7 @@ describe('utils', function () {
|
|
|
79
86
|
}, {
|
|
80
87
|
value: 'b',
|
|
81
88
|
label: 'Bravo',
|
|
89
|
+
hint: '',
|
|
82
90
|
show_when: {
|
|
83
91
|
field: 'other',
|
|
84
92
|
op: 'neq',
|
|
@@ -99,6 +107,7 @@ describe('utils', function () {
|
|
|
99
107
|
options: [{
|
|
100
108
|
value: 'a',
|
|
101
109
|
label: 'Alpha',
|
|
110
|
+
hint: '',
|
|
102
111
|
show_when: {
|
|
103
112
|
type: 'or',
|
|
104
113
|
conditions: [{
|
|
@@ -114,6 +123,7 @@ describe('utils', function () {
|
|
|
114
123
|
}, {
|
|
115
124
|
value: 'b',
|
|
116
125
|
label: 'Bravo',
|
|
126
|
+
hint: '',
|
|
117
127
|
show_when: {
|
|
118
128
|
type: 'or',
|
|
119
129
|
conditions: [{
|
|
@@ -152,16 +162,19 @@ describe('utils', function () {
|
|
|
152
162
|
options: [{
|
|
153
163
|
id: 1,
|
|
154
164
|
description: 'First refdata item',
|
|
165
|
+
hint: '',
|
|
155
166
|
value: 'firstValue',
|
|
156
167
|
label: 'First label'
|
|
157
168
|
}, {
|
|
158
169
|
id: 2,
|
|
159
170
|
description: 'Second refdata item',
|
|
171
|
+
hint: '',
|
|
160
172
|
value: 'secondValue',
|
|
161
173
|
label: 'Second label'
|
|
162
174
|
}, {
|
|
163
175
|
id: 3,
|
|
164
176
|
description: 'Third refdata item',
|
|
177
|
+
hint: '',
|
|
165
178
|
value: 'thirdValue',
|
|
166
179
|
label: 'Third label'
|
|
167
180
|
}]
|
|
@@ -169,11 +182,13 @@ describe('utils', function () {
|
|
|
169
182
|
var MERGED_CONFIG = [{
|
|
170
183
|
id: 1,
|
|
171
184
|
description: 'First refdata item',
|
|
185
|
+
hint: '',
|
|
172
186
|
value: 'firstValue',
|
|
173
187
|
label: 'First label'
|
|
174
188
|
}, {
|
|
175
189
|
id: 2,
|
|
176
190
|
description: 'Second refdata item',
|
|
191
|
+
hint: '',
|
|
177
192
|
value: 'secondValue',
|
|
178
193
|
nested: [{
|
|
179
194
|
value: 'a',
|
|
@@ -183,6 +198,7 @@ describe('utils', function () {
|
|
|
183
198
|
}, {
|
|
184
199
|
id: 3,
|
|
185
200
|
description: 'Third refdata item',
|
|
201
|
+
hint: '',
|
|
186
202
|
value: 'thirdValue',
|
|
187
203
|
label: 'Third label'
|
|
188
204
|
}];
|
|
@@ -196,11 +212,13 @@ describe('utils', function () {
|
|
|
196
212
|
options: [{
|
|
197
213
|
value: 'a',
|
|
198
214
|
label: 'Alpha',
|
|
199
|
-
description: 'first'
|
|
215
|
+
description: 'first',
|
|
216
|
+
hint: ''
|
|
200
217
|
}, {
|
|
201
218
|
value: 'b',
|
|
202
219
|
label: 'Bravo',
|
|
203
|
-
description: 'second'
|
|
220
|
+
description: 'second',
|
|
221
|
+
hint: ''
|
|
204
222
|
}]
|
|
205
223
|
};
|
|
206
224
|
(0, _getOptions.default)(CONFIG, function (options) {
|