@clxmedia/clxforms-client 1.0.16 → 1.0.17
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 +11 -7
- package/package.json +1 -1
package/dist/layout-processor.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CLXFormLayoutProcessor = void 0;
|
|
4
4
|
const rules_processor_1 = require("./rules-processor");
|
|
5
5
|
const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
6
|
+
const responseCopy = JSON.parse(JSON.stringify(responseData));
|
|
6
7
|
const isQuestionLayoutEnabled = (questionLayout) => {
|
|
7
8
|
if (mode === 'edit') {
|
|
8
9
|
return true;
|
|
@@ -15,7 +16,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
15
16
|
questionLayout.conditions.rules.length === 0) {
|
|
16
17
|
return true;
|
|
17
18
|
}
|
|
18
|
-
return (0, rules_processor_1.CLXRulesetProcessor)({ responseData }).processRuleSet(questionLayout.conditions);
|
|
19
|
+
return (0, rules_processor_1.CLXRulesetProcessor)({ responseData: responseCopy }).processRuleSet(questionLayout.conditions);
|
|
19
20
|
};
|
|
20
21
|
const containsErrors = (errs) => {
|
|
21
22
|
return errs !== undefined && Array.isArray(errs) && errs.some(err => err !== null);
|
|
@@ -34,22 +35,25 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
34
35
|
return ql.is_required && isQuestionLayoutEnabled(ql);
|
|
35
36
|
});
|
|
36
37
|
return requiredQuestionLayouts.every(ql => {
|
|
37
|
-
return isResponseSaved(
|
|
38
|
+
return isResponseSaved(responseCopy[ql.form_question_slug]);
|
|
38
39
|
});
|
|
39
40
|
};
|
|
40
41
|
const questionLayoutProcessor = (questionLayout, response) => {
|
|
41
42
|
const is_enabled = isQuestionLayoutEnabled(questionLayout);
|
|
43
|
+
if (!is_enabled) {
|
|
44
|
+
responseCopy[questionLayout.form_question_slug] = undefined;
|
|
45
|
+
}
|
|
42
46
|
return Object.assign(Object.assign({}, questionLayout), { is_enabled, is_complete: is_enabled ? isResponseSaved(response) : false });
|
|
43
47
|
};
|
|
44
48
|
const sectionProcessor = (section) => {
|
|
45
|
-
if (section.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData }).processRuleSet(section.conditions)) {
|
|
49
|
+
if (section.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData: responseCopy }).processRuleSet(section.conditions)) {
|
|
46
50
|
return Object.assign(Object.assign({}, section), { is_complete: true, question_layouts: [] });
|
|
47
51
|
}
|
|
48
52
|
const is_section_complete = isSectionComplete(section);
|
|
49
|
-
return Object.assign(Object.assign({}, section), { is_complete: is_section_complete, question_layouts: section.question_layouts.map(questionLayout => questionLayoutProcessor(questionLayout,
|
|
53
|
+
return Object.assign(Object.assign({}, section), { is_complete: is_section_complete, question_layouts: section.question_layouts.map(questionLayout => questionLayoutProcessor(questionLayout, responseCopy[questionLayout.form_question_slug])) });
|
|
50
54
|
};
|
|
51
55
|
const stepProcessor = (step) => {
|
|
52
|
-
if (step.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData }).processRuleSet(step.conditions)) {
|
|
56
|
+
if (step.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData: responseCopy }).processRuleSet(step.conditions)) {
|
|
53
57
|
return Object.assign(Object.assign({}, step), { is_complete: true, sections: [] });
|
|
54
58
|
}
|
|
55
59
|
const sections = step.sections
|
|
@@ -70,7 +74,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
70
74
|
};
|
|
71
75
|
};
|
|
72
76
|
const isResponseBooleanTrue = (key) => {
|
|
73
|
-
const value =
|
|
77
|
+
const value = responseCopy[key];
|
|
74
78
|
return !!value && value.type === 'BOOLEAN' && value.value;
|
|
75
79
|
};
|
|
76
80
|
const MockProcessor = (layout) => {
|
|
@@ -109,7 +113,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
109
113
|
};
|
|
110
114
|
return {
|
|
111
115
|
process,
|
|
112
|
-
processRuleSet: (0, rules_processor_1.CLXRulesetProcessor)({ responseData }).processRuleSet
|
|
116
|
+
processRuleSet: (0, rules_processor_1.CLXRulesetProcessor)({ responseData: responseCopy }).processRuleSet
|
|
113
117
|
};
|
|
114
118
|
};
|
|
115
119
|
exports.CLXFormLayoutProcessor = CLXFormLayoutProcessor;
|