@ukhomeoffice/cop-react-form-renderer 4.82.1 → 4.85.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/context/HooksContext/HooksContext.js +3 -3
- package/dist/context/ValidationContext/ValidationContext.js +3 -5
- package/dist/index.js +6 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +12 -4
- package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +45 -4
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Component/isEditable.test.js +5 -0
- package/package.json +1 -1
|
@@ -41,10 +41,10 @@ var DEFAULT_HOOKS = {
|
|
|
41
41
|
onSubmit: function onSubmit(type, payload, onSuccess, onError) {
|
|
42
42
|
if (typeof onSuccess === 'function') onSuccess();
|
|
43
43
|
},
|
|
44
|
-
onValidate: function onValidate(page) {
|
|
45
|
-
return
|
|
44
|
+
onValidate: function onValidate(page, errors) {
|
|
45
|
+
return errors;
|
|
46
46
|
},
|
|
47
|
-
//
|
|
47
|
+
// Returns the list of errors already found in FR by default.
|
|
48
48
|
onCancel: function onCancel() {} // Consuming application must provide function to action, else this does nothing.
|
|
49
49
|
};
|
|
50
50
|
|
|
@@ -70,8 +70,7 @@ var ValidationContextProvider = function ValidationContextProvider(_ref) {
|
|
|
70
70
|
var validate = {
|
|
71
71
|
page: function page(_page) {
|
|
72
72
|
var pageErrors = _utils.default.Validate.page(_page);
|
|
73
|
-
var
|
|
74
|
-
var allErrors = Array.isArray(hookPageErrors) ? pageErrors.concat(hookPageErrors) : pageErrors;
|
|
73
|
+
var allErrors = hooks.onValidate(_page, pageErrors);
|
|
75
74
|
setErrors(allErrors);
|
|
76
75
|
return allErrors;
|
|
77
76
|
},
|
|
@@ -79,10 +78,9 @@ var ValidationContextProvider = function ValidationContextProvider(_ref) {
|
|
|
79
78
|
var pagesErrors = _pages.flatMap(function (page) {
|
|
80
79
|
return _utils.default.Validate.page(page);
|
|
81
80
|
});
|
|
82
|
-
var
|
|
83
|
-
return hooks.onValidate(page);
|
|
81
|
+
var allErrors = _pages.flatMap(function (page) {
|
|
82
|
+
return hooks.onValidate(page, pagesErrors);
|
|
84
83
|
});
|
|
85
|
-
var allErrors = Array.isArray(hookPagesErrors) ? pagesErrors.concat(hookPagesErrors) : pagesErrors;
|
|
86
84
|
setErrors(allErrors);
|
|
87
85
|
return allErrors;
|
|
88
86
|
}
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,12 @@ Object.defineProperty(exports, "FormTypes", {
|
|
|
28
28
|
return _models.FormTypes;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
+
Object.defineProperty(exports, "HooksContextProvider", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function get() {
|
|
34
|
+
return _context.HooksContextProvider;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
31
37
|
Object.defineProperty(exports, "HubFormats", {
|
|
32
38
|
enumerable: true,
|
|
33
39
|
get: function get() {
|
|
@@ -9,6 +9,7 @@ var _Component = _interopRequireDefault(require("../Component"));
|
|
|
9
9
|
var _Container = _interopRequireDefault(require("../Container"));
|
|
10
10
|
var _getSourceData = _interopRequireDefault(require("../Data/getSourceData"));
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
/* eslint-disable no-console */
|
|
12
13
|
// Local imports
|
|
13
14
|
|
|
14
15
|
var EXCLUDE_FROM_CYA = [_models.ComponentTypes.ALERT, _models.ComponentTypes.HEADING, _models.ComponentTypes.HTML, _models.ComponentTypes.INSET_TEXT];
|
|
@@ -32,10 +33,17 @@ var showComponentCYA = function showComponentCYA(options, data) {
|
|
|
32
33
|
if (Object.prototype.hasOwnProperty.call(options, 'show_on_cya') && !options.show_on_cya) {
|
|
33
34
|
return false;
|
|
34
35
|
}
|
|
35
|
-
if (options.hideOnCyaWhenEmpty
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (options.hideOnCyaWhenEmpty) {
|
|
37
|
+
if (options.type === _models.ComponentTypes.COLLECTION) {
|
|
38
|
+
var itemCollectionsData = (0, _getSourceData.default)(data, options.full_path);
|
|
39
|
+
if (!(itemCollectionsData !== null && itemCollectionsData !== void 0 && itemCollectionsData.length)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
var value = (0, _getSourceData.default)(data, options.fieldId);
|
|
44
|
+
if (!value && value !== false && value !== 0) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
if (options.type === _models.ComponentTypes.CONTAINER) {
|
|
@@ -57,9 +57,9 @@ describe('utils', function () {
|
|
|
57
57
|
type: _models.ComponentTypes.TEXT
|
|
58
58
|
}, null)).toBeTruthy();
|
|
59
59
|
});
|
|
60
|
-
it('should show when hideOnCyaWhenEmpty is defined and
|
|
60
|
+
it('should show when hideOnCyaWhenEmpty is defined and falsy', function () {
|
|
61
61
|
expect((0, _showComponentCYA.default)({
|
|
62
|
-
hideOnCyaWhenEmpty:
|
|
62
|
+
hideOnCyaWhenEmpty: false
|
|
63
63
|
})).toBeTruthy();
|
|
64
64
|
});
|
|
65
65
|
it('should show collection when hideOnCyaWhenEmpty is not defined', function () {
|
|
@@ -73,11 +73,11 @@ describe('utils', function () {
|
|
|
73
73
|
type: _models.ComponentTypes.COLLECTION
|
|
74
74
|
})).toBeFalsy();
|
|
75
75
|
});
|
|
76
|
-
it('should show when it\'s not a collection and hideOnCyaWhenEmpty is truthy', function () {
|
|
76
|
+
it('should not show when it\'s not a collection and hideOnCyaWhenEmpty is truthy', function () {
|
|
77
77
|
expect((0, _showComponentCYA.default)({
|
|
78
78
|
hideOnCyaWhenEmpty: true,
|
|
79
79
|
type: _models.ComponentTypes.TEXT
|
|
80
|
-
})).
|
|
80
|
+
})).toBeFalsy();
|
|
81
81
|
});
|
|
82
82
|
it('should show when length of full_path data is 1 or more', function () {
|
|
83
83
|
expect((0, _showComponentCYA.default)({
|
|
@@ -97,6 +97,47 @@ describe('utils', function () {
|
|
|
97
97
|
example: []
|
|
98
98
|
})).toBeFalsy();
|
|
99
99
|
});
|
|
100
|
+
it('should show when value of component data does exist and hideOnCyaWhenEmpty is truthy', function () {
|
|
101
|
+
expect((0, _showComponentCYA.default)({
|
|
102
|
+
hideOnCyaWhenEmpty: true,
|
|
103
|
+
type: _models.ComponentTypes.TEXT,
|
|
104
|
+
fieldId: "example"
|
|
105
|
+
}, {
|
|
106
|
+
example: "yes"
|
|
107
|
+
})).toBeTruthy();
|
|
108
|
+
});
|
|
109
|
+
it('should not show when value of component data does not exist and hideOnCyaWhenEmpty is truthy', function () {
|
|
110
|
+
expect((0, _showComponentCYA.default)({
|
|
111
|
+
hideOnCyaWhenEmpty: true,
|
|
112
|
+
type: _models.ComponentTypes.TEXT,
|
|
113
|
+
fieldId: "example"
|
|
114
|
+
}, {})).toBeFalsy();
|
|
115
|
+
});
|
|
116
|
+
it('should show when value of component data does not exist and hideOnCyaWhenEmpty is falsy', function () {
|
|
117
|
+
expect((0, _showComponentCYA.default)({
|
|
118
|
+
hideOnCyaWhenEmpty: false,
|
|
119
|
+
type: _models.ComponentTypes.TEXT,
|
|
120
|
+
fieldId: "example"
|
|
121
|
+
}, {})).toBeTruthy();
|
|
122
|
+
});
|
|
123
|
+
it('should show when value of component data does is falsy and hideOnCyaWhenEmpty is truthy', function () {
|
|
124
|
+
expect((0, _showComponentCYA.default)({
|
|
125
|
+
hideOnCyaWhenEmpty: true,
|
|
126
|
+
type: _models.ComponentTypes.TEXT,
|
|
127
|
+
fieldId: "example"
|
|
128
|
+
}, {
|
|
129
|
+
example: false
|
|
130
|
+
})).toBeTruthy();
|
|
131
|
+
});
|
|
132
|
+
it('should show when value of component data is numerically zero and hideOnCyaWhenEmpty is truthy', function () {
|
|
133
|
+
expect((0, _showComponentCYA.default)({
|
|
134
|
+
hideOnCyaWhenEmpty: true,
|
|
135
|
+
type: _models.ComponentTypes.TEXT,
|
|
136
|
+
fieldId: "example"
|
|
137
|
+
}, {
|
|
138
|
+
example: 0
|
|
139
|
+
})).toBeTruthy();
|
|
140
|
+
});
|
|
100
141
|
});
|
|
101
142
|
});
|
|
102
143
|
});
|
|
@@ -10,7 +10,7 @@ var _models = require("../../models");
|
|
|
10
10
|
var EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.MULTI_FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
11
11
|
exports.EDITABLE_TYPES = EDITABLE_TYPES;
|
|
12
12
|
var isEditable = function isEditable(options) {
|
|
13
|
-
return EDITABLE_TYPES.includes(options === null || options === void 0 ? void 0 : options.type);
|
|
13
|
+
return EDITABLE_TYPES.includes(options === null || options === void 0 ? void 0 : options.type) || (options === null || options === void 0 ? void 0 : options.isEditable) || false;
|
|
14
14
|
};
|
|
15
15
|
var _default = isEditable;
|
|
16
16
|
exports.default = _default;
|
|
@@ -33,6 +33,11 @@ describe('utils', function () {
|
|
|
33
33
|
type: 'hidden'
|
|
34
34
|
})).toEqual(false);
|
|
35
35
|
});
|
|
36
|
+
it("should return true if options has 'isEditable' set to true", function () {
|
|
37
|
+
expect((0, _isEditable.default)({
|
|
38
|
+
isEditable: true
|
|
39
|
+
})).toEqual(true);
|
|
40
|
+
});
|
|
36
41
|
});
|
|
37
42
|
});
|
|
38
43
|
});
|