@inseefr/lunatic 0.3.1-experimental → 0.3.2-experimental

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 (51) hide show
  1. package/lib/index.js +192 -189
  2. package/lib/index.js.map +1 -1
  3. package/package.json +2 -2
  4. package/src/components/component-wrapper/controls/validators/datepicker.js +25 -14
  5. package/src/components/component-wrapper/missing/component.js +37 -17
  6. package/src/components/datepicker/component.js +8 -12
  7. package/src/components/declarations/wrappers/input-declarations-wrapper.js +3 -2
  8. package/src/components/loop-constructor/block/index.js +1 -1
  9. package/src/components/loop-constructor/index.js +1 -1
  10. package/src/components/loop-constructor/roster/index.js +1 -1
  11. package/src/components/loop-constructor/wrapper/body-component.js +3 -0
  12. package/src/components/loop-constructor/wrapper/build-components.js +33 -33
  13. package/src/components/loop-constructor/wrapper/index.js +1 -1
  14. package/src/components/suggester/components/panel/option-container.js +1 -1
  15. package/src/components/suggester/suggester-wrapper.js +3 -3
  16. package/src/components/table/table.js +3 -1
  17. package/src/stories/loop-constructor/README.md +27 -27
  18. package/src/stories/loop-constructor/data-input-forced.json +64 -64
  19. package/src/stories/loop-constructor/data-input.json +100 -100
  20. package/src/stories/loop-constructor/data-loop-forced.json +66 -66
  21. package/src/stories/loop-constructor/data-loop-static-forced.json +66 -66
  22. package/src/stories/loop-constructor/data-loop-static.json +81 -81
  23. package/src/stories/loop-constructor/data-loop.json +81 -81
  24. package/src/stories/loop-constructor/data-roster-forced.json +68 -68
  25. package/src/stories/loop-constructor/data-roster.json +83 -83
  26. package/src/stories/loop-constructor/loop-constructor.stories.js +180 -180
  27. package/src/stories/questionnaire/arithmetic-management.json +47 -0
  28. package/src/stories/questionnaire/logement-queen.json +23390 -22706
  29. package/src/stories/questionnaire/questionnaire.stories.js +14 -14
  30. package/src/stories/suggester/data.json +4 -1
  31. package/src/stories/suggester/suggester-workers.stories.js +4 -1
  32. package/src/stories/utils/orchestrator-split.js +117 -0
  33. package/src/tests/utils/to-expose/handler/results/res-input-edited.json +1 -1
  34. package/src/tests/utils/to-expose/state/state.spec.js +59 -59
  35. package/src/utils/lib/index.js +1 -0
  36. package/src/utils/lib/pagination/navigation/shared.js +5 -5
  37. package/src/utils/lib/splitting.js +110 -0
  38. package/src/utils/suggester-workers/commons-tokenizer/create-entity-tokenizer.js +4 -2
  39. package/src/utils/suggester-workers/commons-tokenizer/filters/{filter-accents-to-lower.js → filter-accents.js} +2 -2
  40. package/src/utils/suggester-workers/commons-tokenizer/filters/{filter-accents-to-lower.spec.js → filter-accents.spec.js} +1 -1
  41. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.js +27 -1
  42. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.js +10 -0
  43. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.spec.js +12 -0
  44. package/src/utils/suggester-workers/commons-tokenizer/index.js +1 -1
  45. package/src/utils/to-expose/handler.js +47 -28
  46. package/src/utils/to-expose/hooks/filter-components.js +106 -106
  47. package/src/utils/to-expose/hooks/index.js +2 -1
  48. package/src/utils/to-expose/hooks/lunatic-split.js +407 -0
  49. package/src/utils/to-expose/hooks/lunatic.js +16 -2
  50. package/src/utils/to-expose/index.js +11 -11
  51. package/src/utils/to-expose/state.js +23 -15
@@ -43,10 +43,10 @@ export const updateQuestionnaire =
43
43
  { newVariables: variables, refs: [] }
44
44
  );
45
45
  const { newVariables, refs: r } = varsAndRefs;
46
- const newVariablesWithCalculated =
47
- valueType === C.COLLECTED
48
- ? addCalculatedVars(newVariables, updatedValues)(logFunction)
49
- : newVariables;
46
+ const newVariablesWithCalculated = addCalculatedVars(
47
+ newVariables,
48
+ updatedValues
49
+ )(logFunction, preferences);
50
50
  const collectedVars = newVariables[C.COLLECTED];
