@ukhomeoffice/cop-react-form-renderer 5.61.0 → 5.62.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.
- package/dist/components/CollectionPage/CollectionPage.js +3 -0
- package/dist/components/CollectionSummary/SummaryCard.js +4 -1
- package/dist/components/CollectionSummary/SummaryCardDetails.js +16 -0
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +77 -8
- package/dist/components/FormComponent/FormComponent.js +11 -0
- package/dist/components/FormRenderer/FormRenderer.js +1 -0
- package/dist/hooks/useRefData.js +1 -1
- package/dist/utils/CollectionPage/addCollectionPageEntry.js +1 -2
- package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +4 -24
- package/dist/utils/CollectionPage/setCollectionPageData.js +9 -4
- package/dist/utils/CollectionPage/setCollectionPageData.test.js +18 -0
- package/dist/utils/Data/getOptions.js +6 -0
- package/dist/utils/Data/getOptions.test.js +55 -0
- package/dist/utils/Data/nestInRefdataOptions.js +38 -0
- package/dist/utils/Data/nestInRefdataOptions.test.js +102 -0
- package/package.json +1 -1
|
@@ -31,6 +31,7 @@ var DEFAULT_CLASS = exports.DEFAULT_CLASS = _FormPage2.DEFAULT_CLASS;
|
|
|
31
31
|
var CollectionPage = function CollectionPage(_ref) {
|
|
32
32
|
var _page$collection, _objectSpread4;
|
|
33
33
|
var page = _ref.page,
|
|
34
|
+
pages = _ref.pages,
|
|
34
35
|
onCollectionChange = _ref.onCollectionChange,
|
|
35
36
|
onAction = _ref.onAction,
|
|
36
37
|
hashLink = _ref.hashLink,
|
|
@@ -127,6 +128,7 @@ var CollectionPage = function CollectionPage(_ref) {
|
|
|
127
128
|
});
|
|
128
129
|
})
|
|
129
130
|
}),
|
|
131
|
+
pages: pages,
|
|
130
132
|
onAction: onInnerPageAction,
|
|
131
133
|
onWrapperChange: onInnerPageChange,
|
|
132
134
|
onTopLevelChange: onTopLevelChange,
|
|
@@ -149,6 +151,7 @@ CollectionPage.propTypes = {
|
|
|
149
151
|
actions: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({}), _propTypes.default.string])),
|
|
150
152
|
formData: _propTypes.default.shape({}).isRequired
|
|
151
153
|
}).isRequired,
|
|
154
|
+
pages: _propTypes.default.arrayOf(_propTypes.default.shape({})).isRequired,
|
|
152
155
|
onCollectionChange: _propTypes.default.func,
|
|
153
156
|
onAction: _propTypes.default.func.isRequired,
|
|
154
157
|
hashLink: _propTypes.default.bool,
|
|
@@ -219,7 +219,10 @@ SummaryCard.propTypes = {
|
|
|
219
219
|
}).isRequired,
|
|
220
220
|
config: _propTypes.default.shape({
|
|
221
221
|
banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
|
|
222
|
-
title: _propTypes.default.string,
|
|
222
|
+
title: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.PropTypes.arrayOf(_propTypes.default.shape({
|
|
223
|
+
title: _propTypes.default.string,
|
|
224
|
+
show_when: _propTypes.default.arrayOf({})
|
|
225
|
+
}))]),
|
|
223
226
|
details: _propTypes.default.string,
|
|
224
227
|
changeAction: _propTypes.default.shape({
|
|
225
228
|
label: _propTypes.default.string,
|
|
@@ -7,7 +7,9 @@ exports.default = exports.DEFAULT_CLASS = void 0;
|
|
|
7
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
10
|
+
var _models = require("../../models");
|
|
10
11
|
var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
|
|
12
|
+
var _getCYARowsForContainer = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARowsForContainer"));
|
|
11
13
|
require("./SummaryCardDetails.scss");
|
|
12
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
13
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -84,6 +86,20 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
84
86
|
if (!component) {
|
|
85
87
|
return null;
|
|
86
88
|
}
|
|
89
|
+
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
90
|
+
var containerRows = (0, _getCYARowsForContainer.default)(childPage, component, entryData);
|
|
91
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
92
|
+
key: fieldId,
|
|
93
|
+
className: classes('field')
|
|
94
|
+
}, containerRows.map(function (subComponent) {
|
|
95
|
+
var _entryData$component$;
|
|
96
|
+
// Put value for current subcomponent at top level
|
|
97
|
+
var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$ = entryData[component.fieldId]) === null || _entryData$component$ === void 0 ? void 0 : _entryData$component$[subComponent.fieldId]));
|
|
98
|
+
return (0, _getComponentRowForCYA.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
|
|
99
|
+
label: subComponent.key
|
|
100
|
+
}), classes, modEntry);
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
87
103
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
88
104
|
key: fieldId,
|
|
89
105
|
className: classes('field')
|
|
@@ -82,6 +82,75 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
82
82
|
var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
83
83
|
expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
84
84
|
});
|
|
85
|
+
it('should render sections containing containers based on summaryLayout config', function () {
|
|
86
|
+
var CHILD_PAGES = [{
|
|
87
|
+
summaryLayout: {
|
|
88
|
+
sections: [{
|
|
89
|
+
title: 'Section 1',
|
|
90
|
+
columns: 1,
|
|
91
|
+
fields: ['containerComponent']
|
|
92
|
+
}]
|
|
93
|
+
},
|
|
94
|
+
components: [{
|
|
95
|
+
fieldId: 'containerComponent',
|
|
96
|
+
type: 'container',
|
|
97
|
+
label: 'container',
|
|
98
|
+
components: [{
|
|
99
|
+
fieldId: 'subOne',
|
|
100
|
+
label: 'subOneLabel'
|
|
101
|
+
}, {
|
|
102
|
+
fieldId: 'subTwo',
|
|
103
|
+
label: 'subTwoLabel'
|
|
104
|
+
}, {
|
|
105
|
+
fieldId: 'subThree',
|
|
106
|
+
label: 'subThreeLabel'
|
|
107
|
+
}]
|
|
108
|
+
}]
|
|
109
|
+
}];
|
|
110
|
+
var CONTAINER_ENTRY = {
|
|
111
|
+
id: '001',
|
|
112
|
+
bannerText: 'A banner',
|
|
113
|
+
titleText: 'A title',
|
|
114
|
+
detailsText: 'Some details',
|
|
115
|
+
index: 0,
|
|
116
|
+
summaryText: 'Full details',
|
|
117
|
+
containerComponent: {
|
|
118
|
+
subOne: 'alpha',
|
|
119
|
+
subTwo: 'bravo',
|
|
120
|
+
subThree: 'charlie'
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var MASTER_PAGE = {
|
|
124
|
+
childPages: CHILD_PAGES
|
|
125
|
+
};
|
|
126
|
+
var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
127
|
+
masterPage: MASTER_PAGE,
|
|
128
|
+
childMasterPages: [],
|
|
129
|
+
formData: {},
|
|
130
|
+
entryData: CONTAINER_ENTRY
|
|
131
|
+
})),
|
|
132
|
+
container = _renderWithValidation2.container;
|
|
133
|
+
|
|
134
|
+
// Function to find an element by its text content
|
|
135
|
+
function getByTextContent(parent, text) {
|
|
136
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
137
|
+
return el.textContent === text;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Check for section title
|
|
142
|
+
var section1Title = getByTextContent(container, 'Section 1');
|
|
143
|
+
expect(section1Title).not.toBeUndefined();
|
|
144
|
+
|
|
145
|
+
// All three subcomponents from the container should have labels and values displayed
|
|
146
|
+
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
147
|
+
expect(section1Content.textContent).toContain('subOneLabel');
|
|
148
|
+
expect(section1Content.textContent).toContain('alpha');
|
|
149
|
+
expect(section1Content.textContent).toContain('subTwoLabel');
|
|
150
|
+
expect(section1Content.textContent).toContain('bravo');
|
|
151
|
+
expect(section1Content.textContent).toContain('subThreeLabel');
|
|
152
|
+
expect(section1Content.textContent).toContain('charlie');
|
|
153
|
+
});
|
|
85
154
|
it('should render sections if they have show_when checks and pass them', function () {
|
|
86
155
|
var CHILD_PAGES = [{
|
|
87
156
|
summaryLayout: {
|
|
@@ -114,13 +183,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
114
183
|
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
115
184
|
showSection1: true
|
|
116
185
|
});
|
|
117
|
-
var
|
|
186
|
+
var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
118
187
|
masterPage: MASTER_PAGE,
|
|
119
188
|
childMasterPages: [],
|
|
120
189
|
formData: {},
|
|
121
190
|
entryData: CUSTOM_ENTRY
|
|
122
191
|
})),
|
|
123
|
-
container =
|
|
192
|
+
container = _renderWithValidation3.container;
|
|
124
193
|
|
|
125
194
|
// Function to find an element by its text content
|
|
126
195
|
function getByTextContent(parent, text) {
|
|
@@ -171,13 +240,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
171
240
|
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
172
241
|
showSection1: false
|
|
173
242
|
});
|
|
174
|
-
var
|
|
243
|
+
var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
175
244
|
masterPage: MASTER_PAGE,
|
|
176
245
|
childMasterPages: [],
|
|
177
246
|
formData: {},
|
|
178
247
|
entryData: CUSTOM_ENTRY
|
|
179
248
|
})),
|
|
180
|
-
container =
|
|
249
|
+
container = _renderWithValidation4.container;
|
|
181
250
|
|
|
182
251
|
// Function to find an element by its text content
|
|
183
252
|
function getByTextContent(parent, text) {
|
|
@@ -231,7 +300,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
231
300
|
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
232
301
|
showSection1: false
|
|
233
302
|
});
|
|
234
|
-
var
|
|
303
|
+
var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
235
304
|
masterPage: MASTER_PAGE,
|
|
236
305
|
childMasterPages: [],
|
|
237
306
|
formData: {
|
|
@@ -239,7 +308,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
239
308
|
},
|
|
240
309
|
entryData: CUSTOM_ENTRY
|
|
241
310
|
})),
|
|
242
|
-
container =
|
|
311
|
+
container = _renderWithValidation5.container;
|
|
243
312
|
|
|
244
313
|
// Function to find an element by its text content
|
|
245
314
|
function getByTextContent(parent, text) {
|
|
@@ -294,13 +363,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
294
363
|
childPages: [].concat(CHILD_PAGES, CHILD_MASTER_PAGES)
|
|
295
364
|
};
|
|
296
365
|
var CHILD_COLLECTIONS = ['childCollection'];
|
|
297
|
-
var
|
|
366
|
+
var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
298
367
|
masterPage: MASTER_PAGE,
|
|
299
368
|
childCollections: CHILD_COLLECTIONS,
|
|
300
369
|
formData: {},
|
|
301
370
|
entryData: ENTRY
|
|
302
371
|
})),
|
|
303
|
-
container =
|
|
372
|
+
container = _renderWithValidation6.container;
|
|
304
373
|
|
|
305
374
|
// Function to find an element by its text content
|
|
306
375
|
function getByTextContent(parent, text) {
|
|
@@ -67,6 +67,17 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
67
67
|
// eslint-disable-next-line no-param-reassign
|
|
68
68
|
target.value = target.value.trim();
|
|
69
69
|
}
|
|
70
|
+
if (component.type === _models.ComponentTypes.CHECKBOXES && Array.isArray(target.value)) {
|
|
71
|
+
target.value.forEach(function (item) {
|
|
72
|
+
if (item.children && item.nested) {
|
|
73
|
+
// eslint-disable-next-line no-param-reassign
|
|
74
|
+
delete item.children;
|
|
75
|
+
// eslint-disable-next-line no-param-reassign
|
|
76
|
+
delete item.nested;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
70
81
|
// eslint-disable-next-line no-param-reassign
|
|
71
82
|
target = (0, _helpers.addLabel)(target, component, data);
|
|
72
83
|
onChange({
|
|
@@ -366,6 +366,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
366
366
|
submitting: submitting
|
|
367
367
|
}), formState.page && !formState.cya && formState.page.collection && /*#__PURE__*/_react.default.createElement(_CollectionPage.default, {
|
|
368
368
|
page: formState.page,
|
|
369
|
+
pages: pages,
|
|
369
370
|
onCollectionChange: onChange,
|
|
370
371
|
onAction: function onAction(action, patch, patchLabel) {
|
|
371
372
|
(0, _onPageAction.default)(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors, submitting, setSubmitting, errors);
|
package/dist/hooks/useRefData.js
CHANGED
|
@@ -29,7 +29,7 @@ var STATUS_COMPLETE = exports.STATUS_COMPLETE = 'complete';
|
|
|
29
29
|
var getRefDataUrl = function getRefDataUrl(component) {
|
|
30
30
|
// eslint-disable-next-line prefer-destructuring
|
|
31
31
|
var data = component.data;
|
|
32
|
-
if (data && !data.options) {
|
|
32
|
+
if (data && !data.options || data !== null && data !== void 0 && data.url) {
|
|
33
33
|
return _copReactComponents.Utils.interpolateString(data.url, component.formData);
|
|
34
34
|
}
|
|
35
35
|
return undefined;
|
|
@@ -17,7 +17,6 @@ exports.default = void 0;
|
|
|
17
17
|
*/
|
|
18
18
|
var addCollectionPageEntry = function addCollectionPageEntry(collectionName, formData) {
|
|
19
19
|
var fieldName = collectionName.split('.').pop();
|
|
20
|
-
formData["".concat(fieldName, "ActiveId")] =
|
|
21
|
-
formData["".concat(fieldName, "NumberedIndex")] = Number(formData["".concat(fieldName, "ActiveId")]) + 1;
|
|
20
|
+
formData["".concat(fieldName, "ActiveId")] = null;
|
|
22
21
|
};
|
|
23
22
|
var _default = exports.default = addCollectionPageEntry;
|
|
@@ -3,34 +3,14 @@
|
|
|
3
3
|
var _addCollectionPageEntry = _interopRequireDefault(require("./addCollectionPageEntry"));
|
|
4
4
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
5
|
describe('Utils.CollectionPage.addCollectionPageEntry', function () {
|
|
6
|
-
it('should
|
|
6
|
+
it('should set active ID as null for a top-level collection', function () {
|
|
7
7
|
var FORM_DATA = {};
|
|
8
8
|
(0, _addCollectionPageEntry.default)('testCollection', FORM_DATA);
|
|
9
|
-
expect(FORM_DATA.testCollectionActiveId).
|
|
9
|
+
expect(FORM_DATA.testCollectionActiveId).toBeFalsy();
|
|
10
10
|
});
|
|
11
|
-
it('should
|
|
11
|
+
it('should set a active ID as null for a nested collection', function () {
|
|
12
12
|
var FORM_DATA = {};
|
|
13
13
|
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
14
|
-
expect(FORM_DATA.grandchildActiveId).
|
|
15
|
-
});
|
|
16
|
-
it('should correctly set the active ID for a top-level collection', function () {
|
|
17
|
-
var FORM_DATA = {};
|
|
18
|
-
(0, _addCollectionPageEntry.default)('testCollection', FORM_DATA);
|
|
19
|
-
expect(FORM_DATA.testCollectionActiveId).toBe('0');
|
|
20
|
-
});
|
|
21
|
-
it('should correctly set the active ID for a nested collection', function () {
|
|
22
|
-
var FORM_DATA = {};
|
|
23
|
-
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
24
|
-
expect(FORM_DATA.grandchildActiveId).toBe('0');
|
|
25
|
-
});
|
|
26
|
-
it('should correctly increment the numbered index for a top-level collection', function () {
|
|
27
|
-
var FORM_DATA = {};
|
|
28
|
-
(0, _addCollectionPageEntry.default)('testCollection', FORM_DATA);
|
|
29
|
-
expect(FORM_DATA.testCollectionNumberedIndex).toBe(1);
|
|
30
|
-
});
|
|
31
|
-
it('should correctly increment the numbered index for a nested collection', function () {
|
|
32
|
-
var FORM_DATA = {};
|
|
33
|
-
(0, _addCollectionPageEntry.default)('parent.child.grandchild', FORM_DATA);
|
|
34
|
-
expect(FORM_DATA.grandchildNumberedIndex).toBe(1);
|
|
14
|
+
expect(FORM_DATA.grandchildActiveId).toBeFalsy();
|
|
35
15
|
});
|
|
36
16
|
});
|
|
@@ -28,15 +28,20 @@ var setCollectionPageData = function setCollectionPageData(collectionName, newDa
|
|
|
28
28
|
var data = formData;
|
|
29
29
|
nameParts.some(function (name) {
|
|
30
30
|
var _data$name;
|
|
31
|
-
// Current collection doesn't exist, so create it
|
|
32
|
-
// add an entry and set the active id.
|
|
31
|
+
// Current collection doesn't exist, so create it
|
|
33
32
|
if (!data[name]) {
|
|
33
|
+
data[name] = [];
|
|
34
|
+
}
|
|
35
|
+
// If the entry matching the active ID doesn't exist in the collection, create it.
|
|
36
|
+
if (!data[name].find(function (e) {
|
|
37
|
+
return e.id === formData["".concat(name, "ActiveId")];
|
|
38
|
+
})) {
|
|
34
39
|
var newEntryId = Date.now().toString();
|
|
35
40
|
// eslint-disable-next-line no-param-reassign
|
|
36
41
|
formData["".concat(name, "ActiveId")] = formData["".concat(name, "ActiveId")] || newEntryId;
|
|
37
|
-
data[name]
|
|
42
|
+
data[name].push({
|
|
38
43
|
id: formData["".concat(name, "ActiveId")]
|
|
39
|
-
}
|
|
44
|
+
});
|
|
40
45
|
}
|
|
41
46
|
// We're at the target collection's level, so
|
|
42
47
|
// set the new data.
|
|
@@ -160,4 +160,22 @@ describe('Utils.CollectionPage.setCollectionPageData', function () {
|
|
|
160
160
|
value: 'newValue'
|
|
161
161
|
});
|
|
162
162
|
});
|
|
163
|
+
it('creates a new entry and updates active ID if no matching active ID is found', function () {
|
|
164
|
+
var formData = {};
|
|
165
|
+
var collectionName = 'testCollection';
|
|
166
|
+
var newData = [{
|
|
167
|
+
id: 'dataId',
|
|
168
|
+
value: 'testValue'
|
|
169
|
+
}];
|
|
170
|
+
(0, _setCollectionPageData.default)(collectionName, newData, formData);
|
|
171
|
+
|
|
172
|
+
// Check if formData has been updated
|
|
173
|
+
expect(formData["".concat(collectionName, "ActiveId")]).toBeDefined();
|
|
174
|
+
|
|
175
|
+
// Check if the new entry was added to the collection
|
|
176
|
+
expect(formData[collectionName]).toBeDefined();
|
|
177
|
+
expect(formData[collectionName].length).toBe(1);
|
|
178
|
+
expect(formData[collectionName][0].id).toBe(newData[0].id);
|
|
179
|
+
expect(formData[collectionName][0]).toEqual(expect.objectContaining(newData[0]));
|
|
180
|
+
});
|
|
163
181
|
});
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
8
|
var _Condition = _interopRequireDefault(require("../Condition"));
|
|
9
|
+
var _nestInRefdataOptions = _interopRequireDefault(require("./nestInRefdataOptions"));
|
|
9
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
11
|
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); }
|
|
11
12
|
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; }
|
|
@@ -35,6 +36,11 @@ var interpolateOptions = function interpolateOptions(config, options) {
|
|
|
35
36
|
};
|
|
36
37
|
var getOptions = function getOptions(config, callback) {
|
|
37
38
|
if (config) {
|
|
39
|
+
var _config$data, _config$data2;
|
|
40
|
+
if (config.options && config !== null && config !== void 0 && (_config$data = config.data) !== null && _config$data !== void 0 && _config$data.options && config !== null && config !== void 0 && (_config$data2 = config.data) !== null && _config$data2 !== void 0 && _config$data2.url) {
|
|
41
|
+
var combinedOptions = (0, _nestInRefdataOptions.default)(config.options, config.data.options);
|
|
42
|
+
return callback(interpolateOptions(config, combinedOptions));
|
|
43
|
+
}
|
|
38
44
|
if (config.options) {
|
|
39
45
|
return callback(interpolateOptions(config, config.options));
|
|
40
46
|
}
|
|
@@ -135,6 +135,61 @@ describe('utils', function () {
|
|
|
135
135
|
expect(options).toEqual([CONFIG.options[0]]);
|
|
136
136
|
});
|
|
137
137
|
});
|
|
138
|
+
it('should should use both data from refdata url and options if both present', function () {
|
|
139
|
+
var CONFIG = {
|
|
140
|
+
data: {
|
|
141
|
+
options: [{
|
|
142
|
+
refdata_match: {
|
|
143
|
+
id: 2
|
|
144
|
+
},
|
|
145
|
+
nested: [{
|
|
146
|
+
value: 'a',
|
|
147
|
+
label: 'Alpha'
|
|
148
|
+
}]
|
|
149
|
+
}],
|
|
150
|
+
url: 'refdata.url'
|
|
151
|
+
},
|
|
152
|
+
options: [{
|
|
153
|
+
id: 1,
|
|
154
|
+
description: 'First refdata item',
|
|
155
|
+
value: 'firstValue',
|
|
156
|
+
label: 'First label'
|
|
157
|
+
}, {
|
|
158
|
+
id: 2,
|
|
159
|
+
description: 'Second refdata item',
|
|
160
|
+
value: 'secondValue',
|
|
161
|
+
label: 'Second label'
|
|
162
|
+
}, {
|
|
163
|
+
id: 3,
|
|
164
|
+
description: 'Third refdata item',
|
|
165
|
+
value: 'thirdValue',
|
|
166
|
+
label: 'Third label'
|
|
167
|
+
}]
|
|
168
|
+
};
|
|
169
|
+
var MERGED_CONFIG = [{
|
|
170
|
+
id: 1,
|
|
171
|
+
description: 'First refdata item',
|
|
172
|
+
value: 'firstValue',
|
|
173
|
+
label: 'First label'
|
|
174
|
+
}, {
|
|
175
|
+
id: 2,
|
|
176
|
+
description: 'Second refdata item',
|
|
177
|
+
value: 'secondValue',
|
|
178
|
+
nested: [{
|
|
179
|
+
value: 'a',
|
|
180
|
+
label: 'Alpha'
|
|
181
|
+
}],
|
|
182
|
+
label: 'Second label'
|
|
183
|
+
}, {
|
|
184
|
+
id: 3,
|
|
185
|
+
description: 'Third refdata item',
|
|
186
|
+
value: 'thirdValue',
|
|
187
|
+
label: 'Third label'
|
|
188
|
+
}];
|
|
189
|
+
(0, _getOptions.default)(CONFIG, function (options) {
|
|
190
|
+
expect(options).toEqual(MERGED_CONFIG);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
138
193
|
});
|
|
139
194
|
});
|
|
140
195
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
|
+
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); }
|
|
13
|
+
/**
|
|
14
|
+
* Combines refdata options with custom options with the use of `from_refdata` in the custom option
|
|
15
|
+
* Allowing for nesting of components within refdata lists of checkboxes or radios
|
|
16
|
+
* @param {Array} refdataOptions The list of options coming from refdata
|
|
17
|
+
* @param {Array} options The list of options being defined in the form
|
|
18
|
+
* @returns A combined list of refdata options and custom options to be rendered
|
|
19
|
+
*/
|
|
20
|
+
var nestInRefdataOptions = function nestInRefdataOptions(refdataOptions, options) {
|
|
21
|
+
var nestedRefdataOptions = refdataOptions;
|
|
22
|
+
options.forEach(function (option) {
|
|
23
|
+
if (option.refdata_match) {
|
|
24
|
+
var refdataMatch = option.refdata_match;
|
|
25
|
+
var refdataKey = Object.keys(refdataMatch)[0];
|
|
26
|
+
var refdataIndex = refdataOptions.findIndex(function (refdataOption) {
|
|
27
|
+
return refdataOption[refdataKey] === refdataMatch[refdataKey];
|
|
28
|
+
});
|
|
29
|
+
if (refdataIndex >= 0) {
|
|
30
|
+
nestedRefdataOptions[refdataIndex] = _objectSpread(_objectSpread({}, refdataOptions[refdataIndex]), {}, {
|
|
31
|
+
nested: option.nested
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return nestedRefdataOptions;
|
|
37
|
+
};
|
|
38
|
+
var _default = exports.default = nestInRefdataOptions;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _nestInRefdataOptions = _interopRequireDefault(require("./nestInRefdataOptions"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe("utils.Data.combineOptions", function () {
|
|
6
|
+
it("should combine refdata options with a custom option", function () {
|
|
7
|
+
var refdataOptions = [{
|
|
8
|
+
id: 1,
|
|
9
|
+
description: "First refdata item",
|
|
10
|
+
value: "firstValue",
|
|
11
|
+
label: "First label"
|
|
12
|
+
}, {
|
|
13
|
+
id: 2,
|
|
14
|
+
description: "Second refdata item",
|
|
15
|
+
value: "secondValue",
|
|
16
|
+
label: "Second label"
|
|
17
|
+
}, {
|
|
18
|
+
id: 3,
|
|
19
|
+
description: "Third refdata item",
|
|
20
|
+
value: "thirdValue",
|
|
21
|
+
label: "Third label"
|
|
22
|
+
}];
|
|
23
|
+
var customOptions = [{
|
|
24
|
+
refdata_match: {
|
|
25
|
+
id: 2
|
|
26
|
+
},
|
|
27
|
+
nested: [{
|
|
28
|
+
id: "nestedComponent",
|
|
29
|
+
fieldId: "nestedComponent",
|
|
30
|
+
type: "text",
|
|
31
|
+
label: "Nested Component"
|
|
32
|
+
}]
|
|
33
|
+
}];
|
|
34
|
+
expect((0, _nestInRefdataOptions.default)(refdataOptions, customOptions)).toEqual([{
|
|
35
|
+
description: "First refdata item",
|
|
36
|
+
id: 1,
|
|
37
|
+
label: "First label",
|
|
38
|
+
value: "firstValue"
|
|
39
|
+
}, {
|
|
40
|
+
description: "Second refdata item",
|
|
41
|
+
id: 2,
|
|
42
|
+
label: "Second label",
|
|
43
|
+
nested: [{
|
|
44
|
+
id: "nestedComponent",
|
|
45
|
+
fieldId: "nestedComponent",
|
|
46
|
+
type: "text",
|
|
47
|
+
label: "Nested Component"
|
|
48
|
+
}],
|
|
49
|
+
value: "secondValue"
|
|
50
|
+
}, {
|
|
51
|
+
description: "Third refdata item",
|
|
52
|
+
id: 3,
|
|
53
|
+
label: "Third label",
|
|
54
|
+
value: "thirdValue"
|
|
55
|
+
}]);
|
|
56
|
+
});
|
|
57
|
+
it("should not combine options if it can't find a matching refdata option", function () {
|
|
58
|
+
var refdataOptions = [{
|
|
59
|
+
id: 1,
|
|
60
|
+
description: "First refdata item",
|
|
61
|
+
value: "firstValue",
|
|
62
|
+
label: "First label"
|
|
63
|
+
}, {
|
|
64
|
+
id: 2,
|
|
65
|
+
description: "Second refdata item",
|
|
66
|
+
value: "secondValue",
|
|
67
|
+
label: "Second label"
|
|
68
|
+
}, {
|
|
69
|
+
id: 3,
|
|
70
|
+
description: "Third refdata item",
|
|
71
|
+
value: "thirdValue",
|
|
72
|
+
label: "Third label"
|
|
73
|
+
}];
|
|
74
|
+
var customOptions = [{
|
|
75
|
+
refdata_match: {
|
|
76
|
+
id: 4
|
|
77
|
+
},
|
|
78
|
+
nested: [{
|
|
79
|
+
id: "nestedComponent",
|
|
80
|
+
fieldId: "nestedComponent",
|
|
81
|
+
type: "text",
|
|
82
|
+
label: "Nested Component"
|
|
83
|
+
}]
|
|
84
|
+
}];
|
|
85
|
+
expect((0, _nestInRefdataOptions.default)(refdataOptions, customOptions)).toEqual([{
|
|
86
|
+
description: "First refdata item",
|
|
87
|
+
id: 1,
|
|
88
|
+
label: "First label",
|
|
89
|
+
value: "firstValue"
|
|
90
|
+
}, {
|
|
91
|
+
description: "Second refdata item",
|
|
92
|
+
id: 2,
|
|
93
|
+
label: "Second label",
|
|
94
|
+
value: "secondValue"
|
|
95
|
+
}, {
|
|
96
|
+
description: "Third refdata item",
|
|
97
|
+
id: 3,
|
|
98
|
+
label: "Third label",
|
|
99
|
+
value: "thirdValue"
|
|
100
|
+
}]);
|
|
101
|
+
});
|
|
102
|
+
});
|