@inseefr/lunatic 3.13.5-rc.4 → 3.13.5

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.
Files changed (41) hide show
  1. package/components/Duration/getDurationFromValue.d.ts +2 -2
  2. package/components/Duration/getDurationFromValue.js +7 -6
  3. package/components/Duration/getDurationFromValue.js.map +1 -1
  4. package/components/shared/MDLabel/MDLabel.js +2 -1
  5. package/components/shared/MDLabel/MDLabel.js.map +1 -1
  6. package/esm/components/Duration/getDurationFromValue.d.ts +2 -2
  7. package/esm/components/Duration/getDurationFromValue.js +7 -6
  8. package/esm/components/Duration/getDurationFromValue.js.map +1 -1
  9. package/esm/components/shared/MDLabel/MDLabel.js +2 -1
  10. package/esm/components/shared/MDLabel/MDLabel.js.map +1 -1
  11. package/esm/hooks/useMultimode.js +21 -10
  12. package/esm/hooks/useMultimode.js.map +1 -1
  13. package/esm/use-lunatic/commons/compile-controls.d.ts +5 -0
  14. package/esm/use-lunatic/commons/compile-controls.js +6 -1
  15. package/esm/use-lunatic/commons/compile-controls.js.map +1 -1
  16. package/esm/use-lunatic/commons/compile-controls.spec.d.ts +1 -0
  17. package/esm/use-lunatic/commons/compile-controls.spec.js +121 -0
  18. package/esm/use-lunatic/commons/compile-controls.spec.js.map +1 -0
  19. package/esm/utils/getArticulationState.js +12 -6
  20. package/esm/utils/getArticulationState.js.map +1 -1
  21. package/hooks/useMultimode.js +20 -8
  22. package/hooks/useMultimode.js.map +1 -1
  23. package/package.json +12 -2
  24. package/src/components/Duration/getDurationFromValue.ts +10 -6
  25. package/src/components/shared/MDLabel/MDLabel.tsx +2 -2
  26. package/src/hooks/useMultimode.ts +27 -13
  27. package/src/stories/questionnaires/SRCV/data.json +116 -0
  28. package/src/stories/questionnaires/SRCV/source.json +69256 -0
  29. package/src/stories/questionnaires/SRCV/srcv.stories.tsx +23 -0
  30. package/src/use-lunatic/commons/compile-controls.spec.ts +136 -0
  31. package/src/use-lunatic/commons/compile-controls.ts +7 -1
  32. package/src/utils/getArticulationState.ts +16 -8
  33. package/tsconfig.build.tsbuildinfo +1 -1
  34. package/use-lunatic/commons/compile-controls.d.ts +5 -0
  35. package/use-lunatic/commons/compile-controls.js +6 -0
  36. package/use-lunatic/commons/compile-controls.js.map +1 -1
  37. package/use-lunatic/commons/compile-controls.spec.d.ts +1 -0
  38. package/use-lunatic/commons/compile-controls.spec.js +123 -0
  39. package/use-lunatic/commons/compile-controls.spec.js.map +1 -0
  40. package/utils/getArticulationState.js +12 -6
  41. package/utils/getArticulationState.js.map +1 -1
@@ -55,22 +55,37 @@ export function useMultimode(
55
55
  return {};
56
56
  }
57
57
 
58
- const roundabout = findComponentById(
59
- source.components,
60
- source.multimode.leaf.source
61
- );
58
+ // Initialize rules to empty objects if they do not exist
59
+ const questionnaireRules = source.multimode.questionnaire?.rules || {};
60
+ const leafRules = source.multimode.leaf?.rules || {};
61
+
62
+ // If neither has rules, return an empty object
63
+ if (Object.keys(questionnaireRules).length === 0 && Object.keys(leafRules).length === 0) {
64
+ return {};
65
+ }
62
66
 
67
+ // Get unique rule keys
63
68
  const keys = new Set([
64
- ...Object.keys(source.multimode.questionnaire.rules),
65
- ...Object.keys(source.multimode.leaf.rules),
69
+ ...Object.keys(questionnaireRules),
70
+ ...Object.keys(leafRules),
66
71
  ]);
67
- const iterations = forceInt(store.run(roundabout?.iterations.value ?? '0'));
72
+
73
+ // Handle the case where leaf.source exists to retrieve iterations
74
+ let iterations = 0;
75
+ if (source.multimode.leaf?.source) {
76
+ const roundabout = findComponentById(
77
+ source.components,
78
+ source.multimode.leaf.source
79
+ );
80
+ iterations = forceInt(
81
+ store.run(roundabout?.iterations?.value ?? '') ?? 0
82
+ );
83
+ }
68
84
 
