@inseefr/lunatic 2.7.16 → 2.7.18
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/loop/roster-for-loop/roster-for-loop.js +1 -1
- package/lib/src/utils/array.d.ts +4 -0
- package/lib/stories/loop/source-roster.json +10 -10
- package/lib/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +7 -2
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +17 -0
- package/lib/utils/array.js +12 -0
- package/package.json +1 -1
|
@@ -52,7 +52,7 @@ var RosterForLoop = exports.RosterForLoop = (0, _commons.createCustomizableLunat
|
|
|
52
52
|
otherProps = _objectWithoutProperties(props, _excluded);
|
|
53
53
|
var min = (lines === null || lines === void 0 ? void 0 : lines.min) || DEFAULT_MIN_ROWS;
|
|
54
54
|
var max = (lines === null || lines === void 0 ? void 0 : lines.max) || DEFAULT_MAX_ROWS;
|
|
55
|
-
var _useState = (0, _react.useState)(iterations),
|
|
55
|
+
var _useState = (0, _react.useState)(Math.max(min, iterations)),
|
|
56
56
|
_useState2 = _slicedToArray(_useState, 2),
|
|
57
57
|
nbRows = _useState2[0],
|
|
58
58
|
setNbRows = _useState2[1];
|
package/lib/src/utils/array.d.ts
CHANGED
|
@@ -22,3 +22,7 @@ export declare function firstValueItem<T = unknown>(items: T | T[]): T | undefin
|
|
|
22
22
|
* - subArray([1, 2, 3]) // [[1], [1, 2], [1, 2, 3]]
|
|
23
23
|
*/
|
|
24
24
|
export declare function subArrays<T = unknown>(items: T[] | T): T[][];
|
|
25
|
+
/**
|
|
26
|
+
* Calculates the depth of an array
|
|
27
|
+
*/
|
|
28
|
+
export declare function depth(arr: unknown, base?: number): number;
|
|
@@ -92,22 +92,22 @@
|
|
|
92
92
|
"variableType": "COLLECTED",
|
|
93
93
|
"name": "PRENOM",
|
|
94
94
|
"values": {
|
|
95
|
-
"PREVIOUS": [
|
|
96
|
-
"COLLECTED": [
|
|
97
|
-
"FORCED": [
|
|
98
|
-
"EDITED": [
|
|
99
|
-
"INPUTED": [
|
|
95
|
+
"PREVIOUS": [],
|
|
96
|
+
"COLLECTED": [],
|
|
97
|
+
"FORCED": [],
|
|
98
|
+
"EDITED": [],
|
|
99
|
+
"INPUTED": []
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
102
|
{
|
|
103
103
|
"variableType": "COLLECTED",
|
|
104
104
|
"name": "AGE",
|
|
105
105
|
"values": {
|
|
106
|
-
"PREVIOUS": [
|
|
107
|
-
"COLLECTED": [
|
|
108
|
-
"FORCED": [
|
|
109
|
-
"EDITED": [
|
|
110
|
-
"INPUTED": [
|
|
106
|
+
"PREVIOUS": [],
|
|
107
|
+
"COLLECTED": [],
|
|
108
|
+
"FORCED": [],
|
|
109
|
+
"EDITED": [],
|
|
110
|
+
"INPUTED": []
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
]
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.cleaningBehaviour = cleaningBehaviour;
|
|
7
|
+
var _array = require("../../../../utils/array");
|
|
7
8
|
/**
|
|
8
9
|
* Cleaning behaviour for the store
|
|
9
10
|
* When a variable changes, other variables can be reset
|
|
@@ -32,8 +33,12 @@ function cleaningBehaviour(store, cleaning) {
|
|
|
32
33
|
if (skipCleaning) {
|
|
33
34
|
continue;
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
|
|
37
|
+
// Variable may be top level, so we need to deduce expected iteration
|
|
38
|
+
var variableDepth = (0, _array.depth)(initialValues[variableName]);
|
|
39
|
+
var variableIteration = variableDepth === 0 ? undefined : iteration === null || iteration === void 0 ? void 0 : iteration.slice(0, (0, _array.depth)(initialValues[variableName]));
|
|
40
|
+
store.set(variableName, getValueAtIteration(initialValues[variableName], variableIteration), {
|
|
41
|
+
iteration: variableIteration
|
|
37
42
|
});
|
|
38
43
|
} catch (e) {
|
|
39
44
|
// If we have an error, skip this cleaning
|
|
@@ -287,6 +287,8 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
|
|
|
287
287
|
READY: {
|
|
288
288
|
PRENOM: 'READY'
|
|
289
289
|
}
|
|
290
|
+
}, {
|
|
291
|
+
PRENOM: [null]
|
|
290
292
|
});
|
|
291
293
|
variables.set('READY', false, {
|
|
292
294
|
iteration: [1]
|
|
@@ -308,6 +310,21 @@ var _lunaticVariablesStore = require("./lunatic-variables-store");
|
|
|
308
310
|
});
|
|
309
311
|
(0, _vitest.expect)(variables.get('PRENOM')).toEqual(['John', null, 'Marc']);
|
|
310
312
|
});
|
|
313
|
+
(0, _vitest.it)('should clean root variables even when in an iteration', function () {
|
|
314
|
+
variables.set('PRENOM', 'John');
|
|
315
|
+
variables.set('READY', [true, true, true]);
|
|
316
|
+
(0, _cleaningBehaviour.cleaningBehaviour)(variables, {
|
|
317
|
+
READY: {
|
|
318
|
+
PRENOM: 'READY'
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
PRENOM: null
|
|
322
|
+
});
|
|
323
|
+
variables.set('READY', false, {
|
|
324
|
+
iteration: [1]
|
|
325
|
+
});
|
|
326
|
+
(0, _vitest.expect)(variables.get('PRENOM')).toEqual(null);
|
|
327
|
+
});
|
|
311
328
|
});
|
|
312
329
|
(0, _vitest.describe)('missing', function () {
|
|
313
330
|
(0, _vitest.beforeEach)(function () {
|
package/lib/utils/array.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.depth = depth;
|
|
6
7
|
exports.firstValueItem = firstValueItem;
|
|
7
8
|
exports.getAtIndex = getAtIndex;
|
|
8
9
|
exports.resizeArray = resizeArray;
|
|
@@ -115,4 +116,15 @@ function subArrays(items) {
|
|
|
115
116
|
arrays.push(items.slice(0, i));
|
|
116
117
|
}
|
|
117
118
|
return arrays;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Calculates the depth of an array
|
|
123
|
+
*/
|
|
124
|
+
function depth(arr) {
|
|
125
|
+
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
126
|
+
if (!Array.isArray(arr)) {
|
|
127
|
+
return base;
|
|
128
|
+
}
|
|
129
|
+
return depth(arr[0], base + 1);
|
|
118
130
|
}
|