@inseefr/lunatic 2.6.7 → 2.6.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.
@@ -47,28 +47,33 @@ function Suggester(_ref) {
47
47
  _useState4 = _slicedToArray(_useState3, 2),
48
48
  options = _useState4[0],
49
49
  setOptions = _useState4[1];
50
+ var lastSearch = (0, _react.useRef)('');
50
51
  var handleSelect = (0, _react.useCallback)(function (id) {
51
52
  onSelect(id ? id : null);
52
53
  }, [onSelect]);
53
54
  var handleChange = (0, _react.useCallback)( /*#__PURE__*/function () {
54
55
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(search) {
55
- var _yield$searching, results;
56
+ var _yield$searching, results, previous;
56
57
  return _regeneratorRuntime().wrap(function _callee$(_context) {
57
58
  while (1) switch (_context.prev = _context.next) {
58
59
  case 0:
60
+ lastSearch.current = search !== null && search !== void 0 ? search : '';
59
61
  if (!(search && typeof searching === 'function')) {
60
62
  _context.next = 10;
61
63
  break;
62
64
  }
63
- _context.next = 3;
65
+ _context.next = 4;
64
66
  return searching(search);
65
- case 3:
67
+ case 4:
66
68
  _yield$searching = _context.sent;
67
69
  results = _yield$searching.results;
68
- setOptions(results);
69
- setSearch(search);
70
- // if a user does not select an option in the list, their search term is saved
71
- onSelect(search);
70
+ previous = _yield$searching.search;
71
+ if (previous === lastSearch.current) {
72
+ setOptions(results);
73
+ setSearch(search);
74
+ // if a user does not select an option in the list, their search term is saved
75
+ onSelect(search);
76
+ }
72
77
  _context.next = 13;
73
78
  break;
74
79
  case 10:
@@ -16,6 +16,7 @@ type Props = {
16
16
  id?: string;
17
17
  searching?: (s: string | null) => Promise<{
18
18
  results: ComboBoxOptionType[];
19
+ search: string;
19
20
  }>;
20
21
  label?: ReactNode;
21
22
  description?: ReactNode;
@@ -2,5 +2,6 @@ import type { ComboBoxOptionType } from '../../commons/components/combo-box/comb
2
2
  export declare function isWorkerCompatible(): boolean;
3
3
  declare function createSearching(name: string, version: string, workersBasePath?: string): (search: string | null) => Promise<{
4
4
  results: ComboBoxOptionType[];
5
+ search: string;
5
6
  }>;
6
7
  export default createSearching;
@@ -20,7 +20,10 @@
20
20
  },
21
21
  {
22
22
  "name": "cog-communes",
23
- "fields": [{ "name": "id", "rules": "soft" }],
23
+ "fields": [
24
+ { "name": "id", "rules": "soft" },
25
+ { "name": "label", "rules": "soft" }
26
+ ],
24
27
  "queryParser": { "type": "soft" },
25
28
  "version": "1"
26
29
  },
@@ -85,7 +88,7 @@
85
88
  "name": "HELLO"
86
89
  },
87
90
  "missingResponse": { "name": "HELLO_MISSING" },
88
- "page": "2"
91
+ "page": "1"
89
92
  },
90
93
  {
91
94
  "id": "suggestions-inconnu",
@@ -135,7 +135,6 @@ function createRefreshCalculated(_ref) {
135
135
  iteration: iteration,
136
136
  linksIterations: linksIterations
137
137
  });
138
- if (!skipCleaningRefresh) toRefreshVariables["delete"](name);
139
138
  return _objectSpread(_objectSpread({}, sub), {}, _defineProperty({}, name, value));
140
139
  }
141
140
  return _objectSpread(_objectSpread({}, sub), {}, _defineProperty({}, name, current));
@@ -32,9 +32,10 @@ function fillRoundaboutProps(component, state) {
32
32
  var values = new Array(iterations).fill(null).map(function (_, iteration) {
33
33
  return state.executeExpression(expression, {
34
34
  iteration: iteration,
35
- skipCleaningRefresh: iteration < iterations - 1
35
+ skipCleaningRefresh: true // TODO : this should be "iteration < iterations - 1" but this cause an issue with recensement, investigate further later,
36
36
  });
37
37
  });
38
+
38
39
  return _objectSpread(_objectSpread({}, result), {}, _defineProperty({}, name, values));
39
40
  }, {});
40
41
  return _objectSpread(_objectSpread({}, component), {}, {
@@ -6,17 +6,21 @@ var _searching = _interopRequireDefault(require("./searching"));
6
6
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
7
7
  /* eslint-disable no-restricted-globals */
8
8
 
9
+ var LAST_SEARCH = undefined;
9
10
  self.onmessage = function (e) {
10
11
  var _e$data = e.data,
11
12
  search = _e$data.search,
12
13
  name = _e$data.name,
13
14
  version = _e$data.version,
14
15
  meloto = _e$data.meloto;
16
+ LAST_SEARCH = search;
15
17
  (0, _searching["default"])(search, {
16
18
  name: name,
17
19
  version: version,
18
20
  meloto: meloto
19
21
  }).then(function (result) {
20
- self.postMessage(result);
22
+ if (search === LAST_SEARCH) {
23
+ self.postMessage(result);
24
+ }
21
25
  });
22
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inseefr/lunatic",
3
- "version": "2.6.7",
3
+ "version": "2.6.9",
4
4
  "workersVersion": "0.3.0-experimental",
5
5
  "description": "Library of questionnaire components",
6
6
  "repository": {