@inseefr/lunatic 3.11.2 → 3.12.0-rc.ucq-options-variable.0

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 (33) hide show
  1. package/esm/type.source.d.ts +17 -9
  2. package/esm/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
  3. package/esm/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
  4. package/esm/use-lunatic/commons/fill-components/fill-components.js +10 -2
  5. package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  6. package/esm/use-lunatic/props/propOptions.d.ts +9 -1
  7. package/esm/use-lunatic/props/propOptions.js +56 -1
  8. package/esm/use-lunatic/props/propOptions.js.map +1 -1
  9. package/esm/use-lunatic/props/propOptions.spec.js +220 -56
  10. package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
  11. package/package.json +4 -1
  12. package/src/stories/checkbox/checkbox.stories.tsx +13 -0
  13. package/src/stories/checkbox/sourceOneDynamicOptions.json +496 -0
  14. package/src/stories/dropdown/dropdown.stories.tsx +12 -0
  15. package/src/stories/dropdown/sourceDynamicOptions.json +496 -0
  16. package/src/stories/radio/radio.stories.tsx +13 -0
  17. package/src/stories/radio/sourceDynamicOptions.json +496 -0
  18. package/src/type.source.ts +19 -9
  19. package/src/use-lunatic/commons/fill-components/fill-component-expressions.ts +2 -1
  20. package/src/use-lunatic/commons/fill-components/fill-components.ts +9 -10
  21. package/src/use-lunatic/props/propOptions.spec.ts +217 -147
  22. package/src/use-lunatic/props/propOptions.ts +99 -10
  23. package/tsconfig.build.tsbuildinfo +1 -1
  24. package/type.source.d.ts +17 -9
  25. package/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
  26. package/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
  27. package/use-lunatic/commons/fill-components/fill-components.js +9 -1
  28. package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  29. package/use-lunatic/props/propOptions.d.ts +9 -1
  30. package/use-lunatic/props/propOptions.js +57 -2
  31. package/use-lunatic/props/propOptions.js.map +1 -1
  32. package/use-lunatic/props/propOptions.spec.js +217 -55
  33. package/use-lunatic/props/propOptions.spec.js.map +1 -1
