@inseefr/lunatic 3.6.6 → 3.6.8-rc.0
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/README.md +25 -0
- package/components/Loop/Loop.d.ts +1 -1
- package/components/Loop/Loop.js +5 -27
- package/components/Loop/Loop.js.map +1 -1
- package/components/Loop/utils.d.ts +8 -0
- package/components/Loop/utils.js +66 -0
- package/components/Loop/utils.js.map +1 -0
- package/components/RosterForLoop/RosterForLoop.js +4 -27
- package/components/RosterForLoop/RosterForLoop.js.map +1 -1
- package/esm/components/Loop/Loop.d.ts +1 -1
- package/esm/components/Loop/Loop.js +5 -28
- package/esm/components/Loop/Loop.js.map +1 -1
- package/esm/components/Loop/utils.d.ts +8 -0
- package/esm/components/Loop/utils.js +63 -0
- package/esm/components/Loop/utils.js.map +1 -0
- package/esm/components/RosterForLoop/RosterForLoop.js +5 -29
- package/esm/components/RosterForLoop/RosterForLoop.js.map +1 -1
- package/esm/use-lunatic/commons/compile-controls.js +8 -0
- package/esm/use-lunatic/commons/compile-controls.js.map +1 -1
- package/esm/use-lunatic/props/propIterations.js +12 -1
- package/esm/use-lunatic/props/propIterations.js.map +1 -1
- package/esm/use-lunatic/reducer/controls/check-base-control.js.map +1 -1
- package/package.json +15 -3
- package/src/components/Loop/Loop.tsx +6 -35
- package/src/components/Loop/utils.test.ts +61 -0
- package/src/components/Loop/utils.ts +74 -0
- package/src/components/RosterForLoop/RosterForLoop.tsx +3 -33
- package/src/stories/behaviour/controls/controls.stories.tsx +12 -3
- package/src/stories/behaviour/controls/data-standalone-loop.json +17 -0
- package/src/stories/behaviour/controls/source-standalone-loop.json +5503 -0
- package/src/stories/loop/source-paginated.json +1 -1
- package/src/stories/roundabout/sourceWithControl.json +14 -0
- package/src/use-lunatic/commons/compile-controls.ts +13 -0
- package/src/use-lunatic/props/propIterations.ts +30 -15
- package/src/use-lunatic/reducer/controls/check-base-control.ts +0 -1
- package/src/use-lunatic/use-lunatic-bug.test.ts +42 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/use-lunatic/commons/compile-controls.js +7 -0
- package/use-lunatic/commons/compile-controls.js.map +1 -1
- package/use-lunatic/props/propIterations.js +12 -1
- package/use-lunatic/props/propIterations.js.map +1 -1
- package/use-lunatic/reducer/controls/check-base-control.js.map +1 -1
- /package/src/stories/behaviour/controls/{source-loop.json → source-roster-for-loop.json} +0 -0
|
@@ -347,6 +347,20 @@
|
|
|
347
347
|
},
|
|
348
348
|
"locked": false,
|
|
349
349
|
"controls": [
|
|
350
|
+
{
|
|
351
|
+
"id": "lypxwut2-CI-3",
|
|
352
|
+
"type": "ROW",
|
|
353
|
+
"control": {
|
|
354
|
+
"type": "VTL",
|
|
355
|
+
"value": "not(AGE = \"null\")"
|
|
356
|
+
},
|
|
357
|
+
"criticality": "WARN",
|
|
358
|
+
"errorMessage": {
|
|
359
|
+
"type": "VTL|MD",
|
|
360
|
+
"value": "\"Vous n'avez pas renseigné l'âge de \" || PRENOM || \".\" "
|
|
361
|
+
},
|
|
362
|
+
"typeOfControl": "CONSISTENCY"
|
|
363
|
+
},
|
|
350
364
|
{
|
|
351
365
|
"id": "lypxwut2-CI-1",
|
|
352
366
|
"type": "SIMPLE",
|
|
@@ -217,6 +217,19 @@ function checkComponentInLoop(
|
|
|
217
217
|
if (!('controls' in component) || !component.controls) {
|
|
218
218
|
continue;
|
|
219
219
|
}
|
|
220
|
+
|
|
221
|
+
// For Roundabout, we don't check controls for iterations that are disabled
|
|
222
|
+
if (component.componentType === 'Roundabout' && component.item.disabled) {
|
|
223
|
+
const isIterationDisabled = state.executeExpression(
|
|
224
|
+
{ value: component.item.disabled?.value, type: 'VTL' },
|
|
225
|
+
iterationPager
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
if (isIterationDisabled) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
220
233
|
// The component is filtered on this iteration, skip it
|
|
221
234
|
if (
|
|
222
235
|
// conditionFilter can be the interpreted expression, or the object representing the expression
|
|
@@ -32,20 +32,35 @@ export function getIterationsProp(
|
|
|
32
32
|
|
|
33
33
|
// Iterations expression is not present on the component definition
|
|
34
34
|
// infer it from the value of child components
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return acc;
|
|
39
|
-
}
|
|
40
|
-
const value = state.variables.get(
|
|
41
|
-
component.response.name,
|
|
42
|
-
isNumber(state.pager.iteration) ? [state.pager.iteration] : undefined
|
|
43
|
-
);
|
|
44
|
-
if (Array.isArray(value) && value.length > acc) {
|
|
45
|
-
return value.length;
|
|
46
|
-
}
|
|
35
|
+
|
|
36
|
+
return getFlatComponentsInLoop(definition).reduce((acc, component) => {
|
|
37
|
+
if (!hasResponse(component)) {
|
|
47
38
|
return acc;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
}
|
|
40
|
+
const value = state.variables.get(
|
|
41
|
+
component.response.name,
|
|
42
|
+
isNumber(state.pager.iteration) ? [state.pager.iteration] : undefined
|
|
43
|
+
);
|
|
44
|
+
if (Array.isArray(value) && value.length > acc) {
|
|
45
|
+
return value.length;
|
|
46
|
+
}
|
|
47
|
+
return acc;
|
|
48
|
+
}, 0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getFlatComponentsInLoop(
|
|
52
|
+
definition: LunaticComponentDefinition
|
|
53
|
+
): LunaticComponentDefinition[] {
|
|
54
|
+
if (
|
|
55
|
+
definition.componentType !== 'RosterForLoop' &&
|
|
56
|
+
definition.componentType !== 'Loop'
|
|
57
|
+
) {
|
|
58
|
+
return [definition];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return definition.components.reduce((acc, component) => {
|
|
62
|
+
if (component.componentType === 'Question')
|
|
63
|
+
return [...acc, ...component.components];
|
|
64
|
+
return [...acc, component];
|
|
65
|
+
}, [] as LunaticComponentDefinition[]);
|
|
51
66
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import loopControlSource from '../stories/behaviour/controls/source-standalone-loop.json';
|
|
5
|
+
import surveyUnit from '../stories/behaviour/controls/data-standalone-loop.json';
|
|
6
|
+
import { useLunatic } from './use-lunatic';
|
|
7
|
+
|
|
8
|
+
describe('use-lunatic()', () => {
|
|
9
|
+
/**
|
|
10
|
+
* This test should be succeded after make some improvment
|
|
11
|
+
* See: comment above useEffect of src/components/Loop/utils.ts > useLoopUtils
|
|
12
|
+
*/
|
|
13
|
+
it.skip('should compile errors correctly', () => {
|
|
14
|
+
const { result } = renderHook(() =>
|
|
15
|
+
useLunatic(loopControlSource, surveyUnit.data)
|
|
16
|
+
);
|
|
17
|
+
act(() => {
|
|
18
|
+
result.current.goToPage({ page: '3' });
|
|
19
|
+
});
|
|
20
|
+
const { currentErrors } = result.current.compileControls();
|
|
21
|
+
expect(currentErrors).not.toBeUndefined();
|
|
22
|
+
expect(Object.keys(currentErrors!).length).toEqual(6);
|
|
23
|
+
});
|
|
24
|
+
it('should compile errors correctly 2', () => {
|
|
25
|
+
const { result } = renderHook(() =>
|
|
26
|
+
useLunatic(loopControlSource, {
|
|
27
|
+
COLLECTED: {
|
|
28
|
+
PRES_SAL: { COLLECTED: ['1', null, '2', null, null, null] },
|
|
29
|
+
},
|
|
30
|
+
...surveyUnit.data,
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
act(() => {
|
|
34
|
+
result.current.goToPage({ page: '3' });
|
|
35
|
+
});
|
|
36
|
+
act(() => {
|
|
37
|
+
const { currentErrors } = result.current.compileControls();
|
|
38
|
+
expect(currentErrors).not.toBeUndefined();
|
|
39
|
+
expect(Object.keys(currentErrors!).length).toEqual(4);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|