@inseefr/lunatic 3.4.15 → 3.4.16

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.
@@ -13,4 +13,4 @@ export type InterpretedLunaticOverviewItem = {
13
13
  /**
14
14
  * Build a filled overview everytime the deps change.
15
15
  */
16
- export declare const useOverview: ({ overview, executeExpression, pager, }: Pick<LunaticReducerState, "executeExpression" | "overview" | "pager">, deps: DependencyList) => InterpretedLunaticOverviewItem[];
16
+ export declare const useOverview: ({ overview, executeExpression, pager, options, }: Pick<LunaticReducerState, "executeExpression" | "overview" | "pager" | "options">, deps: DependencyList) => InterpretedLunaticOverviewItem[];
@@ -3,17 +3,20 @@ import { getPageTag, pageTagComparator } from '../commons/page-tag';
3
3
  /**
4
4
  * Build a filled overview everytime the deps change.
5
5
  */
6
- export const useOverview = ({ overview, executeExpression, pager, }, deps) => {
7
- return useMemo(() => interpretOverview(overview, executeExpression, pager),
6
+ export const useOverview = ({ overview, executeExpression, pager, options, }, deps) => {
7
+ return useMemo(() => interpretOverview(overview, executeExpression, pager, options.disableFilters),
8
8
  // eslint-disable-next-line react-hooks/exhaustive-deps
9
- [...deps, overview]);
9
+ [...deps, overview, options.disableFilters]);
10
10
  };
11
11
  /**
12
12
  * Use Lunatic data to interpret the static overview (calculated on init) with the real data.
13
13
  */
14
- const interpretOverview = (overviewItems, executeExpression, pager) => {
14
+ const interpretOverview = (overviewItems, executeExpression, pager, disableFilters) => {
15
15
  // Flat structure of the overview
16
- let items = overviewItems.reduce((acc, item) => interpretOverviewItem(acc, item, executeExpression, pager), []);
16
+ let items = overviewItems.reduce((acc, item) => interpretOverviewItem(acc, item, executeExpression, {
17
+ pager,
18
+ disableFilters,
19
+ }), []);
17
20
  // Sort using the page logic
18
21
  items = items.sort((a, b) => pageTagComparator(a.page, b.page));
19
22
  // Build a tree with nested item, a subsequence will be a child of the previous sequence
@@ -36,25 +39,29 @@ const interpretOverview = (overviewItems, executeExpression, pager) => {
36
39
  /**
37
40
  * Interpret expression inside an item (label & condition).
38
41
  */
39
- const interpretOverviewItem = (items, item, executeExpression, pager, iteration) => {
42
+ const interpretOverviewItem = (items, item, executeExpression, state, iteration) => {
40
43
  var _a;
41
44
  // We reached a loop item, we need to add it multiple time
42
45
  if (item.iterations && iteration === undefined) {
43
46
  const iterations = (_a = executeExpression(item.iterations)) !== null && _a !== void 0 ? _a : 0;
44
47
  return Array.from({ length: iterations }).reduce((acc, _, k) => {
45
- return interpretOverviewItem(acc, item, executeExpression, pager, k);
48
+ return interpretOverviewItem(acc, item, executeExpression, state, k);
46
49
  }, items);
47
50
  }
48
- const isVisible = item.conditionFilter
49
- ? Boolean(executeExpression(item.conditionFilter, {
51
+ // if disableFilters is set to true, item are visible and reached by default
52
+ const isVisible = (() => {
53
+ if (state.disableFilters || !item.conditionFilter)
54
+ return true;
55
+ return Boolean(executeExpression(item.conditionFilter, {
50
56
  iteration: iteration,
51
- }))
52
- : true;
57
+ }));
58
+ })();
53
59
  if (!isVisible) {
54
60
  return items;
55
61
  }
56
62
  // Append the item to the list of items
57
63
  const page = `${item.pageTag}${iteration !== undefined ? `#${iteration + 1}` : ''}`;
64
+ const reached = pageTagComparator(state.pager ? getPageTag(state.pager) : '-1', page) >= 0;
58
65
  return [
59
66
  ...items,
60
67
  {
@@ -65,9 +72,7 @@ const interpretOverviewItem = (items, item, executeExpression, pager, iteration)
65
72
  ? executeExpression(item.description, { iteration })
66
73
  : undefined,
67
74
  children: [],
68
- reached: pageTagComparator(pager ? getPageTag(pager) : '-1', page) >= 0
69
- ? true
70
- : false,
75
+ reached: reached,
71
76
  page: page,
72
77
  current: false,
73
78
  },
@@ -1 +1 @@
1
- {"version":3,"file":"useOverview.js","sourceRoot":"","sources":["../../../src/use-lunatic/hooks/useOverview.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuC,OAAO,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,qB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@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ import { renderHook } from '@testing-library/react';
2
+ import { describe, expect, it } from 'vitest';
3
+ import source from '../../stories/overview/sourceWithHierarchy.json';
4
+ import { useLunatic } from '../use-lunatic';
5
+ import { dataFromObject } from '../test.utils';
6
+ describe('use-overview test with useLunatic()', () => {
7
+ it('should initialize correctly with disableFilters: false (without data)', () => {
8
+ const params = [
9
+ source,
10
+ dataFromObject({}),
11
+ { withOverview: true },
12
+ ];
13
+ const { result } = renderHook(() => useLunatic(...params));
14
+ expect(result.current.overview.length).toBe(3);
15
+ });
16
+ it('should initialize correctly with disableFilters: false (with data)', () => {
17
+ const params = [
18
+ source,
19
+ dataFromObject({
20
+ READY: true,
21
+ }),
22
+ { withOverview: true },
23
+ ];
24
+ const { result } = renderHook(() => useLunatic(...params));
25
+ expect(result.current.overview.length).toBe(9);
26
+ });
27
+ it('should initialize correctly with disableFilters: true (without data)', () => {
28
+ const params = [
29
+ source,
30
+ dataFromObject({}),
31
+ { withOverview: true, disableFilters: true },
32
+ ];
33
+ const { result } = renderHook(() => useLunatic(...params));
34
+ // All elements have to be presents
35
+ expect(result.current.overview.length).toBe(9);
36
+ });
37
+ });
38
+ //# sourceMappingURL=useOverview.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOverview.spec.js","sourceRoot":"","sources":["../../../src/use-lunatic/hooks/useOverview.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,MAAM,MAAM,iDAAiD,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;IACpD,EAAE,CAAC,uEAAuE,EAAE,GAAG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-0,0 +1,2 @@
1
+ import { LunaticData } from './type';
2
+ export declare const dataFromObject: (o: Record<string, unknown>) => LunaticData;
@@ -0,0 +1,13 @@
1
+ export const dataFromObject = (o) => {
2
+ return {
3
+ EXTERNAL: {},
4
+ COLLECTED: Object.keys(o).reduce((acc, k) => ({
5
+ ...acc,
6
+ [k]: {
7
+ COLLECTED: o[k],
8
+ },
9
+ }), {}),
10
+ CALCULATED: {},
11
+ };
12
+ };
13
+ //# sourceMappingURL=test.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.utils.js","sourceRoot":"","sources":["../../src/use-lunatic/test.utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAA0B,EAAe,EAAE;IACzE,OAAO;QACN,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAC/B,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACZ,GAAG,GAAG;YACN,CAAC,CAAC,CAAC,EAAE;gBACJ,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;aACf;SACD,CAAC,EACF,EAAE,CACF;QACD,UAAU,EAAE,EAAE;KACd,CAAC;AACH,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "3.4.15",
3
+ "version": "3.4.16",
4
4
  "description": "Library of questionnaire components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -408,6 +408,7 @@
408
408
  "src/use-lunatic/hooks/use-loop-variables.ts",
409
409
  "src/use-lunatic/hooks/use-page-has-response.test.ts",
410
410
  "src/use-lunatic/hooks/use-page-has-response.ts",
411
+ "src/use-lunatic/hooks/useOverview.spec.ts",
411
412
  "src/use-lunatic/hooks/useOverview.ts",
412
413
  "src/use-lunatic/hooks/useWarnDepChange.ts",
413
414
  "src/use-lunatic/logger/ConsoleLogger.ts",
@@ -434,6 +435,7 @@
434
435
  "src/use-lunatic/reducer/reducer.ts",
435
436
  "src/use-lunatic/reducer/reducerInitializer.tsx",
436
437
  "src/use-lunatic/replace-component-sequence.ts",
438
+ "src/use-lunatic/test.utils.ts",
437
439
  "src/use-lunatic/type.ts",
438
440
  "src/use-lunatic/use-lunatic.test.ts",
439
441
  "src/use-lunatic/use-lunatic.ts",
@@ -1327,6 +1329,7 @@
1327
1329
  "esm/index.js.map",
1328
1330
  "esm/main.css",
1329
1331
  "esm/main.css.map",
1332
+ "esm/stories/overview/sourceWithHierarchy.json",
1330
1333
  "esm/tests/setup.d.ts",
1331
1334
  "esm/tests/setup.js",
1332
1335
  "esm/tests/setup.js.map",
@@ -1435,6 +1438,9 @@
1435
1438
  "esm/use-lunatic/hooks/useOverview.d.ts",
1436
1439
  "esm/use-lunatic/hooks/useOverview.js",
1437
1440
  "esm/use-lunatic/hooks/useOverview.js.map",
1441
+ "esm/use-lunatic/hooks/useOverview.spec.d.ts",
1442
+ "esm/use-lunatic/hooks/useOverview.spec.js",
1443
+ "esm/use-lunatic/hooks/useOverview.spec.js.map",
1438
1444
  "esm/use-lunatic/hooks/useWarnDepChange.d.ts",
1439
1445
  "esm/use-lunatic/hooks/useWarnDepChange.js",
1440
1446
  "esm/use-lunatic/hooks/useWarnDepChange.js.map",
@@ -1510,6 +1516,9 @@
1510
1516
  "esm/use-lunatic/replace-component-sequence.d.ts",
1511
1517
  "esm/use-lunatic/replace-component-sequence.js",
1512
1518
  "esm/use-lunatic/replace-component-sequence.js.map",
1519
+ "esm/use-lunatic/test.utils.d.ts",
1520
+ "esm/use-lunatic/test.utils.js",
1521
+ "esm/use-lunatic/test.utils.js.map",
1513
1522
  "esm/use-lunatic/type.d.ts",
1514
1523
  "esm/use-lunatic/type.js",
1515
1524
  "esm/use-lunatic/type.js.map",
@@ -1650,6 +1659,7 @@
1650
1659
  "index.js.map",
1651
1660
  "main.css",
1652
1661
  "main.css.map",
1662
+ "stories/overview/sourceWithHierarchy.json",
1653
1663
  "tests/setup.d.ts",
1654
1664
  "tests/setup.js",
1655
1665
  "tests/setup.js.map",
@@ -1759,6 +1769,9 @@
1759
1769
  "use-lunatic/hooks/useOverview.d.ts",
1760
1770
  "use-lunatic/hooks/useOverview.js",
1761
1771
  "use-lunatic/hooks/useOverview.js.map",
1772
+ "use-lunatic/hooks/useOverview.spec.d.ts",
1773
+ "use-lunatic/hooks/useOverview.spec.js",
1774
+ "use-lunatic/hooks/useOverview.spec.js.map",
1762
1775
  "use-lunatic/hooks/useWarnDepChange.d.ts",
1763
1776
  "use-lunatic/hooks/useWarnDepChange.js",
1764
1777
  "use-lunatic/hooks/useWarnDepChange.js.map",
@@ -1834,6 +1847,9 @@
1834
1847
  "use-lunatic/replace-component-sequence.d.ts",
1835
1848
  "use-lunatic/replace-component-sequence.js",
1836
1849
  "use-lunatic/replace-component-sequence.js.map",
1850
+ "use-lunatic/test.utils.d.ts",
1851
+ "use-lunatic/test.utils.js",
1852
+ "use-lunatic/test.utils.js.map",
1837
1853
  "use-lunatic/type.d.ts",
1838
1854
  "use-lunatic/type.js",
1839
1855
  "use-lunatic/type.js.map",
@@ -33,3 +33,12 @@ WithLoop.args = {
33
33
  data: dataLoop.data,
34
34
  lastReachedPage: '11.2#2',
35
35
  };
36
+
37
+ export const DisableFilterOverview = Template.bind({});
38
+ DisableFilterOverview.args = {
39
+ id: 'overview-disableFilter',
40
+ source,
41
+ showOverview: true,
42
+ disableFilters: true,
43
+ data,
44
+ };
@@ -0,0 +1,42 @@
1
+ import { renderHook } from '@testing-library/react';
2
+ import { describe, expect, it } from 'vitest';
3
+ import source from '../../stories/overview/sourceWithHierarchy.json';
4
+ import { useLunatic } from '../use-lunatic';
5
+ import { dataFromObject } from '../test.utils';
6
+
7
+ describe('use-overview test with useLunatic()', () => {
8
+ it('should initialize correctly with disableFilters: false (without data)', () => {
9
+ const params = [
10
+ source as any,
11
+ dataFromObject({}),
12
+ { withOverview: true },
13
+ ] as const;
14
+ const { result } = renderHook(() => useLunatic(...params));
15
+ expect(result.current.overview.length).toBe(3);
16
+ });
17
+
18
+ it('should initialize correctly with disableFilters: false (with data)', () => {
19
+ const params = [
20
+ source as any,
21
+ dataFromObject({
22
+ READY: true,
23
+ }),
24
+ { withOverview: true },
25
+ ] as const;
26
+
27
+ const { result } = renderHook(() => useLunatic(...params));
28
+ expect(result.current.overview.length).toBe(9);
29
+ });
30
+
31
+ it('should initialize correctly with disableFilters: true (without data)', () => {
32
+ const params = [
33
+ source as any,
34
+ dataFromObject({}),
35
+ { withOverview: true, disableFilters: true },
36
+ ] as const;
37
+
38
+ const { result } = renderHook(() => useLunatic(...params));
39
+ // All elements have to be presents
40
+ expect(result.current.overview.length).toBe(9);
41
+ });
42
+ });
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ LunaticOptions,
2
3
  LunaticOverviewItem,
3
4
  LunaticReducerState,
4
5
  PageTag,
@@ -25,13 +26,23 @@ export const useOverview = (
25
26
  overview,
26
27
  executeExpression,
27
28
  pager,
28
- }: Pick<LunaticReducerState, 'executeExpression' | 'overview' | 'pager'>,
29
+ options,
30
+ }: Pick<
31
+ LunaticReducerState,
32
+ 'executeExpression' | 'overview' | 'pager' | 'options'
33
+ >,
29
34
  deps: DependencyList
30
35
  ) => {
31
36
  return useMemo(
32
- () => interpretOverview(overview, executeExpression, pager),
37
+ () =>
38
+ interpretOverview(
39
+ overview,
40
+ executeExpression,
41
+ pager,
42
+ options.disableFilters
43
+ ),
33
44
  // eslint-disable-next-line react-hooks/exhaustive-deps
34
- [...deps, overview]
45
+ [...deps, overview, options.disableFilters]
35
46
  );
36
47
  };
37
48
 
@@ -41,11 +52,16 @@ export const useOverview = (
41
52
  const interpretOverview = (
42
53
  overviewItems: LunaticOverviewItem[],
43
54
  executeExpression: LunaticReducerState['executeExpression'],
44
- pager?: LunaticReducerState['pager']
55
+ pager?: LunaticReducerState['pager'],
56
+ disableFilters?: LunaticOptions['disableFilters']
45
57
  ) => {
46
58
  // Flat structure of the overview
47
59
  let items = overviewItems.reduce(
48
- (acc, item) => interpretOverviewItem(acc, item, executeExpression, pager),
60
+ (acc, item) =>
61
+ interpretOverviewItem(acc, item, executeExpression, {
62
+ pager,
63
+ disableFilters,
64
+ }),
49
65
  [] as InterpretedLunaticOverviewItem[]
50
66
  );
51
67
  // Sort using the page logic
@@ -77,7 +93,11 @@ const interpretOverviewItem = (
77
93
  items: InterpretedLunaticOverviewItem[],
78
94
  item: LunaticOverviewItem,
79
95
  executeExpression: LunaticReducerState['executeExpression'],
80
- pager?: LunaticReducerState['pager'],
96
+ state: {
97
+ pager?: LunaticReducerState['pager'];
98
+ disableFilters?: LunaticOptions['disableFilters'];
99
+ },
100
+
81
101
  iteration?: number
82
102
  ): InterpretedLunaticOverviewItem[] => {
83
103
  // We reached a loop item, we need to add it multiple time
@@ -85,19 +105,21 @@ const interpretOverviewItem = (
85
105
  const iterations = executeExpression<number>(item.iterations) ?? 0;
86
106
  return Array.from({ length: iterations }).reduce(
87
107
  (acc: InterpretedLunaticOverviewItem[], _, k) => {
88
- return interpretOverviewItem(acc, item, executeExpression, pager, k);
108
+ return interpretOverviewItem(acc, item, executeExpression, state, k);
89
109
  },
90
110
  items
91
111
  );
92
112
  }
93
113
 
94
- const isVisible = item.conditionFilter
95
- ? Boolean(
96
- executeExpression(item.conditionFilter, {
97
- iteration: iteration,
98
- })
99
- )
100
- : true;
114
+ // if disableFilters is set to true, item are visible and reached by default
115
+ const isVisible = (() => {
116
+ if (state.disableFilters || !item.conditionFilter) return true;
117
+ return Boolean(
118
+ executeExpression(item.conditionFilter, {
119
+ iteration: iteration,
120
+ })
121
+ );
122
+ })();
101
123
 
102
124
  if (!isVisible) {
103
125
  return items;
@@ -106,6 +128,10 @@ const interpretOverviewItem = (
106
128
  // Append the item to the list of items
107
129
  const page =
108
130
  `${item.pageTag}${iteration !== undefined ? `#${iteration + 1}` : ''}` as PageTag;
131
+
132
+ const reached =
133
+ pageTagComparator(state.pager ? getPageTag(state.pager) : '-1', page) >= 0;
134
+
109
135
  return [
110
136
  ...items,
111
137
  {
@@ -116,10 +142,7 @@ const interpretOverviewItem = (
116
142
  ? executeExpression(item.description, { iteration })
117
143
  : undefined,
118
144
  children: [],
119
- reached:
120
- pageTagComparator(pager ? getPageTag(pager) : '-1', page) >= 0
121
- ? true
122
- : false,
145
+ reached: reached,
123
146
  page: page,
124
147
  current: false,
125
148
  },
@@ -0,0 +1,17 @@
1
+ import { LunaticData } from './type';
2
+
3
+ export const dataFromObject = (o: Record<string, unknown>): LunaticData => {
4
+ return {
5
+ EXTERNAL: {},
6
+ COLLECTED: Object.keys(o).reduce(
7
+ (acc, k) => ({
8
+ ...acc,
9
+ [k]: {
10
+ COLLECTED: o[k],
11
+ },
12
+ }),
13
+ {}
14
+ ),
15
+ CALCULATED: {},
16
+ };
17
+ };
@@ -9,25 +9,10 @@ import sourceCheckboxGroup from '../stories/checkbox-group/source.json';
9
9
  import dataOverview from '../stories/overview/dataLoop.json';
10
10
  import sourceCleaningLoop from '../stories/behaviour/cleaning/source-loop.json';
11
11
  import sourceCleaningResizing from '../stories/behaviour/resizing/source-resizing-cleaning.json';
12
- import type { LunaticData, PageTag } from './type';
12
+ import type { PageTag } from './type';
13
13
  import { useLunatic } from './use-lunatic';
14
14
  import { useCallback } from 'react';
15
-
16
- const dataFromObject = (o: Record<string, unknown>): LunaticData => {
17
- return {
18
- EXTERNAL: {},
19
- COLLECTED: Object.keys(o).reduce(
20
- (acc, k) => ({
21
- ...acc,
22
- [k]: {
23
- COLLECTED: o[k],
24
- },
25
- }),
26
- {}
27
- ),
28
- CALCULATED: {},
29
- };
30
- };
15
+ import { dataFromObject } from './test.utils';
31
16
 
32
17
  describe('use-lunatic()', () => {
33
18
  const defaultParams = [