@inseefr/lunatic 3.4.13 → 3.4.14
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/type.d.ts +1 -0
- package/esm/components/type.d.ts +1 -0
- package/esm/use-lunatic/hooks/use-page-has-response.js +45 -35
- package/esm/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/esm/use-lunatic/props/getComponentTypeProps.d.ts +1 -0
- package/package.json +2 -1
- package/src/components/type.ts +1 -0
- package/src/use-lunatic/hooks/use-page-has-response.test.ts +143 -0
- package/src/use-lunatic/hooks/use-page-has-response.ts +61 -44
- package/tsconfig.build.tsbuildinfo +1 -1
- package/use-lunatic/hooks/use-page-has-response.js +44 -34
- package/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/use-lunatic/props/getComponentTypeProps.d.ts +1 -0
|
@@ -8,43 +8,53 @@ const is_object_1 = require("../../utils/is-object");
|
|
|
8
8
|
*/
|
|
9
9
|
function usePageHasResponse(components, executeExpression) {
|
|
10
10
|
return (0, react_1.useCallback)(() => {
|
|
11
|
-
|
|
11
|
+
return hasOneResponse(components, executeExpression);
|
|
12
|
+
}, [components, executeExpression]);
|
|
13
|
+
}
|
|
14
|
+
function hasOneResponse(components, executeExpression) {
|
|
15
|
+
if (!Array.isArray(components) || components.length === 0) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
for (const component of components) {
|
|
19
|
+
// Some components are considered as "filled" by default
|
|
20
|
+
// We assume they are not in the same page has other components
|
|
21
|
+
if (['PairwiseLinks', 'Roundabout', 'Sequence', 'Subsequence'].includes(component.componentType ?? '')) {
|
|
12
22
|
return true;
|
|
13
23
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
// We have a missing response for this component
|
|
21
|
-
if ('missingResponse' in component &&
|
|
22
|
-
component.missingResponse &&
|
|
23
|
-
component.missingResponse.value) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
// For Table, we have to extract components from its body and apply isSubComponentsEmpty function
|
|
27
|
-
if (component.componentType === 'Table') {
|
|
28
|
-
// Body is array for array (row), each "cell" could be an Label or Component, so we filter array.
|
|
29
|
-
const childrenComponent = component.body.reduce((_, row) => {
|
|
30
|
-
const componentsInRow = row.filter((cell) => (0, is_object_1.isObject)(cell) && 'componentType' in cell);
|
|
31
|
-
return [..._, ...componentsInRow];
|
|
32
|
-
}, []);
|
|
33
|
-
return !isSubComponentsEmpty(childrenComponent, executeExpression);
|
|
34
|
-
}
|
|
35
|
-
// We found a value in one of the root component
|
|
36
|
-
if ('value' in component && !isEmpty(component.value)) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
// For rosterForLoop we need to inspect child components
|
|
40
|
-
if ('components' in component &&
|
|
41
|
-
Array.isArray(component.components) &&
|
|
42
|
-
!isSubComponentsEmpty(component.components, executeExpression)) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
24
|
+
// We have a missing response for this component
|
|
25
|
+
if ('missingResponse' in component &&
|
|
26
|
+
component.missingResponse &&
|
|
27
|
+
component.missingResponse.value) {
|
|
28
|
+
return true;
|
|
45
29
|
}
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
// For Table, we have to extract components from its body and apply isSubComponentsEmpty function
|
|
31
|
+
if (component.componentType === 'Table') {
|
|
32
|
+
// Body is array for array (row), each "cell" could be an Label or Component, so we filter array.
|
|
33
|
+
const childrenComponent = component.body.reduce((_, row) => {
|
|
34
|
+
const componentsInRow = row.filter((cell) => (0, is_object_1.isObject)(cell) && 'componentType' in cell);
|
|
35
|
+
return [..._, ...componentsInRow];
|
|
36
|
+
}, []);
|
|
37
|
+
return !isSubComponentsEmpty(childrenComponent, executeExpression);
|
|
38
|
+
}
|
|
39
|
+
// We found a value in one of the root component
|
|
40
|
+
if ('value' in component && !isEmpty(component.value)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
// For Question, we need to check subcomponents
|
|
44
|
+
if (component.componentType === 'Question' &&
|
|
45
|
+
'components' in component &&
|
|
46
|
+
Array.isArray(component.components) &&
|
|
47
|
+
hasOneResponse(component.components, executeExpression)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
// For rosterForLoop we need to inspect child components
|
|
51
|
+
if ('components' in component &&
|
|
52
|
+
Array.isArray(component.components) &&
|
|
53
|
+
!isSubComponentsEmpty(component.components, executeExpression)) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
48
58
|
}
|
|
49
59
|
/**
|
|
50
60
|
* Check if a value is empty.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-page-has-response.js","sourceRoot":"","sources":["../../src/use-lunatic/hooks/use-page-has-response.ts"],"names":[],"mappings":";;AAQA,
|
|
1
|
+
{"version":3,"file":"use-page-has-response.js","sourceRoot":"","sources":["../../src/use-lunatic/hooks/use-page-has-response.ts"],"names":[],"mappings":";;AAQA,gDAOC;AAfD,iCAAoC;AACpC,qDAAiD;AAIjD;;GAEG;AACH,SAAgB,kBAAkB,CACjC,UAAmC,EACnC,iBAA2D;IAE3D,OAAO,IAAA,mBAAW,EAAC,GAAG,EAAE;QACvB,OAAO,cAAc,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACtD,CAAC,EAAE,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,cAAc,CACtB,UAAmC,EACnC,iBAA2D;IAE3D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,wDAAwD;QACxD,+DAA+D;QAC/D,IACC,CAAC,eAAe,EAAE,YAAY,EAAE,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QAAQ;YAClB,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ;YACtC,MAAM,IAAI,SAAS,CAAC,QAAQ;YAC5B,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ;YAC3C,CAAC,OAAO,CACP,iBAAiB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAClE,EACA,CAAC;YACF,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -188,6 +188,7 @@ export declare function getComponentTypeProps(component: DeepTranslateExpression
|
|
|
188
188
|
components: import("../..").LunaticComponentProps[];
|
|
189
189
|
componentType?: "Question";
|
|
190
190
|
iteration?: number;
|
|
191
|
+
value: Record<string, unknown>;
|
|
191
192
|
} & {
|
|
192
193
|
conditionFilter?: boolean;
|
|
193
194
|
}) | (import("../../components/type").LunaticBaseProps<string | null> & import("../..").LunaticExtraProps & {
|