@inseefr/lunatic 2.7.13 → 2.7.15
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/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +3 -1
- package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +4 -1
- package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +7 -2
- package/lib/components/commons/components/missing/missing.js +4 -1
- package/lib/components/commons/components/missing/missing.scss +26 -29
- package/lib/components/datepicker/lunatic-datepicker.js +1 -0
- package/lib/components/dropdown/lunatic-dropdown.js +1 -0
- package/lib/components/duration/duration.js +4 -1
- package/lib/components/input/lunatic-input.js +1 -0
- package/lib/components/input-number/lunatic-input-number.js +1 -0
- package/lib/components/loop/roster-for-loop/roster-for-loop.js +1 -0
- package/lib/components/lunatic-components.js +3 -1
- package/lib/components/radio/lunatic-radio-group.js +1 -0
- package/lib/components/suggester/lunatic-suggester.js +1 -0
- package/lib/components/switch/lunatic-switch.js +7 -2
- package/lib/components/textarea/lunatic-textarea.js +3 -1
- package/lib/src/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.d.ts +1 -1
- package/lib/src/components/checkbox/checkbox-group/lunatic-checkbox-group.d.ts +1 -1
- package/lib/src/components/checkbox/checkbox-one/lunatic-checkbox-one.d.ts +1 -1
- package/lib/src/components/commons/components/lunatic-component-without-label.d.ts +1 -1
- package/lib/src/components/commons/components/missing/missing.d.ts +2 -1
- package/lib/src/components/lunatic-components.d.ts +2 -1
- package/lib/src/components/switch/html/switch.d.ts +1 -0
- package/lib/src/components/switch/lunatic-switch.d.ts +1 -1
- package/lib/src/use-lunatic/commons/execute-condition-filter.d.ts +1 -1
- package/lib/src/use-lunatic/reducer/commons/index.d.ts +0 -1
- package/lib/src/utils/array.d.ts +1 -0
- package/lib/src/utils/variables.spec.d.ts +1 -0
- package/lib/stories/behaviour/missing/missing.stories.js +90 -0
- package/lib/stories/behaviour/missing/source.json +822 -0
- package/lib/stories/behaviour/performance/performance.stories.js +47 -0
- package/lib/stories/behaviour/performance/source.json +172 -0
- package/lib/stories/utils/orchestrator.js +13 -1
- package/lib/stories/utils/referentiel.js +3 -3
- package/lib/use-lunatic/commons/compile-controls.js +11 -5
- package/lib/use-lunatic/commons/execute-condition-filter.js +4 -1
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +4 -2
- package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js +22 -5
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +5 -0
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +10 -0
- package/lib/use-lunatic/hooks/use-page-has-response.js +11 -3
- package/lib/use-lunatic/reducer/commons/index.js +1 -9
- package/lib/utils/array.js +21 -0
- package/lib/utils/variables.js +4 -15
- package/lib/utils/variables.spec.js +74 -0
- package/package.json +1 -1
- package/lib/src/use-lunatic/reducer/commons/is-loop-component.d.ts +0 -10
- package/lib/use-lunatic/reducer/commons/is-loop-component.js +0 -9
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = exports.Default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _orchestrator = _interopRequireDefault(require("../../utils/orchestrator"));
|
|
9
|
+
var _source = _interopRequireDefault(require("./source.json"));
|
|
10
|
+
var _lunatic = require("../../../../tests/utils/lunatic");
|
|
11
|
+
var _array = require("../../../utils/array");
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
19
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
20
|
+
var stories = {
|
|
21
|
+
title: 'Behaviour/Performance',
|
|
22
|
+
component: _orchestrator["default"]
|
|
23
|
+
};
|
|
24
|
+
var _default = exports["default"] = stories;
|
|
25
|
+
var Template = function Template(args) {
|
|
26
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_orchestrator["default"], _objectSpread({}, args));
|
|
27
|
+
};
|
|
28
|
+
var Default = exports.Default = Template.bind({});
|
|
29
|
+
Default.args = {
|
|
30
|
+
id: 'performance-default',
|
|
31
|
+
pagination: true,
|
|
32
|
+
source: _source["default"],
|
|
33
|
+
data: (0, _lunatic.generateData)({
|
|
34
|
+
PRENOM: (0, _array.times)(200, function (k) {
|
|
35
|
+
return "John".concat(k);
|
|
36
|
+
}),
|
|
37
|
+
NOM: (0, _array.times)(200, function (k) {
|
|
38
|
+
return "Doe".concat(k);
|
|
39
|
+
}),
|
|
40
|
+
AGE: (0, _array.times)(200, function (k) {
|
|
41
|
+
return k + 1;
|
|
42
|
+
}),
|
|
43
|
+
BIRTHDAY: (0, _array.times)(200, function (k) {
|
|
44
|
+
return "2".concat(k.toString().padStart(3, '0'), "-01-01");
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
{
|
|
2
|
+
"maxPage": "3",
|
|
3
|
+
"components": [
|
|
4
|
+
{
|
|
5
|
+
"id": "seq",
|
|
6
|
+
"componentType": "Sequence",
|
|
7
|
+
"label": {
|
|
8
|
+
"value": "\"Description des individus de votre logement\"",
|
|
9
|
+
"type": "VTL|MD"
|
|
10
|
+
},
|
|
11
|
+
"conditionFilter": { "value": "true", "type": "VTL" },
|
|
12
|
+
"page": "1"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "loop-prenom",
|
|
16
|
+
"componentType": "RosterForLoop",
|
|
17
|
+
"header": [
|
|
18
|
+
{ "headerCell": true, "label": "Prénom" },
|
|
19
|
+
{ "headerCell": true, "label": "Nom" },
|
|
20
|
+
{ "headerCell": true, "label": "Date de naissance" },
|
|
21
|
+
{ "headerCell": true, "label": "Age" }
|
|
22
|
+
],
|
|
23
|
+
"label": { "value": "\"Ajouter un individu\"", "type": "VTL|MD" },
|
|
24
|
+
"conditionFilter": { "value": "true", "type": "VTL" },
|
|
25
|
+
"bindingDependencies": ["PRENOM", "AGE"],
|
|
26
|
+
"lines": {
|
|
27
|
+
"min": { "value": 1, "type": "VTL" },
|
|
28
|
+
"max": { "value": 250, "type": "VTL" }
|
|
29
|
+
},
|
|
30
|
+
"page": "1",
|
|
31
|
+
"components": [
|
|
32
|
+
{
|
|
33
|
+
"componentType": "Input",
|
|
34
|
+
"conditionFilter": { "value": "true", "type": "VTL" },
|
|
35
|
+
"maxLength": 30,
|
|
36
|
+
"bindingDependencies": ["PRENOM"],
|
|
37
|
+
"id": "prenom",
|
|
38
|
+
"response": {
|
|
39
|
+
"name": "PRENOM"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"componentType": "Input",
|
|
44
|
+
"conditionFilter": { "value": "true", "type": "VTL" },
|
|
45
|
+
"maxLength": 30,
|
|
46
|
+
"bindingDependencies": ["NOM"],
|
|
47
|
+
"id": "nom",
|
|
48
|
+
"response": {
|
|
49
|
+
"name": "NOM"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"componentType": "Datepicker",
|
|
54
|
+
"conditionFilter": { "value": "true", "type": "VTL" },
|
|
55
|
+
"maxLength": 30,
|
|
56
|
+
"bindingDependencies": ["BIRTHDAY"],
|
|
57
|
+
"id": "birthday",
|
|
58
|
+
"dateFormat": "YYYY-MM-DD",
|
|
59
|
+
"response": {
|
|
60
|
+
"name": "BIRTHDAY"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"componentType": "Input",
|
|
65
|
+
"conditionFilter": { "value": "true", "type": "VTL" },
|
|
66
|
+
"maxLength": 30,
|
|
67
|
+
"bindingDependencies": ["AGE"],
|
|
68
|
+
"id": "age",
|
|
69
|
+
"response": {
|
|
70
|
+
"name": "AGE"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": "loop",
|
|
77
|
+
"componentType": "Loop",
|
|
78
|
+
|
|
79
|
+
"loopDependencies": ["PRENOM"],
|
|
80
|
+
"iterations": { "value": "count(PRENOM)", "type": "VTL" },
|
|
81
|
+
"page": "2",
|
|
82
|
+
"maxPage": "1",
|
|
83
|
+
"depth": 1,
|
|
84
|
+
"paginatedLoop": true,
|
|
85
|
+
"conditionFilter": {
|
|
86
|
+
"value": "true",
|
|
87
|
+
"type": "VTL"
|
|
88
|
+
},
|
|
89
|
+
"components": [
|
|
90
|
+
{
|
|
91
|
+
"id": "age",
|
|
92
|
+
"label": {
|
|
93
|
+
"value": "PRENOM || \", quel est vôtre âge ?\"",
|
|
94
|
+
"type": "VTL"
|
|
95
|
+
},
|
|
96
|
+
"conditionFilter": {
|
|
97
|
+
"value": "true",
|
|
98
|
+
"type": "VTL"
|
|
99
|
+
},
|
|
100
|
+
"page": "2.1",
|
|
101
|
+
"componentType": "InputNumber",
|
|
102
|
+
"min": 0,
|
|
103
|
+
"max": 120,
|
|
104
|
+
"decimals": 0,
|
|
105
|
+
"response": { "name": "AGE" }
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"id": "seq-end",
|
|
111
|
+
"componentType": "Sequence",
|
|
112
|
+
"label": {
|
|
113
|
+
"value": "\"End\"",
|
|
114
|
+
"type": "VTL|MD"
|
|
115
|
+
},
|
|
116
|
+
"conditionFilter": { "value": "true", "type": "VTL" },
|
|
117
|
+
"page": "3"
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"resizing": {
|
|
121
|
+
"PRENOM": {
|
|
122
|
+
"size": "count(PRENOM)",
|
|
123
|
+
"variables": ["AGE"]
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
"variables": [
|
|
127
|
+
{
|
|
128
|
+
"variableType": "COLLECTED",
|
|
129
|
+
"name": "PRENOM",
|
|
130
|
+
"values": {
|
|
131
|
+
"PREVIOUS": [null],
|
|
132
|
+
"COLLECTED": [null],
|
|
133
|
+
"FORCED": [null],
|
|
134
|
+
"EDITED": [null],
|
|
135
|
+
"INPUTED": [null]
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"variableType": "COLLECTED",
|
|
140
|
+
"name": "NOM",
|
|
141
|
+
"values": {
|
|
142
|
+
"PREVIOUS": [null],
|
|
143
|
+
"COLLECTED": [null],
|
|
144
|
+
"FORCED": [null],
|
|
145
|
+
"EDITED": [null],
|
|
146
|
+
"INPUTED": [null]
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"variableType": "COLLECTED",
|
|
151
|
+
"name": "BIRTHDAY",
|
|
152
|
+
"values": {
|
|
153
|
+
"PREVIOUS": [null],
|
|
154
|
+
"COLLECTED": [null],
|
|
155
|
+
"FORCED": [null],
|
|
156
|
+
"EDITED": [null],
|
|
157
|
+
"INPUTED": [null]
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"variableType": "COLLECTED",
|
|
162
|
+
"name": "AGE",
|
|
163
|
+
"values": {
|
|
164
|
+
"PREVIOUS": [null],
|
|
165
|
+
"COLLECTED": [null],
|
|
166
|
+
"FORCED": [null],
|
|
167
|
+
"EDITED": [null],
|
|
168
|
+
"INPUTED": [null]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
}
|
|
@@ -204,7 +204,8 @@ function OrchestratorForStories(_ref3) {
|
|
|
204
204
|
overview = _lunatic$useLunatic.overview,
|
|
205
205
|
compileControls = _lunatic$useLunatic.compileControls,
|
|
206
206
|
getData = _lunatic$useLunatic.getData,
|
|
207
|
-
Provider = _lunatic$useLunatic.Provider
|
|
207
|
+
Provider = _lunatic$useLunatic.Provider,
|
|
208
|
+
hasPageResponse = _lunatic$useLunatic.hasPageResponse;
|
|
208
209
|
var components = getComponents();
|
|
209
210
|
var lastReachedPage = pager.lastReachedPage;
|
|
210
211
|
var _useState3 = (0, _react.useState)({}),
|
|
@@ -286,6 +287,17 @@ function OrchestratorForStories(_ref3) {
|
|
|
286
287
|
maxPage: maxPage,
|
|
287
288
|
getData: getData,
|
|
288
289
|
pager: pager
|
|
290
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
291
|
+
className: "story-pager",
|
|
292
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
293
|
+
children: "Misc"
|
|
294
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
295
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("li", {
|
|
296
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("strong", {
|
|
297
|
+
children: "pageHasResponse:"
|
|
298
|
+
}), ' ', JSON.stringify(hasPageResponse())]
|
|
299
|
+
})
|
|
300
|
+
})]
|
|
289
301
|
}), showOverview && /*#__PURE__*/(0, _jsxRuntime.jsx)(_overview.Overview, {
|
|
290
302
|
overview: overview,
|
|
291
303
|
goToPage: goToPage
|
|
@@ -17,15 +17,15 @@ var getReferentiel = exports.getReferentiel = /*#__PURE__*/function () {
|
|
|
17
17
|
_context.next = _context.t0 === 'libelle-pcs2020' ? 3 : _context.t0 === 'naf-rev2-stop' ? 4 : _context.t0 === 'naf-rev2' ? 4 : _context.t0 === 'cog-communes' ? 5 : 6;
|
|
18
18
|
break;
|
|
19
19
|
case 3:
|
|
20
|
-
return _context.abrupt("return", fetch('
|
|
20
|
+
return _context.abrupt("return", fetch('./libelles-pcs-2020.json').then(function (r) {
|
|
21
21
|
return r.json();
|
|
22
22
|
}));
|
|
23
23
|
case 4:
|
|
24
|
-
return _context.abrupt("return", fetch('
|
|
24
|
+
return _context.abrupt("return", fetch('./naf-rev2.json').then(function (r) {
|
|
25
25
|
return r.json();
|
|
26
26
|
}));
|
|
27
27
|
case 5:
|
|
28
|
-
return _context.abrupt("return", fetch('
|
|
28
|
+
return _context.abrupt("return", fetch('./communes-2019.json').then(function (r) {
|
|
29
29
|
return r.json();
|
|
30
30
|
}));
|
|
31
31
|
case 6:
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.compileControls = compileControls;
|
|
8
|
-
var _commons = require("../reducer/commons");
|
|
9
7
|
var _replaceComponentSequence = require("../replace-component-sequence");
|
|
10
8
|
var _typeSource = require("../type-source");
|
|
11
9
|
var _fillComponentExpressions = _interopRequireDefault(require("./fill-components/fill-component-expressions"));
|
|
@@ -13,6 +11,7 @@ var _getComponentsFromState = _interopRequireDefault(require("./get-components-f
|
|
|
13
11
|
var _checkRoundaboutControl = require("../reducer/controls/check-roundabout-control");
|
|
14
12
|
var _checkBaseControl = require("../reducer/controls/check-base-control");
|
|
15
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
15
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
16
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
17
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -21,6 +20,10 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
21
20
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
22
21
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
23
22
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
23
|
+
var isLoopComponent = function isLoopComponent(component) {
|
|
24
|
+
return ['Loop', 'RosterForLoop'].includes(component.componentType);
|
|
25
|
+
};
|
|
26
|
+
|
|
24
27
|
/**
|
|
25
28
|
* Check if components of the current page have errors, and return a map of error (indexed by component ID)
|
|
26
29
|
*/
|
|
@@ -33,6 +36,7 @@ function checkComponents(state, components) {
|
|
|
33
36
|
var component = _step.value;
|
|
34
37
|
var controls = component.controls,
|
|
35
38
|
id = component.id;
|
|
39
|
+
|
|
36
40
|
// The component has global level controls
|
|
37
41
|
if (Array.isArray(controls)) {
|
|
38
42
|
var componentErrors = checkControls(controls.filter(function (c) {
|
|
@@ -44,7 +48,7 @@ function checkComponents(state, components) {
|
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
// For loop, inspect children
|
|
47
|
-
if (
|
|
51
|
+
if (isLoopComponent(component)) {
|
|
48
52
|
var _component$controls;
|
|
49
53
|
var rowControls = (_component$controls = component.controls) === null || _component$controls === void 0 ? void 0 : _component$controls.filter(function (c) {
|
|
50
54
|
return c.type === _typeSource.ControlTypeEnum.row;
|
|
@@ -92,7 +96,7 @@ function checkControls(controls, executeExpression, pager) {
|
|
|
92
96
|
* Figure out the number of iterations of a component
|
|
93
97
|
*/
|
|
94
98
|
function computeIterations(component, executeExpression) {
|
|
95
|
-
if ('iterations' in component) {
|
|
99
|
+
if ('iterations' in component && component.iterations && _typeof(component.iterations) === 'object' && 'value' in component.iterations) {
|
|
96
100
|
return executeExpression(component.iterations.value);
|
|
97
101
|
}
|
|
98
102
|
if ('response' in component) {
|
|
@@ -127,7 +131,9 @@ function checkComponentInLoop(state, component, errors) {
|
|
|
127
131
|
nbIterations: iterations
|
|
128
132
|
});
|
|
129
133
|
// The component is filtered on this iteration, skip it
|
|
130
|
-
if (
|
|
134
|
+
if (
|
|
135
|
+
// conditionFilter can be the interpreted expression, or the object representing the expression
|
|
136
|
+
_typeof(component.conditionFilter) == 'object' && !state.executeExpression(component.conditionFilter.value, iterationPager) || component.conditionFilter === false) {
|
|
131
137
|
continue;
|
|
132
138
|
}
|
|
133
139
|
var componentErrors = checkControls(component.controls, state.executeExpression, iterationPager);
|
|
@@ -5,13 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _getCompatibleVtlExpression = _interopRequireDefault(require("./get-compatible-vtl-expression"));
|
|
8
|
+
var _array = require("../../utils/array");
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
10
|
function executeConditionFilter(filter, execute, iteration) {
|
|
10
11
|
if (filter && typeof execute === 'function') {
|
|
11
12
|
var value = filter.value;
|
|
12
|
-
|
|
13
|
+
var result = execute((0, _getCompatibleVtlExpression["default"])(value), {
|
|
13
14
|
iteration: iteration
|
|
14
15
|
});
|
|
16
|
+
// Todo : replace this with a casting system on execute
|
|
17
|
+
return Array.isArray(result) ? (0, _array.firstItem)(result) : result;
|
|
15
18
|
}
|
|
16
19
|
return undefined;
|
|
17
20
|
}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _isObject = require("../../../utils/is-object");
|
|
8
|
+
var _array = require("../../../utils/array");
|
|
8
9
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
10
|
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
10
11
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -38,9 +39,10 @@ function createCrawl(_ref) {
|
|
|
38
39
|
function executeAndFillObject(object, path) {
|
|
39
40
|
var candidate = object[path];
|
|
40
41
|
try {
|
|
41
|
-
|
|
42
|
+
var result = executeExpression(candidate, {
|
|
42
43
|
iteration: linksIterations !== null && linksIterations !== void 0 ? linksIterations : iteration
|
|
43
|
-
})
|
|
44
|
+
});
|
|
45
|
+
return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, Array.isArray(result) ? (0, _array.firstItem)(result) : result));
|
|
44
46
|
} catch (e) {
|
|
45
47
|
return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, e instanceof Error ? e.toString() : e));
|
|
46
48
|
}
|
|
@@ -59,11 +59,7 @@ function fillChildComponentsWithIteration(component, state) {
|
|
|
59
59
|
return _objectSpread(_objectSpread({}, component), {}, {
|
|
60
60
|
getComponents: function getComponents(iteration) {
|
|
61
61
|
return (0, _fillComponents["default"])(component.components, _objectSpread(_objectSpread({}, state), {}, {
|
|
62
|
-
handleChange:
|
|
63
|
-
state.handleChange(response, value, {
|
|
64
|
-
iteration: [iteration]
|
|
65
|
-
});
|
|
66
|
-
},
|
|
62
|
+
handleChange: createChangeHandlerForIteration(state.handleChange, iteration),
|
|
67
63
|
pager: _objectSpread(_objectSpread({}, state.pager), {}, {
|
|
68
64
|
iteration: iteration,
|
|
69
65
|
subPage: 0 // Fake a subpage to simulate an iteration
|
|
@@ -73,6 +69,27 @@ function fillChildComponentsWithIteration(component, state) {
|
|
|
73
69
|
});
|
|
74
70
|
}
|
|
75
71
|
|
|
72
|
+
// Create change handler memoized for every iteration
|
|
73
|
+
var changeHandler = null;
|
|
74
|
+
var changeHandlerMap = new Map();
|
|
75
|
+
function createChangeHandlerForIteration(handleChange, iteration) {
|
|
76
|
+
if (handleChange !== changeHandler) {
|
|
77
|
+
changeHandler = handleChange;
|
|
78
|
+
changeHandlerMap.clear();
|
|
79
|
+
}
|
|
80
|
+
var handler = changeHandlerMap.get(iteration);
|
|
81
|
+
if (handler) {
|
|
82
|
+
return handler;
|
|
83
|
+
}
|
|
84
|
+
handler = function handler(response, value) {
|
|
85
|
+
handleChange(response, value, {
|
|
86
|
+
iteration: [iteration]
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
changeHandlerMap.set(iteration, handler);
|
|
90
|
+
return handler;
|
|
91
|
+
}
|
|
92
|
+
|
|
76
93
|
/**
|
|
77
94
|
* For pairwise, inject a method to retrieve component at a specific iteration combination
|
|
78
95
|
*/
|
|
@@ -260,6 +260,11 @@ var LunaticVariable = /*#__PURE__*/function () {
|
|
|
260
260
|
|
|
261
261
|
// Calculate bindings first to refresh "updatedAt" on calculated dependencies
|
|
262
262
|
var bindings = this.getDependenciesValues(iteration);
|
|
263
|
+
// A variable without binding is a primitive (string, boolean...)
|
|
264
|
+
// it yields the same results for every iteration, so we can ignore iteration
|
|
265
|
+
if (Object.keys(bindings).length === 0) {
|
|
266
|
+
iteration = undefined;
|
|
267
|
+
}
|
|
263
268
|
if (!this.isOutdated(iteration)) {
|
|
264
269
|
return this.getSavedValue(iteration);
|
|
265
270
|
}
|
|
@@ -212,6 +212,16 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
|
|
|
212
212
|
(0, _vitest.expect)(variables.get('AGE', [1])).toEqual(12);
|
|
213
213
|
(0, _vitest.expect)(variables.get('AGE_AND_MAX', [0])).toEqual(13);
|
|
214
214
|
});
|
|
215
|
+
(0, _vitest.it)('should handle primitive value', function () {
|
|
216
|
+
variables.run('"hello"', {
|
|
217
|
+
iteration: [0]
|
|
218
|
+
});
|
|
219
|
+
variables.run('"hello"', {
|
|
220
|
+
iteration: [1]
|
|
221
|
+
});
|
|
222
|
+
(0, _vitest.expect)(variables.run('"hello"')).toEqual('hello');
|
|
223
|
+
(0, _vitest.expect)(variables.interpretCount).toBe(1);
|
|
224
|
+
});
|
|
215
225
|
});
|
|
216
226
|
(0, _vitest.describe)('resizing', function () {
|
|
217
227
|
(0, _vitest.it)('should resize variables', function () {
|
|
@@ -19,8 +19,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
19
19
|
*/
|
|
20
20
|
function usePageHasResponse(components, executeExpression) {
|
|
21
21
|
return (0, _react.useCallback)(function () {
|
|
22
|
-
if (!Array.isArray(components)) {
|
|
23
|
-
return
|
|
22
|
+
if (!Array.isArray(components) || components.length === 0) {
|
|
23
|
+
return true;
|
|
24
24
|
}
|
|
25
25
|
var _iterator = _createForOfIteratorHelper(components),
|
|
26
26
|
_step;
|
|
@@ -28,9 +28,16 @@ function usePageHasResponse(components, executeExpression) {
|
|
|
28
28
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
29
29
|
var component = _step.value;
|
|
30
30
|
// Some components are considered as "filled" by default
|
|
31
|
-
|
|
31
|
+
// We assume they are not in the same page has other components
|
|
32
|
+
if (['PairwiseLinks', 'Roundabout', 'Sequence', 'Subsequence'].includes(component.componentType)) {
|
|
32
33
|
return true;
|
|
33
34
|
}
|
|
35
|
+
|
|
36
|
+
// We have a missing response for this component
|
|
37
|
+
if ('missingResponse' in component && component.missingResponse && component.missingResponse.value) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
// For Table, we have to extract components from its body and apply isSubComponentsEmpty function
|
|
35
42
|
if (component.componentType === 'Table') {
|
|
36
43
|
// Body is array for array (row), each "cell" could be an Label or Component, so we filter array.
|
|
@@ -47,6 +54,7 @@ function usePageHasResponse(components, executeExpression) {
|
|
|
47
54
|
if ('value' in component && !isEmpty(component.value)) {
|
|
48
55
|
return true;
|
|
49
56
|
}
|
|
57
|
+
|
|
50
58
|
// For rosterForLoop we need to inspect child components
|
|
51
59
|
if ('components' in component && Array.isArray(component.components) && !isSubComponentsEmpty(component.components, executeExpression)) {
|
|
52
60
|
return true;
|
|
@@ -4,15 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
-
resizeArrayVariable: true
|
|
8
|
-
isLoopComponent: true
|
|
7
|
+
resizeArrayVariable: true
|
|
9
8
|
};
|
|
10
|
-
Object.defineProperty(exports, "isLoopComponent", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _isLoopComponent.isLoopComponent;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
9
|
Object.defineProperty(exports, "resizeArrayVariable", {
|
|
17
10
|
enumerable: true,
|
|
18
11
|
get: function get() {
|
|
@@ -20,7 +13,6 @@ Object.defineProperty(exports, "resizeArrayVariable", {
|
|
|
20
13
|
}
|
|
21
14
|
});
|
|
22
15
|
var _resizeArrayVariable = _interopRequireDefault(require("./resize-array-variable"));
|
|
23
|
-
var _isLoopComponent = require("./is-loop-component");
|
|
24
16
|
var _validateConditionFilter = require("./validate-condition-filter");
|
|
25
17
|
Object.keys(_validateConditionFilter).forEach(function (key) {
|
|
26
18
|
if (key === "default" || key === "__esModule") return;
|
package/lib/utils/array.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.firstItem = firstItem;
|
|
6
7
|
exports.getAtIndex = getAtIndex;
|
|
7
8
|
exports.resizeArray = resizeArray;
|
|
8
9
|
exports.setAtIndex = setAtIndex;
|
|
@@ -81,4 +82,24 @@ function resizeArray(array, newLength, defaultValue) {
|
|
|
81
82
|
return new Array(newLength).fill(defaultValue !== null && defaultValue !== void 0 ? defaultValue : null).map(function (value, index) {
|
|
82
83
|
return index < array.length ? array[index] : value;
|
|
83
84
|
}, []);
|
|
85
|
+
}
|
|
86
|
+
function firstItem(items) {
|
|
87
|
+
if (!Array.isArray(items)) {
|
|
88
|
+
return items;
|
|
89
|
+
}
|
|
90
|
+
var _iterator2 = _createForOfIteratorHelper(items),
|
|
91
|
+
_step2;
|
|
92
|
+
try {
|
|
93
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
94
|
+
var item = _step2.value;
|
|
95
|
+
if (item !== undefined) {
|
|
96
|
+
return item;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
_iterator2.e(err);
|
|
101
|
+
} finally {
|
|
102
|
+
_iterator2.f();
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
84
105
|
}
|
package/lib/utils/variables.js
CHANGED
|
@@ -8,29 +8,18 @@ exports.getInitialVariableValue = getInitialVariableValue;
|
|
|
8
8
|
* Extract the initial value from the source.json and data.json
|
|
9
9
|
*/
|
|
10
10
|
function getInitialVariableValue(variable) {
|
|
11
|
-
var _data$variable$variab;
|
|
11
|
+
var _data$variable$variab, _data$COLLECTED;
|
|
12
12
|
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
13
13
|
switch (variable.variableType) {
|
|
14
14
|
case 'EXTERNAL':
|
|
15
15
|
case 'CALCULATED':
|
|
16
16
|
return (_data$variable$variab = data[variable.variableType]) === null || _data$variable$variab === void 0 ? void 0 : _data$variable$variab[variable.name];
|
|
17
17
|
case 'COLLECTED':
|
|
18
|
-
var
|
|
19
|
-
var fromData;
|
|
20
|
-
if (collectedData && variable.name in collectedData) {
|
|
21
|
-
var _collectedData$variab = collectedData[variable.name],
|
|
22
|
-
COLLECTED = _collectedData$variab.COLLECTED,
|
|
23
|
-
FORCED = _collectedData$variab.FORCED;
|
|
24
|
-
fromData = COLLECTED !== null && COLLECTED !== void 0 ? COLLECTED : FORCED;
|
|
25
|
-
}
|
|
18
|
+
var fromData = (_data$COLLECTED = data.COLLECTED) === null || _data$COLLECTED === void 0 || (_data$COLLECTED = _data$COLLECTED[variable.name]) === null || _data$COLLECTED === void 0 ? void 0 : _data$COLLECTED.COLLECTED;
|
|
26
19
|
if ('values' in variable && variable.values) {
|
|
27
|
-
|
|
28
|
-
var _variable$values = variable.values,
|
|
29
|
-
_COLLECTED = _variable$values.COLLECTED,
|
|
30
|
-
_FORCED = _variable$values.FORCED;
|
|
31
|
-
return (_ref = (_fromData = fromData) !== null && _fromData !== void 0 ? _fromData : _FORCED) !== null && _ref !== void 0 ? _ref : _COLLECTED;
|
|
20
|
+
return fromData !== null && fromData !== void 0 ? fromData : variable.values.COLLECTED;
|
|
32
21
|
}
|
|
33
|
-
return
|
|
22
|
+
return fromData;
|
|
34
23
|
default:
|
|
35
24
|
return null;
|
|
36
25
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _variables = require("./variables");
|
|
5
|
+
var data = {
|
|
6
|
+
EXTERNAL: {
|
|
7
|
+
ADRESSE: 'mon adresse'
|
|
8
|
+
},
|
|
9
|
+
CALCULATED: {
|
|
10
|
+
PRENOMSB: ['Paul', 'Pierre']
|
|
11
|
+
},
|
|
12
|
+
COLLECTED: {
|
|
13
|
+
NB_HAB: {
|
|
14
|
+
COLLECTED: 2
|
|
15
|
+
},
|
|
16
|
+
PRENOMS: {
|
|
17
|
+
COLLECTED: ['Paul', 'Pierre'],
|
|
18
|
+
EDITED: [],
|
|
19
|
+
INPUTED: [],
|
|
20
|
+
FORCED: [],
|
|
21
|
+
PREVIOUS: []
|
|
22
|
+
},
|
|
23
|
+
AGE: {}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var externalVariable = {
|
|
27
|
+
variableType: 'EXTERNAL',
|
|
28
|
+
name: 'ADRESSE'
|
|
29
|
+
};
|
|
30
|
+
var calculatedVariable = {
|
|
31
|
+
variableType: 'CALCULATED',
|
|
32
|
+
bindingDependencies: ['PRENOMS'],
|
|
33
|
+
expression: {
|
|
34
|
+
type: 'VTL',
|
|
35
|
+
value: 'PRENOMS'
|
|
36
|
+
},
|
|
37
|
+
name: 'PRENOMSB',
|
|
38
|
+
shapeFrom: 'PRENOMS'
|
|
39
|
+
};
|
|
40
|
+
var simpleCollectedVariable = {
|
|
41
|
+
variableType: 'COLLECTED',
|
|
42
|
+
name: 'NB_HAB'
|
|
43
|
+
};
|
|
44
|
+
var loopCollectedVariable = {
|
|
45
|
+
variableType: 'COLLECTED',
|
|
46
|
+
values: {
|
|
47
|
+
COLLECTED: []
|
|
48
|
+
},
|
|
49
|
+
name: 'PRENOMS'
|
|
50
|
+
};
|
|
51
|
+
var emptyCollectedVariable = {
|
|
52
|
+
variableType: 'COLLECTED',
|
|
53
|
+
name: 'AGE'
|
|
54
|
+
};
|
|
55
|
+
(0, _vitest.describe)('getInitialVariableValue', function () {
|
|
56
|
+
(0, _vitest.it)('should return external value', function () {
|
|
57
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(externalVariable, data)).toEqual('mon adresse');
|
|
58
|
+
});
|
|
59
|
+
(0, _vitest.it)('should return calculated value', function () {
|
|
60
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(calculatedVariable, data)).toEqual(['Paul', 'Pierre']);
|
|
61
|
+
});
|
|
62
|
+
(0, _vitest.it)('should return collected value out of a loop', function () {
|
|
63
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(simpleCollectedVariable, data)).toEqual(2);
|
|
64
|
+
});
|
|
65
|
+
(0, _vitest.it)('should return array of collected values in a loop', function () {
|
|
66
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(loopCollectedVariable, data)).toEqual(['Paul', 'Pierre']);
|
|
67
|
+
});
|
|
68
|
+
(0, _vitest.it)('should return undefined value out of a loop', function () {
|
|
69
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(emptyCollectedVariable, data)).toEqual(undefined);
|
|
70
|
+
});
|
|
71
|
+
(0, _vitest.it)('should set empty undefined if no data', function () {
|
|
72
|
+
(0, _vitest.expect)((0, _variables.getInitialVariableValue)(simpleCollectedVariable)).toEqual(undefined);
|
|
73
|
+
});
|
|
74
|
+
});
|