@ukhomeoffice/cop-react-form-renderer 6.11.1 → 6.12.1
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/README.md +8 -0
- package/dist/components/CheckYourAnswers/Answer.js +1 -1
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +6 -2
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +131 -50
- package/dist/components/CollectionPage/CollectionPage.js +2 -1
- package/dist/components/CollectionSummary/CollectionSummary.js +6 -4
- package/dist/components/CollectionSummary/CollectionSummary.scss +5 -0
- package/dist/components/CollectionSummary/CollectionSummary.test.js +60 -36
- package/dist/components/CollectionSummary/RenderListView.js +18 -6
- package/dist/components/CollectionSummary/RenderListView.scss +9 -0
- package/dist/components/CollectionSummary/RenderListView.test.js +42 -5
- package/dist/components/CollectionSummary/SummaryCard.js +6 -4
- package/dist/components/CollectionSummary/SummaryCard.scss +6 -0
- package/dist/components/CollectionSummary/SummaryCard.test.js +5 -5
- package/dist/components/CollectionSummary/SummaryCardDetails.js +3 -2
- package/dist/components/CollectionSummary/SummaryCardDetails.scss +2 -0
- package/dist/components/FormComponent/Collection.js +2 -1
- package/dist/components/FormComponent/Collection.scss +1 -1
- package/dist/components/FormComponent/Container.js +2 -0
- package/dist/components/FormComponent/Container.scss +15 -0
- package/dist/components/FormComponent/FormComponent.js +1 -1
- package/dist/components/FormPage/FormPage.js +19 -7
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.js +25 -13
- package/dist/components/FormRenderer/helpers/cleanHiddenNestedData.test.js +59 -1
- package/dist/components/FormRenderer/onPageAction.js +5 -1
- package/dist/json/actions.json +17 -0
- package/dist/json/actionsNoSave.json +17 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +7 -4
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +39 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -1
- package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +2 -1
- package/dist/utils/CollectionPage/mergeCollectionPages.test.js +0 -26
- package/dist/utils/CollectionPage/setCollectionPageData.js +2 -1
- package/dist/utils/Data/deleteValues.js +22 -0
- package/dist/utils/Data/deleteValues.test.js +57 -0
- package/dist/utils/Data/getAutocompleteSource.test.js +14 -5
- package/dist/utils/Data/getOptions.js +2 -1
- package/dist/utils/Data/getOptions.test.js +26 -8
- package/dist/utils/Data/index.js +2 -0
- package/dist/utils/Operate/deleteValueInFormData.js +26 -0
- package/dist/utils/Operate/deleteValueInFormData.test.js +60 -0
- package/dist/utils/Operate/runPageOperations.js +2 -0
- package/dist/utils/Validate/additional/conditionallyPermittedChange.js +25 -0
- package/dist/utils/Validate/additional/conditionallyPermittedChange.test.js +33 -0
- package/dist/utils/Validate/additional/index.js +6 -1
- package/dist/utils/Validate/additional/index.test.js +66 -0
- package/dist/utils/Validate/additional/mustBeOneOf.js +21 -0
- package/dist/utils/Validate/additional/mustBeOneOf.test.js +36 -0
- package/package.json +4 -3
|
@@ -103,6 +103,45 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
103
103
|
expect(ROWS.length).toEqual(7); // Collection title, item title, action rows & component rows
|
|
104
104
|
expect(ROWS[1].key).toEqual('Collection entry 1');
|
|
105
105
|
});
|
|
106
|
+
it('should hide titles when hideItemTitles is true', function () {
|
|
107
|
+
var FORM_DATA = {
|
|
108
|
+
collection: [{
|
|
109
|
+
id: '01',
|
|
110
|
+
testText: 'value'
|
|
111
|
+
}]
|
|
112
|
+
};
|
|
113
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
114
|
+
formData: FORM_DATA,
|
|
115
|
+
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
116
|
+
hideItemTitles: true
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
120
|
+
expect(ROWS.length).toEqual(6); // Collection title, NO item title, action rows & component rows
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should hide titles when hideItemTitles is a show_when that is true', function () {
|
|
124
|
+
var FORM_DATA = {
|
|
125
|
+
shouldShow: false,
|
|
126
|
+
collection: [{
|
|
127
|
+
id: '01',
|
|
128
|
+
testText: 'value'
|
|
129
|
+
}]
|
|
130
|
+
};
|
|
131
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
132
|
+
formData: FORM_DATA,
|
|
133
|
+
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
134
|
+
hideItemTitles: [{
|
|
135
|
+
field: 'shouldShow',
|
|
136
|
+
op: '=',
|
|
137
|
+
value: false
|
|
138
|
+
}]
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
142
|
+
expect(ROWS.length).toEqual(6); // Collection title, NO item title, action rows & component rows
|
|
143
|
+
});
|
|
144
|
+
|
|
106
145
|
it('should provide default titles if collection.labels.item is not specified', function () {
|
|
107
146
|
var FORM_DATA = {
|
|
108
147
|
collection: [{
|
|
@@ -33,7 +33,7 @@ var showComponentCYA = function showComponentCYA(options, data) {
|
|
|
33
33
|
}
|
|
34
34
|
if (options.hideOnCyaWhenEmpty) {
|
|
35
35
|
if (options.type === _models.ComponentTypes.COLLECTION) {
|
|
36
|
-
var itemCollectionsData = (0, _getSourceData.default)(data, options.full_path);
|
|
36
|
+
var itemCollectionsData = (0, _getSourceData.default)(data, options.full_path || options.fieldId);
|
|
37
37
|
if (!(itemCollectionsData !== null && itemCollectionsData !== void 0 && itemCollectionsData.length)) {
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _uuid = require("uuid");
|
|
7
8
|
var _getCollectionPageData = _interopRequireDefault(require("./getCollectionPageData"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
10
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
@@ -33,7 +34,7 @@ var duplicateCollectionPageEntry = function duplicateCollectionPageEntry(collect
|
|
|
33
34
|
if (!entryToDuplicate) {
|
|
34
35
|
return null;
|
|
35
36
|
}
|
|
36
|
-
var newEntryId =
|
|
37
|
+
var newEntryId = (0, _uuid.v4)();
|
|
37
38
|
var newEntry = _objectSpread(_objectSpread(_objectSpread({}, entryToDuplicate), fieldsToAdd), {}, {
|
|
38
39
|
id: newEntryId
|
|
39
40
|
});
|
|
@@ -23,32 +23,6 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
|
|
|
23
23
|
}];
|
|
24
24
|
expect((0, _mergeCollectionPages.default)(PAGES)).toEqual(PAGES);
|
|
25
25
|
});
|
|
26
|
-
it('should merge pages from the same collection into a single page', function () {
|
|
27
|
-
var PAGES = [{
|
|
28
|
-
id: 'page1',
|
|
29
|
-
collection: {
|
|
30
|
-
name: 'collection'
|
|
31
|
-
},
|
|
32
|
-
components: [TEXT_COMP]
|
|
33
|
-
}, {
|
|
34
|
-
id: 'page2',
|
|
35
|
-
collection: {
|
|
36
|
-
name: 'collection'
|
|
37
|
-
},
|
|
38
|
-
components: [DATE_COMP]
|
|
39
|
-
}];
|
|
40
|
-
var RESULT = (0, _mergeCollectionPages.default)(PAGES);
|
|
41
|
-
expect(RESULT.length).toEqual(1);
|
|
42
|
-
expect(RESULT[0]).toMatchObject({
|
|
43
|
-
id: 'page1',
|
|
44
|
-
collection: {
|
|
45
|
-
name: 'collection',
|
|
46
|
-
masterPage: true
|
|
47
|
-
},
|
|
48
|
-
formData: {},
|
|
49
|
-
childPages: PAGES
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
26
|
it('should correctly merge and nest child collection pages under their parents', function () {
|
|
53
27
|
var PAGES = [{
|
|
54
28
|
id: 'page1',
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _uuid = require("uuid");
|
|
7
8
|
var isValidIndex = function isValidIndex(value) {
|
|
8
9
|
return typeof value === 'number' && value >= 0;
|
|
9
10
|
};
|
|
@@ -36,7 +37,7 @@ var setCollectionPageData = function setCollectionPageData(collectionName, newDa
|
|
|
36
37
|
if (!data[name].find(function (e) {
|
|
37
38
|
return e.id === formData["".concat(name, "ActiveId")];
|
|
38
39
|
})) {
|
|
39
|
-
var newEntryId =
|
|
40
|
+
var newEntryId = (0, _uuid.v4)();
|
|
40
41
|
// eslint-disable-next-line no-param-reassign
|
|
41
42
|
formData["".concat(name, "ActiveId")] = formData["".concat(name, "ActiveId")] || newEntryId;
|
|
42
43
|
data[name].push({
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Find values in data not in formData
|
|
9
|
+
* and delete them from data.
|
|
10
|
+
* @param {object} data The page's data.
|
|
11
|
+
* @param {object} formData The page's formData.
|
|
12
|
+
*/
|
|
13
|
+
var deleteValues = function deleteValues(data, formData) {
|
|
14
|
+
var deletedValues = Object.keys(data).filter(function (k) {
|
|
15
|
+
return !(k in formData);
|
|
16
|
+
});
|
|
17
|
+
var node = data;
|
|
18
|
+
deletedValues.forEach(function (i) {
|
|
19
|
+
return delete node[i];
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var _default = exports.default = deleteValues;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _deleteValues = _interopRequireDefault(require("./deleteValues"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('Utils.Data.deleteValues', function () {
|
|
6
|
+
it('Should delete values from data', function () {
|
|
7
|
+
var DATA = {
|
|
8
|
+
a: '1',
|
|
9
|
+
b: '2',
|
|
10
|
+
c: '3'
|
|
11
|
+
};
|
|
12
|
+
var FORMDATA = {
|
|
13
|
+
a: '1'
|
|
14
|
+
};
|
|
15
|
+
(0, _deleteValues.default)(DATA, FORMDATA);
|
|
16
|
+
expect(DATA).toEqual({
|
|
17
|
+
a: '1'
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
it('Should leave data unchanged if no differences', function () {
|
|
21
|
+
var DATA = {
|
|
22
|
+
a: '1',
|
|
23
|
+
b: '2',
|
|
24
|
+
c: '3'
|
|
25
|
+
};
|
|
26
|
+
var FORMDATA = {
|
|
27
|
+
a: '1',
|
|
28
|
+
b: '2',
|
|
29
|
+
c: '3'
|
|
30
|
+
};
|
|
31
|
+
(0, _deleteValues.default)(DATA, FORMDATA);
|
|
32
|
+
expect(DATA).toEqual({
|
|
33
|
+
a: '1',
|
|
34
|
+
b: '2',
|
|
35
|
+
c: '3'
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
it('Should leave data unchanged if form data has additional fields', function () {
|
|
39
|
+
var DATA = {
|
|
40
|
+
a: '1',
|
|
41
|
+
b: '2',
|
|
42
|
+
c: '3'
|
|
43
|
+
};
|
|
44
|
+
var FORMDATA = {
|
|
45
|
+
a: '1',
|
|
46
|
+
b: '2',
|
|
47
|
+
c: '3',
|
|
48
|
+
d: '4'
|
|
49
|
+
};
|
|
50
|
+
(0, _deleteValues.default)(DATA, FORMDATA);
|
|
51
|
+
expect(DATA).toEqual({
|
|
52
|
+
a: '1',
|
|
53
|
+
b: '2',
|
|
54
|
+
c: '3'
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -14,6 +14,7 @@ describe('utils', function () {
|
|
|
14
14
|
var gbCurrency = {
|
|
15
15
|
currencyName: 'Great British Pounds',
|
|
16
16
|
currencyCode: 'GBP',
|
|
17
|
+
hint: 'hint',
|
|
17
18
|
value: 'GBP',
|
|
18
19
|
label: 'GBP',
|
|
19
20
|
slangTerm: 'quid'
|
|
@@ -21,6 +22,7 @@ describe('utils', function () {
|
|
|
21
22
|
var usCurrency = {
|
|
22
23
|
currencyName: 'United States Dollars',
|
|
23
24
|
currencyCode: 'USD',
|
|
25
|
+
hint: 'hint',
|
|
24
26
|
value: 'USD',
|
|
25
27
|
label: 'USD',
|
|
26
28
|
slangTerm: 'bucks',
|
|
@@ -29,19 +31,23 @@ describe('utils', function () {
|
|
|
29
31
|
var options = {
|
|
30
32
|
alpha: {
|
|
31
33
|
value: 'a',
|
|
32
|
-
label: 'Alpha'
|
|
34
|
+
label: 'Alpha',
|
|
35
|
+
hint: 'hint'
|
|
33
36
|
},
|
|
34
37
|
bravo: {
|
|
35
38
|
value: 'b',
|
|
36
|
-
label: 'Bravo'
|
|
39
|
+
label: 'Bravo',
|
|
40
|
+
hint: 'hint'
|
|
37
41
|
},
|
|
38
42
|
alIncluded: {
|
|
39
43
|
value: 'c',
|
|
40
|
-
label: 'Call me alan'
|
|
44
|
+
label: 'Call me alan',
|
|
45
|
+
hint: 'hint'
|
|
41
46
|
},
|
|
42
47
|
alStart: {
|
|
43
48
|
value: 'd',
|
|
44
|
-
label: 'Word Alphabet'
|
|
49
|
+
label: 'Word Alphabet',
|
|
50
|
+
hint: 'hint'
|
|
45
51
|
}
|
|
46
52
|
};
|
|
47
53
|
var testCurrencies = [gbCurrency, usCurrency];
|
|
@@ -71,7 +77,8 @@ describe('utils', function () {
|
|
|
71
77
|
expect(results.length).toEqual(1);
|
|
72
78
|
expect(results).toEqual([{
|
|
73
79
|
value: 'a',
|
|
74
|
-
label: 'Alpha'
|
|
80
|
+
label: 'Alpha',
|
|
81
|
+
hint: 'hint'
|
|
75
82
|
}]);
|
|
76
83
|
});
|
|
77
84
|
});
|
|
@@ -249,6 +256,7 @@ describe('utils', function () {
|
|
|
249
256
|
options: [gbCurrency, {
|
|
250
257
|
currencyName: 'United States Dollars',
|
|
251
258
|
currencyCode: 'USD',
|
|
259
|
+
hint: 'hint',
|
|
252
260
|
value: 'USD'
|
|
253
261
|
}]
|
|
254
262
|
}
|
|
@@ -263,6 +271,7 @@ describe('utils', function () {
|
|
|
263
271
|
expect(results).toEqual([gbCurrency, {
|
|
264
272
|
currencyName: 'United States Dollars',
|
|
265
273
|
currencyCode: 'USD',
|
|
274
|
+
hint: 'hint',
|
|
266
275
|
value: 'USD',
|
|
267
276
|
label: ''
|
|
268
277
|
}]);
|
|
@@ -32,7 +32,8 @@ var interpolateOptions = function interpolateOptions(config, options) {
|
|
|
32
32
|
}
|
|
33
33
|
return _objectSpread(_objectSpread({}, opt), {}, {
|
|
34
34
|
value: _copReactComponents.Utils.interpolateString(opt.value, config.formData),
|
|
35
|
-
label: _copReactComponents.Utils.interpolateString(opt.label, config.formData)
|
|
35
|
+
label: _copReactComponents.Utils.interpolateString(opt.label, config.formData),
|
|
36
|
+
hint: _copReactComponents.Utils.interpolateString(opt.hint, config.formData)
|
|
36
37
|
});
|
|
37
38
|
}).filter(function (n) {
|
|
38
39
|
return n;
|
|
@@ -16,10 +16,12 @@ describe('utils', function () {
|
|
|
16
16
|
var CONFIG = {
|
|
17
17
|
options: [{
|
|
18
18
|
value: 'a',
|
|
19
|
-
label: 'Alpha'
|
|
19
|
+
label: 'Alpha',
|
|
20
|
+
hint: ''
|
|
20
21
|
}, {
|
|
21
22
|
value: 'b',
|
|
22
|
-
label: 'Bravo'
|
|
23
|
+
label: 'Bravo',
|
|
24
|
+
hint: ''
|
|
23
25
|
}]
|
|
24
26
|
};
|
|
25
27
|
(0, _getOptions.default)(CONFIG, function (options) {
|
|
@@ -31,10 +33,12 @@ describe('utils', function () {
|
|
|
31
33
|
data: {
|
|
32
34
|
options: [{
|
|
33
35
|
value: 'a',
|
|
34
|
-
label: 'Alpha'
|
|
36
|
+
label: 'Alpha',
|
|
37
|
+
hint: ''
|
|
35
38
|
}, {
|
|
36
39
|
value: 'b',
|
|
37
|
-
label: 'Bravo'
|
|
40
|
+
label: 'Bravo',
|
|
41
|
+
hint: ''
|
|
38
42
|
}]
|
|
39
43
|
}
|
|
40
44
|
};
|
|
@@ -46,10 +50,12 @@ describe('utils', function () {
|
|
|
46
50
|
var CONFIG = {
|
|
47
51
|
options: [{
|
|
48
52
|
value: 'a',
|
|
49
|
-
label: 'Alpha'
|
|
53
|
+
label: 'Alpha',
|
|
54
|
+
hint: ''
|
|
50
55
|
}, {
|
|
51
56
|
value: 'b',
|
|
52
|
-
label: 'Bravo'
|
|
57
|
+
label: 'Bravo',
|
|
58
|
+
hint: ''
|
|
53
59
|
}],
|
|
54
60
|
data: {
|
|
55
61
|
options: [{
|
|
@@ -71,6 +77,7 @@ describe('utils', function () {
|
|
|
71
77
|
options: [{
|
|
72
78
|
value: 'a',
|
|
73
79
|
label: 'Alpha',
|
|
80
|
+
hint: '',
|
|
74
81
|
show_when: {
|
|
75
82
|
field: 'other',
|
|
76
83
|
op: 'eq',
|
|
@@ -79,6 +86,7 @@ describe('utils', function () {
|
|
|
79
86
|
}, {
|
|
80
87
|
value: 'b',
|
|
81
88
|
label: 'Bravo',
|
|
89
|
+
hint: '',
|
|
82
90
|
show_when: {
|
|
83
91
|
field: 'other',
|
|
84
92
|
op: 'neq',
|
|
@@ -99,6 +107,7 @@ describe('utils', function () {
|
|
|
99
107
|
options: [{
|
|
100
108
|
value: 'a',
|
|
101
109
|
label: 'Alpha',
|
|
110
|
+
hint: '',
|
|
102
111
|
show_when: {
|
|
103
112
|
type: 'or',
|
|
104
113
|
conditions: [{
|
|
@@ -114,6 +123,7 @@ describe('utils', function () {
|
|
|
114
123
|
}, {
|
|
115
124
|
value: 'b',
|
|
116
125
|
label: 'Bravo',
|
|
126
|
+
hint: '',
|
|
117
127
|
show_when: {
|
|
118
128
|
type: 'or',
|
|
119
129
|
conditions: [{
|
|
@@ -152,16 +162,19 @@ describe('utils', function () {
|
|
|
152
162
|
options: [{
|
|
153
163
|
id: 1,
|
|
154
164
|
description: 'First refdata item',
|
|
165
|
+
hint: '',
|
|
155
166
|
value: 'firstValue',
|
|
156
167
|
label: 'First label'
|
|
157
168
|
}, {
|
|
158
169
|
id: 2,
|
|
159
170
|
description: 'Second refdata item',
|
|
171
|
+
hint: '',
|
|
160
172
|
value: 'secondValue',
|
|
161
173
|
label: 'Second label'
|
|
162
174
|
}, {
|
|
163
175
|
id: 3,
|
|
164
176
|
description: 'Third refdata item',
|
|
177
|
+
hint: '',
|
|
165
178
|
value: 'thirdValue',
|
|
166
179
|
label: 'Third label'
|
|
167
180
|
}]
|
|
@@ -169,11 +182,13 @@ describe('utils', function () {
|
|
|
169
182
|
var MERGED_CONFIG = [{
|
|
170
183
|
id: 1,
|
|
171
184
|
description: 'First refdata item',
|
|
185
|
+
hint: '',
|
|
172
186
|
value: 'firstValue',
|
|
173
187
|
label: 'First label'
|
|
174
188
|
}, {
|
|
175
189
|
id: 2,
|
|
176
190
|
description: 'Second refdata item',
|
|
191
|
+
hint: '',
|
|
177
192
|
value: 'secondValue',
|
|
178
193
|
nested: [{
|
|
179
194
|
value: 'a',
|
|
@@ -183,6 +198,7 @@ describe('utils', function () {
|
|
|
183
198
|
}, {
|
|
184
199
|
id: 3,
|
|
185
200
|
description: 'Third refdata item',
|
|
201
|
+
hint: '',
|
|
186
202
|
value: 'thirdValue',
|
|
187
203
|
label: 'Third label'
|
|
188
204
|
}];
|
|
@@ -196,11 +212,13 @@ describe('utils', function () {
|
|
|
196
212
|
options: [{
|
|
197
213
|
value: 'a',
|
|
198
214
|
label: 'Alpha',
|
|
199
|
-
description: 'first'
|
|
215
|
+
description: 'first',
|
|
216
|
+
hint: ''
|
|
200
217
|
}, {
|
|
201
218
|
value: 'b',
|
|
202
219
|
label: 'Bravo',
|
|
203
|
-
description: 'second'
|
|
220
|
+
description: 'second',
|
|
221
|
+
hint: ''
|
|
204
222
|
}]
|
|
205
223
|
};
|
|
206
224
|
(0, _getOptions.default)(CONFIG, function (options) {
|
package/dist/utils/Data/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var _getDataPath = _interopRequireDefault(require("./getDataPath"));
|
|
|
10
10
|
var _getOptions = _interopRequireDefault(require("./getOptions"));
|
|
11
11
|
var _getSourceData = _interopRequireDefault(require("./getSourceData"));
|
|
12
12
|
var _refDataToOptions = _interopRequireDefault(require("./refDataToOptions"));
|
|
13
|
+
var _deleteValues = _interopRequireDefault(require("./deleteValues"));
|
|
13
14
|
var _setDataItem = _interopRequireDefault(require("./setDataItem"));
|
|
14
15
|
var _setupFormData = _interopRequireDefault(require("./setupFormData"));
|
|
15
16
|
var _setupRefDataUrlForComponent = _interopRequireDefault(require("./setupRefDataUrlForComponent"));
|
|
@@ -26,6 +27,7 @@ var Data = {
|
|
|
26
27
|
setupUrl: _setupRefDataUrlForComponent.default,
|
|
27
28
|
toOptions: _refDataToOptions.default
|
|
28
29
|
},
|
|
30
|
+
deleteValues: _deleteValues.default,
|
|
29
31
|
setDataItem: _setDataItem.default,
|
|
30
32
|
setupForm: _setupFormData.default
|
|
31
33
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Simple operation to delete a value in the form data.
|
|
9
|
+
* @param {object} config The operation config.
|
|
10
|
+
* @param {object} data The page's formData.
|
|
11
|
+
* @param {function} onChange The page's onChange handler.
|
|
12
|
+
*/
|
|
13
|
+
var deleteValueInFormData = function deleteValueInFormData(config, data, onChange) {
|
|
14
|
+
var node = data;
|
|
15
|
+
if (config !== null && config !== void 0 && config.field && config !== null && config !== void 0 && config.component) {
|
|
16
|
+
delete node[config.field];
|
|
17
|
+
onChange({
|
|
18
|
+
target: {
|
|
19
|
+
name: config.field,
|
|
20
|
+
value: null,
|
|
21
|
+
component: config.component
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var _default = exports.default = deleteValueInFormData;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _deleteValueInFormData = _interopRequireDefault(require("./deleteValueInFormData"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('Utils.Operate.deleteValueInFormData', function () {
|
|
6
|
+
var ON_CHANGE = function ON_CHANGE() {};
|
|
7
|
+
it('Should delete value from data', function () {
|
|
8
|
+
var CONFIG = {
|
|
9
|
+
field: 'a',
|
|
10
|
+
component: 'A'
|
|
11
|
+
};
|
|
12
|
+
var DATA = {
|
|
13
|
+
a: '1',
|
|
14
|
+
b: '2'
|
|
15
|
+
};
|
|
16
|
+
(0, _deleteValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
17
|
+
expect(DATA).toEqual({
|
|
18
|
+
b: '2'
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
it('Should do nothing if value is absent', function () {
|
|
22
|
+
var CONFIG = {
|
|
23
|
+
field: 'c',
|
|
24
|
+
component: 'C'
|
|
25
|
+
};
|
|
26
|
+
var DATA = {
|
|
27
|
+
a: '1',
|
|
28
|
+
b: '2'
|
|
29
|
+
};
|
|
30
|
+
(0, _deleteValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
31
|
+
expect(DATA).toEqual({
|
|
32
|
+
a: '1',
|
|
33
|
+
b: '2'
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it('Should do nothing if config is null', function () {
|
|
37
|
+
var CONFIG = null;
|
|
38
|
+
var DATA = {
|
|
39
|
+
a: '1',
|
|
40
|
+
b: '2'
|
|
41
|
+
};
|
|
42
|
+
(0, _deleteValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
43
|
+
expect(DATA).toEqual({
|
|
44
|
+
a: '1',
|
|
45
|
+
b: '2'
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it('Should do nothing if config is empty', function () {
|
|
49
|
+
var CONFIG = {};
|
|
50
|
+
var DATA = {
|
|
51
|
+
a: '1',
|
|
52
|
+
b: '2'
|
|
53
|
+
};
|
|
54
|
+
(0, _deleteValueInFormData.default)(CONFIG, DATA, ON_CHANGE);
|
|
55
|
+
expect(DATA).toEqual({
|
|
56
|
+
a: '1',
|
|
57
|
+
b: '2'
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -9,6 +9,7 @@ var _checkValueIsTruthy = _interopRequireDefault(require("./checkValueIsTruthy")
|
|
|
9
9
|
var _getIndexOfMatchingValueIn = _interopRequireDefault(require("./getIndexOfMatchingValueIn"));
|
|
10
10
|
var _persistValueInFormData = _interopRequireDefault(require("./persistValueInFormData"));
|
|
11
11
|
var _setValueInFormData = _interopRequireDefault(require("./setValueInFormData"));
|
|
12
|
+
var _deleteValueInFormData = _interopRequireDefault(require("./deleteValueInFormData"));
|
|
12
13
|
var _shouldRun = _interopRequireDefault(require("./shouldRun"));
|
|
13
14
|
var _setDataItem = _interopRequireDefault(require("../Data/setDataItem"));
|
|
14
15
|
var _getFirstOf = _interopRequireDefault(require("./getFirstOf"));
|
|
@@ -23,6 +24,7 @@ var functions = {
|
|
|
23
24
|
getIndexOfMatchingValueIn: _getIndexOfMatchingValueIn.default,
|
|
24
25
|
persistValueInFormData: _persistValueInFormData.default,
|
|
25
26
|
setValueInFormData: _setValueInFormData.default,
|
|
27
|
+
deleteValueInFormData: _deleteValueInFormData.default,
|
|
26
28
|
getLength: _getLength.default,
|
|
27
29
|
getFirstOf: _getFirstOf.default
|
|
28
30
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Additional validator to not permit a value change if a specified item exists in formData.
|
|
9
|
+
* @param {object} data the changed value
|
|
10
|
+
* @param {object} config the config for the validation must contain
|
|
11
|
+
* a property 'base' holding the value for checking
|
|
12
|
+
* a property 'check' holding the formData item name to check if exists
|
|
13
|
+
* @param {object} formData the form data
|
|
14
|
+
* @returns false if:
|
|
15
|
+
* the 'base' value is not the same as the changed value AND
|
|
16
|
+
* the 'check' value exists in formData as an item
|
|
17
|
+
* otherwise returns true
|
|
18
|
+
*/
|
|
19
|
+
var conditionallyPermittedChange = function conditionallyPermittedChange(data, config, _, formData) {
|
|
20
|
+
if (data !== config.base && formData[config.check]) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
var _default = exports.default = conditionallyPermittedChange;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _conditionallyPermittedChange = _interopRequireDefault(require("./conditionallyPermittedChange"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('utils', function () {
|
|
6
|
+
describe('Validate', function () {
|
|
7
|
+
describe('additional', function () {
|
|
8
|
+
describe('conditionallyPermittedChange', function () {
|
|
9
|
+
var CONFIG = {
|
|
10
|
+
base: 'Value1',
|
|
11
|
+
check: 'Item1'
|
|
12
|
+
};
|
|
13
|
+
test('should pass if the base value has same value as data parameter', function () {
|
|
14
|
+
var DATA = 'Value1';
|
|
15
|
+
var FORMDATA = {};
|
|
16
|
+
expect((0, _conditionallyPermittedChange.default)(DATA, CONFIG, null, FORMDATA)).toEqual(true);
|
|
17
|
+
});
|
|
18
|
+
test('should fail if the base value is different to data parameter and check item exists in form data', function () {
|
|
19
|
+
var DATA = 'Value2';
|
|
20
|
+
var FORMDATA = {
|
|
21
|
+
Item1: "any"
|
|
22
|
+
};
|
|
23
|
+
expect((0, _conditionallyPermittedChange.default)(DATA, CONFIG, null, FORMDATA)).toEqual(false);
|
|
24
|
+
});
|
|
25
|
+
test('should pass if the base value is different to data parameter and check item not exists in form data', function () {
|
|
26
|
+
var DATA = 'Value2';
|
|
27
|
+
var FORMDATA = {};
|
|
28
|
+
expect((0, _conditionallyPermittedChange.default)(DATA, CONFIG, null, FORMDATA)).toEqual(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _conditionallyPermittedChange = _interopRequireDefault(require("./conditionallyPermittedChange"));
|
|
7
8
|
var _conditionallyRequired = _interopRequireDefault(require("./conditionallyRequired"));
|
|
8
9
|
var _mustBeAfter = _interopRequireDefault(require("./mustBeAfter"));
|
|
9
10
|
var _mustBeBefore = _interopRequireDefault(require("./mustBeBefore"));
|
|
@@ -15,6 +16,7 @@ var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
|
|
|
15
16
|
var _mustBeGreaterThan = _interopRequireDefault(require("./mustBeGreaterThan"));
|
|
16
17
|
var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
|
|
17
18
|
var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
|
|
19
|
+
var _mustBeOneOf = _interopRequireDefault(require("./mustBeOneOf"));
|
|
18
20
|
var _mustBeUniqueInCollection = _interopRequireDefault(require("./mustBeUniqueInCollection"));
|
|
19
21
|
var _mustEnterAtLeastOne = _interopRequireDefault(require("./mustEnterAtLeastOne"));
|
|
20
22
|
var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveLessThanDecimalPlaces"));
|
|
@@ -24,6 +26,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
24
26
|
// Local imports
|
|
25
27
|
|
|
26
28
|
var functions = {
|
|
29
|
+
conditionallyPermittedChange: _conditionallyPermittedChange.default,
|
|
27
30
|
conditionallyRequired: _conditionallyRequired.default,
|
|
28
31
|
mustBeAfter: _mustBeAfter.default,
|
|
29
32
|
mustBeBefore: _mustBeBefore.default,
|
|
@@ -34,6 +37,7 @@ var functions = {
|
|
|
34
37
|
mustBeLessThan: _mustBeLessThan.default,
|
|
35
38
|
mustBeLongerThan: _mustBeLongerThan.default,
|
|
36
39
|
mustBeNumbersOnly: _mustBeNumbersOnly.default,
|
|
40
|
+
mustBeOneOf: _mustBeOneOf.default,
|
|
37
41
|
mustBeShorterThan: _mustBeShorterThan.default,
|
|
38
42
|
mustBeUniqueInCollection: _mustBeUniqueInCollection.default,
|
|
39
43
|
mustEnterAtLeastOne: _mustEnterAtLeastOne.default,
|
|
@@ -43,8 +47,9 @@ var functions = {
|
|
|
43
47
|
};
|
|
44
48
|
var additionalValidation = function additionalValidation(value, config, component, formData) {
|
|
45
49
|
var fn = functions[config.function];
|
|
50
|
+
var valueToValidate = config.objectValueToUse ? value[config.objectValueToUse] : value;
|
|
46
51
|
if (typeof fn === 'function') {
|
|
47
|
-
return fn(
|
|
52
|
+
return fn(valueToValidate, config, component, formData) ? undefined : config.message;
|
|
48
53
|
}
|
|
49
54
|
return undefined;
|
|
50
55
|
};
|