@ukhomeoffice/cop-react-form-renderer 5.92.0 → 5.94.0
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/CollectionSummary/RenderListView.js +16 -4
- package/dist/components/CollectionSummary/RenderListView.scss +4 -0
- package/dist/components/CollectionSummary/RenderListView.test.js +35 -2
- package/dist/utils/Component/getComponent.js +6 -2
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +52 -0
- package/dist/utils/Data/getOptions.js +3 -0
- package/dist/utils/Data/getOptions.test.js +10 -0
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ var DEFAULT_DELETE_BUTTON_LABEL = exports.DEFAULT_DELETE_BUTTON_LABEL = 'Delete'
|
|
|
29
29
|
var DEFAULT_CHANGE_BUTTON_CLASS = exports.DEFAULT_CHANGE_BUTTON_CLASS = 'secondary';
|
|
30
30
|
var DEFAULT_DELETE_BUTTON_CLASS = exports.DEFAULT_DELETE_BUTTON_CLASS = 'warning';
|
|
31
31
|
var RenderListView = function RenderListView(_ref) {
|
|
32
|
-
var _config$changeAction, _config$deleteAction, _masterPage$childPage;
|
|
32
|
+
var _config$changeAction, _config$changeAction2, _config$changeAction3, _config$changeAction4, _config$deleteAction, _masterPage$childPage;
|
|
33
33
|
var id = _ref.id,
|
|
34
34
|
entryData = _ref.entryData,
|
|
35
35
|
config = _ref.config,
|
|
@@ -59,16 +59,28 @@ var RenderListView = function RenderListView(_ref) {
|
|
|
59
59
|
className: classes('actions')
|
|
60
60
|
}, /*#__PURE__*/_react.default.createElement("li", {
|
|
61
61
|
className: classes('action')
|
|
62
|
-
}, config.changeAction && typeof onFullEdit === 'function' &&
|
|
62
|
+
}, config.changeAction && typeof onFullEdit === 'function' &&
|
|
63
|
+
// If passed a value for classModifiers, render a Button with those classModifiers applied -
|
|
64
|
+
// otherwise, revert to the default GOVUK List View styling of rendering a Link button instead:
|
|
65
|
+
config.changeAction.classModifiers ? /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
66
|
+
id: "".concat(id, ".changeButton"),
|
|
67
|
+
onClick: function onClick() {
|
|
68
|
+
return onFullEdit(config.changeAction.page, entryData.id);
|
|
69
|
+
},
|
|
70
|
+
classModifiers: config.changeAction.classModifiers,
|
|
71
|
+
"aria-label": _copReactComponents.Utils.interpolateString("".concat(((_config$changeAction = config.changeAction) === null || _config$changeAction === void 0 ? void 0 : _config$changeAction.label) || DEFAULT_CHANGE_BUTTON_LABEL, " ").concat(config.title || DEFAULT_TITLE), _objectSpread(_objectSpread({}, entryData), {}, {
|
|
72
|
+
index: entryData.index + 1
|
|
73
|
+
}))
|
|
74
|
+
}, ((_config$changeAction2 = config.changeAction) === null || _config$changeAction2 === void 0 ? void 0 : _config$changeAction2.label) || DEFAULT_CHANGE_BUTTON_LABEL) : /*#__PURE__*/_react.default.createElement("button", {
|
|
63
75
|
type: "button",
|
|
64
76
|
className: "govuk-link govuk-link-button",
|
|
65
77
|
onClick: function onClick() {
|
|
66
78
|
return onFullEdit(config.changeAction.page, entryData.id);
|
|
67
79
|
},
|
|
68
|
-
"aria-label": _copReactComponents.Utils.interpolateString("".concat(((_config$
|
|
80
|
+
"aria-label": _copReactComponents.Utils.interpolateString("".concat(((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.label) || DEFAULT_CHANGE_BUTTON_LABEL, " ").concat(config.title || DEFAULT_TITLE), _objectSpread(_objectSpread({}, entryData), {}, {
|
|
69
81
|
index: entryData.index + 1
|
|
70
82
|
}))
|
|
71
|
-
}, config.changeAction.label || DEFAULT_CHANGE_BUTTON_LABEL)), /*#__PURE__*/_react.default.createElement("li", {
|
|
83
|
+
}, ((_config$changeAction4 = config.changeAction) === null || _config$changeAction4 === void 0 ? void 0 : _config$changeAction4.label) || DEFAULT_CHANGE_BUTTON_LABEL)), /*#__PURE__*/_react.default.createElement("li", {
|
|
72
84
|
className: classes('action')
|
|
73
85
|
}, config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
74
86
|
id: "".concat(id, ".deleteButton"),
|
|
@@ -224,7 +224,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
224
224
|
onDeleteArgs = [];
|
|
225
225
|
onDeleteCalls = 0;
|
|
226
226
|
});
|
|
227
|
-
it('should render and handle action buttons correctly', function () {
|
|
227
|
+
it('should render and handle action buttons correctly, including a GOVUK default Change Link when no classModifiers are passed in', function () {
|
|
228
228
|
var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_RenderListView.default, {
|
|
229
229
|
id: ID,
|
|
230
230
|
entryData: ENTRY,
|
|
@@ -238,7 +238,7 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
238
238
|
var listViewDiv = container.querySelector('.govuk-summary-card');
|
|
239
239
|
expect(listViewDiv).not.toBeNull();
|
|
240
240
|
|
|
241
|
-
// Check for change
|
|
241
|
+
// Check for change link
|
|
242
242
|
var changeLink = listViewDiv.querySelector('.govuk-link');
|
|
243
243
|
expect(changeLink.textContent).toEqual(CONFIG.changeAction.label);
|
|
244
244
|
expect(changeLink.getAttribute('aria-label')).toEqual("".concat(CONFIG.changeAction.label, " ").concat(CONFIG.title));
|
|
@@ -257,5 +257,38 @@ describe('components.CollectionSummary.RenderListView', function () {
|
|
|
257
257
|
expect(onDeleteCalls).toEqual(1);
|
|
258
258
|
expect(onDeleteArgs[0]).toEqual(ENTRY);
|
|
259
259
|
});
|
|
260
|
+
it('should render and handle an Update button instead of the GOVUK default Change link when classModifiers are passed in', function () {
|
|
261
|
+
var CONFIG_WITH_BUTTON = _objectSpread(_objectSpread({}, CONFIG), {}, {
|
|
262
|
+
changeAction: {
|
|
263
|
+
label: 'Update label',
|
|
264
|
+
page: 'testPage',
|
|
265
|
+
classModifiers: 'primary'
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_RenderListView.default, {
|
|
269
|
+
id: ID,
|
|
270
|
+
entryData: ENTRY,
|
|
271
|
+
config: CONFIG_WITH_BUTTON,
|
|
272
|
+
onFullEdit: ON_CHANGE,
|
|
273
|
+
onDelete: ON_DELETE,
|
|
274
|
+
masterPage: MASTER_PAGE,
|
|
275
|
+
getComponentRow: getComponentRow
|
|
276
|
+
})),
|
|
277
|
+
container = _renderWithValidation5.container;
|
|
278
|
+
var listViewDiv = container.querySelector('.govuk-summary-card');
|
|
279
|
+
expect(listViewDiv).not.toBeNull();
|
|
280
|
+
|
|
281
|
+
// Check for update button
|
|
282
|
+
var changeButton = listViewDiv.querySelector('.hods-button');
|
|
283
|
+
expect(changeButton.classList).toContain('hods-button--primary');
|
|
284
|
+
expect(changeButton.textContent).toEqual(CONFIG_WITH_BUTTON.changeAction.label);
|
|
285
|
+
expect(changeButton.getAttribute('aria-label')).toEqual("".concat(CONFIG_WITH_BUTTON.changeAction.label, " ").concat(CONFIG_WITH_BUTTON.title));
|
|
286
|
+
_react.fireEvent.click(changeButton, {});
|
|
287
|
+
expect(onChangeCalls).toEqual(1);
|
|
288
|
+
expect(onChangeArgs[0]).toMatchObject({
|
|
289
|
+
page: CONFIG_WITH_BUTTON.changeAction.page,
|
|
290
|
+
id: ENTRY.id
|
|
291
|
+
});
|
|
292
|
+
});
|
|
260
293
|
});
|
|
261
294
|
});
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.getChildrenJsx = exports.default = void 0;
|
|
8
8
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _Condition = _interopRequireDefault(require("../Condition"));
|
|
10
11
|
var _models = require("../../models");
|
|
11
12
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
12
13
|
var _cleanAttributes = _interopRequireDefault(require("./cleanAttributes"));
|
|
@@ -265,11 +266,14 @@ var getChildJsx = function getChildJsx(parent, paramChild) {
|
|
|
265
266
|
* @param {*} childrenConfigs array of configurations for the child components
|
|
266
267
|
*/
|
|
267
268
|
var getChildrenJsx = exports.getChildrenJsx = function getChildrenJsx(parentConfig, childrenConfigs) {
|
|
268
|
-
|
|
269
|
+
var validChildren = childrenConfigs.filter(function (config) {
|
|
270
|
+
return !(config.show_when && !_Condition.default.meetsAll(config.show_when, parentConfig.formData));
|
|
271
|
+
}).map(function (config) {
|
|
269
272
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
270
273
|
key: config.id
|
|
271
274
|
}, getChildJsx(parentConfig, config));
|
|
272
|
-
})
|
|
275
|
+
});
|
|
276
|
+
return validChildren.length > 0 ? validChildren : null;
|
|
273
277
|
};
|
|
274
278
|
/**
|
|
275
279
|
* Get a renderable component, based on a configuration object.
|
|
@@ -180,4 +180,56 @@ describe('utils.Component.get', function () {
|
|
|
180
180
|
}
|
|
181
181
|
}, _callee4);
|
|
182
182
|
})));
|
|
183
|
+
it('should correctly show nested component with show_when', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
184
|
+
var FIELD_ID, VALUE, VisibleComponent, HiddenComponent, PARENT_CONFIG, _renderWithValidation4, container, child, label, input;
|
|
185
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
186
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
187
|
+
case 0:
|
|
188
|
+
FIELD_ID = 'fieldId';
|
|
189
|
+
VALUE = 'nestedValue';
|
|
190
|
+
VisibleComponent = {
|
|
191
|
+
id: 'testId',
|
|
192
|
+
fieldId: FIELD_ID,
|
|
193
|
+
label: 'Test label',
|
|
194
|
+
type: 'text',
|
|
195
|
+
show_when: [{
|
|
196
|
+
field: FIELD_ID,
|
|
197
|
+
op: "=",
|
|
198
|
+
value: VALUE
|
|
199
|
+
}]
|
|
200
|
+
};
|
|
201
|
+
HiddenComponent = {
|
|
202
|
+
id: 'hiddenID',
|
|
203
|
+
fieldId: "hiddenFeild",
|
|
204
|
+
label: 'Hidden label',
|
|
205
|
+
type: 'text',
|
|
206
|
+
show_when: [{
|
|
207
|
+
field: FIELD_ID,
|
|
208
|
+
op: "!=",
|
|
209
|
+
value: VALUE
|
|
210
|
+
}]
|
|
211
|
+
};
|
|
212
|
+
PARENT_CONFIG = {
|
|
213
|
+
onChange: function onChange() {},
|
|
214
|
+
formData: _defineProperty({}, FIELD_ID, VALUE)
|
|
215
|
+
};
|
|
216
|
+
_renderWithValidation4 = (0, _setupTests.renderWithValidation)((0, _getComponent.getChildrenJsx)(PARENT_CONFIG, [VisibleComponent, HiddenComponent])), container = _renderWithValidation4.container;
|
|
217
|
+
expect(container.childNodes.length).toEqual(1);
|
|
218
|
+
child = container.childNodes[0];
|
|
219
|
+
expect(child.childNodes[0].childNodes.length).toEqual(2);
|
|
220
|
+
expect(child.classList).toContain('govuk-form-group');
|
|
221
|
+
label = child.childNodes[0];
|
|
222
|
+
expect(label).toBeDefined();
|
|
223
|
+
expect(label.innerHTML).toContain(VisibleComponent.label);
|
|
224
|
+
input = child.childNodes[2];
|
|
225
|
+
expect(input.tagName).toEqual('INPUT');
|
|
226
|
+
expect(input.classList).toContain('govuk-input');
|
|
227
|
+
expect(input.id).toEqual("".concat(VisibleComponent.id));
|
|
228
|
+
expect(input.value).toEqual(VALUE);
|
|
229
|
+
case 18:
|
|
230
|
+
case "end":
|
|
231
|
+
return _context5.stop();
|
|
232
|
+
}
|
|
233
|
+
}, _callee5);
|
|
234
|
+
})));
|
|
183
235
|
});
|
|
@@ -26,6 +26,9 @@ var interpolateOptions = function interpolateOptions(config, options) {
|
|
|
26
26
|
if (typeof opt === 'string') {
|
|
27
27
|
return opt;
|
|
28
28
|
}
|
|
29
|
+
if (!opt.value) {
|
|
30
|
+
return opt.label;
|
|
31
|
+
}
|
|
29
32
|
if (config.alternativeHintField) {
|
|
30
33
|
// eslint-disable-next-line no-param-reassign
|
|
31
34
|
opt.hint = opt[config.alternativeHintField];
|
|
@@ -28,6 +28,16 @@ describe('utils', function () {
|
|
|
28
28
|
expect(options).toEqual(CONFIG.options);
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
|
+
it('should handle stings in option and if no value is supplied treat it as a string', function () {
|
|
32
|
+
var CONFIG = {
|
|
33
|
+
options: ["or", {
|
|
34
|
+
label: "and"
|
|
35
|
+
}]
|
|
36
|
+
};
|
|
37
|
+
(0, _getOptions.default)(CONFIG, function (options) {
|
|
38
|
+
expect(options).toEqual(["or", "and"]);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
31
41
|
it('should get any specified options from the data property of the config', function () {
|
|
32
42
|
var CONFIG = {
|
|
33
43
|
data: {
|