@ukhomeoffice/cop-react-form-renderer 4.18.0 → 4.19.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/dist/utils/FormPage/useComponent.js +24 -11
- package/dist/utils/FormPage/useComponent.test.js +6 -5
- package/dist/utils/Validate/additional/mustBeAfter.js +8 -6
- package/dist/utils/Validate/additional/mustBeAfter.test.js +15 -1
- package/dist/utils/Validate/additional/mustBeBefore.js +9 -5
- package/dist/utils/Validate/additional/mustBeBefore.test.js +14 -0
- package/package.json +1 -1
|
@@ -19,38 +19,55 @@ var getComponentToUse = function getComponentToUse(toUse, formComponents) {
|
|
|
19
19
|
return fc.id === firstId;
|
|
20
20
|
}));
|
|
21
21
|
|
|
22
|
+
var component = wrapper;
|
|
22
23
|
var parent = wrapper;
|
|
23
24
|
|
|
24
25
|
var _loop = function _loop() {
|
|
25
26
|
var id = path.shift();
|
|
26
27
|
|
|
27
|
-
if (Array.isArray(
|
|
28
|
+
if (Array.isArray(component.components)) {
|
|
28
29
|
// Filter the parent components down to just the one referenced
|
|
29
30
|
// by the current id.
|
|
31
|
+
parent = component;
|
|
30
32
|
parent.components = parent.components.filter(function (c) {
|
|
31
33
|
return c.id === id;
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
if (parent.components.length > 0) {
|
|
35
37
|
// Make the found child the parent so we can iterate.
|
|
36
|
-
|
|
38
|
+
component = parent.components[0];
|
|
37
39
|
} else {
|
|
38
40
|
// If no child was found, there can be no parent.
|
|
39
|
-
|
|
41
|
+
component = undefined;
|
|
40
42
|
}
|
|
41
43
|
} else {
|
|
42
44
|
// We cannot find the child with this id if there are no child
|
|
43
45
|
// components on this parent.
|
|
44
|
-
|
|
46
|
+
component = undefined;
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
while (
|
|
50
|
+
while (component && path.length > 0) {
|
|
49
51
|
_loop();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (component) {
|
|
55
|
+
component = _objectSpread(_objectSpread(_objectSpread({}, component), toUse), {}, {
|
|
56
|
+
cya_label: component.label || component.cya_label,
|
|
57
|
+
fieldId: toUse.fieldId || component.fieldId
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
if (parent && parent.id !== component.id) {
|
|
61
|
+
parent.components[0] = component;
|
|
62
|
+
} else {
|
|
63
|
+
wrapper = component;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return wrapper;
|
|
50
67
|
} // If we missed a nested reference along the way, don't return the wrapper.
|
|
51
68
|
|
|
52
69
|
|
|
53
|
-
return
|
|
70
|
+
return undefined;
|
|
54
71
|
};
|
|
55
72
|
/**
|
|
56
73
|
* Use an existing component from the formComponents, overriding any properties
|
|
@@ -66,11 +83,7 @@ var useComponent = function useComponent(toUse, formComponents) {
|
|
|
66
83
|
var component = getComponentToUse(toUse, formComponents);
|
|
67
84
|
|
|
68
85
|
if (component) {
|
|
69
|
-
|
|
70
|
-
return _objectSpread(_objectSpread(_objectSpread({}, component), toUse), {}, {
|
|
71
|
-
cya_label: component.label || component.cya_label,
|
|
72
|
-
fieldId: fieldId
|
|
73
|
-
});
|
|
86
|
+
return component;
|
|
74
87
|
}
|
|
75
88
|
}
|
|
76
89
|
|
|
@@ -142,11 +142,12 @@ describe('utils', function () {
|
|
|
142
142
|
var TO_USE = {
|
|
143
143
|
use: ID
|
|
144
144
|
};
|
|
145
|
-
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({}, CONTAINER), {}, {
|
|
146
|
+
components: [_objectSpread(_objectSpread({
|
|
147
|
+
use: ID
|
|
148
|
+
}, ZULU), {}, {
|
|
149
|
+
cya_label: ZULU.label
|
|
150
|
+
}) // Foxtrot is not included
|
|
150
151
|
]
|
|
151
152
|
}));
|
|
152
153
|
});
|
|
@@ -17,19 +17,21 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
// Local imports
|
|
18
18
|
_dayjs.default.extend(_customParseFormat.default);
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* Checks that a date is after either:
|
|
21
|
+
* - A specified, fixed date.
|
|
22
|
+
* Or
|
|
23
|
+
* - An offset to the current date in days/months/years.
|
|
24
|
+
*
|
|
24
25
|
* @param {string} date - date string in a valid date format e.g. DD-MM-YYYY
|
|
26
|
+
* @param {string} config.date - fixed date string that date must be after, in the format DD-MM-YYYY
|
|
25
27
|
* @param {string} config.unit - day, month or year
|
|
26
28
|
* @param {number} config.value - number of the unit to be after
|
|
27
|
-
* @returns false if date is
|
|
29
|
+
* @returns false if date is not after the given date/offset or true if it is.
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
var mustBeAfter = function mustBeAfter(date, config) {
|
|
32
|
-
var dateToCompare = (0, _dayjs.default)().add(config.value, config.unit);
|
|
34
|
+
var dateToCompare = config.date ? (0, _dayjs.default)((0, _utils.formatString)(config.date), _utils.DATE_FORMAT) : (0, _dayjs.default)().add(config.value, config.unit);
|
|
33
35
|
return (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isAfter(dateToCompare);
|
|
34
36
|
};
|
|
35
37
|
|
|
@@ -84,7 +84,7 @@ describe('utils', function () {
|
|
|
84
84
|
});
|
|
85
85
|
expect(result).toEqual(true);
|
|
86
86
|
});
|
|
87
|
-
test('should return
|
|
87
|
+
test('should return false given a date before the given number of days in the future', function () {
|
|
88
88
|
var date = (0, _dayjs.default)().add(250, 'day').format(_utils.DATE_FORMAT);
|
|
89
89
|
var result = (0, _mustBeAfter.default)(date, {
|
|
90
90
|
value: 275,
|
|
@@ -92,6 +92,20 @@ describe('utils', function () {
|
|
|
92
92
|
});
|
|
93
93
|
expect(result).toEqual(false);
|
|
94
94
|
});
|
|
95
|
+
test('should return false given a date before the specified fixed date', function () {
|
|
96
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
97
|
+
var result = (0, _mustBeAfter.default)(date, {
|
|
98
|
+
date: '01-01-5000'
|
|
99
|
+
});
|
|
100
|
+
expect(result).toEqual(false);
|
|
101
|
+
});
|
|
102
|
+
test('should return true given a date after the specified fixed date', function () {
|
|
103
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
104
|
+
var result = (0, _mustBeAfter.default)(date, {
|
|
105
|
+
date: '01-01-2000'
|
|
106
|
+
});
|
|
107
|
+
expect(result).toEqual(true);
|
|
108
|
+
});
|
|
95
109
|
});
|
|
96
110
|
});
|
|
97
111
|
});
|
|
@@ -17,17 +17,21 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
// Local imports
|
|
18
18
|
_dayjs.default.extend(_customParseFormat.default);
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Checks that a date is before either:
|
|
21
|
+
* - A specified, fixed date.
|
|
22
|
+
* Or
|
|
23
|
+
* - An offset to the current date in days/months/years.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} date - date string in a valid date format e.g. DD-MM-YYYY
|
|
26
|
+
* @param {string} config.date - fixed date string that date must be before, in the format DD-MM-YYYY
|
|
23
27
|
* @param {string} config.unit - day, month or year
|
|
24
28
|
* @param {number} config.value - number of the unit to be before
|
|
25
|
-
* @returns
|
|
29
|
+
* @returns false if date is not before the given date/offset or true if it is.
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
var mustBeBefore = function mustBeBefore(date, config) {
|
|
30
|
-
var dateToCompare = (0, _dayjs.default)().add(config.value, config.unit);
|
|
34
|
+
var dateToCompare = config.date ? (0, _dayjs.default)((0, _utils.formatString)(config.date), _utils.DATE_FORMAT) : (0, _dayjs.default)().add(config.value, config.unit);
|
|
31
35
|
return (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isBefore(dateToCompare);
|
|
32
36
|
};
|
|
33
37
|
|
|
@@ -60,6 +60,20 @@ describe('utils', function () {
|
|
|
60
60
|
});
|
|
61
61
|
expect(result).toEqual(false);
|
|
62
62
|
});
|
|
63
|
+
test('should return false given a date after the specified fixed date', function () {
|
|
64
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
65
|
+
var result = (0, _mustBeBefore.default)(date, {
|
|
66
|
+
date: '01-01-2000'
|
|
67
|
+
});
|
|
68
|
+
expect(result).toEqual(false);
|
|
69
|
+
});
|
|
70
|
+
test('should return true given a date before the specified fixed date', function () {
|
|
71
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
72
|
+
var result = (0, _mustBeBefore.default)(date, {
|
|
73
|
+
date: '01-01-5000'
|
|
74
|
+
});
|
|
75
|
+
expect(result).toEqual(true);
|
|
76
|
+
});
|
|
63
77
|
});
|
|
64
78
|
});
|
|
65
79
|
});
|