@inseefr/lunatic 3.11.2 → 3.12.0
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/Accordion/Accordion.d.ts +1 -1
- package/components/Datepicker/DatepickerFields.js +4 -2
- package/components/Datepicker/DatepickerFields.js.map +1 -1
- package/components/Duration/getDurationFromValue.js +3 -3
- package/components/Duration/getDurationFromValue.js.map +1 -1
- package/components/FilterDescription/FilterDescription.d.ts +1 -1
- package/components/LunaticComponents.d.ts +1 -1
- package/components/LunaticComponents.js +9 -7
- package/components/LunaticComponents.js.map +1 -1
- package/components/PairwiseLinks/PairwiseLinks.d.ts +1 -1
- package/components/PairwiseLinks/PairwiseLinks.js +15 -30
- package/components/PairwiseLinks/PairwiseLinks.js.map +1 -1
- package/components/PairwiseLinks/PairwiseMirror.d.ts +2 -0
- package/components/PairwiseLinks/PairwiseMirror.js +14 -0
- package/components/PairwiseLinks/PairwiseMirror.js.map +1 -0
- package/components/PairwiseLinks/combinations.d.ts +18 -0
- package/components/PairwiseLinks/combinations.js +29 -0
- package/components/PairwiseLinks/combinations.js.map +1 -0
- package/components/Radio/Radio.d.ts +1 -1
- package/components/Sequence/Sequence.d.ts +1 -1
- package/components/Subsequence/Subsequence.d.ts +1 -1
- package/components/Switch/Switch.d.ts +1 -1
- package/components/library.d.ts +6 -6
- package/components/type.d.ts +25 -28
- package/esm/components/Accordion/Accordion.d.ts +1 -1
- package/esm/components/Datepicker/DatepickerFields.js +4 -2
- package/esm/components/Datepicker/DatepickerFields.js.map +1 -1
- package/esm/components/Duration/getDurationFromValue.js +3 -3
- package/esm/components/Duration/getDurationFromValue.js.map +1 -1
- package/esm/components/FilterDescription/FilterDescription.d.ts +1 -1
- package/esm/components/LunaticComponents.d.ts +1 -1
- package/esm/components/LunaticComponents.js +9 -7
- package/esm/components/LunaticComponents.js.map +1 -1
- package/esm/components/PairwiseLinks/PairwiseLinks.d.ts +1 -1
- package/esm/components/PairwiseLinks/PairwiseLinks.js +16 -31
- package/esm/components/PairwiseLinks/PairwiseLinks.js.map +1 -1
- package/esm/components/PairwiseLinks/PairwiseMirror.d.ts +2 -0
- package/esm/components/PairwiseLinks/PairwiseMirror.js +10 -0
- package/esm/components/PairwiseLinks/PairwiseMirror.js.map +1 -0
- package/esm/components/PairwiseLinks/combinations.d.ts +18 -0
- package/esm/components/PairwiseLinks/combinations.js +24 -0
- package/esm/components/PairwiseLinks/combinations.js.map +1 -0
- package/esm/components/Radio/Radio.d.ts +1 -1
- package/esm/components/Sequence/Sequence.d.ts +1 -1
- package/esm/components/Subsequence/Subsequence.d.ts +1 -1
- package/esm/components/Switch/Switch.d.ts +1 -1
- package/esm/components/library.d.ts +6 -6
- package/esm/components/type.d.ts +25 -28
- package/esm/index.d.ts +1 -1
- package/esm/index.js.map +1 -1
- package/esm/type.source.d.ts +43 -13
- package/esm/type.source.js +0 -1
- package/esm/type.source.js.map +1 -1
- package/esm/use-lunatic/commons/compile-controls.js +1 -1
- package/esm/use-lunatic/commons/compile-controls.js.map +1 -1
- package/esm/use-lunatic/commons/component.d.ts +3 -2
- package/esm/use-lunatic/commons/component.js +5 -0
- package/esm/use-lunatic/commons/component.js.map +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-component-expressions.js +1 -42
- package/esm/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
- package/esm/use-lunatic/commons/fill-components/fill-components.js +10 -2
- package/esm/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/esm/use-lunatic/commons/index.d.ts +4 -4
- package/esm/use-lunatic/commons/index.js +4 -4
- package/esm/use-lunatic/commons/index.js.map +1 -1
- package/esm/use-lunatic/commons/{check-loops.d.ts → pagination/check-loops.d.ts} +7 -7
- package/esm/use-lunatic/commons/{check-loops.js → pagination/check-loops.js} +3 -5
- package/esm/use-lunatic/commons/pagination/check-loops.js.map +1 -0
- package/{use-lunatic/commons → esm/use-lunatic/commons/pagination}/check-pager.d.ts +1 -1
- package/esm/use-lunatic/commons/pagination/check-pager.js.map +1 -0
- package/{use-lunatic/commons → esm/use-lunatic/commons/pagination}/create-map-pages.d.ts +1 -1
- package/esm/use-lunatic/commons/pagination/create-map-pages.js.map +1 -0
- package/esm/use-lunatic/commons/{is-First-last-page.d.ts → pagination/is-First-last-page.d.ts} +1 -1
- package/esm/use-lunatic/commons/pagination/is-First-last-page.js.map +1 -0
- package/{use-lunatic/commons → esm/use-lunatic/commons/pagination}/is-paginated-loop.d.ts +1 -1
- package/esm/use-lunatic/commons/pagination/is-paginated-loop.js.map +1 -0
- package/esm/use-lunatic/commons/{is-roundabout.d.ts → pagination/is-roundabout.d.ts} +1 -1
- package/esm/use-lunatic/commons/pagination/is-roundabout.js.map +1 -0
- package/esm/use-lunatic/commons/{page-navigation.d.ts → pagination/page-navigation.d.ts} +2 -2
- package/esm/use-lunatic/commons/{page-navigation.js → pagination/page-navigation.js} +6 -6
- package/esm/use-lunatic/commons/pagination/page-navigation.js.map +1 -0
- package/esm/use-lunatic/commons/pagination/page-navigation.spec.js.map +1 -0
- package/esm/use-lunatic/commons/{page-tag.d.ts → pagination/page-tag.d.ts} +8 -1
- package/esm/use-lunatic/commons/{page-tag.js → pagination/page-tag.js} +17 -6
- package/esm/use-lunatic/commons/pagination/page-tag.js.map +1 -0
- package/esm/use-lunatic/commons/{page-tag.spec.js → pagination/page-tag.spec.js} +9 -1
- package/esm/use-lunatic/commons/pagination/page-tag.spec.js.map +1 -0
- package/{use-lunatic/commons → esm/use-lunatic/commons/pagination}/page.d.ts +1 -1
- package/esm/use-lunatic/commons/{page.js → pagination/page.js} +2 -2
- package/esm/use-lunatic/commons/pagination/page.js.map +1 -0
- package/esm/use-lunatic/hooks/use-page-has-response.js +37 -21
- package/esm/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/esm/use-lunatic/hooks/useOverview.js +2 -2
- package/esm/use-lunatic/hooks/useOverview.js.map +1 -1
- package/esm/use-lunatic/props/getComponentTypeProps.d.ts +28 -26
- package/esm/use-lunatic/props/getComponentTypeProps.js +3 -1
- package/esm/use-lunatic/props/getComponentTypeProps.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.d.ts +9 -1
- package/esm/use-lunatic/props/propOptions.js +56 -1
- package/esm/use-lunatic/props/propOptions.js.map +1 -1
- package/esm/use-lunatic/props/propOptions.spec.js +220 -56
- package/esm/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/esm/use-lunatic/reducer/commons/auto-explore-loop.js +3 -2
- package/esm/use-lunatic/reducer/commons/auto-explore-loop.js.map +1 -1
- package/esm/use-lunatic/reducer/overview/overviewOnInit.d.ts +1 -2
- package/esm/use-lunatic/reducer/overview/overviewOnInit.js +1 -1
- package/esm/use-lunatic/reducer/overview/overviewOnInit.js.map +1 -1
- package/esm/use-lunatic/reducer/reduce-go-next-page.js +4 -3
- package/esm/use-lunatic/reducer/reduce-go-next-page.js.map +1 -1
- package/esm/use-lunatic/reducer/reduce-go-previous-page.js +2 -2
- package/esm/use-lunatic/reducer/reduce-go-previous-page.js.map +1 -1
- package/esm/use-lunatic/reducer/reduce-go-to-page.js +2 -2
- package/esm/use-lunatic/reducer/reduce-go-to-page.js.map +1 -1
- package/esm/use-lunatic/reducer/reducerInitializer.js +2 -2
- package/esm/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/esm/use-lunatic/type.d.ts +1 -1
- package/esm/utils/cast.js +5 -2
- package/esm/utils/cast.js.map +1 -1
- package/esm/utils/getArticulationState.js +2 -1
- package/esm/utils/getArticulationState.js.map +1 -1
- package/esm/utils/number.js +4 -4
- package/esm/utils/number.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js.map +1 -1
- package/package.json +98 -79
- package/src/components/Datepicker/DatepickerFields.tsx +4 -2
- package/src/components/Duration/getDurationFromValue.ts +3 -3
- package/src/components/LunaticComponents.tsx +32 -25
- package/src/components/PairwiseLinks/PairwiseLinks.tsx +18 -57
- package/src/components/PairwiseLinks/PairwiseMirror.tsx +19 -0
- package/src/components/PairwiseLinks/combinations.test.ts +103 -0
- package/src/components/PairwiseLinks/combinations.ts +34 -0
- package/src/components/type.ts +204 -231
- package/src/index.ts +1 -4
- package/src/stories/checkbox/checkbox.stories.tsx +13 -0
- package/src/stories/checkbox/sourceOneDynamicOptions.json +496 -0
- package/src/stories/dropdown/dropdown.stories.tsx +12 -0
- package/src/stories/dropdown/sourceDynamicOptions.json +496 -0
- package/src/stories/pairwise/pairwise.stories.tsx +17 -1
- package/src/stories/pairwise/sourcePairwiseLoop.json +356 -0
- package/src/stories/radio/radio.stories.tsx +13 -0
- package/src/stories/radio/sourceDynamicOptions.json +496 -0
- package/src/type.source.ts +45 -14
- package/src/use-lunatic/commons/compile-controls.ts +1 -1
- package/src/use-lunatic/commons/component.ts +7 -2
- package/src/use-lunatic/commons/fill-components/fill-component-expressions.ts +3 -46
- package/src/use-lunatic/commons/fill-components/fill-components.ts +9 -10
- package/src/use-lunatic/commons/index.ts +8 -4
- package/src/use-lunatic/commons/{check-loops.ts → pagination/check-loops.ts} +4 -10
- package/src/use-lunatic/commons/{check-pager.ts → pagination/check-pager.ts} +1 -1
- package/src/use-lunatic/commons/{create-map-pages.ts → pagination/create-map-pages.ts} +2 -2
- package/src/use-lunatic/commons/{is-First-last-page.ts → pagination/is-First-last-page.ts} +1 -1
- package/src/use-lunatic/commons/{is-paginated-loop.ts → pagination/is-paginated-loop.ts} +1 -1
- package/src/use-lunatic/commons/{is-roundabout.ts → pagination/is-roundabout.ts} +1 -1
- package/src/use-lunatic/commons/{page-navigation.spec.ts → pagination/page-navigation.spec.ts} +1 -1
- package/src/use-lunatic/commons/{page-navigation.ts → pagination/page-navigation.ts} +8 -8
- package/src/use-lunatic/commons/{page-tag.spec.ts → pagination/page-tag.spec.ts} +15 -2
- package/src/use-lunatic/commons/{page-tag.ts → pagination/page-tag.ts} +18 -7
- package/src/use-lunatic/commons/{page.ts → pagination/page.ts} +6 -3
- package/src/use-lunatic/hooks/use-page-has-response.ts +59 -28
- package/src/use-lunatic/hooks/useOverview.ts +6 -3
- package/src/use-lunatic/props/getComponentTypeProps.ts +2 -1
- package/src/use-lunatic/props/propOptions.spec.ts +217 -147
- package/src/use-lunatic/props/propOptions.ts +99 -10
- package/src/use-lunatic/reducer/commons/auto-explore-loop.ts +3 -2
- package/src/use-lunatic/reducer/overview/overviewOnInit.ts +2 -2
- package/src/use-lunatic/reducer/reduce-go-next-page.ts +4 -3
- package/src/use-lunatic/reducer/reduce-go-previous-page.ts +2 -2
- package/src/use-lunatic/reducer/reduce-go-to-page.ts +2 -2
- package/src/use-lunatic/reducer/reducerInitializer.tsx +2 -2
- package/src/use-lunatic/type.ts +1 -1
- package/src/utils/cast.ts +5 -2
- package/src/utils/getArticulationState.ts +2 -1
- package/src/utils/number.ts +4 -4
- package/tsconfig.build.tsbuildinfo +1 -1
- package/type.source.d.ts +43 -13
- package/type.source.js +0 -1
- package/type.source.js.map +1 -1
- package/use-lunatic/commons/compile-controls.js +1 -1
- package/use-lunatic/commons/compile-controls.js.map +1 -1
- package/use-lunatic/commons/component.d.ts +3 -2
- package/use-lunatic/commons/component.js +5 -0
- package/use-lunatic/commons/component.js.map +1 -1
- package/use-lunatic/commons/fill-components/fill-component-expressions.d.ts +1 -1
- package/use-lunatic/commons/fill-components/fill-component-expressions.js +12 -53
- package/use-lunatic/commons/fill-components/fill-component-expressions.js.map +1 -1
- package/use-lunatic/commons/fill-components/fill-components.js +9 -1
- package/use-lunatic/commons/fill-components/fill-components.js.map +1 -1
- package/use-lunatic/commons/index.d.ts +4 -4
- package/use-lunatic/commons/index.js +4 -4
- package/use-lunatic/commons/index.js.map +1 -1
- package/use-lunatic/commons/{check-loops.d.ts → pagination/check-loops.d.ts} +7 -7
- package/use-lunatic/commons/{check-loops.js → pagination/check-loops.js} +3 -5
- package/use-lunatic/commons/pagination/check-loops.js.map +1 -0
- package/{esm/use-lunatic/commons → use-lunatic/commons/pagination}/check-pager.d.ts +1 -1
- package/use-lunatic/commons/pagination/check-pager.js.map +1 -0
- package/{esm/use-lunatic/commons → use-lunatic/commons/pagination}/create-map-pages.d.ts +1 -1
- package/use-lunatic/commons/pagination/create-map-pages.js.map +1 -0
- package/use-lunatic/commons/{is-First-last-page.d.ts → pagination/is-First-last-page.d.ts} +1 -1
- package/use-lunatic/commons/pagination/is-First-last-page.js.map +1 -0
- package/{esm/use-lunatic/commons → use-lunatic/commons/pagination}/is-paginated-loop.d.ts +1 -1
- package/use-lunatic/commons/pagination/is-paginated-loop.js.map +1 -0
- package/use-lunatic/commons/{is-roundabout.d.ts → pagination/is-roundabout.d.ts} +1 -1
- package/use-lunatic/commons/pagination/is-roundabout.js.map +1 -0
- package/use-lunatic/commons/{page-navigation.d.ts → pagination/page-navigation.d.ts} +2 -2
- package/use-lunatic/commons/{page-navigation.js → pagination/page-navigation.js} +6 -6
- package/use-lunatic/commons/pagination/page-navigation.js.map +1 -0
- package/use-lunatic/commons/pagination/page-navigation.spec.js.map +1 -0
- package/use-lunatic/commons/{page-tag.d.ts → pagination/page-tag.d.ts} +8 -1
- package/use-lunatic/commons/{page-tag.js → pagination/page-tag.js} +18 -6
- package/use-lunatic/commons/pagination/page-tag.js.map +1 -0
- package/use-lunatic/commons/{page-tag.spec.js → pagination/page-tag.spec.js} +8 -0
- package/use-lunatic/commons/pagination/page-tag.spec.js.map +1 -0
- package/{esm/use-lunatic/commons → use-lunatic/commons/pagination}/page.d.ts +1 -1
- package/use-lunatic/commons/{page.js → pagination/page.js} +2 -2
- package/use-lunatic/commons/pagination/page.js.map +1 -0
- package/use-lunatic/hooks/use-page-has-response.js +36 -21
- package/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/use-lunatic/hooks/useOverview.js +2 -2
- package/use-lunatic/hooks/useOverview.js.map +1 -1
- package/use-lunatic/props/getComponentTypeProps.d.ts +28 -26
- package/use-lunatic/props/getComponentTypeProps.js +2 -1
- package/use-lunatic/props/getComponentTypeProps.js.map +1 -1
- package/use-lunatic/props/propOptions.d.ts +9 -1
- package/use-lunatic/props/propOptions.js +57 -2
- package/use-lunatic/props/propOptions.js.map +1 -1
- package/use-lunatic/props/propOptions.spec.js +217 -55
- package/use-lunatic/props/propOptions.spec.js.map +1 -1
- package/use-lunatic/reducer/commons/auto-explore-loop.js +6 -2
- package/use-lunatic/reducer/commons/auto-explore-loop.js.map +1 -1
- package/use-lunatic/reducer/overview/overviewOnInit.d.ts +1 -2
- package/use-lunatic/reducer/overview/overviewOnInit.js +1 -1
- package/use-lunatic/reducer/overview/overviewOnInit.js.map +1 -1
- package/use-lunatic/reducer/reduce-go-next-page.js +4 -3
- package/use-lunatic/reducer/reduce-go-next-page.js.map +1 -1
- package/use-lunatic/reducer/reduce-go-previous-page.js +2 -2
- package/use-lunatic/reducer/reduce-go-previous-page.js.map +1 -1
- package/use-lunatic/reducer/reduce-go-to-page.js +2 -2
- package/use-lunatic/reducer/reduce-go-to-page.js.map +1 -1
- package/use-lunatic/reducer/reducerInitializer.js +2 -2
- package/use-lunatic/reducer/reducerInitializer.js.map +1 -1
- package/use-lunatic/type.d.ts +1 -1
- package/utils/cast.js +5 -2
- package/utils/cast.js.map +1 -1
- package/utils/getArticulationState.js +2 -1
- package/utils/getArticulationState.js.map +1 -1
- package/utils/number.js +4 -4
- package/utils/number.js.map +1 -1
- package/esm/use-lunatic/commons/check-loops.js.map +0 -1
- package/esm/use-lunatic/commons/check-pager.js.map +0 -1
- package/esm/use-lunatic/commons/create-map-pages.js.map +0 -1
- package/esm/use-lunatic/commons/is-First-last-page.js.map +0 -1
- package/esm/use-lunatic/commons/is-paginated-loop.js.map +0 -1
- package/esm/use-lunatic/commons/is-roundabout.js.map +0 -1
- package/esm/use-lunatic/commons/page-navigation.js.map +0 -1
- package/esm/use-lunatic/commons/page-navigation.spec.js.map +0 -1
- package/esm/use-lunatic/commons/page-tag.js.map +0 -1
- package/esm/use-lunatic/commons/page-tag.spec.js.map +0 -1
- package/esm/use-lunatic/commons/page.js.map +0 -1
- package/use-lunatic/commons/check-loops.js.map +0 -1
- package/use-lunatic/commons/check-pager.js.map +0 -1
- package/use-lunatic/commons/create-map-pages.js.map +0 -1
- package/use-lunatic/commons/is-First-last-page.js.map +0 -1
- package/use-lunatic/commons/is-paginated-loop.js.map +0 -1
- package/use-lunatic/commons/is-roundabout.js.map +0 -1
- package/use-lunatic/commons/page-navigation.js.map +0 -1
- package/use-lunatic/commons/page-navigation.spec.js.map +0 -1
- package/use-lunatic/commons/page-tag.js.map +0 -1
- package/use-lunatic/commons/page-tag.spec.js.map +0 -1
- package/use-lunatic/commons/page.js.map +0 -1
- /package/esm/use-lunatic/commons/{check-pager.js → pagination/check-pager.js} +0 -0
- /package/esm/use-lunatic/commons/{create-map-pages.js → pagination/create-map-pages.js} +0 -0
- /package/esm/use-lunatic/commons/{is-First-last-page.js → pagination/is-First-last-page.js} +0 -0
- /package/esm/use-lunatic/commons/{is-paginated-loop.js → pagination/is-paginated-loop.js} +0 -0
- /package/esm/use-lunatic/commons/{is-roundabout.js → pagination/is-roundabout.js} +0 -0
- /package/esm/use-lunatic/commons/{page-navigation.spec.d.ts → pagination/page-navigation.spec.d.ts} +0 -0
- /package/esm/use-lunatic/commons/{page-navigation.spec.js → pagination/page-navigation.spec.js} +0 -0
- /package/esm/use-lunatic/commons/{page-tag.spec.d.ts → pagination/page-tag.spec.d.ts} +0 -0
- /package/use-lunatic/commons/{check-pager.js → pagination/check-pager.js} +0 -0
- /package/use-lunatic/commons/{create-map-pages.js → pagination/create-map-pages.js} +0 -0
- /package/use-lunatic/commons/{is-First-last-page.js → pagination/is-First-last-page.js} +0 -0
- /package/use-lunatic/commons/{is-paginated-loop.js → pagination/is-paginated-loop.js} +0 -0
- /package/use-lunatic/commons/{is-roundabout.js → pagination/is-roundabout.js} +0 -0
- /package/use-lunatic/commons/{page-navigation.spec.d.ts → pagination/page-navigation.spec.d.ts} +0 -0
- /package/use-lunatic/commons/{page-navigation.spec.js → pagination/page-navigation.spec.js} +0 -0
- /package/use-lunatic/commons/{page-tag.spec.d.ts → pagination/page-tag.spec.d.ts} +0 -0
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
LunaticReducerState,
|
|
6
6
|
} from '../../type';
|
|
7
7
|
import { isObject } from '../../../utils/object';
|
|
8
|
+
import { castBool, castNumber, castString } from '../../../utils/cast';
|
|
8
9
|
|
|
9
10
|
const VTL_ATTRIBUTES = [
|
|
10
11
|
['label', null],
|
|
@@ -37,51 +38,6 @@ const VTL_ATTRIBUTES = [
|
|
|
37
38
|
// List of property that can be simple string instead of expressions
|
|
38
39
|
const allowString = new Set(['unit']);
|
|
39
40
|
|
|
40
|
-
function castNumber(v: unknown): number {
|
|
41
|
-
if (typeof v === 'number') {
|
|
42
|
-
return v;
|
|
43
|
-
}
|
|
44
|
-
if (typeof v === 'string') {
|
|
45
|
-
return parseInt(v, 10);
|
|
46
|
-
}
|
|
47
|
-
if (Array.isArray(v) && v.length > 0) {
|
|
48
|
-
return castNumber(v[0]);
|
|
49
|
-
}
|
|
50
|
-
if (v === null) {
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
throw new Error(`Cannot cast "${v}" to number`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function castBool(v: unknown): boolean {
|
|
57
|
-
if (typeof v === 'boolean') {
|
|
58
|
-
return v;
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(v) && v.length > 0) {
|
|
61
|
-
return castBool(v[0]);
|
|
62
|
-
}
|
|
63
|
-
if (Array.isArray(v)) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return Boolean(v);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function castString(v: unknown): string {
|
|
70
|
-
if (typeof v === 'string') {
|
|
71
|
-
return v;
|
|
72
|
-
}
|
|
73
|
-
if (typeof v === 'number') {
|
|
74
|
-
return v.toString();
|
|
75
|
-
}
|
|
76
|
-
if (Array.isArray(v)) {
|
|
77
|
-
return v.map(castString).join(', ');
|
|
78
|
-
}
|
|
79
|
-
if (!v) {
|
|
80
|
-
return '';
|
|
81
|
-
}
|
|
82
|
-
return v.toString();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
41
|
// Utility type to replace all expression from an object into a translated version
|
|
86
42
|
type UntranslatedProperties =
|
|
87
43
|
| 'expressions'
|
|
@@ -91,7 +47,8 @@ type UntranslatedProperties =
|
|
|
91
47
|
| 'controls'
|
|
92
48
|
| 'conditionFilter'
|
|
93
49
|
| 'conditionReadOnly'
|
|
94
|
-
| 'components'
|
|
50
|
+
| 'components'
|
|
51
|
+
| 'optionFilter';
|
|
95
52
|
export type DeepTranslateExpression<T> = T extends LunaticExpression
|
|
96
53
|
? ReactNode
|
|
97
54
|
: T extends (infer ElementType)[]
|
|
@@ -11,7 +11,7 @@ import type { LunaticComponentProps } from '../../../components/type';
|
|
|
11
11
|
import { getMissingResponseProp } from '../../props/propMissingResponse';
|
|
12
12
|
import { getValueProp } from '../../props/propValue';
|
|
13
13
|
import { getIterationsProp } from '../../props/propIterations';
|
|
14
|
-
import {
|
|
14
|
+
import { computeOptionsFromComponent } from '../../props/propOptions';
|
|
15
15
|
import { LunaticLogger } from '../../logger/type';
|
|
16
16
|
import { VTLScalarExpression } from '../../../type.source';
|
|
17
17
|
|
|
@@ -80,16 +80,15 @@ export const fillComponent = (
|
|
|
80
80
|
missingResponse: getMissingResponseProp(component, state),
|
|
81
81
|
management: state.management,
|
|
82
82
|
iterations: getIterationsProp(component, state),
|
|
83
|
-
options:
|
|
84
|
-
|
|
85
|
-
state.
|
|
86
|
-
state.
|
|
87
|
-
state.pager.iteration,
|
|
83
|
+
options: computeOptionsFromComponent(interpretedProps, {
|
|
84
|
+
variables: state.variables,
|
|
85
|
+
handleChanges: state.handleChanges,
|
|
86
|
+
pagerIteration: state.pager.iteration,
|
|
88
87
|
value,
|
|
89
|
-
state.logger,
|
|
90
|
-
state.disableFilters,
|
|
91
|
-
shouldBeFiltered
|
|
92
|
-
),
|
|
88
|
+
logger: state.logger,
|
|
89
|
+
disableFilters: state.disableFilters,
|
|
90
|
+
shouldParentBeFiltered: shouldBeFiltered,
|
|
91
|
+
}),
|
|
93
92
|
...getComponentTypeProps(interpretedProps, state),
|
|
94
93
|
// This is too dynamic to be typed correctly, so we allow any here
|
|
95
94
|
} as any;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export { default as checkLoops } from './check-loops';
|
|
2
|
-
export { default as createMapPages } from './create-map-pages';
|
|
1
|
+
export { default as checkLoops } from './pagination/check-loops';
|
|
2
|
+
export { default as createMapPages } from './pagination/create-map-pages';
|
|
3
3
|
export { default as executeConditionFilter } from './execute-condition-filter';
|
|
4
4
|
export { default as getCompatibleVTLExpression } from './get-compatible-vtl-expression';
|
|
5
|
-
export { default as isFirstLastPage } from './is-First-last-page';
|
|
6
|
-
export {
|
|
5
|
+
export { default as isFirstLastPage } from './pagination/is-First-last-page';
|
|
6
|
+
export {
|
|
7
|
+
getNewReachedPage,
|
|
8
|
+
getPageTag,
|
|
9
|
+
isNewReachedPage,
|
|
10
|
+
} from './pagination/page-tag';
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
LunaticComponentDefinition,
|
|
5
5
|
LunaticExpression,
|
|
6
6
|
LunaticReducerState,
|
|
7
|
-
} from '
|
|
7
|
+
} from '../../type';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Extract the list of subpages linked to a component
|
|
@@ -22,7 +22,7 @@ function extractSubPages(
|
|
|
22
22
|
(pages, component) => {
|
|
23
23
|
const { page } = component;
|
|
24
24
|
|
|
25
|
-
if (page && pages.
|
|
25
|
+
if (page && !pages.includes(page)) {
|
|
26
26
|
return [...pages, page];
|
|
27
27
|
}
|
|
28
28
|
return pages;
|
|
@@ -33,35 +33,29 @@ function extractSubPages(
|
|
|
33
33
|
|
|
34
34
|
function extractLoop(components: LunaticComponentDefinition[] = []) {
|
|
35
35
|
return components.reduce(
|
|
36
|
-
function (
|
|
37
|
-
{ isLoop, subPages, iterations, loopDependencies, roundabout },
|
|
38
|
-
component
|
|
39
|
-
) {
|
|
36
|
+
function ({ isLoop, subPages, iterations, loopDependencies }, component) {
|
|
40
37
|
const currentIsLoop = isPaginatedLoop(component);
|
|
41
38
|
const currentIsRoundabout = isRoundabout(component);
|
|
42
39
|
if (currentIsLoop || currentIsRoundabout) {
|
|
43
40
|
return {
|
|
44
41
|
isLoop: isLoop || currentIsLoop,
|
|
45
|
-
roundabout: roundabout || currentIsRoundabout,
|
|
46
42
|
subPages: extractSubPages(component, subPages),
|
|
47
43
|
iterations: iterations || component.iterations,
|
|
48
44
|
loopDependencies: loopDependencies || undefined,
|
|
49
45
|
};
|
|
50
46
|
}
|
|
51
|
-
return { isLoop, subPages, iterations
|
|
47
|
+
return { isLoop, subPages, iterations };
|
|
52
48
|
},
|
|
53
49
|
{
|
|
54
50
|
isLoop: false,
|
|
55
51
|
subPages: undefined,
|
|
56
52
|
iterations: undefined,
|
|
57
53
|
loopDependencies: undefined,
|
|
58
|
-
roundabout: undefined,
|
|
59
54
|
} as {
|
|
60
55
|
isLoop: boolean;
|
|
61
56
|
iterations?: LunaticExpression;
|
|
62
57
|
loopDependencies?: string[];
|
|
63
58
|
subPages?: string[];
|
|
64
|
-
roundabout?: boolean;
|
|
65
59
|
}
|
|
66
60
|
);
|
|
67
61
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import isPaginatedLoop from './is-paginated-loop';
|
|
2
2
|
import isRoundabout from './is-roundabout';
|
|
3
|
-
import type { LunaticReducerState, LunaticSource } from '
|
|
4
|
-
import type { ItemOf } from '
|
|
3
|
+
import type { LunaticReducerState, LunaticSource } from '../../type';
|
|
4
|
+
import type { ItemOf } from '../../../type.utils';
|
|
5
5
|
|
|
6
6
|
function isUnpaginated(questionnaire: { maxPage?: unknown }): boolean {
|
|
7
7
|
const { maxPage } = questionnaire;
|
package/src/use-lunatic/commons/{page-navigation.spec.ts → pagination/page-navigation.spec.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { getNextPager, getPrevPager } from './page-navigation';
|
|
3
|
-
import type { LunaticReducerState } from '
|
|
3
|
+
import type { LunaticReducerState } from '../../type';
|
|
4
4
|
|
|
5
5
|
describe('page-navigation', () => {
|
|
6
6
|
describe('getNextPager', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { LunaticReducerState } from '
|
|
2
|
-
import type { LunaticComponentType } from '
|
|
1
|
+
import type { LunaticReducerState } from '../../type';
|
|
2
|
+
import type { LunaticComponentType } from '../../../components/type';
|
|
3
3
|
|
|
4
4
|
const resetIteration = {
|
|
5
5
|
subPage: undefined,
|
|
@@ -18,9 +18,9 @@ export function getNextPager(
|
|
|
18
18
|
// Increment the page or subPage
|
|
19
19
|
// eslint-disable-next-line prefer-const
|
|
20
20
|
let [page, subPage] =
|
|
21
|
-
pager.subPage
|
|
22
|
-
? [pager.page
|
|
23
|
-
: [pager.page + 1
|
|
21
|
+
pager.subPage === undefined
|
|
22
|
+
? [pager.page + 1, undefined]
|
|
23
|
+
: [pager.page, pager.subPage + 1];
|
|
24
24
|
let iteration = pager.iteration;
|
|
25
25
|
|
|
26
26
|
// We reached the end of the questionnaire
|
|
@@ -77,9 +77,9 @@ export function getPrevPager(
|
|
|
77
77
|
// Decrement the page or subPage
|
|
78
78
|
// eslint-disable-next-line prefer-const
|
|
79
79
|
let [page, subPage] =
|
|
80
|
-
pager.subPage
|
|
81
|
-
? [pager.page
|
|
82
|
-
: [pager.page - 1
|
|
80
|
+
pager.subPage === undefined
|
|
81
|
+
? [pager.page - 1, undefined]
|
|
82
|
+
: [pager.page, pager.subPage - 1];
|
|
83
83
|
let iteration = pager.iteration;
|
|
84
84
|
const moveUpOnStart =
|
|
85
85
|
parent === 'Roundabout' && pager.nbIterations && pager.nbIterations > 1;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
addIterationToPage,
|
|
4
|
+
getPagerFromPageTag,
|
|
5
|
+
pageTagComparator,
|
|
6
|
+
} from './page-tag';
|
|
7
|
+
import type { PageTag } from '../../type';
|
|
4
8
|
|
|
5
9
|
describe('page-tag', () => {
|
|
6
10
|
describe('getPagerFromPageTag', () => {
|
|
@@ -18,6 +22,15 @@ describe('page-tag', () => {
|
|
|
18
22
|
});
|
|
19
23
|
});
|
|
20
24
|
|
|
25
|
+
describe('addIterationToPage', () => {
|
|
26
|
+
it('should add itereation to simple page', () => {
|
|
27
|
+
expect(addIterationToPage('2', 0)).toEqual('2#1');
|
|
28
|
+
expect(addIterationToPage('2.1', 0)).toEqual('2.1#1');
|
|
29
|
+
expect(addIterationToPage('2', 1)).toEqual('2#2');
|
|
30
|
+
expect(addIterationToPage('2.1', 1)).toEqual('2.1#2');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
21
34
|
it.each([
|
|
22
35
|
['4.1', '4.2', -1],
|
|
23
36
|
['4.2#1', '4.2#1', 0],
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import type { LunaticReducerState, PageTag } from '
|
|
1
|
+
import type { LunaticReducerState, PageTag } from '../../type';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add iteration to existing pageTag (with subpage, use for overview)
|
|
5
|
+
* @param pageTag
|
|
6
|
+
* @param iteration
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export function addIterationToPage(page: string, iteration?: number): PageTag {
|
|
10
|
+
if (iteration === undefined) return page as PageTag;
|
|
11
|
+
return `${page}#${iteration + 1}` as PageTag;
|
|
12
|
+
}
|
|
2
13
|
|
|
3
14
|
/**
|
|
4
15
|
* Generate page name from the pager
|
|
@@ -38,12 +49,12 @@ export function getPagerFromPageTag(pageTag: string | number = 1) {
|
|
|
38
49
|
},
|
|
39
50
|
] = match;
|
|
40
51
|
if (!subPagePlusUn) {
|
|
41
|
-
return { page: parseInt(page, 10) };
|
|
52
|
+
return { page: Number.parseInt(page, 10) };
|
|
42
53
|
}
|
|
43
54
|
return {
|
|
44
|
-
page: parseInt(page, 10),
|
|
45
|
-
subPage: parseInt(subPagePlusUn, 10) - 1,
|
|
46
|
-
iteration: parseInt(iterationPlusUn, 10) - 1,
|
|
55
|
+
page: Number.parseInt(page, 10),
|
|
56
|
+
subPage: Number.parseInt(subPagePlusUn, 10) - 1,
|
|
57
|
+
iteration: Number.parseInt(iterationPlusUn, 10) - 1,
|
|
47
58
|
};
|
|
48
59
|
}
|
|
49
60
|
|
|
@@ -66,8 +77,8 @@ export function getNewReachedPage(
|
|
|
66
77
|
* - 0 if a is the same as b
|
|
67
78
|
*/
|
|
68
79
|
export function pageTagComparator(a: PageTag, b: PageTag) {
|
|
69
|
-
const pageA = a.split(/\D/).map((v) => parseInt(v, 10));
|
|
70
|
-
const pageB = b.split(/\D/).map((v) => parseInt(v, 10));
|
|
80
|
+
const pageA = a.split(/\D/).map((v) => Number.parseInt(v, 10));
|
|
81
|
+
const pageB = b.split(/\D/).map((v) => Number.parseInt(v, 10));
|
|
71
82
|
// [0, 2, 1] is used to extract the significant part of the pageTag part (start with page, then iteration, then subpage)
|
|
72
83
|
for (const index of [0, 2, 1]) {
|
|
73
84
|
if (pageA[index] !== pageB[index]) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
LunaticComponentDefinition,
|
|
3
|
+
LunaticReducerState,
|
|
4
|
+
} from '../../type';
|
|
5
|
+
import { getComponentsFromState } from '../get-components-from-state';
|
|
6
|
+
import executeConditionFilter from '../execute-condition-filter';
|
|
4
7
|
|
|
5
8
|
export function getPageId({
|
|
6
9
|
subPage,
|
|
@@ -15,6 +15,54 @@ export function usePageHasResponse(
|
|
|
15
15
|
}, [components, executeExpression]);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const hasMissingResponse = (component: LunaticComponentProps): boolean => {
|
|
19
|
+
if ('missingResponse' in component && component.missingResponse?.value)
|
|
20
|
+
return true;
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const hasArbitraryValue = (component: LunaticComponentProps): boolean => {
|
|
25
|
+
if ('arbitraryValue' in component && component.arbitraryValue !== undefined)
|
|
26
|
+
return true;
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const hasOneResponseInQuestion = (
|
|
31
|
+
component: LunaticComponentProps<'Question'>,
|
|
32
|
+
executeExpression: LunaticReducerState['executeExpression']
|
|
33
|
+
): boolean => {
|
|
34
|
+
return (
|
|
35
|
+
'components' in component &&
|
|
36
|
+
Array.isArray(component.components) &&
|
|
37
|
+
hasOneResponse(component.components, executeExpression)
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// For Table, we have to extract components from its body and apply isSubComponentsEmpty function
|
|
42
|
+
const hasOneResponseInTable = (
|
|
43
|
+
component: LunaticComponentProps<'Table'>,
|
|
44
|
+
executeExpression: LunaticReducerState['executeExpression']
|
|
45
|
+
): boolean => {
|
|
46
|
+
const childrenComponent = component.body.reduce((_, row) => {
|
|
47
|
+
const componentsInRow = row.filter(
|
|
48
|
+
(cell) => isObject(cell) && 'componentType' in cell
|
|
49
|
+
);
|
|
50
|
+
return [..._, ...componentsInRow];
|
|
51
|
+
}, [] as LunaticComponentProps[]);
|
|
52
|
+
return !isSubComponentsEmpty(childrenComponent, executeExpression);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const hasOneResponseInRosterForLoop = (
|
|
56
|
+
component: LunaticComponentProps<'RosterForLoop'>,
|
|
57
|
+
executeExpression: LunaticReducerState['executeExpression']
|
|
58
|
+
): boolean => {
|
|
59
|
+
return (
|
|
60
|
+
'components' in component &&
|
|
61
|
+
Array.isArray(component.components) &&
|
|
62
|
+
!isSubComponentsEmpty(component.components, executeExpression)
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
18
66
|
function hasOneResponse(
|
|
19
67
|
components: LunaticComponentProps[],
|
|
20
68
|
executeExpression: LunaticReducerState['executeExpression']
|
|
@@ -35,29 +83,17 @@ function hasOneResponse(
|
|
|
35
83
|
}
|
|
36
84
|
|
|
37
85
|
// We have a missing response for this component
|
|
38
|
-
if (
|
|
39
|
-
'missingResponse' in component &&
|
|
40
|
-
component.missingResponse &&
|
|
41
|
-
component.missingResponse.value
|
|
42
|
-
) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
86
|
+
if (hasMissingResponse(component)) return true;
|
|
45
87
|
|
|
46
88
|
// We have an arbitrary response for this component
|
|
47
|
-
if (
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
89
|
+
if (hasArbitraryValue(component)) return true;
|
|
50
90
|
|
|
51
91
|
// For Table, we have to extract components from its body and apply isSubComponentsEmpty function
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
);
|
|
58
|
-
return [..._, ...componentsInRow];
|
|
59
|
-
}, [] as LunaticComponentProps[]);
|
|
60
|
-
return !isSubComponentsEmpty(childrenComponent, executeExpression);
|
|
92
|
+
if (
|
|
93
|
+
component.componentType === 'Table' &&
|
|
94
|
+
hasOneResponseInTable(component, executeExpression)
|
|
95
|
+
) {
|
|
96
|
+
return true;
|
|
61
97
|
}
|
|
62
98
|
|
|
63
99
|
// We found a value in one of the root component. Used for Loop
|
|
@@ -68,19 +104,14 @@ function hasOneResponse(
|
|
|
68
104
|
// For Question, we need to check subcomponents
|
|
69
105
|
if (
|
|
70
106
|
component.componentType === 'Question' &&
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
hasOneResponse(component.components, executeExpression)
|
|
74
|
-
) {
|
|
107
|
+
hasOneResponseInQuestion(component, executeExpression)
|
|
108
|
+
)
|
|
75
109
|
return true;
|
|
76
|
-
}
|
|
77
110
|
|
|
78
111
|
// For rosterForLoop we need to inspect child components
|
|
79
112
|
if (
|
|
80
113
|
component.componentType === 'RosterForLoop' &&
|
|
81
|
-
|
|
82
|
-
Array.isArray(component.components) &&
|
|
83
|
-
!isSubComponentsEmpty(component.components, executeExpression)
|
|
114
|
+
hasOneResponseInRosterForLoop(component, executeExpression)
|
|
84
115
|
) {
|
|
85
116
|
return true;
|
|
86
117
|
}
|
|
@@ -99,7 +130,7 @@ function isEmpty(value: unknown): boolean {
|
|
|
99
130
|
// Array is empty if all items are empty
|
|
100
131
|
if (Array.isArray(value)) {
|
|
101
132
|
// We find one value that is not empty
|
|
102
|
-
return value.
|
|
133
|
+
return !value.some((v) => !isEmpty(v));
|
|
103
134
|
}
|
|
104
135
|
// For object inspect each values
|
|
105
136
|
if (typeof value === 'object' && value !== null) {
|
|
@@ -5,7 +5,11 @@ import type {
|
|
|
5
5
|
PageTag,
|
|
6
6
|
} from '../type';
|
|
7
7
|
import { type DependencyList, type ReactNode, useMemo } from 'react';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
addIterationToPage,
|
|
10
|
+
getPageTag,
|
|
11
|
+
pageTagComparator,
|
|
12
|
+
} from '../commons/pagination/page-tag';
|
|
9
13
|
|
|
10
14
|
export type InterpretedLunaticOverviewItem = {
|
|
11
15
|
id: string;
|
|
@@ -126,8 +130,7 @@ const interpretOverviewItem = (
|
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
// Append the item to the list of items
|
|
129
|
-
const page =
|
|
130
|
-
`${item.pageTag}${iteration !== undefined ? `#${iteration + 1}` : ''}` as PageTag;
|
|
133
|
+
const page = addIterationToPage(item.pageTag, iteration);
|
|
131
134
|
|
|
132
135
|
const reached =
|
|
133
136
|
pageTagComparator(state.pager ? getPageTag(state.pager) : '-1', page) >= 0;
|
|
@@ -33,7 +33,7 @@ function getRoundaboutProps(
|
|
|
33
33
|
}));
|
|
34
34
|
return {
|
|
35
35
|
items: items,
|
|
36
|
-
page: parseInt(component.page ?? '1', 10),
|
|
36
|
+
page: Number.parseInt(component.page ?? '1', 10),
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -121,6 +121,7 @@ function getPairwiseProps(
|
|
|
121
121
|
state: State
|
|
122
122
|
) {
|
|
123
123
|
return {
|
|
124
|
+
size: state.pager.nbIterations ?? component.xAxisIterations,
|
|
124
125
|
getComponents: (x: number, y: number) => {
|
|
125
126
|
if (x === y) {
|
|
126
127
|
return [];
|