@inseefr/lunatic 3.4.8 → 3.4.9

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 (160) hide show
  1. package/components/CheckboxGroup/CheckboxGroup.js +3 -1
  2. package/components/CheckboxGroup/CheckboxGroup.js.map +1 -1
  3. package/components/CheckboxGroup/CustomCheckboxGroup.d.ts +1 -1
  4. package/components/CheckboxGroup/CustomCheckboxGroup.js +2 -5
  5. package/components/CheckboxGroup/CustomCheckboxGroup.js.map +1 -1
  6. package/components/CheckboxOne/CheckboxOne.js +3 -1
  7. package/components/CheckboxOne/CheckboxOne.js.map +1 -1
  8. package/components/Datepicker/Datepicker.js +7 -1
  9. package/components/Datepicker/Datepicker.js.map +1 -1
  10. package/components/Input/Input.js +3 -1
  11. package/components/Input/Input.js.map +1 -1
  12. package/components/InputNumber/InputNumber.spec.js +12 -0
  13. package/components/InputNumber/InputNumber.spec.js.map +1 -1
  14. package/components/InputNumber/InputNumberThousand.js +3 -1
  15. package/components/InputNumber/InputNumberThousand.js.map +1 -1
  16. package/components/Radio/Radio.d.ts +1 -0
  17. package/components/Radio/Radio.js +3 -1
  18. package/components/Radio/Radio.js.map +1 -1
  19. package/components/library.d.ts +1 -0
  20. package/components/shared/Checkbox/CheckboxOption.d.ts +4 -0
  21. package/components/shared/Checkbox/CheckboxOption.js +4 -2
  22. package/components/shared/Checkbox/CheckboxOption.js.map +1 -1
  23. package/components/shared/Checkbox/CheckboxOption.spec.js +14 -0
  24. package/components/shared/Checkbox/CheckboxOption.spec.js.map +1 -1
  25. package/components/shared/Radio/RadioGroup.d.ts +1 -1
  26. package/components/shared/Radio/RadioGroup.js +2 -2
  27. package/components/shared/Radio/RadioGroup.js.map +1 -1
  28. package/components/shared/Radio/RadioOption.d.ts +1 -0
  29. package/components/shared/Radio/RadioOption.js +2 -2
  30. package/components/shared/Radio/RadioOption.js.map +1 -1
  31. package/components/shared/Radio/RadioOption.spec.js +12 -0
  32. package/components/shared/Radio/RadioOption.spec.js.map +1 -1
  33. package/components/type.d.ts +3 -0
  34. package/esm/components/CheckboxGroup/CheckboxGroup.js +3 -1
  35. package/esm/components/CheckboxGroup/CheckboxGroup.js.map +1 -1
  36. package/esm/components/CheckboxGroup/CustomCheckboxGroup.d.ts +1 -1
  37. package/esm/components/CheckboxGroup/CustomCheckboxGroup.js +2 -6
  38. package/esm/components/CheckboxGroup/CustomCheckboxGroup.js.map +1 -1
  39. package/esm/components/CheckboxOne/CheckboxOne.js +3 -1
  40. package/esm/components/CheckboxOne/CheckboxOne.js.map +1 -1
  41. package/esm/components/Datepicker/Datepicker.js +7 -1
  42. package/esm/components/Datepicker/Datepicker.js.map +1 -1
  43. package/esm/components/Input/Input.js +3 -1
  44. package/esm/components/Input/Input.js.map +1 -1
  45. package/esm/components/InputNumber/InputNumber.spec.js +12 -0
  46. package/esm/components/InputNumber/InputNumber.spec.js.map +1 -1
  47. package/esm/components/InputNumber/InputNumberThousand.js +3 -1
  48. package/esm/components/InputNumber/InputNumberThousand.js.map +1 -1
  49. package/esm/components/Radio/Radio.d.ts +1 -0
  50. package/esm/components/Radio/Radio.js +3 -1
  51. package/esm/components/Radio/Radio.js.map +1 -1
  52. package/esm/components/library.d.ts +1 -0
  53. package/esm/components/shared/Checkbox/CheckboxOption.d.ts +4 -0
  54. package/esm/components/shared/Checkbox/CheckboxOption.js +4 -2
  55. package/esm/components/shared/Checkbox/CheckboxOption.js.map +1 -1
  56. package/esm/components/shared/Checkbox/CheckboxOption.spec.js +14 -0
  57. package/esm/components/shared/Checkbox/CheckboxOption.spec.js.map +1 -1
  58. package/esm/components/shared/Radio/RadioGroup.d.ts +1 -1
  59. package/esm/components/shared/Radio/RadioGroup.js +2 -2
  60. package/esm/components/shared/Radio/RadioGroup.js.map +1 -1
  61. package/esm/components/shared/Radio/RadioOption.d.ts +1 -0
  62. package/esm/components/shared/Radio/RadioOption.js +2 -2
  63. package/esm/components/shared/Radio/RadioOption.js.map +1 -1
  64. package/esm/components/shared/Radio/RadioOption.spec.js +12 -0
  65. package/esm/components/shared/Radio/RadioOption.spec.js.map +1 -1
  66. package/esm/components/type.d.ts +3 -0
  67. package/esm/main.css +5 -2
  68. package/esm/main.css.map +1 -1
  69. package/esm/use-lunatic/commons/fill-components/fill-components.d.ts +1 -0
  70. package/esm/use-lunatic/commons/fill-components/fill-components.js +1 -1
  71. package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  72. package/esm/use-lunatic/commons/page.js +4 -1
  73. package/esm/use-lunatic/commons/page.js.map +1 -1
  74. package/esm/use-lunatic/lunatic-context.d.ts +7 -1
  75. package/esm/use-lunatic/lunatic-context.js +7 -1
  76. package/esm/use-lunatic/lunatic-context.js.map +1 -1
  77. package/esm/use-lunatic/props/getComponentTypeProps.d.ts +3 -0
  78. package/esm/use-lunatic/props/propOptions.d.ts +1 -1
  79. package/esm/use-lunatic/props/propOptions.js.map +1 -1
  80. package/esm/use-lunatic/reducer/reducerInitializer.d.ts +2 -1
  81. package/esm/use-lunatic/reducer/reducerInitializer.js +3 -1
  82. package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
  83. package/esm/use-lunatic/type.d.ts +7 -0
  84. package/esm/use-lunatic/use-lunatic.js +6 -1
  85. package/esm/use-lunatic/use-lunatic.js.map +1 -1
  86. package/main.css +5 -2
  87. package/main.css.map +1 -1
  88. package/package.json +6 -1
  89. package/src/components/CheckboxGroup/CheckboxGroup.tsx +3 -0
  90. package/src/components/CheckboxGroup/CustomCheckboxGroup.tsx +3 -14
  91. package/src/components/CheckboxOne/CheckboxOne.tsx +3 -0
  92. package/src/components/Datepicker/Datepicker.tsx +8 -1
  93. package/src/components/Input/Input.tsx +4 -0
  94. package/src/components/Input/__snapshots__/Input.spec.tsx.snap +2 -0
  95. package/src/components/InputNumber/InputNumber.spec.tsx +20 -0
  96. package/src/components/InputNumber/InputNumberThousand.tsx +4 -0
  97. package/src/components/InputNumber/__snapshots__/InputNumber.spec.tsx.snap +2 -0
  98. package/src/components/Radio/Radio.tsx +3 -0
  99. package/src/components/RosterForLoop/__snapshots__/RosterForLoop.spec.tsx.snap +2 -0
  100. package/src/components/shared/Checkbox/CheckboxOption.spec.tsx +21 -0
  101. package/src/components/shared/Checkbox/CheckboxOption.tsx +19 -0
  102. package/src/components/shared/Radio/RadioGroup.tsx +3 -0
  103. package/src/components/shared/Radio/RadioOption.spec.tsx +36 -0
  104. package/src/components/shared/Radio/RadioOption.tsx +5 -1
  105. package/src/components/type.ts +3 -0
  106. package/src/css/components/CheckboxOne.scss +1 -1
  107. package/src/css/components/CheckboxOption.scss +14 -18
  108. package/src/css/components/Combobox.scss +3 -2
  109. package/src/css/components/Datepicker.scss +8 -8
  110. package/src/css/components/Declarations.scss +1 -1
  111. package/src/css/components/Dragger.scss +6 -6
  112. package/src/css/components/Duration.scss +4 -4
  113. package/src/css/components/IconButton.scss +4 -2
  114. package/src/css/components/Input.scss +3 -0
  115. package/src/css/components/Missing.scss +1 -1
  116. package/src/css/components/Roundabout.scss +3 -3
  117. package/src/css/components/Suggester.scss +2 -2
  118. package/src/css/components/Table.scss +9 -7
  119. package/src/css/main.scss +167 -167
  120. package/src/stories/behaviour/filter/dataLoop.json +22 -0
  121. package/src/stories/behaviour/filter/filter.stories.jsx +36 -0
  122. package/src/stories/behaviour/filter/source.json +238 -0
  123. package/src/stories/behaviour/filter/sourceLoop.json +372 -0
  124. package/src/stories/behaviour/missing/missing.stories.jsx +9 -0
  125. package/src/stories/behaviour/paste/test.stories.jsx +5 -0
  126. package/src/stories/checkbox-group/checkbox-group.stories.jsx +25 -6
  127. package/src/stories/checkbox-one/checkboxOne.stories.jsx +24 -2
  128. package/src/stories/overview/overview.stories.jsx +8 -1
  129. package/src/stories/radio/radio.stories.jsx +46 -6
  130. package/src/stories/utils/default-arg-types.js +12 -1
  131. package/src/stories/utils/default-args.js +3 -0
  132. package/src/stories/utils/orchestrator.jsx +11 -1
  133. package/src/stories/utils/orchestrator.scss +9 -7
  134. package/src/stories/utils/overview.scss +0 -1
  135. package/src/use-lunatic/commons/fill-components/fill-components.ts +4 -1
  136. package/src/use-lunatic/commons/page.ts +4 -1
  137. package/src/use-lunatic/lunatic-context.tsx +9 -0
  138. package/src/use-lunatic/props/propOptions.ts +2 -1
  139. package/src/use-lunatic/reducer/reducerInitializer.tsx +4 -0
  140. package/src/use-lunatic/type.ts +5 -0
  141. package/src/use-lunatic/use-lunatic.test.ts +52 -0
  142. package/src/use-lunatic/use-lunatic.ts +7 -0
  143. package/tsconfig.build.tsbuildinfo +1 -1
  144. package/use-lunatic/commons/fill-components/fill-components.d.ts +1 -0
  145. package/use-lunatic/commons/fill-components/fill-components.js +1 -1
  146. package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
  147. package/use-lunatic/commons/page.js +4 -1
  148. package/use-lunatic/commons/page.js.map +1 -1
  149. package/use-lunatic/lunatic-context.d.ts +7 -1
  150. package/use-lunatic/lunatic-context.js +9 -2
  151. package/use-lunatic/lunatic-context.js.map +1 -1
  152. package/use-lunatic/props/getComponentTypeProps.d.ts +3 -0
  153. package/use-lunatic/props/propOptions.d.ts +1 -1
  154. package/use-lunatic/props/propOptions.js.map +1 -1
  155. package/use-lunatic/reducer/reducerInitializer.d.ts +2 -1
  156. package/use-lunatic/reducer/reducerInitializer.js +3 -1
  157. package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
  158. package/use-lunatic/type.d.ts +7 -0
  159. package/use-lunatic/use-lunatic.js +6 -1
  160. package/use-lunatic/use-lunatic.js.map +1 -1