51
51
  const newComponents = components.map((c) => {
52
52
  if (r.includes(c.id)) return buildFilledComponent(collectedVars)(c);
@@ -92,41 +92,60 @@ export const buildNewValue =
92
92
  return lastValue === value ? null : value;
93
93
  };
94
94
 
95
- const getCollectedAndExternal = (variables) => {
95
+ // Separate methods to avoid perf issue on collect simplest use case
96
+ const getCollectedAndExternal = (preferences) => (variables) => {
96
97
  const { COLLECTED } = variables;
97
- const collected = Object.entries(COLLECTED).reduce(
98
+ if (preferences.length === 1 && preferences[0] === 'COLLECTED')
99
+ return getCollectedAndExternalSimple(COLLECTED);
100
+ return getCollectedAndExternalByPreferences(preferences)(COLLECTED);
101
+ };
102
+
103
+ const getCollectedAndExternalSimple = (variables) => {
104
+ const collected = Object.entries(variables).reduce(
98
105
  (acc, [k, { values }]) => ({ ...acc, [k]: values.COLLECTED }),
99
106
  {}
100
107
  );
101
108
  return { ...collected, ...variables.EXTERNAL };
102
109
  };
103
110
 
104
- const addCalculatedVars = (variables, updatedValues) => (logFunction) => {
105
- if (
106
- !variables[C.CALCULATED] ||
107
- Object.keys(variables[C.CALCULATED]).length === 0
108
- )
109
- return variables;
111
+ const getCollectedAndExternalByPreferences = (preferences) => (variables) => {
112
+ const collected = Object.entries(variables).reduce((acc, [k, { values }]) => {
113
+ const v = preferences.reduce((acc, p) => {
114
+ const value = values[p];
115
+ return [null, ''].includes(value) ? acc : value;
116
+ }, null);
117
+ return { ...acc, [k]: v };
118
+ }, {});
119
+ return { ...collected, ...variables.EXTERNAL };
120
+ };
110
121
 
111
- if (isDev) {
112
- console.log('Start var calculation');
113
- var start = new Date().getTime();
114
- }
122
+ const addCalculatedVars =
123
+ (variables, updatedValues) => (logFunction, preferences) => {
124
+ if (
125
+ !variables[C.CALCULATED] ||
126
+ Object.keys(variables[C.CALCULATED]).length === 0
127
+ )
128
+ return variables;
129
+
130
+ if (isDev) {
131
+ console.log('Start var calculation');
132
+ var start = new Date().getTime();
133
+ }
115
134
 
116
- const { COLLECTED, EXTERNAL, CALCULATED: calculatedVariables } = variables;
135
+ const { COLLECTED, EXTERNAL, CALCULATED: calculatedVariables } = variables;
117
136
 
118
- const updatedVars = Object.keys(updatedValues);
137
+ const updatedVars = Object.keys(updatedValues);
119
138
 
120
- const bindings = getCollectedAndExternal(variables);
139
+ const bindings = getCollectedAndExternal(preferences)(variables);
121
140
 
122
- const CALCULATED = getCalculatedVariables(calculatedVariables)({
123
- bindings,
124
- updatedVars,
125
- logFunction,
126
- });
141
+ const CALCULATED = getCalculatedVariables(calculatedVariables)({
142
+ bindings,
143
+ updatedVars,
144
+ logFunction,
145
+ });
127
146
 
128
- if (isDev)
129
- console.log(`End var calculation: ${new Date().getTime() - start} ms`);
147
+ if (isDev)
148
+ console.log(`End var calculation: ${new Date().getTime() - start} ms`);
130
149
 
131
- return { EXTERNAL, COLLECTED, CALCULATED };
132
- };
150
+ return { EXTERNAL, COLLECTED, CALCULATED };
151
+ };
@@ -1,106 +1,106 @@
1
- import { interpret } from '../interpret';
2
- import { isDev, buildVectorialBindings } from '../../lib';
3
-
4
- let cache = {};
5
-
6
- const customFilterPagination = ({ page }, pagination, currentPage) => {
7
- return pagination ? currentPage.split('.')[0] === page : true;
8
- };
9
-
10
- const filterComponents = ({ components, updatedVars, features, bindings }) => {
11
- const localCache = {};
12
- const filtered = components.filter(({ conditionFilter }) => {
13
- if (!conditionFilter || !conditionFilter.value) return true;
14
- const { bindingDependencies, value } = conditionFilter;
15
- if (localCache[value] !== undefined) return localCache[value];
16
- if (
17
- (!bindingDependencies ||
18
- !updatedVars.some((t) => bindingDependencies.includes(t))) &&
19
- cache[value] !== undefined
20
- )
21
- return cache[value];
22
- const vectorialBindings = buildVectorialBindings(bindings);
23
- const inter = interpret(features)(vectorialBindings)(value);
24
- localCache[value] = inter;
25
- return inter;
26
- });
27
- cache = { ...cache, ...localCache };
28
- return filtered;
29
- };
30
-
31
- const buildComponents = ({
32
- components,
33
- management,
34
- bindings,
35
- features,
36
- page,
37
- pagination,
38
- todo,
39
- }) => {
40
- if (management && !pagination) return components;
41
-
42
- if (management && pagination)
43
- return components.filter((c) =>
44
- customFilterPagination(c, pagination, page)
45
- );
46
-
47
- if (isDev) {
48
- console.log('Start filter');
49
- var start = new Date().getTime();
50
- }
51
-
52
- const updatedVars = Object.keys(todo);
53
-
54
- if (!pagination) {
55
- const filtered = filterComponents({
56
- components,
57
- updatedVars,
58
- features,
59
- bindings,
60
- });
61
- if (isDev) console.log(`End filter: ${new Date().getTime() - start} ms`);
62
- return filtered;
63
- }
64
-
65
- const pageComponents = components.filter((c) =>
66
- customFilterPagination(c, pagination, page)
67
- );
68
-
69
- const pageComponentsFiltered = filterComponents({
70
- components: pageComponents,
71
- updatedVars,
72
- features,
73
- bindings,
74
- });
75
- if (isDev) console.log(`End filter: ${new Date().getTime() - start}`);
76
- return pageComponentsFiltered;
77
- };
78
-
79
- let oldComponents = [];
80
- let memoryTodo = {};
81
-
82
- export const useFilterComponents = ({
83
- questionnaire,
84
- management,
85
- bindings,
86
- features,
87
- page,
88
- pagination,
89
- todo,
90
- }) => {
91
- if (Object.keys(todo).length > 0) {
92
- memoryTodo = todo;
93
- return oldComponents;
94
- }
95
- const components = buildComponents({
96
- components: questionnaire.components,
97
- management,
98
- bindings,
99
- features,
100
- page,
101
- pagination,
102
- todo: memoryTodo,
103
- });
104
- oldComponents = components;
105
- return components;
106
- };
1
+ import { interpret } from '../interpret';
2
+ import { isDev, buildVectorialBindings } from '../../lib';
3
+
4
+ let cache = {};
5
+
6
+ const customFilterPagination = ({ page }, pagination, currentPage) => {
7
+ return pagination ? currentPage?.split('.')[0] === page : true;
8
+ };
9
+
10
+ const filterComponents = ({ components, updatedVars, features, bindings }) => {
11
+ const localCache = {};
12
+ const filtered = components.filter(({ conditionFilter }) => {
13
+ if (!conditionFilter || !conditionFilter.value) return true;
14
+ const { bindingDependencies, value } = conditionFilter;
15
+ if (localCache[value] !== undefined) return localCache[value];
16
+ if (
17
+ (!bindingDependencies ||
18
+ !updatedVars.some((t) => bindingDependencies.includes(t))) &&
19
+ cache[value] !== undefined
20
+ )
21
+ return cache[value];
22
+ const vectorialBindings = buildVectorialBindings(bindings);
23
+ const inter = interpret(features)(vectorialBindings)(value);
24
+ localCache[value] = inter;
25
+ return inter;
26
+ });
27
+ cache = { ...cache, ...localCache };
28
+ return filtered;
29
+ };
30
+
31
+ const buildComponents = ({
32
+ components,
33
+ management,
34
+ bindings,
35
+ features,
36
+ page,
37
+ pagination,
38
+ todo,
39
+ }) => {
40
+ if (management && !pagination) return components;
41
+
42
+ if (management && pagination)
43
+ return components.filter((c) =>
44
+ customFilterPagination(c, pagination, page)
45
+ );
46
+
47
+ if (isDev) {
48
+ console.log('Start filter');
49
+ var start = new Date().getTime();
50
+ }
51
+
52
+ const updatedVars = Object.keys(todo);
53
+
54
+ if (!pagination) {
55
+ const filtered = filterComponents({
56
+ components,
57
+ updatedVars,
58
+ features,
59
+ bindings,
60
+ });
61
+ if (isDev) console.log(`End filter: ${new Date().getTime() - start} ms`);
62
+ return filtered;
63
+ }
64
+
65
+ const pageComponents = components.filter((c) =>
66
+ customFilterPagination(c, pagination, page)
67
+ );
68
+
69
+ const pageComponentsFiltered = filterComponents({
70
+ components: pageComponents,
71
+ updatedVars,
72
+ features,
73
+ bindings,
74
+ });
75
+ if (isDev) console.log(`End filter: ${new Date().getTime() - start}`);
76
+ return pageComponentsFiltered;
77
+ };
78
+
79
+ let oldComponents = [];
80
+ let memoryTodo = {};
81
+
82
+ export const useFilterComponents = ({
83
+ questionnaire,
84
+ management,
85
+ bindings,
86
+ features,
87
+ page,
88
+ pagination,
89
+ todo,
90
+ }) => {
91
+ if (Object.keys(todo).length > 0) {
92
+ memoryTodo = todo;
93
+ return oldComponents;
94
+ }
95
+ const components = buildComponents({
96
+ components: questionnaire.components,
97
+ management,
98
+ bindings,
99
+ features,
100
+ page,
101
+ pagination,
102
+ todo: memoryTodo,
103
+ });
104
+ oldComponents = components;
105
+ return components;
106
+ };
@@ -1 +1,2 @@
1
- export { default } from './lunatic';
1
+ export { default as useLunatic } from './lunatic';
2
+ export { default as useLunaticSplit } from './lunatic-split';