@inseefr/lunatic 0.4.7-v2 → 0.4.8-v2

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.
@@ -137,9 +137,6 @@ function OrchestratorForStories(_ref2) {
137
137
  var errors = getErrors();
138
138
  var modalErrors = getModalErrors();
139
139
  var currentErrors = getCurrentErrors();
140
- console.log('errors: ', errors);
141
- console.log('modalErrors: ', modalErrors);
142
- console.log('currentErrors: ', currentErrors);
143
140
  return /*#__PURE__*/_react["default"].createElement("div", {
144
141
  className: "container"
145
142
  }, /*#__PURE__*/_react["default"].createElement("div", {
@@ -122,6 +122,25 @@ function createExecuteExpression(variables, features) {
122
122
 
123
123
  pushToLazy(name);
124
124
  }
125
+ /**
126
+ *
127
+ * @param {*} variables
128
+ * @param {*} iteration
129
+ */
130
+
131
+
132
+ function setLoopBindings(variables, iteration) {
133
+ Object.entries(bindings).forEach(function (_ref3) {
134
+ var _ref4 = _slicedToArray(_ref3, 2),
135
+ k = _ref4[0],
136
+ v = _ref4[1];
137
+
138
+ var _variables$k = variables[k],
139
+ type = _variables$k.type,
140
+ value = _variables$k.value;
141
+ if (!Array.isArray(v) && type === _constants.COLLECTED && Array.isArray(value)) bindings[k] = value[iteration];
142
+ });
143
+ }
125
144
 
126
145
  function getVariablesAndCach(expression) {
127
146
  if (tokensMap.has(expression)) {
@@ -163,9 +182,9 @@ function createExecuteExpression(variables, features) {
163
182
  return {};
164
183
  }
165
184
 
166
- function resolveUseContext(name, _ref3) {
167
- var iteration = _ref3.iteration,
168
- linksIterations = _ref3.linksIterations;
185
+ function resolveUseContext(name, _ref5) {
186
+ var iteration = _ref5.iteration,
187
+ linksIterations = _ref5.linksIterations;
169
188
  var value = bindings[name];
170
189
 
171
190
  if ([_constants.X_AXIS, _constants.Y_AXIS].includes(name) && linksIterations !== undefined) {
@@ -195,13 +214,13 @@ function createExecuteExpression(variables, features) {
195
214
  return (0, _vtl["default"])(value);
196
215
  }
197
216
 
198
- function fillVariablesValues(map, _ref4) {
199
- var iteration = _ref4.iteration,
200
- linksIterations = _ref4.linksIterations;
201
- return Object.entries(map).reduce(function (sub, _ref5) {
202
- var _ref6 = _slicedToArray(_ref5, 2),
203
- name = _ref6[0],
204
- _ = _ref6[1];
217
+ function fillVariablesValues(map, _ref6) {
218
+ var iteration = _ref6.iteration,
219
+ linksIterations = _ref6.linksIterations;
220
+ return Object.entries(map).reduce(function (sub, _ref7) {
221
+ var _ref8 = _slicedToArray(_ref7, 2),
222
+ name = _ref8[0],
223
+ _ = _ref8[1];
205
224
 
206
225
  return _objectSpread(_objectSpread({}, sub), {}, _defineProperty({}, name, resolveUseContext(name, {
207
226
  iteration: iteration,
@@ -257,7 +276,7 @@ function createExecuteExpression(variables, features) {
257
276
  return memoized;
258
277
  }
259
278
 
260
- return [execute, updateBindings];
279
+ return [execute, updateBindings, setLoopBindings];
261
280
  }
262
281
 
263
282
  var _default = createExecuteExpression;
@@ -157,7 +157,9 @@ function validateChange(state) {
157
157
  function reduceGoNextPage(state) {
158
158
  var pages = state.pages,
159
159
  isInLoop = state.isInLoop,
160
- pager = state.pager;
160
+ pager = state.pager,
161
+ setLoopBindings = state.setLoopBindings,
162
+ variables = state.variables;
161
163
  var iteration = pager.iteration,
162
164
  nbIterations = pager.nbIterations,
163
165
  subPage = pager.subPage,
@@ -169,6 +171,7 @@ function reduceGoNextPage(state) {
169
171
  }
170
172
 
171
173
  if (isInLoop && subPage === nbSubPages - 1 && iteration < nbIterations - 1) {
174
+ setLoopBindings(variables, iteration + 1);
172
175
  return validateChange(reduceNextIteration(state));
173
176
  }
174
177
 
@@ -124,7 +124,9 @@ function validateChange(state) {
124
124
  function reduceGoPreviousPage(state) {
125
125
  var pages = state.pages,
126
126
  pager = state.pager,
127
- isInLoop = state.isInLoop;
127
+ isInLoop = state.isInLoop,
128
+ setLoopBindings = state.setLoopBindings,
129
+ variables = state.variables;
128
130
  var iteration = pager.iteration,
129
131
  subPage = pager.subPage; // dans une boucle et l'itération courante n'est pas finie
130
132
 
@@ -134,6 +136,7 @@ function reduceGoPreviousPage(state) {
134
136
 
135
137
 
136
138
  if (isInLoop && subPage === 0 && iteration > 0) {
139
+ setLoopBindings(variables, iteration - 1);
137
140
  return validateChange(goPreviousIteration(state));
138
141
  }
139
142
 
@@ -50,6 +50,7 @@ function reduceGoToPage(state, action) {
50
50
  }); // TODO: fix when redirect to loop component
51
51
  // How to calculate nbSubPages & nbIterations?
52
52
  // How to calculate lazy variables we need?
53
+ // Handle setLoopBindings with the good iteration
53
54
 
54
55
  return validateChange(state);
55
56
  }
@@ -204,9 +204,10 @@ function reduceOnInit(state, action) {
204
204
  var variables = createVariables(source, data); // map des variables
205
205
 
206
206
  var _createExecuteExpress = (0, _commons.createExecuteExpression)(variables, features),
207
- _createExecuteExpress2 = _slicedToArray(_createExecuteExpress, 2),
207
+ _createExecuteExpress2 = _slicedToArray(_createExecuteExpress, 3),
208
208
  executeExpression = _createExecuteExpress2[0],
209
- updateBindings = _createExecuteExpress2[1];
209
+ updateBindings = _createExecuteExpress2[1],
210
+ setLoopBindings = _createExecuteExpress2[2];
210
211
 
211
212
  var pages = (0, _commons.checkLoops)((0, _commons.createMapPages)(source));
212
213
  var maxPage = source.maxPage,
@@ -241,6 +242,7 @@ function reduceOnInit(state, action) {
241
242
  pager: pager,
242
243
  executeExpression: executeExpression,
243
244
  updateBindings: updateBindings,
245
+ setLoopBindings: setLoopBindings,
244
246
  handleChange: handleChange,
245
247
  preferences: preferences,
246
248
  management: management,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "0.4.7-v2",
3
+ "version": "0.4.8-v2",
4
4
  "workersVersion": "0.2.4-experimental",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {