@inseefr/lunatic 3.5.5 → 3.5.7
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/CheckboxOne/CheckboxOne.spec.js +3 -2
- package/components/CheckboxOne/CheckboxOne.spec.js.map +1 -1
- 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 +7 -3
- package/esm/components/CheckboxOne/CheckboxOne.spec.js +3 -2
- package/esm/components/CheckboxOne/CheckboxOne.spec.js.map +1 -1
- 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 +7 -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 +6 -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/CheckboxOne/CheckboxOne.spec.tsx +3 -0
- package/src/components/Duration/durationUtils.ts +1 -1
- package/src/components/type.ts +10 -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 +6 -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
|
@@ -208,6 +208,7 @@ describe('getOptionsProp()', () => {
|
|
|
208
208
|
|
|
209
209
|
// Ensure the option is not filtered
|
|
210
210
|
expect(options).toHaveLength(1);
|
|
211
|
+
expect(options[0].shouldBeFiltered).toBe(false);
|
|
211
212
|
});
|
|
212
213
|
it('should not filter option (radio) when its conditionFilter evaluation fails', () => {
|
|
213
214
|
const definition = {
|
|
@@ -237,6 +238,7 @@ describe('getOptionsProp()', () => {
|
|
|
237
238
|
|
|
238
239
|
// Ensure the option is not filtered
|
|
239
240
|
expect(options).toHaveLength(1);
|
|
241
|
+
expect(options[0].shouldBeFiltered).toBe(false);
|
|
240
242
|
});
|
|
241
243
|
it('should not filter any response (CheckboxGroup) when disableFilters is true', () => {
|
|
242
244
|
const definition = {
|
|
@@ -268,6 +270,8 @@ describe('getOptionsProp()', () => {
|
|
|
268
270
|
|
|
269
271
|
// Ensure the option is not filtered
|
|
270
272
|
expect(options).toHaveLength(1);
|
|
273
|
+
// the option should would have been filtered if we did not disable filters
|
|
274
|
+
expect(options[0].shouldBeFiltered).toBe(true);
|
|
271
275
|
});
|
|
272
276
|
it('should not filter any option (Radio) when disableFilters is true', () => {
|
|
273
277
|
const definition = {
|
|
@@ -296,7 +300,67 @@ describe('getOptionsProp()', () => {
|
|
|
296
300
|
true // disableFilters = true
|
|
297
301
|
);
|
|
298
302
|
|
|
303
|
+
// Ensure the option is not filtered
|
|
304
|
+
expect(options).toHaveLength(1);
|
|
305
|
+
// the option should would have been filtered if we did not disable filters
|
|
306
|
+
expect(options[0].shouldBeFiltered).toBe(true);
|
|
307
|
+
});
|
|
308
|
+
it('should set the response (CheckboxGroup) shouldBeFiltered=true when the parent component should be filtered', () => {
|
|
309
|
+
const definition = {
|
|
310
|
+
...checkboxGroupDefinition,
|
|
311
|
+
responses: [
|
|
312
|
+
{
|
|
313
|
+
label: 'Option 1',
|
|
314
|
+
response: { name: 'O1' },
|
|
315
|
+
id: 'id1',
|
|
316
|
+
conditionFilter: { type: 'VTL', value: 'expression' },
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
320
|
+
|
|
321
|
+
const options = getOptionsProp(
|
|
322
|
+
definition,
|
|
323
|
+
variables,
|
|
324
|
+
mockChange,
|
|
325
|
+
undefined,
|
|
326
|
+
undefined,
|
|
327
|
+
mockLogger,
|
|
328
|
+
true, // disableFilters = true
|
|
329
|
+
true // parent component should be filtered
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
// Ensure the option is not filtered
|
|
333
|
+
expect(options).toHaveLength(1);
|
|
334
|
+
// the option would have been filtered if we did not disable filters because its parent would
|
|
335
|
+
expect(options[0].shouldBeFiltered).toBe(true);
|
|
336
|
+
});
|
|
337
|
+
it('should set the option (Radio) shouldBeFiltered=true when the parent component should be filtered', () => {
|
|
338
|
+
const definition = {
|
|
339
|
+
...radioDefinition,
|
|
340
|
+
options: [
|
|
341
|
+
{
|
|
342
|
+
label: 'Option 1',
|
|
343
|
+
value: 'id1',
|
|
344
|
+
conditionFilter: { type: 'VTL', value: 'expression' },
|
|
345
|
+
},
|
|
346
|
+
],
|
|
347
|
+
} as any as DeepTranslateExpression<LunaticComponentDefinition>;
|
|
348
|
+
|
|
349
|
+
const options = getOptionsProp(
|
|
350
|
+
definition,
|
|
351
|
+
variables,
|
|
352
|
+
mockChange,
|
|
353
|
+
undefined,
|
|
354
|
+
undefined,
|
|
355
|
+
mockLogger,
|
|
356
|
+
true, // disableFilters = true
|
|
357
|
+
true // parent component should be filtered
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
// Ensure the option is not filtered
|
|
299
361
|
expect(options).toHaveLength(1);
|
|
362
|
+
// the option would have been filtered if we did not disable filters because its parent would
|
|
363
|
+
expect(options[0].shouldBeFiltered).toBe(true);
|
|
300
364
|
});
|
|
301
365
|
});
|
|
302
366
|
});
|
|
@@ -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
|
+
}
|