@ukhomeoffice/cop-react-form-renderer 3.15.0 → 3.16.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.
@@ -104,7 +104,9 @@ var FormPage = function FormPage(_ref) {
104
104
  formData: _objectSpread(_objectSpread({}, page.formData), patch)
105
105
  });
106
106
  }), /*#__PURE__*/_react.default.createElement(_PageActions.default, {
107
- actions: page.actions,
107
+ actions: page.actions.filter(function (action) {
108
+ return _utils.default.Component.show(action, page.formData);
109
+ }),
108
110
  onAction: function onAction(action) {
109
111
  return _onAction(action, patch);
110
112
  }
@@ -92,6 +92,44 @@ describe('components.FormPage', function () {
92
92
  }
93
93
  }
94
94
  };
95
+ var PAGE_WITH_CONDITIONAL_BUTTONS = {
96
+ id: 'pageId',
97
+ // eslint-disable-next-line no-template-curly-in-string
98
+ title: '${title}',
99
+ components: [TEXT_WITH_EXPRESSION, AUTO_WITH_EXPRESSION],
100
+ actions: [{
101
+ type: 'submit',
102
+ validate: true,
103
+ label: 'Button 1',
104
+ show_when: [{
105
+ field: 'currentUser.givenName',
106
+ op: '!=',
107
+ value: 'Doe'
108
+ }]
109
+ }, {
110
+ type: 'submit',
111
+ validate: false,
112
+ label: 'Button 2',
113
+ show_when: [{
114
+ field: 'currentUser.givenName',
115
+ op: '=',
116
+ value: 'Doe'
117
+ }]
118
+ }],
119
+ formData: {
120
+ title: 'Order Form',
121
+ text1: "Text1 ".concat(VALUE),
122
+ text2: "Text2 ".concat(VALUE),
123
+ wrapper: {
124
+ email: 'test@example.email',
125
+ nextAction: 'Payment',
126
+ prevAction: 'User Details'
127
+ },
128
+ currentUser: {
129
+ givenName: 'Doe'
130
+ }
131
+ }
132
+ };
95
133
  var ON_ACTION_CALLS = [];
96
134
 
97
135
  var checkInputField = function checkInputField(formGroup, fieldId, lbl, hnt, val) {
@@ -305,5 +343,26 @@ describe('components.FormPage', function () {
305
343
  }
306
344
  }, _callee4);
307
345
  })));
346
+ it('should render only the conditionally shown button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
347
+ var _renderWithValidation5, container, page;
348
+
349
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
350
+ while (1) {
351
+ switch (_context5.prev = _context5.next) {
352
+ case 0:
353
+ _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormPage.default, {
354
+ page: PAGE_WITH_CONDITIONAL_BUTTONS,
355
+ onAction: ON_ACTION
356
+ })), container = _renderWithValidation5.container;
357
+ page = container.childNodes[0];
358
+ checkFormButtonGroup(page.childNodes[3], ['Button 2']); // Just the second button shown
359
+
360
+ case 3:
361
+ case "end":
362
+ return _context5.stop();
363
+ }
364
+ }
365
+ }, _callee5);
366
+ })));
308
367
  });
309
368
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "3.15.0",
3
+ "version": "3.16.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",