@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.
- package/components/Duration/durationUtils.js +1 -1
- package/components/Duration/durationUtils.js.map +1 -1
- package/components/Sequence/Sequence.d.ts +1 -1
- package/components/Subsequence/Subsequence.d.ts +1 -1
- package/components/library.d.ts +2 -2
- package/components/type.d.ts +4 -3
- package/esm/components/Duration/durationUtils.js +1 -1
- package/esm/components/Duration/durationUtils.js.map +1 -1
- package/esm/components/Sequence/Sequence.d.ts +1 -1
- package/esm/components/Subsequence/Subsequence.d.ts +1 -1
- package/esm/components/library.d.ts +2 -2
- package/esm/components/type.d.ts +4 -3
- package/esm/use-lunatic/commons/fill-components/fill-component.spec.js +105 -0
- package/esm/use-lunatic/commons/fill-components/fill-component.spec.js.map +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.d.ts +3 -2
- package/esm/use-lunatic/commons/fill-components/fill-components.js +12 -4
- package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/esm/use-lunatic/props/getComponentTypeProps.d.ts +3 -3
- package/esm/use-lunatic/props/getComponentTypeProps.js +1 -1
- package/esm/use-lunatic/props/getComponentTypeProps.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.d.ts +3 -1
- package/esm/use-lunatic/props/propOptions.js +22 -24
- package/esm/use-lunatic/props/propOptions.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.spec.js +46 -0
- package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Duration/durationUtils.ts +1 -1
- package/src/components/type.ts +9 -2
- package/src/use-lunatic/commons/fill-components/fill-component.spec.ts +126 -0
- package/src/use-lunatic/commons/fill-components/fill-components.ts +19 -4
- package/src/use-lunatic/props/getComponentTypeProps.ts +6 -1
- package/src/use-lunatic/props/propOptions.spec.ts +64 -0
- package/src/use-lunatic/props/propOptions.ts +50 -22
- package/tsconfig.build.tsbuildinfo +1 -1
- package/use-lunatic/commons/fill-components/fill-component.spec.js +105 -0
- package/use-lunatic/commons/fill-components/fill-component.spec.js.map +1 -1
- package/use-lunatic/commons/fill-components/fill-components.d.ts +3 -2
- package/use-lunatic/commons/fill-components/fill-components.js +12 -4
- package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/use-lunatic/props/getComponentTypeProps.d.ts +3 -3
- package/use-lunatic/props/getComponentTypeProps.js +1 -1
- package/use-lunatic/props/getComponentTypeProps.js.map +1 -1
- package/use-lunatic/props/propOptions.d.ts +3 -1
- package/use-lunatic/props/propOptions.js +22 -24
- package/use-lunatic/props/propOptions.js.map +1 -1
- package/use-lunatic/props/propOptions.spec.js +46 -0
- 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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
}
|