@@ -18,7 +18,7 @@
18
18
  .story-with-sidebar aside label {
19
19
  display: block;
20
20
  font-weight: bold;
21
- margin-bottom: .3em;
21
+ margin-bottom: 0.3em;
22
22
  }
23
23
 
24
24
  .story-with-sidebar aside {
@@ -26,7 +26,9 @@
26
26
  grid-template-columns: 1fr;
27
27
  gap: 1rem;
28
28
  padding: 1rem;
29
- box-shadow: 0 4px 3px rgba(0, 0, 0, 0.07), 0px 2px 2px rgba(0, 0, 0, 0.06);
29
+ box-shadow:
30
+ 0 4px 3px rgba(0, 0, 0, 0.07),
31
+ 0px 2px 2px rgba(0, 0, 0, 0.06);
30
32
  background-color: #f1f5f9;
31
33
 
32
34
  .pagination {
@@ -36,8 +38,8 @@
36
38
 
37
39
  .story-pager h3 {
38
40
  font-size: 1rem;
39
- padding-bottom: .3rem;
40
- margin-bottom: .5rem;
41
+ padding-bottom: 0.3rem;
42
+ margin-bottom: 0.5rem;
41
43
  border-bottom: solid 1px rgba(0, 0, 0, 0.3);
42
44
  }
43
45
 
@@ -46,7 +48,7 @@
46
48
  padding: 0 0 0 20px;
47
49
  line-height: 1.4;
48
50
  font-size: 0.9rem;
49
- color: rgba(0, 0, 0, 0.75)
51
+ color: rgba(0, 0, 0, 0.75);
50
52
  }
51
53
 
52
54
  .story-pager ul strong {
@@ -57,8 +59,8 @@
57
59
  color: #721c24;
58
60
  background-color: #f8d7da;
59
61
  position: relative;
60
- padding: .75rem 1.25rem;
62
+ padding: 0.75rem 1.25rem;
61
63
  margin-bottom: 1rem;
62
64
  border: 1px solid #f5c6cb;
63
- border-radius: .25rem;
65
+ border-radius: 0.25rem;
64
66
  }
@@ -35,4 +35,3 @@
35
35
  list-style: none;
36
36
  }
