@inseefr/lunatic 3.5.5 → 3.5.6

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 (47) hide show
  1. package/components/Duration/durationUtils.js +1 -1
  2. package/components/Duration/durationUtils.js.map +1 -1
  3. package/components/Sequence/Sequence.d.ts +1 -1
  4. package/components/Subsequence/Subsequence.d.ts +1 -1
  5. package/components/library.d.ts +2 -2
  6. package/components/type.d.ts +4 -3
  7. package/esm/components/Duration/durationUtils.js +1 -1
  8. package/esm/components/Duration/durationUtils.js.map +1 -1
  9. package/esm/components/Sequence/Sequence.d.ts +1 -1
  10. package/esm/components/Subsequence/Subsequence.d.ts +1 -1
  11. package/esm/components/library.d.ts +2 -2
  12. package/esm/components/type.d.ts +4 -3
  13. package/esm/use-lunatic/commons/fill-components/fill-component.spec.js +105 -0
  14. package/esm/use-lunatic/commons/fill-components/fill-component.spec.js.map +1 -1
  15. package/esm/use-lunatic/commons/fill-components/fill-components.d.ts +3 -2
  16. package/esm/use-lunatic/commons/fill-components/fill-components.js +12 -4
  17. package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  18. package/esm/use-lunatic/props/getComponentTypeProps.d.ts +3 -3
  19. package/esm/use-lunatic/props/getComponentTypeProps.js +1 -1
  20. package/esm/use-lunatic/props/getComponentTypeProps.js.map +1 -1
  21. package/esm/use-lunatic/props/propOptions.d.ts +3 -1
  22. package/esm/use-lunatic/props/propOptions.js +22 -24
  23. package/esm/use-lunatic/props/propOptions.js.map +1 -1
  24. package/esm/use-lunatic/props/propOptions.spec.js +46 -0
  25. package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/components/Duration/durationUtils.ts +1 -1
  28. package/src/components/type.ts +9 -2
  29. package/src/use-lunatic/commons/fill-components/fill-component.spec.ts +126 -0
  30. package/src/use-lunatic/commons/fill-components/fill-components.ts +19 -4
  31. package/src/use-lunatic/props/getComponentTypeProps.ts +6 -1
  32. package/src/use-lunatic/props/propOptions.spec.ts +64 -0
  33. package/src/use-lunatic/props/propOptions.ts +50 -22
  34. package/tsconfig.build.tsbuildinfo +1 -1
  35. package/use-lunatic/commons/fill-components/fill-component.spec.js +105 -0
  36. package/use-lunatic/commons/fill-components/fill-component.spec.js.map +1 -1
  37. package/use-lunatic/commons/fill-components/fill-components.d.ts +3 -2
  38. package/use-lunatic/commons/fill-components/fill-components.js +12 -4
  39. package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  40. package/use-lunatic/props/getComponentTypeProps.d.ts +3 -3
  41. package/use-lunatic/props/getComponentTypeProps.js +1 -1
  42. package/use-lunatic/props/getComponentTypeProps.js.map +1 -1
  43. package/use-lunatic/props/propOptions.d.ts +3 -1
  44. package/use-lunatic/props/propOptions.js +22 -24
  45. package/use-lunatic/props/propOptions.js.map +1 -1
  46. package/use-lunatic/props/propOptions.spec.js +46 -0
  47. package/use-lunatic/props/propOptions.spec.js.map +1 -1
@@ -8,6 +8,7 @@ import type { DeepTranslateExpression } from '../commons/fill-components/fill-co
8
8
  import { isNumber } from '../../utils/number';
9
9
  import type { LunaticVariablesStore } from '../commons/variables/lunatic-variables-store';
10
10
  import { LunaticLogger } from '../logger/type';
11
+ import { VtlExpression } from '../../components/type';
11
12
 
12
13
  /* Used for radio option and checkbox one option */
13
14
  export type InterpretedOption = {
@@ -32,10 +33,10 @@ export function getOptionsProp(
32
33
  pagerIteration: LunaticState['pager']['iteration'],
33
34
  value: unknown,
34
35
  logger: LunaticLogger,
35
- disableFilters?: boolean
36
+ disableFilters?: boolean,
37
+ shouldParentBeFiltered?: boolean
36
38
  ) {
37
39
  const iteration = isNumber(pagerIteration) ? [pagerIteration] : undefined;
38
- //const iteration = pagerIteration ? [pagerIteration] : undefined;
39
40
 
40
41
  if (definition.componentType === 'CheckboxGroup') {
41
42
  return definition.responses
@@ -43,16 +44,12 @@ export function getOptionsProp(
43
44
  if (disableFilters || !response.conditionFilter) {
44
45
  return true;
45
46
  }
46
- try {
47
- return variables.run(response.conditionFilter.value, { iteration });
48
- } catch (e) {
49
- // If there is an error interpreting a variable, we do not filter
50
- logger({
51
- type: 'ERROR',
52
- error: e as Error,
53
- });
54
- return true;
55
- }
47
+ return !isFilteredOutOption(
48
+ variables,
49
+ iteration,
50
+ logger,
51
+ response.conditionFilter
52
+ );
56
53
  })
57
54
  .map((response) => ({
58
55
  label: response.label,
@@ -74,6 +71,14 @@ export function getOptionsProp(
74
71
  ]);
75
72
  }
76
73
  : undefined,
74
+ shouldBeFiltered:
75
+ shouldParentBeFiltered ||
76
+ isFilteredOutOption(
77
+ variables,
78
+ iteration,
79
+ logger,
80
+ response.conditionFilter
81
+ ),
77
82
  }));
78
83
  }
79
84
 
@@ -90,16 +95,12 @@ export function getOptionsProp(
90
95
  ) {
91
96
  return true;
92
97
  }
93
- try {
94
- return variables.run(option.conditionFilter.value, { iteration });
95
- } catch (e) {
96
- // If there is an error interpreting a variable, we do not filter
97
- logger({
98
- type: 'ERROR',
99
- error: e as Error,
100
- });
101
- return true;
102
- }
98
+ return !isFilteredOutOption(
99
+ variables,
100
+ iteration,
101
+ logger,
102
+ option.conditionFilter
103
+ );
103
104
  })
104
105
  .map((option) => ({
105
106
  label: option.label,
@@ -126,5 +127,32 @@ export function getOptionsProp(
126
127
  handleChanges([{ name: option.detail!.response.name, value }]);
127
128
  }
128
129
  : null,
130
+ shouldBeFiltered:
131
+ shouldParentBeFiltered ||
132
+ ('conditionFilter' in option &&
133
+ isFilteredOutOption(
134
+ variables,
135
+ iteration,
136
+ logger,
137
+ option.conditionFilter
138
+ )),
129
139
  }));
130
140
  }
141
+
142
+ /**
143
+ * Check if an option should be filtered, depending on its conditionFilter.
144
+ */
145
+ function isFilteredOutOption(
146
+ variables: LunaticVariablesStore,
147
+ iteration: number[] | undefined,
148
+ logger: LunaticLogger,
149
+ conditionFilter?: VtlExpression
150
+ ): boolean {
151
+ if (!conditionFilter) return false;
152
+ try {
153
+ return !variables.run(conditionFilter.value, { iteration });
154
+ } catch (e) {
155
+ logger({ type: 'ERROR', error: e as Error });
156
+ return false;
157
+ }
158
+ }