@ukhomeoffice/cop-react-form-renderer 4.15.1-alpha → 4.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.
- package/dist/components/FormComponent/FormComponent.js +1 -0
- package/dist/components/FormComponent/helpers/addLabel.js +29 -0
- package/dist/components/FormComponent/helpers/index.js +8 -0
- package/dist/components/FormPage/FormPage.js +9 -1
- package/dist/components/FormRenderer/FormRenderer.js +11 -7
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Adds label to target for given value.
|
|
12
|
+
* @param {object} target The target to be updated.
|
|
13
|
+
* @returns The updated target.
|
|
14
|
+
*/
|
|
15
|
+
var addLabel = function addLabel(target, component, data) {
|
|
16
|
+
// target.value can be an object in which case use value in object attribute
|
|
17
|
+
var value = _typeof(target.value) === 'object' ? target.value.value : target.value; // find the reference data item using the value
|
|
18
|
+
|
|
19
|
+
var item = data.find(function (e) {
|
|
20
|
+
return e.id === value;
|
|
21
|
+
}); // if item is null it means that the target.value can be used as a label otherwise use item.label
|
|
22
|
+
|
|
23
|
+
target['label'] = item === undefined ? target.value : item.label;
|
|
24
|
+
target['component'] = component.cya_label;
|
|
25
|
+
return target;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var _default = addLabel;
|
|
29
|
+
exports.default = _default;
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "addLabel", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _addLabel.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "getComponentDisabled", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function get() {
|
|
@@ -20,4 +26,6 @@ var _getComponentDisabled = _interopRequireDefault(require("./getComponentDisabl
|
|
|
20
26
|
|
|
21
27
|
var _getComponentError = _interopRequireDefault(require("./getComponentError"));
|
|
22
28
|
|
|
29
|
+
var _addLabel = _interopRequireDefault(require("./addLabel"));
|
|
30
|
+
|
|
23
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -68,6 +68,11 @@ var FormPage = function FormPage(_ref) {
|
|
|
68
68
|
|
|
69
69
|
var _useValidation = (0, _hooks.useValidation)(),
|
|
70
70
|
errors = _useValidation.errors;
|
|
71
|
+
|
|
72
|
+
var _useState3 = (0, _react.useState)({}),
|
|
73
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
74
|
+
patchLabel = _useState4[0],
|
|
75
|
+
setPatchLabel = _useState4[1];
|
|
71
76
|
/**
|
|
72
77
|
* Handle the state of the data directly within the page.
|
|
73
78
|
* This is so that the overall form data isn't affected until such
|
|
@@ -81,6 +86,9 @@ var FormPage = function FormPage(_ref) {
|
|
|
81
86
|
setPatch(function (prev) {
|
|
82
87
|
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, target.name, target.value));
|
|
83
88
|
});
|
|
89
|
+
setPatchLabel(function (prev) {
|
|
90
|
+
return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, target.component, target.label));
|
|
91
|
+
});
|
|
84
92
|
};
|
|
85
93
|
|
|
86
94
|
var classes = _utils.default.classBuilder(classBlock, classModifiers, className);
|
|
@@ -112,7 +120,7 @@ var FormPage = function FormPage(_ref) {
|
|
|
112
120
|
return _utils.default.Component.show(action, page.formData);
|
|
113
121
|
}),
|
|
114
122
|
onAction: function onAction(action) {
|
|
115
|
-
return _onAction(action, patch);
|
|
123
|
+
return _onAction(action, patch, patchLabel);
|
|
116
124
|
}
|
|
117
125
|
}));
|
|
118
126
|
};
|
|
@@ -292,8 +292,11 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
292
292
|
(0, _react.useEffect)(function () {
|
|
293
293
|
if (newPageId !== undefined) setPageId(newPageId);
|
|
294
294
|
}, [newPageId]); // Handle actions from pages.
|
|
295
|
+
// (patch captures payload ready field name and value,
|
|
296
|
+
// patchLabel captures non ID values
|
|
297
|
+
// for display purposes after submission.)
|
|
295
298
|
|
|
296
|
-
var onPageAction = function onPageAction(action, patch) {
|
|
299
|
+
var onPageAction = function onPageAction(action, patch, patchLabel) {
|
|
297
300
|
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
298
301
|
hooks.onCancel();
|
|
299
302
|
return;
|
|
@@ -370,15 +373,16 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
370
373
|
|
|
371
374
|
if (patch) {
|
|
372
375
|
setData(submissionData);
|
|
373
|
-
} // In case of hub-and-spoke if
|
|
376
|
+
} // In case of hub-and-spoke if patchLabel has changed then
|
|
377
|
+
// save name and value to variables for call to onSubmit hook
|
|
374
378
|
|
|
375
379
|
|
|
376
|
-
var changedFieldName
|
|
377
|
-
var changedFieldValue
|
|
380
|
+
var changedFieldName;
|
|
381
|
+
var changedFieldValue;
|
|
378
382
|
|
|
379
|
-
if (type === _models.FormTypes.HUB && Object.keys(
|
|
380
|
-
changedFieldName =
|
|
381
|
-
changedFieldValue = Object.values(
|
|
383
|
+
if (type === _models.FormTypes.HUB && Object.keys(patchLabel).length > 0) {
|
|
384
|
+
changedFieldName = Object.keys(patchLabel)[0];
|
|
385
|
+
changedFieldValue = Object.values(patchLabel)[0];
|
|
382
386
|
} // Now submit the data to the backend...
|
|
383
387
|
|
|
384
388
|
|