69
85
  return Object.fromEntries(
70
86
  Array.from(keys).map((key) => {
71
- // Check the value at questionnaire level
72
- const questionnaireExpression =
73
- source.multimode?.questionnaire.rules[key];
87
+ // Check the rule at the questionnaire level
88
+ const questionnaireExpression = questionnaireRules[key];
74
89
  if (
75
90
  questionnaireExpression &&
76
91
  store.run(questionnaireExpression.value)
@@ -78,9 +93,8 @@ export function useMultimode(
78
93
  return [key, true];
79
94
  }
80
95
 
81
- const leafExpression = source.multimode?.leaf.rules[key];
82
-
83
- // There is no expression for the leaf
96
+ // Check the rule at the leaf level
97
+ const leafExpression = leafRules[key];
84
98
  if (!leafExpression) {
85
99
  return [key, false];
86
100
  }
@@ -0,0 +1,116 @@
1
+ {
2
+ "id": "5a90586e-a2a3-4853-aa3a-f8ebd0f6e86b",
3
+ "questionnaireId": "4552-CAPI",
4
+ "personalization": [],
5
+ "data": {
6
+ "EXTERNAL": {
7
+ "ADR": "1 RUE DU GRAND CHENE 79200 PARTHENAY",
8
+ "TROPIQUE": "1"
9
+ },
10
+ "COLLECTED": {
11
+ "RESIND": [],
12
+ "LIENS": {
13
+ "COLLECTED": [
14
+ [
15
+ null,
16
+ "17",
17
+ "17"
18
+ ],
19
+ [
20
+ "17",
21
+ null,
22
+ "17"
23
+ ],
24
+ [
25
+ "17",
26
+ "17"
27
+ ]
28
+ ]
29
+ },
30
+ "T_NHAB": {
31
+ "COLLECTED": 3
32
+ },
33
+ "T_SEXE": {
34
+ "COLLECTED": [
35
+ "1",
36
+ "1",
37
+ "1"
38
+ ]
39
+ },
40
+ "T_STOC": {
41
+ "COLLECTED": "3"
42
+ },
43
+ "T_STOL": {
44
+ "COLLECTED": "2"
45
+ },
46
+ "T_LNAIS": {
47
+ "COLLECTED": [
48
+ "1",
49
+ "1",
50
+ "1"
51
+ ]
52
+ },
53
+ "T_UNLOG": {
54
+ "COLLECTED": [
55
+ "2",
56
+ "2",
57
+ "2"
58
+ ]
59
+ },
60
+ "DATE_ITW": {
61
+ "COLLECTED": "2027-03-01"
62
+ },
63
+ "T_PRENOM": {
64
+ "COLLECTED": [
65
+ "Lucas",
66
+ "Mathieu",
67
+ "Antoine"
68
+ ]
69
+ },
70
+ "T_TYPLOG": {
71
+ "COLLECTED": "1"
72
+ },
73
+ "T_DEPNAIS": {
74
+ "COLLECTED": [
75
+ "Seine-Saint-Denis",
76
+ "Seine-et-Marne",
77
+ "Seine-Maritime"
78
+ ]
79
+ },
80
+ "T_NATION1": {
81
+ "COLLECTED": [
82
+ true,
83
+ true,
84
+ true
85
+ ]
86
+ },
87
+ "T_NPIECES": {
88
+ "COLLECTED": 5
89
+ },
90
+ "T_SURFACE": {
91
+ "COLLECTED": 98
92
+ },
93
+ "T_TYPMAIS": {
94
+ "COLLECTED": "2"
95
+ },
96
+ "T_DATENAIS": {
97
+ "COLLECTED": [
98
+ "1998-02-19",
99
+ "1997-06-03",
100
+ "1999-06-14"
101
+ ]
102
+ },
103
+ "T_EMMENAGE": {
104
+ "COLLECTED": "2023"
105
+ },
106
+ "T_LOGPROPRI": {
107
+ "COLLECTED": "6"
108
+ }
109
+ }
110
+ },
111
+ "stateData": {
112
+ "state": "INIT",
113
+ "date": 1790865361892,
114
+ "currentPage": "1"
115
+ }
116
+ }