@inseefr/lunatic 4.0.0 → 4.0.2
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/README.md +9 -7
- package/components/LunaticComponents.d.ts +1 -1
- package/components/LunaticComponents.js +1 -1
- package/esm/components/LunaticComponents.d.ts +1 -1
- package/esm/components/LunaticComponents.js +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-component.spec.js +89 -0
- package/esm/use-lunatic/commons/fill-components/fill-component.spec.js.map +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.js +6 -0
- package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/esm/use-lunatic/commons/pagination/page.js +5 -0
- package/esm/use-lunatic/commons/pagination/page.js.map +1 -1
- package/esm/use-lunatic/commons/remove-condition-filters.d.ts +3 -2
- package/esm/use-lunatic/commons/remove-condition-filters.js +5 -4
- package/esm/use-lunatic/commons/remove-condition-filters.js.map +1 -1
- package/esm/use-lunatic/commons/remove-condition-filters.spec.js +5 -1
- package/esm/use-lunatic/commons/remove-condition-filters.spec.js.map +1 -1
- package/esm/use-lunatic/hooks/useOverview.d.ts +1 -1
- package/esm/use-lunatic/hooks/useOverview.js +9 -5
- package/esm/use-lunatic/hooks/useOverview.js.map +1 -1
- package/esm/use-lunatic/hooks/useOverview.spec.js +10 -0
- package/esm/use-lunatic/hooks/useOverview.spec.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.d.ts +2 -1
- package/esm/use-lunatic/props/propOptions.js +5 -3
- package/esm/use-lunatic/props/propOptions.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.spec.js +110 -0
- package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/esm/use-lunatic/reducer/reducerInitializer.js +1 -3
- package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/esm/use-lunatic/type.d.ts +3 -2
- package/esm/utils/search/SearchInterface.d.ts +0 -8
- package/package.json +1 -1
- package/src/components/LunaticComponents.tsx +1 -1
- package/src/stories/behaviour/filter/filter.stories.tsx +8 -0
- package/src/stories/utils/Orchestrator.tsx +1 -1
- package/src/use-lunatic/commons/fill-components/fill-component.spec.ts +109 -0
- package/src/use-lunatic/commons/fill-components/fill-components.ts +12 -5
- package/src/use-lunatic/commons/pagination/page.ts +6 -0
- package/src/use-lunatic/commons/remove-condition-filters.spec.ts +6 -1
- package/src/use-lunatic/commons/remove-condition-filters.ts +8 -7
- package/src/use-lunatic/hooks/useOverview.spec.ts +12 -0
- package/src/use-lunatic/hooks/useOverview.ts +20 -5
- package/src/use-lunatic/props/propOptions.spec.ts +121 -0
- package/src/use-lunatic/props/propOptions.ts +8 -2
- package/src/use-lunatic/reducer/reducerInitializer.tsx +3 -6
- package/src/use-lunatic/type.ts +19 -18
- package/src/use-lunatic/use-lunatic.test.ts +15 -5
- package/src/utils/search/SearchInterface.ts +0 -9
- package/tsconfig.build.tsbuildinfo +1 -1
- package/use-lunatic/commons/fill-components/fill-component.spec.js +89 -0
- package/use-lunatic/commons/fill-components/fill-component.spec.js.map +1 -1
- package/use-lunatic/commons/fill-components/fill-components.js +6 -0
- package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/use-lunatic/commons/pagination/page.js +5 -0
- package/use-lunatic/commons/pagination/page.js.map +1 -1
- package/use-lunatic/commons/remove-condition-filters.d.ts +3 -2
- package/use-lunatic/commons/remove-condition-filters.js +5 -4
- package/use-lunatic/commons/remove-condition-filters.js.map +1 -1
- package/use-lunatic/commons/remove-condition-filters.spec.js +5 -1
- package/use-lunatic/commons/remove-condition-filters.spec.js.map +1 -1
- package/use-lunatic/hooks/useOverview.d.ts +1 -1
- package/use-lunatic/hooks/useOverview.js +9 -5
- package/use-lunatic/hooks/useOverview.js.map +1 -1
- package/use-lunatic/hooks/useOverview.spec.js +10 -0
- package/use-lunatic/hooks/useOverview.spec.js.map +1 -1
- package/use-lunatic/props/propOptions.d.ts +2 -1
- package/use-lunatic/props/propOptions.js +5 -3
- package/use-lunatic/props/propOptions.js.map +1 -1
- package/use-lunatic/props/propOptions.spec.js +110 -0
- package/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/use-lunatic/reducer/reducerInitializer.js +1 -3
- package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/use-lunatic/type.d.ts +3 -2
- package/utils/search/SearchInterface.d.ts +0 -8
|
@@ -29,13 +29,24 @@ export const useOverview = (
|
|
|
29
29
|
overview,
|
|
30
30
|
executeExpression,
|
|
31
31
|
pager,
|
|
32
|
-
|
|
32
|
+
options,
|
|
33
|
+
}: Pick<
|
|
34
|
+
LunaticReducerState,
|
|
35
|
+
'executeExpression' | 'overview' | 'pager' | 'options'
|
|
36
|
+
>,
|
|
33
37
|
deps: DependencyList
|
|
34
38
|
) => {
|
|
35
39
|
return useMemo(
|
|
36
|
-
() =>
|
|
40
|
+
() =>
|
|
41
|
+
interpretOverview(
|
|
42
|
+
overview,
|
|
43
|
+
executeExpression,
|
|
44
|
+
pager,
|
|
45
|
+
// ignore active filters for showing every overview items
|
|
46
|
+
options.activeFilters === 'DISABLED'
|
|
47
|
+
),
|
|
37
48
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
-
[...deps, overview]
|
|
49
|
+
[...deps, overview, options.activeFilters]
|
|
39
50
|
);
|
|
40
51
|
};
|
|
41
52
|
|
|
@@ -45,13 +56,15 @@ export const useOverview = (
|
|
|
45
56
|
const interpretOverview = (
|
|
46
57
|
overviewItems: LunaticOverviewItem[],
|
|
47
58
|
executeExpression: LunaticReducerState['executeExpression'],
|
|
48
|
-
pager?: LunaticReducerState['pager']
|
|
59
|
+
pager?: LunaticReducerState['pager'],
|
|
60
|
+
disabledFilters?: boolean
|
|
49
61
|
) => {
|
|
50
62
|
// Flat structure of the overview
|
|
51
63
|
let items = overviewItems.reduce(
|
|
52
64
|
(acc, item) =>
|
|
53
65
|
interpretOverviewItem(acc, item, executeExpression, {
|
|
54
66
|
pager,
|
|
67
|
+
disabledFilters,
|
|
55
68
|
}),
|
|
56
69
|
[] as InterpretedLunaticOverviewItem[]
|
|
57
70
|
);
|
|
@@ -86,6 +99,7 @@ const interpretOverviewItem = (
|
|
|
86
99
|
executeExpression: LunaticReducerState['executeExpression'],
|
|
87
100
|
state: {
|
|
88
101
|
pager?: LunaticReducerState['pager'];
|
|
102
|
+
disabledFilters?: boolean;
|
|
89
103
|
},
|
|
90
104
|
|
|
91
105
|
iteration?: number
|
|
@@ -101,8 +115,9 @@ const interpretOverviewItem = (
|
|
|
101
115
|
);
|
|
102
116
|
}
|
|
103
117
|
|
|
118
|
+
// if filters are disabled, item are visible and reached by default
|
|
104
119
|
const isVisible = (() => {
|
|
105
|
-
if (!item.conditionFilter) return true;
|
|
120
|
+
if (state.disabledFilters || !item.conditionFilter) return true;
|
|
106
121
|
return Boolean(
|
|
107
122
|
executeExpression(item.conditionFilter, {
|
|
108
123
|
iteration: iteration,
|
|
@@ -385,6 +385,65 @@ describe('computeOptionsFromComponent', () => {
|
|
|
385
385
|
expect(options).toHaveLength(1);
|
|
386
386
|
expect(options[0].shouldBeFiltered).toBe(false);
|
|
387
387
|
});
|
|
388
|
+
it('should keep responses when filters are DISABLED', () => {
|
|
389
|
+
const definition = {
|
|
390
|
+
...checkboxGroupDefinition,
|
|
391
|
+
responses: [
|
|
392
|
+
{
|
|
393
|
+
label: 'Option 1',
|
|
394
|
+
response: { name: 'O1' },
|
|
395
|
+
id: 'id1',
|
|
396
|
+
conditionFilter: { type: 'VTL', value: 'expression' },
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
400
|
+
|
|
401
|
+
// ensure interpreted expression is false
|
|
402
|
+
vi.spyOn(variables, 'run').mockImplementation(() => {
|
|
403
|
+
return false;
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const options = computeOptionsFromComponent(definition, {
|
|
407
|
+
variables,
|
|
408
|
+
handleChanges: mockChange,
|
|
409
|
+
pagerIteration: undefined,
|
|
410
|
+
value: undefined,
|
|
411
|
+
logger: mockLogger,
|
|
412
|
+
disabledFilters: true,
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
expect(options).toHaveLength(1);
|
|
416
|
+
expect(options[0].shouldBeFiltered).toBe(true);
|
|
417
|
+
});
|
|
418
|
+
it('should keep options when filters are DISABLED', () => {
|
|
419
|
+
const definition = {
|
|
420
|
+
...radioDefinition,
|
|
421
|
+
options: [
|
|
422
|
+
{
|
|
423
|
+
label: 'Option 1',
|
|
424
|
+
value: 'id1',
|
|
425
|
+
conditionFilter: { type: 'VTL', value: 'expression' },
|
|
426
|
+
},
|
|
427
|
+
],
|
|
428
|
+
} as any as DeepTranslateExpression<LunaticComponentDefinition>;
|
|
429
|
+
|
|
430
|
+
// ensure interpreted expression is false
|
|
431
|
+
vi.spyOn(variables, 'run').mockImplementation(() => {
|
|
432
|
+
return false;
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const options = computeOptionsFromComponent(definition, {
|
|
436
|
+
variables,
|
|
437
|
+
handleChanges: mockChange,
|
|
438
|
+
pagerIteration: undefined,
|
|
439
|
+
value: undefined,
|
|
440
|
+
logger: mockLogger,
|
|
441
|
+
disabledFilters: true,
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
expect(options).toHaveLength(1);
|
|
445
|
+
expect(options[0].shouldBeFiltered).toBe(true);
|
|
446
|
+
});
|
|
388
447
|
|
|
389
448
|
it('should evaluate the external-only filters retained during initialization', () => {
|
|
390
449
|
const definition = {
|
|
@@ -459,6 +518,68 @@ describe('computeOptionsFromComponent', () => {
|
|
|
459
518
|
(options as InterpretedOption[]).map((option) => option.value)
|
|
460
519
|
).toEqual(['collected']);
|
|
461
520
|
});
|
|
521
|
+
|
|
522
|
+
it('should set the response (CheckboxGroup) as shouldBeFiltered when the parent component should be filtered', () => {
|
|
523
|
+
const definition = {
|
|
524
|
+
...checkboxGroupDefinition,
|
|
525
|
+
responses: [
|
|
526
|
+
{
|
|
527
|
+
label: 'Option 1',
|
|
528
|
+
response: { name: 'O1' },
|
|
529
|
+
id: 'id1',
|
|
530
|
+
conditionFilter: { type: 'VTL', value: 'expression' },
|
|
531
|
+
},
|
|
532
|
+
],
|
|
533
|
+
} satisfies DeepTranslateExpression<LunaticComponentDefinition>;
|
|
534
|
+
|
|
535
|
+
const options = computeOptionsFromComponent(definition, {
|
|
536
|
+
variables,
|
|
537
|
+
handleChanges: mockChange,
|
|
538
|
+
pagerIteration: undefined,
|
|
539
|
+
value: undefined,
|
|
540
|
+
logger: mockLogger,
|
|
541
|
+
disabledFilters: true,
|
|
542
|
+
shouldParentBeFiltered: true,
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
expect(options).toHaveLength(1);
|
|
546
|
+
// the option would have been filtered if we did not disable filters because its parent would
|
|
547
|
+
expect(options[0].shouldBeFiltered).toBe(true);
|
|
548
|
+
});
|
|
549
|
+
it('should set the option (Radio) as shouldBeFiltered when the parent component should be filtered', () => {
|
|
550
|
+
const definition = {
|
|
551
|
+
...radioDefinition,
|
|
552
|
+
options: [
|
|
553
|
+
{
|
|
554
|
+
label: 'Option 1',
|
|
555
|
+
value: 'id1',
|
|
556
|
+
conditionFilter: {
|
|
557
|
+
type: 'VTL',
|
|
558
|
+
value: 'expression',
|
|
559
|
+
variablesDependencies: {
|
|
560
|
+
EXTERNAL: [],
|
|
561
|
+
COLLECTED: [],
|
|
562
|
+
CALCULATED: [],
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
],
|
|
567
|
+
} as any as DeepTranslateExpression<LunaticComponentDefinition>;
|
|
568
|
+
|
|
569
|
+
const options = computeOptionsFromComponent(definition, {
|
|
570
|
+
variables,
|
|
571
|
+
handleChanges: mockChange,
|
|
572
|
+
pagerIteration: undefined,
|
|
573
|
+
value: undefined,
|
|
574
|
+
logger: mockLogger,
|
|
575
|
+
disabledFilters: true,
|
|
576
|
+
shouldParentBeFiltered: true,
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
expect(options).toHaveLength(1);
|
|
580
|
+
// the option would have been filtered if we did not disable filters because its parent would
|
|
581
|
+
expect(options[0].shouldBeFiltered).toBe(true);
|
|
582
|
+
});
|
|
462
583
|
});
|
|
463
584
|
|
|
464
585
|
describe('Options based on a source variable', () => {
|
|
@@ -36,6 +36,7 @@ export function computeOptionsFromComponent(
|
|
|
36
36
|
pagerIteration,
|
|
37
37
|
value,
|
|
38
38
|
logger,
|
|
39
|
+
disabledFilters,
|
|
39
40
|
shouldParentBeFiltered,
|
|
40
41
|
}: {
|
|
41
42
|
variables: LunaticVariablesStore;
|
|
@@ -43,6 +44,7 @@ export function computeOptionsFromComponent(
|
|
|
43
44
|
pagerIteration: LunaticState['pager']['iteration'];
|
|
44
45
|
value: unknown;
|
|
45
46
|
logger: LunaticLogger;
|
|
47
|
+
disabledFilters?: boolean;
|
|
46
48
|
shouldParentBeFiltered?: boolean;
|
|
47
49
|
}
|
|
48
50
|
) {
|
|
@@ -51,7 +53,7 @@ export function computeOptionsFromComponent(
|
|
|
51
53
|
if (definition.componentType === 'CheckboxGroup') {
|
|
52
54
|
return definition.responses
|
|
53
55
|
.filter((response) => {
|
|
54
|
-
if (!response.conditionFilter) {
|
|
56
|
+
if (disabledFilters || !response.conditionFilter) {
|
|
55
57
|
return true;
|
|
56
58
|
}
|
|
57
59
|
return !isFilteredOutOption(
|
|
@@ -116,7 +118,11 @@ export function computeOptionsFromComponent(
|
|
|
116
118
|
|
|
117
119
|
return definition.options
|
|
118
120
|
.filter((option) => {
|
|
119
|
-
if (
|
|
121
|
+
if (
|
|
122
|
+
disabledFilters ||
|
|
123
|
+
!('conditionFilter' in option) ||
|
|
124
|
+
!option.conditionFilter
|
|
125
|
+
) {
|
|
120
126
|
return true;
|
|
121
127
|
}
|
|
122
128
|
return !isFilteredOutOption(
|
|
@@ -34,7 +34,7 @@ const baseState = {
|
|
|
34
34
|
isInLoop: false,
|
|
35
35
|
updatedAt: Date.now(),
|
|
36
36
|
overview: [],
|
|
37
|
-
updateBindings: () => {},
|
|
37
|
+
updateBindings: () => { },
|
|
38
38
|
executeExpression: <T,>() => null as T,
|
|
39
39
|
options: {
|
|
40
40
|
activeFilters: 'ALL',
|
|
@@ -42,7 +42,7 @@ const baseState = {
|
|
|
42
42
|
},
|
|
43
43
|
} satisfies LunaticReducerState;
|
|
44
44
|
|
|
45
|
-
const onChange = { current: () => {} };
|
|
45
|
+
const onChange = { current: () => { } };
|
|
46
46
|
|
|
47
47
|
export function reducerInitializer({
|
|
48
48
|
source,
|
|
@@ -69,10 +69,7 @@ export function reducerInitializer({
|
|
|
69
69
|
onVariableChange?: RefObject<LunaticOptions['onVariableChange']>;
|
|
70
70
|
logger?: LunaticLogger;
|
|
71
71
|
}): LunaticReducerState {
|
|
72
|
-
const filteredSource =
|
|
73
|
-
activeFilters && activeFilters !== 'ALL'
|
|
74
|
-
? removeConditionFilters(source, activeFilters)
|
|
75
|
-
: source;
|
|
72
|
+
const filteredSource = activeFilters ? removeConditionFilters(source, activeFilters) : source
|
|
76
73
|
|
|
77
74
|
// Cleaning is disabled if not all filters are active.
|
|
78
75
|
const disableCleaning =
|
package/src/use-lunatic/type.ts
CHANGED
|
@@ -59,7 +59,7 @@ export type LunaticError = Pick<
|
|
|
59
59
|
|
|
60
60
|
export type VariableType = 'COLLECTED' | 'EXTERNAL' | 'CALCULATED';
|
|
61
61
|
export type LunaticExpression = VTLExpression | VTLScalarExpression;
|
|
62
|
-
export type ActiveFilter = 'ALL' | 'EXTERNAL' | 'NONE';
|
|
62
|
+
export type ActiveFilter = 'ALL' | 'EXTERNAL' | 'NONE' | 'DISABLED';
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Page numerotation.
|
|
@@ -143,22 +143,22 @@ export type LunaticReducerState = {
|
|
|
143
143
|
pager: LunaticPager;
|
|
144
144
|
pages: {
|
|
145
145
|
[key: number | string]:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
146
|
+
| {
|
|
147
|
+
components: LunaticSource['components'];
|
|
148
|
+
isLoop: false;
|
|
149
|
+
iterations?: undefined;
|
|
150
|
+
loopDependencies?: undefined;
|
|
151
|
+
subPages?: undefined;
|
|
152
|
+
}
|
|
153
|
+
| {
|
|
154
|
+
components: LunaticSource['components'];
|
|
155
|
+
isLoop: true;
|
|
156
|
+
iterations: VTLScalarExpression;
|
|
157
|
+
/** Variables affecting this loop. */
|
|
158
|
+
loopDependencies: string[];
|
|
159
|
+
/** List of child pages (ex: ['20.1', '20.2'] */
|
|
160
|
+
subPages: string[];
|
|
161
|
+
};
|
|
162
162
|
};
|
|
163
163
|
/** Run an expression using the value from the state. */
|
|
164
164
|
executeExpression: <T = unknown>(
|
|
@@ -196,7 +196,8 @@ export type LunaticOptions = {
|
|
|
196
196
|
* Decides whether or not filters are active.
|
|
197
197
|
* - "ALL": Keep every filters
|
|
198
198
|
* - "EXTERNAL": Keep filter only if it is based on external variables only
|
|
199
|
-
* - "NONE":
|
|
199
|
+
* - "NONE": Remove every filters
|
|
200
|
+
* - "DISABLED": Keep every filters, but never apply it to components (only tag them as they should have been filtered)
|
|
200
201
|
* @default 'ALL'
|
|
201
202
|
*/
|
|
202
203
|
activeFilters?: ActiveFilter;
|
|
@@ -255,11 +255,7 @@ describe('use-lunatic()', () => {
|
|
|
255
255
|
|
|
256
256
|
it('should filter out some components by default', function () {
|
|
257
257
|
const { result } = renderHook(() =>
|
|
258
|
-
useLunatic(
|
|
259
|
-
sourceLogement,
|
|
260
|
-
undefined,
|
|
261
|
-
lunaticConfiguration
|
|
262
|
-
)
|
|
258
|
+
useLunatic(sourceLogement, undefined, lunaticConfiguration)
|
|
263
259
|
);
|
|
264
260
|
act(() => result.current.goToPage({ page: '3' }));
|
|
265
261
|
const currentPage = result.current.pageTag;
|
|
@@ -287,6 +283,20 @@ describe('use-lunatic()', () => {
|
|
|
287
283
|
const currentPage = result.current.pageTag;
|
|
288
284
|
expect(currentPage).toBe('3');
|
|
289
285
|
|
|
286
|
+
const components = result.current.getComponents();
|
|
287
|
+
expect(components.length).toBe(1);
|
|
288
|
+
});
|
|
289
|
+
it('should not filter any component when activeFilters is DISABLED', function () {
|
|
290
|
+
const { result } = renderHook(() =>
|
|
291
|
+
useLunatic(sourceLogement, undefined, {
|
|
292
|
+
...lunaticConfiguration,
|
|
293
|
+
activeFilters: 'DISABLED',
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
act(() => result.current.goToPage({ page: '3' }));
|
|
297
|
+
const currentPage = result.current.pageTag;
|
|
298
|
+
expect(currentPage).toBe('3');
|
|
299
|
+
|
|
290
300
|
const components = result.current.getComponents();
|
|
291
301
|
expect(components.length).toBe(1);
|
|
292
302
|
});
|
|
@@ -5,15 +5,6 @@ export type SearchInfo = LunaticSuggester;
|
|
|
5
5
|
export type IndexEntry = {
|
|
6
6
|
id: string;
|
|
7
7
|
label: string;
|
|
8
|
-
/**
|
|
9
|
-
* Score computed by MiniSearch algo
|
|
10
|
-
*/
|
|
11
|
-
score: number;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Score compute by melauto algo
|
|
15
|
-
*/
|
|
16
|
-
melautoScore: number;
|
|
17
8
|
[k: string]: any;
|
|
18
9
|
};
|
|
19
10
|
|