@inseefr/lunatic 3.7.2-rc.0 → 3.7.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.
@@ -22,6 +22,7 @@ export type ComponentSequenceDefinition = ComponentDefinitionBase & {
22
22
  };
23
23
  export type ComponentRoundaboutDefinition = ComponentDefinitionBase & {
24
24
  componentType: 'Roundabout';
25
+ loopDependencies?: string[];
25
26
  iterations: VTLScalarExpression;
26
27
  locked: boolean;
27
28
  progressVariable: string;
@@ -1,5 +1,5 @@
1
1
  import type { LunaticReducerState } from '../type';
2
2
  /**
3
- * Extract the list of variables used for the current loop.
3
+ * Extract the list of variables used for the current loop or roundabout.
4
4
  */
5
- export declare function useLoopVariables(pager: LunaticReducerState['pager'], pages: LunaticReducerState['pages']): string[];
5
+ export declare function useLoopVariables(pager: LunaticReducerState['pager'], pages: LunaticReducerState['pages'], loopType?: 'Loop' | 'Roundabout'): string[];
@@ -1,8 +1,8 @@
1
1
  import { useMemo } from 'react';
2
2
  /**
3
- * Extract the list of variables used for the current loop.
3
+ * Extract the list of variables used for the current loop or roundabout.
4
4
  */
5
- export function useLoopVariables(pager, pages) {
5
+ export function useLoopVariables(pager, pages, loopType = 'Loop') {
6
6
  const { iteration, page } = pager;
7
7
  const inIteration = iteration !== undefined;
8
8
  return useMemo(() => {
@@ -11,8 +11,8 @@ export function useLoopVariables(pager, pages) {
11
11
  return [];
12
12
  }
13
13
  // Find the loop to extract the dependencies
14
- const loop = (_a = pages[page]) === null || _a === void 0 ? void 0 : _a.components.find((c) => c.componentType === 'Loop');
14
+ const loop = (_a = pages[page]) === null || _a === void 0 ? void 0 : _a.components.find((c) => c.componentType === loopType);
15
15
  return (_b = loop === null || loop === void 0 ? void 0 : loop.loopDependencies) !== null && _b !== void 0 ? _b : [];
16
- }, [page, pages, inIteration]);
16
+ }, [inIteration, pages, page, loopType]);
17
17
  }
18
18
  //# sourceMappingURL=use-loop-variables.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-loop-variables.js","sourceRoot":"","sources":["../../../src/use-lunatic/hooks/use-loop-variables.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAAmC,EACnC,KAAmC;IAEnC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAClC,MAAM,WAAW,GAAG,SAAS,KAAK,SAAS,CAAC;IAC5C,OAAO,OAAO,CAAC,GAAG,EAAE;;QACnB,IAAI,CAAC,WAAW,EAAE,CAAC;YAClB,OAAO,EAAE,CAAC;QACX,CAAC;QACD,4CAA4C;QAC5C,MAAM,IAAI,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,0CAAE,UAAU,CAAC,IAAI,CACxC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,MAAM,CACiB,CAAC;QACpD,OAAO,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,gBAAgB,mCAAI,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;AAChC,CAAC"}
