@ukhomeoffice/cop-react-form-renderer 2.2.0 → 2.6.1-alpha
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/components/FormComponent/Container.test.js +250 -0
- package/dist/components/FormComponent/FormComponent.js +101 -22
- package/dist/components/FormPage/FormPage.js +2 -1
- package/dist/components/FormRenderer/FormRenderer.js +105 -6
- package/dist/components/FormRenderer/FormRenderer.test.js +235 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.js +3 -0
- package/dist/components/FormRenderer/helpers/getNextPageId.test.js +6 -0
- package/dist/components/FormRenderer/helpers/getPage.js +1 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +18 -1
- package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +44 -6
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +50 -0
- package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -0
- package/dist/components/FormRenderer/helpers/index.js +7 -1
- package/dist/components/TaskList/Task.js +83 -0
- package/dist/components/TaskList/Task.test.js +112 -0
- package/dist/components/TaskList/TaskList.js +112 -0
- package/dist/components/TaskList/TaskList.scss +70 -0
- package/dist/components/TaskList/TaskList.stories.mdx +57 -0
- package/dist/components/TaskList/TaskList.test.js +223 -0
- package/dist/components/TaskList/TaskState.js +42 -0
- package/dist/components/TaskList/TaskState.test.js +99 -0
- package/dist/components/TaskList/index.js +13 -0
- package/dist/hooks/index.js +19 -1
- package/dist/json/taskList.json +228 -0
- package/dist/json/userProfile.data.json +2 -1
- package/dist/models/ComponentTypes.js +5 -1
- package/dist/models/FormTypes.js +2 -0
- package/dist/models/HubFormats.js +3 -1
- package/dist/models/PageAction.js +5 -0
- package/dist/models/TaskStates.js +41 -0
- package/dist/models/index.js +8 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +40 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +257 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +9 -1
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +44 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +6 -0
- package/dist/utils/Component/cleanAttributes.js +1 -1
- package/dist/utils/Component/getComponent.js +8 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/dist/utils/Component/showComponent.js +2 -20
- package/dist/utils/Condition/index.js +19 -0
- package/dist/utils/Condition/meetsAllConditions.js +40 -0
- package/dist/utils/Condition/meetsAllConditions.test.js +62 -0
- package/dist/utils/{meetsCondition.js → Condition/meetsCondition.js} +0 -0
- package/dist/utils/Condition/meetsCondition.test.js +302 -0
- package/dist/utils/Condition/setupConditions.js +47 -0
- package/dist/utils/Condition/setupConditions.test.js +35 -0
- package/dist/utils/Container/getEditableComponents.js +38 -0
- package/dist/utils/Container/getEditableComponents.test.js +157 -0
- package/dist/utils/Container/index.js +22 -0
- package/dist/utils/Container/setupNesting.js +45 -0
- package/dist/utils/Container/setupNesting.test.js +92 -0
- package/dist/utils/Container/showContainer.js +61 -0
- package/dist/utils/Container/showContainer.test.js +128 -0
- package/dist/utils/Data/getDataPath.js +90 -0
- package/dist/utils/Data/getDataPath.test.js +52 -0
- package/dist/utils/Data/index.js +3 -0
- package/dist/utils/FormPage/getFormPage.js +4 -2
- package/dist/utils/FormPage/getFormPage.test.js +18 -7
- package/dist/utils/FormPage/getFormPages.test.js +5 -2
- package/dist/utils/FormPage/getPageActions.js +6 -0
- package/dist/utils/FormPage/index.js +0 -3
- package/dist/utils/FormPage/showFormPage.js +7 -27
- package/dist/utils/Hub/getFormHub.js +4 -0
- package/dist/utils/Hub/getFormHub.test.js +15 -4
- package/dist/utils/Validate/additional/index.js +55 -0
- package/dist/utils/Validate/additional/index.test.js +69 -0
- package/dist/utils/Validate/additional/mustBeAfter.js +37 -0
- package/dist/utils/Validate/additional/mustBeAfter.test.js +98 -0
- package/dist/utils/Validate/additional/mustBeBefore.js +35 -0
- package/dist/utils/Validate/additional/mustBeBefore.test.js +66 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.js +42 -0
- package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +34 -0
- package/dist/utils/Validate/additional/mustBeInThePast.js +44 -0
- package/dist/utils/Validate/additional/mustBeInThePast.test.js +34 -0
- package/dist/utils/Validate/additional/utils.js +66 -0
- package/dist/utils/Validate/index.js +7 -1
- package/dist/utils/Validate/validateComponent.js +57 -0
- package/dist/utils/Validate/validateComponent.test.js +92 -2
- package/dist/utils/Validate/validateDate.js +155 -0
- package/dist/utils/Validate/validateDate.test.js +118 -0
- package/dist/utils/Validate/validatePage.js +6 -8
- package/dist/utils/Validate/validateTime.js +95 -0
- package/dist/utils/Validate/validateTime.test.js +61 -0
- package/dist/utils/index.js +6 -3
- package/package.json +5 -4
- package/dist/utils/FormPage/getEditableComponents.js +0 -28
- package/dist/utils/FormPage/getEditableComponents.test.js +0 -75
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _models = require("../../models");
|
|
4
|
+
|
|
5
|
+
var _setupNesting = _interopRequireDefault(require("./setupNesting"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
12
|
+
|
|
13
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
|
|
15
|
+
describe('utils.Container.setupNesting', function () {
|
|
16
|
+
var getComponent = function getComponent(id, type) {
|
|
17
|
+
return {
|
|
18
|
+
id: id,
|
|
19
|
+
fieldId: id,
|
|
20
|
+
type: type
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
it('should handle an undefined container', function () {
|
|
25
|
+
expect((0, _setupNesting.default)(undefined)).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
it('should handle a null container', function () {
|
|
28
|
+
expect((0, _setupNesting.default)(null)).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
it('should handle a single level of nesting', function () {
|
|
31
|
+
var CONTAINER = _objectSpread(_objectSpread({}, getComponent('container', _models.ComponentTypes.CONTAINER)), {}, {
|
|
32
|
+
components: [getComponent('text', _models.ComponentTypes.TEXT), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect((0, _setupNesting.default)(CONTAINER)).toEqual({
|
|
36
|
+
id: 'container',
|
|
37
|
+
fieldId: 'container',
|
|
38
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
39
|
+
components: [{
|
|
40
|
+
id: 'text',
|
|
41
|
+
fieldId: 'text',
|
|
42
|
+
full_path: 'container.text',
|
|
43
|
+
type: _models.ComponentTypes.TEXT
|
|
44
|
+
}, {
|
|
45
|
+
id: 'email',
|
|
46
|
+
fieldId: 'email',
|
|
47
|
+
full_path: 'container.email',
|
|
48
|
+
type: _models.ComponentTypes.EMAIL
|
|
49
|
+
}]
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it('should handle multiple levels of nesting', function () {
|
|
53
|
+
var CONTAINER = _objectSpread(_objectSpread({}, getComponent('container', _models.ComponentTypes.CONTAINER)), {}, {
|
|
54
|
+
components: [getComponent('text', _models.ComponentTypes.TEXT), _objectSpread(_objectSpread({}, getComponent('inner', _models.ComponentTypes.CONTAINER)), {}, {
|
|
55
|
+
components: [getComponent('text', _models.ComponentTypes.TEXT), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
56
|
+
}), getComponent('email', _models.ComponentTypes.EMAIL)]
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect((0, _setupNesting.default)(CONTAINER)).toEqual({
|
|
60
|
+
id: 'container',
|
|
61
|
+
fieldId: 'container',
|
|
62
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
63
|
+
components: [{
|
|
64
|
+
id: 'text',
|
|
65
|
+
fieldId: 'text',
|
|
66
|
+
full_path: 'container.text',
|
|
67
|
+
type: _models.ComponentTypes.TEXT
|
|
68
|
+
}, {
|
|
69
|
+
id: 'inner',
|
|
70
|
+
fieldId: 'inner',
|
|
71
|
+
full_path: 'container.inner',
|
|
72
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
73
|
+
components: [{
|
|
74
|
+
id: 'text',
|
|
75
|
+
fieldId: 'text',
|
|
76
|
+
full_path: 'container.inner.text',
|
|
77
|
+
type: _models.ComponentTypes.TEXT
|
|
78
|
+
}, {
|
|
79
|
+
id: 'email',
|
|
80
|
+
fieldId: 'email',
|
|
81
|
+
full_path: 'container.inner.email',
|
|
82
|
+
type: _models.ComponentTypes.EMAIL
|
|
83
|
+
}]
|
|
84
|
+
}, {
|
|
85
|
+
id: 'email',
|
|
86
|
+
fieldId: 'email',
|
|
87
|
+
full_path: 'container.email',
|
|
88
|
+
type: _models.ComponentTypes.EMAIL
|
|
89
|
+
}]
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _Component = _interopRequireDefault(require("../Component"));
|
|
9
|
+
|
|
10
|
+
var _Condition = _interopRequireDefault(require("../Condition"));
|
|
11
|
+
|
|
12
|
+
var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
// Local imports
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether any of the editable components on a container should be shown.
|
|
20
|
+
* @param {Array} editableComponents The editable components on the container.
|
|
21
|
+
* @param {object} data The top-level form data.
|
|
22
|
+
* @returns Boolean true if ANY of the editable components should be shown; false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
var showEditableComponent = function showEditableComponent(editableComponents, data) {
|
|
25
|
+
return editableComponents.some(function (component) {
|
|
26
|
+
return _Component.default.show(component, data);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Indicates whether or not a container should be shown.
|
|
31
|
+
* @param {object} container The container to consider.
|
|
32
|
+
* @param {object} data The top-level form data.
|
|
33
|
+
* @returns Boolean true if the container should be shown; false if not.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
var showContainer = function showContainer(container, data) {
|
|
38
|
+
if (!container) {
|
|
39
|
+
return false;
|
|
40
|
+
} // If the container has a show_when condition, we should evaluate that.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if (container.show_when) {
|
|
44
|
+
return _Condition.default.meetsAll(container, data);
|
|
45
|
+
} // If the container itself doesn't have a show_when, we need to make sure that if it
|
|
46
|
+
// contains ANY editable components, at least one of them is shown.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
var editableComponents = (0, _getEditableComponents.default)(container);
|
|
50
|
+
|
|
51
|
+
if (editableComponents.length > 0) {
|
|
52
|
+
return showEditableComponent(editableComponents, data);
|
|
53
|
+
} // At this point, either the container has no show_when condition of its own, or
|
|
54
|
+
// the container has no editable components. In either case, it should be shown.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var _default = showContainer;
|
|
61
|
+
exports.default = _default;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _showContainer = _interopRequireDefault(require("./showContainer"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
// Local imports
|
|
8
|
+
describe('utils.Container.showContainer', function () {
|
|
9
|
+
var DATA = {
|
|
10
|
+
alpha: 'Alpha',
|
|
11
|
+
bravo: 'Bravo'
|
|
12
|
+
};
|
|
13
|
+
var HTML = {
|
|
14
|
+
type: 'html',
|
|
15
|
+
tagName: 'p',
|
|
16
|
+
content: 'Alpha'
|
|
17
|
+
};
|
|
18
|
+
var INSET_TEXT = {
|
|
19
|
+
type: 'inset-text',
|
|
20
|
+
content: 'Bravo'
|
|
21
|
+
};
|
|
22
|
+
var HEADING = {
|
|
23
|
+
type: 'heading',
|
|
24
|
+
size: 'm',
|
|
25
|
+
content: 'Charlie'
|
|
26
|
+
};
|
|
27
|
+
it('should NOT be shown when the container is null', function () {
|
|
28
|
+
expect((0, _showContainer.default)(null, DATA)).toBeFalsy();
|
|
29
|
+
});
|
|
30
|
+
it('should NOT be shown when the container has a single show_when condition that is NOT matched', function () {
|
|
31
|
+
var CONTAINER = {
|
|
32
|
+
show_when: {
|
|
33
|
+
field: 'charlie',
|
|
34
|
+
op: '=',
|
|
35
|
+
value: 'Charlie'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
39
|
+
});
|
|
40
|
+
it('should NOT be shown when the container has multiple show_when conditions and at least one is NOT matched', function () {
|
|
41
|
+
var CONTAINER = {
|
|
42
|
+
show_when: [{
|
|
43
|
+
field: 'alpha',
|
|
44
|
+
op: '=',
|
|
45
|
+
value: 'Alpha'
|
|
46
|
+
}, {
|
|
47
|
+
field: 'charlie',
|
|
48
|
+
op: '=',
|
|
49
|
+
value: 'Charlie'
|
|
50
|
+
}]
|
|
51
|
+
};
|
|
52
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
53
|
+
});
|
|
54
|
+
it('SHOULD be shown when the container has a single show_when condition that IS matched', function () {
|
|
55
|
+
var CONTAINER = {
|
|
56
|
+
show_when: {
|
|
57
|
+
field: 'alpha',
|
|
58
|
+
op: '=',
|
|
59
|
+
value: 'Alpha'
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
63
|
+
});
|
|
64
|
+
it('SHOULD be shown when the container has multiple show_when conditions that are ALL matched', function () {
|
|
65
|
+
var CONTAINER = {
|
|
66
|
+
show_when: [{
|
|
67
|
+
field: 'alpha',
|
|
68
|
+
op: '=',
|
|
69
|
+
value: 'Alpha'
|
|
70
|
+
}, {
|
|
71
|
+
field: 'charlie',
|
|
72
|
+
op: '!=',
|
|
73
|
+
value: 'Charlie'
|
|
74
|
+
}]
|
|
75
|
+
};
|
|
76
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
77
|
+
});
|
|
78
|
+
it('SHOULD be shown when the container has NO show_when conditions and NO editable components', function () {
|
|
79
|
+
var CONTAINER = {
|
|
80
|
+
components: [HTML, INSET_TEXT, HEADING]
|
|
81
|
+
};
|
|
82
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
83
|
+
});
|
|
84
|
+
it('should NOT be shown when the container has NO show_when conditions and NO SHOWN editable components', function () {
|
|
85
|
+
var TEXT = {
|
|
86
|
+
type: 'text',
|
|
87
|
+
show_when: {
|
|
88
|
+
field: 'charlie',
|
|
89
|
+
op: '=',
|
|
90
|
+
value: 'Charlie'
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var RADIOS = {
|
|
94
|
+
type: 'radios',
|
|
95
|
+
show_when: {
|
|
96
|
+
field: 'charlie',
|
|
97
|
+
op: '=',
|
|
98
|
+
value: 'Charlie'
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var CONTAINER = {
|
|
102
|
+
components: [TEXT, RADIOS]
|
|
103
|
+
};
|
|
104
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeFalsy();
|
|
105
|
+
});
|
|
106
|
+
it('SHOULD be shown when the container has NO show_when conditions and AT LEAST ONE SHOWN editable components', function () {
|
|
107
|
+
var TEXT = {
|
|
108
|
+
type: 'text',
|
|
109
|
+
show_when: {
|
|
110
|
+
field: 'alpha',
|
|
111
|
+
op: '=',
|
|
112
|
+
value: 'Alpha'
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var RADIOS = {
|
|
116
|
+
type: 'radios',
|
|
117
|
+
show_when: {
|
|
118
|
+
field: 'charlie',
|
|
119
|
+
op: '=',
|
|
120
|
+
value: 'Charlie'
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var CONTAINER = {
|
|
124
|
+
components: [TEXT, RADIOS]
|
|
125
|
+
};
|
|
126
|
+
expect((0, _showContainer.default)(CONTAINER, DATA)).toBeTruthy();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var DOT = '.';
|
|
8
|
+
var SLASH = '/';
|
|
9
|
+
var DOT_DOT = "".concat(DOT).concat(DOT);
|
|
10
|
+
var PARENT_PATH = "".concat(DOT).concat(SLASH);
|
|
11
|
+
|
|
12
|
+
var toPath = function toPath(arr) {
|
|
13
|
+
return arr.join(DOT);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
var toParts = function toParts(str) {
|
|
17
|
+
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DOT;
|
|
18
|
+
return str.split(separator);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var isDotDot = function isDotDot(str) {
|
|
22
|
+
return str === DOT_DOT;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var isDotOrDotDot = function isDotOrDotDot(str) {
|
|
26
|
+
return [DOT, DOT_DOT].indexOf(str) > -1;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var isRelativePath = function isRelativePath(path) {
|
|
30
|
+
return path && path.indexOf(DOT) === 0;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var standardiseRelativePath = function standardiseRelativePath(path) {
|
|
34
|
+
if (path.indexOf(PARENT_PATH) === 0) {
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return "".concat(PARENT_PATH).concat(path);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var ascendPath = function ascendPath(startPath, ascent) {
|
|
42
|
+
var relativePath = standardiseRelativePath(ascent); // Always add 1 because we're starting on a leaf node within a "directory".
|
|
43
|
+
|
|
44
|
+
var stepsToClimb = toParts(relativePath, SLASH).filter(isDotDot).length + 1;
|
|
45
|
+
var pathParts = startPath ? toParts(startPath) : [];
|
|
46
|
+
|
|
47
|
+
if (stepsToClimb >= pathParts.length) {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return toPath(pathParts.slice(0, -stepsToClimb));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var descendPath = function descendPath(startPath, descent) {
|
|
55
|
+
var stepsDown = toParts(descent, SLASH).filter(function (str) {
|
|
56
|
+
return !isDotOrDotDot(str);
|
|
57
|
+
});
|
|
58
|
+
return startPath ? "".concat(startPath, ".").concat(toPath(stepsDown)) : toPath(stepsDown);
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Takes a path and a current path and returns an absolute path to a data element.
|
|
62
|
+
* Note that the path may be absolute or relative.
|
|
63
|
+
*
|
|
64
|
+
* The behaviour should mirror the way imports work.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} path The path to attempt to get to, which may be absolute or relative.
|
|
67
|
+
* @param {string} currentPath The current absolute path.
|
|
68
|
+
* @returns An absolute path to a data element.
|
|
69
|
+
* @example
|
|
70
|
+
* getDataPath('./relative.path', 'this.is.the.current.path');
|
|
71
|
+
* // => 'this.is.the.current.relative.path'
|
|
72
|
+
* @example
|
|
73
|
+
* getDataPath('../relative.path', 'this.is.the.current.path');
|
|
74
|
+
* // => 'this.is.the.relative.path'
|
|
75
|
+
* @example
|
|
76
|
+
* getDataPath('../../relative.path', 'this.is.the.current.path');
|
|
77
|
+
* // => 'this.is.relative.path'
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
var getDataPath = function getDataPath(path, currentPath) {
|
|
82
|
+
if (isRelativePath(path)) {
|
|
83
|
+
return descendPath(ascendPath(currentPath, path), path);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return path;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var _default = getDataPath;
|
|
90
|
+
exports.default = _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getDataPath = _interopRequireDefault(require("./getDataPath"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('utils.Data.getDataPath', function () {
|
|
8
|
+
var CURRENT_PATH = 'this.is.the.current.path';
|
|
9
|
+
var RELATIVE = 'relative.path';
|
|
10
|
+
var ABSOLUTE = 'absolute.path';
|
|
11
|
+
|
|
12
|
+
var doTest = function doTest(path, currentPath, expected) {
|
|
13
|
+
expect((0, _getDataPath.default)(path, currentPath)).toEqual(expected);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
it("should return an absolute path appropriately", function () {
|
|
17
|
+
doTest(ABSOLUTE, CURRENT_PATH, ABSOLUTE);
|
|
18
|
+
});
|
|
19
|
+
it("should return an absolute path appropriately where the current path is null", function () {
|
|
20
|
+
doTest(ABSOLUTE, null, ABSOLUTE);
|
|
21
|
+
});
|
|
22
|
+
[{
|
|
23
|
+
p: "./".concat(RELATIVE),
|
|
24
|
+
e: "this.is.the.current.".concat(RELATIVE),
|
|
25
|
+
d: 'a sibling node'
|
|
26
|
+
}, {
|
|
27
|
+
p: "../".concat(RELATIVE),
|
|
28
|
+
e: "this.is.the.".concat(RELATIVE),
|
|
29
|
+
d: 'a cousin node'
|
|
30
|
+
}, {
|
|
31
|
+
p: "./../".concat(RELATIVE),
|
|
32
|
+
e: "this.is.the.".concat(RELATIVE),
|
|
33
|
+
d: 'a cousin node with leading dot-slash'
|
|
34
|
+
}, {
|
|
35
|
+
p: "../../../../../../../".concat(RELATIVE),
|
|
36
|
+
e: RELATIVE,
|
|
37
|
+
d: 'an inappropriately nested node'
|
|
38
|
+
}].forEach(function (test) {
|
|
39
|
+
it("should return ".concat(test.d, " appropriately"), function () {
|
|
40
|
+
doTest(test.p, CURRENT_PATH, test.e);
|
|
41
|
+
});
|
|
42
|
+
it("should return ".concat(test.d, " appropriately where the current path is null"), function () {
|
|
43
|
+
doTest(test.p, null, RELATIVE);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it('should handle a null path and return null', function () {
|
|
47
|
+
doTest(null, CURRENT_PATH, null);
|
|
48
|
+
});
|
|
49
|
+
it('should handle an undefined path and return undefined', function () {
|
|
50
|
+
doTest(undefined, CURRENT_PATH, undefined);
|
|
51
|
+
});
|
|
52
|
+
});
|
package/dist/utils/Data/index.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _getAutocompleteSource = _interopRequireDefault(require("./getAutocompleteSource"));
|
|
9
9
|
|
|
10
|
+
var _getDataPath = _interopRequireDefault(require("./getDataPath"));
|
|
11
|
+
|
|
10
12
|
var _getOptions = _interopRequireDefault(require("./getOptions"));
|
|
11
13
|
|
|
12
14
|
var _getSourceData = _interopRequireDefault(require("./getSourceData"));
|
|
@@ -22,6 +24,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
22
24
|
// Local imports
|
|
23
25
|
var Data = {
|
|
24
26
|
getAutocompleteSource: _getAutocompleteSource.default,
|
|
27
|
+
getDataPath: _getDataPath.default,
|
|
25
28
|
getOptions: _getOptions.default,
|
|
26
29
|
getSource: _getSourceData.default,
|
|
27
30
|
refData: {
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _Container = _interopRequireDefault(require("../Container"));
|
|
9
|
+
|
|
8
10
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
9
11
|
|
|
10
12
|
var _getPageActions = _interopRequireDefault(require("./getPageActions"));
|
|
@@ -49,11 +51,11 @@ var getFormPage = function getFormPage(pageOptions, formComponents, formData) {
|
|
|
49
51
|
return formData && formData.urls ? _Data.default.refData.setupUrl(ret, formData) : ret;
|
|
50
52
|
});
|
|
51
53
|
var actions = (0, _getPageActions.default)(pageOptions);
|
|
52
|
-
return _objectSpread(_objectSpread({}, pageOptions), {}, {
|
|
54
|
+
return _Container.default.setup(_objectSpread(_objectSpread({}, pageOptions), {}, {
|
|
53
55
|
formData: formData,
|
|
54
56
|
components: components,
|
|
55
57
|
actions: actions
|
|
56
|
-
});
|
|
58
|
+
}));
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
var _default = getFormPage;
|
|
@@ -72,7 +72,9 @@ describe('utils', function () {
|
|
|
72
72
|
type: 'html',
|
|
73
73
|
tagName: 'p',
|
|
74
74
|
content: PAGE.components[0]
|
|
75
|
-
}, PAGE.components[1], {
|
|
75
|
+
}, _objectSpread(_objectSpread({}, PAGE.components[1]), {}, {
|
|
76
|
+
full_path: PAGE.components[1].fieldId
|
|
77
|
+
}), {
|
|
76
78
|
type: 'html',
|
|
77
79
|
tagName: 'p',
|
|
78
80
|
content: PAGE.components[2]
|
|
@@ -98,14 +100,17 @@ describe('utils', function () {
|
|
|
98
100
|
type: 'html',
|
|
99
101
|
tagName: 'p',
|
|
100
102
|
content: PAGE.components[0]
|
|
101
|
-
}, PAGE.components[1], {
|
|
103
|
+
}, _objectSpread(_objectSpread({}, PAGE.components[1]), {}, {
|
|
104
|
+
full_path: PAGE.components[1].fieldId
|
|
105
|
+
}), {
|
|
102
106
|
type: 'html',
|
|
103
107
|
tagName: 'p',
|
|
104
108
|
content: PAGE.components[2]
|
|
105
109
|
}, _objectSpread(_objectSpread({
|
|
106
110
|
use: 'a'
|
|
107
111
|
}, A), {}, {
|
|
108
|
-
cya_label: A.label
|
|
112
|
+
cya_label: A.label,
|
|
113
|
+
full_path: A.fieldId
|
|
109
114
|
})],
|
|
110
115
|
formData: FORM_DATA
|
|
111
116
|
});
|
|
@@ -128,7 +133,9 @@ describe('utils', function () {
|
|
|
128
133
|
type: 'html',
|
|
129
134
|
tagName: 'p',
|
|
130
135
|
content: PAGE.components[0]
|
|
131
|
-
}, PAGE.components[1], {
|
|
136
|
+
}, _objectSpread(_objectSpread({}, PAGE.components[1]), {}, {
|
|
137
|
+
full_path: PAGE.components[1].fieldId
|
|
138
|
+
}), {
|
|
132
139
|
type: 'html',
|
|
133
140
|
tagName: 'p',
|
|
134
141
|
content: PAGE.components[2]
|
|
@@ -138,7 +145,8 @@ describe('utils', function () {
|
|
|
138
145
|
cya_label: C.label,
|
|
139
146
|
data: {
|
|
140
147
|
url: "".concat(FORM_DATA.urls.refData, "/v3/charlies")
|
|
141
|
-
}
|
|
148
|
+
},
|
|
149
|
+
full_path: C.fieldId
|
|
142
150
|
})],
|
|
143
151
|
formData: FORM_DATA
|
|
144
152
|
});
|
|
@@ -161,14 +169,17 @@ describe('utils', function () {
|
|
|
161
169
|
type: 'html',
|
|
162
170
|
tagName: 'p',
|
|
163
171
|
content: PAGE.components[0]
|
|
164
|
-
}, PAGE.components[1], {
|
|
172
|
+
}, _objectSpread(_objectSpread({}, PAGE.components[1]), {}, {
|
|
173
|
+
full_path: PAGE.components[1].fieldId
|
|
174
|
+
}), {
|
|
165
175
|
type: 'html',
|
|
166
176
|
tagName: 'p',
|
|
167
177
|
content: PAGE.components[2]
|
|
168
178
|
}, _objectSpread(_objectSpread({
|
|
169
179
|
use: 'c'
|
|
170
180
|
}, C), {}, {
|
|
171
|
-
cya_label: C.label
|
|
181
|
+
cya_label: C.label,
|
|
182
|
+
full_path: C.fieldId
|
|
172
183
|
})],
|
|
173
184
|
formData: {}
|
|
174
185
|
});
|
|
@@ -75,7 +75,9 @@ describe('utils', function () {
|
|
|
75
75
|
type: 'html',
|
|
76
76
|
tagName: 'p',
|
|
77
77
|
content: PAGE_2.components[0]
|
|
78
|
-
}, PAGE_2.components[1], {
|
|
78
|
+
}, _objectSpread(_objectSpread({}, PAGE_2.components[1]), {}, {
|
|
79
|
+
full_path: PAGE_2.components[1].fieldId
|
|
80
|
+
}), {
|
|
79
81
|
type: 'html',
|
|
80
82
|
tagName: 'p',
|
|
81
83
|
content: PAGE_2.components[2]
|
|
@@ -85,7 +87,8 @@ describe('utils', function () {
|
|
|
85
87
|
cya_label: C.label,
|
|
86
88
|
data: {
|
|
87
89
|
url: "".concat(FORM_DATA.urls.refData, "/v3/charlies")
|
|
88
|
-
}
|
|
90
|
+
},
|
|
91
|
+
full_path: C.fieldId
|
|
89
92
|
})],
|
|
90
93
|
formData: FORM_DATA
|
|
91
94
|
}]);
|
|
@@ -50,6 +50,12 @@ var getPageActions = function getPageActions(page) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
if (a && _typeof(a) === 'object') {
|
|
53
|
+
var _PageAction$DEFAULTS$;
|
|
54
|
+
|
|
55
|
+
if ((_PageAction$DEFAULTS$ = _models.PageAction.DEFAULTS[a.type]) !== null && _PageAction$DEFAULTS$ !== void 0 && _PageAction$DEFAULTS$.validate) {
|
|
56
|
+
a.validate = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
return standardiseAction(a);
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
|
|
9
|
-
|
|
10
8
|
var _getFormPage = _interopRequireDefault(require("./getFormPage"));
|
|
11
9
|
|
|
12
10
|
var _getFormPages = _interopRequireDefault(require("./getFormPages"));
|
|
@@ -16,7 +14,6 @@ var _showFormPage = _interopRequireDefault(require("./showFormPage"));
|
|
|
16
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
15
|
|
|
18
16
|
var FormPage = {
|
|
19
|
-
editableComponents: _getEditableComponents.default,
|
|
20
17
|
get: _getFormPage.default,
|
|
21
18
|
getAll: _getFormPages.default,
|
|
22
19
|
show: _showFormPage.default
|
|
@@ -7,44 +7,24 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _Component = _interopRequireDefault(require("../Component"));
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _Condition = _interopRequireDefault(require("../Condition"));
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
|
|
12
|
+
var _Container = _interopRequireDefault(require("../Container"));
|
|
15
13
|
|
|
16
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
15
|
|
|
18
16
|
// Local imports
|
|
19
17
|
|
|
20
|
-
/**
|
|
21
|
-
* Evaluates the show_when condition(s) on a page.
|
|
22
|
-
* @param {object} page The page to consider.
|
|
23
|
-
* @param {object} data The top-level form data.
|
|
24
|
-
* @returns Boolean true if all show_when conditions are met; false otherwise.
|
|
25
|
-
*/
|
|
26
|
-
var evaluatePageShowWhen = function evaluatePageShowWhen(page, data) {
|
|
27
|
-
var show_when = Array.isArray(page.show_when) ? page.show_when : [page.show_when];
|
|
28
|
-
var allConditionsMet = true;
|
|
29
|
-
show_when.forEach(function (condition) {
|
|
30
|
-
var sourceDataValue = _Data.default.getSource(data, condition.field);
|
|
31
|
-
|
|
32
|
-
allConditionsMet = allConditionsMet && (0, _meetsCondition.default)(condition, sourceDataValue);
|
|
33
|
-
});
|
|
34
|
-
return allConditionsMet;
|
|
35
|
-
};
|
|
36
18
|
/**
|
|
37
19
|
* Checks whether any of the editable components on a page should be shown.
|
|
38
20
|
* @param {Array} editableComponents The editable components on the page.
|
|
39
21
|
* @param {object} data The top-level form data.
|
|
40
22
|
* @returns Boolean true if ANY of the editable components should be shown; false otherwise.
|
|
41
23
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
24
|
var showEditableComponent = function showEditableComponent(editableComponents, data) {
|
|
45
|
-
return editableComponents.
|
|
46
|
-
return
|
|
47
|
-
}
|
|
25
|
+
return editableComponents.some(function (component) {
|
|
26
|
+
return _Component.default.show(component, data);
|
|
27
|
+
});
|
|
48
28
|
};
|
|
49
29
|
/**
|
|
50
30
|
* Indicates whether or not a page should be shown.
|
|
@@ -61,12 +41,12 @@ var showFormPage = function showFormPage(page, data) {
|
|
|
61
41
|
|
|
62
42
|
|
|
63
43
|
if (page.show_when) {
|
|
64
|
-
return
|
|
44
|
+
return _Condition.default.meetsAll(page, data);
|
|
65
45
|
} // If the page itself doesn't have a show_when, we need to make sure that if it
|
|
66
46
|
// contains ANY editable components, at least one of them is shown.
|
|
67
47
|
|
|
68
48
|
|
|
69
|
-
var editableComponents =
|
|
49
|
+
var editableComponents = _Container.default.editableComponents(page);
|
|
70
50
|
|
|
71
51
|
if (editableComponents.length > 0) {
|
|
72
52
|
return showEditableComponent(editableComponents, data);
|