@inseefr/lunatic 3.13.4 → 3.13.5-rc-fix-multimode.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.
Files changed (81) 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/Suggester/CustomSuggester.d.ts +1 -0
  5. package/components/Suggester/CustomSuggester.js +2 -2
  6. package/components/Suggester/CustomSuggester.js.map +1 -1
  7. package/components/Suggester/CustomSuggester.spec.d.ts +1 -0
  8. package/components/Suggester/CustomSuggester.spec.js +32 -0
  9. package/components/Suggester/CustomSuggester.spec.js.map +1 -0
  10. package/components/Suggester/Suggester.d.ts +1 -1
  11. package/components/Suggester/Suggester.js +2 -2
  12. package/components/Suggester/Suggester.js.map +1 -1
  13. package/components/shared/Combobox/Combobox.js +2 -2
  14. package/components/shared/Combobox/Combobox.js.map +1 -1
  15. package/components/shared/Combobox/ComboboxType.d.ts +1 -0
  16. package/components/shared/Combobox/Selection/ComboboxInput.d.ts +1 -0
  17. package/components/shared/Combobox/Selection/ComboboxInput.js +2 -2
  18. package/components/shared/Combobox/Selection/ComboboxInput.js.map +1 -1
  19. package/components/shared/Combobox/Selection/ComboboxSelection.d.ts +1 -1
  20. package/components/shared/Combobox/Selection/ComboboxSelection.js +3 -3
  21. package/components/shared/Combobox/Selection/ComboboxSelection.js.map +1 -1
  22. package/esm/components/Duration/getDurationFromValue.d.ts +2 -2
  23. package/esm/components/Duration/getDurationFromValue.js +7 -6
  24. package/esm/components/Duration/getDurationFromValue.js.map +1 -1
  25. package/esm/components/Suggester/CustomSuggester.d.ts +1 -0
  26. package/esm/components/Suggester/CustomSuggester.js +2 -2
  27. package/esm/components/Suggester/CustomSuggester.js.map +1 -1
  28. package/esm/components/Suggester/CustomSuggester.spec.d.ts +1 -0
  29. package/esm/components/Suggester/CustomSuggester.spec.js +30 -0
  30. package/esm/components/Suggester/CustomSuggester.spec.js.map +1 -0
  31. package/esm/components/Suggester/Suggester.d.ts +1 -1
  32. package/esm/components/Suggester/Suggester.js +2 -2
  33. package/esm/components/Suggester/Suggester.js.map +1 -1
  34. package/esm/components/shared/Combobox/Combobox.js +2 -2
  35. package/esm/components/shared/Combobox/Combobox.js.map +1 -1
  36. package/esm/components/shared/Combobox/ComboboxType.d.ts +1 -0
  37. package/esm/components/shared/Combobox/Selection/ComboboxInput.d.ts +1 -0
  38. package/esm/components/shared/Combobox/Selection/ComboboxInput.js +2 -2
  39. package/esm/components/shared/Combobox/Selection/ComboboxInput.js.map +1 -1
  40. package/esm/components/shared/Combobox/Selection/ComboboxSelection.d.ts +1 -1
  41. package/esm/components/shared/Combobox/Selection/ComboboxSelection.js +3 -3
  42. package/esm/components/shared/Combobox/Selection/ComboboxSelection.js.map +1 -1
  43. package/esm/hooks/useMultimode.js +21 -10
  44. package/esm/hooks/useMultimode.js.map +1 -1
  45. package/esm/use-lunatic/commons/compile-controls.d.ts +5 -0
  46. package/esm/use-lunatic/commons/compile-controls.js +6 -1
  47. package/esm/use-lunatic/commons/compile-controls.js.map +1 -1
  48. package/esm/use-lunatic/commons/compile-controls.spec.d.ts +1 -0
  49. package/esm/use-lunatic/commons/compile-controls.spec.js +121 -0
  50. package/esm/use-lunatic/commons/compile-controls.spec.js.map +1 -0
  51. package/esm/utils/getArticulationState.js +12 -6
  52. package/esm/utils/getArticulationState.js.map +1 -1
  53. package/hooks/useMultimode.js +20 -8
  54. package/hooks/useMultimode.js.map +1 -1
  55. package/package.json +21 -3
  56. package/src/components/Dropdown/__snapshots__/Dropdown.spec.tsx.snap +0 -2
  57. package/src/components/Duration/getDurationFromValue.ts +10 -6
  58. package/src/components/Suggester/CustomSuggester.spec.tsx +32 -0
  59. package/src/components/Suggester/CustomSuggester.tsx +3 -0
  60. package/src/components/Suggester/Suggester.tsx +2 -0
  61. package/src/components/shared/Combobox/Combobox.tsx +2 -0
  62. package/src/components/shared/Combobox/ComboboxType.ts +1 -0
  63. package/src/components/shared/Combobox/Selection/ComboboxInput.tsx +4 -0
  64. package/src/components/shared/Combobox/Selection/ComboboxSelection.tsx +3 -2
  65. package/src/components/shared/Combobox/Selection/__snapshots__/ComboboxSelection.spec.tsx.snap +0 -4
  66. package/src/hooks/useMultimode.ts +27 -13
  67. package/src/stories/questionnaires/SRCV/data.json +116 -0
  68. package/src/stories/questionnaires/SRCV/source.json +69256 -0
  69. package/src/stories/questionnaires/SRCV/srcv.stories.tsx +23 -0
  70. package/src/use-lunatic/commons/compile-controls.spec.ts +136 -0
  71. package/src/use-lunatic/commons/compile-controls.ts +7 -1
  72. package/src/utils/getArticulationState.ts +16 -8
  73. package/tsconfig.build.tsbuildinfo +1 -1
  74. package/use-lunatic/commons/compile-controls.d.ts +5 -0
  75. package/use-lunatic/commons/compile-controls.js +6 -0
  76. package/use-lunatic/commons/compile-controls.js.map +1 -1
  77. package/use-lunatic/commons/compile-controls.spec.d.ts +1 -0
  78. package/use-lunatic/commons/compile-controls.spec.js +123 -0
  79. package/use-lunatic/commons/compile-controls.spec.js.map +1 -0
  80. package/utils/getArticulationState.js +12 -6
  81. package/utils/getArticulationState.js.map +1 -1
