@beabee/beabee-common 1.10.19 → 1.10.21
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertComponentsToFilters = exports.flattenComponents = void 0;
|
|
3
|
+
exports.convertAnswers = exports.convertAnswer = exports.getNiceAnswer = exports.convertComponentsToFilters = exports.flattenComponents = void 0;
|
|
4
4
|
function flattenComponents(components) {
|
|
5
5
|
return components.flatMap((component) => [
|
|
6
6
|
component,
|
|
@@ -45,3 +45,43 @@ function convertComponentsToFilters(components) {
|
|
|
45
45
|
return Object.fromEntries(items);
|
|
46
46
|
}
|
|
47
47
|
exports.convertComponentsToFilters = convertComponentsToFilters;
|
|
48
|
+
function getNiceAnswer(component, value) {
|
|
49
|
+
switch (component.type) {
|
|
50
|
+
case "radio":
|
|
51
|
+
case "selectboxes":
|
|
52
|
+
return component.values.find((v) => v.value === value)?.label || value;
|
|
53
|
+
case "select":
|
|
54
|
+
return (component.data.values.find((v) => v.value === value)?.label || value);
|
|
55
|
+
default:
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.getNiceAnswer = getNiceAnswer;
|
|
60
|
+
function convertAnswer(component, answer) {
|
|
61
|
+
if (!answer) {
|
|
62
|
+
return "";
|
|
63
|
+
}
|
|
64
|
+
else if (typeof answer === "object") {
|
|
65
|
+
return Object.entries(answer)
|
|
66
|
+
.filter(([value, selected]) => selected)
|
|
67
|
+
.map(([value]) => getNiceAnswer(component, value))
|
|
68
|
+
.join(", ");
|
|
69
|
+
}
|
|
70
|
+
else if (typeof answer === "string") {
|
|
71
|
+
return getNiceAnswer(component, answer);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return answer.toString();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.convertAnswer = convertAnswer;
|
|
78
|
+
function convertAnswers(formSchema, answers) {
|
|
79
|
+
return Object.assign({}, ...flattenComponents(formSchema.components)
|
|
80
|
+
.filter((component) => component.input)
|
|
81
|
+
.map((component) => {
|
|
82
|
+
return {
|
|
83
|
+
[component.label || component.key]: convertAnswer(component, answers[component.key]),
|
|
84
|
+
};
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
exports.convertAnswers = convertAnswers;
|
|
@@ -40,3 +40,40 @@ export function convertComponentsToFilters(components) {
|
|
|
40
40
|
});
|
|
41
41
|
return Object.fromEntries(items);
|
|
42
42
|
}
|
|
43
|
+
export function getNiceAnswer(component, value) {
|
|
44
|
+
switch (component.type) {
|
|
45
|
+
case "radio":
|
|
46
|
+
case "selectboxes":
|
|
47
|
+
return component.values.find((v) => v.value === value)?.label || value;
|
|
48
|
+
case "select":
|
|
49
|
+
return (component.data.values.find((v) => v.value === value)?.label || value);
|
|
50
|
+
default:
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function convertAnswer(component, answer) {
|
|
55
|
+
if (!answer) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
else if (typeof answer === "object") {
|
|
59
|
+
return Object.entries(answer)
|
|
60
|
+
.filter(([value, selected]) => selected)
|
|
61
|
+
.map(([value]) => getNiceAnswer(component, value))
|
|
62
|
+
.join(", ");
|
|
63
|
+
}
|
|
64
|
+
else if (typeof answer === "string") {
|
|
65
|
+
return getNiceAnswer(component, answer);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return answer.toString();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function convertAnswers(formSchema, answers) {
|
|
72
|
+
return Object.assign({}, ...flattenComponents(formSchema.components)
|
|
73
|
+
.filter((component) => component.input)
|
|
74
|
+
.map((component) => {
|
|
75
|
+
return {
|
|
76
|
+
[component.label || component.key]: convertAnswer(component, answers[component.key]),
|
|
77
|
+
};
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
@@ -6,7 +6,7 @@ export interface BaseCalloutComponentSchema {
|
|
|
6
6
|
[key: string]: unknown;
|
|
7
7
|
}
|
|
8
8
|
export interface OtherCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
9
|
-
type: "button" | "checkbox" | "number" | "password" | "textfield" | "textarea";
|
|
9
|
+
type: "address" | "button" | "checkbox" | "email" | "number" | "password" | "textfield" | "textarea";
|
|
10
10
|
}
|
|
11
11
|
export interface SelectCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
12
12
|
type: "select";
|
|
@@ -28,3 +28,5 @@ export type CalloutComponentSchema = SelectCalloutComponentSchema | RadioCallout
|
|
|
28
28
|
export interface CalloutFormSchema {
|
|
29
29
|
components: CalloutComponentSchema[];
|
|
30
30
|
}
|
|
31
|
+
export type CalloutResponseAnswer = string | boolean | number | null | undefined | Record<string, boolean>;
|
|
32
|
+
export type CalloutResponseAnswers = Record<string, CalloutResponseAnswer>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { CalloutComponentSchema } from "../data/callouts";
|
|
1
|
+
import { CalloutComponentSchema, CalloutFormSchema, CalloutResponseAnswer, CalloutResponseAnswers } from "../data/callouts";
|
|
2
2
|
import { Filters } from "../search";
|
|
3
3
|
export declare function flattenComponents(components: CalloutComponentSchema[]): CalloutComponentSchema[];
|
|
4
4
|
export declare function convertComponentsToFilters(components: CalloutComponentSchema[]): Filters;
|
|
5
|
+
export declare function getNiceAnswer(component: CalloutComponentSchema, value: string): string;
|
|
6
|
+
export declare function convertAnswer(component: CalloutComponentSchema, answer: CalloutResponseAnswer): string;
|
|
7
|
+
export declare function convertAnswers(formSchema: CalloutFormSchema, answers: CalloutResponseAnswers): Record<string, unknown>;
|