@inseefr/lunatic 3.6.5 → 3.6.7

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 (69) hide show
  1. package/README.md +25 -0
  2. package/components/CheckboxGroup/CustomCheckboxGroup.d.ts +1 -1
  3. package/components/CheckboxGroup/CustomCheckboxGroup.js.map +1 -1
  4. package/components/Loop/Loop.d.ts +1 -1
  5. package/components/Loop/Loop.js +5 -27
  6. package/components/Loop/Loop.js.map +1 -1
  7. package/components/Loop/utils.d.ts +8 -0
  8. package/components/Loop/utils.js +65 -0
  9. package/components/Loop/utils.js.map +1 -0
  10. package/components/RosterForLoop/RosterForLoop.js +4 -27
  11. package/components/RosterForLoop/RosterForLoop.js.map +1 -1
  12. package/components/Roundabout/CustomRoundabout.js +2 -2
  13. package/components/Roundabout/CustomRoundabout.js.map +1 -1
  14. package/components/Roundabout/roundabout.spec.js +22 -0
  15. package/components/Roundabout/roundabout.spec.js.map +1 -1
  16. package/components/shared/Checkbox/CheckboxOption.d.ts +4 -2
  17. package/components/shared/Checkbox/CheckboxOption.js.map +1 -1
  18. package/components/shared/Radio/RadioGroup.d.ts +1 -1
  19. package/components/shared/Radio/RadioGroup.js.map +1 -1
  20. package/esm/components/CheckboxGroup/CustomCheckboxGroup.d.ts +1 -1
  21. package/esm/components/CheckboxGroup/CustomCheckboxGroup.js.map +1 -1
  22. package/esm/components/Loop/Loop.d.ts +1 -1
  23. package/esm/components/Loop/Loop.js +5 -28
  24. package/esm/components/Loop/Loop.js.map +1 -1
  25. package/esm/components/Loop/utils.d.ts +8 -0
  26. package/esm/components/Loop/utils.js +62 -0
  27. package/esm/components/Loop/utils.js.map +1 -0
  28. package/esm/components/RosterForLoop/RosterForLoop.js +5 -29
  29. package/esm/components/RosterForLoop/RosterForLoop.js.map +1 -1
  30. package/esm/components/Roundabout/CustomRoundabout.js +2 -2
  31. package/esm/components/Roundabout/CustomRoundabout.js.map +1 -1
  32. package/esm/components/Roundabout/roundabout.spec.js +22 -0
  33. package/esm/components/Roundabout/roundabout.spec.js.map +1 -1
  34. package/esm/components/shared/Checkbox/CheckboxOption.d.ts +4 -2
  35. package/esm/components/shared/Checkbox/CheckboxOption.js.map +1 -1
  36. package/esm/components/shared/Radio/RadioGroup.d.ts +1 -1
  37. package/esm/components/shared/Radio/RadioGroup.js.map +1 -1
  38. package/esm/use-lunatic/commons/compile-controls.js +33 -7
  39. package/esm/use-lunatic/commons/compile-controls.js.map +1 -1
  40. package/esm/use-lunatic/props/propIterations.js +12 -1
  41. package/esm/use-lunatic/props/propIterations.js.map +1 -1
  42. package/esm/use-lunatic/reducer/controls/check-base-control.js.map +1 -1
  43. package/package.json +16 -3
  44. package/src/components/CheckboxGroup/CustomCheckboxGroup.tsx +1 -0
  45. package/src/components/Loop/Loop.tsx +6 -35
  46. package/src/components/Loop/utils.test.ts +39 -0
  47. package/src/components/Loop/utils.ts +73 -0
  48. package/src/components/RosterForLoop/RosterForLoop.tsx +3 -33
  49. package/src/components/Roundabout/CustomRoundabout.tsx +11 -1
  50. package/src/components/Roundabout/roundabout.spec.tsx +38 -0
  51. package/src/components/shared/Checkbox/CheckboxOption.tsx +3 -2
  52. package/src/components/shared/Radio/RadioGroup.tsx +1 -0
  53. package/src/stories/behaviour/controls/controls.stories.tsx +12 -3
  54. package/src/stories/behaviour/controls/data-standalone-loop.json +17 -0
  55. package/src/stories/behaviour/controls/source-standalone-loop.json +5503 -0
  56. package/src/stories/loop/source-paginated.json +1 -1
  57. package/src/stories/roundabout/roundabout.stories.tsx +13 -0
  58. package/src/stories/roundabout/sourceWithControl.json +613 -0
  59. package/src/use-lunatic/commons/compile-controls.ts +60 -11
  60. package/src/use-lunatic/props/propIterations.ts +30 -15
  61. package/src/use-lunatic/reducer/controls/check-base-control.ts +0 -1
  62. package/src/use-lunatic/use-lunatic-bug.test.ts +42 -0
  63. package/tsconfig.build.tsbuildinfo +1 -1
  64. package/use-lunatic/commons/compile-controls.js +31 -7
  65. package/use-lunatic/commons/compile-controls.js.map +1 -1
  66. package/use-lunatic/props/propIterations.js +12 -1
  67. package/use-lunatic/props/propIterations.js.map +1 -1
  68. package/use-lunatic/reducer/controls/check-base-control.js.map +1 -1
  69. /package/src/stories/behaviour/controls/{source-loop.json → source-roster-for-loop.json} +0 -0
