@inseefr/lunatic 3.5.1 → 3.5.3

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 (88) hide show
  1. package/components/FilterDescription/FilterDescription.d.ts +5 -7
  2. package/components/FilterDescription/FilterDescription.js +10 -3
  3. package/components/FilterDescription/FilterDescription.js.map +1 -1
  4. package/components/InputNumber/InputNumber.js +2 -2
  5. package/components/InputNumber/InputNumber.js.map +1 -1
  6. package/components/InputNumber/InputNumberThousand.d.ts +2 -1
  7. package/components/InputNumber/InputNumberThousand.js +14 -6
  8. package/components/InputNumber/InputNumberThousand.js.map +1 -1
  9. package/components/library.d.ts +2 -4
  10. package/components/shared/HOC/slottableComponent.d.ts +2 -0
  11. package/components/shared/HOC/slottableComponent.js.map +1 -1
  12. package/esm/components/FilterDescription/FilterDescription.d.ts +5 -7
  13. package/esm/components/FilterDescription/FilterDescription.js +8 -1
  14. package/esm/components/FilterDescription/FilterDescription.js.map +1 -1
  15. package/esm/components/InputNumber/InputNumber.js +2 -2
  16. package/esm/components/InputNumber/InputNumber.js.map +1 -1
  17. package/esm/components/InputNumber/InputNumberThousand.d.ts +2 -1
  18. package/esm/components/InputNumber/InputNumberThousand.js +14 -6
  19. package/esm/components/InputNumber/InputNumberThousand.js.map +1 -1
  20. package/esm/components/library.d.ts +2 -4
  21. package/esm/components/shared/HOC/slottableComponent.d.ts +2 -0
  22. package/esm/components/shared/HOC/slottableComponent.js.map +1 -1
  23. package/esm/type.source.d.ts +5 -1
  24. package/esm/use-lunatic/commons/fill-components/fill-component.spec.d.ts +1 -0
  25. package/esm/use-lunatic/commons/fill-components/fill-component.spec.js +485 -0
  26. package/esm/use-lunatic/commons/fill-components/fill-component.spec.js.map +1 -0
  27. package/esm/use-lunatic/commons/fill-components/fill-components.d.ts +3 -3
  28. package/esm/use-lunatic/commons/fill-components/fill-components.js +29 -5
  29. package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  30. package/esm/use-lunatic/props/getComponentTypeProps.d.ts +4 -4
  31. package/esm/use-lunatic/props/getComponentTypeProps.js +1 -1
  32. package/esm/use-lunatic/props/getComponentTypeProps.js.map +1 -1
  33. package/esm/use-lunatic/props/propOptions.d.ts +1 -1
  34. package/esm/use-lunatic/props/propOptions.js +5 -3
  35. package/esm/use-lunatic/props/propOptions.js.map +1 -1
  36. package/esm/use-lunatic/props/propOptions.spec.js +100 -2
  37. package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
  38. package/esm/use-lunatic/reducer/reducerInitializer.d.ts +2 -1
  39. package/esm/use-lunatic/reducer/reducerInitializer.js +3 -3
  40. package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
  41. package/esm/use-lunatic/replace-component-sequence.d.ts +1 -1
  42. package/esm/use-lunatic/type.d.ts +3 -0
  43. package/esm/use-lunatic/use-lunatic.js +3 -1
  44. package/esm/use-lunatic/use-lunatic.js.map +1 -1
  45. package/package.json +8 -2
  46. package/src/components/FilterDescription/FilterDescription.tsx +24 -13
  47. package/src/components/InputNumber/InputNumber.tsx +2 -0
  48. package/src/components/InputNumber/InputNumberThousand.tsx +13 -5
  49. package/src/components/shared/HOC/slottableComponent.tsx +2 -0
  50. package/src/stories/behaviour/paste/test.stories.jsx +5 -0
  51. package/src/stories/filter-description/filter-description.stories.jsx +7 -3
  52. package/src/stories/loop/roster-for-loop.stories.jsx +1 -4
  53. package/src/stories/loop/source-roster.json +65 -2
  54. package/src/stories/utils/default-arg-types.js +1 -1
  55. package/src/stories/utils/orchestrator.jsx +3 -3
  56. package/src/type.source.ts +6 -1
  57. package/src/use-lunatic/commons/fill-components/fill-component.spec.ts +581 -0
  58. package/src/use-lunatic/commons/fill-components/fill-components.ts +39 -7
  59. package/src/use-lunatic/props/getComponentTypeProps.ts +15 -11
  60. package/src/use-lunatic/props/propOptions.spec.ts +140 -2
  61. package/src/use-lunatic/props/propOptions.ts +8 -3
  62. package/src/use-lunatic/reducer/reducerInitializer.tsx +4 -2
  63. package/src/use-lunatic/type.ts +5 -0
  64. package/src/use-lunatic/use-lunatic.ts +3 -0
  65. package/tsconfig.build.tsbuildinfo +1 -1
  66. package/type.source.d.ts +5 -1
  67. package/use-lunatic/commons/fill-components/fill-component.spec.d.ts +1 -0
  68. package/use-lunatic/commons/fill-components/fill-component.spec.js +487 -0
  69. package/use-lunatic/commons/fill-components/fill-component.spec.js.map +1 -0
  70. package/use-lunatic/commons/fill-components/fill-components.d.ts +3 -3
  71. package/use-lunatic/commons/fill-components/fill-components.js +26 -5
  72. package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  73. package/use-lunatic/props/getComponentTypeProps.d.ts +4 -4
  74. package/use-lunatic/props/getComponentTypeProps.js +1 -1
  75. package/use-lunatic/props/getComponentTypeProps.js.map +1 -1
  76. package/use-lunatic/props/propOptions.d.ts +1 -1
  77. package/use-lunatic/props/propOptions.js +5 -3
  78. package/use-lunatic/props/propOptions.js.map +1 -1
  79. package/use-lunatic/props/propOptions.spec.js +100 -2
  80. package/use-lunatic/props/propOptions.spec.js.map +1 -1
  81. package/use-lunatic/reducer/reducerInitializer.d.ts +2 -1
  82. package/use-lunatic/reducer/reducerInitializer.js +3 -3
  83. package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
  84. package/use-lunatic/replace-component-sequence.d.ts +1 -1
  85. package/use-lunatic/type.d.ts +3 -0
  86. package/use-lunatic/use-lunatic.js +3 -1
  87. package/use-lunatic/use-lunatic.js.map +1 -1
  88. package/src/stories/loop/source-with-header.json +0 -128
