@clxmedia/clxforms-client 1.0.21 → 1.0.22
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/dist/layout-processor.js +16 -18
- package/package.json +1 -1
package/dist/layout-processor.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.CLXFormLayoutProcessor = void 0;
|
|
|
4
4
|
const rules_processor_1 = require("./rules-processor");
|
|
5
5
|
const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
6
6
|
const responseCopy = JSON.parse(JSON.stringify(responseData));
|
|
7
|
-
const isQuestionLayoutEnabled = (questionLayout) => {
|
|
7
|
+
const isQuestionLayoutEnabled = (questionLayout, sectionResponses) => {
|
|
8
8
|
if (mode === 'edit') {
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
@@ -16,7 +16,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
16
16
|
questionLayout.conditions.rules.length === 0) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
|
-
return (0, rules_processor_1.CLXRulesetProcessor)({ responseData:
|
|
19
|
+
return (0, rules_processor_1.CLXRulesetProcessor)({ responseData: sectionResponses }).processRuleSet(questionLayout.conditions);
|
|
20
20
|
};
|
|
21
21
|
const containsErrors = (errs) => {
|
|
22
22
|
return errs !== undefined && Array.isArray(errs) && errs.some(err => err !== null);
|
|
@@ -27,40 +27,38 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
27
27
|
}
|
|
28
28
|
return !!response && response.value !== undefined && !containsErrors(response.errorMsg);
|
|
29
29
|
};
|
|
30
|
-
const isSectionComplete = (section) => {
|
|
30
|
+
const isSectionComplete = (section, sectionResponses) => {
|
|
31
31
|
if (!section || !section.question_layouts || section.question_layouts.length === 0) {
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
34
|
const requiredQuestionLayouts = section.question_layouts.filter(ql => {
|
|
35
|
-
return ql.is_required && isQuestionLayoutEnabled(ql);
|
|
35
|
+
return ql.is_required && isQuestionLayoutEnabled(ql, sectionResponses);
|
|
36
36
|
});
|
|
37
37
|
return requiredQuestionLayouts.every(ql => {
|
|
38
|
-
return isResponseSaved(
|
|
38
|
+
return isResponseSaved(sectionResponses[ql.form_question_slug]);
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
-
const questionLayoutProcessor = (questionLayout,
|
|
42
|
-
const is_enabled = isQuestionLayoutEnabled(questionLayout);
|
|
41
|
+
const questionLayoutProcessor = (questionLayout, sectionResponses) => {
|
|
42
|
+
const is_enabled = isQuestionLayoutEnabled(questionLayout, sectionResponses);
|
|
43
43
|
if (!is_enabled) {
|
|
44
|
-
|
|
45
|
-
return Object.assign(Object.assign({}, questionLayout), { is_enabled, is_complete: false });
|
|
44
|
+
sectionResponses[questionLayout.form_question_slug] = undefined;
|
|
46
45
|
}
|
|
47
|
-
return Object.assign(Object.assign({}, questionLayout), { is_enabled, is_complete: is_enabled ? isResponseSaved(
|
|
46
|
+
return Object.assign(Object.assign({}, questionLayout), { is_enabled, is_complete: is_enabled ? isResponseSaved(sectionResponses[questionLayout.form_question_slug]) : false });
|
|
48
47
|
};
|
|
49
|
-
const sectionProcessor = (section
|
|
50
|
-
const
|
|
51
|
-
if (section.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData:
|
|
48
|
+
const sectionProcessor = (section) => {
|
|
49
|
+
const sectionResponses = JSON.parse(JSON.stringify(responseCopy));
|
|
50
|
+
if (section.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData: sectionResponses }).processRuleSet(section.conditions)) {
|
|
52
51
|
return Object.assign(Object.assign({}, section), { is_complete: true, question_layouts: [] });
|
|
53
52
|
}
|
|
54
|
-
const is_section_complete = isSectionComplete(section);
|
|
55
|
-
return Object.assign(Object.assign({}, section), { is_complete: is_section_complete, question_layouts: section.question_layouts.map(questionLayout => questionLayoutProcessor(questionLayout,
|
|
53
|
+
const is_section_complete = isSectionComplete(section, sectionResponses);
|
|
54
|
+
return Object.assign(Object.assign({}, section), { is_complete: is_section_complete, question_layouts: section.question_layouts.map(questionLayout => questionLayoutProcessor(questionLayout, sectionResponses)) });
|
|
56
55
|
};
|
|
57
56
|
const stepProcessor = (step) => {
|
|
58
|
-
|
|
59
|
-
if (step.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData: responseStep }).processRuleSet(step.conditions)) {
|
|
57
|
+
if (step.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData: responseCopy }).processRuleSet(step.conditions)) {
|
|
60
58
|
return Object.assign(Object.assign({}, step), { is_complete: true, sections: [] });
|
|
61
59
|
}
|
|
62
60
|
const sections = step.sections
|
|
63
|
-
.map(section => sectionProcessor(section
|
|
61
|
+
.map(section => sectionProcessor(section))
|
|
64
62
|
.filter(section => section.question_layouts.some(ql => ql.is_enabled));
|
|
65
63
|
return Object.assign(Object.assign({}, step), { is_complete: sections.every(section => section.is_complete), sections });
|
|
66
64
|
};
|