@ukhomeoffice/cop-react-form-renderer 6.0.5-peter → 6.0.6-peter
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.
|
@@ -27,26 +27,36 @@ var recurseCheckForHiddenComponents = function recurseCheckForHiddenComponents(c
|
|
|
27
27
|
if (!(0, _optionIsSelected.default)(formData[component.id], option) && option.nested) {
|
|
28
28
|
option.nested.forEach(function (nested) {
|
|
29
29
|
path = nested.fieldId;
|
|
30
|
-
|
|
30
|
+
if (path) {
|
|
31
|
+
candidateComponentForDeletion.set(path, component);
|
|
32
|
+
}
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
} else if (!(0, _showComponent.default)(component, formData)) {
|
|
36
|
-
|
|
38
|
+
if (path) {
|
|
39
|
+
candidateComponentForDeletion.set(path, component);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
};
|
|
40
44
|
var buildListOfComponentsUsedInVisiblePages = function buildListOfComponentsUsedInVisiblePages(page, form, formData, componentsUsedInVisiblePagesIds) {
|
|
41
45
|
var _page$components;
|
|
42
46
|
(_page$components = page.components) === null || _page$components === void 0 || _page$components.forEach(function (component) {
|
|
43
|
-
var _form$components$find;
|
|
44
|
-
var componentObj = (_form$components$find = form.components.find(function (c) {
|
|
47
|
+
var _ref, _form$components$find;
|
|
48
|
+
var componentObj = (_ref = (_form$components$find = form.components.find(function (c) {
|
|
45
49
|
return c.fieldId === component.use;
|
|
46
|
-
})) !== null && _form$components$find !== void 0 ? _form$components$find :
|
|
50
|
+
})) !== null && _form$components$find !== void 0 ? _form$components$find : form.components.find(function (c) {
|
|
51
|
+
return c.id === component.use;
|
|
52
|
+
})) !== null && _ref !== void 0 ? _ref : component;
|
|
47
53
|
if (page && (0, _showComponent.default)(page, formData)) {
|
|
48
54
|
if (componentObj && (0, _showComponent.default)(componentObj, formData)) {
|
|
49
|
-
|
|
55
|
+
if (componentObj.fieldId) {
|
|
56
|
+
componentsUsedInVisiblePagesIds.push(componentObj.fieldId);
|
|
57
|
+
} else if (componentObj.id) {
|
|
58
|
+
componentsUsedInVisiblePagesIds.push(componentObj.id);
|
|
59
|
+
}
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
});
|
|
@@ -74,15 +84,19 @@ var markComponentsForDeletion = function markComponentsForDeletion(page, form, f
|
|
|
74
84
|
return;
|
|
75
85
|
}
|
|
76
86
|
(_page$components2 = page.components) === null || _page$components2 === void 0 || _page$components2.forEach(function (component) {
|
|
77
|
-
var _form$components$find2;
|
|
78
|
-
var componentObj = (_form$components$find2 = form.components.find(function (c) {
|
|
87
|
+
var _ref2, _form$components$find2;
|
|
88
|
+
var componentObj = (_ref2 = (_form$components$find2 = form.components.find(function (c) {
|
|
79
89
|
return c.fieldId === component.use;
|
|
80
|
-
})) !== null && _form$components$find2 !== void 0 ? _form$components$find2 :
|
|
90
|
+
})) !== null && _form$components$find2 !== void 0 ? _form$components$find2 : form.components.find(function (c) {
|
|
91
|
+
return c.id === component.use;
|
|
92
|
+
})) !== null && _ref2 !== void 0 ? _ref2 : component;
|
|
81
93
|
if (page && (0, _showComponent.default)(page, formData)) {
|
|
82
94
|
buildListOfComponentsUsedInVisiblePages(page, form, formData, componentsUsedInVisiblePages);
|
|
83
95
|
recurseCheckForHiddenComponents(componentObj, formData, null, candidateComponentForDeletion);
|
|
84
|
-
} else {
|
|
96
|
+
} else if (componentObj.fieldId) {
|
|
85
97
|
candidateComponentForDeletion.set(componentObj.fieldId, componentObj);
|
|
98
|
+
} else if (componentObj.id) {
|
|
99
|
+
candidateComponentForDeletion.set(componentObj.id, componentObj);
|
|
86
100
|
}
|
|
87
101
|
});
|
|
88
102
|
};
|
|
@@ -90,27 +104,50 @@ var deleteHiddenComponent = function deleteHiddenComponent(page, form, collectio
|
|
|
90
104
|
if (page.disableClearWhenHidden) {
|
|
91
105
|
return;
|
|
92
106
|
}
|
|
93
|
-
if (page && (0, _showComponent.default)(page,
|
|
107
|
+
if (page && (0, _showComponent.default)(page, formData)) {
|
|
94
108
|
var _page$components3;
|
|
95
109
|
(_page$components3 = page.components) === null || _page$components3 === void 0 || _page$components3.forEach(function (component) {
|
|
96
|
-
var _form$components$find3;
|
|
97
|
-
var componentObj = (_form$components$find3 = form.components.find(function (c) {
|
|
110
|
+
var _ref3, _form$components$find3;
|
|
111
|
+
var componentObj = (_ref3 = (_form$components$find3 = form.components.find(function (c) {
|
|
98
112
|
return c.fieldId === component.use;
|
|
99
|
-
})) !== null && _form$components$find3 !== void 0 ? _form$components$find3 :
|
|
113
|
+
})) !== null && _form$components$find3 !== void 0 ? _form$components$find3 : form.components.find(function (c) {
|
|
114
|
+
return c.id === component.use;
|
|
115
|
+
})) !== null && _ref3 !== void 0 ? _ref3 : component;
|
|
100
116
|
recurseDeleteComponents(componentObj, collectionData, null, true);
|
|
101
117
|
});
|
|
102
118
|
} else {
|
|
103
119
|
var _page$components4;
|
|
104
120
|
// recursively delete all components on the page
|
|
105
121
|
(_page$components4 = page.components) === null || _page$components4 === void 0 || _page$components4.forEach(function (component) {
|
|
106
|
-
var _form$components$find4;
|
|
107
|
-
var componentObj = (_form$components$find4 = form.components.find(function (c) {
|
|
122
|
+
var _ref4, _form$components$find4;
|
|
123
|
+
var componentObj = (_ref4 = (_form$components$find4 = form.components.find(function (c) {
|
|
108
124
|
return c.fieldId === component.use;
|
|
109
|
-
})) !== null && _form$components$find4 !== void 0 ? _form$components$find4 :
|
|
125
|
+
})) !== null && _form$components$find4 !== void 0 ? _form$components$find4 : form.components.find(function (c) {
|
|
126
|
+
return c.id === component.use;
|
|
127
|
+
})) !== null && _ref4 !== void 0 ? _ref4 : component;
|
|
110
128
|
recurseDeleteComponents(componentObj, collectionData, null, false);
|
|
111
129
|
});
|
|
112
130
|
}
|
|
113
131
|
};
|
|
132
|
+
function clearUncompletedRoutesForCollections(formData, page, form) {
|
|
133
|
+
var _page$collection;
|
|
134
|
+
var collectionDatas = formData[page === null || page === void 0 || (_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name];
|
|
135
|
+
if (collectionDatas) {
|
|
136
|
+
collectionDatas.forEach(function (collectionData) {
|
|
137
|
+
var _page$childPages;
|
|
138
|
+
/* eslint-disable consistent-return */
|
|
139
|
+
(_page$childPages = page.childPages) === null || _page$childPages === void 0 || _page$childPages.forEach(function (childPage) {
|
|
140
|
+
if (childPage.deleteCollectionWhenHidden) {
|
|
141
|
+
if (childPage && !(0, _showComponent.default)(childPage, formData)) {
|
|
142
|
+
delete formData[childPage.collection.name];
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
deleteHiddenComponent(childPage, form, collectionData, formData);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
114
151
|
var clearOutUncompletedRoutes = function clearOutUncompletedRoutes(form, formData) {
|
|
115
152
|
if (form.disableClearWhenHidden) {
|
|
116
153
|
return formData;
|
|
@@ -119,29 +156,14 @@ var clearOutUncompletedRoutes = function clearOutUncompletedRoutes(form, formDat
|
|
|
119
156
|
var candidateComponentForDeletion = new Map();
|
|
120
157
|
var componentsUsedInVisiblePagesIds = [];
|
|
121
158
|
condensedPages === null || condensedPages === void 0 || condensedPages.forEach(function (page) {
|
|
122
|
-
var _page$
|
|
123
|
-
if (page !== null && page !== void 0 && (_page$
|
|
124
|
-
|
|
125
|
-
var collectionDatas = formData[page === null || page === void 0 || (_page$collection2 = page.collection) === null || _page$collection2 === void 0 ? void 0 : _page$collection2.name];
|
|
126
|
-
if (collectionDatas) {
|
|
127
|
-
collectionDatas.forEach(function (collectionData) {
|
|
128
|
-
var _page$childPages;
|
|
129
|
-
/* eslint-disable consistent-return */
|
|
130
|
-
(_page$childPages = page.childPages) === null || _page$childPages === void 0 || _page$childPages.forEach(function (childPage) {
|
|
131
|
-
if (childPage.deleteCollectionWhenHidden) {
|
|
132
|
-
if (childPage && !(0, _showComponent.default)(childPage, collectionData) || childPage && !(0, _showComponent.default)(childPage, formData)) {
|
|
133
|
-
delete formData[childPage.collection.name];
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
deleteHiddenComponent(childPage, form, collectionData, formData);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
}
|
|
159
|
+
var _page$collection2;
|
|
160
|
+
if (page !== null && page !== void 0 && (_page$collection2 = page.collection) !== null && _page$collection2 !== void 0 && _page$collection2.name) {
|
|
161
|
+
clearUncompletedRoutesForCollections(formData, page, form);
|
|
141
162
|
} else {
|
|
142
163
|
markComponentsForDeletion(page, form, formData, candidateComponentForDeletion, componentsUsedInVisiblePagesIds);
|
|
143
164
|
}
|
|
144
165
|
});
|
|
166
|
+
componentsUsedInVisiblePagesIds = [].concat(new Set(componentsUsedInVisiblePagesIds));
|
|
145
167
|
componentsUsedInVisiblePagesIds.forEach(function (componentId) {
|
|
146
168
|
return candidateComponentForDeletion.delete(componentId);
|
|
147
169
|
});
|
|
@@ -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
|
|
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
|
});
|