@ukhomeoffice/cop-react-form-renderer 5.60.0 → 5.61.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.
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
7
8
  var _Data = _interopRequireDefault(require("../Data"));
8
9
  var _meetsCondition = _interopRequireDefault(require("./meetsCondition"));
9
10
  var _setupConditions = _interopRequireDefault(require("./setupConditions"));
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ // Global imports
13
+
11
14
  // Local imports
12
15
 
13
16
  var testConditions = function testConditions(conditions, data) {
@@ -17,7 +20,8 @@ var testConditions = function testConditions(conditions, data) {
17
20
  if (Array.isArray(condition.conditions)) {
18
21
  return testConditions(condition.conditions, data, condition.type);
19
22
  }
20
- var sourceDataValue = _Data.default.getSource(data, condition.field);
23
+ var field = condition.field.startsWith('interpolate::') ? _copReactComponents.Utils.interpolateString(condition.field, data).replace('interpolate::', '') : condition.field;
24
+ var sourceDataValue = _Data.default.getSource(data, field);
21
25
  return (0, _meetsCondition.default)(condition, sourceDataValue, data);
22
26
  };
23
27
  return type === 'and' ? arr.every(testCallback) : arr.some(testCallback);
@@ -92,4 +92,17 @@ describe('utils.Condition.meetsAllConditions', function () {
92
92
  expect((0, _meetsAllConditions.default)(CONDITIONS, VALID_DATA)).toBeTruthy();
93
93
  expect((0, _meetsAllConditions.default)(CONDITIONS, INVALID_DATA)).toBeFalsy();
94
94
  });
95
+ it('should evaluate conditions correctly using interpolated fields', function () {
96
+ var NEW_DATA = {
97
+ role: 'admin',
98
+ 'admin_status': 'active'
99
+ };
100
+ var CONDITION = {
101
+ // eslint-disable-next-line no-template-curly-in-string
102
+ field: 'interpolate::${role}_status',
103
+ op: 'eq',
104
+ value: 'active'
105
+ };
106
+ expect((0, _meetsAllConditions.default)([CONDITION], NEW_DATA)).toBeTruthy();
107
+ });
95
108
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.60.0",
3
+ "version": "5.61.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",