@@ -0,0 +1,496 @@
1
+ {
2
+ "id": "mkb7cgp3",
3
+ "label": {
4
+ "type": "VTL|MD",
5
+ "value": "feat: QCU basé sur une variable - QR"
6
+ },
7
+ "modele": "FEATQCUBAS",
8
+ "maxPage": "7",
9
+ "cleaning": {},
10
+ "resizing": {
11
+ "NBHAB": {
12
+ "size": "NBHAB",
13
+ "variables": ["PRENOM", "AGE"]
14
+ },
15
+ "PRENOM": {
16
+ "size": "count(PRENOM)",
17
+ "variables": ["QCUDANSBOU"]
18
+ }
19
+ },
20
+ "variables": [
21
+ {
22
+ "name": "NBHAB",
23
+ "values": {
24
+ "COLLECTED": null
25
+ },
26
+ "dimension": 0,
27
+ "variableType": "COLLECTED"
28
+ },
29
+ {
30
+ "name": "PRENOM",
31
+ "values": {
32
+ "COLLECTED": []
33
+ },
34
+ "dimension": 1,
35
+ "variableType": "COLLECTED",
36
+ "iterationReference": "mkb798x7"
37
+ },
38
+ {
39
+ "name": "AGE",
40
+ "values": {
41
+ "COLLECTED": []
42
+ },
43
+ "dimension": 1,
44
+ "variableType": "COLLECTED",
45
+ "iterationReference": "mkb798x7"
46
+ },
47
+ {
48
+ "name": "QCUHORSBOU",
49
+ "values": {
50
+ "COLLECTED": null
51
+ },
52
+ "dimension": 0,
53
+ "variableType": "COLLECTED"
54
+ },
55
+ {
56
+ "name": "QCUDANSBOU",
57
+ "values": {
58
+ "COLLECTED": []
59
+ },
60
+ "dimension": 1,
61
+ "variableType": "COLLECTED",
62
+ "iterationReference": "mkb798x7"
63
+ },
64
+ {
65
+ "name": "FILTER_RESULT_NBHAB",
66
+ "dimension": 0,
67
+ "expression": {
68
+ "type": "VTL",
69
+ "value": "true"
70
+ },
71
+ "variableType": "CALCULATED",
72
+ "isIgnoredByLunatic": true
73
+ },
74
+ {
75
+ "name": "FILTER_RESULT_PRENOM",
76
+ "dimension": 1,
77
+ "shapeFrom": ["PRENOM", "AGE"],
78
+ "expression": {
79
+ "type": "VTL",
80
+ "value": "true"
81
+ },
82
+ "variableType": "CALCULATED",
83
+ "isIgnoredByLunatic": true,
84
+ "iterationReference": "mkb798x7"
85
+ },
86
+ {
87
+ "name": "FILTER_RESULT_AGE",
88
+ "dimension": 1,
89
+ "shapeFrom": ["PRENOM", "AGE"],
90
+ "expression": {
91
+ "type": "VTL",
92
+ "value": "true"
93
+ },
94
+ "variableType": "CALCULATED",
95
+ "isIgnoredByLunatic": true,
96
+ "iterationReference": "mkb798x7"
97
+ },
98
+ {
99
+ "name": "FILTER_RESULT_QCUHORSBOU",
100
+ "dimension": 0,
101
+ "expression": {
102
+ "type": "VTL",
103
+ "value": "true"
104
+ },
105
+ "variableType": "CALCULATED",
106
+ "isIgnoredByLunatic": true
107
+ },
108
+ {
109
+ "name": "FILTER_RESULT_QCUDANSBOU",
110
+ "dimension": 1,
111
+ "shapeFrom": ["PRENOM", "AGE"],
112
+ "expression": {
113
+ "type": "VTL",
114
+ "value": "true"
115
+ },
116
+ "variableType": "CALCULATED",
117
+ "isIgnoredByLunatic": true,
118
+ "iterationReference": "mkb798x7"
119
+ }
120
+ ],
121
+ "components": [
122
+ {
123
+ "id": "mkb6zd6d",
124
+ "page": "1",
125
+ "label": {
126
+ "type": "VTL",
127
+ "value": "\"I - \" || \"S1\""
128
+ },
129
+ "componentType": "Sequence",
130
+ "conditionFilter": {
131
+ "type": "VTL",
132
+ "value": "true"
133
+ }
134
+ },
135
+ {
136
+ "id": "question-mkb7hxy8",
137
+ "page": "2",
138
+ "label": {
139
+ "type": "VTL|MD",
140
+ "value": "\"Nombre d'habitants\""
141
+ },
142
+ "components": [
143
+ {
144
+ "id": "mkb7hxy8",
145
+ "max": 10.0,
146
+ "min": 0.0,
147
+ "page": "2",
148
+ "controls": [
149
+ {
150
+ "id": "mkb7hxy8-format-borne-inf-sup",
151
+ "type": "SIMPLE",
152
+ "control": {
153
+ "type": "VTL",
154
+ "value": "not(not(isnull(NBHAB)) and (0>NBHAB or 10<NBHAB))"
155
+ },
156
+ "criticality": "ERROR",
157
+ "errorMessage": {
158
+ "type": "VTL|MD",
159
+ "value": "\" La valeur doit être comprise entre 0 et 10\""
160
+ },
161
+ "typeOfControl": "FORMAT"
162
+ },
163
+ {
164
+ "id": "mkb7hxy8-format-decimal",
165
+ "type": "SIMPLE",
166
+ "control": {
167
+ "type": "VTL",
168
+ "value": "not(not(isnull(NBHAB)) and round(NBHAB,0)<>NBHAB)"
169
+ },
170
+ "criticality": "ERROR",
171
+ "errorMessage": {
172
+ "type": "VTL|MD",
173
+ "value": "\"Le nombre doit comporter au maximum 0 chiffre(s) après la virgule\""
174
+ },
175
+ "typeOfControl": "FORMAT"
176
+ }
177
+ ],
178
+ "decimals": 0,
179
+ "response": {
180
+ "name": "NBHAB"
181
+ },
182
+ "description": {
183
+ "type": "TXT",
184
+ "value": "Format attendu : un nombre entre 0 et 10"
185
+ },
186
+ "isMandatory": false,
187
+ "componentType": "InputNumber"
188
+ }
189
+ ],
190
+ "componentType": "Question",
191
+ "conditionFilter": {
192
+ "type": "VTL",
193
+ "value": "true"
194
+ }
195
+ },
196
+ {
197
+ "id": "mkb798x7",
198
+ "page": "3",
199
+ "depth": 1,
200
+ "lines": {
201
+ "max": {
202
+ "type": "VTL",
203
+ "value": "NBHAB"
204
+ },
205
+ "min": {
206
+ "type": "VTL",
207
+ "value": "NBHAB"
208
+ }
209
+ },
210
+ "components": [
211
+ {
212
+ "id": "mkb6z1pv",
213
+ "page": "3",
214
+ "label": {
215
+ "type": "VTL",
216
+ "value": "\"II - \" || \"THL\"",
217
+ "shapeFrom": "PRENOM"
218
+ },
219
+ "componentType": "Sequence",
220
+ "conditionFilter": {
221
+ "type": "VTL",
222
+ "value": "true",
223
+ "shapeFrom": "PRENOM"
224
+ }
225
+ },
226
+ {
227
+ "id": "question-mkb7180z",
228
+ "page": "3",
229
+ "label": {
230
+ "type": "VTL|MD",
231
+ "value": "\"Prénom\""
232
+ },
233
+ "components": [
234
+ {
235
+ "id": "mkb7180z",
236
+ "page": "3",
237
+ "response": {
238
+ "name": "PRENOM"
239
+ },
240
+ "maxLength": 249,
241
+ "isMandatory": false,
242
+ "componentType": "Input"
243
+ }
244
+ ],
245
+ "componentType": "Question",
246
+ "conditionFilter": {
247
+ "type": "VTL",
248
+ "value": "true"
249
+ }
250
+ },
251
+ {
252
+ "id": "question-mkb7gox2",
253
+ "page": "3",
254
+ "label": {
255
+ "type": "VTL|MD",
256
+ "value": "\"Âge\""
257
+ },
258
+ "components": [
259
+ {
260
+ "id": "mkb7gox2",
261
+ "max": 100.0,
262
+ "min": 0.0,
263
+ "page": "3",
264
+ "controls": [
265
+ {
266
+ "id": "mkb7gox2-format-borne-inf-sup",
267
+ "type": "SIMPLE",
268
+ "control": {
269
+ "type": "VTL",
270
+ "value": "not(not(isnull(AGE)) and (0>AGE or 100<AGE))"
271
+ },
272
+ "criticality": "ERROR",
273
+ "errorMessage": {
274
+ "type": "VTL|MD",
275
+ "value": "\" La valeur doit être comprise entre 0 et 100\""
276
+ },
277
+ "typeOfControl": "FORMAT"
278
+ },
279
+ {
280
+ "id": "mkb7gox2-format-decimal",
281
+ "type": "SIMPLE",
282
+ "control": {
283
+ "type": "VTL",
284
+ "value": "not(not(isnull(AGE)) and round(AGE,0)<>AGE)"
285
+ },
286
+ "criticality": "ERROR",
287
+ "errorMessage": {
288
+ "type": "VTL|MD",
289
+ "value": "\"Le nombre doit comporter au maximum 0 chiffre(s) après la virgule\""
290
+ },
291
+ "typeOfControl": "FORMAT"
292
+ }
293
+ ],
294
+ "decimals": 0,
295
+ "response": {
296
+ "name": "AGE"
297
+ },
298
+ "description": {
299
+ "type": "TXT",
300
+ "value": "Format attendu : un nombre entre 0 et 100"
301
+ },
302
+ "isMandatory": false,
303
+ "componentType": "InputNumber"
304
+ }
305
+ ],
306
+ "componentType": "Question",
307
+ "conditionFilter": {
308
+ "type": "VTL",
309
+ "value": "true"
310
+ }
311
+ }
312
+ ],
313
+ "componentType": "Loop",
314
+ "paginatedLoop": false,
315
+ "conditionFilter": {
316
+ "type": "VTL",
317
+ "value": "(true)"
318
+ },
319
+ "loopDependencies": ["NBHAB"],
320
+ "isPaginatedByIterations": false
321
+ },
322
+ {
323
+ "id": "mkb7ed5t",
324
+ "page": "4",
325
+ "label": {
326
+ "type": "VTL",
327
+ "value": "\"III - \" || \"S2\""
328
+ },
329
+ "componentType": "Sequence",
330
+ "conditionFilter": {
331
+ "type": "VTL",
332
+ "value": "true"
333
+ }
334
+ },
335
+ {
336
+ "id": "question-mkb7ktxx",
337
+ "page": "5",
338
+ "label": {
339
+ "type": "VTL|MD",
340
+ "value": "\"QCU hors boucle\""
341
+ },
342
+ "components": [
343
+ {
344
+ "id": "mkb7ktxx",
345
+ "page": "5",
346
+ "optionSource": "PRENOM",
347
+ "optionFilter": {
348
+ "type": "VTL",
349
+ "value": "AGE >= 18",
350
+ "shapeFrom": "PRENOM"
351
+ },
352
+ "response": {
353
+ "name": "QCUHORSBOU"
354
+ },
355
+ "isMandatory": false,
356
+ "orientation": "vertical",
357
+ "componentType": "Radio"
358
+ }
359
+ ],
360
+ "declarations": [
361
+ {
362
+ "id": "mke55sef",
363
+ "label": {
364
+ "type": "VTL|MD",
365
+ "value": "\"Les modalités de réponse sont les prénoms des individus ayant 18 ans ou plus\""
366
+ },
367
+ "position": "AFTER_QUESTION_TEXT",
368
+ "declarationType": "HELP"
369
+ }
370
+ ],
371
+ "componentType": "Question",
372
+ "conditionFilter": {
373
+ "type": "VTL",
374
+ "value": "true"
375
+ }
376
+ },
377
+ {
378
+ "id": "mkb71vg8",
379
+ "page": "6",
380
+ "depth": 1,
381
+ "maxPage": "2",
382
+ "components": [
383
+ {
384
+ "id": "mkb76y5x",
385
+ "page": "6.1",
386
+ "label": {
387
+ "type": "VTL",
388
+ "value": "\"IV - \" || \"S3\"",
389
+ "shapeFrom": "PRENOM"
390
+ },
391
+ "componentType": "Sequence",
392
+ "conditionFilter": {
393
+ "type": "VTL",
394
+ "value": "true",
395
+ "shapeFrom": "PRENOM"
396
+ }
397
+ },
398
+ {
399
+ "id": "question-mkb73lyz",
400
+ "page": "6.2",
401
+ "label": {
402
+ "type": "VTL|MD",
403
+ "value": "\"QCU dans boucle\""
404
+ },
405
+ "components": [
406
+ {
407
+ "id": "mkb73lyz",
408
+ "page": "6.2",
409
+ "optionSource": "PRENOM",
410
+ "optionFilter": {
411
+ "type": "VTL",
412
+ "value": "AGE >= 18",
413
+ "shapeFrom": "PRENOM"
414
+ },
415
+ "response": {
416
+ "name": "QCUDANSBOU"
417
+ },
418
+ "isMandatory": false,
419
+ "orientation": "vertical",
420
+ "componentType": "Radio"
421
+ }
422
+ ],
423
+ "declarations": [
424
+ {
425
+ "id": "mke5bdkv",
426
+ "label": {
427
+ "type": "VTL|MD",
428
+ "value": "\"Les modalités de réponse sont les prénoms des individus ayant 18 ans ou plus\""
429
+ },
430
+ "position": "AFTER_QUESTION_TEXT",
431
+ "declarationType": "HELP"
432
+ }
433
+ ],
434
+ "componentType": "Question",
435
+ "conditionFilter": {
436
+ "type": "VTL",
437
+ "value": "true"
438
+ }
439
+ }
440
+ ],
441
+ "iterations": {
442
+ "type": "VTL",
443
+ "value": "count(PRENOM)"
444
+ },
445
+ "componentType": "Loop",
446
+ "paginatedLoop": true,
447
+ "conditionFilter": {
448
+ "type": "VTL",
449
+ "value": "(true)"
450
+ },
451
+ "loopDependencies": ["PRENOM"]
452
+ },
453
+ {
454
+ "id": "mkb7iuwp",
455
+ "page": "7",
456
+ "label": {
457
+ "type": "VTL",
458
+ "value": "\"V - \" || \"S4 - Fin\""
459
+ },
460
+ "componentType": "Sequence",
461
+ "conditionFilter": {
462
+ "type": "VTL",
463
+ "value": "true"
464
+ }
465
+ }
466
+ ],
467
+ "pagination": "question",
468
+ "suggesters": [
469
+ {
470
+ "name": "L_DIPLOMES-2-1-0",
471
+ "fields": [
472
+ {
473
+ "min": 3,
474
+ "name": "label",
475
+ "rules": ["[\\w-]+"],
476
+ "stemmer": false,
477
+ "language": "French"
478
+ }
479
+ ],
480
+ "version": 1,
481
+ "queryParser": {
482
+ "type": "tokenized",
483
+ "params": {
484
+ "min": 3,
485
+ "pattern": "[\\w.-]+",
486
+ "stemmer": false,
487
+ "language": "French"
488
+ }
489
+ }
490
+ }
491
+ ],
492
+ "componentType": "Questionnaire",
493
+ "enoCoreVersion": "3.59.0",
494
+ "generatingDate": "14-01-2026 14:51:23",
495
+ "lunaticModelVersion": "5.11.0"
496
+ }
@@ -159,8 +159,8 @@ export type ComponentCheckboxBooleanDefinition =
159
159
  export type ComponentRadioDefinition = ComponentDefinitionBaseWithResponse & {
160
160
  componentType: 'Radio';
161
161
  orientation?: 'horizontal' | 'vertical';
162
- options: OptionsWithDetail;
163
- };
162
+ } & ComponentRadioDefinition1;
163
+ export type ComponentRadioDefinition1 = StaticOptions | OptionsFromVariable;
164
164
  export type OptionsWithDetail = {
165
165
  value: string | boolean;
166
166
  label: VTLExpression;
@@ -176,8 +176,8 @@ export type OptionsWithDetail = {
176
176
  export type ComponentDropdownDefinition =
177
177
  ComponentDefinitionBaseWithResponse & {
178
178
  componentType: 'Dropdown';
179
- options: Options;
180
- };
179
+ } & ComponentDropdownDefinition1;
180
+ export type ComponentDropdownDefinition1 = StaticOptions | OptionsFromVariable;
181
181
  export type ComponentQuestionDefinition = ComponentDefinitionBase & {
182
182
  componentType: 'Question';
183
183
  components: ComponentDefinition[];
@@ -185,8 +185,10 @@ export type ComponentQuestionDefinition = ComponentDefinitionBase & {
185
185
  export type ComponentCheckboxOneDefinition =
186
186
  ComponentDefinitionBaseWithResponse & {
187
187
  componentType: 'CheckboxOne';
188
- options: OptionsWithDetail;
189
- };
188
+ } & ComponentCheckboxOneDefinition1;
189
+ export type ComponentCheckboxOneDefinition1 =
190
+ | StaticOptions
191
+ | OptionsFromVariable;
190
192
  export type ComponentSuggesterDefinition =
191
193
  ComponentDefinitionBaseWithResponse & {
192
194
  componentType: 'Suggester';
@@ -224,11 +226,12 @@ export type ComponentPairWiseLinksDefinition = ComponentDefinitionBase & {
224
226
  };
225
227
  };
226
228
  sourceVariables?: {
227
- /** Name of the variable containing the name of the respondent */
229
+ /**
230
+ * Name of the variable containing the name of the respondent
231
+ */
228
232
  name?: string;
229
233
  /**
230
- * Name of the variable containing the gender of the respondent
231
- * (value of variable -> 1:male, 2: female)
234
+ * Name of the variable containing the sex/gender of the respondent (value of variable -> 1: man, 2: woman)
232
235
  */
233
236
  gender?: string;
234
237
  };
@@ -436,6 +439,13 @@ export type ControlDefinition = {
436
439
  export type ResponseDefinition = {
437
440
  name: string;
438
441
  };
442
+ export type StaticOptions = {
443
+ options: OptionsWithDetail;
444
+ };
445
+ export type OptionsFromVariable = {
446
+ optionSource: string;
447
+ optionFilter?: VTLExpression;
448
+ };
439
449
  export type ComponentText = {
440
450
  componentType: 'Text';
441
451
  label: VTLExpression;
@@ -91,7 +91,8 @@ type UntranslatedProperties =
91
91
  | 'controls'
92
92
  | 'conditionFilter'
93
93
  | 'conditionReadOnly'
94
- | 'components';
94
+ | 'components'
95
+ | 'optionFilter';
95
96
  export type DeepTranslateExpression<T> = T extends LunaticExpression
96
97
  ? ReactNode
97
98
  : T extends (infer ElementType)[]
@@ -11,7 +11,7 @@ import type { LunaticComponentProps } from '../../../components/type';
11
11
  import { getMissingResponseProp } from '../../props/propMissingResponse';
12
12
  import { getValueProp } from '../../props/propValue';
13
13
  import { getIterationsProp } from '../../props/propIterations';
14
- import { getOptionsProp } from '../../props/propOptions';
14
+ import { computeOptionsFromComponent } from '../../props/propOptions';
15
15
  import { LunaticLogger } from '../../logger/type';
16
16
  import { VTLScalarExpression } from '../../../type.source';
17
17
 
@@ -80,16 +80,15 @@ export const fillComponent = (
80
80
  missingResponse: getMissingResponseProp(component, state),
81
81
  management: state.management,
82
82
  iterations: getIterationsProp(component, state),
83
- options: getOptionsProp(
84
- interpretedProps,
85
- state.variables,
86
- state.handleChanges,
87
- state.pager.iteration,
83
+ options: computeOptionsFromComponent(interpretedProps, {
84
+ variables: state.variables,
85
+ handleChanges: state.handleChanges,
86
+ pagerIteration: state.pager.iteration,
88
87
  value,
89
- state.logger,
90
- state.disableFilters,
91
- shouldBeFiltered
92
- ),
88
+ logger: state.logger,
89
+ disableFilters: state.disableFilters,
90
+ shouldParentBeFiltered: shouldBeFiltered,
91
+ }),
93
92
  ...getComponentTypeProps(interpretedProps, state),
94
93
  // This is too dynamic to be typed correctly, so we allow any here
95
94
  } as any;