@inseefr/lunatic 3.5.0-rc.3 → 3.5.1-rc.1743691949561
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/components/Datepicker/Datepicker.js +1 -1
- package/components/Datepicker/Datepicker.js.map +1 -1
- package/components/Duration/Duration.js +3 -2
- package/components/Duration/Duration.js.map +1 -1
- package/components/Duration/durationUtils.d.ts +0 -1
- package/components/Duration/durationUtils.js.map +1 -1
- package/components/Duration/getDurationFromValue.d.ts +3 -2
- package/components/Duration/getDurationFromValue.js.map +1 -1
- package/components/Input/Input.js +6 -3
- package/components/Input/Input.js.map +1 -1
- package/components/Input/Input.spec.js +25 -0
- package/components/Input/Input.spec.js.map +1 -1
- package/components/InputNumber/InputNumber.js +1 -1
- package/components/InputNumber/InputNumber.js.map +1 -1
- package/components/InputNumber/InputNumber.spec.js +9 -1
- package/components/InputNumber/InputNumber.spec.js.map +1 -1
- package/components/InputNumber/InputNumberThousand.d.ts +2 -1
- package/components/InputNumber/InputNumberThousand.js +8 -2
- package/components/InputNumber/InputNumberThousand.js.map +1 -1
- package/components/Loop/Loop.js +1 -1
- package/components/Loop/Loop.js.map +1 -1
- package/components/Loop/Loop.spec.d.ts +1 -0
- package/components/Loop/Loop.spec.js +39 -0
- package/components/Loop/Loop.spec.js.map +1 -0
- package/components/Roundabout/CustomRoundabout.d.ts +1 -1
- package/components/Roundabout/CustomRoundabout.js +4 -3
- package/components/Roundabout/CustomRoundabout.js.map +1 -1
- package/components/Roundabout/roundabout.spec.js +3 -1
- package/components/Roundabout/roundabout.spec.js.map +1 -1
- package/components/Textarea/Textarea.js +4 -1
- package/components/Textarea/Textarea.js.map +1 -1
- package/components/Textarea/Textarea.spec.js +13 -0
- package/components/Textarea/Textarea.spec.js.map +1 -1
- package/components/shared/CharactersCount/CharactersCount.d.ts +7 -0
- package/components/shared/CharactersCount/CharactersCount.js +20 -0
- package/components/shared/CharactersCount/CharactersCount.js.map +1 -0
- package/components/shared/CharactersCount/CharactersCount.spec.d.ts +1 -0
- package/components/shared/CharactersCount/CharactersCount.spec.js +28 -0
- package/components/shared/CharactersCount/CharactersCount.spec.js.map +1 -0
- package/components/shared/Label/Label.js +1 -1
- package/components/shared/Label/Label.js.map +1 -1
- package/components/shared/Label/Label.spec.js +11 -3
- package/components/shared/Label/Label.spec.js.map +1 -1
- package/components/shared/utils/getCharactersCountId.d.ts +4 -0
- package/components/shared/utils/getCharactersCountId.js +10 -0
- package/components/shared/utils/getCharactersCountId.js.map +1 -0
- package/components/type.d.ts +3 -3
- package/esm/components/Datepicker/Datepicker.js +1 -1
- package/esm/components/Datepicker/Datepicker.js.map +1 -1
- package/esm/components/Duration/Duration.js +3 -2
- package/esm/components/Duration/Duration.js.map +1 -1
- package/esm/components/Duration/durationUtils.d.ts +0 -1
- package/esm/components/Duration/durationUtils.js.map +1 -1
- package/esm/components/Duration/getDurationFromValue.d.ts +3 -2
- package/esm/components/Duration/getDurationFromValue.js.map +1 -1
- package/esm/components/Input/Input.js +6 -3
- package/esm/components/Input/Input.js.map +1 -1
- package/esm/components/Input/Input.spec.js +25 -0
- package/esm/components/Input/Input.spec.js.map +1 -1
- package/esm/components/InputNumber/InputNumber.js +1 -1
- package/esm/components/InputNumber/InputNumber.js.map +1 -1
- package/esm/components/InputNumber/InputNumber.spec.js +9 -1
- package/esm/components/InputNumber/InputNumber.spec.js.map +1 -1
- package/esm/components/InputNumber/InputNumberThousand.d.ts +2 -1
- package/esm/components/InputNumber/InputNumberThousand.js +8 -2
- package/esm/components/InputNumber/InputNumberThousand.js.map +1 -1
- package/esm/components/Loop/Loop.js +1 -1
- package/esm/components/Loop/Loop.js.map +1 -1
- package/esm/components/Loop/Loop.spec.d.ts +1 -0
- package/esm/components/Loop/Loop.spec.js +37 -0
- package/esm/components/Loop/Loop.spec.js.map +1 -0
- package/esm/components/Roundabout/CustomRoundabout.d.ts +1 -1
- package/esm/components/Roundabout/CustomRoundabout.js +4 -3
- package/esm/components/Roundabout/CustomRoundabout.js.map +1 -1
- package/esm/components/Roundabout/roundabout.spec.js +3 -1
- package/esm/components/Roundabout/roundabout.spec.js.map +1 -1
- package/esm/components/Textarea/Textarea.js +4 -1
- package/esm/components/Textarea/Textarea.js.map +1 -1
- package/esm/components/Textarea/Textarea.spec.js +13 -0
- package/esm/components/Textarea/Textarea.spec.js.map +1 -1
- package/esm/components/shared/CharactersCount/CharactersCount.d.ts +7 -0
- package/esm/components/shared/CharactersCount/CharactersCount.js +15 -0
- package/esm/components/shared/CharactersCount/CharactersCount.js.map +1 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.d.ts +1 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.js +26 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.js.map +1 -0
- package/esm/components/shared/Label/Label.js +1 -1
- package/esm/components/shared/Label/Label.js.map +1 -1
- package/esm/components/shared/Label/Label.spec.js +11 -3
- package/esm/components/shared/Label/Label.spec.js.map +1 -1
- package/esm/components/shared/utils/getCharactersCountId.d.ts +4 -0
- package/esm/components/shared/utils/getCharactersCountId.js +7 -0
- package/esm/components/shared/utils/getCharactersCountId.js.map +1 -0
- package/esm/components/type.d.ts +3 -3
- package/esm/index.d.ts +0 -1
- package/esm/index.js +0 -1
- package/esm/index.js.map +1 -1
- package/esm/main.css +20 -0
- package/esm/main.css.map +1 -1
- package/esm/stories/overview/sourceWithHierarchy.json +5151 -0
- package/esm/tests/utils/lunatic.d.ts +0 -4
- package/esm/tests/utils/lunatic.js +0 -4
- package/esm/tests/utils/lunatic.js.map +1 -1
- package/esm/type.source.d.ts +6 -6
- package/esm/type.source.js +0 -1
- package/esm/type.source.js.map +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.d.ts +2 -0
- package/esm/use-lunatic/commons/fill-components/fill-components.js +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/esm/use-lunatic/commons/page.js +8 -0
- package/esm/use-lunatic/commons/page.js.map +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +111 -14
- package/esm/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js.map +1 -1
- package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +3 -3
- package/esm/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
- package/esm/use-lunatic/commons/variables/get-questionnaire-data.js +0 -8
- package/esm/use-lunatic/commons/variables/get-questionnaire-data.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.d.ts +2 -2
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js +5 -3
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js +181 -9
- package/esm/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/esm/use-lunatic/hooks/use-page-has-response.js +50 -35
- package/esm/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/esm/use-lunatic/hooks/useOverview.d.ts +1 -1
- package/esm/use-lunatic/hooks/useOverview.js +19 -14
- package/esm/use-lunatic/hooks/useOverview.js.map +1 -1
- package/esm/use-lunatic/hooks/useOverview.spec.d.ts +1 -0
- package/esm/use-lunatic/hooks/useOverview.spec.js +38 -0
- package/esm/use-lunatic/hooks/useOverview.spec.js.map +1 -0
- package/esm/use-lunatic/props/getComponentTypeProps.d.ts +2 -1
- package/esm/use-lunatic/props/propOptions.d.ts +2 -1
- package/esm/use-lunatic/props/propOptions.js +23 -3
- package/esm/use-lunatic/props/propOptions.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.spec.js +46 -5
- package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/esm/use-lunatic/props/propValue.js +18 -6
- package/esm/use-lunatic/props/propValue.js.map +1 -1
- package/esm/use-lunatic/props/propValue.spec.js +97 -2
- package/esm/use-lunatic/props/propValue.spec.js.map +1 -1
- package/esm/use-lunatic/reducer/reducerInitializer.d.ts +2 -2
- package/esm/use-lunatic/reducer/reducerInitializer.js +25 -32
- package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/esm/use-lunatic/test.utils.d.ts +2 -0
- package/esm/use-lunatic/test.utils.js +13 -0
- package/esm/use-lunatic/test.utils.js.map +1 -0
- package/esm/use-lunatic/type.d.ts +18 -8
- package/esm/use-lunatic/use-lunatic.d.ts +1 -2
- package/esm/use-lunatic/use-lunatic.js +2 -3
- package/esm/use-lunatic/use-lunatic.js.map +1 -1
- package/esm/utils/cast.d.ts +19 -0
- package/esm/utils/cast.js +63 -0
- package/esm/utils/cast.js.map +1 -0
- package/esm/utils/constants/variable-status.d.ts +0 -4
- package/esm/utils/constants/variable-status.js +0 -4
- package/esm/utils/constants/variable-status.js.map +1 -1
- package/esm/utils/variables.spec.js +0 -8
- package/esm/utils/variables.spec.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +1 -3
- package/index.js.map +1 -1
- package/main.css +20 -0
- package/main.css.map +1 -1
- package/package.json +60 -69
- package/src/components/Datepicker/Datepicker.tsx +1 -1
- package/src/components/Datepicker/__snapshots__/Datepicker.spec.tsx.snap +2 -2
- package/src/components/Duration/Duration.test.tsx +52 -0
- package/src/components/Duration/Duration.tsx +17 -4
- package/src/components/Duration/durationUtils.ts +0 -2
- package/src/components/Duration/getDurationFromValue.ts +4 -3
- package/src/components/Input/Input.spec.tsx +34 -0
- package/src/components/Input/Input.tsx +26 -18
- package/src/components/Input/__snapshots__/Input.spec.tsx.snap +38 -19
- package/src/components/InputNumber/InputNumber.spec.tsx +15 -1
- package/src/components/InputNumber/InputNumber.tsx +1 -0
- package/src/components/InputNumber/InputNumberThousand.tsx +11 -1
- package/src/components/Loop/Loop.spec.tsx +77 -0
- package/src/components/Loop/Loop.tsx +1 -1
- package/src/components/RosterForLoop/__snapshots__/RosterForLoop.spec.tsx.snap +42 -20
- package/src/components/Roundabout/CustomRoundabout.tsx +13 -4
- package/src/components/Roundabout/roundabout.spec.tsx +3 -0
- package/src/components/Textarea/Textarea.spec.tsx +18 -0
- package/src/components/Textarea/Textarea.tsx +21 -13
- package/src/components/Textarea/__snapshots__/Textarea.spec.tsx.snap +21 -11
- package/src/components/shared/CharactersCount/CharactersCount.spec.tsx +31 -0
- package/src/components/shared/CharactersCount/CharactersCount.tsx +27 -0
- package/src/components/shared/Label/Label.spec.tsx +15 -3
- package/src/components/shared/Label/Label.tsx +1 -1
- package/src/components/shared/utils/getCharactersCountId.test.ts +14 -0
- package/src/components/shared/utils/getCharactersCountId.ts +6 -0
- package/src/components/type.ts +3 -2
- package/src/css/components/Input.scss +10 -0
- package/src/css/components/Roundabout.scss +10 -0
- package/src/index.ts +0 -1
- package/src/stories/accordion/source.json +1 -5
- package/src/stories/behaviour/cleaning/cleaning.stories.jsx +11 -0
- package/src/stories/behaviour/cleaning/loop.json +246 -0
- package/src/stories/behaviour/cleaning/source-loop.json +3 -15
- package/src/stories/behaviour/cleaning/source.json +2 -10
- package/src/stories/behaviour/controls/boucles-n.json +2 -10
- package/src/stories/behaviour/controls/loop.json +2 -10
- package/src/stories/behaviour/controls/roundabout.json +3 -15
- package/src/stories/behaviour/controls/simple-numeric.json +19 -95
- package/src/stories/behaviour/controls/simple.json +7 -35
- package/src/stories/behaviour/filter/dataLoop.json +0 -8
- package/src/stories/behaviour/filter/source.json +0 -12
- package/src/stories/behaviour/filter/sourceLoop.json +0 -12
- package/src/stories/behaviour/missing/source.json +12 -60
- package/src/stories/behaviour/others/V2_DeclarationsSimples.json +14 -70
- package/src/stories/behaviour/others/V2_MinMaxSum_Boucles.json +5 -25
- package/src/stories/behaviour/others/V2_QuestSimple_Boucles.json +107 -535
- package/src/stories/behaviour/others/V2_TCMRallyeGames.json +33 -165
- package/src/stories/behaviour/others/test-dylan.json +5 -25
- package/src/stories/behaviour/paste/source.json +1 -5
- package/src/stories/behaviour/performance/performance.stories.jsx +2 -2
- package/src/stories/behaviour/performance/source.json +4 -20
- package/src/stories/behaviour/resizing/source-resizing-cleaning.json +2 -10
- package/src/stories/behaviour/resizing/source.json +5 -25
- package/src/stories/checkbox-boolean/source.json +1 -5
- package/src/stories/checkbox-group/source.json +16 -80
- package/src/stories/checkbox-group/sourceCondition.json +3 -15
- package/src/stories/checkbox-group/sourceDetail.json +18 -90
- package/src/stories/checkbox-group/sourceLoop.json +2 -10
- package/src/stories/checkbox-one/source.json +1 -5
- package/src/stories/checkbox-one/sourceDetail.json +2 -10
- package/src/stories/date-picker/source.json +1 -5
- package/src/stories/declaration/source.json +2 -10
- package/src/stories/disabled/data.json +0 -16
- package/src/stories/disabled/source.json +7 -35
- package/src/stories/dropdown/data.json +2 -10
- package/src/stories/dropdown/source.json +2 -10
- package/src/stories/duration/mois.json +1 -5
- package/src/stories/duration/time.json +1 -5
- package/src/stories/filter-description/source-options.json +3 -15
- package/src/stories/input/source.json +1 -5
- package/src/stories/input-number/input-number.stories.jsx +5 -0
- package/src/stories/input-number/source-big-number.json +27 -0
- package/src/stories/input-number/source-euro.json +2 -6
- package/src/stories/input-number/source.json +1 -5
- package/src/stories/loop/source-bloc.json +2 -10
- package/src/stories/loop/source-paginated.json +2 -10
- package/src/stories/loop/source-roster.json +2 -10
- package/src/stories/loop/source-with-header.json +2 -10
- package/src/stories/overview/dataLoop.json +24 -120
- package/src/stories/overview/overview.stories.jsx +9 -0
- package/src/stories/overview/source.json +1 -5
- package/src/stories/overview/sourceLoop.json +24 -120
- package/src/stories/overview/sourceWithHierarchy.json +164 -820
- package/src/stories/pairwise/source.json +5 -25
- package/src/stories/question/source.json +2 -10
- package/src/stories/questionnaires/logement/data.json +0 -1288
- package/src/stories/questionnaires/logement/source-sequence.json +564 -2820
- package/src/stories/questionnaires/logement/source-sum.json +280 -1400
- package/src/stories/questionnaires/logement/source.json +564 -2820
- package/src/stories/questionnaires/recensement/source.json +106 -530
- package/src/stories/questionnaires/rp/source.json +8 -40
- package/src/stories/questionnaires/simpsons/source.json +104 -520
- package/src/stories/radio/source.json +1 -5
- package/src/stories/radio/sourceCondition.json +2 -10
- package/src/stories/radio/sourceDetail.json +2 -10
- package/src/stories/radio/sourceHorizontal.json +1 -5
- package/src/stories/roundabout/data1.json +0 -12
- package/src/stories/roundabout/data2.json +0 -16
- package/src/stories/roundabout/source.json +11 -35
- package/src/stories/suggester/source-arbitrary-response.json +6 -30
- package/src/stories/suggester/source-error.json +6 -30
- package/src/stories/suggester/source-multiline.json +0 -16
- package/src/stories/suggester/source-option-responses.json +5 -25
- package/src/stories/suggester/source.json +7 -35
- package/src/stories/summary/data.json +0 -16
- package/src/stories/summary/source.json +7 -35
- package/src/stories/switch/data-forced.json +2 -10
- package/src/stories/switch/source.json +4 -20
- package/src/stories/table/source-colspan.json +8 -40
- package/src/stories/table/table-dynamique.json +1 -5
- package/src/stories/text/source-roster.json +3 -15
- package/src/stories/text/source-table.json +9 -45
- package/src/stories/textarea/source.json +1 -5
- package/src/stories/utils/{SchemaValidator.tsx → SchemaValidator.jsx} +1 -1
- package/src/stories/utils/{orchestrator.tsx → orchestrator.jsx} +9 -13
- package/src/stories/utils/{overview.tsx → overview.jsx} +0 -2
- package/src/tests/utils/lunatic.ts +0 -4
- package/src/type.source.ts +8 -7
- package/src/use-lunatic/__snapshots__/use-lunatic.test.ts.snap +0 -1159
- package/src/use-lunatic/commons/fill-components/fill-components.ts +4 -1
- package/src/use-lunatic/commons/page.ts +10 -0
- package/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.ts +182 -24
- package/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.ts +2 -5
- package/src/use-lunatic/commons/variables/get-questionnaire-data.ts +0 -12
- package/src/use-lunatic/commons/variables/lunatic-variables-store.spec.ts +207 -9
- package/src/use-lunatic/commons/variables/lunatic-variables-store.ts +7 -4
- package/src/use-lunatic/hooks/use-page-has-response.test.ts +200 -0
- package/src/use-lunatic/hooks/use-page-has-response.ts +67 -44
- package/src/use-lunatic/hooks/useOverview.spec.ts +42 -0
- package/src/use-lunatic/hooks/useOverview.ts +41 -18
- package/src/use-lunatic/props/propOptions.spec.ts +71 -5
- package/src/use-lunatic/props/propOptions.ts +23 -3
- package/src/use-lunatic/props/propValue.spec.ts +105 -2
- package/src/use-lunatic/props/propValue.ts +26 -8
- package/src/use-lunatic/reducer/reducerInitializer.tsx +31 -41
- package/src/use-lunatic/test.utils.ts +17 -0
- package/src/use-lunatic/type.ts +18 -8
- package/src/use-lunatic/use-lunatic.test.ts +15 -44
- package/src/use-lunatic/use-lunatic.ts +7 -7
- package/src/utils/cast.ts +67 -0
- package/src/utils/constants/variable-status.ts +0 -4
- package/src/utils/variables.spec.ts +0 -8
- package/stories/overview/sourceWithHierarchy.json +5151 -0
- package/tests/utils/lunatic.d.ts +0 -4
- package/tests/utils/lunatic.js +0 -4
- package/tests/utils/lunatic.js.map +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/type.source.d.ts +6 -6
- package/type.source.js +0 -1
- package/type.source.js.map +1 -1
- package/use-lunatic/commons/fill-components/fill-components.d.ts +2 -0
- package/use-lunatic/commons/fill-components/fill-components.js +1 -1
- package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/use-lunatic/commons/page.js +8 -0
- package/use-lunatic/commons/page.js.map +1 -1
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +1 -1
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +111 -14
- package/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js.map +1 -1
- package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +3 -3
- package/use-lunatic/commons/variables/behaviours/resizing-behaviour.js.map +1 -1
- package/use-lunatic/commons/variables/get-questionnaire-data.js +0 -8
- package/use-lunatic/commons/variables/get-questionnaire-data.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.d.ts +2 -2
- package/use-lunatic/commons/variables/lunatic-variables-store.js +5 -3
- package/use-lunatic/commons/variables/lunatic-variables-store.js.map +1 -1
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js +204 -9
- package/use-lunatic/commons/variables/lunatic-variables-store.spec.js.map +1 -1
- package/use-lunatic/hooks/use-page-has-response.js +49 -34
- package/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/use-lunatic/hooks/useOverview.d.ts +1 -1
- package/use-lunatic/hooks/useOverview.js +19 -14
- package/use-lunatic/hooks/useOverview.js.map +1 -1
- package/use-lunatic/hooks/useOverview.spec.d.ts +1 -0
- package/use-lunatic/hooks/useOverview.spec.js +43 -0
- package/use-lunatic/hooks/useOverview.spec.js.map +1 -0
- package/use-lunatic/props/getComponentTypeProps.d.ts +2 -1
- package/use-lunatic/props/propOptions.d.ts +2 -1
- package/use-lunatic/props/propOptions.js +23 -3
- package/use-lunatic/props/propOptions.js.map +1 -1
- package/use-lunatic/props/propOptions.spec.js +46 -5
- package/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/use-lunatic/props/propValue.js +18 -6
- package/use-lunatic/props/propValue.js.map +1 -1
- package/use-lunatic/props/propValue.spec.js +97 -2
- package/use-lunatic/props/propValue.spec.js.map +1 -1
- package/use-lunatic/reducer/reducerInitializer.d.ts +2 -2
- package/use-lunatic/reducer/reducerInitializer.js +25 -32
- package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/use-lunatic/test.utils.d.ts +2 -0
- package/use-lunatic/test.utils.js +17 -0
- package/use-lunatic/test.utils.js.map +1 -0
- package/use-lunatic/type.d.ts +18 -8
- package/use-lunatic/use-lunatic.d.ts +1 -2
- package/use-lunatic/use-lunatic.js +2 -3
- package/use-lunatic/use-lunatic.js.map +1 -1
- package/utils/cast.d.ts +19 -0
- package/utils/cast.js +70 -0
- package/utils/cast.js.map +1 -0
- package/utils/constants/variable-status.d.ts +0 -4
- package/utils/constants/variable-status.js +1 -5
- package/utils/constants/variable-status.js.map +1 -1
- package/utils/variables.spec.js +0 -8
- package/utils/variables.spec.js.map +1 -1
- package/constants/component-types.d.ts +0 -1
- package/constants/component-types.js +0 -5
- package/constants/component-types.js.map +0 -1
- package/constants/declarations.d.ts +0 -9
- package/constants/declarations.js +0 -15
- package/constants/declarations.js.map +0 -1
- package/constants/event-types.d.ts +0 -10
- package/constants/event-types.js +0 -16
- package/constants/event-types.js.map +0 -1
- package/constants/index.d.ts +0 -5
- package/constants/index.js +0 -22
- package/constants/index.js.map +0 -1
- package/constants/indexedDBStore.d.ts +0 -21
- package/constants/indexedDBStore.js +0 -22
- package/constants/indexedDBStore.js.map +0 -1
- package/constants/supported-preferences.d.ts +0 -1
- package/constants/supported-preferences.js +0 -36
- package/constants/supported-preferences.js.map +0 -1
- package/constants/value-types.d.ts +0 -5
- package/constants/value-types.js +0 -9
- package/constants/value-types.js.map +0 -1
- package/constants/variable-types.d.ts +0 -2
- package/constants/variable-types.js +0 -8
- package/constants/variable-types.js.map +0 -1
- package/esm/constants/component-types.d.ts +0 -1
- package/esm/constants/component-types.js +0 -2
- package/esm/constants/component-types.js.map +0 -1
- package/esm/constants/declarations.d.ts +0 -9
- package/esm/constants/declarations.js +0 -12
- package/esm/constants/declarations.js.map +0 -1
- package/esm/constants/event-types.d.ts +0 -10
- package/esm/constants/event-types.js +0 -13
- package/esm/constants/event-types.js.map +0 -1
- package/esm/constants/index.d.ts +0 -5
- package/esm/constants/index.js +0 -6
- package/esm/constants/index.js.map +0 -1
- package/esm/constants/indexedDBStore.d.ts +0 -21
- package/esm/constants/indexedDBStore.js +0 -19
- package/esm/constants/indexedDBStore.js.map +0 -1
- package/esm/constants/supported-preferences.d.ts +0 -1
- package/esm/constants/supported-preferences.js +0 -10
- package/esm/constants/supported-preferences.js.map +0 -1
- package/esm/constants/value-types.d.ts +0 -5
- package/esm/constants/value-types.js +0 -6
- package/esm/constants/value-types.js.map +0 -1
- package/esm/constants/variable-types.d.ts +0 -2
- package/esm/constants/variable-types.js +0 -5
- package/esm/constants/variable-types.js.map +0 -1
- package/esm/utils/getArticulation.d.ts +0 -58
- package/esm/utils/getArticulation.js +0 -78
- package/esm/utils/getArticulation.js.map +0 -1
- package/src/constants/component-types.ts +0 -1
- package/src/constants/declarations.ts +0 -14
- package/src/constants/event-types.ts +0 -13
- package/src/constants/index.ts +0 -5
- package/src/constants/indexedDBStore.ts +0 -20
- package/src/constants/supported-preferences.ts +0 -10
- package/src/constants/value-types.ts +0 -5
- package/src/constants/variable-types.ts +0 -4
- package/src/stories/behaviour/articulation/articulation.stories.tsx +0 -108
- package/src/stories/behaviour/articulation/roundabout.json +0 -348
- package/src/utils/getArticulation.ts +0 -117
- package/utils/getArticulation.d.ts +0 -58
- package/utils/getArticulation.js +0 -77
- package/utils/getArticulation.js.map +0 -1
|
@@ -12,6 +12,7 @@ import { getMissingResponseProp } from '../../props/propMissingResponse';
|
|
|
12
12
|
import { getValueProp } from '../../props/propValue';
|
|
13
13
|
import { getIterationsProp } from '../../props/propIterations';
|
|
14
14
|
import { getOptionsProp } from '../../props/propOptions';
|
|
15
|
+
import { LunaticLogger } from '../../logger/type';
|
|
15
16
|
|
|
16
17
|
type FillComponentArgs = {
|
|
17
18
|
disableFilters?: boolean;
|
|
@@ -25,6 +26,7 @@ type FillComponentArgs = {
|
|
|
25
26
|
preferences: LunaticOptions['preferences'];
|
|
26
27
|
pager: LunaticReducerState['pager'];
|
|
27
28
|
variables: LunaticReducerState['variables'];
|
|
29
|
+
logger: LunaticLogger;
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -56,7 +58,8 @@ export const fillComponent = (
|
|
|
56
58
|
state.variables,
|
|
57
59
|
state.handleChanges,
|
|
58
60
|
state.pager.iteration,
|
|
59
|
-
value
|
|
61
|
+
value,
|
|
62
|
+
state.logger
|
|
60
63
|
),
|
|
61
64
|
...getComponentTypeProps(interpretedProps, state),
|
|
62
65
|
// This is too dynamic to be typed correctly, so we allow any here
|
|
@@ -31,6 +31,16 @@ export function isPageEmpty(state: LunaticReducerState): boolean {
|
|
|
31
31
|
if (options.disableFilters) {
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
// The component is a paginated loop, consider it invisible if iteration size is 0
|
|
36
|
+
if ('paginatedLoop' in component && component.paginatedLoop) {
|
|
37
|
+
const iterations = state.executeExpression<number>(component.iterations);
|
|
38
|
+
if (!iterations) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Use condition filter if present
|
|
34
44
|
if ('conditionFilter' in component && component.conditionFilter) {
|
|
35
45
|
return executeConditionFilter(
|
|
36
46
|
component.conditionFilter,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
IterationLevel,
|
|
3
|
+
LunaticVariablesStore,
|
|
4
|
+
} from '../lunatic-variables-store';
|
|
2
5
|
import type { LunaticSource } from '../../../type';
|
|
3
6
|
import { depth } from '../../../../utils/array';
|
|
7
|
+
import { castBool } from '../../../../utils/cast';
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Cleaning behaviour for the store
|
|
@@ -9,13 +13,30 @@ import { depth } from '../../../../utils/array';
|
|
|
9
13
|
export function cleaningBehaviour(
|
|
10
14
|
store: LunaticVariablesStore,
|
|
11
15
|
cleaning: LunaticSource['cleaning'],
|
|
12
|
-
// Value used as default when cleaning a variable
|
|
13
|
-
|
|
16
|
+
// Value used as default when cleaning a variable, correspoding to value of variable in source.json (not data)
|
|
17
|
+
sourceValues: Record<string, unknown> = {}
|
|
14
18
|
) {
|
|
15
19
|
if (!cleaning) {
|
|
16
20
|
return;
|
|
17
21
|
}
|
|
18
22
|
|
|
23
|
+
// Create calculated variables from cleaning expressions
|
|
24
|
+
for (const source in cleaning) {
|
|
25
|
+
for (const target in cleaning[source]) {
|
|
26
|
+
if (Array.isArray(cleaning[source][target])) {
|
|
27
|
+
for (const cleaningInfo of cleaning[source][target]) {
|
|
28
|
+
store.setCalculated(
|
|
29
|
+
cleaningInfo.expression,
|
|
30
|
+
cleaningInfo.expression,
|
|
31
|
+
{
|
|
32
|
+
shapeFrom: cleaningInfo.shapeFrom,
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
19
40
|
// Create a map to improve performance
|
|
20
41
|
const cleaningMap = new Map(Object.entries(cleaning));
|
|
21
42
|
|
|
@@ -30,28 +51,28 @@ export function cleaningBehaviour(
|
|
|
30
51
|
|
|
31
52
|
for (const variableName in cleaningInfo) {
|
|
32
53
|
try {
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
// First: check if variable is already cleaned i.e, value is `null`, empty or list of `null`
|
|
55
|
+
if (isAlreadyCleaned(store, variableName)) continue;
|
|
56
|
+
// Second: check if variable should be clean i.e one of expressions is true
|
|
57
|
+
|
|
58
|
+
// shouldClean is simple boolean or array of boolean if there have a shapeFrom
|
|
59
|
+
const shouldCleanResult = shouldClean(store, {
|
|
60
|
+
expressions: cleaningInfo[variableName],
|
|
61
|
+
iteration: iteration,
|
|
62
|
+
isResizing: e.detail.cause === 'resizing',
|
|
35
63
|
});
|
|
36
|
-
|
|
64
|
+
|
|
65
|
+
if (Array.isArray(shouldCleanResult)) {
|
|
66
|
+
cleanArrayVariableAccordingCondition(
|
|
67
|
+
store,
|
|
68
|
+
sourceValues,
|
|
69
|
+
variableName,
|
|
70
|
+
shouldCleanResult
|
|
71
|
+
);
|
|
37
72
|
continue;
|
|
38
73
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const variableDepth = depth(initialValues[variableName]);
|
|
42
|
-
const variableIteration =
|
|
43
|
-
variableDepth === 0
|
|
44
|
-
? undefined
|
|
45
|
-
: iteration?.slice(0, depth(initialValues[variableName]));
|
|
46
|
-
|
|
47
|
-
store.set(
|
|
48
|
-
variableName,
|
|
49
|
-
getValueAtIteration(initialValues[variableName], variableIteration),
|
|
50
|
-
{
|
|
51
|
-
iteration: variableIteration,
|
|
52
|
-
cause: 'cleaning',
|
|
53
|
-
}
|
|
54
|
-
);
|
|
74
|
+
if (shouldCleanResult)
|
|
75
|
+
cleanVariable(store, sourceValues, variableName, iteration);
|
|
55
76
|
} catch (e) {
|
|
56
77
|
// If we have an error, skip this cleaning
|
|
57
78
|
console.error(e);
|
|
@@ -60,14 +81,151 @@ export function cleaningBehaviour(
|
|
|
60
81
|
});
|
|
61
82
|
}
|
|
62
83
|
|
|
84
|
+
function isAlreadyCleaned(store: LunaticVariablesStore, variableName: string) {
|
|
85
|
+
const value = store.get(variableName);
|
|
86
|
+
if (Array.isArray(value)) return value.every((v) => v === null);
|
|
87
|
+
if (value === null) return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Check if a variable need to be cleaned
|
|
92
|
+
*/
|
|
93
|
+
function shouldClean(
|
|
94
|
+
store: LunaticVariablesStore,
|
|
95
|
+
{
|
|
96
|
+
// The expressions are a list of condition filter to display the variable, so we should clean if the filter is evaluated to false (false = variable is not visible)
|
|
97
|
+
expressions,
|
|
98
|
+
iteration,
|
|
99
|
+
isResizing,
|
|
100
|
+
}: {
|
|
101
|
+
expressions:
|
|
102
|
+
| string
|
|
103
|
+
| {
|
|
104
|
+
expression: string;
|
|
105
|
+
shapeFrom?: string;
|
|
106
|
+
isAggregatorUsed: boolean;
|
|
107
|
+
}[];
|
|
108
|
+
iteration?: number[];
|
|
109
|
+
isResizing: boolean;
|
|
110
|
+
}
|
|
111
|
+
) {
|
|
112
|
+
// Legacy cleaning used a simple string
|
|
113
|
+
if (typeof expressions === 'string') {
|
|
114
|
+
return !castBool(
|
|
115
|
+
store.run(expressions, {
|
|
116
|
+
iteration,
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// New format use tuples { expression, shapeFrom, isAggregatorUsed }
|
|
122
|
+
if (isResizing) {
|
|
123
|
+
// If we are resizing a variable, only run expression containing aggregators (count(), sum()...)
|
|
124
|
+
expressions = expressions.filter((expr) => expr.isAggregatorUsed);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// here, value has change in root scope, but we have to to check for each iteration of variable
|
|
128
|
+
if (hasShapeFrom(expressions) && !iteration) {
|
|
129
|
+
const shapeFromVariable = store.get(
|
|
130
|
+
expressions[0].shapeFrom as string
|
|
131
|
+
) as Array<unknown>;
|
|
132
|
+
|
|
133
|
+
const shouldCleanArray = new Array(shapeFromVariable.length).fill(
|
|
134
|
+
false
|
|
135
|
+
) as Array<boolean>;
|
|
136
|
+
|
|
137
|
+
for (const [iterationIndex] of shouldCleanArray.entries()) {
|
|
138
|
+
shouldCleanArray[iterationIndex] = shouldClean(store, {
|
|
139
|
+
expressions,
|
|
140
|
+
iteration: [iterationIndex],
|
|
141
|
+
isResizing,
|
|
142
|
+
}) as boolean;
|
|
143
|
+
}
|
|
144
|
+
return shouldCleanArray;
|
|
145
|
+
} else {
|
|
146
|
+
// if only one expression is false, we have to clean (condition is display condition)
|
|
147
|
+
for (const expression of expressions) {
|
|
148
|
+
// Run the expression to check if cleaning should happen
|
|
149
|
+
if (
|
|
150
|
+
!store.run(expression.expression, {
|
|
151
|
+
iteration,
|
|
152
|
+
})
|
|
153
|
+
)
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
63
161
|
function getValueAtIteration(value: unknown, iteration?: number[]) {
|
|
64
162
|
if (!iteration || iteration.length === 0) {
|
|
65
163
|
return value ?? null;
|
|
66
164
|
}
|
|
67
|
-
|
|
68
165
|
if (!Array.isArray(value)) {
|
|
69
166
|
return null;
|
|
70
167
|
}
|
|
71
|
-
|
|
72
168
|
return getValueAtIteration(value[iteration[0]], iteration.slice(1));
|
|
73
169
|
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* hasShapeFrom
|
|
173
|
+
* actually, in cleaning modelisation,
|
|
174
|
+
* all expressions have no shapeFrom or have the **same** shapeFrom
|
|
175
|
+
* @param expressions
|
|
176
|
+
* @returns boolean if all expression has shapeFrom
|
|
177
|
+
*
|
|
178
|
+
*/
|
|
179
|
+
function hasShapeFrom(
|
|
180
|
+
expressions: {
|
|
181
|
+
expression: string;
|
|
182
|
+
shapeFrom?: string;
|
|
183
|
+
isAggregatorUsed: boolean;
|
|
184
|
+
}[]
|
|
185
|
+
) {
|
|
186
|
+
return expressions.every(
|
|
187
|
+
(expression) =>
|
|
188
|
+
expression.shapeFrom !== null && expression.shapeFrom !== undefined
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function cleanArrayVariableAccordingCondition(
|
|
193
|
+
store: LunaticVariablesStore,
|
|
194
|
+
sourceValues: Record<string, unknown>,
|
|
195
|
+
variableName: string,
|
|
196
|
+
shouldClean: boolean[]
|
|
197
|
+
) {
|
|
198
|
+
for (const [iteration, shouldCleanByIteration] of shouldClean.entries()) {
|
|
199
|
+
if (shouldCleanByIteration)
|
|
200
|
+
cleanVariable(store, sourceValues, variableName, [iteration]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* cleanVariable: this function set to null (and not initalValue) the variable at iteration
|
|
206
|
+
* @param store
|
|
207
|
+
* @param variableName
|
|
208
|
+
* @param iteration
|
|
209
|
+
*/
|
|
210
|
+
function cleanVariable(
|
|
211
|
+
store: LunaticVariablesStore,
|
|
212
|
+
sourceValues: Record<string, unknown>,
|
|
213
|
+
variableName: string,
|
|
214
|
+
iteration: IterationLevel | undefined
|
|
215
|
+
) {
|
|
216
|
+
// Variable may be top level, so we need to deduce expected iteration
|
|
217
|
+
const variableDepth = depth(sourceValues[variableName]);
|
|
218
|
+
const variableIteration =
|
|
219
|
+
variableDepth === 0
|
|
220
|
+
? undefined
|
|
221
|
+
: iteration?.slice(0, depth(sourceValues[variableName]));
|
|
222
|
+
|
|
223
|
+
store.set(
|
|
224
|
+
variableName,
|
|
225
|
+
getValueAtIteration(sourceValues[variableName], variableIteration),
|
|
226
|
+
{
|
|
227
|
+
iteration: variableIteration,
|
|
228
|
+
cause: 'cleaning',
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
}
|
|
@@ -29,7 +29,7 @@ export function resizingBehaviour(
|
|
|
29
29
|
|
|
30
30
|
// Pairwise resizing
|
|
31
31
|
if ('sizeForLinksVariables' in resizingInfo) {
|
|
32
|
-
resizePairwise(store, resizingInfo
|
|
32
|
+
resizePairwise(store, resizingInfo);
|
|
33
33
|
if (!('size' in resizingInfo)) {
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
@@ -58,9 +58,6 @@ function resizePairwise(
|
|
|
58
58
|
| [string, string]
|
|
59
59
|
| { xAxisSize: string; yAxisSize: string };
|
|
60
60
|
linksVariables: string[];
|
|
61
|
-
},
|
|
62
|
-
args: {
|
|
63
|
-
iteration?: number[];
|
|
64
61
|
}
|
|
65
62
|
) {
|
|
66
63
|
// Handle expression being sent as an array or an object (ensure backward compatibility)
|
|
@@ -77,7 +74,7 @@ function resizePairwise(
|
|
|
77
74
|
return forceInt(store.run(getExpressionAsString(expression)));
|
|
78
75
|
});
|
|
79
76
|
resizingInfo.linksVariables.forEach((variable) => {
|
|
80
|
-
const value = store.get(variable
|
|
77
|
+
const value = store.get(variable);
|
|
81
78
|
const resizedValue = resizeArray(
|
|
82
79
|
// The value is not an array, force an array
|
|
83
80
|
Array.isArray(value) ? value.map((i) => resizeArray(i, ySize, null)) : [],
|
|
@@ -13,10 +13,6 @@ export function getQuestionnaireData(
|
|
|
13
13
|
COLLECTED: {} as Record<
|
|
14
14
|
string,
|
|
15
15
|
{
|
|
16
|
-
EDITED: unknown;
|
|
17
|
-
FORCED: unknown;
|
|
18
|
-
INPUTTED: unknown;
|
|
19
|
-
PREVIOUS: unknown;
|
|
20
16
|
COLLECTED: unknown;
|
|
21
17
|
}
|
|
22
18
|
>,
|
|
@@ -34,10 +30,6 @@ export function getQuestionnaireData(
|
|
|
34
30
|
variableNames.map((name) => [
|
|
35
31
|
name,
|
|
36
32
|
{
|
|
37
|
-
EDITED: null,
|
|
38
|
-
FORCED: null,
|
|
39
|
-
INPUTTED: null,
|
|
40
|
-
PREVIOUS: null,
|
|
41
33
|
COLLECTED: store.get(name),
|
|
42
34
|
},
|
|
43
35
|
])
|
|
@@ -53,10 +45,6 @@ export function getQuestionnaireData(
|
|
|
53
45
|
|
|
54
46
|
if (variable.variableType === 'COLLECTED') {
|
|
55
47
|
result.COLLECTED[variable.name] = {
|
|
56
|
-
PREVIOUS: null,
|
|
57
|
-
FORCED: null,
|
|
58
|
-
EDITED: null,
|
|
59
|
-
INPUTTED: null,
|
|
60
48
|
...variable.values,
|
|
61
49
|
COLLECTED: store.get(variable.name),
|
|
62
50
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { cleaningBehaviour } from './behaviours/cleaning-behaviour';
|
|
3
|
+
import * as cleaningModule from './behaviours/cleaning-behaviour';
|
|
3
4
|
import { missingBehaviour } from './behaviours/missing-behaviour';
|
|
4
5
|
import { resizingBehaviour } from './behaviours/resizing-behaviour';
|
|
5
6
|
import { LunaticVariablesStore } from './lunatic-variables-store';
|
|
@@ -103,6 +104,17 @@ describe('lunatic-variables-store', () => {
|
|
|
103
104
|
expect(() => variables.run('Hello world')).toThrowError();
|
|
104
105
|
});
|
|
105
106
|
|
|
107
|
+
it('should handle calculated with aggregates', () => {
|
|
108
|
+
variables.set('AGES', [1, 2, 3]);
|
|
109
|
+
variables.setCalculated('NB_HAB', 'count(AGES)');
|
|
110
|
+
variables.setCalculated('AGES_PLUS_NBHAB', 'NB_HAB + AGES', {
|
|
111
|
+
shapeFrom: 'AGES',
|
|
112
|
+
});
|
|
113
|
+
expect(variables.get('NB_HAB')).toBe(3);
|
|
114
|
+
expect(variables.get('AGES_PLUS_NBHAB', [0])).toBe(4);
|
|
115
|
+
expect(variables.get('AGES_PLUS_NBHAB')).toEqual([4, 5, 6]);
|
|
116
|
+
});
|
|
117
|
+
|
|
106
118
|
describe('event listener', () => {
|
|
107
119
|
it('should trigger onChange', () => {
|
|
108
120
|
variables.set('FIRSTNAME', 'John');
|
|
@@ -286,7 +298,10 @@ describe('lunatic-variables-store', () => {
|
|
|
286
298
|
variables.set('LINKS', [[]]);
|
|
287
299
|
resizingBehaviour(variables, {
|
|
288
300
|
PRENOM: {
|
|
289
|
-
sizeForLinksVariables:
|
|
301
|
+
sizeForLinksVariables: {
|
|
302
|
+
xAxisSize: 'count(PRENOM)',
|
|
303
|
+
yAxisSize: 'count(PRENOM)',
|
|
304
|
+
},
|
|
290
305
|
linksVariables: ['LINKS'],
|
|
291
306
|
},
|
|
292
307
|
});
|
|
@@ -296,6 +311,19 @@ describe('lunatic-variables-store', () => {
|
|
|
296
311
|
[null, null, null],
|
|
297
312
|
[null, null, null],
|
|
298
313
|
]);
|
|
314
|
+
// Adding a person should not reset links
|
|
315
|
+
variables.set('LINKS', [
|
|
316
|
+
[null, '1', '3'],
|
|
317
|
+
['1', null, '3'],
|
|
318
|
+
['2', '2', null],
|
|
319
|
+
]);
|
|
320
|
+
variables.set('PRENOM', 'Marie', { iteration: [3] });
|
|
321
|
+
expect(variables.get('LINKS') as string[][]).toEqual([
|
|
322
|
+
[null, '1', '3', null],
|
|
323
|
+
['1', null, '3', null],
|
|
324
|
+
['2', '2', null, null],
|
|
325
|
+
[null, null, null, null],
|
|
326
|
+
]);
|
|
299
327
|
});
|
|
300
328
|
it('should resize pairwise with the object syntax', () => {
|
|
301
329
|
variables.set('PRENOM', []);
|
|
@@ -414,6 +442,106 @@ describe('lunatic-variables-store', () => {
|
|
|
414
442
|
variables.set('READY', false, { iteration: [1] });
|
|
415
443
|
expect(variables.get('PRENOM')).toEqual(null);
|
|
416
444
|
});
|
|
445
|
+
it('should handle the new array format', () => {
|
|
446
|
+
variables.set('PRENOM', ['John', 'Jane', 'Marc']);
|
|
447
|
+
variables.set('READY', [true, true, true]);
|
|
448
|
+
cleaningBehaviour(
|
|
449
|
+
variables,
|
|
450
|
+
{
|
|
451
|
+
READY: {
|
|
452
|
+
PRENOM: [
|
|
453
|
+
{
|
|
454
|
+
expression: 'READY',
|
|
455
|
+
shapeFrom: 'READY',
|
|
456
|
+
isAggregatorUsed: false,
|
|
457
|
+
},
|
|
458
|
+
],
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
{ PRENOM: [null] }
|
|
462
|
+
);
|
|
463
|
+
variables.set('READY', false, { iteration: [1] });
|
|
464
|
+
expect(variables.get('PRENOM')).toEqual(['John', null, 'Marc']);
|
|
465
|
+
});
|
|
466
|
+
it('should handle cleaning on aggregations', () => {
|
|
467
|
+
variables.set('PRENOM', ['John', 'Jane', 'Marc']);
|
|
468
|
+
variables.set('READY', [true, true, true]);
|
|
469
|
+
variables.setCalculated('NB_HAB', 'count(PRENOM)');
|
|
470
|
+
cleaningBehaviour(
|
|
471
|
+
variables,
|
|
472
|
+
{
|
|
473
|
+
READY: {
|
|
474
|
+
PRENOM: [
|
|
475
|
+
{
|
|
476
|
+
expression: 'READY',
|
|
477
|
+
shapeFrom: 'READY',
|
|
478
|
+
isAggregatorUsed: false,
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
expression: 'NB_HAB > 1',
|
|
482
|
+
isAggregatorUsed: true,
|
|
483
|
+
},
|
|
484
|
+
],
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
{ PRENOM: [null] }
|
|
488
|
+
);
|
|
489
|
+
variables.set('READY', false, { iteration: [1], cause: 'resizing' });
|
|
490
|
+
expect(variables.get('PRENOM')).toEqual(['John', 'Jane', 'Marc']);
|
|
491
|
+
variables.set('PRENOM', ['John'], { cause: 'resizing' });
|
|
492
|
+
variables.set('READY', [true], { cause: 'resizing' });
|
|
493
|
+
expect(variables.get('PRENOM')).toEqual([null]);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('should evaluate cleaning for each iteration', () => {
|
|
497
|
+
variables.set('PRENOM', ['John', 'Jane', 'Marc']);
|
|
498
|
+
variables.set('READY', [true, true, true]);
|
|
499
|
+
cleaningBehaviour(
|
|
500
|
+
variables,
|
|
501
|
+
{
|
|
502
|
+
READY: {
|
|
503
|
+
PRENOM: [
|
|
504
|
+
{
|
|
505
|
+
expression: 'READY',
|
|
506
|
+
shapeFrom: 'READY',
|
|
507
|
+
isAggregatorUsed: false,
|
|
508
|
+
},
|
|
509
|
+
],
|
|
510
|
+
},
|
|
511
|
+
},
|
|
512
|
+
{ PRENOM: [null] }
|
|
513
|
+
);
|
|
514
|
+
variables.set('READY', [true, true, false]);
|
|
515
|
+
expect(variables.get('PRENOM')).toEqual(['John', 'Jane', null]);
|
|
516
|
+
});
|
|
517
|
+
it('should evaluate cleaning for each iteration at root levl', () => {
|
|
518
|
+
variables.set('PRENOM', ['John', 'Jane', 'Marc']);
|
|
519
|
+
variables.set('AGE', [18, 21, 23]);
|
|
520
|
+
variables.setCalculated('NB_HAB', 'count(PRENOM)');
|
|
521
|
+
resizingBehaviour(variables, {
|
|
522
|
+
PRENOM: {
|
|
523
|
+
size: 'count(PRENOM)',
|
|
524
|
+
variables: ['AGE'],
|
|
525
|
+
},
|
|
526
|
+
});
|
|
527
|
+
cleaningBehaviour(
|
|
528
|
+
variables,
|
|
529
|
+
{
|
|
530
|
+
PRENOM: {
|
|
531
|
+
AGE: [
|
|
532
|
+
{
|
|
533
|
+
expression: 'NB_HAB >= 3',
|
|
534
|
+
shapeFrom: 'PRENOM',
|
|
535
|
+
isAggregatorUsed: true,
|
|
536
|
+
},
|
|
537
|
+
],
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
{ PRENOM: [], AGE: [] }
|
|
541
|
+
);
|
|
542
|
+
variables.set('PRENOM', ['John', 'Jane']);
|
|
543
|
+
expect(variables.get('AGE')).toEqual([null, null]);
|
|
544
|
+
});
|
|
417
545
|
});
|
|
418
546
|
|
|
419
547
|
describe('missing', () => {
|
|
@@ -449,10 +577,6 @@ describe('lunatic-variables-store', () => {
|
|
|
449
577
|
{
|
|
450
578
|
name: 'PRENOM',
|
|
451
579
|
values: {
|
|
452
|
-
EDITED: null,
|
|
453
|
-
FORCED: null,
|
|
454
|
-
INPUTTED: null,
|
|
455
|
-
PREVIOUS: null,
|
|
456
580
|
COLLECTED: 'John',
|
|
457
581
|
},
|
|
458
582
|
variableType: 'COLLECTED',
|
|
@@ -460,10 +584,6 @@ describe('lunatic-variables-store', () => {
|
|
|
460
584
|
{
|
|
461
585
|
name: 'NOM',
|
|
462
586
|
values: {
|
|
463
|
-
EDITED: null,
|
|
464
|
-
FORCED: null,
|
|
465
|
-
INPUTTED: null,
|
|
466
|
-
PREVIOUS: null,
|
|
467
587
|
COLLECTED: '',
|
|
468
588
|
},
|
|
469
589
|
variableType: 'COLLECTED',
|
|
@@ -488,5 +608,83 @@ describe('lunatic-variables-store', () => {
|
|
|
488
608
|
store.set('NOM', 'Doe');
|
|
489
609
|
expect(store.get('PRENOM')).toEqual('John');
|
|
490
610
|
});
|
|
611
|
+
it('should enable cleaning when disableCleaning = false', () => {
|
|
612
|
+
const cleaningSpy = vi.spyOn(cleaningModule, 'cleaningBehaviour');
|
|
613
|
+
LunaticVariablesStore.makeFromSource(
|
|
614
|
+
{
|
|
615
|
+
components: [],
|
|
616
|
+
variables: [
|
|
617
|
+
{
|
|
618
|
+
name: 'PRENOM',
|
|
619
|
+
values: {
|
|
620
|
+
COLLECTED: 'John',
|
|
621
|
+
},
|
|
622
|
+
variableType: 'COLLECTED',
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
name: 'NOM',
|
|
626
|
+
values: {
|
|
627
|
+
COLLECTED: '',
|
|
628
|
+
},
|
|
629
|
+
variableType: 'COLLECTED',
|
|
630
|
+
},
|
|
631
|
+
],
|
|
632
|
+
cleaning: {
|
|
633
|
+
NOM: {
|
|
634
|
+
PRENOM: 'false',
|
|
635
|
+
},
|
|
636
|
+
},
|
|
637
|
+
},
|
|
638
|
+
{
|
|
639
|
+
COLLECTED: {
|
|
640
|
+
PRENOM: {
|
|
641
|
+
COLLECTED: 'Jane',
|
|
642
|
+
},
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
{ current: () => {} },
|
|
646
|
+
false // enable cleaning
|
|
647
|
+
);
|
|
648
|
+
expect(cleaningSpy).toHaveBeenCalled();
|
|
649
|
+
});
|
|
650
|
+
it('should disable cleaning when disableCleaning = true', () => {
|
|
651
|
+
const cleaningSpy = vi.spyOn(cleaningModule, 'cleaningBehaviour');
|
|
652
|
+
LunaticVariablesStore.makeFromSource(
|
|
653
|
+
{
|
|
654
|
+
components: [],
|
|
655
|
+
variables: [
|
|
656
|
+
{
|
|
657
|
+
name: 'PRENOM',
|
|
658
|
+
values: {
|
|
659
|
+
COLLECTED: 'John',
|
|
660
|
+
},
|
|
661
|
+
variableType: 'COLLECTED',
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
name: 'NOM',
|
|
665
|
+
values: {
|
|
666
|
+
COLLECTED: '',
|
|
667
|
+
},
|
|
668
|
+
variableType: 'COLLECTED',
|
|
669
|
+
},
|
|
670
|
+
],
|
|
671
|
+
cleaning: {
|
|
672
|
+
NOM: {
|
|
673
|
+
PRENOM: 'false',
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
COLLECTED: {
|
|
679
|
+
PRENOM: {
|
|
680
|
+
COLLECTED: 'Jane',
|
|
681
|
+
},
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
{ current: () => {} },
|
|
685
|
+
true // disable cleaning
|
|
686
|
+
);
|
|
687
|
+
expect(cleaningSpy).not.toHaveBeenCalled();
|
|
688
|
+
});
|
|
491
689
|
});
|
|
492
690
|
});
|
|
@@ -24,7 +24,7 @@ let interpretCount = 0;
|
|
|
24
24
|
/** Special variable that will take the current iteration value. */
|
|
25
25
|
const iterationVariableName = 'GLOBAL_ITERATION_INDEX';
|
|
26
26
|
|
|
27
|
-
type IterationLevel = number[];
|
|
27
|
+
export type IterationLevel = number[];
|
|
28
28
|
export type EventArgs = {
|
|
29
29
|
change: {
|
|
30
30
|
/** Name of the changed variable. */
|
|
@@ -54,13 +54,14 @@ export class LunaticVariablesStore {
|
|
|
54
54
|
public static makeFromSource(
|
|
55
55
|
source: LunaticSource,
|
|
56
56
|
data: LunaticData,
|
|
57
|
-
changeHandler: RefObject<LunaticOptions['onVariableChange']
|
|
57
|
+
changeHandler: RefObject<LunaticOptions['onVariableChange']>,
|
|
58
|
+
disableCleaning?: boolean
|
|
58
59
|
) {
|
|
59
60
|
const store = new LunaticVariablesStore();
|
|
60
61
|
if (!source.variables) {
|
|
61
62
|
return store;
|
|
62
63
|
}
|
|
63
|
-
// Source data (picked from "variables" in the source.json)
|
|
64
|
+
// Source data (picked from "variables" in the source.json)s
|
|
64
65
|
const sourceValues: Record<string, unknown> = {};
|
|
65
66
|
// Starting data for the form (merged with data.json or injected data)
|
|
66
67
|
const initialValues: Record<string, unknown> = {};
|
|
@@ -90,7 +91,9 @@ export class LunaticVariablesStore {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
store.on('change', (e) => changeHandler?.current?.(e.detail));
|
|
93
|
-
|
|
94
|
+
if (!disableCleaning) {
|
|
95
|
+
cleaningBehaviour(store, source.cleaning, sourceValues);
|
|
96
|
+
}
|
|
94
97
|
resizingBehaviour(store, source.resizing);
|
|
95
98
|
missingBehaviour(store, source.missingBlock);
|
|
96
99
|
return store;
|