@ukhomeoffice/cop-react-form-renderer 3.15.0 → 3.17.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
  });
@@ -437,7 +437,7 @@ FormRenderer.propTypes = InternalFormRenderer.propTypes = {
437
437
  title: _propTypes.default.string,
438
438
 
439
439
  /** See <a href="/?path=/docs/f-json--page#formtypes">FormTypes</a>. */
440
- type: _propTypes.default.oneOf([_models.FormTypes.CYA, _models.FormTypes.FORM, _models.FormTypes.HUB, _models.FormTypes.TASK, _models.FormTypes.WIZARD, _models.FormTypes.TASKCYA]).isRequired,
440
+ type: _propTypes.default.oneOf([_models.FormTypes.CYA, _models.FormTypes.FORM, _models.FormTypes.HUB, _models.FormTypes.TASK, _models.FormTypes.WIZARD, _models.FormTypes.TASK_CYA, _models.FormTypes.FORM_WITH_TASK]).isRequired,
441
441
  components: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
442
442
  pages: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
443
443
  hub: _propTypes.default.object,
@@ -12,7 +12,7 @@ var _getNextPageId = _interopRequireDefault(require("./getNextPageId"));
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
14
  var getSubmissionStatus = function getSubmissionStatus(formType, pages, currentPageId, action, formData, currentTask, isCompleted) {
15
- if (formType === _models.FormTypes.TASK) {
15
+ if (formType === _models.FormTypes.TASK || formType === _models.FormTypes.FORM_WITH_TASK) {
16
16
  var formStatus = formData.formStatus || {};
17
17
  formStatus.tasks = formStatus.tasks || {};
18
18
  formStatus.tasks[currentTask.name] = formStatus.tasks[currentTask.name] || {};
@@ -103,7 +103,7 @@ describe('components', function () {
103
103
  });
104
104
  describe("when the action type is '".concat(_models.PageAction.TYPES.SAVE_AND_RETURN, "'"), function () {
105
105
  Object.values(_models.FormTypes).forEach(function (formType) {
106
- if (formType !== _models.FormTypes.TASK) {
106
+ if (formType !== _models.FormTypes.TASK && formType !== _models.FormTypes.FORM_WITH_TASK) {
107
107
  it("should return the current page if the form type is '".concat(formType, "'"), function () {
108
108
  var ACTION = _models.PageAction.DEFAULTS.saveAndReturn;
109
109
  expect((0, _getSubmissionStatus.default)(formType, PAGES, PAGES[0].id, ACTION, FORM_DATA)).toMatchObject({
@@ -4,19 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var TYPE_FORM = 'form';
8
7
  var TYPE_CHECK_YOUR_ANSWERS = 'cya';
8
+ var TYPE_FORM = 'form';
9
+ var TYPE_FORM_WITH_TASK_LIST = 'form-with-task-list';
9
10
  var TYPE_HUB_AND_SPOKE = 'hub-and-spoke';
10
11
  var TYPE_TASK_LIST = 'task-list';
11
- var TYPE_WIZARD = 'wizard';
12
12
  var TYPE_TASK_LIST_CYA = 'task-list-cya';
13
+ var TYPE_WIZARD = 'wizard';
13
14
  var FormTypes = {
14
- FORM: TYPE_FORM,
15
15
  CYA: TYPE_CHECK_YOUR_ANSWERS,
16
+ FORM: TYPE_FORM,
17
+ FORM_WITH_TASK: TYPE_FORM_WITH_TASK_LIST,
16
18
  HUB: TYPE_HUB_AND_SPOKE,
17
19
  TASK: TYPE_TASK_LIST,
18
- WIZARD: TYPE_WIZARD,
19
- TASKCYA: TYPE_TASK_LIST_CYA
20
+ TASK_CYA: TYPE_TASK_LIST_CYA,
21
+ WIZARD: TYPE_WIZARD
20
22
  };
21
23
  var _default = FormTypes;
22
24
  exports.default = _default;
@@ -37,7 +37,7 @@ var getFormHub = function getFormHub(type, hub, components, formData) {
37
37
  }
38
38
  }
39
39
 
40
- if (type === _models.FormTypes.TASK) {
40
+ if (type === _models.FormTypes.TASK || type === _models.FormTypes.FORM_WITH_TASK) {
41
41
  return _models.HubFormats.TASK;
42
42
  }
43
43
 
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.17.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",