@@ -25,6 +25,23 @@ describe('getOptionsProp()', () => {
25
25
  },
26
26
  ],
27
27
  } satisfies DeepTranslateExpression<LunaticComponentDefinition>;
28
+
29
+ const radioDefinition = {
30
+ id: 'RadioGroup',
31
+ componentType: 'Radio',
32
+ response: { name: 'RADIO' },
33
+ options: [
34
+ {
35
+ label: 'Option 1',
36
+ value: 'id1',
37
+ },
38
+ {
39
+ label: 'Option 2',
40
+ value: 'id2',
41
+ },
42
+ ],
43
+ } satisfies DeepTranslateExpression<LunaticComponentDefinition>;
44
+
28
45
  let mockChange: LunaticChangesHandler;
29
46
  const mockLogger = vi.fn();
30
47
 
@@ -100,6 +117,68 @@ describe('getOptionsProp()', () => {
100
117
  { name: 'O2', value: false },
101
118
  ]);
102
119
  });
120
+ it('should filter responses (CheckboxGroup) with conditionFilter evaluated to false', () => {
121
+ const definition = {
122
+ ...checkboxGroupDefinition,
123
+ responses: [
124
+ {
125
+ label: 'Option 1',
126
+ response: { name: 'O1' },
127
+ id: 'id1',
128
+ conditionFilter: { type: 'VTL', value: 'false' },
129
+ },
130
+ {
131
+ label: 'Option 2',
132
+ response: { name: 'O2' },
133
+ id: 'id2',
134
+ conditionFilter: { type: 'VTL', value: 'true' },
135
+ },
136
+ ],
137
+ } satisfies DeepTranslateExpression<LunaticComponentDefinition>;
138
+
139
+ const options = getOptionsProp(
140
+ definition,
141
+ variables,
142
+ mockChange,
143
+ undefined,
144
+ undefined,
145
+ mockLogger
146
+ );
147
+
148
+ // First option should be filtered out since its conditionFilter is evaluated to false
149
+ expect(options).toHaveLength(1);
150
+ expect(options[0].label).toBe('Option 2');
151
+ });
152
+ it('should filter options (Radio) with conditionFilter evaluated to false', () => {
153
+ const definition = {
154
+ ...radioDefinition,
155
+ options: [
156
+ {
157
+ label: 'Option 1',
158
+ value: 'id1',
159
+ conditionFilter: { type: 'VTL', value: 'false' },
160
+ },
161
+ {
162
+ label: 'Option 2',
163
+ value: 'id2',
164
+ conditionFilter: { type: 'VTL', value: 'true' },
165
+ },
166
+ ],
167
+ } as any as DeepTranslateExpression<LunaticComponentDefinition>;
168
+
169
+ const options = getOptionsProp(
170
+ definition,
171
+ variables,
172
+ mockChange,
173
+ undefined,
174
+ undefined,
175
+ mockLogger
176
+ );
177
+
178
+ // First option should be filtered out since its conditionFilter is evaluated to false
179
+ expect(options).toHaveLength(1);
180
+ expect(options[0].label).toBe('Option 2');
181
+ });
103
182
  it('should not filter response (checkboxGroup) when its conditionFilter evaluation fails', () => {
104
183
  const definition = {
105
184
  ...checkboxGroupDefinition,
@@ -132,8 +211,7 @@ describe('getOptionsProp()', () => {
132
211
  });
133
212
  it('should not filter option (radio) when its conditionFilter evaluation fails', () => {
134
213
  const definition = {
135
- id: 'RadioGroup',
136
- componentType: 'Radio',
214
+ ...radioDefinition,
137
215
  options: [
138
216
  {
139
217
  label: 'Option 1',
@@ -160,5 +238,65 @@ describe('getOptionsProp()', () => {
160
238
  // Ensure the option is not filtered
161
239
  expect(options).toHaveLength(1);
162
240
  });
241
+ it('should not filter any response (CheckboxGroup) when disableFilters is true', () => {
242
+ const definition = {
243
+ ...checkboxGroupDefinition,
244
+ responses: [
245
+ {
246
+ label: 'Option 1',
247
+ response: { name: 'O1' },
248
+ id: 'id1',
249
+ conditionFilter: { type: 'VTL', value: 'expression' },
250
+ },
251
+ ],
252
+ } satisfies DeepTranslateExpression<LunaticComponentDefinition>;
253
+
254
+ // ensure interpreted expression is false
255
+ vi.spyOn(variables, 'run').mockImplementation(() => {
256
+ return false;
257
+ });
258
+
259
+ const options = getOptionsProp(
260
+ definition,
261
+ variables,
262
+ mockChange,
263
+ undefined,
264
+ undefined,
265
+ mockLogger,
266
+ true // disableFilters = true
267
+ );
268
+
269
+ // Ensure the option is not filtered
270
+ expect(options).toHaveLength(1);
271
+ });
272
+ it('should not filter any option (Radio) when disableFilters is true', () => {
273
+ const definition = {
274
+ ...radioDefinition,
275
+ options: [
276
+ {
277
+ label: 'Option 1',
278
+ value: 'id1',
279
+ conditionFilter: { type: 'VTL', value: 'expression' },
280
+ },
281
+ ],
282
+ } as any as DeepTranslateExpression<LunaticComponentDefinition>;
283
+
284
+ // ensure interpreted expression is false
285
+ vi.spyOn(variables, 'run').mockImplementation(() => {
286
+ return false;
287
+ });
288
+
289
+ const options = getOptionsProp(
290
+ definition,
291
+ variables,
292
+ mockChange,
293
+ undefined,
294
+ undefined,
295
+ mockLogger,
296
+ true // disableFilters = true
297
+ );
298
+
299
+ expect(options).toHaveLength(1);
300
+ });
163
301
  });
164
302
  });
@@ -31,7 +31,8 @@ export function getOptionsProp(
31
31
  handleChanges: LunaticChangesHandler,
32
32
  pagerIteration: LunaticState['pager']['iteration'],
33
33
  value: unknown,
34
- logger: LunaticLogger
34
+ logger: LunaticLogger,
35
+ disableFilters?: boolean
35
36
  ) {
36
37
  const iteration = isNumber(pagerIteration) ? [pagerIteration] : undefined;
37
38
  //const iteration = pagerIteration ? [pagerIteration] : undefined;
@@ -39,7 +40,7 @@ export function getOptionsProp(
39
40
  if (definition.componentType === 'CheckboxGroup') {
40
41
  return definition.responses
41
42
  .filter((response) => {
42
- if (!response.conditionFilter) {
43
+ if (disableFilters || !response.conditionFilter) {
43
44
  return true;
44
45
  }
45
46
  try {
@@ -82,7 +83,11 @@ export function getOptionsProp(
82
83
 
83
84
  return definition.options
84
85
  .filter((option) => {
85
- if (!('conditionFilter' in option) || !option.conditionFilter) {
86
+ if (
87
+ disableFilters ||
88
+ !('conditionFilter' in option) ||
89
+ !option.conditionFilter
90
+ ) {
86
91
  return true;
87
92
  }
88
93
  try {
@@ -35,7 +35,7 @@ const baseState = {
35
35
  overview: [],
36
36
  updateBindings: () => {},
37
37
  executeExpression: <T,>() => null as T,
38
- options: { disableFilters: false },
38
+ options: { disableFilters: false, disableFiltersDescription: true },
39
39
  } satisfies LunaticReducerState;
40
40
 
41
41
  export function reducerInitializer({
@@ -46,6 +46,7 @@ export function reducerInitializer({
46
46
  lastReachedPage = undefined,
47
47
  withOverview = false,
48
48
  disableFilters = false,
49
+ disableFiltersDescription = true,
49
50
  getReferentiel,
50
51
  onVariableChange,
51
52
  logger,
@@ -57,6 +58,7 @@ export function reducerInitializer({
57
58
  lastReachedPage?: LunaticOptions['lastReachedPage'];
58
59
  withOverview?: LunaticOptions['withOverview'];
59
60
  disableFilters?: LunaticOptions['disableFilters'];
61
+ disableFiltersDescription?: LunaticOptions['disableFiltersDescription'];
60
62
  getReferentiel?: LunaticOptions['getReferentiel'];
61
63
  onVariableChange: RefObject<LunaticOptions['onVariableChange']>;
62
64
  logger: LunaticLogger;
@@ -149,7 +151,7 @@ export function reducerInitializer({
149
151
  overview: withOverview ? buildOverview(source) : [],
150
152
  updateBindings,
151
153
  executeExpression,
152
- options: { disableFilters },
154
+ options: { disableFilters, disableFiltersDescription },
153
155
  });
154
156
  }
155
157
 
@@ -179,6 +179,7 @@ export type LunaticReducerState = {
179
179
  ) => unknown;
180
180
  options: {
181
181
  disableFilters?: boolean;
182
+ disableFiltersDescription?: boolean;
182
183
  };
183
184
  };
184
185
 
@@ -186,6 +187,10 @@ export type LunaticReducerState = {
186
187
  export type LunaticOptions = {
187
188
  /** Ignore filters. (default: `false`) */
188
189
  disableFilters?: boolean;
190
+
191
+ /** Disable filters description. (default: `true`) */
192
+ disableFiltersDescription?: boolean;
193
+
189
194
  /** Enable VTL and Markdown support. */
190
195
  features?: ('MD' | 'VTL')[];
191
196
  preferences?: ['COLLECTED'];
@@ -44,6 +44,7 @@ const DEFAULT_REFUSED = D.RF;
44
44
 
45
45
  const defaultOptions = {
46
46
  disableFilters: false,
47
+ disableFiltersDescription: true,
47
48
  features: DEFAULT_FEATURES,
48
49
  preferences: DEFAULT_PREFERENCES,
49
50
  savingType: COLLECTED,
@@ -83,6 +84,7 @@ export function useLunatic(
83
84
  const options = mergeDefault(argOptions, defaultOptions);
84
85
  const {
85
86
  disableFilters,
87
+ disableFiltersDescription,
86
88
  management,
87
89
  missing,
88
90
  missingStrategy,
@@ -198,6 +200,7 @@ export function useLunatic(
198
200
 
199
201
  const components = fillComponents(getComponentsFromState(state), {
200
202
  disableFilters,
203
+ disableFiltersDescription,
201
204
  handleChanges,
202
205
  preferences,
203
206
  goToPage,