@@ -35,6 +35,7 @@ export function WrappedSuggester({
35
35
  iteration,
36
36
  arbitrary,
37
37
  arbitraryValue,
38
+ required,
38
39
  }: LunaticComponentProps<'Suggester'>) {
39
40
  const { store, storeState, setStoreState, getLabelById } = useStore({
40
41
  storeName,
@@ -182,6 +183,7 @@ export function WrappedSuggester({
182
183
  onClear={handleClear}
183
184
  disabled={disabled}
184
185
  readOnly={readOnly}
186
+ required={required}
185
187
  value={selectedOptions}
186
188
  label={label}
187
189
  onBlur={onBlur}
@@ -68,6 +68,7 @@ function LunaticComboBox({
68
68
  onBlur,
69
69
  onFocus,
70
70
  isLoading,
71
+ required,
71
72
  }: Props) {
72
73
  const [expanded, setExpanded] = useState(false);
73
74
  const [focused, setFocused] = useState(false);
@@ -180,6 +181,7 @@ function LunaticComboBox({
180
181
  onChange={handleChange}
181
182
  classNamePrefix={classNamePrefix}
182
183
  invalid={!!errors}
184
+ required={required}
183
185
  />
184
186
  <ComboboxPanel
185
187
  isLoading={isLoading}
@@ -32,6 +32,7 @@ export type ComboboxSelectionProps = {
32
32
  options: Array<ComboboxOptionType>;
33
33
  search?: string;
34
34
  disabled?: boolean;
35
+ required?: boolean;
35
36
  };
36
37
 
37
38
  export type ComboboxPanelProps = {
@@ -15,6 +15,7 @@ export type InputProps = {
15
15
  focused?: boolean;
16
16
  invalid?: boolean;
17
17
  readOnly?: boolean;
18
+ required?: boolean;
18
19
  } & HTMLAttributes<HTMLInputElement>;
19
20
 
20
21
  function LunaticComboboxInput({
@@ -27,6 +28,7 @@ function LunaticComboboxInput({
27
28
  focused,
28
29
  className,
29
30
  invalid,
31
+ required,
30
32
  }: InputProps) {
31
33
  const inputEl = useRef<HTMLInputElement>(null);
32
34
 
@@ -52,6 +54,8 @@ function LunaticComboboxInput({
52
54
  onChange={onChange}
53
55
  value={value}
54
56
  aria-invalid={invalid}
57
+ aria-required={required}
58
+ required={required}
55
59
  title="combo-box"
56
60
  autoComplete="off"
57
61
  autoCapitalize="off"
@@ -24,10 +24,11 @@ export function ComboboxSelection({
24
24
  id,
25
25
  classNamePrefix,
26
26
  invalid,
27
+ required,
27
28
  }: ComboboxSelectionProps) {
28
29
  const showLabel = !editable || !expanded;
29
30
  const selectedOption =
30
- selectedIndex !== undefined ? options[selectedIndex] : undefined;
31
+ selectedIndex === undefined ? undefined : options[selectedIndex];
31
32
  const LabelSelectionComponent = labelRenderer ?? ComboboxLabelSelection;
32
33
 
33
34
  return (
@@ -41,7 +42,6 @@ export function ComboboxSelection({
41
42
  }
42
43
  )}
43
44
  role="combobox"
44
- aria-controls={'todo'}
45
45
  aria-haspopup="listbox"
46
46
  aria-expanded={expanded}
47
47
  aria-autocomplete="list"
@@ -70,6 +70,7 @@ export function ComboboxSelection({
70
70
  readOnly={readOnly}
71
71
  focused={focused}
72
72
  labelledBy={labelId}
73
+ required={required}
73
74
  />
74
75
  )}
75
76
  </div>
@@ -3,7 +3,6 @@
3
3
  exports[`Selection component > should render correctly when it is disabled 1`] = `
4
4
  <div
5
5
  aria-autocomplete="list"
6
- aria-controls="todo"
7
6
  aria-haspopup="listbox"
8
7
  class="lunatic-combo-box-selection disabled"
9
8
  role="combobox"
@@ -23,7 +22,6 @@ exports[`Selection component > should render correctly when it is disabled 1`] =
23
22
  exports[`Selection component > should render correctly when it is editable 1`] = `
24
23
  <div
25
24
  aria-autocomplete="list"
26
- aria-controls="todo"
27
25
  aria-haspopup="listbox"
28
26
  class="lunatic-combo-box-selection"
29
27
  role="combobox"
@@ -41,7 +39,6 @@ exports[`Selection component > should render correctly when it is editable 1`] =
41
39
  exports[`Selection component > should render correctly when it is expanded 1`] = `
42
40
  <div
43
41
  aria-autocomplete="list"
44
- aria-controls="todo"
45
42
  aria-expanded="true"
46
43
  aria-haspopup="listbox"
47
44
  class="lunatic-combo-box-selection"
@@ -60,7 +57,6 @@ exports[`Selection component > should render correctly when it is expanded 1`] =
60
57
  exports[`Selection component > should render correctly with default props 1`] = `
61
58
  <div
62
59
  aria-autocomplete="list"
63
- aria-controls="todo"
64
60
  aria-haspopup="listbox"
65
61
  class="lunatic-combo-box-selection"
66
62
  role="combobox"
@@ -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
+ }