@ukhomeoffice/cop-react-form-renderer 5.27.1 → 5.27.2
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,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
8
|
+
var _showComponent = _interopRequireDefault(require("./showComponent"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
10
|
/**
|
|
10
11
|
* Iterates over an array of components and brings any nested
|
|
@@ -35,16 +36,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
35
36
|
var elevateNestedComponents = function elevateNestedComponents(components, data) {
|
|
36
37
|
var allComponents = [];
|
|
37
38
|
components === null || components === void 0 ? void 0 : components.forEach(function (component) {
|
|
38
|
-
var _component$data;
|
|
39
39
|
allComponents.push(component);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
// If the component wasn't shown we shouldn't elevate anything nested under it
|
|
41
|
+
if ((0, _showComponent.default)(component, data)) {
|
|
42
|
+
var _component$data;
|
|
43
|
+
(_component$data = component.data) === null || _component$data === void 0 || (_component$data = _component$data.options) === null || _component$data === void 0 ? void 0 : _component$data.forEach(function (option) {
|
|
44
|
+
// If this option has nested components and is
|
|
45
|
+
// selected, then add its nested components to the array.
|
|
46
|
+
var sourceData = (data === null || data === void 0 ? void 0 : data[component.id]) || _Data.default.getSource(data, component.full_path);
|
|
47
|
+
// If the specific option wasn't shown we shouldn't elevate anything nested under it
|
|
48
|
+
if (Array.isArray(option.nested) && sourceData === option.value && (0, _showComponent.default)(option, data)) {
|
|
49
|
+
allComponents = allComponents.concat(option.nested);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
48
53
|
});
|
|
49
54
|
return allComponents;
|
|
50
55
|
};
|
|
@@ -119,4 +119,148 @@ describe('utils.Component.elevateNestedComponents', function () {
|
|
|
119
119
|
id: 'nestedTwo'
|
|
120
120
|
}]));
|
|
121
121
|
});
|
|
122
|
+
it('should not elevate nested components under a component which is hidden with a show_when', function () {
|
|
123
|
+
var COMPONENTS = [{
|
|
124
|
+
id: 'textComp'
|
|
125
|
+
}, {
|
|
126
|
+
id: 'radiosComp',
|
|
127
|
+
show_when: {
|
|
128
|
+
field: 'testField',
|
|
129
|
+
op: 'eq',
|
|
130
|
+
value: 'blue'
|
|
131
|
+
},
|
|
132
|
+
data: {
|
|
133
|
+
options: [{
|
|
134
|
+
label: 'Yes',
|
|
135
|
+
value: 'yes',
|
|
136
|
+
nested: [{
|
|
137
|
+
id: 'nestedOne'
|
|
138
|
+
}, {
|
|
139
|
+
id: 'nestedTwo'
|
|
140
|
+
}]
|
|
141
|
+
}, {
|
|
142
|
+
label: 'No',
|
|
143
|
+
value: 'no'
|
|
144
|
+
}]
|
|
145
|
+
}
|
|
146
|
+
}];
|
|
147
|
+
var DATA = {
|
|
148
|
+
radiosComp: 'yes',
|
|
149
|
+
testField: 'red'
|
|
150
|
+
};
|
|
151
|
+
expect((0, _elevateNestedComponents.default)(COMPONENTS, DATA)).toEqual([].concat(COMPONENTS));
|
|
152
|
+
});
|
|
153
|
+
it('should elevate nested components under a component which is shown with a show_When', function () {
|
|
154
|
+
var COMPONENTS = [{
|
|
155
|
+
id: 'textComp'
|
|
156
|
+
}, {
|
|
157
|
+
id: 'radiosComp',
|
|
158
|
+
show_when: {
|
|
159
|
+
field: 'testField',
|
|
160
|
+
op: 'eq',
|
|
161
|
+
value: 'red'
|
|
162
|
+
},
|
|
163
|
+
data: {
|
|
164
|
+
options: [{
|
|
165
|
+
label: 'Yes',
|
|
166
|
+
value: 'yes',
|
|
167
|
+
nested: [{
|
|
168
|
+
id: 'nestedOne'
|
|
169
|
+
}, {
|
|
170
|
+
id: 'nestedTwo'
|
|
171
|
+
}]
|
|
172
|
+
}, {
|
|
173
|
+
label: 'No',
|
|
174
|
+
value: 'no'
|
|
175
|
+
}]
|
|
176
|
+
}
|
|
177
|
+
}];
|
|
178
|
+
var DATA = {
|
|
179
|
+
radiosComp: 'yes',
|
|
180
|
+
testField: 'red'
|
|
181
|
+
};
|
|
182
|
+
expect((0, _elevateNestedComponents.default)(COMPONENTS, DATA)).toEqual([].concat(COMPONENTS, [{
|
|
183
|
+
id: 'nestedOne'
|
|
184
|
+
}, {
|
|
185
|
+
id: 'nestedTwo'
|
|
186
|
+
}]));
|
|
187
|
+
});
|
|
188
|
+
it('should elevate nested components under an option which is shown with a show_When', function () {
|
|
189
|
+
var COMPONENTS = [{
|
|
190
|
+
id: 'textComp'
|
|
191
|
+
}, {
|
|
192
|
+
id: 'radiosComp',
|
|
193
|
+
show_when: {
|
|
194
|
+
field: 'testField',
|
|
195
|
+
op: 'eq',
|
|
196
|
+
value: 'red'
|
|
197
|
+
},
|
|
198
|
+
data: {
|
|
199
|
+
options: [{
|
|
200
|
+
label: 'Yes',
|
|
201
|
+
value: 'yes',
|
|
202
|
+
nested: [{
|
|
203
|
+
id: 'nestedOne'
|
|
204
|
+
}, {
|
|
205
|
+
id: 'nestedTwo'
|
|
206
|
+
}],
|
|
207
|
+
show_when: {
|
|
208
|
+
field: 'testFieldTwo',
|
|
209
|
+
op: 'eq',
|
|
210
|
+
value: 'purple'
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
label: 'No',
|
|
214
|
+
value: 'no'
|
|
215
|
+
}]
|
|
216
|
+
}
|
|
217
|
+
}];
|
|
218
|
+
var DATA = {
|
|
219
|
+
radiosComp: 'yes',
|
|
220
|
+
testField: 'red',
|
|
221
|
+
testFieldTwo: 'purple'
|
|
222
|
+
};
|
|
223
|
+
expect((0, _elevateNestedComponents.default)(COMPONENTS, DATA)).toEqual([].concat(COMPONENTS, [{
|
|
224
|
+
id: 'nestedOne'
|
|
225
|
+
}, {
|
|
226
|
+
id: 'nestedTwo'
|
|
227
|
+
}]));
|
|
228
|
+
});
|
|
229
|
+
it('should not elevate nested components under an option which is hidden with a show_When', function () {
|
|
230
|
+
var COMPONENTS = [{
|
|
231
|
+
id: 'textComp'
|
|
232
|
+
}, {
|
|
233
|
+
id: 'radiosComp',
|
|
234
|
+
show_when: {
|
|
235
|
+
field: 'testField',
|
|
236
|
+
op: 'eq',
|
|
237
|
+
value: 'red'
|
|
238
|
+
},
|
|
239
|
+
data: {
|
|
240
|
+
options: [{
|
|
241
|
+
label: 'Yes',
|
|
242
|
+
value: 'yes',
|
|
243
|
+
nested: [{
|
|
244
|
+
id: 'nestedOne'
|
|
245
|
+
}, {
|
|
246
|
+
id: 'nestedTwo'
|
|
247
|
+
}],
|
|
248
|
+
show_when: {
|
|
249
|
+
field: 'testFieldTwo',
|
|
250
|
+
op: 'eq',
|
|
251
|
+
value: 'purple'
|
|
252
|
+
}
|
|
253
|
+
}, {
|
|
254
|
+
label: 'No',
|
|
255
|
+
value: 'no'
|
|
256
|
+
}]
|
|
257
|
+
}
|
|
258
|
+
}];
|
|
259
|
+
var DATA = {
|
|
260
|
+
radiosComp: 'yes',
|
|
261
|
+
testField: 'red',
|
|
262
|
+
testFieldTwo: 'orange'
|
|
263
|
+
};
|
|
264
|
+
expect((0, _elevateNestedComponents.default)(COMPONENTS, DATA)).toEqual([].concat(COMPONENTS));
|
|
265
|
+
});
|
|
122
266
|
});
|