@ukhomeoffice/cop-react-form-renderer 4.62.0 → 4.63.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.
|
@@ -7,6 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
9
9
|
|
|
10
|
+
var _Condition = _interopRequireDefault(require("../Condition"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
10
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
15
|
|
|
12
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -15,6 +19,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
15
19
|
|
|
16
20
|
var interpolateOptions = function interpolateOptions(config, options) {
|
|
17
21
|
return options.map(function (opt) {
|
|
22
|
+
if (opt.show_when) {
|
|
23
|
+
var result = opt.show_when.type === 'or' ? _Condition.default.meetsOne(opt, config.formData) : _Condition.default.meetsAll(opt, config.formData);
|
|
24
|
+
|
|
25
|
+
if (!result) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
if (typeof opt === 'string') {
|
|
19
31
|
return opt;
|
|
20
32
|
}
|
|
@@ -23,6 +35,8 @@ var interpolateOptions = function interpolateOptions(config, options) {
|
|
|
23
35
|
value: _copReactComponents.Utils.interpolateString(opt.value, config.formData),
|
|
24
36
|
label: _copReactComponents.Utils.interpolateString(opt.label, config.formData)
|
|
25
37
|
});
|
|
38
|
+
}).filter(function (n) {
|
|
39
|
+
return n;
|
|
26
40
|
});
|
|
27
41
|
};
|
|
28
42
|
|
|
@@ -66,6 +66,76 @@ describe('utils', function () {
|
|
|
66
66
|
expect(options).toEqual(CONFIG.options);
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
|
+
it('should exclude options from the config that fail show_when checks', function () {
|
|
70
|
+
var CONFIG = {
|
|
71
|
+
id: 'test',
|
|
72
|
+
options: [{
|
|
73
|
+
value: 'a',
|
|
74
|
+
label: 'Alpha',
|
|
75
|
+
show_when: {
|
|
76
|
+
field: 'other',
|
|
77
|
+
op: 'eq',
|
|
78
|
+
value: 'c'
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
value: 'b',
|
|
82
|
+
label: 'Bravo',
|
|
83
|
+
show_when: {
|
|
84
|
+
field: 'other',
|
|
85
|
+
op: 'neq',
|
|
86
|
+
value: 'c'
|
|
87
|
+
}
|
|
88
|
+
}],
|
|
89
|
+
formData: {
|
|
90
|
+
other: 'c'
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
(0, _getOptions.default)(CONFIG, function (options) {
|
|
94
|
+
expect(options).toEqual([CONFIG.options[0]]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
it('should exclude options from the config that fail or type show_when checks', function () {
|
|
98
|
+
var CONFIG = {
|
|
99
|
+
id: 'test',
|
|
100
|
+
options: [{
|
|
101
|
+
value: 'a',
|
|
102
|
+
label: 'Alpha',
|
|
103
|
+
show_when: {
|
|
104
|
+
type: 'or',
|
|
105
|
+
conditions: [{
|
|
106
|
+
field: 'other',
|
|
107
|
+
op: 'eq',
|
|
108
|
+
value: 'c'
|
|
109
|
+
}, {
|
|
110
|
+
field: 'other',
|
|
111
|
+
op: 'eq',
|
|
112
|
+
value: 'd'
|
|
113
|
+
}]
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
value: 'b',
|
|
117
|
+
label: 'Bravo',
|
|
118
|
+
show_when: {
|
|
119
|
+
type: 'or',
|
|
120
|
+
conditions: [{
|
|
121
|
+
field: 'other',
|
|
122
|
+
op: 'eq',
|
|
123
|
+
value: 'e'
|
|
124
|
+
}, {
|
|
125
|
+
field: 'other',
|
|
126
|
+
op: 'eq',
|
|
127
|
+
value: 'f'
|
|
128
|
+
}]
|
|
129
|
+
}
|
|
130
|
+
}],
|
|
131
|
+
formData: {
|
|
132
|
+
other: 'c'
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
(0, _getOptions.default)(CONFIG, function (options) {
|
|
136
|
+
expect(options).toEqual([CONFIG.options[0]]);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
69
139
|
});
|
|
70
140
|
});
|
|
71
141
|
});
|