@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,231 +1,231 @@
|
|
|
1
|
-
import React, { useState, useRef, useEffect } from 'react';
|
|
2
|
-
import KeyboardEventHandler from 'react-keyboard-event-handler';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import
|
|
5
|
-
import debounce from 'lodash.debounce';
|
|
6
|
-
import Declarations from '../declarations';
|
|
7
|
-
import Icon from '../icon';
|
|
8
|
-
import { TooltipResponse } from '../tooltip';
|
|
9
|
-
import * as U from '../../utils/lib';
|
|
10
|
-
import * as C from '../../constants';
|
|
11
|
-
import { interpret } from '../../utils/to-expose';
|
|
12
|
-
import './checkbox.scss';
|
|
13
|
-
|
|
14
|
-
const CheckboxGroup = ({
|
|
15
|
-
id,
|
|
16
|
-
label,
|
|
17
|
-
preferences,
|
|
18
|
-
responses,
|
|
19
|
-
handleChange: propsHandleChange,
|
|
20
|
-
disabled,
|
|
21
|
-
focused,
|
|
22
|
-
shortcut,
|
|
23
|
-
positioning,
|
|
24
|
-
declarations,
|
|
25
|
-
features,
|
|
26
|
-
bindings,
|
|
27
|
-
management,
|
|
28
|
-
style,
|
|
29
|
-
logFunction,
|
|
30
|
-
}) => {
|
|
31
|
-
const { fieldsetStyle, modalityStyle } = style;
|
|
32
|
-
const inputRef = useRef();
|
|
33
|
-
|
|
34
|
-
const [values, setValues] = useState(() =>
|
|
35
|
-
responses.map(({ response }) =>
|
|
36
|
-
U.getResponseByPreference(preferences)(response)
|
|
37
|
-
)
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const handleChange = debounce((obj) => propsHandleChange(obj), 50);
|
|
41
|
-
|
|
42
|
-
const specificHandleChange = (e) => {
|
|
43
|
-
const [key, value] = Object.entries(e)[0];
|
|
44
|
-
if (value === false && U.responsesToClean(responses)(preferences)(key))
|
|
45
|
-
handleChange({ [key]: null });
|
|
46
|
-
else handleChange(e);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Assume we only want to handle enable external updates
|
|
50
|
-
// Don't need to check all value changes
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
const newValues = responses.map(({ response }) =>
|
|
53
|
-
U.getResponseByPreference(preferences)(response)
|
|
54
|
-
);
|
|
55
|
-
if (newValues.join('|') !== values.join('|')) setValues(newValues);
|
|
56
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
-
}, [responses, preferences]);
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (focused) inputRef.current.focus();
|
|
61
|
-
}, [focused]);
|
|
62
|
-
|
|
63
|
-
const checkedArray = [];
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<>
|
|
67
|
-
<Declarations
|
|
68
|
-
id={id}
|
|
69
|
-
type={C.BEFORE_QUESTION_TEXT}
|
|
70
|
-
declarations={declarations}
|
|
71
|
-
features={features}
|
|
72
|
-
bindings={bindings}
|
|
73
|
-
/>
|
|
74
|
-
<fieldset
|
|
75
|
-
key={`checkbox-${id}`}
|
|
76
|
-
className="checkbox-group-list"
|
|
77
|
-
style={U.buildStyleObject(fieldsetStyle)}
|
|
78
|
-
>
|
|
79
|
-
<legend>{interpret(features, logFunction)(bindings)(label)}</legend>
|
|
80
|
-
<Declarations
|
|
81
|
-
id={id}
|
|
82
|
-
type={C.AFTER_QUESTION_TEXT}
|
|
83
|
-
declarations={declarations}
|
|
84
|
-
features={features}
|
|
85
|
-
bindings={bindings}
|
|
86
|
-
/>
|
|
87
|
-
{responses.map(({ id: modId, label: modLabel, response }, i) => {
|
|
88
|
-
const checked = values[i];
|
|
89
|
-
if (checked) checkedArray.push(modId);
|
|
90
|
-
const toRef =
|
|
91
|
-
i === 0 || (checkedArray[0] && checkedArray[0] === modId);
|
|
92
|
-
const interpretedLabel = interpret(features)(bindings)(modLabel);
|
|
93
|
-
const keyboardSelectionKey =
|
|
94
|
-
responses.length < 10 ? `${i + 1}` : U.getAlphabet()[i];
|
|
95
|
-
return (
|
|
96
|
-
<div
|
|
97
|
-
className={`${U.getItemsPositioningClass(positioning)}`}
|
|
98
|
-
key={`checkbox-${id}-${modId}`}
|
|
99
|
-
>
|
|
100
|
-
<div className="field-container">
|
|
101
|
-
<div
|
|
102
|
-
className={`${management ? 'field-with-tooltip' : 'field'}`}
|
|
103
|
-
>
|
|
104
|
-
<div
|
|
105
|
-
className={`checkbox-modality ${
|
|
106
|
-
checked ? 'content-checked' : ''
|
|
107
|
-
}`}
|
|
108
|
-
>
|
|
109
|
-
<Icon type="checkbox" checked={checked} disabled={disabled}>
|
|
110
|
-
<input
|
|
111
|
-
type="checkbox"
|
|
112
|
-
id={`checkbox-${id}-${modId}`}
|
|
113
|
-
ref={toRef ? inputRef : null}
|
|
114
|
-
key={`checkbox-${id}-${modId}`}
|
|
115
|
-
aria-labelledby={`input-label-${id}-${modId}`}
|
|
116
|
-
className="checkbox-lunatic"
|
|
117
|
-
checked={checked || false}
|
|
118
|
-
disabled={disabled}
|
|
119
|
-
onChange={({ target: { checked } }) => {
|
|
120
|
-
setValues(
|
|
121
|
-
values.map((v, j) => (i === j ? checked : v))
|
|
122
|
-
);
|
|
123
|
-
specificHandleChange({
|
|
124
|
-
[U.getResponseName(response)]: checked,
|
|
125
|
-
});
|
|
126
|
-
if (U.isFunction(logFunction))
|
|
127
|
-
logFunction(
|
|
128
|
-
U.createObjectEvent(
|
|
129
|
-
`checkbox-${id}-${modId}`,
|
|
130
|
-
C.INPUT_CATEGORY,
|
|
131
|
-
C.EVENT_SELECTION,
|
|
132
|
-
U.getResponseName(response),
|
|
133
|
-
checked
|
|
134
|
-
)
|
|
135
|
-
);
|
|
136
|
-
}}
|
|
137
|
-
/>
|
|
138
|
-
<label
|
|
139
|
-
htmlFor={`checkbox-${id}-${modId}`}
|
|
140
|
-
id={`input-label-${id}-${modId}`}
|
|
141
|
-
style={checked ? U.buildStyleObject(modalityStyle) : {}}
|
|
142
|
-
className="modality-label"
|
|
143
|
-
>
|
|
144
|
-
{shortcut && (
|
|
145
|
-
<span className="code-modality">
|
|
146
|
-
{keyboardSelectionKey.toUpperCase()}
|
|
147
|
-
</span>
|
|
148
|
-
)}
|
|
149
|
-
{interpretedLabel}
|
|
150
|
-
</label>
|
|
151
|
-
</Icon>
|
|
152
|
-
</div>
|
|
153
|
-
</div>
|
|
154
|
-
{management && (
|
|
155
|
-
<div className="tooltip">
|
|
156
|
-
<TooltipResponse
|
|
157
|
-
id={id}
|
|
158
|
-
response={U.buildBooleanTooltipResponse(response)}
|
|
159
|
-
/>
|
|
160
|
-
</div>
|
|
161
|
-
)}
|
|
162
|
-
</div>
|
|
163
|
-
{shortcut && (
|
|
164
|
-
<KeyboardEventHandler
|
|
165
|
-
handleKeys={[keyboardSelectionKey.toLowerCase()]}
|
|
166
|
-
onKeyEvent={(key, e) => {
|
|
167
|
-
e.preventDefault();
|
|
168
|
-
setValues(values.map((v, j) => (i === j ? !checked : v)));
|
|
169
|
-
specificHandleChange({
|
|
170
|
-
[U.getResponseName(response)]: !checked,
|
|
171
|
-
});
|
|
172
|
-
if (U.isFunction(logFunction))
|
|
173
|
-
logFunction(
|
|
174
|
-
U.createObjectEvent(
|
|
175
|
-
`checkbox-${id}-${modId}`,
|
|
176
|
-
C.INPUT_CATEGORY,
|
|
177
|
-
C.EVENT_SELECTION,
|
|
178
|
-
U.getResponseName(response),
|
|
179
|
-
!checked
|
|
180
|
-
)
|
|
181
|
-
);
|
|
182
|
-
}}
|
|
183
|
-
handleFocusableElements
|
|
184
|
-
/>
|
|
185
|
-
)}
|
|
186
|
-
</div>
|
|
187
|
-
);
|
|
188
|
-
})}
|
|
189
|
-
</fieldset>
|
|
190
|
-
<Declarations
|
|
191
|
-
id={id}
|
|
192
|
-
type={C.DETACHABLE}
|
|
193
|
-
declarations={declarations}
|
|
194
|
-
features={features}
|
|
195
|
-
bindings={bindings}
|
|
196
|
-
/>
|
|
197
|
-
</>
|
|
198
|
-
);
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
CheckboxGroup.defaultProps = {
|
|
202
|
-
label: '',
|
|
203
|
-
preferences: ['COLLECTED'],
|
|
204
|
-
responses: [],
|
|
205
|
-
disabled: false,
|
|
206
|
-
focused: false,
|
|
207
|
-
positioning: 'DEFAULT',
|
|
208
|
-
declarations: [],
|
|
209
|
-
features: [],
|
|
210
|
-
bindings: {},
|
|
211
|
-
management: false,
|
|
212
|
-
style: { fieldsetStyle: {}, modalityStyle: {} },
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
CheckboxGroup.propTypes = {
|
|
216
|
-
id: PropTypes.string.isRequired,
|
|
217
|
-
label: PropTypes.string,
|
|
218
|
-
preferences: PropTypes.arrayOf(U.valueTypePropTypes),
|
|
219
|
-
response: U.responsePropTypes,
|
|
220
|
-
handleChange: PropTypes.func.isRequired,
|
|
221
|
-
disabled: PropTypes.bool,
|
|
222
|
-
focused: PropTypes.bool,
|
|
223
|
-
positioning: PropTypes.oneOf(['DEFAULT', 'HORIZONTAL', 'VERTICAL']),
|
|
224
|
-
declarations: U.declarationsPropTypes,
|
|
225
|
-
features: PropTypes.arrayOf(PropTypes.string),
|
|
226
|
-
bindings: PropTypes.object,
|
|
227
|
-
management: PropTypes.bool,
|
|
228
|
-
style: PropTypes.object,
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
export default
|
|
1
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import KeyboardEventHandler from 'react-keyboard-event-handler';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import componentWrapper from '../component-wrapper';
|
|
5
|
+
import debounce from 'lodash.debounce';
|
|
6
|
+
import Declarations from '../declarations';
|
|
7
|
+
import Icon from '../icon';
|
|
8
|
+
import { TooltipResponse } from '../tooltip';
|
|
9
|
+
import * as U from '../../utils/lib';
|
|
10
|
+
import * as C from '../../constants';
|
|
11
|
+
import { interpret } from '../../utils/to-expose';
|
|
12
|
+
import './checkbox.scss';
|
|
13
|
+
|
|
14
|
+
const CheckboxGroup = ({
|
|
15
|
+
id,
|
|
16
|
+
label,
|
|
17
|
+
preferences,
|
|
18
|
+
responses,
|
|
19
|
+
handleChange: propsHandleChange,
|
|
20
|
+
disabled,
|
|
21
|
+
focused,
|
|
22
|
+
shortcut,
|
|
23
|
+
positioning,
|
|
24
|
+
declarations,
|
|
25
|
+
features,
|
|
26
|
+
bindings,
|
|
27
|
+
management,
|
|
28
|
+
style,
|
|
29
|
+
logFunction,
|
|
30
|
+
}) => {
|
|
31
|
+
const { fieldsetStyle, modalityStyle } = style;
|
|
32
|
+
const inputRef = useRef();
|
|
33
|
+
|
|
34
|
+
const [values, setValues] = useState(() =>
|
|
35
|
+
responses.map(({ response }) =>
|
|
36
|
+
U.getResponseByPreference(preferences)(response)
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const handleChange = debounce((obj) => propsHandleChange(obj), 50);
|
|
41
|
+
|
|
42
|
+
const specificHandleChange = (e) => {
|
|
43
|
+
const [key, value] = Object.entries(e)[0];
|
|
44
|
+
if (value === false && U.responsesToClean(responses)(preferences)(key))
|
|
45
|
+
handleChange({ [key]: null });
|
|
46
|
+
else handleChange(e);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Assume we only want to handle enable external updates
|
|
50
|
+
// Don't need to check all value changes
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const newValues = responses.map(({ response }) =>
|
|
53
|
+
U.getResponseByPreference(preferences)(response)
|
|
54
|
+
);
|
|
55
|
+
if (newValues.join('|') !== values.join('|')) setValues(newValues);
|
|
56
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
+
}, [responses, preferences]);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (focused) inputRef.current.focus();
|
|
61
|
+
}, [focused]);
|
|
62
|
+
|
|
63
|
+
const checkedArray = [];
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<Declarations
|
|
68
|
+
id={id}
|
|
69
|
+
type={C.BEFORE_QUESTION_TEXT}
|
|
70
|
+
declarations={declarations}
|
|
71
|
+
features={features}
|
|
72
|
+
bindings={bindings}
|
|
73
|
+
/>
|
|
74
|
+
<fieldset
|
|
75
|
+
key={`checkbox-${id}`}
|
|
76
|
+
className="checkbox-group-list"
|
|
77
|
+
style={U.buildStyleObject(fieldsetStyle)}
|
|
78
|
+
>
|
|
79
|
+
<legend>{interpret(features, logFunction)(bindings)(label)}</legend>
|
|
80
|
+
<Declarations
|
|
81
|
+
id={id}
|
|
82
|
+
type={C.AFTER_QUESTION_TEXT}
|
|
83
|
+
declarations={declarations}
|
|
84
|
+
features={features}
|
|
85
|
+
bindings={bindings}
|
|
86
|
+
/>
|
|
87
|
+
{responses.map(({ id: modId, label: modLabel, response }, i) => {
|
|
88
|
+
const checked = values[i];
|
|
89
|
+
if (checked) checkedArray.push(modId);
|
|
90
|
+
const toRef =
|
|
91
|
+
i === 0 || (checkedArray[0] && checkedArray[0] === modId);
|
|
92
|
+
const interpretedLabel = interpret(features)(bindings)(modLabel);
|
|
93
|
+
const keyboardSelectionKey =
|
|
94
|
+
responses.length < 10 ? `${i + 1}` : U.getAlphabet()[i];
|
|
95
|
+
return (
|
|
96
|
+
<div
|
|
97
|
+
className={`${U.getItemsPositioningClass(positioning)}`}
|
|
98
|
+
key={`checkbox-${id}-${modId}`}
|
|
99
|
+
>
|
|
100
|
+
<div className="field-container">
|
|
101
|
+
<div
|
|
102
|
+
className={`${management ? 'field-with-tooltip' : 'field'}`}
|
|
103
|
+
>
|
|
104
|
+
<div
|
|
105
|
+
className={`checkbox-modality ${
|
|
106
|
+
checked ? 'content-checked' : ''
|
|
107
|
+
}`}
|
|
108
|
+
>
|
|
109
|
+
<Icon type="checkbox" checked={checked} disabled={disabled}>
|
|
110
|
+
<input
|
|
111
|
+
type="checkbox"
|
|
112
|
+
id={`checkbox-${id}-${modId}`}
|
|
113
|
+
ref={toRef ? inputRef : null}
|
|
114
|
+
key={`checkbox-${id}-${modId}`}
|
|
115
|
+
aria-labelledby={`input-label-${id}-${modId}`}
|
|
116
|
+
className="checkbox-lunatic"
|
|
117
|
+
checked={checked || false}
|
|
118
|
+
disabled={disabled}
|
|
119
|
+
onChange={({ target: { checked } }) => {
|
|
120
|
+
setValues(
|
|
121
|
+
values.map((v, j) => (i === j ? checked : v))
|
|
122
|
+
);
|
|
123
|
+
specificHandleChange({
|
|
124
|
+
[U.getResponseName(response)]: checked,
|
|
125
|
+
});
|
|
126
|
+
if (U.isFunction(logFunction))
|
|
127
|
+
logFunction(
|
|
128
|
+
U.createObjectEvent(
|
|
129
|
+
`checkbox-${id}-${modId}`,
|
|
130
|
+
C.INPUT_CATEGORY,
|
|
131
|
+
C.EVENT_SELECTION,
|
|
132
|
+
U.getResponseName(response),
|
|
133
|
+
checked
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
<label
|
|
139
|
+
htmlFor={`checkbox-${id}-${modId}`}
|
|
140
|
+
id={`input-label-${id}-${modId}`}
|
|
141
|
+
style={checked ? U.buildStyleObject(modalityStyle) : {}}
|
|
142
|
+
className="modality-label"
|
|
143
|
+
>
|
|
144
|
+
{shortcut && (
|
|
145
|
+
<span className="code-modality">
|
|
146
|
+
{keyboardSelectionKey.toUpperCase()}
|
|
147
|
+
</span>
|
|
148
|
+
)}
|
|
149
|
+
{interpretedLabel}
|
|
150
|
+
</label>
|
|
151
|
+
</Icon>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
{management && (
|
|
155
|
+
<div className="tooltip">
|
|
156
|
+
<TooltipResponse
|
|
157
|
+
id={id}
|
|
158
|
+
response={U.buildBooleanTooltipResponse(response)}
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
{shortcut && (
|
|
164
|
+
<KeyboardEventHandler
|
|
165
|
+
handleKeys={[keyboardSelectionKey.toLowerCase()]}
|
|
166
|
+
onKeyEvent={(key, e) => {
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
setValues(values.map((v, j) => (i === j ? !checked : v)));
|
|
169
|
+
specificHandleChange({
|
|
170
|
+
[U.getResponseName(response)]: !checked,
|
|
171
|
+
});
|
|
172
|
+
if (U.isFunction(logFunction))
|
|
173
|
+
logFunction(
|
|
174
|
+
U.createObjectEvent(
|
|
175
|
+
`checkbox-${id}-${modId}`,
|
|
176
|
+
C.INPUT_CATEGORY,
|
|
177
|
+
C.EVENT_SELECTION,
|
|
178
|
+
U.getResponseName(response),
|
|
179
|
+
!checked
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
}}
|
|
183
|
+
handleFocusableElements
|
|
184
|
+
/>
|
|
185
|
+
)}
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
})}
|
|
189
|
+
</fieldset>
|
|
190
|
+
<Declarations
|
|
191
|
+
id={id}
|
|
192
|
+
type={C.DETACHABLE}
|
|
193
|
+
declarations={declarations}
|
|
194
|
+
features={features}
|
|
195
|
+
bindings={bindings}
|
|
196
|
+
/>
|
|
197
|
+
</>
|
|
198
|
+
);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
CheckboxGroup.defaultProps = {
|
|
202
|
+
label: '',
|
|
203
|
+
preferences: ['COLLECTED'],
|
|
204
|
+
responses: [],
|
|
205
|
+
disabled: false,
|
|
206
|
+
focused: false,
|
|
207
|
+
positioning: 'DEFAULT',
|
|
208
|
+
declarations: [],
|
|
209
|
+
features: [],
|
|
210
|
+
bindings: {},
|
|
211
|
+
management: false,
|
|
212
|
+
style: { fieldsetStyle: {}, modalityStyle: {} },
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
CheckboxGroup.propTypes = {
|
|
216
|
+
id: PropTypes.string.isRequired,
|
|
217
|
+
label: PropTypes.string,
|
|
218
|
+
preferences: PropTypes.arrayOf(U.valueTypePropTypes),
|
|
219
|
+
response: U.responsePropTypes,
|
|
220
|
+
handleChange: PropTypes.func.isRequired,
|
|
221
|
+
disabled: PropTypes.bool,
|
|
222
|
+
focused: PropTypes.bool,
|
|
223
|
+
positioning: PropTypes.oneOf(['DEFAULT', 'HORIZONTAL', 'VERTICAL']),
|
|
224
|
+
declarations: U.declarationsPropTypes,
|
|
225
|
+
features: PropTypes.arrayOf(PropTypes.string),
|
|
226
|
+
bindings: PropTypes.object,
|
|
227
|
+
management: PropTypes.bool,
|
|
228
|
+
style: PropTypes.object,
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export default componentWrapper(React.memo(CheckboxGroup, U.areEqual));
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { ListDeclarationsWrapper } from '../declarations/wrappers';
|
|
4
|
-
import { areEqual } from '../../utils/lib';
|
|
5
|
-
import './checkbox.scss';
|
|
6
|
-
|
|
7
|
-
const CheckboxOne = (props) => (
|
|
8
|
-
<ListDeclarationsWrapper type="checkbox" {...props} hasSpecificHandler />
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
export default
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import componentWrapper from '../component-wrapper';
|
|
3
|
+
import { ListDeclarationsWrapper } from '../declarations/wrappers';
|
|
4
|
+
import { areEqual } from '../../utils/lib';
|
|
5
|
+
import './checkbox.scss';
|
|
6
|
+
|
|
7
|
+
const CheckboxOne = (props) => (
|
|
8
|
+
<ListDeclarationsWrapper type="checkbox" {...props} hasSpecificHandler />
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export default componentWrapper(React.memo(CheckboxOne, areEqual));
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import * as U from '../../../utils/lib';
|
|
3
|
+
import { interpret } from '../../../utils/to-expose/interpret';
|
|
4
|
+
import './controls.scss';
|
|
5
|
+
|
|
6
|
+
const Controls = ({ Component, props }) => {
|
|
7
|
+
// handle responses & cells
|
|
8
|
+
const {
|
|
9
|
+
response,
|
|
10
|
+
responses,
|
|
11
|
+
cells,
|
|
12
|
+
components,
|
|
13
|
+
preferences,
|
|
14
|
+
missingResponse,
|
|
15
|
+
savingType,
|
|
16
|
+
} = props;
|
|
17
|
+
// savingType or preferences[preferences.length-1]?
|
|
18
|
+
const [applyControls, setApplyControls] = useState(() =>
|
|
19
|
+
U.hasToCleanMissing(savingType)({ response, responses, cells, components })
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!applyControls) {
|
|
24
|
+
if (
|
|
25
|
+
U.hasToCleanMissing(savingType)({
|
|
26
|
+
response,
|
|
27
|
+
responses,
|
|
28
|
+
cells,
|
|
29
|
+
components,
|
|
30
|
+
})
|
|
31
|
+
) {
|
|
32
|
+
setApplyControls(true);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, [response, responses, cells, components, applyControls, savingType]);
|
|
36
|
+
|
|
37
|
+
const hasMissingResponse =
|
|
38
|
+
U.getResponseByPreference(preferences)(missingResponse) !== null;
|
|
39
|
+
|
|
40
|
+
const { controls, features, bindings } = props;
|
|
41
|
+
const featuresWithoutMD = features.filter((f) => f !== 'MD');
|
|
42
|
+
const filteredControls =
|
|
43
|
+
(!applyControls && !hasMissingResponse) || !controls
|
|
44
|
+
? []
|
|
45
|
+
: controls.filter((control) => {
|
|
46
|
+
const { bindingDependencies, control: formula } = control;
|
|
47
|
+
const reducedBindings = (bindingDependencies || []).reduce(
|
|
48
|
+
(acc, bD) => ({ ...acc, [bD]: bindings[bD] }),
|
|
49
|
+
{}
|
|
50
|
+
);
|
|
51
|
+
const vectorialBindings = U.buildVectorialBindings(reducedBindings);
|
|
52
|
+
return (
|
|
53
|
+
interpret(featuresWithoutMD)(vectorialBindings)(formula) !== true
|
|
54
|
+
);
|
|
55
|
+
}, []);
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<Component {...props} />
|
|
59
|
+
<div className="lunatic-controls">
|
|
60
|
+
{filteredControls.map(({ id, errorMessage }) => (
|
|
61
|
+
<div key={`control-${id}`} className="lunatic-control">
|
|
62
|
+
{errorMessage}
|
|
63
|
+
</div>
|
|
64
|
+
))}
|
|
65
|
+
</div>
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default Controls;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './component';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import compareAsc from 'date-fns/compareAsc';
|
|
2
|
+
import format from 'date-fns/format';
|
|
3
|
+
|
|
4
|
+
export const minMaxValidatorDatepicker =
|
|
5
|
+
({ min, max, id }) =>
|
|
6
|
+
(value) => {
|
|
7
|
+
const errorMessage = getMessage(min, max, value);
|
|
8
|
+
if (errorMessage) return { id: `control-${id}`, errorMessage };
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getMessage = (min, max, value) => {
|
|
13
|
+
if (!value) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const dateFormat = 'dd-MM-yyyy';
|
|
17
|
+
const date = new Date(value);
|
|
18
|
+
if (isDef(min) && isDef(max)) {
|
|
19
|
+
const minDate = new Date(min);
|
|
20
|
+
const maxDate = new Date(max);
|
|
21
|
+
if (date < minDate || date > maxDate) {
|
|
22
|
+
const minDateAsString = minDate ? format(minDate, dateFormat) : '';
|
|
23
|
+
const maxDateAsString = maxDate ? format(maxDate, dateFormat) : '';
|
|
24
|
+
return `La date doit être comprise entre le ${minDateAsString} et le ${maxDateAsString}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (isDef(min)) {
|
|
28
|
+
const minDate = new Date(min);
|
|
29
|
+
if (compareAsc(date, minDate) < 0) {
|
|
30
|
+
const minDateAsString = minDate ? format(minDate, dateFormat) : '';
|
|
31
|
+
return `La date doit être supérieure au ${minDateAsString}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (isDef(max)) {
|
|
35
|
+
const maxDate = new Date(max);
|
|
36
|
+
if (compareAsc(date, maxDate) > 0) {
|
|
37
|
+
const maxDateAsString = maxDate ? format(maxDate, dateFormat) : '';
|
|
38
|
+
return `La date doit être inférieure au ${maxDateAsString}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const isDef = (d) => !isNaN(Date.parse(d));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { minMaxValidatorInputNumber } from './input-number';
|
|
2
|
+
import { minMaxValidatorDatepicker } from './datepicker';
|
|
3
|
+
import * as U from '../../../../utils/lib';
|
|
4
|
+
|
|
5
|
+
export const getTypeControls = (props) => {
|
|
6
|
+
const { min, max, value, response, preferences, componentType, id } = props;
|
|
7
|
+
const v =
|
|
8
|
+
value || value === null
|
|
9
|
+
? value
|
|
10
|
+
: U.getResponseByPreference(preferences)(response);
|
|
11
|
+
if (componentType === 'InputNumber')
|
|
12
|
+
return minMaxValidatorInputNumber({ id, min, max })(v);
|
|
13
|
+
if (componentType === 'Datepicker')
|
|
14
|
+
return minMaxValidatorDatepicker({ id, min, max })(v);
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const minMaxValidatorInputNumber =
|
|
2
|
+
({ min, max, id }) =>
|
|
3
|
+
(value) => {
|
|
4
|
+
const errorMessage = getMessage(min, max, value);
|
|
5
|
+
if (errorMessage) return { id: `control-${id}`, errorMessage };
|
|
6
|
+
return null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const getMessage = (min, max, value) => {
|
|
10
|
+
if (!value) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const valueNumber = Number(value);
|
|
14
|
+
if (!min && isDef(max) && valueNumber > max)
|
|
15
|
+
return `La valeur doit être inférieure à ${max}`;
|
|
16
|
+
else if (isDef(min) && !max && valueNumber < min)
|
|
17
|
+
return `La valeur doit être supérieure à ${min}`;
|
|
18
|
+
else if (isDef(min) && isDef(max) && (valueNumber < min || valueNumber > max))
|
|
19
|
+
return `La valeur doit être comprise entre ${min} et ${max}`;
|
|
20
|
+
return undefined;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const isDef = (number) => number || number === 0;
|
|
File without changes
|