@inseefr/lunatic 0.2.2-experimental → 0.2.3-prisme
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.
- package/LICENSE +21 -21
- package/README.md +25 -23
- package/lib/index.js +1191 -475
- package/lib/index.js.map +1 -1
- package/package.json +174 -172
- package/src/components/breadcrumb/breadcrumb.scss +22 -22
- package/src/components/checkbox/boolean.js +172 -172
- package/src/components/checkbox/checkbox.scss +73 -73
- package/src/components/checkbox/group.js +231 -231
- package/src/components/checkbox/one.js +11 -11
- package/src/components/component-wrapper/controls/component.js +70 -0
- package/src/components/component-wrapper/controls/controls.scss +6 -0
- package/src/components/component-wrapper/controls/index.js +1 -0
- package/src/components/component-wrapper/controls/validators/datepicker.js +44 -0
- package/src/components/component-wrapper/controls/validators/index.js +16 -0
- package/src/components/component-wrapper/controls/validators/input-number.js +23 -0
- package/src/components/{missing-wrapper → component-wrapper}/index.js +0 -0
- package/src/components/component-wrapper/missing/component.js +200 -0
- package/src/components/component-wrapper/missing/index.js +1 -0
- package/src/components/{missing-wrapper → component-wrapper/missing}/missing.scss +32 -32
- package/src/components/component-wrapper/wrapper.js +23 -0
- package/src/components/components.js +1 -0
- package/src/components/datepicker/component.js +26 -11
- package/src/components/declarations/component.js +46 -46
- package/src/components/declarations/declarations.scss +40 -40
- package/src/components/declarations/wrappers/input-declarations-wrapper.js +328 -274
- package/src/components/declarations/wrappers/simple-declarations-wrapper.js +54 -54
- package/src/components/dropdown/commons/actions.js +65 -56
- package/src/components/dropdown/commons/children-to-option.js +9 -9
- package/src/components/dropdown/commons/cleaner-callbacks.js +58 -58
- package/src/components/dropdown/commons/components/dropdown-container.js +29 -29
- package/src/components/dropdown/commons/components/dropdown.js +204 -183
- package/src/components/dropdown/commons/event-callbacks/on-mousedown-callback.js +15 -15
- package/src/components/dropdown/commons/reducer.js +3 -0
- package/src/components/dropdown/commons/tools/index.js +17 -17
- package/src/components/dropdown/component.js +135 -135
- package/src/components/dropdown/dropdown-edit/dropdown-edit.js +194 -185
- package/src/components/dropdown/dropdown-edit/index.js +11 -11
- package/src/components/dropdown/dropdown-simple/dropdown.js +173 -164
- package/src/components/dropdown/dropdown-simple/index.js +20 -20
- package/src/components/dropdown/dropdown.scss +178 -178
- package/src/components/icon/icon.scss +15 -15
- package/src/components/index.js +2 -0
- package/src/components/index.scss +177 -175
- package/src/components/input/input-number.js +30 -54
- package/src/components/input/input.js +11 -11
- package/src/components/input/input.scss +31 -37
- package/src/components/loop/component.js +170 -169
- package/src/components/loop/loop.scss +13 -13
- package/src/components/loop/wrapper.js +1 -1
- package/src/components/loop-constructor/block/block.scss +10 -10
- package/src/components/loop-constructor/block/component.js +9 -9
- package/src/components/loop-constructor/roster/component.js +8 -8
- package/src/components/loop-constructor/wrapper/body-component.js +146 -125
- package/src/components/modal/component.js +36 -0
- package/src/components/modal/index.js +1 -0
- package/src/components/modal/modal.scss +33 -0
- package/src/components/progress-bar/progress-bar.scss +54 -54
- package/src/components/radio/component.js +9 -9
- package/src/components/radio/radio.scss +59 -59
- package/src/components/sequence/component.js +50 -50
- package/src/components/sequence/sequence.scss +10 -10
- package/src/components/subsequence/component.js +49 -49
- package/src/components/suggester/check-store.js +2 -4
- package/src/components/suggester/components/panel/default-option-renderer.js +27 -27
- package/src/components/suggester/components/panel/option-container.js +61 -61
- package/src/components/suggester/components/panel/panel.js +47 -47
- package/src/components/suggester/components/selection/default-label-renderer.js +31 -31
- package/src/components/suggester/components/selection/label.js +35 -35
- package/src/components/suggester/components/selection/selection.js +50 -50
- package/src/components/suggester/components/suggester-content.js +2 -2
- package/src/components/suggester/components/suggester.js +128 -88
- package/src/components/suggester/components/suggester.scss +101 -101
- package/src/components/suggester/default-style.scss +125 -125
- package/src/components/suggester/find-best-label/find-best-label.js +51 -49
- package/src/components/suggester/find-best-label/index.js +1 -1
- package/src/components/suggester/idb-suggester.js +73 -67
- package/src/components/suggester/lunatic-suggester.js +140 -137
- package/src/components/suggester/searching/create-searching.js +49 -47
- package/src/components/suggester/searching/index.js +1 -1
- package/src/components/suggester/state-management/actions.js +38 -38
- package/src/components/suggester/state-management/reducer/reduce-on-delete-search.js +11 -11
- package/src/components/suggester/state-management/reducer/reduce-on-init.js +29 -29
- package/src/components/suggester/state-management/reducer/reducer.js +38 -38
- package/src/components/suggester/suggester-wrapper.js +127 -121
- package/src/components/suggester-loader-widget/loader.js +67 -67
- package/src/components/suggester-loader-widget/widget.js +123 -123
- package/src/components/table/table.js +173 -171
- package/src/components/table/table.scss +26 -26
- package/src/components/textarea/component.js +11 -11
- package/src/components/textarea/textarea.scss +8 -8
- package/src/components/tooltip/tooltip.scss +30 -30
- package/src/stories/checkbox-boolean/data.json +78 -78
- package/src/stories/datepicker/data.json +3 -1
- package/src/stories/dropdown/README.md +44 -44
- package/src/stories/dropdown/data.json +98 -98
- package/src/stories/dropdown/dropdown.stories.js +89 -89
- package/src/stories/progress-bar/progress-bar.stories.js +24 -24
- package/src/stories/questionnaire/arithmetic-management.json +47 -0
- package/src/stories/questionnaire/arithmetic.json +247 -247
- package/src/stories/questionnaire/kish.json +275 -0
- package/src/stories/questionnaire/logement-queen.json +23390 -0
- package/src/stories/questionnaire/logement-s2.json +46028 -0
- package/src/stories/questionnaire/logement.json +20347 -26087
- package/src/stories/questionnaire/loop-and-controls.json +481 -0
- package/src/stories/questionnaire/questionnaire.stories.js +236 -138
- package/src/stories/questionnaire/update-external/data.json +1 -0
- package/src/stories/questionnaire/update-external/questionnaire.json +75 -0
- package/src/stories/suggester/README.md +46 -46
- package/src/stories/suggester/bailleurs-sociaux/fetch-bailleurs.js +15 -15
- package/src/stories/suggester/bailleurs-sociaux/index.js +2 -2
- package/src/stories/suggester/bailleurs-sociaux/option-bailleur-renderer.js +58 -58
- package/src/stories/suggester/bailleurs-sociaux/preloader.svg +51 -51
- package/src/stories/suggester/bailleurs-sociaux/theme.scss +22 -22
- package/src/stories/suggester/bailleurs-sociaux-2021/fetch-bailleurs.js +12 -0
- package/src/stories/suggester/bailleurs-sociaux-2021/index.js +1 -0
- package/src/stories/suggester/cog-communes/fetch-cog.js +15 -15
- package/src/stories/suggester/data-auto.json +232 -231
- package/src/stories/suggester/data-vtl.json +82 -82
- package/src/stories/suggester/data.json +169 -136
- package/src/stories/suggester/naf-rev2/index.js +2 -2
- package/src/stories/suggester/naf-rev2/option-naf-renderer.js +17 -17
- package/src/stories/suggester/suggester-workers.stories.js +226 -179
- package/src/stories/suggester/suggester.stories.js +138 -133
- package/src/stories/utils/orchestrator-split.js +119 -0
- package/src/stories/utils/orchestrator.js +119 -108
- package/src/tests/components/input-number.spec.js +6 -12
- package/src/tests/components/missing-wrapper.spec.js +0 -1
- package/src/tests/utils/lib/table/roster.spec.js +25 -25
- package/src/tests/utils/to-expose/handler/results/res-input-edited.json +1 -1
- package/src/utils/components/dragger/dragger.scss +7 -7
- package/src/utils/idb-tools/create-db-opener.js +43 -43
- package/src/utils/idb-tools/create-open-db.js +25 -25
- package/src/utils/idb-tools/idb-bulk-insert.js +96 -96
- package/src/utils/idb-tools/index.js +10 -10
- package/src/utils/idb-tools/insert-entity.js +15 -15
- package/src/utils/idb-tools/open-db.js +13 -13
- package/src/utils/idb-tools/open-or-create-db.js +34 -34
- package/src/utils/lib/controls/index.js +1 -0
- package/src/utils/lib/controls/utils.js +152 -0
- package/src/utils/lib/decorator/title-decorator.js +16 -16
- package/src/utils/lib/env.js +2 -2
- package/src/utils/lib/index.js +2 -0
- package/src/utils/lib/input-number.js +1 -1
- package/src/utils/lib/options-positioning.js +9 -9
- package/src/utils/lib/pagination/navigation/shared.js +12 -9
- package/src/utils/lib/prop-types/lines.js +6 -6
- package/src/utils/lib/responses.js +11 -9
- package/src/utils/lib/splitting.js +142 -0
- package/src/utils/lib/style.js +10 -10
- package/src/utils/store-tools/auto-load.js +74 -73
- package/src/utils/suggester-workers/append-to-index/append.js +25 -25
- package/src/utils/suggester-workers/append-to-index/append.worker.js +16 -16
- package/src/utils/suggester-workers/append-to-index/create-append-task.js +45 -43
- package/src/utils/suggester-workers/append-to-index/index.js +2 -2
- package/src/utils/suggester-workers/append-to-index/prepare-entities.js +61 -61
- package/src/utils/suggester-workers/append-to-index/store-messages.js +21 -21
- package/src/utils/suggester-workers/commons-tokenizer/create-entity-tokenizer.js +56 -0
- package/src/utils/suggester-workers/commons-tokenizer/create-fields-tokenizer.js +56 -0
- package/src/utils/suggester-workers/commons-tokenizer/create-filter-stop-words.js +17 -17
- package/src/utils/suggester-workers/commons-tokenizer/filters/compose-filters.js +10 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.js +17 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.spec.js +14 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-accents.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-accents.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/{filter-double.js → filters/filter-double.js} +12 -12
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-double.spec.js +20 -0
- package/src/utils/suggester-workers/commons-tokenizer/{filter-length.js → filters/filter-length.js} +7 -7
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-length.spec.js +18 -0
- package/src/utils/suggester-workers/commons-tokenizer/{filter-stemmer.js → filters/filter-stemmer.js} +13 -13
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-stemmer.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.js +36 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.js +10 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/index.js +2 -0
- package/src/utils/suggester-workers/commons-tokenizer/{stop-words.js → filters/stop-words.js} +118 -118
- package/src/utils/suggester-workers/commons-tokenizer/get-regexp-from-pattern.js +8 -8
- package/src/utils/suggester-workers/commons-tokenizer/get-stemmer.js +18 -18
- package/src/utils/suggester-workers/commons-tokenizer/index.js +9 -8
- package/src/utils/suggester-workers/commons-tokenizer/prepare-string-indexation.js +13 -9
- package/src/utils/suggester-workers/commons-tokenizer/soft-tokenizer.js +7 -7
- package/src/utils/suggester-workers/create-worker.js +56 -0
- package/src/utils/suggester-workers/find-best-label/find-best-label.js +39 -39
- package/src/utils/suggester-workers/find-best-label/find-best-label.worker.js +40 -40
- package/src/utils/suggester-workers/find-best-label/tokenize.js +30 -33
- package/src/utils/suggester-workers/find-best-label/tokenize.spec.js +19 -19
- package/src/utils/suggester-workers/searching/compute-score.js +33 -33
- package/src/utils/suggester-workers/searching/get-db.js +18 -18
- package/src/utils/suggester-workers/searching/index.js +1 -1
- package/src/utils/suggester-workers/searching/order/create-alphanumeric-orderer.js +20 -20
- package/src/utils/suggester-workers/searching/order/index.js +19 -19
- package/src/utils/suggester-workers/{query-parser → searching/query-parser}/index.js +2 -2
- package/src/utils/suggester-workers/searching/query-parser/query-parser-soft.js +7 -0
- package/src/utils/suggester-workers/{query-parser → searching/query-parser}/query-parser-soft.spec.js +24 -24
- package/src/utils/suggester-workers/searching/query-parser/query-parser-tokenized.js +34 -0
- package/src/utils/suggester-workers/searching/resolve-query-parser.js +27 -27
- package/src/utils/suggester-workers/searching/search-in-index.js +17 -17
- package/src/utils/suggester-workers/searching/searching.js +70 -70
- package/src/utils/suggester-workers/searching/searching.worker.js +11 -11
- package/src/utils/to-expose/calculated-variables.js +113 -113
- package/src/utils/to-expose/handler.js +149 -112
- package/src/utils/to-expose/hooks/filter-components.js +27 -12
- package/src/utils/to-expose/hooks/index.js +2 -1
- package/src/utils/to-expose/hooks/lunatic-split.js +428 -0
- package/src/utils/to-expose/hooks/lunatic.js +284 -187
- package/src/utils/to-expose/index.js +1 -1
- package/src/utils/to-expose/init-questionnaire.js +164 -164
- package/src/utils/to-expose/interpret/vtl.js +18 -18
- package/src/utils/to-expose/state.js +66 -58
- package/src/components/missing-wrapper/component.js +0 -120
- package/src/components/missing-wrapper/wrapper.js +0 -10
- package/src/tests/utils/to-expose/hooks/use-lunatic.spec.js +0 -46
- package/src/utils/suggester-workers/commons-tokenizer/create-tokenizer.js +0 -103
- package/src/utils/suggester-workers/commons-tokenizer/filter-accents-to-lower.js +0 -9
- package/src/utils/suggester-workers/commons-tokenizer/filter-synonyms.js +0 -10
- package/src/utils/suggester-workers/query-parser/query-parser-soft.js +0 -7
- package/src/utils/suggester-workers/query-parser/query-parser-tokenized.js +0 -31
- package/src/utils/suggester-workers/query-parser/query-parser-tokenized.spec.js +0 -32
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import getDb from './get-db';
|
|
2
|
-
import { CONSTANTES } from '../../store-tools';
|
|
3
|
-
import { getEntity } from '../../idb-tools';
|
|
4
|
-
import searchInIndex from './search-in-index';
|
|
5
|
-
import resolveQueryParser from './resolve-query-parser';
|
|
6
|
-
import computeScore from './compute-score';
|
|
7
|
-
import getOrderingFunction from './order';
|
|
8
|
-
|
|
9
|
-
function prepare(response) {
|
|
10
|
-
return response.map(({ suggestion, tokensMap }) => ({
|
|
11
|
-
...suggestion,
|
|
12
|
-
tokensMap,
|
|
13
|
-
}));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function searchTokens(tokens, index) {
|
|
17
|
-
const results = await Promise.all(
|
|
18
|
-
tokens.map((token) => searchInIndex(token, index))
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
return results.reduce(function (a, step, i) {
|
|
22
|
-
return { ...a, [tokens[i]]: step };
|
|
23
|
-
}, {});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isValideSearch(search) {
|
|
27
|
-
if (typeof search === 'string' && search.trim().length) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function filterSize(response, max) {
|
|
34
|
-
if (max && max < response.length) {
|
|
35
|
-
return response.slice(0, max);
|
|
36
|
-
}
|
|
37
|
-
return response;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function searching(search, { name, version = '1' }) {
|
|
41
|
-
try {
|
|
42
|
-
if (isValideSearch(search)) {
|
|
43
|
-
const db = await getDb(name, version);
|
|
44
|
-
const info = await getEntity(db, CONSTANTES.STORE_INFO_NAME, name);
|
|
45
|
-
const { queryParser, max, order } = info;
|
|
46
|
-
const parser = await resolveQueryParser(
|
|
47
|
-
const transaction = db.transaction(
|
|
48
|
-
CONSTANTES.STORE_DATA_NAME,
|
|
49
|
-
'readonly'
|
|
50
|
-
);
|
|
51
|
-
const store = transaction.objectStore(CONSTANTES.STORE_DATA_NAME);
|
|
52
|
-
const index = store.index(CONSTANTES.STORE_INDEX_NAME);
|
|
53
|
-
const tokens = parser(search);
|
|
54
|
-
const tokensSuggestions = await searchTokens(tokens, index);
|
|
55
|
-
const response = computeScore(tokensSuggestions);
|
|
56
|
-
return {
|
|
57
|
-
results: prepare(
|
|
58
|
-
getOrderingFunction(order)(filterSize(response, max), order)
|
|
59
|
-
),
|
|
60
|
-
search,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return { results: [], search };
|
|
64
|
-
} catch (e) {
|
|
65
|
-
console.
|
|
66
|
-
throw e;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default searching;
|
|
1
|
+
import getDb from './get-db';
|
|
2
|
+
import { CONSTANTES } from '../../store-tools';
|
|
3
|
+
import { getEntity } from '../../idb-tools';
|
|
4
|
+
import searchInIndex from './search-in-index';
|
|
5
|
+
import resolveQueryParser from './resolve-query-parser';
|
|
6
|
+
import computeScore from './compute-score';
|
|
7
|
+
import getOrderingFunction from './order';
|
|
8
|
+
|
|
9
|
+
function prepare(response) {
|
|
10
|
+
return response.map(({ suggestion, tokensMap }) => ({
|
|
11
|
+
...suggestion,
|
|
12
|
+
tokensMap,
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function searchTokens(tokens, index) {
|
|
17
|
+
const results = await Promise.all(
|
|
18
|
+
tokens.map((token) => searchInIndex(token, index))
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return results.reduce(function (a, step, i) {
|
|
22
|
+
return { ...a, [tokens[i]]: step };
|
|
23
|
+
}, {});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isValideSearch(search) {
|
|
27
|
+
if (typeof search === 'string' && search.trim().length) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function filterSize(response, max) {
|
|
34
|
+
if (max && max < response.length) {
|
|
35
|
+
return response.slice(0, max);
|
|
36
|
+
}
|
|
37
|
+
return response;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function searching(search, { name, version = '1' }) {
|
|
41
|
+
try {
|
|
42
|
+
if (isValideSearch(search)) {
|
|
43
|
+
const db = await getDb(name, version);
|
|
44
|
+
const info = await getEntity(db, CONSTANTES.STORE_INFO_NAME, name);
|
|
45
|
+
const { queryParser, max, order } = info;
|
|
46
|
+
const parser = await resolveQueryParser(queryParser);
|
|
47
|
+
const transaction = db.transaction(
|
|
48
|
+
CONSTANTES.STORE_DATA_NAME,
|
|
49
|
+
'readonly'
|
|
50
|
+
);
|
|
51
|
+
const store = transaction.objectStore(CONSTANTES.STORE_DATA_NAME);
|
|
52
|
+
const index = store.index(CONSTANTES.STORE_INDEX_NAME);
|
|
53
|
+
const tokens = parser(search);
|
|
54
|
+
const tokensSuggestions = await searchTokens(tokens, index);
|
|
55
|
+
const response = computeScore(tokensSuggestions);
|
|
56
|
+
return {
|
|
57
|
+
results: prepare(
|
|
58
|
+
getOrderingFunction(order)(filterSize(response, max), order)
|
|
59
|
+
),
|
|
60
|
+
search,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return { results: [], search };
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error(e);
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default searching;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-globals */
|
|
2
|
-
import 'core-js/stable';
|
|
3
|
-
import 'regenerator-runtime/runtime';
|
|
4
|
-
import searching from './searching';
|
|
5
|
-
|
|
6
|
-
self.onmessage = function (e) {
|
|
7
|
-
const { search, name, version } = e.data;
|
|
8
|
-
searching(search, { name, version }).then(function (result) {
|
|
9
|
-
self.postMessage(result);
|
|
10
|
-
});
|
|
11
|
-
};
|
|
1
|
+
/* eslint-disable no-restricted-globals */
|
|
2
|
+
import 'core-js/stable';
|
|
3
|
+
import 'regenerator-runtime/runtime';
|
|
4
|
+
import searching from './searching';
|
|
5
|
+
|
|
6
|
+
self.onmessage = function (e) {
|
|
7
|
+
const { search, name, version } = e.data;
|
|
8
|
+
searching(search, { name, version }).then(function (result) {
|
|
9
|
+
self.postMessage(result);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import { interpret } from './interpret';
|
|
2
|
-
import {
|
|
3
|
-
buildVectorialBindings,
|
|
4
|
-
buildBindingsForDeeperComponents,
|
|
5
|
-
} from '../lib/loops/bindings';
|
|
6
|
-
import { isFunction } from '../lib';
|
|
7
|
-
import {
|
|
8
|
-
CALCULATED_VAR_CATEGORY,
|
|
9
|
-
EVENT_VALUE_CHANGE,
|
|
10
|
-
} from '../../constants/event-types';
|
|
11
|
-
|
|
12
|
-
export const getCalculatedVariables =
|
|
13
|
-
(variables) =>
|
|
14
|
-
({ bindings, updatedVars, logFunction, init = false }) => {
|
|
15
|
-
let wip = {};
|
|
16
|
-
return Object.entries(variables).reduce((acc, [name, v]) => {
|
|
17
|
-
const value = getCalculatedVariable(v, name)(variables)({
|
|
18
|
-
bindings,
|
|
19
|
-
wip,
|
|
20
|
-
updatedVars,
|
|
21
|
-
logFunction,
|
|
22
|
-
init,
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
...acc,
|
|
26
|
-
[name]: value,
|
|
27
|
-
};
|
|
28
|
-
}, {});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const getCalculatedVariable =
|
|
32
|
-
(v, name) =>
|
|
33
|
-
(variables) =>
|
|
34
|
-
({ bindings, wip, updatedVars, logFunction, init }) => {
|
|
35
|
-
const { bindingDependencies } = v;
|
|
36
|
-
if (!init && !Array.isArray(bindingDependencies)) return v;
|
|
37
|
-
if (
|
|
38
|
-
Array.isArray(updatedVars) &&
|
|
39
|
-
updatedVars.length > 0 &&
|
|
40
|
-
Array.isArray(bindingDependencies) &&
|
|
41
|
-
!updatedVars.some((ai) => bindingDependencies.includes(ai))
|
|
42
|
-
)
|
|
43
|
-
return v;
|
|
44
|
-
const exactBindings = (bindingDependencies || []).reduce((acc, b) => {
|
|
45
|
-
if (bindings[b] !== undefined) return { ...acc, [b]: bindings[b] };
|
|
46
|
-
if (wip[b] !== undefined) return { ...acc, [b]: wip[b] };
|
|
47
|
-
const varToCalc = variables[b];
|
|
48
|
-
if (!varToCalc) return acc;
|
|
49
|
-
const newValue = getCalculatedVariable(varToCalc)(variables)({
|
|
50
|
-
bindings,
|
|
51
|
-
wip,
|
|
52
|
-
updatedVars,
|
|
53
|
-
init,
|
|
54
|
-
});
|
|
55
|
-
wip[b] = newValue.value;
|
|
56
|
-
return { ...acc, [b]: newValue.value };
|
|
57
|
-
}, {});
|
|
58
|
-
const { expression, shapeFrom } = v;
|
|
59
|
-
const value =
|
|
60
|
-
wip[name] !== undefined
|
|
61
|
-
? wip[name]
|
|
62
|
-
: getValue(bindings, exactBindings, expression, shapeFrom);
|
|
63
|
-
const handleTempMomentValue =
|
|
64
|
-
value && value._isAMomentObject ? value.format('DD-MM-YYYY') : value;
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
isFunction(logFunction) &&
|
|
68
|
-
// Filter only filterResult vars : name.startsWith('FILTER_RESULT_') &&
|
|
69
|
-
JSON.stringify(value) !== JSON.stringify(variables[name].value)
|
|
70
|
-
) {
|
|
71
|
-
logFunction({
|
|
72
|
-
idParadataObject: `${name}`,
|
|
73
|
-
typeParadataObject: CALCULATED_VAR_CATEGORY,
|
|
74
|
-
type: EVENT_VALUE_CHANGE,
|
|
75
|
-
oldValue: value,
|
|
76
|
-
newValue: variables[name]?.value,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (shapeFrom)
|
|
81
|
-
return {
|
|
82
|
-
expression,
|
|
83
|
-
bindingDependencies,
|
|
84
|
-
value: handleTempMomentValue,
|
|
85
|
-
shapeFrom,
|
|
86
|
-
};
|
|
87
|
-
return {
|
|
88
|
-
expression,
|
|
89
|
-
bindingDependencies,
|
|
90
|
-
value: handleTempMomentValue,
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const getValue = (bindings, exactBindings, expression, shapeFrom) => {
|
|
95
|
-
if (!shapeFrom) {
|
|
96
|
-
const vectorialBindings = buildVectorialBindings(exactBindings);
|
|
97
|
-
const res = interpret(['VTL'])(vectorialBindings)(expression);
|
|
98
|
-
return Array.isArray(res) ? res[0] : res;
|
|
99
|
-
}
|
|
100
|
-
const shape = bindings[shapeFrom];
|
|
101
|
-
return buildShape(exactBindings, expression)(shape);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const buildShape = (exactBindings, expression) => (array) =>
|
|
105
|
-
array.map((a, i) => {
|
|
106
|
-
const loopBindings = buildBindingsForDeeperComponents(i)(exactBindings);
|
|
107
|
-
if (Array.isArray(a)) {
|
|
108
|
-
return buildShape(loopBindings, expression)(a);
|
|
109
|
-
}
|
|
110
|
-
const vectorialBindings = buildVectorialBindings(loopBindings);
|
|
111
|
-
const res = interpret(['VTL'])(vectorialBindings)(expression);
|
|
112
|
-
return Array.isArray(res) ? res[0] : res;
|
|
113
|
-
});
|
|
1
|
+
import { interpret } from './interpret';
|
|
2
|
+
import {
|
|
3
|
+
buildVectorialBindings,
|
|
4
|
+
buildBindingsForDeeperComponents,
|
|
5
|
+
} from '../lib/loops/bindings';
|
|
6
|
+
import { isFunction } from '../lib';
|
|
7
|
+
import {
|
|
8
|
+
CALCULATED_VAR_CATEGORY,
|
|
9
|
+
EVENT_VALUE_CHANGE,
|
|
10
|
+
} from '../../constants/event-types';
|
|
11
|
+
|
|
12
|
+
export const getCalculatedVariables =
|
|
13
|
+
(variables) =>
|
|
14
|
+
({ bindings, updatedVars, logFunction, init = false }) => {
|
|
15
|
+
let wip = {};
|
|
16
|
+
return Object.entries(variables).reduce((acc, [name, v]) => {
|
|
17
|
+
const value = getCalculatedVariable(v, name)(variables)({
|
|
18
|
+
bindings,
|
|
19
|
+
wip,
|
|
20
|
+
updatedVars,
|
|
21
|
+
logFunction,
|
|
22
|
+
init,
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
...acc,
|
|
26
|
+
[name]: value,
|
|
27
|
+
};
|
|
28
|
+
}, {});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getCalculatedVariable =
|
|
32
|
+
(v, name) =>
|
|
33
|
+
(variables) =>
|
|
34
|
+
({ bindings, wip, updatedVars, logFunction, init }) => {
|
|
35
|
+
const { bindingDependencies } = v;
|
|
36
|
+
if (!init && !Array.isArray(bindingDependencies)) return v;
|
|
37
|
+
if (
|
|
38
|
+
Array.isArray(updatedVars) &&
|
|
39
|
+
updatedVars.length > 0 &&
|
|
40
|
+
Array.isArray(bindingDependencies) &&
|
|
41
|
+
!updatedVars.some((ai) => bindingDependencies.includes(ai))
|
|
42
|
+
)
|
|
43
|
+
return v;
|
|
44
|
+
const exactBindings = (bindingDependencies || []).reduce((acc, b) => {
|
|
45
|
+
if (bindings[b] !== undefined) return { ...acc, [b]: bindings[b] };
|
|
46
|
+
if (wip[b] !== undefined) return { ...acc, [b]: wip[b] };
|
|
47
|
+
const varToCalc = variables[b];
|
|
48
|
+
if (!varToCalc) return acc;
|
|
49
|
+
const newValue = getCalculatedVariable(varToCalc)(variables)({
|
|
50
|
+
bindings,
|
|
51
|
+
wip,
|
|
52
|
+
updatedVars,
|
|
53
|
+
init,
|
|
54
|
+
});
|
|
55
|
+
wip[b] = newValue.value;
|
|
56
|
+
return { ...acc, [b]: newValue.value };
|
|
57
|
+
}, {});
|
|
58
|
+
const { expression, shapeFrom } = v;
|
|
59
|
+
const value =
|
|
60
|
+
wip[name] !== undefined
|
|
61
|
+
? wip[name]
|
|
62
|
+
: getValue(bindings, exactBindings, expression, shapeFrom);
|
|
63
|
+
const handleTempMomentValue =
|
|
64
|
+
value && value._isAMomentObject ? value.format('DD-MM-YYYY') : value;
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
isFunction(logFunction) &&
|
|
68
|
+
// Filter only filterResult vars : name.startsWith('FILTER_RESULT_') &&
|
|
69
|
+
JSON.stringify(value) !== JSON.stringify(variables[name].value)
|
|
70
|
+
) {
|
|
71
|
+
logFunction({
|
|
72
|
+
idParadataObject: `${name}`,
|
|
73
|
+
typeParadataObject: CALCULATED_VAR_CATEGORY,
|
|
74
|
+
type: EVENT_VALUE_CHANGE,
|
|
75
|
+
oldValue: value,
|
|
76
|
+
newValue: variables[name]?.value,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (shapeFrom)
|
|
81
|
+
return {
|
|
82
|
+
expression,
|
|
83
|
+
bindingDependencies,
|
|
84
|
+
value: handleTempMomentValue,
|
|
85
|
+
shapeFrom,
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
expression,
|
|
89
|
+
bindingDependencies,
|
|
90
|
+
value: handleTempMomentValue,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const getValue = (bindings, exactBindings, expression, shapeFrom) => {
|
|
95
|
+
if (!shapeFrom) {
|
|
96
|
+
const vectorialBindings = buildVectorialBindings(exactBindings);
|
|
97
|
+
const res = interpret(['VTL'])(vectorialBindings)(expression);
|
|
98
|
+
return Array.isArray(res) ? res[0] : res;
|
|
99
|
+
}
|
|
100
|
+
const shape = bindings[shapeFrom];
|
|
101
|
+
return buildShape(exactBindings, expression)(shape);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const buildShape = (exactBindings, expression) => (array) =>
|
|
105
|
+
array.map((a, i) => {
|
|
106
|
+
const loopBindings = buildBindingsForDeeperComponents(i)(exactBindings);
|
|
107
|
+
if (Array.isArray(a)) {
|
|
108
|
+
return buildShape(loopBindings, expression)(a);
|
|
109
|
+
}
|
|
110
|
+
const vectorialBindings = buildVectorialBindings(loopBindings);
|
|
111
|
+
const res = interpret(['VTL'])(vectorialBindings)(expression);
|
|
112
|
+
return Array.isArray(res) ? res[0] : res;
|
|
113
|
+
});
|
|
@@ -1,112 +1,149 @@
|
|
|
1
|
-
import * as C from '../../constants';
|
|
2
|
-
import { buildFilledComponent } from './init-questionnaire';
|
|
3
|
-
import { supportedPreferences } from '../../constants/supported-preferences';
|
|
4
|
-
import { getCalculatedVariables } from './calculated-variables';
|
|
5
|
-
import { isDev } from '../lib';
|
|
6
|
-
|
|
7
|
-
export const updateQuestionnaire =
|
|
8
|
-
(valueType) =>
|
|
9
|
-
(questionnaire) =>
|
|
10
|
-
(preferences, logFunction) =>
|
|
11
|
-
(updatedValues) => {
|
|
12
|
-
if (
|
|
13
|
-
!supportedPreferences.includes(valueType) ||
|
|
14
|
-
preferences.length === 0 ||
|
|
15
|
-
!updatedValues
|
|
16
|
-
)
|
|
17
|
-
return questionnaire;
|
|
18
|
-
const { variables, components, ...other } = questionnaire;
|
|
19
|
-
if (!components || components.length === 0) return questionnaire;
|
|
20
|
-
const varsAndRefs = Object.entries(updatedValues).reduce(
|
|
21
|
-
(acc, [key, value]) => {
|
|
22
|
-
const {
|
|
23
|
-
newVariables: { COLLECTED, ...otherVars },
|
|
24
|
-
refs,
|
|
25
|
-
} = acc;
|
|
26
|
-
const { componentRef, values } = COLLECTED[key];
|
|
27
|
-
const updated = {
|
|
28
|
-
componentRef,
|
|
29
|
-
values: {
|
|
30
|
-
...values,
|
|
31
|
-
[valueType]: buildNewValue(preferences)(valueType)(values)(value),
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
const newCollected = { ...COLLECTED, [key]: updated };
|
|
35
|
-
return {
|
|
36
|
-
newVariables: {
|
|
37
|
-
...otherVars,
|
|
38
|
-
COLLECTED: newCollected,
|
|
39
|
-
},
|
|
40
|
-
refs: [...refs, componentRef],
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
{ newVariables: variables, refs: [] }
|
|
44
|
-
);
|
|
45
|
-
const { newVariables, refs: r } = varsAndRefs;
|
|
46
|
-
const newVariablesWithCalculated =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const collectedVars = newVariables[C.COLLECTED];
|
|
51
|
-
const newComponents = components.map((c) => {
|
|
52
|
-
if (r.includes(c.id)) return buildFilledComponent(collectedVars)(c);
|
|
53
|
-
return c;
|
|
54
|
-
});
|
|
55
|
-
return {
|
|
56
|
-
...other,
|
|
57
|
-
variables: newVariablesWithCalculated,
|
|
58
|
-
components: newComponents,
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const
|
|
63
|
-
(
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const { COLLECTED, EXTERNAL
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
1
|
+
import * as C from '../../constants';
|
|
2
|
+
import { buildFilledComponent } from './init-questionnaire';
|
|
3
|
+
import { supportedPreferences } from '../../constants/supported-preferences';
|
|
4
|
+
import { getCalculatedVariables } from './calculated-variables';
|
|
5
|
+
import { isDev } from '../lib';
|
|
6
|
+
|
|
7
|
+
export const updateQuestionnaire =
|
|
8
|
+
(valueType) =>
|
|
9
|
+
(questionnaire) =>
|
|
10
|
+
(preferences, logFunction) =>
|
|
11
|
+
(updatedValues) => {
|
|
12
|
+
if (
|
|
13
|
+
!supportedPreferences.includes(valueType) ||
|
|
14
|
+
preferences.length === 0 ||
|
|
15
|
+
!updatedValues
|
|
16
|
+
)
|
|
17
|
+
return questionnaire;
|
|
18
|
+
const { variables, components, ...other } = questionnaire;
|
|
19
|
+
if (!components || components.length === 0) return questionnaire;
|
|
20
|
+
const varsAndRefs = Object.entries(updatedValues).reduce(
|
|
21
|
+
(acc, [key, value]) => {
|
|
22
|
+
const {
|
|
23
|
+
newVariables: { COLLECTED, ...otherVars },
|
|
24
|
+
refs,
|
|
25
|
+
} = acc;
|
|
26
|
+
const { componentRef, values } = COLLECTED[key];
|
|
27
|
+
const updated = {
|
|
28
|
+
componentRef,
|
|
29
|
+
values: {
|
|
30
|
+
...values,
|
|
31
|
+
[valueType]: buildNewValue(preferences)(valueType)(values)(value),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const newCollected = { ...COLLECTED, [key]: updated };
|
|
35
|
+
return {
|
|
36
|
+
newVariables: {
|
|
37
|
+
...otherVars,
|
|
38
|
+
COLLECTED: newCollected,
|
|
39
|
+
},
|
|
40
|
+
refs: [...refs, componentRef],
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
{ newVariables: variables, refs: [] }
|
|
44
|
+
);
|
|
45
|
+
const { newVariables, refs: r } = varsAndRefs;
|
|
46
|
+
const newVariablesWithCalculated = addCalculatedVars(
|
|
47
|
+
newVariables,
|
|
48
|
+
updatedValues
|
|
49
|
+
)(logFunction, preferences);
|
|
50
|
+
const collectedVars = newVariables[C.COLLECTED];
|
|
51
|
+
const newComponents = components.map((c) => {
|
|
52
|
+
if (r.includes(c.id)) return buildFilledComponent(collectedVars)(c);
|
|
53
|
+
return c;
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
...other,
|
|
57
|
+
variables: newVariablesWithCalculated,
|
|
58
|
+
components: newComponents,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const updateExternals =
|
|
63
|
+
(questionnaire) => (logFunction, preferences) => (updatedValues) => {
|
|
64
|
+
const { variables, ...other } = questionnaire;
|
|
65
|
+
const { EXTERNAL } = variables;
|
|
66
|
+
const newVariables = {
|
|
67
|
+
...variables,
|
|
68
|
+
EXTERNAL: { ...EXTERNAL, ...updatedValues },
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const newVariablesWithCalculated = addCalculatedVars(
|
|
72
|
+
newVariables,
|
|
73
|
+
updatedValues
|
|
74
|
+
)(logFunction, preferences);
|
|
75
|
+
return {
|
|
76
|
+
...other,
|
|
77
|
+
variables: newVariablesWithCalculated,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const buildNewValue =
|
|
82
|
+
(preferences) => (valueType) => (oldValues) => (value) => {
|
|
83
|
+
if (preferences.length === 1) return value;
|
|
84
|
+
const index = preferences.indexOf(valueType);
|
|
85
|
+
if (index < 1) return value;
|
|
86
|
+
const valuesByPreference = preferences
|
|
87
|
+
.slice(0, index)
|
|
88
|
+
.map((p) => oldValues[p])
|
|
89
|
+
.filter((v) => v !== null);
|
|
90
|
+
const lastValue = valuesByPreference[valuesByPreference.length - 1];
|
|
91
|
+
return lastValue === value ? null : value;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Separate methods to avoid perf issue on collect simplest use case
|
|
95
|
+
const getCollectedAndExternal = (preferences) => (variables) => {
|
|
96
|
+
const { COLLECTED, EXTERNAL } = variables;
|
|
97
|
+
if (preferences.length === 1 && preferences[0] === 'COLLECTED')
|
|
98
|
+
return { ...getCollectedAndExternalSimple(COLLECTED), ...EXTERNAL };
|
|
99
|
+
return {
|
|
100
|
+
...getCollectedAndExternalByPreferences(preferences)(COLLECTED),
|
|
101
|
+
...EXTERNAL,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const getCollectedAndExternalSimple = (variables) =>
|
|
106
|
+
Object.entries(variables).reduce(
|
|
107
|
+
(acc, [k, { values }]) => ({ ...acc, [k]: values.COLLECTED }),
|
|
108
|
+
{}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const getCollectedAndExternalByPreferences = (preferences) => (variables) =>
|
|
112
|
+
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
|
+
|
|
120
|
+
const addCalculatedVars =
|
|
121
|
+
(variables, updatedValues) => (logFunction, preferences) => {
|
|
122
|
+
if (
|
|
123
|
+
!variables[C.CALCULATED] ||
|
|
124
|
+
Object.keys(variables[C.CALCULATED]).length === 0
|
|
125
|
+
)
|
|
126
|
+
return variables;
|
|
127
|
+
|
|
128
|
+
if (isDev) {
|
|
129
|
+
console.log('Start var calculation');
|
|
130
|
+
var start = new Date().getTime();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const { COLLECTED, EXTERNAL, CALCULATED: calculatedVariables } = variables;
|
|
134
|
+
|
|
135
|
+
const updatedVars = Object.keys(updatedValues);
|
|
136
|
+
|
|
137
|
+
const bindings = getCollectedAndExternal(preferences)(variables);
|
|
138
|
+
|
|
139
|
+
const CALCULATED = getCalculatedVariables(calculatedVariables)({
|
|
140
|
+
bindings,
|
|
141
|
+
updatedVars,
|
|
142
|
+
logFunction,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (isDev)
|
|
146
|
+
console.log(`End var calculation: ${new Date().getTime() - start} ms`);
|
|
147
|
+
|
|
148
|
+
return { EXTERNAL, COLLECTED, CALCULATED };
|
|
149
|
+
};
|