@inseefr/lunatic 2.7.14 → 2.7.15

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 (33) hide show
  1. package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +3 -1
  2. package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +4 -1
  3. package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +7 -2
  4. package/lib/components/commons/components/missing/missing.js +4 -1
  5. package/lib/components/commons/components/missing/missing.scss +26 -29
  6. package/lib/components/datepicker/lunatic-datepicker.js +1 -0
  7. package/lib/components/dropdown/lunatic-dropdown.js +1 -0
  8. package/lib/components/duration/duration.js +4 -1
  9. package/lib/components/input/lunatic-input.js +1 -0
  10. package/lib/components/input-number/lunatic-input-number.js +1 -0
  11. package/lib/components/radio/lunatic-radio-group.js +1 -0
  12. package/lib/components/suggester/lunatic-suggester.js +1 -0
  13. package/lib/components/switch/lunatic-switch.js +7 -2
  14. package/lib/components/textarea/lunatic-textarea.js +3 -1
  15. package/lib/src/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.d.ts +1 -1
  16. package/lib/src/components/checkbox/checkbox-group/lunatic-checkbox-group.d.ts +1 -1
  17. package/lib/src/components/checkbox/checkbox-one/lunatic-checkbox-one.d.ts +1 -1
  18. package/lib/src/components/commons/components/lunatic-component-without-label.d.ts +1 -1
  19. package/lib/src/components/commons/components/missing/missing.d.ts +2 -1
  20. package/lib/src/components/switch/html/switch.d.ts +1 -0
  21. package/lib/src/components/switch/lunatic-switch.d.ts +1 -1
  22. package/lib/src/use-lunatic/commons/execute-condition-filter.d.ts +1 -1
  23. package/lib/src/utils/array.d.ts +1 -0
  24. package/lib/src/utils/variables.spec.d.ts +1 -0
  25. package/lib/stories/behaviour/missing/missing.stories.js +90 -0
  26. package/lib/stories/behaviour/missing/source.json +822 -0
  27. package/lib/stories/utils/referentiel.js +3 -3
  28. package/lib/use-lunatic/commons/execute-condition-filter.js +4 -1
  29. package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +4 -2
  30. package/lib/utils/array.js +21 -0
  31. package/lib/utils/variables.js +4 -15
  32. package/lib/utils/variables.spec.js +74 -0
  33. package/package.json +1 -1
