@clxmedia/clxforms-client 1.0.10 → 1.0.12
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.
|
@@ -21,11 +21,15 @@ export type ProcessedCLXFormLayout = {
|
|
|
21
21
|
steps: ProcessedCLXFormStep[];
|
|
22
22
|
stats?: FormStats;
|
|
23
23
|
};
|
|
24
|
+
export type FilteredCLXFormLayout = ProcessedCLXFormLayout & {
|
|
25
|
+
usedSlugs: string[];
|
|
26
|
+
};
|
|
24
27
|
export declare const CLXFormLayoutProcessor: ({ mode, responseData, formRights }: {
|
|
25
28
|
mode: CLXFormMode;
|
|
26
29
|
responseData: CLXFormResponses;
|
|
27
30
|
formRights: XperienceAbility;
|
|
28
31
|
}) => {
|
|
32
|
+
filter: (pl: ProcessedCLXFormLayout) => FilteredCLXFormLayout;
|
|
29
33
|
process: (layout: CLXFormLayout) => ProcessedCLXFormLayout;
|
|
30
34
|
processRuleSet: (ruleSet?: CLXFormRuleSet) => boolean;
|
|
31
35
|
};
|
package/dist/layout-processor.js
CHANGED
|
@@ -39,6 +39,9 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
39
39
|
};
|
|
40
40
|
const questionLayoutProcessor = (questionLayout, response) => {
|
|
41
41
|
const is_enabled = isQuestionLayoutEnabled(questionLayout);
|
|
42
|
+
if (!is_enabled) {
|
|
43
|
+
responseData[questionLayout.form_question_slug] = undefined;
|
|
44
|
+
}
|
|
42
45
|
return Object.assign(Object.assign({}, questionLayout), { is_enabled, is_complete: is_enabled ? isResponseSaved(response) : false });
|
|
43
46
|
};
|
|
44
47
|
const sectionProcessor = (section) => {
|
|
@@ -73,6 +76,78 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
73
76
|
const value = responseData[key];
|
|
74
77
|
return !!value && value.type === 'BOOLEAN' && value.value;
|
|
75
78
|
};
|
|
79
|
+
const slugExtractor = (rs) => {
|
|
80
|
+
var _a;
|
|
81
|
+
return (_a = rs === null || rs === void 0 ? void 0 : rs.rules) === null || _a === void 0 ? void 0 : _a.reduce((acc, rule) => {
|
|
82
|
+
const subject = rule.subject;
|
|
83
|
+
if (subject) {
|
|
84
|
+
return acc.concat(subject);
|
|
85
|
+
}
|
|
86
|
+
return acc.concat(slugExtractor(rule));
|
|
87
|
+
}, []);
|
|
88
|
+
};
|
|
89
|
+
const determineUsedSlugs = (steps) => {
|
|
90
|
+
const activeSlugs = steps.reduce((acc, step) => {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
for (const section of step.sections) {
|
|
93
|
+
for (const ql of section.question_layouts) {
|
|
94
|
+
acc.add(ql.form_question_slug);
|
|
95
|
+
const conditionSlugs = slugExtractor(ql.conditions);
|
|
96
|
+
const overrideSlugs = (_b = (_a = ql.overrides) === null || _a === void 0 ? void 0 : _a.max_select_override) === null || _b === void 0 ? void 0 : _b.reduce((acc, rule) => {
|
|
97
|
+
return acc.concat(slugExtractor(rule === null || rule === void 0 ? void 0 : rule.ruleset));
|
|
98
|
+
}, []);
|
|
99
|
+
conditionSlugs === null || conditionSlugs === void 0 ? void 0 : conditionSlugs.forEach((slug) => acc.add(slug));
|
|
100
|
+
overrideSlugs === null || overrideSlugs === void 0 ? void 0 : overrideSlugs.forEach((slug) => acc.add(slug));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return acc;
|
|
104
|
+
}, new Set());
|
|
105
|
+
return Array.from(activeSlugs);
|
|
106
|
+
};
|
|
107
|
+
const filter = (pl) => {
|
|
108
|
+
const filtered = {
|
|
109
|
+
form: pl.form,
|
|
110
|
+
steps: pl.steps
|
|
111
|
+
.map((step) => {
|
|
112
|
+
return {
|
|
113
|
+
id: step.id,
|
|
114
|
+
name: step.name,
|
|
115
|
+
description: step.description,
|
|
116
|
+
is_gate: step.is_gate,
|
|
117
|
+
sections: step.sections
|
|
118
|
+
.map((section) => {
|
|
119
|
+
return {
|
|
120
|
+
id: section.id,
|
|
121
|
+
name: section.name,
|
|
122
|
+
question_layouts: section.question_layouts
|
|
123
|
+
.map((ql) => {
|
|
124
|
+
return {
|
|
125
|
+
id: ql.id,
|
|
126
|
+
form_question_slug: ql.form_question_slug,
|
|
127
|
+
is_enabled: ql.is_enabled,
|
|
128
|
+
is_required: ql.is_required,
|
|
129
|
+
conditions: ql.conditions,
|
|
130
|
+
overrides: ql.overrides,
|
|
131
|
+
};
|
|
132
|
+
})
|
|
133
|
+
.filter((ql) => {
|
|
134
|
+
return ql.is_enabled;
|
|
135
|
+
}),
|
|
136
|
+
};
|
|
137
|
+
})
|
|
138
|
+
.filter((section) => {
|
|
139
|
+
return section.question_layouts.length > 0;
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
})
|
|
143
|
+
.filter((step) => {
|
|
144
|
+
return step.sections.length > 0;
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
filtered.usedSlugs = determineUsedSlugs(filtered.steps);
|
|
148
|
+
;
|
|
149
|
+
return filtered;
|
|
150
|
+
};
|
|
76
151
|
const MockProcessor = (layout) => {
|
|
77
152
|
return {
|
|
78
153
|
form: layout.form,
|
|
@@ -108,6 +183,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
108
183
|
return { form: layout.form, steps, stats: gatherFormStats(steps) };
|
|
109
184
|
};
|
|
110
185
|
return {
|
|
186
|
+
filter,
|
|
111
187
|
process,
|
|
112
188
|
processRuleSet: (0, rules_processor_1.CLXRulesetProcessor)({ responseData }).processRuleSet
|
|
113
189
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clxmedia/clxforms-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "CLXperience Forms Client",
|
|
5
5
|
"author": "Brandon Thompson <brandont@clxmedia.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"bugs": "https://github.com/adsupnow/xperience-library/clxforms-client",
|
|
43
43
|
"peerDependencies": {},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@clxmedia/types": "1.0.
|
|
45
|
+
"@clxmedia/types": "1.0.161",
|
|
46
46
|
"luxon": "3.4.4"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|