37
37
  }
38
-
@@ -14,6 +14,7 @@ import { getIterationsProp } from '../../props/propIterations';
14
14
  import { getOptionsProp } from '../../props/propOptions';
15
15
 
16
16
  type FillComponentArgs = {
17
+ disableFilters?: boolean;
17
18
  handleChanges: LunaticChangesHandler;
18
19
  executeExpression: LunaticReducerState['executeExpression'];
19
20
  goToPage: LunaticState['goToPage'];
@@ -71,5 +72,7 @@ export function fillComponents(
71
72
  ): LunaticComponentProps[] {
72
73
  return components
73
74
  .map((component) => fillComponent(component, state))
74
- .filter(({ conditionFilter }) => conditionFilter ?? true);
75
+ .filter(
76
+ ({ conditionFilter }) => state.disableFilters || (conditionFilter ?? true)
77
+ );
75
78
  }
@@ -24,10 +24,13 @@ export function pageStringToNumbers(page: string): number[] {
24
24
  * if no components can be displayed on this page (using filter)
25
25
  */
26
26
  export function isPageEmpty(state: LunaticReducerState): boolean {
27
- const { executeExpression, pager } = state;
27
+ const { executeExpression, pager, options } = state;
28
28
  const { iteration } = pager;
29
29
  const components = getComponentsFromState(state);
30
30
  const visibleComponents = components.filter((component) => {
31
+ if (options.disableFilters) {
32
+ return true;
33
+ }
31
34
  if ('conditionFilter' in component && component.conditionFilter) {
32
35
  return executeConditionFilter(
33
36
  component.conditionFilter,
@@ -15,6 +15,7 @@ const LunaticContext = createContext({
15
15
  missingShortcut: { dontKnow: '', refused: '' },
16
16
  dontKnowButton: D.DK,
17
17
  refusedButton: D.RF,
18
+ componentsOptions: { detailAlwaysDisplayed: false },
18
19
  });
19
20
  /** Provide `missing` `missingStrategy`, `shortcut` and `missingShortcut`, `dontKnowButton`, `refusedButton` to Missing component
20
21
  * to manage non-response buttons and shortcut */
@@ -37,6 +38,11 @@ export const useLunaticMissing = () => {
37
38
  };
38
39
  };
39
40
 
41
+ export const useLunaticComponentsOptions = () => {
42
+ const { componentsOptions } = useContext(LunaticContext);
43
+ return componentsOptions;
44
+ };
45
+
40
46
  /** Provide `management` to display data states [COLLECTED,EDITED,FORCED] */
41
47
  export const useLunaticManagement = () => {
42
48
  return useContext(LunaticContext).management;
@@ -50,6 +56,7 @@ export function createLunaticProvider({
50
56
  missingShortcut,
51
57
  dontKnowButton,
52
58
  refusedButton,
59
+ componentsOptions,
53
60
  }: {
54
61
  management: boolean;
55
62
  missing: boolean;
@@ -58,6 +65,7 @@ export function createLunaticProvider({
58
65
  missingShortcut: { dontKnow: string; refused: string };
59
66
  dontKnowButton: string;
60
67
  refusedButton: string;
68
+ componentsOptions: { detailAlwaysDisplayed: boolean };
61
69
  }): FunctionComponent<PropsWithChildren> {
62
70
  const value = {
63
71
  management,
@@ -67,6 +75,7 @@ export function createLunaticProvider({
67
75
  missingShortcut,
68
76
  dontKnowButton,
69
77
  refusedButton,
78
+ componentsOptions,
70
79
  };
71
80
  return function Provider({ children }: PropsWithChildren) {
72
81
  return (
@@ -8,12 +8,13 @@ import type { DeepTranslateExpression } from '../commons/fill-components/fill-co
8
8
  import { isNumber } from '../../utils/number';
9
9
  import type { LunaticVariablesStore } from '../commons/variables/lunatic-variables-store';
10
10
 
11
+ /* Used for radio option and checkbox one option */
11
12
  export type InterpretedOption = {
12
13
  label: ReactNode;
13
14
  value?: string;
14
15
  checked?: boolean;
15
- detailLabel?: ReactNode;
16
16
  description?: ReactNode;
17
+ detailLabel?: ReactNode;
17
18
  detailValue?: string | null;
18
19
  onDetailChange?: (value: string) => void;
19
20
  onCheck?: () => void;
@@ -35,6 +35,7 @@ const baseState = {
35
35
  overview: [],
36
36
  updateBindings: () => {},
37
37
  executeExpression: <T,>() => null as T,
38
+ options: { disableFilters: false },
38
39
  } satisfies LunaticReducerState;
39
40
 
40
41
  export function reducerInitializer({
@@ -44,6 +45,7 @@ export function reducerInitializer({
44
45
  initialPage = '1',
45
46
  lastReachedPage = undefined,
46
47
  withOverview = false,
48
+ disableFilters = false,
47
49
  getReferentiel,
48
50
  onVariableChange,
49
51
  logger,
@@ -54,6 +56,7 @@ export function reducerInitializer({
54
56
  initialPage?: LunaticOptions['initialPage'];
55
57
  lastReachedPage?: LunaticOptions['lastReachedPage'];
56
58
  withOverview?: LunaticOptions['withOverview'];
59
+ disableFilters?: LunaticOptions['disableFilters'];
57
60
  getReferentiel?: LunaticOptions['getReferentiel'];
58
61
  onVariableChange: RefObject<LunaticOptions['onVariableChange']>;
59
62
  logger: LunaticLogger;
@@ -145,6 +148,7 @@ export function reducerInitializer({
145
148
  overview: withOverview ? buildOverview(source) : [],
146
149
  updateBindings,
147
150
  executeExpression,
151
+ options: { disableFilters },
148
152
  });
149
153
  }
150
154
 
@@ -131,9 +131,13 @@ export type LunaticReducerState = {
131
131
  value: unknown,
132
132
  options: { iteration?: number[] }
133
133
  ) => unknown;
134
+ options: {
135
+ disableFilters?: boolean;
136
+ };
134
137
  };
135
138
 
136
139
  export type LunaticOptions = {
140
+ disableFilters?: boolean;
137
141
  features?: ('MD' | 'VTL')[];
138
142
  preferences?: ['COLLECTED'];
139
143
  savingType?: 'COLLECTED';
@@ -157,6 +161,7 @@ export type LunaticOptions = {
157
161
  // Enable change tracking to keep a track of what variable changed (allow using getChangedData())
158
162
  trackChanges?: boolean;
159
163
  logger?: LunaticLogger;
164
+ componentsOptions?: { detailAlwaysDisplayed?: boolean };
160
165
  };
161
166
 
162
167
  // Type representing the return type of "useLunatic()"
@@ -179,6 +179,58 @@ describe('use-lunatic()', () => {
179
179
  });
180
180
  });
181
181
 
182
+ describe('disable filters', () => {
183
+ const lunaticConfigurationWithoutDisableFilters = {
184
+ management: false,
185
+ activeControls: false,
186
+ initialPage: '1' as PageTag,
187
+ getStoreInfo: () => {},
188
+ missing: false,
189
+ shortcut: false,
190
+ activeGoNextForMissing: false,
191
+ showOverview: false,
192
+ filterDescription: true,
193
+ };
194
+
195
+ it('should filter out some components by default', function () {
196
+ const { result } = renderHook(() =>
197
+ useLunatic(
198
+ sourceLogement as any,
199
+ undefined,
200
+ lunaticConfigurationWithoutDisableFilters
201
+ )
202
+ );
203
+ act(() => result.current.goToPage({ page: '3' }));
204
+ const currentPage = result.current.pageTag;
205
+ expect(currentPage).not.toBe('3');
206
+ });
207
+ it('should filter out some components when false', function () {
208
+ const { result } = renderHook(() =>
209
+ useLunatic(sourceLogement as any, undefined, {
210
+ ...lunaticConfigurationWithoutDisableFilters,
211
+ disableFilters: false,
212
+ })
213
+ );
214
+ act(() => result.current.goToPage({ page: '3' }));
215
+ const currentPage = result.current.pageTag;
216
+ expect(currentPage).not.toBe('3');
217
+ });
218
+ it('should not filter any component when true', function () {
219
+ const { result } = renderHook(() =>
220
+ useLunatic(sourceLogement as any, undefined, {
221
+ ...lunaticConfigurationWithoutDisableFilters,
222
+ disableFilters: true,
223
+ })
224
+ );
225
+ act(() => result.current.goToPage({ page: '3' }));
226
+ const currentPage = result.current.pageTag;
227
+ expect(currentPage).toBe('3');
228
+
229
+ const components = result.current.getComponents();
230
+ expect(components.length).toBe(1);
231
+ });
232
+ });
233
+
182
234
  describe('cleaning', () => {
183
235
  it('should handle cleaning in a loop', () => {
184
236
  const { result } = renderHook(() =>
@@ -42,6 +42,7 @@ const DEFAULT_DONT_KNOW = D.DK;
42
42
  const DEFAULT_REFUSED = D.RF;
43
43
 
44
44
  const defaultOptions = {
45
+ disableFilters: false,
45
46
  features: DEFAULT_FEATURES,
46
47
  preferences: DEFAULT_PREFERENCES,
47
48
  savingType: COLLECTED,
@@ -62,6 +63,7 @@ const defaultOptions = {
62
63
  refusedButton: DEFAULT_REFUSED,
63
64
  trackChanges: false,
64
65
  logger: ConsoleLogger,
66
+ componentsOptions: { detailAlwaysDisplayed: false },
65
67
  } satisfies LunaticOptions;
66
68
 
67
69
  export function useLunatic(
@@ -71,6 +73,7 @@ export function useLunatic(
71
73
  ) {
72
74
  const options = mergeDefault(argOptions, defaultOptions);
73
75
  const {
76
+ disableFilters,
74
77
  management,
75
78
  missing,
76
79
  missingStrategy,
@@ -82,6 +85,7 @@ export function useLunatic(
82
85
  trackChanges,
83
86
  preferences,
84
87
  logger,
88
+ componentsOptions,
85
89
  } = options;
86
90
 
87
91
  // Help debug with warnings for options expected to be memoized
@@ -113,6 +117,7 @@ export function useLunatic(
113
117
  missingShortcut,
114
118
  dontKnowButton,
115
119
  refusedButton,
120
+ componentsOptions,
116
121
  }),
117
122
  [
118
123
  management,
@@ -122,6 +127,7 @@ export function useLunatic(
122
127
  missingShortcut,
123
128
  dontKnowButton,
124
129
  refusedButton,
130
+ componentsOptions,
125
131
  ]
126
132
  );
127
133
 
@@ -179,6 +185,7 @@ export function useLunatic(
179
185
  const { isFirstPage, isLastPage } = isFirstLastPage(state.pager);
180
186
 
181
187
  const components = fillComponents(getComponentsFromState(state), {
188
+ disableFilters,
182
189
  handleChanges,
183
190
  preferences,
184
191
  goToPage,