1
+ {"version":3,"file":"use-loop-variables.js","sourceRoot":"","sources":["../../../src/use-lunatic/hooks/use-loop-variables.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAAmC,EACnC,KAAmC,EACnC,WAAkC,MAAM;IAExC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IAClC,MAAM,WAAW,GAAG,SAAS,KAAK,SAAS,CAAC;IAC5C,OAAO,OAAO,CAAC,GAAG,EAAE;;QACnB,IAAI,CAAC,WAAW,EAAE,CAAC;YAClB,OAAO,EAAE,CAAC;QACX,CAAC;QACD,4CAA4C;QAC5C,MAAM,IAAI,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,0CAAE,UAAU,CAAC,IAAI,CACxC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,KAAK,QAAQ,CAIxB,CAAC;QAEb,OAAO,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,gBAAgB,mCAAI,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC"}
@@ -226,6 +226,8 @@ export type LunaticState = {
226
226
  isInLoop: boolean;
227
227
  /** Current loop's variables. */
228
228
  loopVariables: string[];
229
+ /** Current roundabout loop's variables. */
230
+ roundaboutLoopVariables: string[];
229
231
  /** Whether or not we're on the survey first page. */
230
232
  isFirstPage: boolean;
231
233
  /** Whether or not we're on the survey last page (we reached `maxPage`). */
@@ -146,6 +146,7 @@ argOptions = empty) {
146
146
  isInLoop: state.isInLoop,
147
147
  overview: useOverview(state, [pageTag]),
148
148
  loopVariables: useLoopVariables(state.pager, state.pages),
149
+ roundaboutLoopVariables: useLoopVariables(state.pager, state.pages, 'Roundabout'),
149
150
  // Methods
150
151
  getComponents,
151
152
  goPreviousPage,
@@ -1 +1 @@
1
- {"version":3,"file":"use-lunatic.js","sourceRoot":"","sources":["../../src/use-lunatic/use-lunatic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAExD,OAAO,CAAC,MAAM,SAAS,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,C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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "3.7.2-rc.0",
3
+ "version": "3.7.2",
4
4
  "description": "Library of questionnaire components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,6 +67,7 @@
67
67
  "page": "3",
68
68
  "conditionFilter": { "value": "true", "type": "VTL" },
69
69
  "iterations": { "value": "NB_HAB", "type": "VTL" },
70
+ "loopDependencies": ["PRENOMS"],
70
71
  "label": { "value": "\"Libellé du rondpoint\"", "type": "VTL" },
71
72
  "description": {
72
73
  "value": "\"Description du rond-point\"",
@@ -48,6 +48,7 @@ export type ComponentSequenceDefinition = ComponentDefinitionBase & {
48
48
  };
49
49
  export type ComponentRoundaboutDefinition = ComponentDefinitionBase & {
50
50
  componentType: 'Roundabout';
51
+ loopDependencies?: string[];
51
52
  iterations: VTLScalarExpression;
52
53
  locked: boolean;
53
54
  progressVariable: string;
@@ -2,11 +2,12 @@ import type { LunaticComponentDefinition, LunaticReducerState } from '../type';
2
2
  import { useMemo } from 'react';
3
3
 
4
4
  /**
5
- * Extract the list of variables used for the current loop.
5
+ * Extract the list of variables used for the current loop or roundabout.
6
6
  */
7
7
  export function useLoopVariables(
8
8
  pager: LunaticReducerState['pager'],
9
- pages: LunaticReducerState['pages']
9
+ pages: LunaticReducerState['pages'],
10
+ loopType: 'Loop' | 'Roundabout' = 'Loop'
10
11
  ): string[] {
11
12
  const { iteration, page } = pager;
12
13
  const inIteration = iteration !== undefined;
@@ -16,8 +17,12 @@ export function useLoopVariables(
16
17
  }
17
18
  // Find the loop to extract the dependencies
18
19
  const loop = pages[page]?.components.find(
19
- (c) => c.componentType === 'Loop'
20
- ) as LunaticComponentDefinition<'Loop'> | undefined;
20
+ (c) => c.componentType === loopType
21
+ ) as
22
+ | LunaticComponentDefinition<'Loop'>
23
+ | LunaticComponentDefinition<'Roundabout'>
24
+ | undefined;
25
+
21
26
  return loop?.loopDependencies ?? [];
22
- }, [page, pages, inIteration]);
27
+ }, [inIteration, pages, page, loopType]);
23
28
  }
@@ -258,6 +258,8 @@ export type LunaticState = {
258
258
  isInLoop: boolean;
259
259
  /** Current loop's variables. */
260
260
  loopVariables: string[];
261
+ /** Current roundabout loop's variables. */
262
+ roundaboutLoopVariables: string[];
261
263
  /** Whether or not we're on the survey first page. */
262
264
  isFirstPage: boolean;
263
265
  /** Whether or not we're on the survey last page (we reached `maxPage`). */
@@ -5,6 +5,8 @@ import sourceLogement from '../stories/questionnaires/logement/source.json';
5
5
  import sourceSimpsons from '../stories/questionnaires/simpsons/source.json';
6
6
  import sourceOverview from '../stories/behaviour/overview/sourceLoop.json';
7
7
  import sourceCheckboxGroup from '../stories/checkbox/sourceGroup.json';
8
+ import sourceRoundabout from '../stories/roundabout/source.json';
9
+ import sourcePaginatedLoop from '../stories/loop/source-paginated.json';
8
10
  import sourceCleaningLoop from '../stories/behaviour/cleaning/source-loop.json';
9
11
  import sourceCleaningResizing from '../stories/behaviour/resizing/source-resizing-cleaning.json';
10
12
  import type { PageTag } from './type';
@@ -455,4 +457,121 @@ describe('use-lunatic()', () => {
455
457
  expect(result.current.hasPageResponse()).toBeFalsy();
456
458
  });
457
459
  });
