@inseefr/lunatic 0.3.7-experimental → 0.3.8-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.
@@ -62,8 +62,14 @@ const getControlsFromComponents = ({
62
62
  }),
63
63
  ];
64
64
  } else {
65
- const { loopDependencies } = component;
66
- const iterations = parseInt(bindings[loopDependencies[0]], 10);
65
+ const {
66
+ loopDependencies,
67
+ lines: { min },
68
+ } = component;
69
+ const iterationsStr = loopDependencies
70
+ ? bindings[loopDependencies[0]]
71
+ : min;
72
+ const iterations = parseInt(iterationsStr, 10);
67
73
  const ctrls = [...Array(iterations).keys()].reduce((accIt, i) => {
68
74
  loopBindings = buildLoopBindings(i)(Object.entries(rootLoopBindings));
69
75
  return [
@@ -7,10 +7,14 @@ function defaultTokenizeIt(string) {
7
7
  return [prepareStringIndexation(string)];
8
8
  }
9
9
 
10
+ function toArray(content) {
11
+ return Array.isArray(content) ? content : [content];
12
+ }
13
+
10
14
  function tokensToArray(tokenized) {
11
15
  return Object.entries(tokenized).reduce(function (a, [k, values]) {
12
16
  if (k.startsWith('pattern')) {
13
- return [...a, ...values];
17
+ return [...a, ...toArray(values)];
14
18
  }
15
19
  return a;
16
20
  }, []);
@@ -5,4 +5,5 @@ export { default as filterStemmer } from './filters/filter-stemmer';
5
5
  export { default as filterLength } from './filters/filter-length';
6
6
  export { default as filterDouble } from './filters/filter-double';
7
7
  export { default as filterAccents } from './filters/filter-accents';
8
+ export { default as filterToLower } from './filters/filter-to-lower';
8
9
  export { default as getRegExpFromPattern } from './get-regexp-from-pattern';
@@ -4,10 +4,16 @@ import {
4
4
  filterLength,
5
5
  filterDouble,
6
6
  getRegExpFromPattern,
7
+ filterToLower,
7
8
  } from '../../commons-tokenizer';
8
9
  import { composeFilters } from '../../commons-tokenizer/filters';
9
10
 
10
- const filterTokens = composeFilters(filterDouble, filterStemmer, filterLength);
11
+ const filterTokens = composeFilters(
12
+ filterDouble,
13
+ filterStemmer,
14
+ filterToLower,
15
+ filterLength
16
+ );
11
17
 
12
18
  function toArray(tokens) {
13
19
  if (tokens) {
@@ -60,7 +60,7 @@ export const updateQuestionnaire =
60
60
  };
61
61
 
62
62
  export const updateExternals =
63
- (questionnaire) => (logFunction) => (updatedValues) => {
63
+ (questionnaire) => (logFunction, preferences) => (updatedValues) => {
64
64
  const { variables, ...other } = questionnaire;
65
65
  const { EXTERNAL } = variables;
66
66
  const newVariables = {
@@ -71,8 +71,7 @@ export const updateExternals =
71
71
  const newVariablesWithCalculated = addCalculatedVars(
72
72
  newVariables,
73
73
  updatedValues
74
- )(logFunction);
75
-
74
+ )(logFunction, preferences);
76
75
  return {
77
76
  ...other,
78
77
  variables: newVariablesWithCalculated,
@@ -94,30 +93,29 @@ export const buildNewValue =
94
93
 
95
94
  // Separate methods to avoid perf issue on collect simplest use case
96
95
  const getCollectedAndExternal = (preferences) => (variables) => {
97
- const { COLLECTED } = variables;
96
+ const { COLLECTED, EXTERNAL } = variables;
98
97
  if (preferences.length === 1 && preferences[0] === 'COLLECTED')
99
- return getCollectedAndExternalSimple(COLLECTED);
100
- return getCollectedAndExternalByPreferences(preferences)(COLLECTED);
98
+ return { ...getCollectedAndExternalSimple(COLLECTED), ...EXTERNAL };
99
+ return {
100
+ ...getCollectedAndExternalByPreferences(preferences)(COLLECTED),
101
+ ...EXTERNAL,
102
+ };
101
103
  };
102
104
 
103
- const getCollectedAndExternalSimple = (variables) => {
104
- const collected = Object.entries(variables).reduce(
105
+ const getCollectedAndExternalSimple = (variables) =>
106
+ Object.entries(variables).reduce(
105
107
  (acc, [k, { values }]) => ({ ...acc, [k]: values.COLLECTED }),
106
108
  {}
107
109
  );
108
- return { ...collected, ...variables.EXTERNAL };
109
- };
110
110
 
111
- const getCollectedAndExternalByPreferences = (preferences) => (variables) => {
112
- const collected = Object.entries(variables).reduce((acc, [k, { values }]) => {
111
+ const getCollectedAndExternalByPreferences = (preferences) => (variables) =>
112
+ Object.entries(variables).reduce((acc, [k, { values }]) => {
113
113
  const v = preferences.reduce((acc, p) => {
114
114
  const value = values[p];
115
115
  return [null, ''].includes(value) ? acc : value;
116
116
  }, null);
117
117
  return { ...acc, [k]: v };
118
118
  }, {});
119
- return { ...collected, ...variables.EXTERNAL };
120
- };
121
119
 
122
120
  const addCalculatedVars =
123
121
  (variables, updatedValues) => (logFunction, preferences) => {
@@ -361,11 +361,14 @@ const useLunaticSplit = (
361
361
 
362
362
  useEffect(() => {
363
363
  if (Object.keys(todoExternals).length !== 0) {
364
- const newQ = updateExternals(questionnaire)(logFunction)(todoExternals);
364
+ const newQ = updateExternals(questionnaire)(logFunction, preferences)(
365
+ todoExternals
366
+ );
367
+ setBindings(getBindings(newQ));
365
368
  setQuestionnaire(newQ);
366
369
  setTodoExternals({});
367
370
  }
368
- }, [todoExternals, logFunction, questionnaire]);
371
+ }, [todoExternals, logFunction, questionnaire, preferences]);
369
372
 
370
373
  const cancelModal = () => {
371
374
  setModalContent(null);
@@ -216,11 +216,14 @@ const useLunatic = (
216
216
 
217
217
  useEffect(() => {
218
218
  if (Object.keys(todoExternals).length !== 0) {
219
- const newQ = updateExternals(questionnaire)(logFunction)(todoExternals);
219
+ const newQ = updateExternals(questionnaire)(logFunction, preferences)(
220
+ todoExternals
221
+ );
222
+ setBindings(getBindings(newQ));
220
223
  setQuestionnaire(newQ);
221
224
  setTodoExternals({});
222
225
  }
223
- }, [todoExternals, logFunction, questionnaire]);
226
+ }, [todoExternals, logFunction, questionnaire, preferences]);
224
227
 
225
228
  const cancelModal = () => {
226
229
  setModalContent(null);