@@ -17,15 +17,15 @@ var getReferentiel = exports.getReferentiel = /*#__PURE__*/function () {
17
17
  _context.next = _context.t0 === 'libelle-pcs2020' ? 3 : _context.t0 === 'naf-rev2-stop' ? 4 : _context.t0 === 'naf-rev2' ? 4 : _context.t0 === 'cog-communes' ? 5 : 6;
18
18
  break;
19
19
  case 3:
20
- return _context.abrupt("return", fetch('/libelles-pcs-2020.json').then(function (r) {
20
+ return _context.abrupt("return", fetch('./libelles-pcs-2020.json').then(function (r) {
21
21
  return r.json();
22
22
  }));
23
23
  case 4:
24
- return _context.abrupt("return", fetch('/naf-rev2.json').then(function (r) {
24
+ return _context.abrupt("return", fetch('./naf-rev2.json').then(function (r) {
25
25
  return r.json();
26
26
  }));
27
27
  case 5:
28
- return _context.abrupt("return", fetch('/communes-2019.json').then(function (r) {
28
+ return _context.abrupt("return", fetch('./communes-2019.json').then(function (r) {
29
29
  return r.json();
30
30
  }));
31
31
  case 6:
@@ -5,13 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _getCompatibleVtlExpression = _interopRequireDefault(require("./get-compatible-vtl-expression"));
8
+ var _array = require("../../utils/array");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
10
  function executeConditionFilter(filter, execute, iteration) {
10
11
  if (filter && typeof execute === 'function') {
11
12
  var value = filter.value;
12
- return execute((0, _getCompatibleVtlExpression["default"])(value), {
13
+ var result = execute((0, _getCompatibleVtlExpression["default"])(value), {
13
14
  iteration: iteration
14
15
  });
16
+ // Todo : replace this with a casting system on execute
17
+ return Array.isArray(result) ? (0, _array.firstItem)(result) : result;
15
18
  }
16
19
  return undefined;
17
20
  }
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  var _isObject = require("../../../utils/is-object");
8
+ var _array = require("../../../utils/array");
8
9
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
10
  function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
10
11
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -38,9 +39,10 @@ function createCrawl(_ref) {
38
39
  function executeAndFillObject(object, path) {
39
40
  var candidate = object[path];
40
41
  try {
41
- return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, executeExpression(candidate, {
42
+ var result = executeExpression(candidate, {
42
43
  iteration: linksIterations !== null && linksIterations !== void 0 ? linksIterations : iteration
43
- })));
44
+ });
45
+ return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, Array.isArray(result) ? (0, _array.firstItem)(result) : result));
44
46
  } catch (e) {
45
47
  return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, e instanceof Error ? e.toString() : e));
46
48
  }
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.firstItem = firstItem;
6
7
  exports.getAtIndex = getAtIndex;
7
8
  exports.resizeArray = resizeArray;
8
9
  exports.setAtIndex = setAtIndex;
@@ -81,4 +82,24 @@ function resizeArray(array, newLength, defaultValue) {
81
82
  return new Array(newLength).fill(defaultValue !== null && defaultValue !== void 0 ? defaultValue : null).map(function (value, index) {
82
83
  return index < array.length ? array[index] : value;
83
84
  }, []);
85
+ }
86
+ function firstItem(items) {
87
+ if (!Array.isArray(items)) {
88
+ return items;
89
+ }
90
+ var _iterator2 = _createForOfIteratorHelper(items),
91
+ _step2;
92
+ try {
93
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
94
+ var item = _step2.value;
95
+ if (item !== undefined) {
96
+ return item;
97
+ }
98
+ }
99
+ } catch (err) {
100
+ _iterator2.e(err);
101
+ } finally {
102
+ _iterator2.f();
103
+ }
104
+ return undefined;
84
105
  }
@@ -8,29 +8,18 @@ exports.getInitialVariableValue = getInitialVariableValue;
8
8
  * Extract the initial value from the source.json and data.json
9
9
  */
10
10
  function getInitialVariableValue(variable) {
11
- var _data$variable$variab;
11
+ var _data$variable$variab, _data$COLLECTED;
12
12
  var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13
13
  switch (variable.variableType) {
14
14
  case 'EXTERNAL':
15
15
  case 'CALCULATED':
16
16
  return (_data$variable$variab = data[variable.variableType]) === null || _data$variable$variab === void 0 ? void 0 : _data$variable$variab[variable.name];
17
17
  case 'COLLECTED':
18
- var collectedData = data.COLLECTED;
19
- var fromData;
20
- if (collectedData && variable.name in collectedData) {
21
- var _collectedData$variab = collectedData[variable.name],
22
- COLLECTED = _collectedData$variab.COLLECTED,
23
- FORCED = _collectedData$variab.FORCED;
24
- fromData = COLLECTED !== null && COLLECTED !== void 0 ? COLLECTED : FORCED;
25
- }
18
+ var fromData = (_data$COLLECTED = data.COLLECTED) === null || _data$COLLECTED === void 0 || (_data$COLLECTED = _data$COLLECTED[variable.name]) === null || _data$COLLECTED === void 0 ? void 0 : _data$COLLECTED.COLLECTED;
26
19
  if ('values' in variable && variable.values) {
27
- var _ref, _fromData;
28
- var _variable$values = variable.values,
29
- _COLLECTED = _variable$values.COLLECTED,
30
- _FORCED = _variable$values.FORCED;
31
- return (_ref = (_fromData = fromData) !== null && _fromData !== void 0 ? _fromData : _FORCED) !== null && _ref !== void 0 ? _ref : _COLLECTED;
20
+ return fromData !== null && fromData !== void 0 ? fromData : variable.values.COLLECTED;
32
21
  }
33
- return undefined;
22
+ return fromData;
34
23
  default:
35
24
  return null;
36
25
  }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _variables = require("./variables");
5
+ var data = {
6
+ EXTERNAL: {
7
+ ADRESSE: 'mon adresse'
8
+ },
9
+ CALCULATED: {
10
+ PRENOMSB: ['Paul', 'Pierre']
11
+ },
12
+ COLLECTED: {
13
+ NB_HAB: {
14
+ COLLECTED: 2
15
+ },
16
+ PRENOMS: {
17
+ COLLECTED: ['Paul', 'Pierre'],
18
+ EDITED: [],
19
+ INPUTED: [],
20
+ FORCED: [],
21
+ PREVIOUS: []
22
+ },
23
+ AGE: {}
24
+ }
25
+ };
26
+ var externalVariable = {
27
+ variableType: 'EXTERNAL',
28
+ name: 'ADRESSE'
29
+ };
30
+ var calculatedVariable = {
31
+ variableType: 'CALCULATED',
32
+ bindingDependencies: ['PRENOMS'],
33
+ expression: {
34
+ type: 'VTL',
35
+ value: 'PRENOMS'
36
+ },
37
+ name: 'PRENOMSB',
38
+ shapeFrom: 'PRENOMS'
39
+ };
40
+ var simpleCollectedVariable = {
41
+ variableType: 'COLLECTED',
42
+ name: 'NB_HAB'
43
+ };
44
+ var loopCollectedVariable = {
45
+ variableType: 'COLLECTED',
46
+ values: {
47
+ COLLECTED: []
48
+ },
49
+ name: 'PRENOMS'
50
+ };
51
+ var emptyCollectedVariable = {
52
+ variableType: 'COLLECTED',
53
+ name: 'AGE'
54
+ };
55
+ (0, _vitest.describe)('getInitialVariableValue', function () {
56
+ (0, _vitest.it)('should return external value', function () {
57
+ (0, _vitest.expect)((0, _variables.getInitialVariableValue)(externalVariable, data)).toEqual('mon adresse');
58
+ });
59
+ (0, _vitest.it)('should return calculated value', function () {
60
+ (0, _vitest.expect)((0, _variables.getInitialVariableValue)(calculatedVariable, data)).toEqual(['Paul', 'Pierre']);
61
+ });
62
+ (0, _vitest.it)('should return collected value out of a loop', function () {
63
+ (0, _vitest.expect)((0, _variables.getInitialVariableValue)(simpleCollectedVariable, data)).toEqual(2);
64
+ });
65
+ (0, _vitest.it)('should return array of collected values in a loop', function () {
66
+ (0, _vitest.expect)((0, _variables.getInitialVariableValue)(loopCollectedVariable, data)).toEqual(['Paul', 'Pierre']);
67
+ });
68
+ (0, _vitest.it)('should return undefined value out of a loop', function () {
69
+ (0, _vitest.expect)((0, _variables.getInitialVariableValue)(emptyCollectedVariable, data)).toEqual(undefined);
70
+ });
71
+ (0, _vitest.it)('should set empty undefined if no data', function () {
72
+ (0, _vitest.expect)((0, _variables.getInitialVariableValue)(simpleCollectedVariable)).toEqual(undefined);
73
+ });
74
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.7.14",
3
+ "version": "2.7.15",
4
4
  "workersVersion": "0.3.0",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {