@inseefr/lunatic 0.2.3-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.
Files changed (230) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +25 -23
  3. package/lib/index.js +1191 -475
  4. package/lib/index.js.map +1 -1
  5. package/package.json +174 -172
  6. package/src/components/breadcrumb/breadcrumb.scss +22 -22
  7. package/src/components/checkbox/boolean.js +172 -172
  8. package/src/components/checkbox/checkbox.scss +73 -73
  9. package/src/components/checkbox/group.js +231 -231
  10. package/src/components/checkbox/one.js +11 -11
  11. package/src/components/component-wrapper/controls/component.js +70 -0
  12. package/src/components/component-wrapper/controls/controls.scss +6 -0
  13. package/src/components/component-wrapper/controls/index.js +1 -0
  14. package/src/components/component-wrapper/controls/validators/datepicker.js +44 -0
  15. package/src/components/component-wrapper/controls/validators/index.js +16 -0
  16. package/src/components/component-wrapper/controls/validators/input-number.js +23 -0
  17. package/src/components/{missing-wrapper → component-wrapper}/index.js +0 -0
  18. package/src/components/component-wrapper/missing/component.js +200 -0
  19. package/src/components/component-wrapper/missing/index.js +1 -0
  20. package/src/components/{missing-wrapper → component-wrapper/missing}/missing.scss +32 -32
  21. package/src/components/component-wrapper/wrapper.js +23 -0
  22. package/src/components/components.js +1 -0
  23. package/src/components/datepicker/component.js +26 -11
  24. package/src/components/declarations/component.js +46 -46
  25. package/src/components/declarations/declarations.scss +40 -40
  26. package/src/components/declarations/wrappers/input-declarations-wrapper.js +328 -274
  27. package/src/components/declarations/wrappers/simple-declarations-wrapper.js +54 -54
  28. package/src/components/dropdown/commons/actions.js +65 -56
  29. package/src/components/dropdown/commons/children-to-option.js +9 -9
  30. package/src/components/dropdown/commons/cleaner-callbacks.js +58 -58
  31. package/src/components/dropdown/commons/components/dropdown-container.js +29 -29
  32. package/src/components/dropdown/commons/components/dropdown.js +204 -183
  33. package/src/components/dropdown/commons/event-callbacks/on-mousedown-callback.js +15 -15
  34. package/src/components/dropdown/commons/reducer.js +3 -0
  35. package/src/components/dropdown/commons/tools/index.js +17 -17
  36. package/src/components/dropdown/component.js +135 -135
  37. package/src/components/dropdown/dropdown-edit/dropdown-edit.js +194 -185
  38. package/src/components/dropdown/dropdown-edit/index.js +11 -11
  39. package/src/components/dropdown/dropdown-simple/dropdown.js +173 -164
  40. package/src/components/dropdown/dropdown-simple/index.js +20 -20
  41. package/src/components/dropdown/dropdown.scss +178 -178
  42. package/src/components/icon/icon.scss +15 -15
  43. package/src/components/index.js +2 -0
  44. package/src/components/index.scss +177 -175
  45. package/src/components/input/input-number.js +30 -54
  46. package/src/components/input/input.js +11 -11
  47. package/src/components/input/input.scss +31 -37
  48. package/src/components/loop/component.js +170 -169
  49. package/src/components/loop/loop.scss +13 -13
  50. package/src/components/loop/wrapper.js +1 -1
  51. package/src/components/loop-constructor/block/block.scss +10 -10
  52. package/src/components/loop-constructor/block/component.js +9 -9
  53. package/src/components/loop-constructor/roster/component.js +8 -8
  54. package/src/components/loop-constructor/wrapper/body-component.js +146 -125
  55. package/src/components/loop-constructor/wrapper/component.js +190 -190
  56. package/src/components/modal/component.js +36 -0
  57. package/src/components/modal/index.js +1 -0
  58. package/src/components/modal/modal.scss +33 -0
  59. package/src/components/progress-bar/progress-bar.scss +54 -54
  60. package/src/components/radio/component.js +9 -9
  61. package/src/components/radio/radio.scss +59 -59
  62. package/src/components/sequence/component.js +50 -50
  63. package/src/components/sequence/sequence.scss +10 -10
  64. package/src/components/subsequence/component.js +49 -49
  65. package/src/components/suggester/check-store.js +2 -4
  66. package/src/components/suggester/components/panel/default-option-renderer.js +27 -27
  67. package/src/components/suggester/components/panel/option-container.js +61 -61
  68. package/src/components/suggester/components/panel/panel.js +47 -47
  69. package/src/components/suggester/components/selection/default-label-renderer.js +31 -31
  70. package/src/components/suggester/components/selection/label.js +35 -35
  71. package/src/components/suggester/components/selection/selection.js +50 -50
  72. package/src/components/suggester/components/suggester-content.js +2 -2
  73. package/src/components/suggester/components/suggester.js +128 -88
  74. package/src/components/suggester/components/suggester.scss +101 -101
  75. package/src/components/suggester/default-style.scss +125 -125
  76. package/src/components/suggester/find-best-label/find-best-label.js +51 -49
  77. package/src/components/suggester/find-best-label/index.js +1 -1
  78. package/src/components/suggester/idb-suggester.js +73 -67
  79. package/src/components/suggester/lunatic-suggester.js +140 -137
  80. package/src/components/suggester/searching/create-searching.js +49 -47
  81. package/src/components/suggester/searching/index.js +1 -1
  82. package/src/components/suggester/state-management/actions.js +38 -38
  83. package/src/components/suggester/state-management/reducer/reduce-on-delete-search.js +11 -11
  84. package/src/components/suggester/state-management/reducer/reduce-on-init.js +29 -29
  85. package/src/components/suggester/state-management/reducer/reducer.js +38 -38
  86. package/src/components/suggester/suggester-wrapper.js +127 -121
  87. package/src/components/suggester-loader-widget/loader.js +67 -67
  88. package/src/components/suggester-loader-widget/widget.js +123 -123
  89. package/src/components/table/table.js +173 -171
  90. package/src/components/table/table.scss +26 -26
  91. package/src/components/textarea/component.js +11 -11
  92. package/src/components/textarea/textarea.scss +8 -8
  93. package/src/components/tooltip/tooltip.scss +30 -30
  94. package/src/stories/breadcrumb/breadcrumb.stories.js +21 -21
  95. package/src/stories/checkbox-boolean/data.json +78 -78
  96. package/src/stories/datepicker/data.json +3 -1
  97. package/src/stories/declarations/declarations.stories.js +116 -116
  98. package/src/stories/dropdown/README.md +44 -44
  99. package/src/stories/dropdown/data.json +98 -98
  100. package/src/stories/dropdown/dropdown.stories.js +89 -89
  101. package/src/stories/progress-bar/progress-bar.stories.js +24 -24
  102. package/src/stories/questionnaire/arithmetic-management.json +47 -0
  103. package/src/stories/questionnaire/arithmetic.json +247 -247
  104. package/src/stories/questionnaire/calc-var.json +187 -187
  105. package/src/stories/questionnaire/data-logement.json +2691 -2691
  106. package/src/stories/questionnaire/kish.json +275 -0
  107. package/src/stories/questionnaire/logement-queen.json +23390 -0
  108. package/src/stories/questionnaire/logement-s2.json +46028 -44537
  109. package/src/stories/questionnaire/logement-sequence.json +26741 -26741
  110. package/src/stories/questionnaire/logement.json +21073 -26813
  111. package/src/stories/questionnaire/loop-and-controls.json +481 -0
  112. package/src/stories/questionnaire/questionnaire.stories.js +236 -154
  113. package/src/stories/questionnaire/update-external/data.json +1 -0
  114. package/src/stories/questionnaire/update-external/questionnaire.json +75 -0
  115. package/src/stories/sequence/sequence.stories.js +32 -32
  116. package/src/stories/subsequence/subsequence.stories.js +32 -32
  117. package/src/stories/suggester/README.md +46 -46
  118. package/src/stories/suggester/bailleurs-sociaux/fetch-bailleurs.js +15 -15
  119. package/src/stories/suggester/bailleurs-sociaux/index.js +2 -2
  120. package/src/stories/suggester/bailleurs-sociaux/option-bailleur-renderer.js +58 -58
  121. package/src/stories/suggester/bailleurs-sociaux/preloader.svg +51 -51
  122. package/src/stories/suggester/bailleurs-sociaux/theme.scss +22 -22
  123. package/src/stories/suggester/bailleurs-sociaux-2021/fetch-bailleurs.js +12 -0
  124. package/src/stories/suggester/bailleurs-sociaux-2021/index.js +1 -0
  125. package/src/stories/suggester/cog-communes/fetch-cog.js +15 -15
  126. package/src/stories/suggester/data-auto.json +232 -231
  127. package/src/stories/suggester/data-vtl.json +82 -82
  128. package/src/stories/suggester/data.json +169 -136
  129. package/src/stories/suggester/naf-rev2/index.js +2 -2
  130. package/src/stories/suggester/naf-rev2/option-naf-renderer.js +17 -17
  131. package/src/stories/suggester/suggester-workers.stories.js +226 -179
  132. package/src/stories/suggester/suggester.stories.js +138 -133
  133. package/src/stories/utils/orchestrator-split.js +119 -0
  134. package/src/stories/utils/orchestrator.js +119 -108
  135. package/src/tests/components/input-number.spec.js +6 -12
  136. package/src/tests/components/loops/roster-loop.json +71 -71
  137. package/src/tests/components/missing-wrapper.spec.js +0 -1
  138. package/src/tests/utils/lib/table/roster.spec.js +25 -25
  139. package/src/tests/utils/to-expose/handler/results/res-input-edited.json +1 -1
  140. package/src/tests/utils/to-expose/init-questionnaire/questionnaire.json +148 -148
  141. package/src/tests/utils/to-expose/init-questionnaire/result.json +181 -181
  142. package/src/utils/components/dragger/dragger.scss +7 -7
  143. package/src/utils/idb-tools/create-db-opener.js +43 -43
  144. package/src/utils/idb-tools/create-open-db.js +25 -25
  145. package/src/utils/idb-tools/idb-bulk-insert.js +96 -96
  146. package/src/utils/idb-tools/index.js +10 -10
  147. package/src/utils/idb-tools/insert-entity.js +15 -15
  148. package/src/utils/idb-tools/open-db.js +13 -13
  149. package/src/utils/idb-tools/open-or-create-db.js +34 -34
  150. package/src/utils/lib/controls/index.js +1 -0
  151. package/src/utils/lib/controls/utils.js +152 -0
  152. package/src/utils/lib/decorator/title-decorator.js +16 -16
  153. package/src/utils/lib/env.js +2 -2
  154. package/src/utils/lib/index.js +2 -0
  155. package/src/utils/lib/input-number.js +1 -1
  156. package/src/utils/lib/options-positioning.js +9 -9
  157. package/src/utils/lib/pagination/navigation/shared.js +256 -253
  158. package/src/utils/lib/prop-types/lines.js +6 -6
  159. package/src/utils/lib/responses.js +11 -9
  160. package/src/utils/lib/splitting.js +142 -0
  161. package/src/utils/lib/style.js +10 -10
  162. package/src/utils/store-tools/auto-load.js +74 -73
  163. package/src/utils/suggester-workers/append-to-index/append.js +25 -25
  164. package/src/utils/suggester-workers/append-to-index/append.worker.js +16 -16
  165. package/src/utils/suggester-workers/append-to-index/create-append-task.js +45 -43
  166. package/src/utils/suggester-workers/append-to-index/index.js +2 -2
  167. package/src/utils/suggester-workers/append-to-index/prepare-entities.js +61 -61
  168. package/src/utils/suggester-workers/append-to-index/store-messages.js +21 -21
  169. package/src/utils/suggester-workers/commons-tokenizer/create-entity-tokenizer.js +56 -0
  170. package/src/utils/suggester-workers/commons-tokenizer/create-fields-tokenizer.js +56 -0
  171. package/src/utils/suggester-workers/commons-tokenizer/create-filter-stop-words.js +17 -17
  172. package/src/utils/suggester-workers/commons-tokenizer/filters/compose-filters.js +10 -0
  173. package/src/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.js +17 -0
  174. package/src/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.spec.js +14 -0
  175. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-accents.js +12 -0
  176. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-accents.spec.js +12 -0
  177. package/src/utils/suggester-workers/commons-tokenizer/{filter-double.js → filters/filter-double.js} +12 -12
  178. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-double.spec.js +20 -0
  179. package/src/utils/suggester-workers/commons-tokenizer/{filter-length.js → filters/filter-length.js} +7 -7
  180. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-length.spec.js +18 -0
  181. package/src/utils/suggester-workers/commons-tokenizer/{filter-stemmer.js → filters/filter-stemmer.js} +13 -13
  182. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-stemmer.spec.js +12 -0
  183. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.js +36 -0
  184. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.spec.js +12 -0
  185. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.js +10 -0
  186. package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.spec.js +12 -0
  187. package/src/utils/suggester-workers/commons-tokenizer/filters/index.js +2 -0
  188. package/src/utils/suggester-workers/commons-tokenizer/{stop-words.js → filters/stop-words.js} +118 -118
  189. package/src/utils/suggester-workers/commons-tokenizer/get-regexp-from-pattern.js +8 -8
  190. package/src/utils/suggester-workers/commons-tokenizer/get-stemmer.js +18 -18
  191. package/src/utils/suggester-workers/commons-tokenizer/index.js +9 -8
  192. package/src/utils/suggester-workers/commons-tokenizer/prepare-string-indexation.js +13 -9
  193. package/src/utils/suggester-workers/commons-tokenizer/soft-tokenizer.js +7 -7
  194. package/src/utils/suggester-workers/create-worker.js +56 -0
  195. package/src/utils/suggester-workers/find-best-label/find-best-label.js +39 -39
  196. package/src/utils/suggester-workers/find-best-label/find-best-label.worker.js +40 -40
  197. package/src/utils/suggester-workers/find-best-label/tokenize.js +30 -33
  198. package/src/utils/suggester-workers/find-best-label/tokenize.spec.js +19 -19
  199. package/src/utils/suggester-workers/searching/compute-score.js +33 -33
  200. package/src/utils/suggester-workers/searching/get-db.js +18 -18
  201. package/src/utils/suggester-workers/searching/index.js +1 -1
  202. package/src/utils/suggester-workers/searching/order/create-alphanumeric-orderer.js +20 -20
  203. package/src/utils/suggester-workers/searching/order/index.js +19 -19
  204. package/src/utils/suggester-workers/{query-parser → searching/query-parser}/index.js +2 -2
  205. package/src/utils/suggester-workers/searching/query-parser/query-parser-soft.js +7 -0
  206. package/src/utils/suggester-workers/{query-parser → searching/query-parser}/query-parser-soft.spec.js +24 -24
  207. package/src/utils/suggester-workers/searching/query-parser/query-parser-tokenized.js +34 -0
  208. package/src/utils/suggester-workers/searching/resolve-query-parser.js +27 -27
  209. package/src/utils/suggester-workers/searching/search-in-index.js +17 -17
  210. package/src/utils/suggester-workers/searching/searching.js +70 -70
  211. package/src/utils/suggester-workers/searching/searching.worker.js +11 -11
  212. package/src/utils/to-expose/calculated-variables.js +113 -113
  213. package/src/utils/to-expose/handler.js +149 -112
  214. package/src/utils/to-expose/hooks/filter-components.js +27 -12
  215. package/src/utils/to-expose/hooks/index.js +2 -1
  216. package/src/utils/to-expose/hooks/lunatic-split.js +428 -0
  217. package/src/utils/to-expose/hooks/lunatic.js +284 -188
  218. package/src/utils/to-expose/index.js +1 -1
  219. package/src/utils/to-expose/init-questionnaire.js +164 -164
  220. package/src/utils/to-expose/interpret/vtl.js +18 -18
  221. package/src/utils/to-expose/state.js +66 -58
  222. package/src/components/missing-wrapper/component.js +0 -120
  223. package/src/components/missing-wrapper/wrapper.js +0 -10
  224. package/src/tests/utils/to-expose/hooks/use-lunatic.spec.js +0 -46
  225. package/src/utils/suggester-workers/commons-tokenizer/create-tokenizer.js +0 -103
  226. package/src/utils/suggester-workers/commons-tokenizer/filter-accents-to-lower.js +0 -9
  227. package/src/utils/suggester-workers/commons-tokenizer/filter-synonyms.js +0 -10
  228. package/src/utils/suggester-workers/query-parser/query-parser-soft.js +0 -7
  229. package/src/utils/suggester-workers/query-parser/query-parser-tokenized.js +0 -31
  230. package/src/utils/suggester-workers/query-parser/query-parser-tokenized.spec.js +0 -32
@@ -1,133 +1,138 @@
1
- import React, { useState, useCallback } from 'react';
2
- import { storiesOf } from '@storybook/react';
3
- import { withReadme } from 'storybook-readme';
4
- import Orchestrator from '../utils/orchestrator';
5
- import readme from './README.md';
6
- import { titleDecorator } from 'utils/lib';
7
- import data from './data';
8
- import dataAuto from './data-auto';
9
- import dataVTL from './data-vtl';
10
- import { labelPositionOptions, featuresOptions } from '../utils/options';
11
- import { text, boolean, object, select } from '@storybook/addon-knobs/react';
12
- import { SuggesterLoaderWidget } from 'components';
13
- import * as NAF from './naf-rev2';
14
- import * as COG from './cog-communes';
15
- import * as BAILLEURS from './bailleurs-sociaux';
16
-
17
- /**
18
- *
19
- */
20
- function getSuggesterInfo(name) {
21
- if (name === 'naf-rev2') {
22
- return { optionRenderer: NAF.OptionRenderer, idbVersion: '1' };
23
- } else if (name === 'cog-communes') {
24
- return { optionRenderer: COG.OptionRenderer, idbVersion: '1' };
25
- } else if (name === 'bailleurs-sociaux') {
26
- return { optionRenderer: BAILLEURS.OptionRenderer, idbVersion: '1' };
27
- }
28
- console.warn(`Unknown store : ${name}`);
29
- return {};
30
- }
31
-
32
- function getWidgetLoaderInfo(name) {
33
- if (name === 'naf-rev2') {
34
- return {
35
- fetch: NAF.fetch,
36
- idbVersion: '1',
37
- };
38
- } else if (name === 'cog-communes') {
39
- return { fetch: COG.fetch, idbVersion: '1' };
40
- } else if (name === 'bailleurs-sociaux') {
41
- return { fetch: BAILLEURS.fetch, idbVersion: '1' };
42
- }
43
- console.warn(`Unknown store : ${name}`);
44
- return {};
45
- }
46
-
47
- const stories = storiesOf('Suggester/Manual loading', module)
48
- .addDecorator(withReadme(readme))
49
- .addDecorator((Component) => {
50
- const WrappedComponent = titleDecorator(Component);
51
- return <WrappedComponent title="<Suggester />" />;
52
- });
53
-
54
- stories.addWithJSX('Default', () => {
55
- const [message, setMessage] = useState(undefined);
56
- const onRefresh = useCallback(function (m) {
57
- setMessage(m);
58
- }, []);
59
- return (
60
- <>
61
- <SuggesterLoaderWidget
62
- source={data}
63
- getStoreInfo={getWidgetLoaderInfo}
64
- onRefresh={onRefresh}
65
- absolute
66
- />
67
- <Orchestrator
68
- id="default"
69
- source={data}
70
- getStoreInfo={getSuggesterInfo}
71
- />
72
- <div>{message}</div>
73
- </>
74
- );
75
- });
76
-
77
- stories.addWithJSX('Props', () => {
78
- return (
79
- <>
80
- <SuggesterLoaderWidget source={data} getStoreInfo={getWidgetLoaderInfo} />
81
- <Orchestrator
82
- id="props"
83
- source={dataVTL}
84
- label={text('Label', '"Enjoy the suggester below"')}
85
- features={select('Features', featuresOptions, ['VTL', 'MD'])}
86
- bindings={object('Bindings', {})}
87
- disabled={boolean('Disabled', false)}
88
- focused={boolean('Focused', false)}
89
- management={boolean('Management', false)}
90
- labelPosition={select(
91
- 'Label position',
92
- labelPositionOptions,
93
- 'DEFAULT'
94
- )}
95
- getStoreInfo={getSuggesterInfo}
96
- />
97
- </>
98
- );
99
- });
100
-
101
- const storiesAuto = storiesOf('Suggester/Auto loading', module)
102
- .addDecorator(withReadme(readme))
103
- .addDecorator((Component) => {
104
- const WrappedComponent = titleDecorator(Component);
105
- return <WrappedComponent title="<Suggester />" />;
106
- });
107
-
108
- const suggesterFetcher = (url) =>
109
- fetch(url, {
110
- headers: { Accept: 'application/json' },
111
- });
112
-
113
- storiesAuto.addWithJSX('Default', () => (
114
- <Orchestrator
115
- id="default"
116
- source={dataAuto}
117
- suggesters={{
118
- 'naf-rev2': {
119
- url: 'https://inseefr.github.io/Lunatic/storybook/naf-rev2.json',
120
- },
121
- 'naf-rev2-stop': {
122
- url: 'https://inseefr.github.io/Lunatic/storybook/naf-rev2.json',
123
- stopWords: [],
124
- },
125
- 'cog-communes': {
126
- url: 'https://inseefr.github.io/Lunatic/storybook/communes-2019.json',
127
- },
128
- }}
129
- suggesterFetcher={suggesterFetcher}
130
- autoSuggesterLoading
131
- pagination
132
- />
133
- ));
1
+ import React, { useState, useCallback } from 'react';
2
+ import { storiesOf } from '@storybook/react';
3
+ import { withReadme } from 'storybook-readme';
4
+ import Orchestrator from '../utils/orchestrator';
5
+ import readme from './README.md';
6
+ import { titleDecorator } from 'utils/lib';
7
+ import data from './data';
8
+ import dataAuto from './data-auto';
9
+ import dataVTL from './data-vtl';
10
+ import { labelPositionOptions, featuresOptions } from '../utils/options';
11
+ import { text, boolean, object, select } from '@storybook/addon-knobs/react';
12
+ import { SuggesterLoaderWidget } from 'components';
13
+ import * as NAF from './naf-rev2';
14
+ import * as COG from './cog-communes';
15
+ import * as BAILLEURS from './bailleurs-sociaux';
16
+ import * as BAILLEURS2021 from './bailleurs-sociaux-2021';
17
+
18
+ /**
19
+ *
20
+ */
21
+ function getSuggesterInfo(name) {
22
+ if (name === 'naf-rev2') {
23
+ return { optionRenderer: NAF.OptionRenderer, idbVersion: '1' };
24
+ } else if (name === 'cog-communes') {
25
+ return { optionRenderer: COG.OptionRenderer, idbVersion: '1' };
26
+ } else if (name === 'bailleurs-sociaux') {
27
+ return { optionRenderer: BAILLEURS.OptionRenderer, idbVersion: '1' };
28
+ } else if (name === 'bailleurs-sociaux-2021') {
29
+ return { idbVersion: '1' };
30
+ }
31
+ console.warn(`Unknown store : ${name}`);
32
+ return {};
33
+ }
34
+
35
+ function getWidgetLoaderInfo(name) {
36
+ if (name === 'naf-rev2') {
37
+ return {
38
+ fetch: NAF.fetch,
39
+ idbVersion: '1',
40
+ };
41
+ } else if (name === 'cog-communes') {
42
+ return { fetch: COG.fetch, idbVersion: '1' };
43
+ } else if (name === 'bailleurs-sociaux') {
44
+ return { fetch: BAILLEURS.fetch, idbVersion: '1' };
45
+ } else if (name === 'bailleurs-sociaux-2021') {
46
+ return { fetch: BAILLEURS2021.fetch, idbVersion: '1' };
47
+ }
48
+ console.warn(`Unknown store : ${name}`);
49
+ return {};
50
+ }
51
+
52
+ const stories = storiesOf('Suggester/Manual loading', module)
53
+ .addDecorator(withReadme(readme))
54
+ .addDecorator((Component) => {
55
+ const WrappedComponent = titleDecorator(Component);
56
+ return <WrappedComponent title="<Suggester />" />;
57
+ });
58
+
59
+ stories.addWithJSX('Default', () => {
60
+ const [message, setMessage] = useState(undefined);
61
+ const onRefresh = useCallback(function (m) {
62
+ setMessage(m);
63
+ }, []);
64
+ return (
65
+ <>
66
+ <SuggesterLoaderWidget
67
+ source={data}
68
+ getStoreInfo={getWidgetLoaderInfo}
69
+ onRefresh={onRefresh}
70
+ absolute
71
+ />
72
+ <Orchestrator
73
+ id="default"
74
+ source={data}
75
+ getStoreInfo={getSuggesterInfo}
76
+ />
77
+ <div>{message}</div>
78
+ </>
79
+ );
80
+ });
81
+
82
+ stories.addWithJSX('Props', () => {
83
+ return (
84
+ <>
85
+ <SuggesterLoaderWidget source={data} getStoreInfo={getWidgetLoaderInfo} />
86
+ <Orchestrator
87
+ id="props"
88
+ source={dataVTL}
89
+ label={text('Label', '"Enjoy the suggester below"')}
90
+ features={select('Features', featuresOptions, ['VTL', 'MD'])}
91
+ bindings={object('Bindings', {})}
92
+ disabled={boolean('Disabled', false)}
93
+ focused={boolean('Focused', false)}
94
+ management={boolean('Management', false)}
95
+ labelPosition={select(
96
+ 'Label position',
97
+ labelPositionOptions,
98
+ 'DEFAULT'
99
+ )}
100
+ getStoreInfo={getSuggesterInfo}
101
+ />
102
+ </>
103
+ );
104
+ });
105
+
106
+ const storiesAuto = storiesOf('Suggester/Auto loading', module)
107
+ .addDecorator(withReadme(readme))
108
+ .addDecorator((Component) => {
109
+ const WrappedComponent = titleDecorator(Component);
110
+ return <WrappedComponent title="<Suggester />" />;
111
+ });
112
+
113
+ const suggesterFetcher = (url) =>
114
+ fetch(url, {
115
+ headers: { Accept: 'application/json' },
116
+ });
117
+
118
+ storiesAuto.addWithJSX('Default', () => (
119
+ <Orchestrator
120
+ id="default"
121
+ source={dataAuto}
122
+ suggesters={{
123
+ 'naf-rev2': {
124
+ url: 'https://inseefr.github.io/Lunatic/storybook/naf-rev2.json',
125
+ },
126
+ 'naf-rev2-stop': {
127
+ url: 'https://inseefr.github.io/Lunatic/storybook/naf-rev2.json',
128
+ stopWords: [],
129
+ },
130
+ 'cog-communes': {
131
+ url: 'https://inseefr.github.io/Lunatic/storybook/communes-2019.json',
132
+ },
133
+ }}
134
+ suggesterFetcher={suggesterFetcher}
135
+ autoSuggesterLoading
136
+ pagination
137
+ />
138
+ ));
@@ -0,0 +1,119 @@
1
+ import React, { useEffect } from 'react';
2
+ import * as lunatic from 'components';
3
+ import './custom-lunatic.scss';
4
+
5
+ function getStoreInfoRequired() {
6
+ return {};
7
+ }
8
+
9
+ const defaultFeatures = ['VTL'];
10
+
11
+ const OrchestratorForStories = ({
12
+ source,
13
+ suggesters,
14
+ data,
15
+ management = false,
16
+ pagination = false,
17
+ modalForControls = false,
18
+ features = defaultFeatures,
19
+ bindings: initialBindings,
20
+ initialPage = '1',
21
+ getStoreInfo = getStoreInfoRequired,
22
+ missing = false,
23
+ shortcut = false,
24
+ activeGoNextForMissing = false,
25
+ suggesterFetcher,
26
+ autoSuggesterLoading,
27
+ addExternal,
28
+ ...rest
29
+ }) => {
30
+ const preferences = management
31
+ ? ['COLLECTED', 'FORCED', 'EDITED']
32
+ : ['COLLECTED'];
33
+ const savingType = management ? 'EDITED' : 'COLLECTED';
34
+ const {
35
+ handleChange,
36
+ handleExternals,
37
+ components,
38
+ bindings,
39
+ pagination: {
40
+ goNext,
41
+ goPrevious,
42
+ page,
43
+ setPage,
44
+ maxPage,
45
+ isFirstPage,
46
+ isLastPage,
47
+ flow,
48
+ },
49
+ } = lunatic.useLunaticSplit(source, data, {
50
+ suggesters,
51
+ savingType,
52
+ preferences,
53
+ features,
54
+ management,
55
+ pagination,
56
+ modalForControls,
57
+ initialPage,
58
+ suggesterFetcher,
59
+ autoSuggesterLoading,
60
+ });
61
+
62
+ useEffect(() => {
63
+ handleExternals(addExternal);
64
+ }, [addExternal, handleExternals]);
65
+
66
+ const Button = lunatic.Button;
67
+
68
+ const missingStrategy = (b) => goNext(null, b);
69
+
70
+ return (
71
+ <div className="container">
72
+ <div className="components">
73
+ {components.map((q) => {
74
+ const { id, componentType } = q;
75
+ const Component = lunatic[componentType];
76
+ const { storeName } = q;
77
+
78
+ return (
79
+ <div className="lunatic lunatic-component" key={`component-${id}`}>
80
+ <Component
81
+ {...rest}
82
+ {...q}
83
+ {...getStoreInfo(storeName)}
84
+ handleChange={handleChange}
85
+ preferences={preferences}
86
+ savingType={savingType}
87
+ management={management}
88
+ features={features}
89
+ bindings={{ ...bindings, ...initialBindings }}
90
+ currentPage={page}
91
+ setPage={setPage}
92
+ flow={flow}
93
+ pagination={pagination}
94
+ missing={missing}
95
+ shortcut={shortcut}
96
+ missingStrategy={activeGoNextForMissing && missingStrategy}
97
+ />
98
+ </div>
99
+ );
100
+ })}
101
+ </div>
102
+ {pagination && (
103
+ <>
104
+ <div className="pagination">
105
+ <Button
106
+ onClick={goPrevious}
107
+ disabled={isFirstPage}
108
+ value="Previous"
109
+ />
110
+ <Button onClick={goNext} disabled={isLastPage} value="Next" />
111
+ </div>
112
+ <div>{`Page : ${page}/${maxPage}`}</div>
113
+ </>
114
+ )}
115
+ </div>
116
+ );
117
+ };
118
+
119
+ export default OrchestratorForStories;
@@ -1,108 +1,119 @@
1
- import React from 'react';
2
- import * as lunatic from 'components';
3
- import './custom-lunatic.scss';
4
-
5
- function getStoreInfoRequired() {
6
- return {};
7
- }
8
-
9
- const OrchestratorForStories = ({
10
- source,
11
- suggesters,
12
- data = {},
13
- management = false,
14
- pagination = false,
15
- features = ['VTL'],
16
- bindings: initialBindings,
17
- initialPage = '1',
18
- getStoreInfo = getStoreInfoRequired,
19
- missing = false,
20
- shortcut = false,
21
- activeGoNextForMissing = false,
22
- suggesterFetcher,
23
- autoSuggesterLoading,
24
- ...rest
25
- }) => {
26
- const preferences = management
27
- ? ['COLLECTED', 'FORCED', 'EDITED']
28
- : ['COLLECTED'];
29
- const savingType = management ? 'EDITED' : 'COLLECTED';
30
- const {
31
- handleChange,
32
- components,
33
- bindings,
34
- pagination: {
35
- goNext,
36
- goPrevious,
37
- page,
38
- setPage,
39
- maxPage,
40
- isFirstPage,
41
- isLastPage,
42
- flow,
43
- },
44
- } = lunatic.useLunatic(source, data, {
45
- suggesters,
46
- savingType,
47
- preferences,
48
- features,
49
- management,
50
- pagination,
51
- initialPage,
52
- suggesterFetcher,
53
- autoSuggesterLoading,
54
- });
55
- const Button = lunatic.Button;
56
-
57
- const missingStrategy = (b) => goNext(null, b);
58
-
59
- return (
60
- <div className="container">
61
- <div className="components">
62
- {components.map((q) => {
63
- const { id, componentType } = q;
64
- const Component = lunatic[componentType];
65
- const { storeName } = q;
66
-
67
- return (
68
- <div className="lunatic lunatic-component" key={`component-${id}`}>
69
- <Component
70
- {...rest}
71
- {...q}
72
- {...getStoreInfo(storeName)}
73
- handleChange={handleChange}
74
- preferences={preferences}
75
- savingType={savingType}
76
- management={management}
77
- features={features}
78
- bindings={{ ...bindings, ...initialBindings }}
79
- currentPage={page}
80
- setPage={setPage}
81
- flow={flow}
82
- pagination={pagination}
83
- missing={missing}
84
- shortcut={shortcut}
85
- missingStrategy={activeGoNextForMissing && missingStrategy}
86
- />
87
- </div>
88
- );
89
- })}
90
- </div>
91
- {pagination && (
92
- <>
93
- <div className="pagination">
94
- <Button
95
- onClick={goPrevious}
96
- disabled={isFirstPage}
97
- value="Previous"
98
- />
99
- <Button onClick={goNext} disabled={isLastPage} value="Next" />
100
- </div>
101
- <div>{`Page : ${page}/${maxPage}`}</div>
102
- </>
103
- )}
104
- </div>
105
- );
106
- };
107
-
108
- export default OrchestratorForStories;
1
+ import React, { useEffect } from 'react';
2
+ import * as lunatic from 'components';
3
+ import './custom-lunatic.scss';
4
+
5
+ function getStoreInfoRequired() {
6
+ return {};
7
+ }
8
+
9
+ const defaultFeatures = ['VTL'];
10
+
11
+ const OrchestratorForStories = ({
12
+ source,
13
+ suggesters,
14
+ data,
15
+ management = false,
16
+ pagination = false,
17
+ modalForControls = false,
18
+ features = defaultFeatures,
19
+ bindings: initialBindings,
20
+ initialPage = '1',
21
+ getStoreInfo = getStoreInfoRequired,
22
+ missing = false,
23
+ shortcut = false,
24
+ activeGoNextForMissing = false,
25
+ suggesterFetcher,
26
+ autoSuggesterLoading,
27
+ addExternal,
28
+ ...rest
29
+ }) => {
30
+ const preferences = management
31
+ ? ['COLLECTED', 'FORCED', 'EDITED']
32
+ : ['COLLECTED'];
33
+ const savingType = management ? 'EDITED' : 'COLLECTED';
34
+ const {
35
+ handleChange,
36
+ handleExternals,
37
+ components,
38
+ bindings,
39
+ pagination: {
40
+ goNext,
41
+ goPrevious,
42
+ page,
43
+ setPage,
44
+ maxPage,
45
+ isFirstPage,
46
+ isLastPage,
47
+ flow,
48
+ },
49
+ } = lunatic.useLunatic(source, data, {
50
+ suggesters,
51
+ savingType,
52
+ preferences,
53
+ features,
54
+ management,
55
+ pagination,
56
+ modalForControls,
57
+ initialPage,
58
+ suggesterFetcher,
59
+ autoSuggesterLoading,
60
+ });
61
+
62
+ useEffect(() => {
63
+ handleExternals(addExternal);
64
+ }, [addExternal, handleExternals]);
65
+
66
+ const Button = lunatic.Button;
67
+
68
+ const missingStrategy = (b) => goNext(null, b);
69
+
70
+ return (
71
+ <div className="container">
72
+ <div className="components">
73
+ {components.map((q) => {
74
+ const { id, componentType } = q;
75
+ const Component = lunatic[componentType];
76
+ const { storeName } = q;
77
+
78
+ return (
79
+ <div className="lunatic lunatic-component" key={`component-${id}`}>
80
+ <Component
81
+ {...rest}
82
+ {...q}
83
+ {...getStoreInfo(storeName)}
84
+ handleChange={handleChange}
85
+ preferences={preferences}
86
+ savingType={savingType}
87
+ management={management}
88
+ features={features}
89
+ bindings={{ ...bindings, ...initialBindings }}
90
+ currentPage={page}
91
+ setPage={setPage}
92
+ flow={flow}
93
+ pagination={pagination}
94
+ missing={missing}
95
+ shortcut={shortcut}
96
+ missingStrategy={activeGoNextForMissing && missingStrategy}
97
+ />
98
+ </div>
99
+ );
100
+ })}
101
+ </div>
102
+ {pagination && (
103
+ <>
104
+ <div className="pagination">
105
+ <Button
106
+ onClick={goPrevious}
107
+ disabled={isFirstPage}
108
+ value="Previous"
109
+ />
110
+ <Button onClick={goNext} disabled={isLastPage} value="Next" />
111
+ </div>
112
+ <div>{`Page : ${page}/${maxPage}`}</div>
113
+ </>
114
+ )}
115
+ </div>
116
+ );
117
+ };
118
+
119
+ export default OrchestratorForStories;