@inseefr/lunatic 3.8.0-rc.ucq-options-variable.0 → 3.8.1-rc.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.
- package/components/Suggester/Suggester.js +19 -7
- package/components/Suggester/Suggester.js.map +1 -1
- package/components/Suggester/Suggester.spec.js +8 -1
- package/components/Suggester/Suggester.spec.js.map +1 -1
- package/components/Suggester/useSuggestions.d.ts +21 -2
- package/components/Suggester/useSuggestions.js +26 -12
- package/components/Suggester/useSuggestions.js.map +1 -1
- package/esm/components/Suggester/Suggester.js +21 -8
- package/esm/components/Suggester/Suggester.js.map +1 -1
- package/esm/components/Suggester/Suggester.spec.js +8 -1
- package/esm/components/Suggester/Suggester.spec.js.map +1 -1
- package/esm/components/Suggester/useSuggestions.d.ts +21 -2
- package/esm/components/Suggester/useSuggestions.js +24 -10
- package/esm/components/Suggester/useSuggestions.js.map +1 -1
- package/esm/type.source.d.ts +3 -9
- package/esm/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.js +2 -10
- package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.d.ts +1 -9
- package/esm/use-lunatic/props/propOptions.js +1 -56
- package/esm/use-lunatic/props/propOptions.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.spec.js +56 -220
- package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/esm/utils/search/SearchInterface.d.ts +1 -0
- package/esm/utils/search/SearchMinisearch.d.ts +1 -0
- package/esm/utils/search/SearchMinisearch.js +6 -0
- package/esm/utils/search/SearchMinisearch.js.map +1 -1
- package/esm/utils/search/SuggestersDatabase.d.ts +7 -0
- package/esm/utils/search/SuggestersDatabase.js.map +1 -1
- package/package.json +1 -4
- package/src/components/Suggester/Suggester.spec.tsx +9 -1
- package/src/components/Suggester/Suggester.tsx +21 -8
- package/src/components/Suggester/useSuggestions.ts +39 -18
- package/src/stories/checkbox/checkbox.stories.tsx +0 -13
- package/src/stories/dropdown/dropdown.stories.tsx +0 -12
- package/src/stories/radio/radio.stories.tsx +0 -13
- package/src/type.source.ts +3 -9
- package/src/use-lunatic/commons/fill-components/fill-component-expressions.ts +1 -2
- package/src/use-lunatic/commons/fill-components/fill-components.ts +10 -9
- package/src/use-lunatic/props/propOptions.spec.ts +147 -217
- package/src/use-lunatic/props/propOptions.ts +8 -97
- package/src/utils/search/SearchInterface.ts +2 -0
- package/src/utils/search/SearchMinisearch.ts +7 -0
- package/src/utils/search/SuggestersDatabase.ts +10 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/type.source.d.ts +3 -9
- package/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
- package/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
- package/use-lunatic/commons/fill-components/fill-components.js +1 -9
- package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/use-lunatic/props/propOptions.d.ts +1 -9
- package/use-lunatic/props/propOptions.js +2 -57
- package/use-lunatic/props/propOptions.js.map +1 -1
- package/use-lunatic/props/propOptions.spec.js +55 -217
- package/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/utils/search/SearchInterface.d.ts +1 -0
- package/utils/search/SearchMinisearch.d.ts +1 -0
- package/utils/search/SearchMinisearch.js +6 -0
- package/utils/search/SearchMinisearch.js.map +1 -1
- package/utils/search/SuggestersDatabase.d.ts +7 -0
- package/utils/search/SuggestersDatabase.js.map +1 -1
- package/src/stories/checkbox/sourceOneDynamicOptions.json +0 -496
- package/src/stories/dropdown/sourceDynamicOptions.json +0 -496
- package/src/stories/radio/sourceDynamicOptions.json +0 -496
|
@@ -1,14 +1,46 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { LunaticVariablesStore } from '../commons/variables/lunatic-variables-store';
|
|
3
|
-
import {
|
|
3
|
+
import { getOptionsProp } from './propOptions';
|
|
4
4
|
import type { DeepTranslateExpression } from '../commons/fill-components/fill-component-expressions';
|
|
5
5
|
import type {
|
|
6
6
|
LunaticChangesHandler,
|
|
7
7
|
LunaticComponentDefinition,
|
|
8
8
|
} from '../type';
|
|
9
9
|
|
|
10
|
-
describe('
|
|
10
|
+
describe('getOptionsProp()', () => {
|
|
11
11
|
let variables: LunaticVariablesStore;
|
|
12
|
+
const checkboxGroupDefinition = {
|
|
13
|
+
id: 'CheckboxGroup',
|
|
14
|
+
componentType: 'CheckboxGroup',
|
|
15
|
+
responses: [
|
|
16
|
+
{
|
|
17
|
+
label: 'Option 1',
|
|
18
|
+
response: { name: 'O1' },
|
|
19
|
+
id: 'id1',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: 'Option 2',
|
|
23
|
+
response: { name: 'O2' },
|
|
24
|
+
id: 'id2',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
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>;
|
|
12
44
|
|
|
13
45
|
let mockChange: LunaticChangesHandler;
|
|
14
46
|
const mockLogger = vi.fn();
|
|
@@ -18,97 +50,69 @@ describe('computeOptionsFromComponent', () => {
|
|
|
18
50
|
variables = new LunaticVariablesStore();
|
|
19
51
|
});
|
|
20
52
|
|
|
21
|
-
describe('
|
|
22
|
-
const checkboxGroupDefinition = {
|
|
23
|
-
id: 'CheckboxGroup',
|
|
24
|
-
componentType: 'CheckboxGroup',
|
|
25
|
-
responses: [
|
|
26
|
-
{
|
|
27
|
-
label: 'Option 1',
|
|
28
|
-
response: { name: 'O1' },
|
|
29
|
-
id: 'id1',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
label: 'Option 2',
|
|
33
|
-
response: { name: 'O2' },
|
|
34
|
-
id: 'id2',
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
38
|
-
|
|
39
|
-
const radioDefinition = {
|
|
40
|
-
id: 'RadioGroup',
|
|
41
|
-
componentType: 'Radio',
|
|
42
|
-
response: { name: 'RADIO' },
|
|
43
|
-
options: [
|
|
44
|
-
{
|
|
45
|
-
label: 'Option 1',
|
|
46
|
-
value: 'id1',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
label: 'Option 2',
|
|
50
|
-
value: 'id2',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
54
|
-
|
|
53
|
+
describe('CheckboxGroup', () => {
|
|
55
54
|
it('should check boxes', () => {
|
|
56
55
|
variables.set('O2', false);
|
|
57
|
-
let options =
|
|
56
|
+
let options = getOptionsProp(
|
|
57
|
+
checkboxGroupDefinition,
|
|
58
58
|
variables,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
mockChange,
|
|
60
|
+
undefined,
|
|
61
|
+
undefined,
|
|
62
|
+
mockLogger
|
|
63
|
+
);
|
|
64
64
|
expect(options[1].checked).toBe(false);
|
|
65
65
|
variables.set('O2', true);
|
|
66
|
-
options =
|
|
66
|
+
options = getOptionsProp(
|
|
67
|
+
checkboxGroupDefinition,
|
|
67
68
|
variables,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
mockChange,
|
|
70
|
+
undefined,
|
|
71
|
+
undefined,
|
|
72
|
+
mockLogger
|
|
73
|
+
);
|
|
73
74
|
expect(options[1].checked).toBe(true);
|
|
74
75
|
});
|
|
75
76
|
it('should check boxes correctly within iteration', () => {
|
|
76
77
|
variables.set('O1', []);
|
|
77
78
|
variables.set('O2', []);
|
|
78
|
-
let options =
|
|
79
|
+
let options = getOptionsProp(
|
|
80
|
+
checkboxGroupDefinition,
|
|
79
81
|
variables,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
mockChange,
|
|
83
|
+
0,
|
|
84
|
+
undefined,
|
|
85
|
+
mockLogger
|
|
86
|
+
);
|
|
85
87
|
expect(
|
|
86
88
|
options.filter((o) => o.checked),
|
|
87
89
|
'Nothing checked when variable empty'
|
|
88
90
|
).toHaveLength(0);
|
|
89
91
|
|
|
90
92
|
variables.set('O1', [true, 0]);
|
|
91
|
-
options =
|
|
93
|
+
options = getOptionsProp(
|
|
94
|
+
checkboxGroupDefinition,
|
|
92
95
|
variables,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
mockChange,
|
|
97
|
+
0,
|
|
98
|
+
undefined,
|
|
99
|
+
mockLogger
|
|
100
|
+
);
|
|
98
101
|
expect(options[0].checked).toBe(true);
|
|
99
102
|
expect(options[1].checked).toBe(false);
|
|
100
103
|
});
|
|
101
104
|
it('should create handleChange correctly', () => {
|
|
102
105
|
variables.set('O1', [true, false]);
|
|
103
106
|
variables.set('O2', [false, true]);
|
|
104
|
-
const options =
|
|
107
|
+
const options = getOptionsProp(
|
|
108
|
+
checkboxGroupDefinition,
|
|
105
109
|
variables,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
options[1].onCheck
|
|
110
|
+
mockChange,
|
|
111
|
+
1,
|
|
112
|
+
undefined,
|
|
113
|
+
mockLogger
|
|
114
|
+
);
|
|
115
|
+
options[1].onCheck(false);
|
|
112
116
|
expect(mockChange).toHaveBeenLastCalledWith([
|
|
113
117
|
{ name: 'O2', value: false },
|
|
114
118
|
]);
|
|
@@ -141,13 +145,14 @@ describe('computeOptionsFromComponent', () => {
|
|
|
141
145
|
|
|
142
146
|
variables.set('DETAIL', true);
|
|
143
147
|
|
|
144
|
-
const options =
|
|
148
|
+
const options = getOptionsProp(
|
|
149
|
+
definition,
|
|
145
150
|
variables,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
mockChange,
|
|
152
|
+
undefined,
|
|
153
|
+
undefined,
|
|
154
|
+
mockLogger
|
|
155
|
+
);
|
|
151
156
|
|
|
152
157
|
expect(options).toHaveLength(2);
|
|
153
158
|
expect(options[0].detailLabel).toBe('Precize:');
|
|
@@ -183,13 +188,14 @@ describe('computeOptionsFromComponent', () => {
|
|
|
183
188
|
|
|
184
189
|
variables.set('DETAIL', true);
|
|
185
190
|
|
|
186
|
-
const options =
|
|
191
|
+
const options = getOptionsProp(
|
|
192
|
+
definition,
|
|
187
193
|
variables,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
mockChange,
|
|
195
|
+
undefined,
|
|
196
|
+
undefined,
|
|
197
|
+
mockLogger
|
|
198
|
+
);
|
|
193
199
|
|
|
194
200
|
expect(options).toHaveLength(2);
|
|
195
201
|
expect(options[0].detailLabel).toBe('Precize:');
|
|
@@ -218,13 +224,14 @@ describe('computeOptionsFromComponent', () => {
|
|
|
218
224
|
],
|
|
219
225
|
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
220
226
|
|
|
221
|
-
const options =
|
|
227
|
+
const options = getOptionsProp(
|
|
228
|
+
definition,
|
|
222
229
|
variables,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
230
|
+
mockChange,
|
|
231
|
+
undefined,
|
|
232
|
+
undefined,
|
|
233
|
+
mockLogger
|
|
234
|
+
);
|
|
228
235
|
|
|
229
236
|
// First option should be filtered out since its conditionFilter is evaluated to false
|
|
230
237
|
expect(options).toHaveLength(1);
|
|
@@ -247,13 +254,14 @@ describe('computeOptionsFromComponent', () => {
|
|
|
247
254
|
],
|
|
248
255
|
} as any as DeepTranslateExpression<LunaticComponentDefinition>;
|
|
249
256
|
|
|
250
|
-
const options =
|
|
257
|
+
const options = getOptionsProp(
|
|
258
|
+
definition,
|
|
251
259
|
variables,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
260
|
+
mockChange,
|
|
261
|
+
undefined,
|
|
262
|
+
undefined,
|
|
263
|
+
mockLogger
|
|
264
|
+
);
|
|
257
265
|
|
|
258
266
|
// First option should be filtered out since its conditionFilter is evaluated to false
|
|
259
267
|
expect(options).toHaveLength(1);
|
|
@@ -277,13 +285,14 @@ describe('computeOptionsFromComponent', () => {
|
|
|
277
285
|
throw new Error('Test error');
|
|
278
286
|
});
|
|
279
287
|
|
|
280
|
-
const options =
|
|
288
|
+
const options = getOptionsProp(
|
|
289
|
+
definition,
|
|
281
290
|
variables,
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
291
|
+
mockChange,
|
|
292
|
+
undefined,
|
|
293
|
+
undefined,
|
|
294
|
+
mockLogger
|
|
295
|
+
);
|
|
287
296
|
|
|
288
297
|
// Ensure the option is not filtered
|
|
289
298
|
expect(options).toHaveLength(1);
|
|
@@ -306,13 +315,14 @@ describe('computeOptionsFromComponent', () => {
|
|
|
306
315
|
throw new Error('Test error');
|
|
307
316
|
});
|
|
308
317
|
|
|
309
|
-
const options =
|
|
318
|
+
const options = getOptionsProp(
|
|
319
|
+
definition,
|
|
310
320
|
variables,
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
321
|
+
mockChange,
|
|
322
|
+
undefined,
|
|
323
|
+
undefined,
|
|
324
|
+
mockLogger
|
|
325
|
+
);
|
|
316
326
|
|
|
317
327
|
// Ensure the option is not filtered
|
|
318
328
|
expect(options).toHaveLength(1);
|
|
@@ -336,14 +346,15 @@ describe('computeOptionsFromComponent', () => {
|
|
|
336
346
|
return false;
|
|
337
347
|
});
|
|
338
348
|
|
|
339
|
-
const options =
|
|
349
|
+
const options = getOptionsProp(
|
|
350
|
+
definition,
|
|
340
351
|
variables,
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
disableFilters
|
|
346
|
-
|
|
352
|
+
mockChange,
|
|
353
|
+
undefined,
|
|
354
|
+
undefined,
|
|
355
|
+
mockLogger,
|
|
356
|
+
true // disableFilters = true
|
|
357
|
+
);
|
|
347
358
|
|
|
348
359
|
// Ensure the option is not filtered
|
|
349
360
|
expect(options).toHaveLength(1);
|
|
@@ -367,14 +378,15 @@ describe('computeOptionsFromComponent', () => {
|
|
|
367
378
|
return false;
|
|
368
379
|
});
|
|
369
380
|
|
|
370
|
-
const options =
|
|
381
|
+
const options = getOptionsProp(
|
|
382
|
+
definition,
|
|
371
383
|
variables,
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
disableFilters
|
|
377
|
-
|
|
384
|
+
mockChange,
|
|
385
|
+
undefined,
|
|
386
|
+
undefined,
|
|
387
|
+
mockLogger,
|
|
388
|
+
true // disableFilters = true
|
|
389
|
+
);
|
|
378
390
|
|
|
379
391
|
// Ensure the option is not filtered
|
|
380
392
|
expect(options).toHaveLength(1);
|
|
@@ -394,15 +406,16 @@ describe('computeOptionsFromComponent', () => {
|
|
|
394
406
|
],
|
|
395
407
|
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
396
408
|
|
|
397
|
-
const options =
|
|
409
|
+
const options = getOptionsProp(
|
|
410
|
+
definition,
|
|
398
411
|
variables,
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
disableFilters
|
|
404
|
-
|
|
405
|
-
|
|
412
|
+
mockChange,
|
|
413
|
+
undefined,
|
|
414
|
+
undefined,
|
|
415
|
+
mockLogger,
|
|
416
|
+
true, // disableFilters = true
|
|
417
|
+
true // parent component should be filtered
|
|
418
|
+
);
|
|
406
419
|
|
|
407
420
|
// Ensure the option is not filtered
|
|
408
421
|
expect(options).toHaveLength(1);
|
|
@@ -421,15 +434,16 @@ describe('computeOptionsFromComponent', () => {
|
|
|
421
434
|
],
|
|
422
435
|
} as any as DeepTranslateExpression<LunaticComponentDefinition>;
|
|
423
436
|
|
|
424
|
-
const options =
|
|
437
|
+
const options = getOptionsProp(
|
|
438
|
+
definition,
|
|
425
439
|
variables,
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
disableFilters
|
|
431
|
-
|
|
432
|
-
|
|
440
|
+
mockChange,
|
|
441
|
+
undefined,
|
|
442
|
+
undefined,
|
|
443
|
+
mockLogger,
|
|
444
|
+
true, // disableFilters = true
|
|
445
|
+
true // parent component should be filtered
|
|
446
|
+
);
|
|
433
447
|
|
|
434
448
|
// Ensure the option is not filtered
|
|
435
449
|
expect(options).toHaveLength(1);
|
|
@@ -437,88 +451,4 @@ describe('computeOptionsFromComponent', () => {
|
|
|
437
451
|
expect(options[0].shouldBeFiltered).toBe(true);
|
|
438
452
|
});
|
|
439
453
|
});
|
|
440
|
-
|
|
441
|
-
describe('Options based on a source variable', () => {
|
|
442
|
-
const radioOptionSourceDefinition = {
|
|
443
|
-
id: 'RadioGroupDynamic',
|
|
444
|
-
componentType: 'Radio',
|
|
445
|
-
response: { name: 'RADIO' },
|
|
446
|
-
optionSource: 'NAME',
|
|
447
|
-
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
448
|
-
|
|
449
|
-
it('should build options when the source variable is an array of strings', () => {
|
|
450
|
-
variables.set('NAME', ['Maëlle', 'Verso']);
|
|
451
|
-
const options = computeOptionsFromComponent(radioOptionSourceDefinition, {
|
|
452
|
-
variables,
|
|
453
|
-
handleChanges: mockChange,
|
|
454
|
-
pagerIteration: undefined,
|
|
455
|
-
value: undefined,
|
|
456
|
-
logger: mockLogger,
|
|
457
|
-
}) as InterpretedOption[]; // force type but it should infer type correctly
|
|
458
|
-
|
|
459
|
-
expect(options).toHaveLength(2);
|
|
460
|
-
expect(options[0].value).toBe('Maëlle');
|
|
461
|
-
expect(options[0].label).toBe('Maëlle');
|
|
462
|
-
expect(options[1].value).toBe('Verso');
|
|
463
|
-
expect(options[1].label).toBe('Verso');
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
it('should build options when the source variable is an array of numbers', () => {
|
|
467
|
-
variables.set('NAME', [10, 20]);
|
|
468
|
-
const options = computeOptionsFromComponent(radioOptionSourceDefinition, {
|
|
469
|
-
variables,
|
|
470
|
-
handleChanges: mockChange,
|
|
471
|
-
pagerIteration: undefined,
|
|
472
|
-
value: undefined,
|
|
473
|
-
logger: mockLogger,
|
|
474
|
-
}) as InterpretedOption[]; // force type but it should infer type correctly
|
|
475
|
-
|
|
476
|
-
expect(options).toHaveLength(2);
|
|
477
|
-
expect(options[0].value).toBe(10);
|
|
478
|
-
expect(options[0].label).toBe('10');
|
|
479
|
-
expect(options[1].value).toBe(20);
|
|
480
|
-
expect(options[1].label).toBe('20');
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
it('should set the response when selecting a dynamic option', () => {
|
|
484
|
-
variables.set('NAME', ['Maëlle', 'Verso']);
|
|
485
|
-
const options = computeOptionsFromComponent(radioOptionSourceDefinition, {
|
|
486
|
-
variables,
|
|
487
|
-
handleChanges: mockChange,
|
|
488
|
-
pagerIteration: undefined,
|
|
489
|
-
value: undefined,
|
|
490
|
-
logger: mockLogger,
|
|
491
|
-
}) as InterpretedOption[]; // force type but it should infer type correctly
|
|
492
|
-
|
|
493
|
-
options[0].onCheck?.();
|
|
494
|
-
expect(mockChange).toHaveBeenLastCalledWith([
|
|
495
|
-
{ name: 'RADIO', value: 'Maëlle' },
|
|
496
|
-
]);
|
|
497
|
-
|
|
498
|
-
options[1].onCheck?.();
|
|
499
|
-
expect(mockChange).toHaveBeenLastCalledWith([
|
|
500
|
-
{ name: 'RADIO', value: 'Verso' },
|
|
501
|
-
]);
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
it('should filter options based on the optionFilter expression', () => {
|
|
505
|
-
const definition = {
|
|
506
|
-
...radioOptionSourceDefinition,
|
|
507
|
-
optionFilter: { type: 'VTL', value: 'AGE >= 18' },
|
|
508
|
-
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
509
|
-
|
|
510
|
-
variables.set('NAME', ['Maëlle', 'Verso', 'Aline']);
|
|
511
|
-
variables.set('AGE', [16, 30, 50]);
|
|
512
|
-
|
|
513
|
-
const options = computeOptionsFromComponent(definition, {
|
|
514
|
-
variables,
|
|
515
|
-
handleChanges: mockChange,
|
|
516
|
-
pagerIteration: undefined,
|
|
517
|
-
value: undefined,
|
|
518
|
-
logger: mockLogger,
|
|
519
|
-
}) as InterpretedOption[]; // force type but it should infer type correctly
|
|
520
|
-
|
|
521
|
-
expect(options.map((option) => option.value)).toEqual(['Verso', 'Aline']);
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
454
|
});
|
|
@@ -28,25 +28,15 @@ export type InterpretedOption = {
|
|
|
28
28
|
/**
|
|
29
29
|
* Compute options for checkboxes / radios / dropdown
|
|
30
30
|
*/
|
|
31
|
-
export function
|
|
31
|
+
export function getOptionsProp(
|
|
32
32
|
definition: DeepTranslateExpression<LunaticComponentDefinition>,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
shouldParentBeFiltered,
|
|
41
|
-
}: {
|
|
42
|
-
variables: LunaticVariablesStore;
|
|
43
|
-
handleChanges: LunaticChangesHandler;
|
|
44
|
-
pagerIteration: LunaticState['pager']['iteration'];
|
|
45
|
-
value: unknown;
|
|
46
|
-
logger: LunaticLogger;
|
|
47
|
-
disableFilters?: boolean;
|
|
48
|
-
shouldParentBeFiltered?: boolean;
|
|
49
|
-
}
|
|
33
|
+
variables: LunaticVariablesStore,
|
|
34
|
+
handleChanges: LunaticChangesHandler,
|
|
35
|
+
pagerIteration: LunaticState['pager']['iteration'],
|
|
36
|
+
value: unknown,
|
|
37
|
+
logger: LunaticLogger,
|
|
38
|
+
disableFilters?: boolean,
|
|
39
|
+
shouldParentBeFiltered?: boolean
|
|
50
40
|
) {
|
|
51
41
|
const iteration = isNumber(pagerIteration) ? [pagerIteration] : undefined;
|
|
52
42
|
|
|
@@ -95,27 +85,10 @@ export function computeOptionsFromComponent(
|
|
|
95
85
|
}));
|
|
96
86
|
}
|
|
97
87
|
|
|
98
|
-
// options based on another variable
|
|
99
|
-
if ('optionSource' in definition && definition.optionSource) {
|
|
100
|
-
return computeOptionsFromSource(definition.optionSource, {
|
|
101
|
-
variables,
|
|
102
|
-
value,
|
|
103
|
-
handleChanges,
|
|
104
|
-
responseName: definition.response.name,
|
|
105
|
-
logger,
|
|
106
|
-
shouldParentBeFiltered,
|
|
107
|
-
optionFilter: definition.optionFilter,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
88
|
if (!('options' in definition)) {
|
|
112
89
|
return [];
|
|
113
90
|
}
|
|
114
91
|
|
|
115
|
-
if (!definition.options) {
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
92
|
return definition.options
|
|
120
93
|
.filter((option) => {
|
|
121
94
|
if (
|
|
@@ -171,68 +144,6 @@ export function computeOptionsFromComponent(
|
|
|
171
144
|
}));
|
|
172
145
|
}
|
|
173
146
|
|
|
174
|
-
/**
|
|
175
|
-
* Get all options from a source variable, applying filters.
|
|
176
|
-
*/
|
|
177
|
-
function computeOptionsFromSource(
|
|
178
|
-
optionSource: string,
|
|
179
|
-
{
|
|
180
|
-
variables,
|
|
181
|
-
value,
|
|
182
|
-
handleChanges,
|
|
183
|
-
responseName,
|
|
184
|
-
logger,
|
|
185
|
-
shouldParentBeFiltered,
|
|
186
|
-
optionFilter,
|
|
187
|
-
}: {
|
|
188
|
-
variables: LunaticVariablesStore;
|
|
189
|
-
value: unknown;
|
|
190
|
-
handleChanges: LunaticChangesHandler;
|
|
191
|
-
responseName: string;
|
|
192
|
-
logger: LunaticLogger;
|
|
193
|
-
shouldParentBeFiltered?: boolean;
|
|
194
|
-
optionFilter?: VtlExpression;
|
|
195
|
-
}
|
|
196
|
-
): InterpretedOption[] {
|
|
197
|
-
// we don't know the type of the optionSource values (string, numbers, boolean)
|
|
198
|
-
const optionValues = variables.get<unknown>(optionSource);
|
|
199
|
-
if (!optionValues) {
|
|
200
|
-
return [];
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const normalizedValues = Array.isArray(optionValues)
|
|
204
|
-
? optionValues
|
|
205
|
-
: [optionValues];
|
|
206
|
-
|
|
207
|
-
return normalizedValues
|
|
208
|
-
.filter((option, index) => {
|
|
209
|
-
// option is an empty value, we remove it from the options list
|
|
210
|
-
if (option === null || option === undefined) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
// no filter expression, we keep the option
|
|
214
|
-
if (!optionFilter) {
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
// apply filter expression on option (applied to its iteration)
|
|
218
|
-
return !isFilteredOutOption(variables, [index], logger, optionFilter);
|
|
219
|
-
})
|
|
220
|
-
.map((option) => {
|
|
221
|
-
return {
|
|
222
|
-
label: String(option),
|
|
223
|
-
value: option,
|
|
224
|
-
checked: value === option,
|
|
225
|
-
onCheck: () => {
|
|
226
|
-
handleChanges([{ name: responseName, value: option }]);
|
|
227
|
-
},
|
|
228
|
-
onUncheck: () => {
|
|
229
|
-
handleChanges([{ name: responseName, value: null }]);
|
|
230
|
-
},
|
|
231
|
-
shouldBeFiltered: shouldParentBeFiltered,
|
|
232
|
-
};
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
147
|
/**
|
|
237
148
|
* Check if an option should be filtered, depending on its conditionFilter.
|
|
238
149
|
*/
|
|
@@ -23,6 +23,16 @@ export function registerSuggesters(
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export type SearchStore =
|
|
27
|
+
| {
|
|
28
|
+
error: string;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
error?: null;
|
|
32
|
+
search: SearchInterface<IndexEntry>;
|
|
33
|
+
index: () => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
|
|
26
36
|
export function getSearchForStore(storeName: string) {
|
|
27
37
|
const search = suggesters.get(storeName);
|
|
28
38
|
if (!search) {
|