@clxmedia/clxforms-client 1.0.11 → 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
|
@@ -76,6 +76,78 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
76
76
|
const value = responseData[key];
|
|
77
77
|
return !!value && value.type === 'BOOLEAN' && value.value;
|
|
78
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
|
+
};
|
|
79
151
|
const MockProcessor = (layout) => {
|
|
80
152
|
return {
|
|
81
153
|
form: layout.form,
|
|
@@ -111,6 +183,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
|
|
|
111
183
|
return { form: layout.form, steps, stats: gatherFormStats(steps) };
|
|
112
184
|
};
|
|
113
185
|
return {
|
|
186
|
+
filter,
|
|
114
187
|
process,
|
|
115
188
|
processRuleSet: (0, rules_processor_1.CLXRulesetProcessor)({ responseData }).processRuleSet
|
|
116
189
|
};
|