@@ -1,4 +1,4 @@
1
- import { Fragment, useCallback, useState } from 'react';
1
+ import { Fragment } from 'react';
2
2
  import type { LunaticComponentProps } from '../type';
3
3
  import { Table, Tbody, Td, Tr, TableHeader } from '../shared/Table';
4
4
  import { times } from '../../utils/array';
@@ -9,9 +9,7 @@ import {
9
9
  getComponentErrors,
10
10
  } from '../shared/ComponentErrors/ComponentErrors';
11
11
  import { CustomLoop } from '../Loop/Loop';
12
-
13
- const DEFAULT_MIN_ROWS = 1;
14
- const DEFAULT_MAX_ROWS = 12;
12
+ import { useLoopUtils } from '../Loop/utils';
15
13
 
16
14
  /**
17
15
  * Loop displayed as a table
@@ -19,46 +17,18 @@ const DEFAULT_MAX_ROWS = 12;
19
17
  export const RosterForLoop = (
20
18
  props: LunaticComponentProps<'RosterForLoop'>
21
19
  ) => {
20
+ const { min, max, nbRows, addRow, removeRow } = useLoopUtils(props);
22
21
  const {
23
- value: valueMap,
24
- lines,
25
22
  errors,
26
- handleChanges,
27
23
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
24
  declarations,
29
25
  header,
30
- iterations,
31
26
  id,
32
27
  getComponents,
33
28
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
29
  label,
35
30
  ...otherProps // These props will be passed down to the child components
36
31
  } = props;
37
- const min = lines?.min ?? DEFAULT_MIN_ROWS;
38
- const max = lines?.max ?? DEFAULT_MAX_ROWS;
39
- const [nbRows, setNbRows] = useState(Math.max(min, iterations));
40
-
41
- const addRow = useCallback(() => {
42
- if (nbRows < max) {
43
- setNbRows(nbRows + 1);
44
- }
45
- }, [max, nbRows]);
46
-
47
- const removeRow = useCallback(() => {
48
- if (nbRows <= min) {
49
- return;
50
- }
51
- const newNbRows = nbRows - 1;
52
- setNbRows(newNbRows);
53
- // Downsize all variables by 1
54
- const newResponses = Object.entries(valueMap).map(([k, v]) => {
55
- return {
56
- name: k,
57
- value: v?.filter((_, i) => i < newNbRows),
58
- };
59
- });
60
- handleChanges(newResponses);
61
- }, [nbRows, min, valueMap, handleChanges]);
62
32
 
63
33
  if (nbRows === 0) {
64
34
  return null;
@@ -76,7 +76,16 @@ type Props = Pick<
76
76
 
77
77
  export const CustomRoundabout = slottableComponent<Props>(
78
78
  'Roundabout',
79
- ({ declarations, description, id, items, goToIteration, label, locked }) => {
79
+ ({
80
+ declarations,
81
+ description,
82
+ id,
83
+ items,
84
+ goToIteration,
85
+ label,
86
+ locked,
87
+ errors,
88
+ }) => {
80
89
  return (
81
90
  <div className="lunatic-roundabout">
82
91
  <div id={`roundabout-${id}`} className="lunatic-roundabout__label">
@@ -88,6 +97,7 @@ export const CustomRoundabout = slottableComponent<Props>(
88
97
  declarations={declarations}
89
98
  id={id}
90
99
  />
100
+ <ComponentErrors errors={errors} />
91
101
  <div className="lunatic-roundabout__items">
92
102
  {items.map((item, k) => (
93
103
  <RoundaboutItem
@@ -1,6 +1,12 @@
1
1
  import { render, fireEvent } from '@testing-library/react';
2
2
  import { CustomRoundabout } from './CustomRoundabout';
3
3
  import { describe, it, expect, vi, afterEach } from 'vitest';
4
+ import { LunaticError } from '../../use-lunatic/type';
5
+ import { ComponentErrors } from '../shared/ComponentErrors/ComponentErrors';
6
+
7
+ vi.mock('../shared/ComponentErrors/ComponentErrors', () => ({
8
+ ComponentErrors: vi.fn(),
9
+ }));
4
10
 
5
11
  describe('Roundabout', () => {
6
12
  const mockGoToIteration = vi.fn();
@@ -77,4 +83,36 @@ describe('Roundabout', () => {
77
83
  const completeButton = getByText('Complété');
78
84
  expect(completeButton).toBeDisabled();
79
85
  });
86
+
87
+ it('displays roundabout errors', () => {
88
+ const errors: LunaticError[] = [
89
+ {
90
+ id: 'error1',
91
+ errorMessage: 'Error 1 message',
92
+ criticality: 'ERROR',
93
+ typeOfControl: 'CONSISTENCY',
94
+ },
95
+ {
96
+ id: 'error2',
97
+ errorMessage: 'Error 2 message',
98
+ criticality: 'WARN',
99
+ typeOfControl: 'CONSISTENCY',
100
+ },
101
+ ];
102
+
103
+ render(
104
+ <CustomRoundabout
105
+ id="r1"
106
+ items={items}
107
+ goToIteration={mockGoToIteration}
108
+ locked={true}
109
+ errors={errors}
110
+ />
111
+ );
112
+
113
+ expect(ComponentErrors).toHaveBeenCalledWith(
114
+ expect.objectContaining({ errors }),
115
+ expect.anything()
116
+ );
117
+ });
80
118
  });
@@ -5,7 +5,7 @@ import { Label } from '../Label/Label';
5
5
  import { useKeyboardKey } from '../../../hooks/useKeyboardKey';
6
6
  import { CustomInput } from '../../Input/Input';
7
7
 
8
- export type CheckboxOptionProps = {
8
+ type CheckboxOptionProps = {
9
9
  disabled?: boolean;
10
10
  readOnly?: boolean;
11
11
  checked?: boolean;
@@ -21,6 +21,7 @@ export type CheckboxOptionProps = {
21
21
  detailMaxLength?: number;
22
22
  detailValue?: string | null;
23
23
  onDetailChange?: (value: string) => void;
24
+ shouldBeFiltered?: boolean;
24
25
  };
25
26
 
26
27
  function LunaticCheckboxOption({
@@ -39,7 +40,7 @@ function LunaticCheckboxOption({
39
40
  codeModality,
40
41
  shortcut,
41
42
  invalid,
42
- }: CheckboxOptionProps) {
43
+ }: Readonly<CheckboxOptionProps>) {
43
44
  const isEnabled = !readOnly && !disabled;
44
45
  const hasDetail = !!onDetailChange;
45
46
  const hasKeyboardShortcut = Boolean(shortcut && codeModality && isEnabled);
@@ -23,6 +23,7 @@ export type RadioGroupProps = Pick<
23
23
  | 'declarations'
24
24
  | 'orientation'
25
25
  | 'detailAlwaysDisplayed'
26
+ | 'shouldBeFiltered'
26
27
  > & {
27
28
  errors?: LunaticError[];
28
29
  clearable?: boolean;
@@ -5,7 +5,9 @@ import {
5
5
  } from '../../utils/Orchestrator';
6
6
  import simple from './source-simple.json';
7
7
  import simpleNum from './source-simple-numeric.json';
8
- import sourceLoop from './source-loop.json';
8
+ import sourceRosterForLoop from './source-roster-for-loop.json';
9
+ import sourceStandaloneLoop from './source-standalone-loop.json';
10
+ import dataStandaloneLoop from './data-standalone-loop.json';
9
11
  import sourceRoundabout from './source-roundabout.json';
10
12
  import boucleNTabDynamique from './source-boucles-n.json';
11
13
 
@@ -38,9 +40,16 @@ export const SimpleNum: OrchestratorStory = {
38
40
 
39
41
  export const LinkedLoop: OrchestratorStory = {};
40
42
 
41
- export const Loop: OrchestratorStory = {
43
+ export const RosterForLoop: OrchestratorStory = {
42
44
  args: {
43
- source: sourceLoop,
45
+ source: sourceRosterForLoop,
46
+ },
47
+ };
48
+
49
+ export const StandaloneLoop: OrchestratorStory = {
50
+ args: {
51
+ source: sourceStandaloneLoop,
52
+ data: dataStandaloneLoop,
44
53
  },
45
54
  };
46
55
 
@@ -0,0 +1,17 @@
1
+ {
2
+ "EXTERNAL": {
3
+ "NIR": ["23456", "23456", "23456", "23456", "23456", "12345"],
4
+ "CODE_CC": ["CODE", "CODE", "CODE", "CODE", "CODE", "CODE"],
5
+ "NBSAL_INT": "6",
6
+ "LIBELLE_CC": ["LIB CC", "LIB CC", "LIB CC", "LIB CC", "LIB CC", "LIB CC"],
7
+ "NUM_ORDRE_SALARIE": ["1", "2", "3", "4", "5", "6"],
8
+ "NOM_COMPLET_SALARIE": [
9
+ "THREEPWOOD GUYBRUSH",
10
+ "LINK",
11
+ "JANE DOE",
12
+ "JOHN DOE",
13
+ "IL FAIT CHAUD",
14
+ "POISSON STEVE"
15
+ ]
16
+ }
17
+ }