460
+
461
+ describe('loopVariables', () => {
462
+ it('should return an empty list when being out of a loop', () => {
463
+ const data = {
464
+ COLLECTED: {
465
+ PRENOM: { COLLECTED: ['John', 'Doe', 'Marc'] },
466
+ },
467
+ };
468
+
469
+ const { result } = renderHook(() =>
470
+ useLunatic(sourcePaginatedLoop, data, {})
471
+ );
472
+
473
+ act(() => {
474
+ // go outside a loop
475
+ result.current.goToPage({ page: 3 });
476
+ });
477
+
478
+ expect(result.current.loopVariables).toMatchObject([]);
479
+ });
480
+
481
+ it('should return an empty list when being on a non paginated loop', () => {
482
+ const data = {
483
+ COLLECTED: {
484
+ PRENOM: { COLLECTED: ['John', 'Doe', 'Marc'] },
485
+ },
486
+ };
487
+
488
+ const { result } = renderHook(() =>
489
+ useLunatic(sourcePaginatedLoop, data, {})
490
+ );
491
+
492
+ // first page is a non paginated loop
493
+ expect(result.current.loopVariables).toMatchObject([]);
494
+ });
495
+
496
+ it('should return the loop dependency variables when being in the loop', () => {
497
+ const data = {
498
+ COLLECTED: {
499
+ PRENOM: { COLLECTED: ['John', 'Doe', 'Marc'] },
500
+ },
501
+ };
502
+
503
+ const { result } = renderHook(() =>
504
+ useLunatic(sourcePaginatedLoop, data, {})
505
+ );
506
+
507
+ act(() => {
508
+ // go inside the non paginated loop, no matter the subPage or iteration
509
+ result.current.goToPage({ page: 2, subPage: 0, iteration: 0 });
510
+ });
511
+
512
+ expect(result.current.loopVariables).toMatchObject(['PRENOM']);
513
+ });
514
+ });
515
+
516
+ describe('roundaboutLoopVariables', () => {
517
+ it('should return an empty list when being outside a roundabout', () => {
518
+ const data = {
519
+ COLLECTED: {
520
+ NBHAB: { COLLECTED: 2 },
521
+ },
522
+ };
523
+
524
+ const { result } = renderHook(() =>
525
+ useLunatic(sourceRoundabout, data, {})
526
+ );
527
+
528
+ act(() => {
529
+ result.current.goNextPage();
530
+ });
531
+
532
+ expect(result.current.roundaboutLoopVariables).toMatchObject([]);
533
+ });
534
+
535
+ it('should return an empty list when being on the roundabout page (not in its loop)', () => {
536
+ const data = {
537
+ COLLECTED: {
538
+ NBHAB: { COLLECTED: 2 },
539
+ PRENOMS: { COLLECTED: ['John', 'Doe', 'Marc'] },
540
+ AGE: { COLLECTED: [18, 18, 18] },
541
+ },
542
+ };
543
+
544
+ const { result } = renderHook(() =>
545
+ useLunatic(sourceRoundabout, data, {})
546
+ );
547
+
548
+ act(() => {
549
+ // go to roundabout page
550
+ result.current.goToPage({ page: 3 });
551
+ });
552
+
553
+ expect(result.current.roundaboutLoopVariables).toMatchObject([]);
554
+ });
555
+
556
+ it('should return the roundabout loop dependencies variables when being in the roundabout loop', () => {
557
+ const data = {
558
+ COLLECTED: {
559
+ NBHAB: { COLLECTED: 2 },
560
+ PRENOMS: { COLLECTED: ['John', 'Doe', 'Marc'] },
561
+ AGE: { COLLECTED: [18, 18, 18] },
562
+ },
563
+ };
564
+
565
+ const { result } = renderHook(() =>
566
+ useLunatic(sourceRoundabout, data, {})
567
+ );
568
+
569
+ act(() => {
570
+ // go inside roundabout loop, no matter the subPage or iteration
571
+ result.current.goToPage({ page: 3, subPage: 0, iteration: 0 });
572
+ });
573
+
574
+ expect(result.current.roundaboutLoopVariables).toMatchObject(['PRENOMS']);
575
+ });
576
+ });
458
577
  });
@@ -231,6 +231,11 @@ export function useLunatic(
231
231
  isInLoop: state.isInLoop,
232
232
  overview: useOverview(state, [pageTag]),
233
233
  loopVariables: useLoopVariables(state.pager, state.pages),
234
+ roundaboutLoopVariables: useLoopVariables(
235
+ state.pager,
236
+ state.pages,
237
+ 'Roundabout'
238
+ ),
234
239
  // Methods
235
240
  getComponents,
236
241
  goPreviousPage,